@livechat/accounts-sdk 2.0.1 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('crypto')) :
3
- typeof define === 'function' && define.amd ? define(['crypto'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.AccountsSDK = factory(global.crypto));
5
- }(this, (function (require$$0) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.AccountsSDK = factory());
5
+ }(this, (function () { 'use strict';
10
6
 
11
7
  function _typeof(obj) {
12
8
  "@babel/helpers - typeof";
@@ -1006,13 +1002,17 @@
1006
1002
 
1007
1003
  return new Promise(function (resolve, reject) {
1008
1004
  var authorizeData = {};
1005
+ var requiredFields = [];
1009
1006
 
1010
1007
  switch (_this.options.response_type) {
1011
1008
  case 'token':
1009
+ requiredFields = ['access_token', 'expires_in', 'token_type'];
1012
1010
  authorizeData = lib.parse(window.location.hash.substring(1));
1013
1011
  authorizeData = pick(authorizeData, ['access_token', 'expires_in', 'state', 'scope', 'token_type']);
1014
1012
 
1015
- if (Object.keys(authorizeData).length != 5) {
1013
+ if (!requiredFields.every(function (field) {
1014
+ return authorizeData.hasOwnProperty(field);
1015
+ })) {
1016
1016
  reject(errors.extend({
1017
1017
  identity_exception: 'unauthorized'
1018
1018
  }));
@@ -1023,12 +1023,15 @@
1023
1023
  break;
1024
1024
 
1025
1025
  case 'code':
1026
+ requiredFields = ['code'];
1026
1027
  authorizeData = lib.parse(window.location.search, {
1027
1028
  ignoreQueryPrefix: true
1028
1029
  });
1029
1030
  authorizeData = pick(authorizeData, ['state', 'code']);
1030
1031
 
1031
- if (Object.keys(authorizeData).length < 2) {
1032
+ if (!requiredFields.every(function (field) {
1033
+ return authorizeData.hasOwnProperty(field);
1034
+ })) {
1032
1035
  reject(errors.extend({
1033
1036
  identity_exception: 'unauthorized'
1034
1037
  }));
@@ -1494,1281 +1497,671 @@
1494
1497
  return Transaction;
1495
1498
  }();
1496
1499
 
1497
- var sjcl_1 = createCommonjsModule(function (module) {
1498
-
1499
- var sjcl = {
1500
- cipher: {},
1501
- hash: {},
1502
- keyexchange: {},
1503
- mode: {},
1504
- misc: {},
1505
- codec: {},
1506
- exception: {
1507
- corrupt: function corrupt(a) {
1508
- this.toString = function () {
1509
- return "CORRUPT: " + this.message;
1510
- };
1511
-
1512
- this.message = a;
1513
- },
1514
- invalid: function invalid(a) {
1515
- this.toString = function () {
1516
- return "INVALID: " + this.message;
1517
- };
1500
+ /** @fileOverview Javascript cryptography implementation.
1501
+ *
1502
+ * Crush to remove comments, shorten variable names and
1503
+ * generally reduce transmission size.
1504
+ *
1505
+ * @author Emily Stark
1506
+ * @author Mike Hamburg
1507
+ * @author Dan Boneh
1508
+ */
1509
+ /*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
1518
1510
 
1519
- this.message = a;
1520
- },
1521
- bug: function bug(a) {
1522
- this.toString = function () {
1523
- return "BUG: " + this.message;
1524
- };
1511
+ /*global document, window, escape, unescape, module, require, Uint32Array */
1525
1512
 
1526
- this.message = a;
1527
- },
1528
- notReady: function notReady(a) {
1529
- this.toString = function () {
1530
- return "NOT READY: " + this.message;
1531
- };
1513
+ /**
1514
+ * The Stanford Javascript Crypto Library, top-level namespace.
1515
+ * @namespace
1516
+ */
1532
1517
 
1533
- this.message = a;
1534
- }
1535
- }
1536
- };
1518
+ var sjcl = {
1519
+ /**
1520
+ * Symmetric ciphers.
1521
+ * @namespace
1522
+ */
1523
+ cipher: {},
1537
1524
 
1538
- sjcl.cipher.aes = function (a) {
1539
- this.s[0][0][0] || this.O();
1540
- var b,
1541
- c,
1542
- d,
1543
- e,
1544
- f = this.s[0][4],
1545
- g = this.s[1];
1546
- b = a.length;
1547
- var h = 1;
1548
- if (4 !== b && 6 !== b && 8 !== b) throw new sjcl.exception.invalid("invalid aes key size");
1549
- this.b = [d = a.slice(0), e = []];
1525
+ /**
1526
+ * Hash functions. Right now only SHA256 is implemented.
1527
+ * @namespace
1528
+ */
1529
+ hash: {},
1550
1530
 
1551
- for (a = b; a < 4 * b + 28; a++) {
1552
- c = d[a - 1];
1553
- if (0 === a % b || 8 === b && 4 === a % b) c = f[c >>> 24] << 24 ^ f[c >> 16 & 255] << 16 ^ f[c >> 8 & 255] << 8 ^ f[c & 255], 0 === a % b && (c = c << 8 ^ c >>> 24 ^ h << 24, h = h << 1 ^ 283 * (h >> 7));
1554
- d[a] = d[a - b] ^ c;
1555
- }
1531
+ /**
1532
+ * Key exchange functions. Right now only SRP is implemented.
1533
+ * @namespace
1534
+ */
1535
+ keyexchange: {},
1556
1536
 
1557
- for (b = 0; a; b++, a--) {
1558
- c = d[b & 3 ? a : a - 4], e[b] = 4 >= a || 4 > b ? c : g[0][f[c >>> 24]] ^ g[1][f[c >> 16 & 255]] ^ g[2][f[c >> 8 & 255]] ^ g[3][f[c & 255]];
1559
- }
1560
- };
1537
+ /**
1538
+ * Cipher modes of operation.
1539
+ * @namespace
1540
+ */
1541
+ mode: {},
1561
1542
 
1562
- sjcl.cipher.aes.prototype = {
1563
- encrypt: function encrypt(a) {
1564
- return t(this, a, 0);
1565
- },
1566
- decrypt: function decrypt(a) {
1567
- return t(this, a, 1);
1568
- },
1569
- s: [[[], [], [], [], []], [[], [], [], [], []]],
1570
- O: function O() {
1571
- var a = this.s[0],
1572
- b = this.s[1],
1573
- c = a[4],
1574
- d = b[4],
1575
- e,
1576
- f,
1577
- g,
1578
- h = [],
1579
- k = [],
1580
- l,
1581
- n,
1582
- m,
1583
- p;
1584
-
1585
- for (e = 0; 0x100 > e; e++) {
1586
- k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e;
1587
- }
1543
+ /**
1544
+ * Miscellaneous. HMAC and PBKDF2.
1545
+ * @namespace
1546
+ */
1547
+ misc: {},
1588
1548
 
1589
- for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) {
1590
- for (m = g ^ g << 1 ^ g << 2 ^ g << 3 ^ g << 4, m = m >> 8 ^ m & 255 ^ 99, c[f] = m, d[m] = f, n = h[e = h[l = h[f]]], p = 0x1010101 * n ^ 0x10001 * e ^ 0x101 * l ^ 0x1010100 * f, n = 0x101 * h[m] ^ 0x1010100 * m, e = 0; 4 > e; e++) {
1591
- a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8;
1592
- }
1593
- }
1549
+ /**
1550
+ * Bit array encoders and decoders.
1551
+ * @namespace
1552
+ *
1553
+ * @description
1554
+ * The members of this namespace are functions which translate between
1555
+ * SJCL's bitArrays and other objects (usually strings). Because it
1556
+ * isn't always clear which direction is encoding and which is decoding,
1557
+ * the method names are "fromBits" and "toBits".
1558
+ */
1559
+ codec: {},
1594
1560
 
1595
- for (e = 0; 5 > e; e++) {
1596
- a[e] = a[e].slice(0), b[e] = b[e].slice(0);
1597
- }
1598
- }
1599
- };
1561
+ /**
1562
+ * Exceptions.
1563
+ * @namespace
1564
+ */
1565
+ exception: {
1566
+ /**
1567
+ * Ciphertext is corrupt.
1568
+ * @constructor
1569
+ */
1570
+ corrupt: function corrupt(message) {
1571
+ this.toString = function () {
1572
+ return 'CORRUPT: ' + this.message;
1573
+ };
1600
1574
 
1601
- function t(a, b, c) {
1602
- if (4 !== b.length) throw new sjcl.exception.invalid("invalid aes block size");
1603
- var d = a.b[c],
1604
- e = b[0] ^ d[0],
1605
- f = b[c ? 3 : 1] ^ d[1],
1606
- g = b[2] ^ d[2];
1607
- b = b[c ? 1 : 3] ^ d[3];
1608
- var h,
1609
- k,
1610
- l,
1611
- n = d.length / 4 - 2,
1612
- m,
1613
- p = 4,
1614
- r = [0, 0, 0, 0];
1615
- h = a.s[c];
1616
- a = h[0];
1617
- var q = h[1],
1618
- v = h[2],
1619
- w = h[3],
1620
- x = h[4];
1621
-
1622
- for (m = 0; m < n; m++) {
1623
- h = a[e >>> 24] ^ q[f >> 16 & 255] ^ v[g >> 8 & 255] ^ w[b & 255] ^ d[p], k = a[f >>> 24] ^ q[g >> 16 & 255] ^ v[b >> 8 & 255] ^ w[e & 255] ^ d[p + 1], l = a[g >>> 24] ^ q[b >> 16 & 255] ^ v[e >> 8 & 255] ^ w[f & 255] ^ d[p + 2], b = a[b >>> 24] ^ q[e >> 16 & 255] ^ v[f >> 8 & 255] ^ w[g & 255] ^ d[p + 3], p += 4, e = h, f = k, g = l;
1624
- }
1625
-
1626
- for (m = 0; 4 > m; m++) {
1627
- r[c ? 3 & -m : m] = x[e >>> 24] << 24 ^ x[f >> 16 & 255] << 16 ^ x[g >> 8 & 255] << 8 ^ x[b & 255] ^ d[p++], h = e, e = f, f = g, g = b, b = h;
1628
- }
1629
-
1630
- return r;
1631
- }
1632
-
1633
- sjcl.bitArray = {
1634
- bitSlice: function bitSlice(a, b, c) {
1635
- a = sjcl.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1);
1636
- return void 0 === c ? a : sjcl.bitArray.clamp(a, c - b);
1637
- },
1638
- extract: function extract(a, b, c) {
1639
- var d = Math.floor(-b - c & 31);
1640
- return ((b + c - 1 ^ b) & -32 ? a[b / 32 | 0] << 32 - d ^ a[b / 32 + 1 | 0] >>> d : a[b / 32 | 0] >>> d) & (1 << c) - 1;
1575
+ this.message = message;
1641
1576
  },
1642
- concat: function concat(a, b) {
1643
- if (0 === a.length || 0 === b.length) return a.concat(b);
1644
- var c = a[a.length - 1],
1645
- d = sjcl.bitArray.getPartial(c);
1646
- return 32 === d ? a.concat(b) : sjcl.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1));
1647
- },
1648
- bitLength: function bitLength(a) {
1649
- var b = a.length;
1650
- return 0 === b ? 0 : 32 * (b - 1) + sjcl.bitArray.getPartial(a[b - 1]);
1651
- },
1652
- clamp: function clamp(a, b) {
1653
- if (32 * a.length < b) return a;
1654
- a = a.slice(0, Math.ceil(b / 32));
1655
- var c = a.length;
1656
- b = b & 31;
1657
- 0 < c && b && (a[c - 1] = sjcl.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1));
1658
- return a;
1659
- },
1660
- partial: function partial(a, b, c) {
1661
- return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 0x10000000000 * a;
1662
- },
1663
- getPartial: function getPartial(a) {
1664
- return Math.round(a / 0x10000000000) || 32;
1665
- },
1666
- equal: function equal(a, b) {
1667
- if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) return !1;
1668
- var c = 0,
1669
- d;
1670
1577
 
1671
- for (d = 0; d < a.length; d++) {
1672
- c |= a[d] ^ b[d];
1673
- }
1578
+ /**
1579
+ * Invalid parameter.
1580
+ * @constructor
1581
+ */
1582
+ invalid: function invalid(message) {
1583
+ this.toString = function () {
1584
+ return 'INVALID: ' + this.message;
1585
+ };
1674
1586
 
1675
- return 0 === c;
1587
+ this.message = message;
1676
1588
  },
1677
- $: function $(a, b, c, d) {
1678
- var e;
1679
- e = 0;
1680
-
1681
- for (void 0 === d && (d = []); 32 <= b; b -= 32) {
1682
- d.push(c), c = 0;
1683
- }
1684
-
1685
- if (0 === b) return d.concat(a);
1686
1589
 
1687
- for (e = 0; e < a.length; e++) {
1688
- d.push(c | a[e] >>> b), c = a[e] << 32 - b;
1689
- }
1590
+ /**
1591
+ * Bug or missing feature in SJCL.
1592
+ * @constructor
1593
+ */
1594
+ bug: function bug(message) {
1595
+ this.toString = function () {
1596
+ return 'BUG: ' + this.message;
1597
+ };
1690
1598
 
1691
- e = a.length ? a[a.length - 1] : 0;
1692
- a = sjcl.bitArray.getPartial(e);
1693
- d.push(sjcl.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1));
1694
- return d;
1599
+ this.message = message;
1695
1600
  },
1696
- i: function i(a, b) {
1697
- return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]];
1698
- },
1699
- byteswapM: function byteswapM(a) {
1700
- var b, c;
1701
1601
 
1702
- for (b = 0; b < a.length; ++b) {
1703
- c = a[b], a[b] = c >>> 24 | c >>> 8 & 0xff00 | (c & 0xff00) << 8 | c << 24;
1704
- }
1705
-
1706
- return a;
1707
- }
1708
- };
1709
- sjcl.codec.utf8String = {
1710
- fromBits: function fromBits(a) {
1711
- var b = "",
1712
- c = sjcl.bitArray.bitLength(a),
1713
- d,
1714
- e;
1715
-
1716
- for (d = 0; d < c / 8; d++) {
1717
- 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8;
1718
- }
1719
-
1720
- return decodeURIComponent(escape(b));
1721
- },
1722
- toBits: function toBits(a) {
1723
- a = unescape(encodeURIComponent(a));
1724
- var b = [],
1725
- c,
1726
- d = 0;
1727
-
1728
- for (c = 0; c < a.length; c++) {
1729
- d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0);
1730
- }
1602
+ /**
1603
+ * Something isn't ready.
1604
+ * @constructor
1605
+ */
1606
+ notReady: function notReady(message) {
1607
+ this.toString = function () {
1608
+ return 'NOT READY: ' + this.message;
1609
+ };
1731
1610
 
1732
- c & 3 && b.push(sjcl.bitArray.partial(8 * (c & 3), d));
1733
- return b;
1611
+ this.message = message;
1734
1612
  }
1735
- };
1736
- sjcl.codec.hex = {
1737
- fromBits: function fromBits(a) {
1738
- var b = "",
1739
- c;
1613
+ }
1614
+ };
1615
+ /** @fileOverview Arrays of bits, encoded as arrays of Numbers.
1616
+ *
1617
+ * @author Emily Stark
1618
+ * @author Mike Hamburg
1619
+ * @author Dan Boneh
1620
+ */
1740
1621
 
1741
- for (c = 0; c < a.length; c++) {
1742
- b += ((a[c] | 0) + 0xf00000000000).toString(16).substr(4);
1743
- }
1622
+ /**
1623
+ * Arrays of bits, encoded as arrays of Numbers.
1624
+ * @namespace
1625
+ * @description
1626
+ * <p>
1627
+ * These objects are the currency accepted by SJCL's crypto functions.
1628
+ * </p>
1629
+ *
1630
+ * <p>
1631
+ * Most of our crypto primitives operate on arrays of 4-byte words internally,
1632
+ * but many of them can take arguments that are not a multiple of 4 bytes.
1633
+ * This library encodes arrays of bits (whose size need not be a multiple of 8
1634
+ * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
1635
+ * array of words, 32 bits at a time. Since the words are double-precision
1636
+ * floating point numbers, they fit some extra data. We use this (in a private,
1637
+ * possibly-changing manner) to encode the number of bits actually present
1638
+ * in the last word of the array.
1639
+ * </p>
1640
+ *
1641
+ * <p>
1642
+ * Because bitwise ops clear this out-of-band data, these arrays can be passed
1643
+ * to ciphers like AES which want arrays of words.
1644
+ * </p>
1645
+ */
1744
1646
 
1745
- return b.substr(0, sjcl.bitArray.bitLength(a) / 4);
1746
- },
1747
- toBits: function toBits(a) {
1748
- var b,
1749
- c = [],
1750
- d;
1751
- a = a.replace(/\s|0x/g, "");
1752
- d = a.length;
1753
- a = a + "00000000";
1754
-
1755
- for (b = 0; b < a.length; b += 8) {
1756
- c.push(parseInt(a.substr(b, 8), 16) ^ 0);
1757
- }
1647
+ sjcl.bitArray = {
1648
+ /**
1649
+ * Array slices in units of bits.
1650
+ * @param {bitArray} a The array to slice.
1651
+ * @param {Number} bstart The offset to the start of the slice, in bits.
1652
+ * @param {Number} bend The offset to the end of the slice, in bits. If this is undefined,
1653
+ * slice until the end of the array.
1654
+ * @return {bitArray} The requested slice.
1655
+ */
1656
+ bitSlice: function bitSlice(a, bstart, bend) {
1657
+ a = sjcl.bitArray._shiftRight(a.slice(bstart / 32), 32 - (bstart & 31)).slice(1);
1658
+ return bend === undefined ? a : sjcl.bitArray.clamp(a, bend - bstart);
1659
+ },
1758
1660
 
1759
- return sjcl.bitArray.clamp(c, 4 * d);
1661
+ /**
1662
+ * Extract a number packed into a bit array.
1663
+ * @param {bitArray} a The array to slice.
1664
+ * @param {Number} bstart The offset to the start of the slice, in bits.
1665
+ * @param {Number} blength The length of the number to extract.
1666
+ * @return {Number} The requested slice.
1667
+ */
1668
+ extract: function extract(a, bstart, blength) {
1669
+ // FIXME: this Math.floor is not necessary at all, but for some reason
1670
+ // seems to suppress a bug in the Chromium JIT.
1671
+ var x,
1672
+ sh = Math.floor(-bstart - blength & 31);
1673
+
1674
+ if ((bstart + blength - 1 ^ bstart) & -32) {
1675
+ // it crosses a boundary
1676
+ x = a[bstart / 32 | 0] << 32 - sh ^ a[bstart / 32 + 1 | 0] >>> sh;
1677
+ } else {
1678
+ // within a single word
1679
+ x = a[bstart / 32 | 0] >>> sh;
1760
1680
  }
1761
- };
1762
- sjcl.codec.base32 = {
1763
- B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
1764
- X: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
1765
- BITS: 32,
1766
- BASE: 5,
1767
- REMAINING: 27,
1768
- fromBits: function fromBits(a, b, c) {
1769
- var d = sjcl.codec.base32.BASE,
1770
- e = sjcl.codec.base32.REMAINING,
1771
- f = "",
1772
- g = 0,
1773
- h = sjcl.codec.base32.B,
1774
- k = 0,
1775
- l = sjcl.bitArray.bitLength(a);
1776
- c && (h = sjcl.codec.base32.X);
1777
-
1778
- for (c = 0; f.length * d < l;) {
1779
- f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d);
1780
- }
1781
-
1782
- for (; f.length & 7 && !b;) {
1783
- f += "=";
1784
- }
1785
-
1786
- return f;
1787
- },
1788
- toBits: function toBits(a, b) {
1789
- a = a.replace(/\s|=/g, "").toUpperCase();
1790
- var c = sjcl.codec.base32.BITS,
1791
- d = sjcl.codec.base32.BASE,
1792
- e = sjcl.codec.base32.REMAINING,
1793
- f = [],
1794
- g,
1795
- h = 0,
1796
- k = sjcl.codec.base32.B,
1797
- l = 0,
1798
- n,
1799
- m = "base32";
1800
- b && (k = sjcl.codec.base32.X, m = "base32hex");
1801
-
1802
- for (g = 0; g < a.length; g++) {
1803
- n = k.indexOf(a.charAt(g));
1804
-
1805
- if (0 > n) {
1806
- if (!b) try {
1807
- return sjcl.codec.base32hex.toBits(a);
1808
- } catch (p) {}
1809
- throw new sjcl.exception.invalid("this isn't " + m + "!");
1810
- }
1811
1681
 
1812
- h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h);
1813
- }
1682
+ return x & (1 << blength) - 1;
1683
+ },
1814
1684
 
1815
- h & 56 && f.push(sjcl.bitArray.partial(h & 56, l, 1));
1816
- return f;
1817
- }
1818
- };
1819
- sjcl.codec.base32hex = {
1820
- fromBits: function fromBits(a, b) {
1821
- return sjcl.codec.base32.fromBits(a, b, 1);
1822
- },
1823
- toBits: function toBits(a) {
1824
- return sjcl.codec.base32.toBits(a, 1);
1685
+ /**
1686
+ * Concatenate two bit arrays.
1687
+ * @param {bitArray} a1 The first array.
1688
+ * @param {bitArray} a2 The second array.
1689
+ * @return {bitArray} The concatenation of a1 and a2.
1690
+ */
1691
+ concat: function concat(a1, a2) {
1692
+ if (a1.length === 0 || a2.length === 0) {
1693
+ return a1.concat(a2);
1825
1694
  }
1826
- };
1827
- sjcl.codec.base64 = {
1828
- B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
1829
- fromBits: function fromBits(a, b, c) {
1830
- var d = "",
1831
- e = 0,
1832
- f = sjcl.codec.base64.B,
1833
- g = 0,
1834
- h = sjcl.bitArray.bitLength(a);
1835
- c && (f = f.substr(0, 62) + "-_");
1836
-
1837
- for (c = 0; 6 * d.length < h;) {
1838
- d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6);
1839
- }
1840
1695
 
1841
- for (; d.length & 3 && !b;) {
1842
- d += "=";
1843
- }
1696
+ var last = a1[a1.length - 1],
1697
+ shift = sjcl.bitArray.getPartial(last);
1844
1698
 
1845
- return d;
1846
- },
1847
- toBits: function toBits(a, b) {
1848
- a = a.replace(/\s|=/g, "");
1849
- var c = [],
1850
- d,
1851
- e = 0,
1852
- f = sjcl.codec.base64.B,
1853
- g = 0,
1854
- h;
1855
- b && (f = f.substr(0, 62) + "-_");
1856
-
1857
- for (d = 0; d < a.length; d++) {
1858
- h = f.indexOf(a.charAt(d));
1859
- if (0 > h) throw new sjcl.exception.invalid("this isn't base64!");
1860
- 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e);
1861
- }
1862
-
1863
- e & 56 && c.push(sjcl.bitArray.partial(e & 56, g, 1));
1864
- return c;
1865
- }
1866
- };
1867
- sjcl.codec.base64url = {
1868
- fromBits: function fromBits(a) {
1869
- return sjcl.codec.base64.fromBits(a, 1, 1);
1870
- },
1871
- toBits: function toBits(a) {
1872
- return sjcl.codec.base64.toBits(a, 1);
1699
+ if (shift === 32) {
1700
+ return a1.concat(a2);
1701
+ } else {
1702
+ return sjcl.bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
1873
1703
  }
1874
- };
1875
-
1876
- sjcl.hash.sha256 = function (a) {
1877
- this.b[0] || this.O();
1878
- a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset();
1879
- };
1880
-
1881
- sjcl.hash.sha256.hash = function (a) {
1882
- return new sjcl.hash.sha256().update(a).finalize();
1883
- };
1884
-
1885
- sjcl.hash.sha256.prototype = {
1886
- blockSize: 512,
1887
- reset: function reset() {
1888
- this.F = this.Y.slice(0);
1889
- this.A = [];
1890
- this.l = 0;
1891
- return this;
1892
- },
1893
- update: function update(a) {
1894
- "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a));
1895
- var b,
1896
- c = this.A = sjcl.bitArray.concat(this.A, a);
1897
- b = this.l;
1898
- a = this.l = b + sjcl.bitArray.bitLength(a);
1899
- if (0x1fffffffffffff < a) throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
1900
-
1901
- if ("undefined" !== typeof Uint32Array) {
1902
- var d = new Uint32Array(c),
1903
- e = 0;
1904
-
1905
- for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) {
1906
- u(this, d.subarray(16 * e, 16 * (e + 1))), e += 1;
1907
- }
1908
-
1909
- c.splice(0, 16 * e);
1910
- } else for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) {
1911
- u(this, c.splice(0, 16));
1912
- }
1913
-
1914
- return this;
1915
- },
1916
- finalize: function finalize() {
1917
- var a,
1918
- b = this.A,
1919
- c = this.F,
1920
- b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]);
1921
-
1922
- for (a = b.length + 2; a & 15; a++) {
1923
- b.push(0);
1924
- }
1925
-
1926
- b.push(Math.floor(this.l / 0x100000000));
1927
-
1928
- for (b.push(this.l | 0); b.length;) {
1929
- u(this, b.splice(0, 16));
1930
- }
1704
+ },
1931
1705
 
1932
- this.reset();
1933
- return c;
1934
- },
1935
- Y: [],
1936
- b: [],
1937
- O: function O() {
1938
- function a(a) {
1939
- return 0x100000000 * (a - Math.floor(a)) | 0;
1940
- }
1706
+ /**
1707
+ * Find the length of an array of bits.
1708
+ * @param {bitArray} a The array.
1709
+ * @return {Number} The length of a, in bits.
1710
+ */
1711
+ bitLength: function bitLength(a) {
1712
+ var l = a.length,
1713
+ x;
1941
1714
 
1942
- for (var b = 0, c = 2, d, e; 64 > b; c++) {
1943
- e = !0;
1715
+ if (l === 0) {
1716
+ return 0;
1717
+ }
1944
1718
 
1945
- for (d = 2; d * d <= c; d++) {
1946
- if (0 === c % d) {
1947
- e = !1;
1948
- break;
1949
- }
1950
- }
1719
+ x = a[l - 1];
1720
+ return (l - 1) * 32 + sjcl.bitArray.getPartial(x);
1721
+ },
1951
1722
 
1952
- e && (8 > b && (this.Y[b] = a(Math.pow(c, .5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++);
1953
- }
1723
+ /**
1724
+ * Truncate an array.
1725
+ * @param {bitArray} a The array.
1726
+ * @param {Number} len The length to truncate to, in bits.
1727
+ * @return {bitArray} A new array, truncated to len bits.
1728
+ */
1729
+ clamp: function clamp(a, len) {
1730
+ if (a.length * 32 < len) {
1731
+ return a;
1954
1732
  }
1955
- };
1956
1733
 
1957
- function u(a, b) {
1958
- var c,
1959
- d,
1960
- e,
1961
- f = a.F,
1962
- g = a.b,
1963
- h = f[0],
1964
- k = f[1],
1965
- l = f[2],
1966
- n = f[3],
1967
- m = f[4],
1968
- p = f[5],
1969
- r = f[6],
1970
- q = f[7];
1971
-
1972
- for (c = 0; 64 > c; c++) {
1973
- 16 > c ? d = b[c] : (d = b[c + 1 & 15], e = b[c + 14 & 15], d = b[c & 15] = (d >>> 7 ^ d >>> 18 ^ d >>> 3 ^ d << 25 ^ d << 14) + (e >>> 17 ^ e >>> 19 ^ e >>> 10 ^ e << 15 ^ e << 13) + b[c & 15] + b[c + 9 & 15] | 0), d = d + q + (m >>> 6 ^ m >>> 11 ^ m >>> 25 ^ m << 26 ^ m << 21 ^ m << 7) + (r ^ m & (p ^ r)) + g[c], q = r, r = p, p = m, m = n + d | 0, n = l, l = k, k = h, h = d + (k & l ^ n & (k ^ l)) + (k >>> 2 ^ k >>> 13 ^ k >>> 22 ^ k << 30 ^ k << 19 ^ k << 10) | 0;
1974
- }
1975
-
1976
- f[0] = f[0] + h | 0;
1977
- f[1] = f[1] + k | 0;
1978
- f[2] = f[2] + l | 0;
1979
- f[3] = f[3] + n | 0;
1980
- f[4] = f[4] + m | 0;
1981
- f[5] = f[5] + p | 0;
1982
- f[6] = f[6] + r | 0;
1983
- f[7] = f[7] + q | 0;
1984
- }
1985
-
1986
- sjcl.mode.ccm = {
1987
- name: "ccm",
1988
- G: [],
1989
- listenProgress: function listenProgress(a) {
1990
- sjcl.mode.ccm.G.push(a);
1991
- },
1992
- unListenProgress: function unListenProgress(a) {
1993
- a = sjcl.mode.ccm.G.indexOf(a);
1994
- -1 < a && sjcl.mode.ccm.G.splice(a, 1);
1995
- },
1996
- fa: function fa(a) {
1997
- var b = sjcl.mode.ccm.G.slice(),
1998
- c;
1734
+ a = a.slice(0, Math.ceil(len / 32));
1735
+ var l = a.length;
1736
+ len = len & 31;
1999
1737
 
2000
- for (c = 0; c < b.length; c += 1) {
2001
- b[c](a);
2002
- }
2003
- },
2004
- encrypt: function encrypt(a, b, c, d, e) {
2005
- var f,
2006
- g = b.slice(0),
2007
- h = sjcl.bitArray,
2008
- k = h.bitLength(c) / 8,
2009
- l = h.bitLength(g) / 8;
2010
- e = e || 64;
2011
- d = d || [];
2012
- if (7 > k) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");
2013
-
2014
- for (f = 2; 4 > f && l >>> 8 * f; f++) {
2015
- }
1738
+ if (l > 0 && len) {
1739
+ a[l - 1] = sjcl.bitArray.partial(len, a[l - 1] & 0x80000000 >> len - 1, 1);
1740
+ }
2016
1741
 
2017
- f < 15 - k && (f = 15 - k);
2018
- c = h.clamp(c, 8 * (15 - f));
2019
- b = sjcl.mode.ccm.V(a, b, c, d, e, f);
2020
- g = sjcl.mode.ccm.C(a, g, c, b, e, f);
2021
- return h.concat(g.data, g.tag);
2022
- },
2023
- decrypt: function decrypt(a, b, c, d, e) {
2024
- e = e || 64;
2025
- d = d || [];
2026
- var f = sjcl.bitArray,
2027
- g = f.bitLength(c) / 8,
2028
- h = f.bitLength(b),
2029
- k = f.clamp(b, h - e),
2030
- l = f.bitSlice(b, h - e),
2031
- h = (h - e) / 8;
2032
- if (7 > g) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");
2033
-
2034
- for (b = 2; 4 > b && h >>> 8 * b; b++) {
2035
- }
1742
+ return a;
1743
+ },
2036
1744
 
2037
- b < 15 - g && (b = 15 - g);
2038
- c = f.clamp(c, 8 * (15 - b));
2039
- k = sjcl.mode.ccm.C(a, k, c, l, e, b);
2040
- a = sjcl.mode.ccm.V(a, k.data, c, d, e, b);
2041
- if (!f.equal(k.tag, a)) throw new sjcl.exception.corrupt("ccm: tag doesn't match");
2042
- return k.data;
2043
- },
2044
- na: function na(a, b, c, d, e, f) {
2045
- var g = [],
2046
- h = sjcl.bitArray,
2047
- k = h.i;
2048
- d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)];
2049
- d = h.concat(d, c);
2050
- d[3] |= e;
2051
- d = a.encrypt(d);
2052
- if (b.length) for (c = h.bitLength(b) / 8, 65279 >= c ? g = [h.partial(16, c)] : 0xffffffff >= c && (g = h.concat([h.partial(16, 65534)], [c])), g = h.concat(g, b), b = 0; b < g.length; b += 4) {
2053
- d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0])));
2054
- }
2055
- return d;
2056
- },
2057
- V: function V(a, b, c, d, e, f) {
2058
- var g = sjcl.bitArray,
2059
- h = g.i;
2060
- e /= 8;
2061
- if (e % 2 || 4 > e || 16 < e) throw new sjcl.exception.invalid("ccm: invalid tag length");
2062
- if (0xffffffff < d.length || 0xffffffff < b.length) throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");
2063
- c = sjcl.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f);
2064
-
2065
- for (d = 0; d < b.length; d += 4) {
2066
- c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0])));
2067
- }
1745
+ /**
1746
+ * Make a partial word for a bit array.
1747
+ * @param {Number} len The number of bits in the word.
1748
+ * @param {Number} x The bits.
1749
+ * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
1750
+ * @return {Number} The partial word.
1751
+ */
1752
+ partial: function partial(len, x, _end) {
1753
+ if (len === 32) {
1754
+ return x;
1755
+ }
2068
1756
 
2069
- return g.clamp(c, 8 * e);
2070
- },
2071
- C: function C(a, b, c, d, e, f) {
2072
- var g,
2073
- h = sjcl.bitArray;
2074
- g = h.i;
2075
- var k = b.length,
2076
- l = h.bitLength(b),
2077
- n = k / 50,
2078
- m = n;
2079
- c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4);
2080
- d = h.bitSlice(g(d, a.encrypt(c)), 0, e);
2081
- if (!k) return {
2082
- tag: d,
2083
- data: []
2084
- };
1757
+ return (_end ? x | 0 : x << 32 - len) + len * 0x10000000000;
1758
+ },
2085
1759
 
2086
- for (g = 0; g < k; g += 4) {
2087
- g > n && (sjcl.mode.ccm.fa(g / k), n += m), c[3]++, e = a.encrypt(c), b[g] ^= e[0], b[g + 1] ^= e[1], b[g + 2] ^= e[2], b[g + 3] ^= e[3];
2088
- }
1760
+ /**
1761
+ * Get the number of bits used by a partial word.
1762
+ * @param {Number} x The partial word.
1763
+ * @return {Number} The number of bits used by the partial word.
1764
+ */
1765
+ getPartial: function getPartial(x) {
1766
+ return Math.round(x / 0x10000000000) || 32;
1767
+ },
2089
1768
 
2090
- return {
2091
- tag: d,
2092
- data: h.clamp(b, l)
2093
- };
1769
+ /**
1770
+ * Compare two arrays for equality in a predictable amount of time.
1771
+ * @param {bitArray} a The first array.
1772
+ * @param {bitArray} b The second array.
1773
+ * @return {boolean} true if a == b; false otherwise.
1774
+ */
1775
+ equal: function equal(a, b) {
1776
+ if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) {
1777
+ return false;
2094
1778
  }
2095
- };
2096
- sjcl.mode.ocb2 = {
2097
- name: "ocb2",
2098
- encrypt: function encrypt(a, b, c, d, e, f) {
2099
- if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits");
2100
- var g,
2101
- h = sjcl.mode.ocb2.S,
2102
- k = sjcl.bitArray,
2103
- l = k.i,
2104
- n = [0, 0, 0, 0];
2105
- c = h(a.encrypt(c));
2106
- var m,
2107
- p = [];
2108
- d = d || [];
2109
- e = e || 64;
2110
-
2111
- for (g = 0; g + 4 < b.length; g += 4) {
2112
- m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c);
2113
- }
2114
1779
 
2115
- m = b.slice(g);
2116
- b = k.bitLength(m);
2117
- g = a.encrypt(l(c, [0, 0, 0, b]));
2118
- m = k.clamp(l(m.concat([0, 0, 0]), g), b);
2119
- n = l(n, l(m.concat([0, 0, 0]), g));
2120
- n = a.encrypt(l(n, l(c, h(c))));
2121
- d.length && (n = l(n, f ? d : sjcl.mode.ocb2.pmac(a, d)));
2122
- return p.concat(k.concat(m, k.clamp(n, e)));
2123
- },
2124
- decrypt: function decrypt(a, b, c, d, e, f) {
2125
- if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits");
2126
- e = e || 64;
2127
- var g = sjcl.mode.ocb2.S,
2128
- h = sjcl.bitArray,
2129
- k = h.i,
2130
- l = [0, 0, 0, 0],
2131
- n = g(a.encrypt(c)),
2132
- m,
2133
- p,
2134
- r = sjcl.bitArray.bitLength(b) - e,
2135
- q = [];
2136
- d = d || [];
2137
-
2138
- for (c = 0; c + 4 < r / 32; c += 4) {
2139
- m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n);
2140
- }
1780
+ var x = 0,
1781
+ i;
2141
1782
 
2142
- p = r - 32 * c;
2143
- m = a.encrypt(k(n, [0, 0, 0, p]));
2144
- m = k(m, h.clamp(b.slice(c), p).concat([0, 0, 0]));
2145
- l = k(l, m);
2146
- l = a.encrypt(k(l, k(n, g(n))));
2147
- d.length && (l = k(l, f ? d : sjcl.mode.ocb2.pmac(a, d)));
2148
- if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl.exception.corrupt("ocb: tag doesn't match");
2149
- return q.concat(h.clamp(m, p));
2150
- },
2151
- pmac: function pmac(a, b) {
2152
- var c,
2153
- d = sjcl.mode.ocb2.S,
2154
- e = sjcl.bitArray,
2155
- f = e.i,
2156
- g = [0, 0, 0, 0],
2157
- h = a.encrypt([0, 0, 0, 0]),
2158
- h = f(h, d(d(h)));
2159
-
2160
- for (c = 0; c + 4 < b.length; c += 4) {
2161
- h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4))));
2162
- }
2163
-
2164
- c = b.slice(c);
2165
- 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0]));
2166
- g = f(g, c);
2167
- return a.encrypt(f(d(f(h, d(h))), g));
2168
- },
2169
- S: function S(a) {
2170
- return [a[0] << 1 ^ a[1] >>> 31, a[1] << 1 ^ a[2] >>> 31, a[2] << 1 ^ a[3] >>> 31, a[3] << 1 ^ 135 * (a[0] >>> 31)];
1783
+ for (i = 0; i < a.length; i++) {
1784
+ x |= a[i] ^ b[i];
2171
1785
  }
2172
- };
2173
- sjcl.mode.gcm = {
2174
- name: "gcm",
2175
- encrypt: function encrypt(a, b, c, d, e) {
2176
- var f = b.slice(0);
2177
- b = sjcl.bitArray;
2178
- d = d || [];
2179
- a = sjcl.mode.gcm.C(!0, a, f, d, c, e || 128);
2180
- return b.concat(a.data, a.tag);
2181
- },
2182
- decrypt: function decrypt(a, b, c, d, e) {
2183
- var f = b.slice(0),
2184
- g = sjcl.bitArray,
2185
- h = g.bitLength(f);
2186
- e = e || 128;
2187
- d = d || [];
2188
- e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []);
2189
- a = sjcl.mode.gcm.C(!1, a, f, d, c, e);
2190
- if (!g.equal(a.tag, b)) throw new sjcl.exception.corrupt("gcm: tag doesn't match");
2191
- return a.data;
2192
- },
2193
- ka: function ka(a, b) {
2194
- var c,
2195
- d,
2196
- e,
2197
- f,
2198
- g,
2199
- h = sjcl.bitArray.i;
2200
- e = [0, 0, 0, 0];
2201
- f = b.slice(0);
2202
-
2203
- for (c = 0; 128 > c; c++) {
2204
- (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f));
2205
- g = 0 !== (f[3] & 1);
2206
-
2207
- for (d = 3; 0 < d; d--) {
2208
- f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31;
2209
- }
2210
-
2211
- f[0] >>>= 1;
2212
- g && (f[0] ^= -0x1f000000);
2213
- }
2214
1786
 
2215
- return e;
2216
- },
2217
- j: function j(a, b, c) {
2218
- var d,
2219
- e = c.length;
2220
- b = b.slice(0);
1787
+ return x === 0;
1788
+ },
2221
1789
 
2222
- for (d = 0; d < e; d += 4) {
2223
- b[0] ^= 0xffffffff & c[d], b[1] ^= 0xffffffff & c[d + 1], b[2] ^= 0xffffffff & c[d + 2], b[3] ^= 0xffffffff & c[d + 3], b = sjcl.mode.gcm.ka(b, a);
2224
- }
1790
+ /** Shift an array right.
1791
+ * @param {bitArray} a The array to shift.
1792
+ * @param {Number} shift The number of bits to shift.
1793
+ * @param {Number} [carry=0] A byte to carry in
1794
+ * @param {bitArray} [out=[]] An array to prepend to the output.
1795
+ * @private
1796
+ */
1797
+ _shiftRight: function _shiftRight(a, shift, carry, out) {
1798
+ var i,
1799
+ last2 = 0,
1800
+ shift2;
2225
1801
 
2226
- return b;
2227
- },
2228
- C: function C(a, b, c, d, e, f) {
2229
- var g,
2230
- h,
2231
- k,
2232
- l,
2233
- n,
2234
- m,
2235
- p,
2236
- r,
2237
- q = sjcl.bitArray;
2238
- m = c.length;
2239
- p = q.bitLength(c);
2240
- r = q.bitLength(d);
2241
- h = q.bitLength(e);
2242
- g = b.encrypt([0, 0, 0, 0]);
2243
- 96 === h ? (e = e.slice(0), e = q.concat(e, [1])) : (e = sjcl.mode.gcm.j(g, [0, 0, 0, 0], e), e = sjcl.mode.gcm.j(g, e, [0, 0, Math.floor(h / 0x100000000), h & 0xffffffff]));
2244
- h = sjcl.mode.gcm.j(g, [0, 0, 0, 0], d);
2245
- n = e.slice(0);
2246
- d = h.slice(0);
2247
- a || (d = sjcl.mode.gcm.j(g, h, c));
2248
-
2249
- for (l = 0; l < m; l += 4) {
2250
- n[3]++, k = b.encrypt(n), c[l] ^= k[0], c[l + 1] ^= k[1], c[l + 2] ^= k[2], c[l + 3] ^= k[3];
2251
- }
1802
+ if (out === undefined) {
1803
+ out = [];
1804
+ }
2252
1805
 
2253
- c = q.clamp(c, p);
2254
- a && (d = sjcl.mode.gcm.j(g, h, c));
2255
- a = [Math.floor(r / 0x100000000), r & 0xffffffff, Math.floor(p / 0x100000000), p & 0xffffffff];
2256
- d = sjcl.mode.gcm.j(g, d, a);
2257
- k = b.encrypt(e);
2258
- d[0] ^= k[0];
2259
- d[1] ^= k[1];
2260
- d[2] ^= k[2];
2261
- d[3] ^= k[3];
2262
- return {
2263
- tag: q.bitSlice(d, 0, f),
2264
- data: c
2265
- };
1806
+ for (; shift >= 32; shift -= 32) {
1807
+ out.push(carry);
1808
+ carry = 0;
2266
1809
  }
2267
- };
2268
1810
 
2269
- sjcl.misc.hmac = function (a, b) {
2270
- this.W = b = b || sjcl.hash.sha256;
2271
- var c = [[], []],
2272
- d,
2273
- e = b.prototype.blockSize / 32;
2274
- this.w = [new b(), new b()];
2275
- a.length > e && (a = b.hash(a));
1811
+ if (shift === 0) {
1812
+ return out.concat(a);
1813
+ }
2276
1814
 
2277
- for (d = 0; d < e; d++) {
2278
- c[0][d] = a[d] ^ 909522486, c[1][d] = a[d] ^ 1549556828;
1815
+ for (i = 0; i < a.length; i++) {
1816
+ out.push(carry | a[i] >>> shift);
1817
+ carry = a[i] << 32 - shift;
2279
1818
  }
2280
1819
 
2281
- this.w[0].update(c[0]);
2282
- this.w[1].update(c[1]);
2283
- this.R = new b(this.w[0]);
2284
- };
1820
+ last2 = a.length ? a[a.length - 1] : 0;
1821
+ shift2 = sjcl.bitArray.getPartial(last2);
1822
+ out.push(sjcl.bitArray.partial(shift + shift2 & 31, shift + shift2 > 32 ? carry : out.pop(), 1));
1823
+ return out;
1824
+ },
2285
1825
 
2286
- sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (a) {
2287
- if (this.aa) throw new sjcl.exception.invalid("encrypt on already updated hmac called!");
2288
- this.update(a);
2289
- return this.digest(a);
2290
- };
1826
+ /** xor a block of 4 words together.
1827
+ * @private
1828
+ */
1829
+ _xor4: function _xor4(x, y) {
1830
+ return [x[0] ^ y[0], x[1] ^ y[1], x[2] ^ y[2], x[3] ^ y[3]];
1831
+ },
2291
1832
 
2292
- sjcl.misc.hmac.prototype.reset = function () {
2293
- this.R = new this.W(this.w[0]);
2294
- this.aa = !1;
2295
- };
1833
+ /** byteswap a word array inplace.
1834
+ * (does not handle partial words)
1835
+ * @param {sjcl.bitArray} a word array
1836
+ * @return {sjcl.bitArray} byteswapped array
1837
+ */
1838
+ byteswapM: function byteswapM(a) {
1839
+ var i,
1840
+ v,
1841
+ m = 0xff00;
2296
1842
 
2297
- sjcl.misc.hmac.prototype.update = function (a) {
2298
- this.aa = !0;
2299
- this.R.update(a);
2300
- };
1843
+ for (i = 0; i < a.length; ++i) {
1844
+ v = a[i];
1845
+ a[i] = v >>> 24 | v >>> 8 & m | (v & m) << 8 | v << 24;
1846
+ }
2301
1847
 
2302
- sjcl.misc.hmac.prototype.digest = function () {
2303
- var a = this.R.finalize(),
2304
- a = new this.W(this.w[1]).update(a).finalize();
2305
- this.reset();
2306
1848
  return a;
2307
- };
1849
+ }
1850
+ };
1851
+ /** @fileOverview Bit array codec implementations.
1852
+ *
1853
+ * @author Emily Stark
1854
+ * @author Mike Hamburg
1855
+ * @author Dan Boneh
1856
+ */
2308
1857
 
2309
- sjcl.misc.pbkdf2 = function (a, b, c, d, e) {
2310
- c = c || 1E4;
2311
- if (0 > d || 0 > c) throw new sjcl.exception.invalid("invalid params to pbkdf2");
2312
- "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a));
2313
- "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b));
2314
- e = e || sjcl.misc.hmac;
2315
- a = new e(a);
2316
- var f,
2317
- g,
2318
- h,
2319
- k,
2320
- l = [],
2321
- n = sjcl.bitArray;
2322
-
2323
- for (k = 1; 32 * l.length < (d || 1); k++) {
2324
- e = f = a.encrypt(n.concat(b, [k]));
2325
-
2326
- for (g = 1; g < c; g++) {
2327
- for (f = a.encrypt(f), h = 0; h < f.length; h++) {
2328
- e[h] ^= f[h];
2329
- }
2330
- }
1858
+ /**
1859
+ * UTF-8 strings
1860
+ * @namespace
1861
+ */
2331
1862
 
2332
- l = l.concat(e);
2333
- }
1863
+ sjcl.codec.utf8String = {
1864
+ /** Convert from a bitArray to a UTF-8 string. */
1865
+ fromBits: function fromBits(arr) {
1866
+ var out = '',
1867
+ bl = sjcl.bitArray.bitLength(arr),
1868
+ i,
1869
+ tmp;
2334
1870
 
2335
- d && (l = n.clamp(l, d));
2336
- return l;
2337
- };
1871
+ for (i = 0; i < bl / 8; i++) {
1872
+ if ((i & 3) === 0) {
1873
+ tmp = arr[i / 4];
1874
+ }
2338
1875
 
2339
- sjcl.prng = function (a) {
2340
- this.c = [new sjcl.hash.sha256()];
2341
- this.m = [0];
2342
- this.P = 0;
2343
- this.H = {};
2344
- this.N = 0;
2345
- this.U = {};
2346
- this.Z = this.f = this.o = this.ha = 0;
2347
- this.b = [0, 0, 0, 0, 0, 0, 0, 0];
2348
- this.h = [0, 0, 0, 0];
2349
- this.L = void 0;
2350
- this.M = a;
2351
- this.D = !1;
2352
- this.K = {
2353
- progress: {},
2354
- seeded: {}
2355
- };
2356
- this.u = this.ga = 0;
2357
- this.I = 1;
2358
- this.J = 2;
2359
- this.ca = 0x10000;
2360
- this.T = [0, 48, 64, 96, 128, 192, 0x100, 384, 512, 768, 1024];
2361
- this.da = 3E4;
2362
- this.ba = 80;
2363
- };
1876
+ out += String.fromCharCode(tmp >>> 8 >>> 8 >>> 8);
1877
+ tmp <<= 8;
1878
+ }
2364
1879
 
2365
- sjcl.prng.prototype = {
2366
- randomWords: function randomWords(a, b) {
2367
- var c = [],
2368
- d;
2369
- d = this.isReady(b);
2370
- var e;
2371
- if (d === this.u) throw new sjcl.exception.notReady("generator isn't seeded");
2372
-
2373
- if (d & this.J) {
2374
- d = !(d & this.I);
2375
- e = [];
2376
- var f = 0,
2377
- g;
2378
- this.Z = e[0] = new Date().valueOf() + this.da;
2379
-
2380
- for (g = 0; 16 > g; g++) {
2381
- e.push(0x100000000 * Math.random() | 0);
2382
- }
1880
+ return decodeURIComponent(escape(out));
1881
+ },
2383
1882
 
2384
- for (g = 0; g < this.c.length && (e = e.concat(this.c[g].finalize()), f += this.m[g], this.m[g] = 0, d || !(this.P & 1 << g)); g++) {
2385
- }
1883
+ /** Convert from a UTF-8 string to a bitArray. */
1884
+ toBits: function toBits(str) {
1885
+ str = unescape(encodeURIComponent(str));
1886
+ var out = [],
1887
+ i,
1888
+ tmp = 0;
2386
1889
 
2387
- this.P >= 1 << this.c.length && (this.c.push(new sjcl.hash.sha256()), this.m.push(0));
2388
- this.f -= f;
2389
- f > this.o && (this.o = f);
2390
- this.P++;
2391
- this.b = sjcl.hash.sha256.hash(this.b.concat(e));
2392
- this.L = new sjcl.cipher.aes(this.b);
1890
+ for (i = 0; i < str.length; i++) {
1891
+ tmp = tmp << 8 | str.charCodeAt(i);
2393
1892
 
2394
- for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) {
2395
- }
1893
+ if ((i & 3) === 3) {
1894
+ out.push(tmp);
1895
+ tmp = 0;
2396
1896
  }
1897
+ }
2397
1898
 
2398
- for (d = 0; d < a; d += 4) {
2399
- 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]);
2400
- }
1899
+ if (i & 3) {
1900
+ out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
1901
+ }
2401
1902
 
2402
- y(this);
2403
- return c.slice(0, a);
2404
- },
2405
- setDefaultParanoia: function setDefaultParanoia(a, b) {
2406
- if (0 === a && "Setting paranoia=0 will ruin your security; use it only for testing" !== b) throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");
2407
- this.M = a;
2408
- },
2409
- addEntropy: function addEntropy(a, b, c) {
2410
- c = c || "user";
2411
- var d,
2412
- e,
2413
- f = new Date().valueOf(),
2414
- g = this.H[c],
2415
- h = this.isReady(),
2416
- k = 0;
2417
- d = this.U[c];
2418
- void 0 === d && (d = this.U[c] = this.ha++);
2419
- void 0 === g && (g = this.H[c] = 0);
2420
- this.H[c] = (this.H[c] + 1) % this.c.length;
2421
-
2422
- switch (_typeof(a)) {
2423
- case "number":
2424
- void 0 === b && (b = 1);
2425
- this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]);
2426
- break;
1903
+ return out;
1904
+ }
1905
+ };
1906
+ /** @fileOverview Javascript SHA-256 implementation.
1907
+ *
1908
+ * An older version of this implementation is available in the public
1909
+ * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
1910
+ * Stanford University 2008-2010 and BSD-licensed for liability
1911
+ * reasons.
1912
+ *
1913
+ * Special thanks to Aldo Cortesi for pointing out several bugs in
1914
+ * this code.
1915
+ *
1916
+ * @author Emily Stark
1917
+ * @author Mike Hamburg
1918
+ * @author Dan Boneh
1919
+ */
2427
1920
 
2428
- case "object":
2429
- c = Object.prototype.toString.call(a);
1921
+ /**
1922
+ * Context for a SHA-256 operation in progress.
1923
+ * @constructor
1924
+ */
2430
1925
 
2431
- if ("[object Uint32Array]" === c) {
2432
- e = [];
1926
+ sjcl.hash.sha256 = function (hash) {
1927
+ if (!this._key[0]) {
1928
+ this._precompute();
1929
+ }
2433
1930
 
2434
- for (c = 0; c < a.length; c++) {
2435
- e.push(a[c]);
2436
- }
1931
+ if (hash) {
1932
+ this._h = hash._h.slice(0);
1933
+ this._buffer = hash._buffer.slice(0);
1934
+ this._length = hash._length;
1935
+ } else {
1936
+ this.reset();
1937
+ }
1938
+ };
1939
+ /**
1940
+ * Hash a string or an array of words.
1941
+ * @static
1942
+ * @param {bitArray|String} data the data to hash.
1943
+ * @return {bitArray} The hash value, an array of 16 big-endian words.
1944
+ */
2437
1945
 
2438
- a = e;
2439
- } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) {
2440
- "number" !== typeof a[c] && (k = 1);
2441
- }
2442
1946
 
2443
- if (!k) {
2444
- if (void 0 === b) for (c = b = 0; c < a.length; c++) {
2445
- for (e = a[c]; 0 < e;) {
2446
- b++, e = e >>> 1;
2447
- }
2448
- }
2449
- this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a));
2450
- }
1947
+ sjcl.hash.sha256.hash = function (data) {
1948
+ return new sjcl.hash.sha256().update(data).finalize();
1949
+ };
2451
1950
 
2452
- break;
1951
+ sjcl.hash.sha256.prototype = {
1952
+ /**
1953
+ * The hash's block size, in bits.
1954
+ * @constant
1955
+ */
1956
+ blockSize: 512,
2453
1957
 
2454
- case "string":
2455
- void 0 === b && (b = a.length);
2456
- this.c[g].update([d, this.N++, 3, b, f, a.length]);
2457
- this.c[g].update(a);
2458
- break;
1958
+ /**
1959
+ * Reset the hash state.
1960
+ * @return this
1961
+ */
1962
+ reset: function reset() {
1963
+ this._h = this._init.slice(0);
1964
+ this._buffer = [];
1965
+ this._length = 0;
1966
+ return this;
1967
+ },
2459
1968
 
2460
- default:
2461
- k = 1;
2462
- }
1969
+ /**
1970
+ * Input several words to the hash.
1971
+ * @param {bitArray|String} data the data to hash.
1972
+ * @return this
1973
+ */
1974
+ update: function update(data) {
1975
+ if (typeof data === 'string') {
1976
+ data = sjcl.codec.utf8String.toBits(data);
1977
+ }
2463
1978
 
2464
- if (k) throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");
2465
- this.m[g] += b;
2466
- this.f += b;
2467
- h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress()));
2468
- },
2469
- isReady: function isReady(a) {
2470
- a = this.T[void 0 !== a ? a : this.M];
2471
- return this.o && this.o >= a ? this.m[0] > this.ba && new Date().valueOf() > this.Z ? this.J | this.I : this.I : this.f >= a ? this.J | this.u : this.u;
2472
- },
2473
- getProgress: function getProgress(a) {
2474
- a = this.T[a ? a : this.M];
2475
- return this.o >= a ? 1 : this.f > a ? 1 : this.f / a;
2476
- },
2477
- startCollectors: function startCollectors() {
2478
- if (!this.D) {
2479
- this.a = {
2480
- loadTimeCollector: B(this, this.ma),
2481
- mouseCollector: B(this, this.oa),
2482
- keyboardCollector: B(this, this.la),
2483
- accelerometerCollector: B(this, this.ea),
2484
- touchCollector: B(this, this.qa)
2485
- };
2486
- if (window.addEventListener) window.addEventListener("load", this.a.loadTimeCollector, !1), window.addEventListener("mousemove", this.a.mouseCollector, !1), window.addEventListener("keypress", this.a.keyboardCollector, !1), window.addEventListener("devicemotion", this.a.accelerometerCollector, !1), window.addEventListener("touchmove", this.a.touchCollector, !1);else if (document.attachEvent) document.attachEvent("onload", this.a.loadTimeCollector), document.attachEvent("onmousemove", this.a.mouseCollector), document.attachEvent("keypress", this.a.keyboardCollector);else throw new sjcl.exception.bug("can't attach event");
2487
- this.D = !0;
2488
- }
2489
- },
2490
- stopCollectors: function stopCollectors() {
2491
- this.D && (window.removeEventListener ? (window.removeEventListener("load", this.a.loadTimeCollector, !1), window.removeEventListener("mousemove", this.a.mouseCollector, !1), window.removeEventListener("keypress", this.a.keyboardCollector, !1), window.removeEventListener("devicemotion", this.a.accelerometerCollector, !1), window.removeEventListener("touchmove", this.a.touchCollector, !1)) : document.detachEvent && (document.detachEvent("onload", this.a.loadTimeCollector), document.detachEvent("onmousemove", this.a.mouseCollector), document.detachEvent("keypress", this.a.keyboardCollector)), this.D = !1);
2492
- },
2493
- addEventListener: function addEventListener(a, b) {
2494
- this.K[a][this.ga++] = b;
2495
- },
2496
- removeEventListener: function removeEventListener(a, b) {
2497
- var c,
2498
- d,
2499
- e = this.K[a],
2500
- f = [];
2501
-
2502
- for (d in e) {
2503
- e.hasOwnProperty(d) && e[d] === b && f.push(d);
2504
- }
1979
+ var i,
1980
+ b = this._buffer = sjcl.bitArray.concat(this._buffer, data),
1981
+ ol = this._length,
1982
+ nl = this._length = ol + sjcl.bitArray.bitLength(data);
2505
1983
 
2506
- for (c = 0; c < f.length; c++) {
2507
- d = f[c], delete e[d];
2508
- }
2509
- },
2510
- la: function la() {
2511
- C(this, 1);
2512
- },
2513
- oa: function oa(a) {
2514
- var b, c;
1984
+ if (nl > 9007199254740991) {
1985
+ throw new sjcl.exception.invalid('Cannot hash more than 2^53 - 1 bits');
1986
+ }
2515
1987
 
2516
- try {
2517
- b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0;
2518
- } catch (d) {
2519
- c = b = 0;
2520
- }
1988
+ if (typeof Uint32Array !== 'undefined') {
1989
+ var c = new Uint32Array(b);
1990
+ var j = 0;
2521
1991
 
2522
- 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse");
2523
- C(this, 0);
2524
- },
2525
- qa: function qa(a) {
2526
- a = a.touches[0] || a.changedTouches[0];
2527
- this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch");
2528
- C(this, 0);
2529
- },
2530
- ma: function ma() {
2531
- C(this, 2);
2532
- },
2533
- ea: function ea(a) {
2534
- a = a.accelerationIncludingGravity.x || a.accelerationIncludingGravity.y || a.accelerationIncludingGravity.z;
1992
+ for (i = 512 + ol - (512 + ol & 511); i <= nl; i += 512) {
1993
+ this._block(c.subarray(16 * j, 16 * (j + 1)));
2535
1994
 
2536
- if (window.orientation) {
2537
- var b = window.orientation;
2538
- "number" === typeof b && this.addEntropy(b, 1, "accelerometer");
1995
+ j += 1;
2539
1996
  }
2540
1997
 
2541
- a && this.addEntropy(a, 2, "accelerometer");
2542
- C(this, 0);
1998
+ b.splice(0, 16 * j);
1999
+ } else {
2000
+ for (i = 512 + ol - (512 + ol & 511); i <= nl; i += 512) {
2001
+ this._block(b.splice(0, 16));
2002
+ }
2543
2003
  }
2544
- };
2545
-
2546
- function A(a, b) {
2547
- var c,
2548
- d = sjcl.random.K[a],
2549
- e = [];
2550
2004
 
2551
- for (c in d) {
2552
- d.hasOwnProperty(c) && e.push(d[c]);
2553
- }
2005
+ return this;
2006
+ },
2554
2007
 
2555
- for (c = 0; c < e.length; c++) {
2556
- e[c](b);
2557
- }
2558
- }
2008
+ /**
2009
+ * Complete hashing and output the hash value.
2010
+ * @return {bitArray} The hash value, an array of 8 big-endian words.
2011
+ */
2012
+ finalize: function finalize() {
2013
+ var i,
2014
+ b = this._buffer,
2015
+ h = this._h; // Round out and push the buffer
2559
2016
 
2560
- function C(a, b) {
2561
- "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy(new Date().valueOf(), b, "loadtime");
2562
- }
2017
+ b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]); // Round out the buffer to a multiple of 16 words, less the 2 length words.
2563
2018
 
2564
- function y(a) {
2565
- a.b = z(a).concat(z(a));
2566
- a.L = new sjcl.cipher.aes(a.b);
2567
- }
2019
+ for (i = b.length + 2; i & 15; i++) {
2020
+ b.push(0);
2021
+ } // append the length
2568
2022
 
2569
- function z(a) {
2570
- for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) {
2571
- }
2572
2023
 
2573
- return a.L.encrypt(a.h);
2574
- }
2024
+ b.push(Math.floor(this._length / 0x100000000));
2025
+ b.push(this._length | 0);
2575
2026
 
2576
- function B(a, b) {
2577
- return function () {
2578
- b.apply(a, arguments);
2579
- };
2580
- }
2027
+ while (b.length) {
2028
+ this._block(b.splice(0, 16));
2029
+ }
2581
2030
 
2582
- sjcl.random = new sjcl.prng(6);
2031
+ this.reset();
2032
+ return h;
2033
+ },
2583
2034
 
2584
- a: try {
2585
- var D, E, F, G;
2035
+ /**
2036
+ * The SHA-256 initialization vector, to be precomputed.
2037
+ * @private
2038
+ */
2039
+ _init: [],
2586
2040
 
2587
- if (G = "undefined" !== 'object' && module.exports) {
2588
- var H;
2041
+ /*
2042
+ _init:[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19],
2043
+ */
2589
2044
 
2590
- try {
2591
- H = require$$0__default['default'];
2592
- } catch (a) {
2593
- H = null;
2594
- }
2045
+ /**
2046
+ * The SHA-256 hash key, to be precomputed.
2047
+ * @private
2048
+ */
2049
+ _key: [],
2050
+
2051
+ /*
2052
+ _key:
2053
+ [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
2054
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
2055
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
2056
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
2057
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
2058
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
2059
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
2060
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2],
2061
+ */
2595
2062
 
2596
- G = E = H;
2597
- }
2063
+ /**
2064
+ * Function to precompute _init and _key.
2065
+ * @private
2066
+ */
2067
+ _precompute: function _precompute() {
2068
+ var i = 0,
2069
+ prime = 2,
2070
+ factor,
2071
+ isPrime;
2598
2072
 
2599
- if (G && E.randomBytes) D = E.randomBytes(128), D = new Uint32Array(new Uint8Array(D).buffer), sjcl.random.addEntropy(D, 1024, "crypto['randomBytes']");else if ("undefined" !== typeof window && "undefined" !== typeof Uint32Array) {
2600
- F = new Uint32Array(32);
2601
- if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F);else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F);else break a;
2602
- sjcl.random.addEntropy(F, 1024, "crypto['getRandomValues']");
2073
+ function frac(x) {
2074
+ return (x - Math.floor(x)) * 0x100000000 | 0;
2603
2075
  }
2604
- } catch (a) {
2605
- "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a));
2606
- }
2607
2076
 
2608
- sjcl.json = {
2609
- defaults: {
2610
- v: 1,
2611
- iter: 1E4,
2612
- ks: 128,
2613
- ts: 64,
2614
- mode: "ccm",
2615
- adata: "",
2616
- cipher: "aes"
2617
- },
2618
- ja: function ja(a, b, c, d) {
2619
- c = c || {};
2620
- d = d || {};
2621
- var e = sjcl.json,
2622
- f = e.g({
2623
- iv: sjcl.random.randomWords(4, 0)
2624
- }, e.defaults),
2625
- g;
2626
- e.g(f, c);
2627
- c = f.adata;
2628
- "string" === typeof f.salt && (f.salt = sjcl.codec.base64.toBits(f.salt));
2629
- "string" === typeof f.iv && (f.iv = sjcl.codec.base64.toBits(f.iv));
2630
- if (!sjcl.mode[f.mode] || !sjcl.cipher[f.cipher] || "string" === typeof a && 100 >= f.iter || 64 !== f.ts && 96 !== f.ts && 128 !== f.ts || 128 !== f.ks && 192 !== f.ks && 0x100 !== f.ks || 2 > f.iv.length || 4 < f.iv.length) throw new sjcl.exception.invalid("json encrypt: invalid parameters");
2631
- "string" === typeof a ? (g = sjcl.misc.cachedPbkdf2(a, f), a = g.key.slice(0, f.ks / 32), f.salt = g.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.publicKey && (g = a.kem(), f.kemtag = g.tag, a = g.key.slice(0, f.ks / 32));
2632
- "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b));
2633
- "string" === typeof c && (f.adata = c = sjcl.codec.utf8String.toBits(c));
2634
- g = new sjcl.cipher[f.cipher](a);
2635
- e.g(d, f);
2636
- d.key = a;
2637
- f.ct = "ccm" === f.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && b instanceof ArrayBuffer ? sjcl.arrayBuffer.ccm.encrypt(g, b, f.iv, c, f.ts) : sjcl.mode[f.mode].encrypt(g, b, f.iv, c, f.ts);
2638
- return f;
2639
- },
2640
- encrypt: function encrypt(a, b, c, d) {
2641
- var e = sjcl.json,
2642
- f = e.ja.apply(e, arguments);
2643
- return e.encode(f);
2644
- },
2645
- ia: function ia(a, b, c, d) {
2646
- c = c || {};
2647
- d = d || {};
2648
- var e = sjcl.json;
2649
- b = e.g(e.g(e.g({}, e.defaults), b), c, !0);
2650
- var f, g;
2651
- f = b.adata;
2652
- "string" === typeof b.salt && (b.salt = sjcl.codec.base64.toBits(b.salt));
2653
- "string" === typeof b.iv && (b.iv = sjcl.codec.base64.toBits(b.iv));
2654
- if (!sjcl.mode[b.mode] || !sjcl.cipher[b.cipher] || "string" === typeof a && 100 >= b.iter || 64 !== b.ts && 96 !== b.ts && 128 !== b.ts || 128 !== b.ks && 192 !== b.ks && 0x100 !== b.ks || !b.iv || 2 > b.iv.length || 4 < b.iv.length) throw new sjcl.exception.invalid("json decrypt: invalid parameters");
2655
- "string" === typeof a ? (g = sjcl.misc.cachedPbkdf2(a, b), a = g.key.slice(0, b.ks / 32), b.salt = g.salt) : sjcl.ecc && a instanceof sjcl.ecc.elGamal.secretKey && (a = a.unkem(sjcl.codec.base64.toBits(b.kemtag)).slice(0, b.ks / 32));
2656
- "string" === typeof f && (f = sjcl.codec.utf8String.toBits(f));
2657
- g = new sjcl.cipher[b.cipher](a);
2658
- f = "ccm" === b.mode && sjcl.arrayBuffer && sjcl.arrayBuffer.ccm && b.ct instanceof ArrayBuffer ? sjcl.arrayBuffer.ccm.decrypt(g, b.ct, b.iv, b.tag, f, b.ts) : sjcl.mode[b.mode].decrypt(g, b.ct, b.iv, f, b.ts);
2659
- e.g(d, b);
2660
- d.key = a;
2661
- return 1 === c.raw ? f : sjcl.codec.utf8String.fromBits(f);
2662
- },
2663
- decrypt: function decrypt(a, b, c, d) {
2664
- var e = sjcl.json;
2665
- return e.ia(a, e.decode(b), c, d);
2666
- },
2667
- encode: function encode(a) {
2668
- var b,
2669
- c = "{",
2670
- d = "";
2671
-
2672
- for (b in a) {
2673
- if (a.hasOwnProperty(b)) {
2674
- if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl.exception.invalid("json encode: invalid property name");
2675
- c += d + '"' + b + '":';
2676
- d = ",";
2677
-
2678
- switch (_typeof(a[b])) {
2679
- case "number":
2680
- case "boolean":
2681
- c += a[b];
2682
- break;
2077
+ for (; i < 64; prime++) {
2078
+ isPrime = true;
2683
2079
 
2684
- case "string":
2685
- c += '"' + escape(a[b]) + '"';
2686
- break;
2687
-
2688
- case "object":
2689
- c += '"' + sjcl.codec.base64.fromBits(a[b], 0) + '"';
2690
- break;
2691
-
2692
- default:
2693
- throw new sjcl.exception.bug("json encode: unsupported type");
2694
- }
2080
+ for (factor = 2; factor * factor <= prime; factor++) {
2081
+ if (prime % factor === 0) {
2082
+ isPrime = false;
2083
+ break;
2695
2084
  }
2696
2085
  }
2697
2086
 
2698
- return c + "}";
2699
- },
2700
- decode: function decode(a) {
2701
- a = a.replace(/\s/g, "");
2702
- if (!a.match(/^\{.*\}$/)) throw new sjcl.exception.invalid("json decode: this isn't json!");
2703
- a = a.replace(/^\{|\}$/g, "").split(/,/);
2704
- var b = {},
2705
- c,
2706
- d;
2707
-
2708
- for (c = 0; c < a.length; c++) {
2709
- if (!(d = a[c].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i))) throw new sjcl.exception.invalid("json decode: this isn't json!");
2710
- null != d[3] ? b[d[2]] = parseInt(d[3], 10) : null != d[4] ? b[d[2]] = d[2].match(/^(ct|adata|salt|iv)$/) ? sjcl.codec.base64.toBits(d[4]) : unescape(d[4]) : null != d[5] && (b[d[2]] = "true" === d[5]);
2711
- }
2712
-
2713
- return b;
2714
- },
2715
- g: function g(a, b, c) {
2716
- void 0 === a && (a = {});
2717
- if (void 0 === b) return a;
2718
-
2719
- for (var d in b) {
2720
- if (b.hasOwnProperty(d)) {
2721
- if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl.exception.invalid("required parameter overridden");
2722
- a[d] = b[d];
2087
+ if (isPrime) {
2088
+ if (i < 8) {
2089
+ this._init[i] = frac(Math.pow(prime, 1 / 2));
2723
2090
  }
2724
- }
2725
-
2726
- return a;
2727
- },
2728
- sa: function sa(a, b) {
2729
- var c = {},
2730
- d;
2731
2091
 
2732
- for (d in a) {
2733
- a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]);
2092
+ this._key[i] = frac(Math.pow(prime, 1 / 3));
2093
+ i++;
2734
2094
  }
2095
+ }
2096
+ },
2735
2097
 
2736
- return c;
2737
- },
2738
- ra: function ra(a, b) {
2739
- var c = {},
2740
- d;
2098
+ /**
2099
+ * Perform one cycle of SHA-256.
2100
+ * @param {Uint32Array|bitArray} w one block of words.
2101
+ * @private
2102
+ */
2103
+ _block: function _block(w) {
2104
+ var i,
2105
+ tmp,
2106
+ a,
2107
+ b,
2108
+ h = this._h,
2109
+ k = this._key,
2110
+ h0 = h[0],
2111
+ h1 = h[1],
2112
+ h2 = h[2],
2113
+ h3 = h[3],
2114
+ h4 = h[4],
2115
+ h5 = h[5],
2116
+ h6 = h[6],
2117
+ h7 = h[7];
2118
+ /* Rationale for placement of |0 :
2119
+ * If a value can overflow is original 32 bits by a factor of more than a few
2120
+ * million (2^23 ish), there is a possibility that it might overflow the
2121
+ * 53-bit mantissa and lose precision.
2122
+ *
2123
+ * To avoid this, we clamp back to 32 bits by |'ing with 0 on any value that
2124
+ * propagates around the loop, and on the hash state h[]. I don't believe
2125
+ * that the clamps on h4 and on h0 are strictly necessary, but it's close
2126
+ * (for h4 anyway), and better safe than sorry.
2127
+ *
2128
+ * The clamps on h[] are necessary for the output to be correct even in the
2129
+ * common case and for short inputs.
2130
+ */
2741
2131
 
2742
- for (d = 0; d < b.length; d++) {
2743
- void 0 !== a[b[d]] && (c[b[d]] = a[b[d]]);
2132
+ for (i = 0; i < 64; i++) {
2133
+ // load up the input word for this round
2134
+ if (i < 16) {
2135
+ tmp = w[i];
2136
+ } else {
2137
+ a = w[i + 1 & 15];
2138
+ b = w[i + 14 & 15];
2139
+ tmp = w[i & 15] = (a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14) + (b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13) + w[i & 15] + w[i + 9 & 15] | 0;
2744
2140
  }
2745
2141
 
2746
- return c;
2142
+ tmp = tmp + h7 + (h4 >>> 6 ^ h4 >>> 11 ^ h4 >>> 25 ^ h4 << 26 ^ h4 << 21 ^ h4 << 7) + (h6 ^ h4 & (h5 ^ h6)) + k[i]; // | 0;
2143
+ // shift register
2144
+
2145
+ h7 = h6;
2146
+ h6 = h5;
2147
+ h5 = h4;
2148
+ h4 = h3 + tmp | 0;
2149
+ h3 = h2;
2150
+ h2 = h1;
2151
+ h1 = h0;
2152
+ h0 = tmp + (h1 & h2 ^ h3 & (h1 ^ h2)) + (h1 >>> 2 ^ h1 >>> 13 ^ h1 >>> 22 ^ h1 << 30 ^ h1 << 19 ^ h1 << 10) | 0;
2747
2153
  }
2748
- };
2749
- sjcl.encrypt = sjcl.json.encrypt;
2750
- sjcl.decrypt = sjcl.json.decrypt;
2751
- sjcl.misc.pa = {};
2752
-
2753
- sjcl.misc.cachedPbkdf2 = function (a, b) {
2754
- var c = sjcl.misc.pa,
2755
- d;
2756
- b = b || {};
2757
- d = b.iter || 1E3;
2758
- c = c[a] = c[a] || {};
2759
- d = c[d] = c[d] || {
2760
- firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl.random.randomWords(2, 0)
2761
- };
2762
- c = void 0 === b.salt ? d.firstSalt : b.salt;
2763
- d[c] = d[c] || sjcl.misc.pbkdf2(a, c, b.iter);
2764
- return {
2765
- key: d[c].slice(0),
2766
- salt: c.slice(0)
2767
- };
2768
- };
2769
2154
 
2770
- module.exports && (module.exports = sjcl);
2771
- });
2155
+ h[0] = h[0] + h0 | 0;
2156
+ h[1] = h[1] + h1 | 0;
2157
+ h[2] = h[2] + h2 | 0;
2158
+ h[3] = h[3] + h3 | 0;
2159
+ h[4] = h[4] + h4 | 0;
2160
+ h[5] = h[5] + h5 | 0;
2161
+ h[6] = h[6] + h6 | 0;
2162
+ h[7] = h[7] + h7 | 0;
2163
+ }
2164
+ };
2772
2165
 
2773
2166
  // eslint-disable-next-line require-jsdoc
2774
2167
  function base64URLEncode(str) {
@@ -2799,6 +2192,7 @@
2799
2192
  * @param {String} [options.redirect_uri=''] OAuth redirect uri - default current location
2800
2193
  * @param {String} [options.email_hint=''] fill in email in forms
2801
2194
  * @param {String} [options.server_url='https://accounts.livechat.com'] authorization server url
2195
+ * @param {String} [options.path=''] option to provide a path when loading accounts, for example '/signup'
2802
2196
  * @param {Object} [options.tracking] tracking querystring params
2803
2197
  * @param {Object} [options.transaction] options for transaction manager
2804
2198
  * @param {String} [options.transaction.namespace='com.livechat.accounts'] transaction keys prefix
@@ -2824,6 +2218,7 @@
2824
2218
  response_type: 'token',
2825
2219
  popup_flow: 'auto',
2826
2220
  state: '',
2221
+ verify_state: true,
2827
2222
  verify_callback: true,
2828
2223
  scope: null,
2829
2224
  redirect_uri: '',
@@ -2926,12 +2321,16 @@
2926
2321
  url += '/signin';
2927
2322
  }
2928
2323
 
2324
+ if (localOptions.path) {
2325
+ url += localOptions.path;
2326
+ }
2327
+
2929
2328
  if (localOptions.response_type === 'code' && localOptions.pkce.enabled) {
2930
2329
  var codeVerifier = localOptions.pkce.code_verifier || random.string(localOptions.pkce.code_verifier_length);
2931
2330
 
2932
2331
  switch (localOptions.pkce.code_challange_method) {
2933
2332
  case 'S256':
2934
- var codeChallenge = sjcl_1.hash.sha256.hash(codeVerifier);
2333
+ var codeChallenge = sjcl.hash.sha256.hash(codeVerifier);
2935
2334
  Object.assign(params, {
2936
2335
  code_verifier: codeVerifier,
2937
2336
  code_challenge: encoding.base64URLEncode(codeChallenge),