Yep, mostly copied over from browserid.