API Docs for: 1.0.8
Show:

File: client/lib/hawkCredentials.js

  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. define(['sjcl', './hkdf'], function (sjcl, hkdf) {
  5. 'use strict';
  6.  
  7. var PREFIX_NAME = 'identity.mozilla.com/picl/v1/';
  8. var bitSlice = sjcl.bitArray.bitSlice;
  9. var salt = sjcl.codec.hex.toBits('');
  10.  
  11. /**
  12. * @class hawkCredentials
  13. * @method deriveHawkCredentials
  14. * @param {String} tokenHex
  15. * @param {String} context
  16. * @param {int} size
  17. * @returns {Promise}
  18. */
  19. function deriveHawkCredentials(tokenHex, context, size) {
  20. var token = sjcl.codec.hex.toBits(tokenHex);
  21. var info = sjcl.codec.utf8String.toBits(PREFIX_NAME + context);
  22.  
  23. return hkdf(token, info, salt, size || 3 * 32)
  24. .then(function(out) {
  25. var authKey = bitSlice(out, 8 * 32, 8 * 64);
  26. var bundleKey = bitSlice(out, 8 * 64);
  27.  
  28. return {
  29. algorithm: 'sha256',
  30. id: sjcl.codec.hex.fromBits(bitSlice(out, 0, 8 * 32)),
  31. key: authKey,
  32. bundleKey: bundleKey
  33. };
  34. });
  35. }
  36.  
  37. return deriveHawkCredentials;
  38. });
  39.