Skip to content

Instantly share code, notes, and snippets.

@zaach
Created January 7, 2014 20:02
Show Gist options
  • Save zaach/8305927 to your computer and use it in GitHub Desktop.
Save zaach/8305927 to your computer and use it in GitHub Desktop.
var PREFIX_NAME = "identity.mozilla.com/picl/v1/";
var bitSlice = sjcl.bitArray.bitSlice;
function deriveHawkCredentials(tokenHex, context, size) {
var token = sjcl.codec.hex.toBits(tokenHex);
var info = sjcl.codec.utf8String.toBits(PREFIX_NAME + context);
return hkdf(token, info, undefined, size || 3 * 32)
.then(function(out) {
var authKey = bitSlice(out, 8 * 32, 8 * 64);
var bundleKey = bitSlice(out, 8 * 64);
return {
algorithm: "sha256",
id: sjcl.codec.hex.fromBits(bitSlice(out, 0, 8 * 32)),
key: authKey,
bundleKey: bundleKey
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment