"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/hawk/lib/browser.js" (8 Feb 2018, 27106 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict';
    2 
    3 /*
    4     HTTP Hawk Authentication Scheme
    5     Copyright (c) 2012-2016, Eran Hammer <eran@hammer.io>
    6     BSD Licensed
    7 */
    8 
    9 
   10 // Declare namespace
   11 
   12 const hawk = {
   13     internals: {}
   14 };
   15 
   16 
   17 hawk.client = {
   18 
   19     // Generate an Authorization header for a given request
   20 
   21     /*
   22         uri: 'http://example.com/resource?a=b' or object generated by hawk.utils.parseUri()
   23         method: HTTP verb (e.g. 'GET', 'POST')
   24         options: {
   25 
   26             // Required
   27 
   28             credentials: {
   29                 id: 'dh37fgj492je',
   30                 key: 'aoijedoaijsdlaksjdl',
   31                 algorithm: 'sha256'                                 // 'sha1', 'sha256'
   32             },
   33 
   34             // Optional
   35 
   36             ext: 'application-specific',                        // Application specific data sent via the ext attribute
   37             timestamp: Date.now() / 1000,                       // A pre-calculated timestamp in seconds
   38             nonce: '2334f34f',                                  // A pre-generated nonce
   39             localtimeOffsetMsec: 400,                           // Time offset to sync with server time (ignored if timestamp provided)
   40             payload: '{"some":"payload"}',                      // UTF-8 encoded string for body hash generation (ignored if hash provided)
   41             contentType: 'application/json',                    // Payload content-type (ignored if hash provided)
   42             hash: 'U4MKKSmiVxk37JCCrAVIjV=',                    // Pre-calculated payload hash
   43             app: '24s23423f34dx',                               // Oz application id
   44             dlg: '234sz34tww3sd'                                // Oz delegated-by application id
   45         }
   46     */
   47 
   48     header: function (uri, method, options) {
   49 
   50         const result = {
   51             field: '',
   52             artifacts: {}
   53         };
   54 
   55         // Validate inputs
   56 
   57         if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') ||
   58             !method || typeof method !== 'string' ||
   59             !options || typeof options !== 'object') {
   60 
   61             result.err = 'Invalid argument type';
   62             return result;
   63         }
   64 
   65         // Application time
   66 
   67         const timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
   68 
   69         // Validate credentials
   70 
   71         const credentials = options.credentials;
   72         if (!credentials ||
   73             !credentials.id ||
   74             !credentials.key ||
   75             !credentials.algorithm) {
   76 
   77             result.err = 'Invalid credentials object';
   78             return result;
   79         }
   80 
   81         if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
   82             result.err = 'Unknown algorithm';
   83             return result;
   84         }
   85 
   86         // Parse URI
   87 
   88         if (typeof uri === 'string') {
   89             uri = hawk.utils.parseUri(uri);
   90         }
   91 
   92         // Calculate signature
   93 
   94         const artifacts = {
   95             ts: timestamp,
   96             nonce: options.nonce || hawk.utils.randomString(6),
   97             method,
   98             resource: uri.resource,
   99             host: uri.host,
  100             port: uri.port,
  101             hash: options.hash,
  102             ext: options.ext,
  103             app: options.app,
  104             dlg: options.dlg
  105         };
  106 
  107         result.artifacts = artifacts;
  108 
  109         // Calculate payload hash
  110 
  111         if (!artifacts.hash &&
  112             (options.payload || options.payload === '')) {
  113 
  114             artifacts.hash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
  115         }
  116 
  117         const mac = hawk.crypto.calculateMac('header', credentials, artifacts);
  118 
  119         // Construct header
  120 
  121         const hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== '';       // Other falsey values allowed
  122         let header = 'Hawk id="' + credentials.id +
  123                      '", ts="' + artifacts.ts +
  124                      '", nonce="' + artifacts.nonce +
  125                      (artifacts.hash ? '", hash="' + artifacts.hash : '') +
  126                      (hasExt ? '", ext="' + hawk.utils.escapeHeaderAttribute(artifacts.ext) : '') +
  127                      '", mac="' + mac + '"';
  128 
  129         if (artifacts.app) {
  130             header += ', app="' + artifacts.app +
  131                       (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
  132         }
  133 
  134         result.field = header;
  135 
  136         return result;
  137     },
  138 
  139     // Generate a bewit value for a given URI
  140 
  141     /*
  142         uri: 'http://example.com/resource?a=b'
  143         options: {
  144 
  145             // Required
  146 
  147             credentials: {
  148             id: 'dh37fgj492je',
  149             key: 'aoijedoaijsdlaksjdl',
  150             algorithm: 'sha256'                             // 'sha1', 'sha256'
  151             },
  152             ttlSec: 60 * 60,                                    // TTL in seconds
  153 
  154             // Optional
  155 
  156             ext: 'application-specific',                        // Application specific data sent via the ext attribute
  157             localtimeOffsetMsec: 400                            // Time offset to sync with server time
  158          };
  159     */
  160 
  161     bewit: function (uri, options) {
  162 
  163         // Validate inputs
  164 
  165         if (!uri ||
  166             (typeof uri !== 'string') ||
  167             !options ||
  168             typeof options !== 'object' ||
  169             !options.ttlSec) {
  170 
  171             return '';
  172         }
  173 
  174         options.ext = (options.ext === null || options.ext === undefined ? '' : options.ext);       // Zero is valid value
  175 
  176         // Application time
  177 
  178         const now = hawk.utils.nowSec(options.localtimeOffsetMsec);
  179 
  180         // Validate credentials
  181 
  182         const credentials = options.credentials;
  183         if (!credentials ||
  184             !credentials.id ||
  185             !credentials.key ||
  186             !credentials.algorithm) {
  187 
  188             return '';
  189         }
  190 
  191         if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  192             return '';
  193         }
  194 
  195         // Parse URI
  196 
  197         uri = hawk.utils.parseUri(uri);
  198 
  199         // Calculate signature
  200 
  201         const exp = now + options.ttlSec;
  202         const mac = hawk.crypto.calculateMac('bewit', credentials, {
  203             ts: exp,
  204             nonce: '',
  205             method: 'GET',
  206             resource: uri.resource,                            // Maintain trailing '?' and query params
  207             host: uri.host,
  208             port: uri.port,
  209             ext: options.ext
  210         });
  211 
  212         // Construct bewit: id\exp\mac\ext
  213 
  214         const bewit = credentials.id + '\\' + exp + '\\' + mac + '\\' + options.ext;
  215         return hawk.utils.base64urlEncode(bewit);
  216     },
  217 
  218     // Validate server response
  219 
  220     /*
  221         request:    object created via 'new XMLHttpRequest()' after response received or fetch API 'Response'
  222         artifacts:  object received from header().artifacts
  223         options: {
  224             payload:    optional payload received
  225             required:   specifies if a Server-Authorization header is required. Defaults to 'false'
  226         }
  227     */
  228 
  229     authenticate: function (request, credentials, artifacts, options) {
  230 
  231         options = options || {};
  232 
  233         const getHeader = function (name) {
  234 
  235             // Fetch API or plain headers
  236 
  237             if (request.headers) {
  238                 return (typeof request.headers.get === 'function' ? request.headers.get(name) : request.headers[name]);
  239             }
  240 
  241             // XMLHttpRequest
  242 
  243             return (request.getResponseHeader ? request.getResponseHeader(name) : request.getHeader(name));
  244         };
  245 
  246         const wwwAuthenticate = getHeader('www-authenticate');
  247         if (wwwAuthenticate) {
  248 
  249             // Parse HTTP WWW-Authenticate header
  250 
  251             const wwwAttributes = hawk.utils.parseAuthorizationHeader(wwwAuthenticate, ['ts', 'tsm', 'error']);
  252             if (!wwwAttributes) {
  253                 return false;
  254             }
  255 
  256             if (wwwAttributes.ts) {
  257                 const tsm = hawk.crypto.calculateTsMac(wwwAttributes.ts, credentials);
  258                 if (tsm !== wwwAttributes.tsm) {
  259                     return false;
  260                 }
  261 
  262                 hawk.utils.setNtpSecOffset(wwwAttributes.ts - Math.floor(Date.now() / 1000));      // Keep offset at 1 second precision
  263             }
  264         }
  265 
  266         // Parse HTTP Server-Authorization header
  267 
  268         const serverAuthorization = getHeader('server-authorization');
  269         if (!serverAuthorization &&
  270             !options.required) {
  271 
  272             return true;
  273         }
  274 
  275         const attributes = hawk.utils.parseAuthorizationHeader(serverAuthorization, ['mac', 'ext', 'hash']);
  276         if (!attributes) {
  277             return false;
  278         }
  279 
  280         const modArtifacts = {
  281             ts: artifacts.ts,
  282             nonce: artifacts.nonce,
  283             method: artifacts.method,
  284             resource: artifacts.resource,
  285             host: artifacts.host,
  286             port: artifacts.port,
  287             hash: attributes.hash,
  288             ext: attributes.ext,
  289             app: artifacts.app,
  290             dlg: artifacts.dlg
  291         };
  292 
  293         const mac = hawk.crypto.calculateMac('response', credentials, modArtifacts);
  294         if (mac !== attributes.mac) {
  295             return false;
  296         }
  297 
  298         if (!options.payload &&
  299             options.payload !== '') {
  300 
  301             return true;
  302         }
  303 
  304         if (!attributes.hash) {
  305             return false;
  306         }
  307 
  308         const calculatedHash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, getHeader('content-type'));
  309         return (calculatedHash === attributes.hash);
  310     },
  311 
  312     message: function (host, port, message, options) {
  313 
  314         // Validate inputs
  315 
  316         if (!host || typeof host !== 'string' ||
  317             !port || typeof port !== 'number' ||
  318             message === null || message === undefined || typeof message !== 'string' ||
  319             !options || typeof options !== 'object') {
  320 
  321             return null;
  322         }
  323 
  324         // Application time
  325 
  326         const timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
  327 
  328         // Validate credentials
  329 
  330         const credentials = options.credentials;
  331         if (!credentials ||
  332             !credentials.id ||
  333             !credentials.key ||
  334             !credentials.algorithm) {
  335 
  336             // Invalid credential object
  337             return null;
  338         }
  339 
  340         if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  341             return null;
  342         }
  343 
  344         // Calculate signature
  345 
  346         const artifacts = {
  347             ts: timestamp,
  348             nonce: options.nonce || hawk.utils.randomString(6),
  349             host,
  350             port,
  351             hash: hawk.crypto.calculatePayloadHash(message, credentials.algorithm)
  352         };
  353 
  354         // Construct authorization
  355 
  356         const result = {
  357             id: credentials.id,
  358             ts: artifacts.ts,
  359             nonce: artifacts.nonce,
  360             hash: artifacts.hash,
  361             mac: hawk.crypto.calculateMac('message', credentials, artifacts)
  362         };
  363 
  364         return result;
  365     },
  366 
  367     authenticateTimestamp: function (message, credentials, updateClock) {               // updateClock defaults to true
  368 
  369         const tsm = hawk.crypto.calculateTsMac(message.ts, credentials);
  370         if (tsm !== message.tsm) {
  371             return false;
  372         }
  373 
  374         if (updateClock !== false) {
  375             hawk.utils.setNtpSecOffset(message.ts - Math.floor(Date.now() / 1000));     // Keep offset at 1 second precision
  376         }
  377 
  378         return true;
  379     }
  380 };
  381 
  382 
  383 hawk.crypto = {
  384 
  385     headerVersion: '1',
  386 
  387     algorithms: ['sha1', 'sha256'],
  388 
  389     calculateMac: function (type, credentials, options) {
  390 
  391         const normalized = hawk.crypto.generateNormalizedString(type, options);
  392 
  393         const hmac = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()](normalized, credentials.key);
  394         return hmac.toString(CryptoJS.enc.Base64);
  395     },
  396 
  397     generateNormalizedString: function (type, options) {
  398 
  399         let normalized = 'hawk.' + hawk.crypto.headerVersion + '.' + type + '\n' +
  400                          options.ts + '\n' +
  401                          options.nonce + '\n' +
  402                          (options.method || '').toUpperCase() + '\n' +
  403                          (options.resource || '') + '\n' +
  404                          options.host.toLowerCase() + '\n' +
  405                          options.port + '\n' +
  406                          (options.hash || '') + '\n';
  407 
  408         if (options.ext) {
  409             normalized += options.ext.replace('\\', '\\\\').replace('\n', '\\n');
  410         }
  411 
  412         normalized += '\n';
  413 
  414         if (options.app) {
  415             normalized += options.app + '\n' +
  416                           (options.dlg || '') + '\n';
  417         }
  418 
  419         return normalized;
  420     },
  421 
  422     calculatePayloadHash: function (payload, algorithm, contentType) {
  423 
  424         const hash = CryptoJS.algo[algorithm.toUpperCase()].create();
  425         hash.update('hawk.' + hawk.crypto.headerVersion + '.payload\n');
  426         hash.update(hawk.utils.parseContentType(contentType) + '\n');
  427         hash.update(payload);
  428         hash.update('\n');
  429         return hash.finalize().toString(CryptoJS.enc.Base64);
  430     },
  431 
  432     calculateTsMac: function (ts, credentials) {
  433 
  434         const hash = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()]('hawk.' + hawk.crypto.headerVersion + '.ts\n' + ts + '\n', credentials.key);
  435         return hash.toString(CryptoJS.enc.Base64);
  436     }
  437 };
  438 
  439 
  440 // localStorage compatible interface
  441 
  442 hawk.internals.LocalStorage = function () {
  443 
  444     this._cache = {};
  445     this.length = 0;
  446 
  447     this.getItem = function (key) {
  448 
  449         return this._cache.hasOwnProperty(key) ? String(this._cache[key]) : null;
  450     };
  451 
  452     this.setItem = function (key, value) {
  453 
  454         this._cache[key] = String(value);
  455         this.length = Object.keys(this._cache).length;
  456     };
  457 
  458     this.removeItem = function (key) {
  459 
  460         delete this._cache[key];
  461         this.length = Object.keys(this._cache).length;
  462     };
  463 
  464     this.clear = function () {
  465 
  466         this._cache = {};
  467         this.length = 0;
  468     };
  469 
  470     this.key = function (i) {
  471 
  472         return Object.keys(this._cache)[i || 0];
  473     };
  474 };
  475 
  476 
  477 hawk.utils = {
  478 
  479     storage: new hawk.internals.LocalStorage(),
  480 
  481     setStorage: function (storage) {
  482 
  483         const ntpOffset = hawk.utils.storage.getItem('hawk_ntp_offset');
  484         hawk.utils.storage = storage;
  485         if (ntpOffset) {
  486             hawk.utils.setNtpSecOffset(ntpOffset);
  487         }
  488     },
  489 
  490     setNtpSecOffset: function (offset) {
  491 
  492         try {
  493             hawk.utils.storage.setItem('hawk_ntp_offset', offset);
  494         }
  495         catch (err) {
  496             console.error('[hawk] could not write to storage.');
  497             console.error(err);
  498         }
  499     },
  500 
  501     getNtpSecOffset: function () {
  502 
  503         const offset = hawk.utils.storage.getItem('hawk_ntp_offset');
  504         if (!offset) {
  505             return 0;
  506         }
  507 
  508         return parseInt(offset, 10);
  509     },
  510 
  511     now: function (localtimeOffsetMsec) {
  512 
  513         return Date.now() + (localtimeOffsetMsec || 0) + (hawk.utils.getNtpSecOffset() * 1000);
  514     },
  515 
  516     nowSec: function (localtimeOffsetMsec) {
  517 
  518         return Math.floor(hawk.utils.now(localtimeOffsetMsec) / 1000);
  519     },
  520 
  521     escapeHeaderAttribute: function (attribute) {
  522 
  523         return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
  524     },
  525 
  526     parseContentType: function (header) {
  527 
  528         if (!header) {
  529             return '';
  530         }
  531 
  532         return header.split(';')[0].replace(/^\s+|\s+$/g, '').toLowerCase();
  533     },
  534 
  535     parseAuthorizationHeader: function (header, keys) {
  536 
  537         if (!header) {
  538             return null;
  539         }
  540 
  541         const headerParts = header.match(/^(\w+)(?:\s+(.*))?$/);       // Header: scheme[ something]
  542         if (!headerParts) {
  543             return null;
  544         }
  545 
  546         const scheme = headerParts[1];
  547         if (scheme.toLowerCase() !== 'hawk') {
  548             return null;
  549         }
  550 
  551         const attributesString = headerParts[2];
  552         if (!attributesString) {
  553             return null;
  554         }
  555 
  556         const attributes = {};
  557         const verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, ($0, $1, $2) => {
  558 
  559             // Check valid attribute names
  560 
  561             if (keys.indexOf($1) === -1) {
  562                 return;
  563             }
  564 
  565             // Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
  566 
  567             if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
  568                 return;
  569             }
  570 
  571             // Check for duplicates
  572 
  573             if (attributes.hasOwnProperty($1)) {
  574                 return;
  575             }
  576 
  577             attributes[$1] = $2;
  578             return '';
  579         });
  580 
  581         if (verify !== '') {
  582             return null;
  583         }
  584 
  585         return attributes;
  586     },
  587 
  588     randomString: function (size) {
  589 
  590         const randomSource = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  591         const len = randomSource.length;
  592 
  593         const result = [];
  594         for (let i = 0; i < size; ++i) {
  595             result[i] = randomSource[Math.floor(Math.random() * len)];
  596         }
  597 
  598         return result.join('');
  599     },
  600 
  601     //          1                        2             3      4
  602     uriRegex: /^([^:]+)\:\/\/(?:[^@/]*@)?([^\/:]+)(?:\:(\d+))?([^#]*)(?:#.*)?$/,       // scheme://credentials@host:port/resource#fragment
  603     parseUri: function (input) {
  604 
  605         const parts = input.match(hawk.utils.uriRegex);
  606         if (!parts) {
  607             return { host: '', port: '', resource: '' };
  608         }
  609 
  610         const scheme = parts[1].toLowerCase();
  611         const uri = {
  612             host: parts[2],
  613             port: parts[3] || (scheme === 'http' ? '80' : (scheme === 'https' ? '443' : '')),
  614             resource: parts[4]
  615         };
  616 
  617         return uri;
  618     },
  619 
  620     base64urlEncode: function (value) {
  621 
  622         const wordArray = CryptoJS.enc.Utf8.parse(value);
  623         const encoded = CryptoJS.enc.Base64.stringify(wordArray);
  624         return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
  625     }
  626 };
  627 
  628 
  629 // $lab:coverage:off$
  630 /* eslint-disable */
  631 
  632 // Based on: Crypto-JS v3.1.2
  633 // Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
  634 // http://code.google.com/p/crypto-js/
  635 // http://code.google.com/p/crypto-js/wiki/License
  636 
  637 var CryptoJS = CryptoJS || function (h, r) { var k = {}, l = k.lib = {}, n = function () { }, f = l.Base = { extend: function (a) { n.prototype = this; var b = new n; a && b.mixIn(a); b.hasOwnProperty("init") || (b.init = function () { b.$super.init.apply(this, arguments) }); b.init.prototype = b; b.$super = this; return b }, create: function () { var a = this.extend(); a.init.apply(a, arguments); return a }, init: function () { }, mixIn: function (a) { for (let b in a) a.hasOwnProperty(b) && (this[b] = a[b]); a.hasOwnProperty("toString") && (this.toString = a.toString) }, clone: function () { return this.init.prototype.extend(this) } }, j = l.WordArray = f.extend({ init: function (a, b) { a = this.words = a || []; this.sigBytes = b != r ? b : 4 * a.length }, toString: function (a) { return (a || s).stringify(this) }, concat: function (a) { var b = this.words, d = a.words, c = this.sigBytes; a = a.sigBytes; this.clamp(); if (c % 4) for (let e = 0; e < a; e++) b[c + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((c + e) % 4); else if (65535 < d.length) for (let e = 0; e < a; e += 4) b[c + e >>> 2] = d[e >>> 2]; else b.push.apply(b, d); this.sigBytes += a; return this }, clamp: function () { var a = this.words, b = this.sigBytes; a[b >>> 2] &= 4294967295 << 32 - 8 * (b % 4); a.length = h.ceil(b / 4) }, clone: function () { var a = f.clone.call(this); a.words = this.words.slice(0); return a }, random: function (a) { for (let b = [], d = 0; d < a; d += 4) b.push(4294967296 * h.random() | 0); return new j.init(b, a) } }), m = k.enc = {}, s = m.Hex = { stringify: function (a) { var b = a.words; a = a.sigBytes; for (var d = [], c = 0; c < a; c++) { var e = b[c >>> 2] >>> 24 - 8 * (c % 4) & 255; d.push((e >>> 4).toString(16)); d.push((e & 15).toString(16)) } return d.join("") }, parse: function (a) { for (var b = a.length, d = [], c = 0; c < b; c += 2) d[c >>> 3] |= parseInt(a.substr(c, 2), 16) << 24 - 4 * (c % 8); return new j.init(d, b / 2) } }, p = m.Latin1 = { stringify: function (a) { var b = a.words; a = a.sigBytes; for (var d = [], c = 0; c < a; c++) d.push(String.fromCharCode(b[c >>> 2] >>> 24 - 8 * (c % 4) & 255)); return d.join("") }, parse: function (a) { for (var b = a.length, d = [], c = 0; c < b; c++) d[c >>> 2] |= (a.charCodeAt(c) & 255) << 24 - 8 * (c % 4); return new j.init(d, b) } }, t = m.Utf8 = { stringify: function (a) { try { return decodeURIComponent(escape(p.stringify(a))) } catch (b) { throw Error("Malformed UTF-8 data"); } }, parse: function (a) { return p.parse(unescape(encodeURIComponent(a))) } }, q = l.BufferedBlockAlgorithm = f.extend({ reset: function () { this._data = new j.init; this._nDataBytes = 0 }, _append: function (a) { "string" == typeof a && (a = t.parse(a)); this._data.concat(a); this._nDataBytes += a.sigBytes }, _process: function (a) { var b = this._data, d = b.words, c = b.sigBytes, e = this.blockSize, f = c / (4 * e), f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); a = f * e; c = h.min(4 * a, c); if (a) { for (var g = 0; g < a; g += e) this._doProcessBlock(d, g); g = d.splice(0, a); b.sigBytes -= c } return new j.init(g, c) }, clone: function () { var a = f.clone.call(this); a._data = this._data.clone(); return a }, _minBufferSize: 0 }); l.Hasher = q.extend({ cfg: f.extend(), init: function (a) { this.cfg = this.cfg.extend(a); this.reset() }, reset: function () { q.reset.call(this); this._doReset() }, update: function (a) { this._append(a); this._process(); return this }, finalize: function (a) { a && this._append(a); return this._doFinalize() }, blockSize: 16, _createHelper: function (a) { return function (b, d) { return (new a.init(d)).finalize(b) } }, _createHmacHelper: function (a) { return function (b, d) { return (new u.HMAC.init(a, d)).finalize(b) } } }); var u = k.algo = {}; return k }(Math);
  638 (() => { var k = CryptoJS, b = k.lib, m = b.WordArray, l = b.Hasher, d = [], b = k.algo.SHA1 = l.extend({ _doReset: function () { this._hash = new m.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (n, p) { for (var a = this._hash.words, e = a[0], f = a[1], h = a[2], j = a[3], b = a[4], c = 0; 80 > c; c++) { if (16 > c) d[c] = n[p + c] | 0; else { var g = d[c - 3] ^ d[c - 8] ^ d[c - 14] ^ d[c - 16]; d[c] = g << 1 | g >>> 31 } g = (e << 5 | e >>> 27) + b + d[c]; g = 20 > c ? g + ((f & h | ~f & j) + 1518500249) : 40 > c ? g + ((f ^ h ^ j) + 1859775393) : 60 > c ? g + ((f & h | f & j | h & j) - 1894007588) : g + ((f ^ h ^ j) - 899497514); b = j; j = h; h = f << 30 | f >>> 2; f = e; e = g } a[0] = a[0] + e | 0; a[1] = a[1] + f | 0; a[2] = a[2] + h | 0; a[3] = a[3] + j | 0; a[4] = a[4] + b | 0 }, _doFinalize: function () { var b = this._data, d = b.words, a = 8 * this._nDataBytes, e = 8 * b.sigBytes; d[e >>> 5] |= 128 << 24 - e % 32; d[(e + 64 >>> 9 << 4) + 14] = Math.floor(a / 4294967296); d[(e + 64 >>> 9 << 4) + 15] = a; b.sigBytes = 4 * d.length; this._process(); return this._hash }, clone: function () { var b = l.clone.call(this); b._hash = this._hash.clone(); return b } }); k.SHA1 = l._createHelper(b); k.HmacSHA1 = l._createHmacHelper(b) })();
  639 (function (k) { for (var g = CryptoJS, h = g.lib, v = h.WordArray, j = h.Hasher, h = g.algo, s = [], t = [], u = function (q) { return 4294967296 * (q - (q | 0)) | 0 }, l = 2, b = 0; 64 > b;) { var d; a: { d = l; for (var w = k.sqrt(d), r = 2; r <= w; r++) if (!(d % r)) { d = !1; break a } d = !0 } d && (8 > b && (s[b] = u(k.pow(l, 0.5))), t[b] = u(k.pow(l, 1 / 3)), b++); l++ } var n = [], h = h.SHA256 = j.extend({ _doReset: function () { this._hash = new v.init(s.slice(0)) }, _doProcessBlock: function (q, h) { for (var a = this._hash.words, c = a[0], d = a[1], b = a[2], k = a[3], f = a[4], g = a[5], j = a[6], l = a[7], e = 0; 64 > e; e++) { if (16 > e) n[e] = q[h + e] | 0; else { var m = n[e - 15], p = n[e - 2]; n[e] = ((m << 25 | m >>> 7) ^ (m << 14 | m >>> 18) ^ m >>> 3) + n[e - 7] + ((p << 15 | p >>> 17) ^ (p << 13 | p >>> 19) ^ p >>> 10) + n[e - 16] } m = l + ((f << 26 | f >>> 6) ^ (f << 21 | f >>> 11) ^ (f << 7 | f >>> 25)) + (f & g ^ ~f & j) + t[e] + n[e]; p = ((c << 30 | c >>> 2) ^ (c << 19 | c >>> 13) ^ (c << 10 | c >>> 22)) + (c & d ^ c & b ^ d & b); l = j; j = g; g = f; f = k + m | 0; k = b; b = d; d = c; c = m + p | 0 } a[0] = a[0] + c | 0; a[1] = a[1] + d | 0; a[2] = a[2] + b | 0; a[3] = a[3] + k | 0; a[4] = a[4] + f | 0; a[5] = a[5] + g | 0; a[6] = a[6] + j | 0; a[7] = a[7] + l | 0 }, _doFinalize: function () { var d = this._data, b = d.words, a = 8 * this._nDataBytes, c = 8 * d.sigBytes; b[c >>> 5] |= 128 << 24 - c % 32; b[(c + 64 >>> 9 << 4) + 14] = k.floor(a / 4294967296); b[(c + 64 >>> 9 << 4) + 15] = a; d.sigBytes = 4 * b.length; this._process(); return this._hash }, clone: function () { var b = j.clone.call(this); b._hash = this._hash.clone(); return b } }); g.SHA256 = j._createHelper(h); g.HmacSHA256 = j._createHmacHelper(h) })(Math);
  640 (() => { var c = CryptoJS, k = c.enc.Utf8; c.algo.HMAC = c.lib.Base.extend({ init: function (a, b) { a = this._hasher = new a.init; "string" == typeof b && (b = k.parse(b)); var c = a.blockSize, e = 4 * c; b.sigBytes > e && (b = a.finalize(b)); b.clamp(); for (var f = this._oKey = b.clone(), g = this._iKey = b.clone(), h = f.words, j = g.words, d = 0; d < c; d++) h[d] ^= 1549556828, j[d] ^= 909522486; f.sigBytes = g.sigBytes = e; this.reset() }, reset: function () { var a = this._hasher; a.reset(); a.update(this._iKey) }, update: function (a) { this._hasher.update(a); return this }, finalize: function (a) { var b = this._hasher; a = b.finalize(a); b.reset(); return b.finalize(this._oKey.clone().concat(a)) } }) })();
  641 (() => { var h = CryptoJS, j = h.lib.WordArray; h.enc.Base64 = { stringify: function (b) { var e = b.words, f = b.sigBytes, c = this._map; b.clamp(); b = []; for (var a = 0; a < f; a += 3) for (var d = (e[a >>> 2] >>> 24 - 8 * (a % 4) & 255) << 16 | (e[a + 1 >>> 2] >>> 24 - 8 * ((a + 1) % 4) & 255) << 8 | e[a + 2 >>> 2] >>> 24 - 8 * ((a + 2) % 4) & 255, g = 0; 4 > g && a + 0.75 * g < f; g++) b.push(c.charAt(d >>> 6 * (3 - g) & 63)); if (e = c.charAt(64)) for (; b.length % 4;) b.push(e); return b.join("") }, parse: function (b) { var e = b.length, f = this._map, c = f.charAt(64); c && (c = b.indexOf(c), -1 != c && (e = c)); for (var c = [], a = 0, d = 0; d < e; d++) if (d % 4) { var g = f.indexOf(b.charAt(d - 1)) << 2 * (d % 4), h = f.indexOf(b.charAt(d)) >>> 6 - 2 * (d % 4); c[a >>> 2] |= (g | h) << 24 - 8 * (a % 4); a++ } return j.create(c, a) }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" } })();
  642 
  643 
  644 hawk.crypto.utils = CryptoJS;
  645 
  646 // Export if used as a module
  647 
  648 if (typeof module !== 'undefined' && module.exports) {
  649     module.exports = hawk;
  650 }
  651 
  652 /* eslint-enable */
  653 // $lab:coverage:on$