@livechat/accounts-sdk 2.0.3 → 2.0.6

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";
@@ -1501,1281 +1497,671 @@
1501
1497
  return Transaction;
1502
1498
  }();
1503
1499
 
1504
- var sjcl_1 = createCommonjsModule(function (module) {
1505
-
1506
- var sjcl = {
1507
- cipher: {},
1508
- hash: {},
1509
- keyexchange: {},
1510
- mode: {},
1511
- misc: {},
1512
- codec: {},
1513
- exception: {
1514
- corrupt: function corrupt(a) {
1515
- this.toString = function () {
1516
- return "CORRUPT: " + this.message;
1517
- };
1518
-
1519
- this.message = a;
1520
- },
1521
- invalid: function invalid(a) {
1522
- this.toString = function () {
1523
- return "INVALID: " + this.message;
1524
- };
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 */
1525
1510
 
1526
- this.message = a;
1527
- },
1528
- bug: function bug(a) {
1529
- this.toString = function () {
1530
- return "BUG: " + this.message;
1531
- };
1511
+ /*global document, window, escape, unescape, module, require, Uint32Array */
1532
1512
 
1533
- this.message = a;
1534
- },
1535
- notReady: function notReady(a) {
1536
- this.toString = function () {
1537
- return "NOT READY: " + this.message;
1538
- };
1513
+ /**
1514
+ * The Stanford Javascript Crypto Library, top-level namespace.
1515
+ * @namespace
1516
+ */
1539
1517
 
1540
- this.message = a;
1541
- }
1542
- }
1543
- };
1518
+ var sjcl = {
1519
+ /**
1520
+ * Symmetric ciphers.
1521
+ * @namespace
1522
+ */
1523
+ cipher: {},
1544
1524
 
1545
- sjcl.cipher.aes = function (a) {
1546
- this.s[0][0][0] || this.O();
1547
- var b,
1548
- c,
1549
- d,
1550
- e,
1551
- f = this.s[0][4],
1552
- g = this.s[1];
1553
- b = a.length;
1554
- var h = 1;
1555
- if (4 !== b && 6 !== b && 8 !== b) throw new sjcl.exception.invalid("invalid aes key size");
1556
- this.b = [d = a.slice(0), e = []];
1525
+ /**
1526
+ * Hash functions. Right now only SHA256 is implemented.
1527
+ * @namespace
1528
+ */
1529
+ hash: {},
1557
1530
 
1558
- for (a = b; a < 4 * b + 28; a++) {
1559
- c = d[a - 1];
1560
- 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));
1561
- d[a] = d[a - b] ^ c;
1562
- }
1531
+ /**
1532
+ * Key exchange functions. Right now only SRP is implemented.
1533
+ * @namespace
1534
+ */
1535
+ keyexchange: {},
1563
1536
 
1564
- for (b = 0; a; b++, a--) {
1565
- 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]];
1566
- }
1567
- };
1537
+ /**
1538
+ * Cipher modes of operation.
1539
+ * @namespace
1540
+ */
1541
+ mode: {},
1568
1542
 
1569
- sjcl.cipher.aes.prototype = {
1570
- encrypt: function encrypt(a) {
1571
- return t(this, a, 0);
1572
- },
1573
- decrypt: function decrypt(a) {
1574
- return t(this, a, 1);
1575
- },
1576
- s: [[[], [], [], [], []], [[], [], [], [], []]],
1577
- O: function O() {
1578
- var a = this.s[0],
1579
- b = this.s[1],
1580
- c = a[4],
1581
- d = b[4],
1582
- e,
1583
- f,
1584
- g,
1585
- h = [],
1586
- k = [],
1587
- l,
1588
- n,
1589
- m,
1590
- p;
1591
-
1592
- for (e = 0; 0x100 > e; e++) {
1593
- k[(h[e] = e << 1 ^ 283 * (e >> 7)) ^ e] = e;
1594
- }
1543
+ /**
1544
+ * Miscellaneous. HMAC and PBKDF2.
1545
+ * @namespace
1546
+ */
1547
+ misc: {},
1595
1548
 
1596
- for (f = g = 0; !c[f]; f ^= l || 1, g = k[g] || 1) {
1597
- 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++) {
1598
- a[e][f] = n = n << 24 ^ n >>> 8, b[e][m] = p = p << 24 ^ p >>> 8;
1599
- }
1600
- }
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: {},
1601
1560
 
1602
- for (e = 0; 5 > e; e++) {
1603
- a[e] = a[e].slice(0), b[e] = b[e].slice(0);
1604
- }
1605
- }
1606
- };
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
+ };
1607
1574
 
1608
- function t(a, b, c) {
1609
- if (4 !== b.length) throw new sjcl.exception.invalid("invalid aes block size");
1610
- var d = a.b[c],
1611
- e = b[0] ^ d[0],
1612
- f = b[c ? 3 : 1] ^ d[1],
1613
- g = b[2] ^ d[2];
1614
- b = b[c ? 1 : 3] ^ d[3];
1615
- var h,
1616
- k,
1617
- l,
1618
- n = d.length / 4 - 2,
1619
- m,
1620
- p = 4,
1621
- r = [0, 0, 0, 0];
1622
- h = a.s[c];
1623
- a = h[0];
1624
- var q = h[1],
1625
- v = h[2],
1626
- w = h[3],
1627
- x = h[4];
1628
-
1629
- for (m = 0; m < n; m++) {
1630
- 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;
1631
- }
1632
-
1633
- for (m = 0; 4 > m; m++) {
1634
- 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;
1635
- }
1636
-
1637
- return r;
1638
- }
1639
-
1640
- sjcl.bitArray = {
1641
- bitSlice: function bitSlice(a, b, c) {
1642
- a = sjcl.bitArray.$(a.slice(b / 32), 32 - (b & 31)).slice(1);
1643
- return void 0 === c ? a : sjcl.bitArray.clamp(a, c - b);
1644
- },
1645
- extract: function extract(a, b, c) {
1646
- var d = Math.floor(-b - c & 31);
1647
- 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;
1648
1576
  },
1649
- concat: function concat(a, b) {
1650
- if (0 === a.length || 0 === b.length) return a.concat(b);
1651
- var c = a[a.length - 1],
1652
- d = sjcl.bitArray.getPartial(c);
1653
- return 32 === d ? a.concat(b) : sjcl.bitArray.$(b, d, c | 0, a.slice(0, a.length - 1));
1654
- },
1655
- bitLength: function bitLength(a) {
1656
- var b = a.length;
1657
- return 0 === b ? 0 : 32 * (b - 1) + sjcl.bitArray.getPartial(a[b - 1]);
1658
- },
1659
- clamp: function clamp(a, b) {
1660
- if (32 * a.length < b) return a;
1661
- a = a.slice(0, Math.ceil(b / 32));
1662
- var c = a.length;
1663
- b = b & 31;
1664
- 0 < c && b && (a[c - 1] = sjcl.bitArray.partial(b, a[c - 1] & 2147483648 >> b - 1, 1));
1665
- return a;
1666
- },
1667
- partial: function partial(a, b, c) {
1668
- return 32 === a ? b : (c ? b | 0 : b << 32 - a) + 0x10000000000 * a;
1669
- },
1670
- getPartial: function getPartial(a) {
1671
- return Math.round(a / 0x10000000000) || 32;
1672
- },
1673
- equal: function equal(a, b) {
1674
- if (sjcl.bitArray.bitLength(a) !== sjcl.bitArray.bitLength(b)) return !1;
1675
- var c = 0,
1676
- d;
1677
1577
 
1678
- for (d = 0; d < a.length; d++) {
1679
- c |= a[d] ^ b[d];
1680
- }
1578
+ /**
1579
+ * Invalid parameter.
1580
+ * @constructor
1581
+ */
1582
+ invalid: function invalid(message) {
1583
+ this.toString = function () {
1584
+ return 'INVALID: ' + this.message;
1585
+ };
1681
1586
 
1682
- return 0 === c;
1587
+ this.message = message;
1683
1588
  },
1684
- $: function $(a, b, c, d) {
1685
- var e;
1686
- e = 0;
1687
-
1688
- for (void 0 === d && (d = []); 32 <= b; b -= 32) {
1689
- d.push(c), c = 0;
1690
- }
1691
-
1692
- if (0 === b) return d.concat(a);
1693
1589
 
1694
- for (e = 0; e < a.length; e++) {
1695
- d.push(c | a[e] >>> b), c = a[e] << 32 - b;
1696
- }
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
+ };
1697
1598
 
1698
- e = a.length ? a[a.length - 1] : 0;
1699
- a = sjcl.bitArray.getPartial(e);
1700
- d.push(sjcl.bitArray.partial(b + a & 31, 32 < b + a ? c : d.pop(), 1));
1701
- return d;
1599
+ this.message = message;
1702
1600
  },
1703
- i: function i(a, b) {
1704
- return [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]];
1705
- },
1706
- byteswapM: function byteswapM(a) {
1707
- var b, c;
1708
1601
 
1709
- for (b = 0; b < a.length; ++b) {
1710
- c = a[b], a[b] = c >>> 24 | c >>> 8 & 0xff00 | (c & 0xff00) << 8 | c << 24;
1711
- }
1712
-
1713
- return a;
1714
- }
1715
- };
1716
- sjcl.codec.utf8String = {
1717
- fromBits: function fromBits(a) {
1718
- var b = "",
1719
- c = sjcl.bitArray.bitLength(a),
1720
- d,
1721
- e;
1722
-
1723
- for (d = 0; d < c / 8; d++) {
1724
- 0 === (d & 3) && (e = a[d / 4]), b += String.fromCharCode(e >>> 8 >>> 8 >>> 8), e <<= 8;
1725
- }
1726
-
1727
- return decodeURIComponent(escape(b));
1728
- },
1729
- toBits: function toBits(a) {
1730
- a = unescape(encodeURIComponent(a));
1731
- var b = [],
1732
- c,
1733
- d = 0;
1734
-
1735
- for (c = 0; c < a.length; c++) {
1736
- d = d << 8 | a.charCodeAt(c), 3 === (c & 3) && (b.push(d), d = 0);
1737
- }
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
+ };
1738
1610
 
1739
- c & 3 && b.push(sjcl.bitArray.partial(8 * (c & 3), d));
1740
- return b;
1611
+ this.message = message;
1741
1612
  }
1742
- };
1743
- sjcl.codec.hex = {
1744
- fromBits: function fromBits(a) {
1745
- var b = "",
1746
- 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
+ */
1747
1621
 
1748
- for (c = 0; c < a.length; c++) {
1749
- b += ((a[c] | 0) + 0xf00000000000).toString(16).substr(4);
1750
- }
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
+ */
1751
1646
 
1752
- return b.substr(0, sjcl.bitArray.bitLength(a) / 4);
1753
- },
1754
- toBits: function toBits(a) {
1755
- var b,
1756
- c = [],
1757
- d;
1758
- a = a.replace(/\s|0x/g, "");
1759
- d = a.length;
1760
- a = a + "00000000";
1761
-
1762
- for (b = 0; b < a.length; b += 8) {
1763
- c.push(parseInt(a.substr(b, 8), 16) ^ 0);
1764
- }
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
+ },
1765
1660
 
1766
- 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;
1767
1680
  }
1768
- };
1769
- sjcl.codec.base32 = {
1770
- B: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
1771
- X: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
1772
- BITS: 32,
1773
- BASE: 5,
1774
- REMAINING: 27,
1775
- fromBits: function fromBits(a, b, c) {
1776
- var d = sjcl.codec.base32.BASE,
1777
- e = sjcl.codec.base32.REMAINING,
1778
- f = "",
1779
- g = 0,
1780
- h = sjcl.codec.base32.B,
1781
- k = 0,
1782
- l = sjcl.bitArray.bitLength(a);
1783
- c && (h = sjcl.codec.base32.X);
1784
-
1785
- for (c = 0; f.length * d < l;) {
1786
- f += h.charAt((k ^ a[c] >>> g) >>> e), g < d ? (k = a[c] << d - g, g += e, c++) : (k <<= d, g -= d);
1787
- }
1788
-
1789
- for (; f.length & 7 && !b;) {
1790
- f += "=";
1791
- }
1792
-
1793
- return f;
1794
- },
1795
- toBits: function toBits(a, b) {
1796
- a = a.replace(/\s|=/g, "").toUpperCase();
1797
- var c = sjcl.codec.base32.BITS,
1798
- d = sjcl.codec.base32.BASE,
1799
- e = sjcl.codec.base32.REMAINING,
1800
- f = [],
1801
- g,
1802
- h = 0,
1803
- k = sjcl.codec.base32.B,
1804
- l = 0,
1805
- n,
1806
- m = "base32";
1807
- b && (k = sjcl.codec.base32.X, m = "base32hex");
1808
-
1809
- for (g = 0; g < a.length; g++) {
1810
- n = k.indexOf(a.charAt(g));
1811
-
1812
- if (0 > n) {
1813
- if (!b) try {
1814
- return sjcl.codec.base32hex.toBits(a);
1815
- } catch (p) {}
1816
- throw new sjcl.exception.invalid("this isn't " + m + "!");
1817
- }
1818
1681
 
1819
- h > e ? (h -= e, f.push(l ^ n >>> h), l = n << c - h) : (h += d, l ^= n << c - h);
1820
- }
1682
+ return x & (1 << blength) - 1;
1683
+ },
1821
1684
 
1822
- h & 56 && f.push(sjcl.bitArray.partial(h & 56, l, 1));
1823
- return f;
1824
- }
1825
- };
1826
- sjcl.codec.base32hex = {
1827
- fromBits: function fromBits(a, b) {
1828
- return sjcl.codec.base32.fromBits(a, b, 1);
1829
- },
1830
- toBits: function toBits(a) {
1831
- 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);
1832
1694
  }
1833
- };
1834
- sjcl.codec.base64 = {
1835
- B: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
1836
- fromBits: function fromBits(a, b, c) {
1837
- var d = "",
1838
- e = 0,
1839
- f = sjcl.codec.base64.B,
1840
- g = 0,
1841
- h = sjcl.bitArray.bitLength(a);
1842
- c && (f = f.substr(0, 62) + "-_");
1843
-
1844
- for (c = 0; 6 * d.length < h;) {
1845
- d += f.charAt((g ^ a[c] >>> e) >>> 26), 6 > e ? (g = a[c] << 6 - e, e += 26, c++) : (g <<= 6, e -= 6);
1846
- }
1847
1695
 
1848
- for (; d.length & 3 && !b;) {
1849
- d += "=";
1850
- }
1696
+ var last = a1[a1.length - 1],
1697
+ shift = sjcl.bitArray.getPartial(last);
1851
1698
 
1852
- return d;
1853
- },
1854
- toBits: function toBits(a, b) {
1855
- a = a.replace(/\s|=/g, "");
1856
- var c = [],
1857
- d,
1858
- e = 0,
1859
- f = sjcl.codec.base64.B,
1860
- g = 0,
1861
- h;
1862
- b && (f = f.substr(0, 62) + "-_");
1863
-
1864
- for (d = 0; d < a.length; d++) {
1865
- h = f.indexOf(a.charAt(d));
1866
- if (0 > h) throw new sjcl.exception.invalid("this isn't base64!");
1867
- 26 < e ? (e -= 26, c.push(g ^ h >>> e), g = h << 32 - e) : (e += 6, g ^= h << 32 - e);
1868
- }
1869
-
1870
- e & 56 && c.push(sjcl.bitArray.partial(e & 56, g, 1));
1871
- return c;
1872
- }
1873
- };
1874
- sjcl.codec.base64url = {
1875
- fromBits: function fromBits(a) {
1876
- return sjcl.codec.base64.fromBits(a, 1, 1);
1877
- },
1878
- toBits: function toBits(a) {
1879
- 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));
1880
1703
  }
1881
- };
1882
-
1883
- sjcl.hash.sha256 = function (a) {
1884
- this.b[0] || this.O();
1885
- a ? (this.F = a.F.slice(0), this.A = a.A.slice(0), this.l = a.l) : this.reset();
1886
- };
1887
-
1888
- sjcl.hash.sha256.hash = function (a) {
1889
- return new sjcl.hash.sha256().update(a).finalize();
1890
- };
1891
-
1892
- sjcl.hash.sha256.prototype = {
1893
- blockSize: 512,
1894
- reset: function reset() {
1895
- this.F = this.Y.slice(0);
1896
- this.A = [];
1897
- this.l = 0;
1898
- return this;
1899
- },
1900
- update: function update(a) {
1901
- "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a));
1902
- var b,
1903
- c = this.A = sjcl.bitArray.concat(this.A, a);
1904
- b = this.l;
1905
- a = this.l = b + sjcl.bitArray.bitLength(a);
1906
- if (0x1fffffffffffff < a) throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");
1907
-
1908
- if ("undefined" !== typeof Uint32Array) {
1909
- var d = new Uint32Array(c),
1910
- e = 0;
1911
-
1912
- for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) {
1913
- u(this, d.subarray(16 * e, 16 * (e + 1))), e += 1;
1914
- }
1915
-
1916
- c.splice(0, 16 * e);
1917
- } else for (b = 512 + b - (512 + b & 0x1ff); b <= a; b += 512) {
1918
- u(this, c.splice(0, 16));
1919
- }
1920
-
1921
- return this;
1922
- },
1923
- finalize: function finalize() {
1924
- var a,
1925
- b = this.A,
1926
- c = this.F,
1927
- b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1, 1)]);
1928
-
1929
- for (a = b.length + 2; a & 15; a++) {
1930
- b.push(0);
1931
- }
1932
-
1933
- b.push(Math.floor(this.l / 0x100000000));
1934
-
1935
- for (b.push(this.l | 0); b.length;) {
1936
- u(this, b.splice(0, 16));
1937
- }
1704
+ },
1938
1705
 
1939
- this.reset();
1940
- return c;
1941
- },
1942
- Y: [],
1943
- b: [],
1944
- O: function O() {
1945
- function a(a) {
1946
- return 0x100000000 * (a - Math.floor(a)) | 0;
1947
- }
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;
1948
1714
 
1949
- for (var b = 0, c = 2, d, e; 64 > b; c++) {
1950
- e = !0;
1715
+ if (l === 0) {
1716
+ return 0;
1717
+ }
1951
1718
 
1952
- for (d = 2; d * d <= c; d++) {
1953
- if (0 === c % d) {
1954
- e = !1;
1955
- break;
1956
- }
1957
- }
1719
+ x = a[l - 1];
1720
+ return (l - 1) * 32 + sjcl.bitArray.getPartial(x);
1721
+ },
1958
1722
 
1959
- e && (8 > b && (this.Y[b] = a(Math.pow(c, .5))), this.b[b] = a(Math.pow(c, 1 / 3)), b++);
1960
- }
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;
1961
1732
  }
1962
- };
1963
1733
 
1964
- function u(a, b) {
1965
- var c,
1966
- d,
1967
- e,
1968
- f = a.F,
1969
- g = a.b,
1970
- h = f[0],
1971
- k = f[1],
1972
- l = f[2],
1973
- n = f[3],
1974
- m = f[4],
1975
- p = f[5],
1976
- r = f[6],
1977
- q = f[7];
1978
-
1979
- for (c = 0; 64 > c; c++) {
1980
- 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;
1981
- }
1982
-
1983
- f[0] = f[0] + h | 0;
1984
- f[1] = f[1] + k | 0;
1985
- f[2] = f[2] + l | 0;
1986
- f[3] = f[3] + n | 0;
1987
- f[4] = f[4] + m | 0;
1988
- f[5] = f[5] + p | 0;
1989
- f[6] = f[6] + r | 0;
1990
- f[7] = f[7] + q | 0;
1991
- }
1992
-
1993
- sjcl.mode.ccm = {
1994
- name: "ccm",
1995
- G: [],
1996
- listenProgress: function listenProgress(a) {
1997
- sjcl.mode.ccm.G.push(a);
1998
- },
1999
- unListenProgress: function unListenProgress(a) {
2000
- a = sjcl.mode.ccm.G.indexOf(a);
2001
- -1 < a && sjcl.mode.ccm.G.splice(a, 1);
2002
- },
2003
- fa: function fa(a) {
2004
- var b = sjcl.mode.ccm.G.slice(),
2005
- c;
1734
+ a = a.slice(0, Math.ceil(len / 32));
1735
+ var l = a.length;
1736
+ len = len & 31;
2006
1737
 
2007
- for (c = 0; c < b.length; c += 1) {
2008
- b[c](a);
2009
- }
2010
- },
2011
- encrypt: function encrypt(a, b, c, d, e) {
2012
- var f,
2013
- g = b.slice(0),
2014
- h = sjcl.bitArray,
2015
- k = h.bitLength(c) / 8,
2016
- l = h.bitLength(g) / 8;
2017
- e = e || 64;
2018
- d = d || [];
2019
- if (7 > k) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");
2020
-
2021
- for (f = 2; 4 > f && l >>> 8 * f; f++) {
2022
- }
1738
+ if (l > 0 && len) {
1739
+ a[l - 1] = sjcl.bitArray.partial(len, a[l - 1] & 0x80000000 >> len - 1, 1);
1740
+ }
2023
1741
 
2024
- f < 15 - k && (f = 15 - k);
2025
- c = h.clamp(c, 8 * (15 - f));
2026
- b = sjcl.mode.ccm.V(a, b, c, d, e, f);
2027
- g = sjcl.mode.ccm.C(a, g, c, b, e, f);
2028
- return h.concat(g.data, g.tag);
2029
- },
2030
- decrypt: function decrypt(a, b, c, d, e) {
2031
- e = e || 64;
2032
- d = d || [];
2033
- var f = sjcl.bitArray,
2034
- g = f.bitLength(c) / 8,
2035
- h = f.bitLength(b),
2036
- k = f.clamp(b, h - e),
2037
- l = f.bitSlice(b, h - e),
2038
- h = (h - e) / 8;
2039
- if (7 > g) throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");
2040
-
2041
- for (b = 2; 4 > b && h >>> 8 * b; b++) {
2042
- }
1742
+ return a;
1743
+ },
2043
1744
 
2044
- b < 15 - g && (b = 15 - g);
2045
- c = f.clamp(c, 8 * (15 - b));
2046
- k = sjcl.mode.ccm.C(a, k, c, l, e, b);
2047
- a = sjcl.mode.ccm.V(a, k.data, c, d, e, b);
2048
- if (!f.equal(k.tag, a)) throw new sjcl.exception.corrupt("ccm: tag doesn't match");
2049
- return k.data;
2050
- },
2051
- na: function na(a, b, c, d, e, f) {
2052
- var g = [],
2053
- h = sjcl.bitArray,
2054
- k = h.i;
2055
- d = [h.partial(8, (b.length ? 64 : 0) | d - 2 << 2 | f - 1)];
2056
- d = h.concat(d, c);
2057
- d[3] |= e;
2058
- d = a.encrypt(d);
2059
- 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) {
2060
- d = a.encrypt(k(d, g.slice(b, b + 4).concat([0, 0, 0])));
2061
- }
2062
- return d;
2063
- },
2064
- V: function V(a, b, c, d, e, f) {
2065
- var g = sjcl.bitArray,
2066
- h = g.i;
2067
- e /= 8;
2068
- if (e % 2 || 4 > e || 16 < e) throw new sjcl.exception.invalid("ccm: invalid tag length");
2069
- if (0xffffffff < d.length || 0xffffffff < b.length) throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");
2070
- c = sjcl.mode.ccm.na(a, d, c, e, g.bitLength(b) / 8, f);
2071
-
2072
- for (d = 0; d < b.length; d += 4) {
2073
- c = a.encrypt(h(c, b.slice(d, d + 4).concat([0, 0, 0])));
2074
- }
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
+ }
2075
1756
 
2076
- return g.clamp(c, 8 * e);
2077
- },
2078
- C: function C(a, b, c, d, e, f) {
2079
- var g,
2080
- h = sjcl.bitArray;
2081
- g = h.i;
2082
- var k = b.length,
2083
- l = h.bitLength(b),
2084
- n = k / 50,
2085
- m = n;
2086
- c = h.concat([h.partial(8, f - 1)], c).concat([0, 0, 0]).slice(0, 4);
2087
- d = h.bitSlice(g(d, a.encrypt(c)), 0, e);
2088
- if (!k) return {
2089
- tag: d,
2090
- data: []
2091
- };
1757
+ return (_end ? x | 0 : x << 32 - len) + len * 0x10000000000;
1758
+ },
2092
1759
 
2093
- for (g = 0; g < k; g += 4) {
2094
- 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];
2095
- }
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
+ },
2096
1768
 
2097
- return {
2098
- tag: d,
2099
- data: h.clamp(b, l)
2100
- };
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;
2101
1778
  }
2102
- };
2103
- sjcl.mode.ocb2 = {
2104
- name: "ocb2",
2105
- encrypt: function encrypt(a, b, c, d, e, f) {
2106
- if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits");
2107
- var g,
2108
- h = sjcl.mode.ocb2.S,
2109
- k = sjcl.bitArray,
2110
- l = k.i,
2111
- n = [0, 0, 0, 0];
2112
- c = h(a.encrypt(c));
2113
- var m,
2114
- p = [];
2115
- d = d || [];
2116
- e = e || 64;
2117
-
2118
- for (g = 0; g + 4 < b.length; g += 4) {
2119
- m = b.slice(g, g + 4), n = l(n, m), p = p.concat(l(c, a.encrypt(l(c, m)))), c = h(c);
2120
- }
2121
1779
 
2122
- m = b.slice(g);
2123
- b = k.bitLength(m);
2124
- g = a.encrypt(l(c, [0, 0, 0, b]));
2125
- m = k.clamp(l(m.concat([0, 0, 0]), g), b);
2126
- n = l(n, l(m.concat([0, 0, 0]), g));
2127
- n = a.encrypt(l(n, l(c, h(c))));
2128
- d.length && (n = l(n, f ? d : sjcl.mode.ocb2.pmac(a, d)));
2129
- return p.concat(k.concat(m, k.clamp(n, e)));
2130
- },
2131
- decrypt: function decrypt(a, b, c, d, e, f) {
2132
- if (128 !== sjcl.bitArray.bitLength(c)) throw new sjcl.exception.invalid("ocb iv must be 128 bits");
2133
- e = e || 64;
2134
- var g = sjcl.mode.ocb2.S,
2135
- h = sjcl.bitArray,
2136
- k = h.i,
2137
- l = [0, 0, 0, 0],
2138
- n = g(a.encrypt(c)),
2139
- m,
2140
- p,
2141
- r = sjcl.bitArray.bitLength(b) - e,
2142
- q = [];
2143
- d = d || [];
2144
-
2145
- for (c = 0; c + 4 < r / 32; c += 4) {
2146
- m = k(n, a.decrypt(k(n, b.slice(c, c + 4)))), l = k(l, m), q = q.concat(m), n = g(n);
2147
- }
1780
+ var x = 0,
1781
+ i;
2148
1782
 
2149
- p = r - 32 * c;
2150
- m = a.encrypt(k(n, [0, 0, 0, p]));
2151
- m = k(m, h.clamp(b.slice(c), p).concat([0, 0, 0]));
2152
- l = k(l, m);
2153
- l = a.encrypt(k(l, k(n, g(n))));
2154
- d.length && (l = k(l, f ? d : sjcl.mode.ocb2.pmac(a, d)));
2155
- if (!h.equal(h.clamp(l, e), h.bitSlice(b, r))) throw new sjcl.exception.corrupt("ocb: tag doesn't match");
2156
- return q.concat(h.clamp(m, p));
2157
- },
2158
- pmac: function pmac(a, b) {
2159
- var c,
2160
- d = sjcl.mode.ocb2.S,
2161
- e = sjcl.bitArray,
2162
- f = e.i,
2163
- g = [0, 0, 0, 0],
2164
- h = a.encrypt([0, 0, 0, 0]),
2165
- h = f(h, d(d(h)));
2166
-
2167
- for (c = 0; c + 4 < b.length; c += 4) {
2168
- h = d(h), g = f(g, a.encrypt(f(h, b.slice(c, c + 4))));
2169
- }
2170
-
2171
- c = b.slice(c);
2172
- 128 > e.bitLength(c) && (h = f(h, d(h)), c = e.concat(c, [-2147483648, 0, 0, 0]));
2173
- g = f(g, c);
2174
- return a.encrypt(f(d(f(h, d(h))), g));
2175
- },
2176
- S: function S(a) {
2177
- 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];
2178
1785
  }
2179
- };
2180
- sjcl.mode.gcm = {
2181
- name: "gcm",
2182
- encrypt: function encrypt(a, b, c, d, e) {
2183
- var f = b.slice(0);
2184
- b = sjcl.bitArray;
2185
- d = d || [];
2186
- a = sjcl.mode.gcm.C(!0, a, f, d, c, e || 128);
2187
- return b.concat(a.data, a.tag);
2188
- },
2189
- decrypt: function decrypt(a, b, c, d, e) {
2190
- var f = b.slice(0),
2191
- g = sjcl.bitArray,
2192
- h = g.bitLength(f);
2193
- e = e || 128;
2194
- d = d || [];
2195
- e <= h ? (b = g.bitSlice(f, h - e), f = g.bitSlice(f, 0, h - e)) : (b = f, f = []);
2196
- a = sjcl.mode.gcm.C(!1, a, f, d, c, e);
2197
- if (!g.equal(a.tag, b)) throw new sjcl.exception.corrupt("gcm: tag doesn't match");
2198
- return a.data;
2199
- },
2200
- ka: function ka(a, b) {
2201
- var c,
2202
- d,
2203
- e,
2204
- f,
2205
- g,
2206
- h = sjcl.bitArray.i;
2207
- e = [0, 0, 0, 0];
2208
- f = b.slice(0);
2209
-
2210
- for (c = 0; 128 > c; c++) {
2211
- (d = 0 !== (a[Math.floor(c / 32)] & 1 << 31 - c % 32)) && (e = h(e, f));
2212
- g = 0 !== (f[3] & 1);
2213
-
2214
- for (d = 3; 0 < d; d--) {
2215
- f[d] = f[d] >>> 1 | (f[d - 1] & 1) << 31;
2216
- }
2217
1786
 
2218
- f[0] >>>= 1;
2219
- g && (f[0] ^= -0x1f000000);
2220
- }
2221
-
2222
- return e;
2223
- },
2224
- j: function j(a, b, c) {
2225
- var d,
2226
- e = c.length;
2227
- b = b.slice(0);
1787
+ return x === 0;
1788
+ },
2228
1789
 
2229
- for (d = 0; d < e; d += 4) {
2230
- 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);
2231
- }
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;
2232
1801
 
2233
- return b;
2234
- },
2235
- C: function C(a, b, c, d, e, f) {
2236
- var g,
2237
- h,
2238
- k,
2239
- l,
2240
- n,
2241
- m,
2242
- p,
2243
- r,
2244
- q = sjcl.bitArray;
2245
- m = c.length;
2246
- p = q.bitLength(c);
2247
- r = q.bitLength(d);
2248
- h = q.bitLength(e);
2249
- g = b.encrypt([0, 0, 0, 0]);
2250
- 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]));
2251
- h = sjcl.mode.gcm.j(g, [0, 0, 0, 0], d);
2252
- n = e.slice(0);
2253
- d = h.slice(0);
2254
- a || (d = sjcl.mode.gcm.j(g, h, c));
2255
-
2256
- for (l = 0; l < m; l += 4) {
2257
- 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];
2258
- }
1802
+ if (out === undefined) {
1803
+ out = [];
1804
+ }
2259
1805
 
2260
- c = q.clamp(c, p);
2261
- a && (d = sjcl.mode.gcm.j(g, h, c));
2262
- a = [Math.floor(r / 0x100000000), r & 0xffffffff, Math.floor(p / 0x100000000), p & 0xffffffff];
2263
- d = sjcl.mode.gcm.j(g, d, a);
2264
- k = b.encrypt(e);
2265
- d[0] ^= k[0];
2266
- d[1] ^= k[1];
2267
- d[2] ^= k[2];
2268
- d[3] ^= k[3];
2269
- return {
2270
- tag: q.bitSlice(d, 0, f),
2271
- data: c
2272
- };
1806
+ for (; shift >= 32; shift -= 32) {
1807
+ out.push(carry);
1808
+ carry = 0;
2273
1809
  }
2274
- };
2275
1810
 
2276
- sjcl.misc.hmac = function (a, b) {
2277
- this.W = b = b || sjcl.hash.sha256;
2278
- var c = [[], []],
2279
- d,
2280
- e = b.prototype.blockSize / 32;
2281
- this.w = [new b(), new b()];
2282
- a.length > e && (a = b.hash(a));
1811
+ if (shift === 0) {
1812
+ return out.concat(a);
1813
+ }
2283
1814
 
2284
- for (d = 0; d < e; d++) {
2285
- 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;
2286
1818
  }
2287
1819
 
2288
- this.w[0].update(c[0]);
2289
- this.w[1].update(c[1]);
2290
- this.R = new b(this.w[0]);
2291
- };
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
+ },
2292
1825
 
2293
- sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (a) {
2294
- if (this.aa) throw new sjcl.exception.invalid("encrypt on already updated hmac called!");
2295
- this.update(a);
2296
- return this.digest(a);
2297
- };
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
+ },
2298
1832
 
2299
- sjcl.misc.hmac.prototype.reset = function () {
2300
- this.R = new this.W(this.w[0]);
2301
- this.aa = !1;
2302
- };
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;
2303
1842
 
2304
- sjcl.misc.hmac.prototype.update = function (a) {
2305
- this.aa = !0;
2306
- this.R.update(a);
2307
- };
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
+ }
2308
1847
 
2309
- sjcl.misc.hmac.prototype.digest = function () {
2310
- var a = this.R.finalize(),
2311
- a = new this.W(this.w[1]).update(a).finalize();
2312
- this.reset();
2313
1848
  return a;
2314
- };
1849
+ }
1850
+ };
1851
+ /** @fileOverview Bit array codec implementations.
1852
+ *
1853
+ * @author Emily Stark
1854
+ * @author Mike Hamburg
1855
+ * @author Dan Boneh
1856
+ */
2315
1857
 
2316
- sjcl.misc.pbkdf2 = function (a, b, c, d, e) {
2317
- c = c || 1E4;
2318
- if (0 > d || 0 > c) throw new sjcl.exception.invalid("invalid params to pbkdf2");
2319
- "string" === typeof a && (a = sjcl.codec.utf8String.toBits(a));
2320
- "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b));
2321
- e = e || sjcl.misc.hmac;
2322
- a = new e(a);
2323
- var f,
2324
- g,
2325
- h,
2326
- k,
2327
- l = [],
2328
- n = sjcl.bitArray;
2329
-
2330
- for (k = 1; 32 * l.length < (d || 1); k++) {
2331
- e = f = a.encrypt(n.concat(b, [k]));
2332
-
2333
- for (g = 1; g < c; g++) {
2334
- for (f = a.encrypt(f), h = 0; h < f.length; h++) {
2335
- e[h] ^= f[h];
2336
- }
2337
- }
1858
+ /**
1859
+ * UTF-8 strings
1860
+ * @namespace
1861
+ */
2338
1862
 
2339
- l = l.concat(e);
2340
- }
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;
2341
1870
 
2342
- d && (l = n.clamp(l, d));
2343
- return l;
2344
- };
1871
+ for (i = 0; i < bl / 8; i++) {
1872
+ if ((i & 3) === 0) {
1873
+ tmp = arr[i / 4];
1874
+ }
2345
1875
 
2346
- sjcl.prng = function (a) {
2347
- this.c = [new sjcl.hash.sha256()];
2348
- this.m = [0];
2349
- this.P = 0;
2350
- this.H = {};
2351
- this.N = 0;
2352
- this.U = {};
2353
- this.Z = this.f = this.o = this.ha = 0;
2354
- this.b = [0, 0, 0, 0, 0, 0, 0, 0];
2355
- this.h = [0, 0, 0, 0];
2356
- this.L = void 0;
2357
- this.M = a;
2358
- this.D = !1;
2359
- this.K = {
2360
- progress: {},
2361
- seeded: {}
2362
- };
2363
- this.u = this.ga = 0;
2364
- this.I = 1;
2365
- this.J = 2;
2366
- this.ca = 0x10000;
2367
- this.T = [0, 48, 64, 96, 128, 192, 0x100, 384, 512, 768, 1024];
2368
- this.da = 3E4;
2369
- this.ba = 80;
2370
- };
1876
+ out += String.fromCharCode(tmp >>> 8 >>> 8 >>> 8);
1877
+ tmp <<= 8;
1878
+ }
2371
1879
 
2372
- sjcl.prng.prototype = {
2373
- randomWords: function randomWords(a, b) {
2374
- var c = [],
2375
- d;
2376
- d = this.isReady(b);
2377
- var e;
2378
- if (d === this.u) throw new sjcl.exception.notReady("generator isn't seeded");
2379
-
2380
- if (d & this.J) {
2381
- d = !(d & this.I);
2382
- e = [];
2383
- var f = 0,
2384
- g;
2385
- this.Z = e[0] = new Date().valueOf() + this.da;
2386
-
2387
- for (g = 0; 16 > g; g++) {
2388
- e.push(0x100000000 * Math.random() | 0);
2389
- }
1880
+ return decodeURIComponent(escape(out));
1881
+ },
2390
1882
 
2391
- 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++) {
2392
- }
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;
2393
1889
 
2394
- this.P >= 1 << this.c.length && (this.c.push(new sjcl.hash.sha256()), this.m.push(0));
2395
- this.f -= f;
2396
- f > this.o && (this.o = f);
2397
- this.P++;
2398
- this.b = sjcl.hash.sha256.hash(this.b.concat(e));
2399
- this.L = new sjcl.cipher.aes(this.b);
1890
+ for (i = 0; i < str.length; i++) {
1891
+ tmp = tmp << 8 | str.charCodeAt(i);
2400
1892
 
2401
- for (d = 0; 4 > d && (this.h[d] = this.h[d] + 1 | 0, !this.h[d]); d++) {
2402
- }
1893
+ if ((i & 3) === 3) {
1894
+ out.push(tmp);
1895
+ tmp = 0;
2403
1896
  }
1897
+ }
2404
1898
 
2405
- for (d = 0; d < a; d += 4) {
2406
- 0 === (d + 1) % this.ca && y(this), e = z(this), c.push(e[0], e[1], e[2], e[3]);
2407
- }
1899
+ if (i & 3) {
1900
+ out.push(sjcl.bitArray.partial(8 * (i & 3), tmp));
1901
+ }
2408
1902
 
2409
- y(this);
2410
- return c.slice(0, a);
2411
- },
2412
- setDefaultParanoia: function setDefaultParanoia(a, b) {
2413
- 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");
2414
- this.M = a;
2415
- },
2416
- addEntropy: function addEntropy(a, b, c) {
2417
- c = c || "user";
2418
- var d,
2419
- e,
2420
- f = new Date().valueOf(),
2421
- g = this.H[c],
2422
- h = this.isReady(),
2423
- k = 0;
2424
- d = this.U[c];
2425
- void 0 === d && (d = this.U[c] = this.ha++);
2426
- void 0 === g && (g = this.H[c] = 0);
2427
- this.H[c] = (this.H[c] + 1) % this.c.length;
2428
-
2429
- switch (_typeof(a)) {
2430
- case "number":
2431
- void 0 === b && (b = 1);
2432
- this.c[g].update([d, this.N++, 1, b, f, 1, a | 0]);
2433
- 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
+ */
2434
1920
 
2435
- case "object":
2436
- c = Object.prototype.toString.call(a);
1921
+ /**
1922
+ * Context for a SHA-256 operation in progress.
1923
+ * @constructor
1924
+ */
2437
1925
 
2438
- if ("[object Uint32Array]" === c) {
2439
- e = [];
1926
+ sjcl.hash.sha256 = function (hash) {
1927
+ if (!this._key[0]) {
1928
+ this._precompute();
1929
+ }
2440
1930
 
2441
- for (c = 0; c < a.length; c++) {
2442
- e.push(a[c]);
2443
- }
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
+ */
2444
1945
 
2445
- a = e;
2446
- } else for ("[object Array]" !== c && (k = 1), c = 0; c < a.length && !k; c++) {
2447
- "number" !== typeof a[c] && (k = 1);
2448
- }
2449
1946
 
2450
- if (!k) {
2451
- if (void 0 === b) for (c = b = 0; c < a.length; c++) {
2452
- for (e = a[c]; 0 < e;) {
2453
- b++, e = e >>> 1;
2454
- }
2455
- }
2456
- this.c[g].update([d, this.N++, 2, b, f, a.length].concat(a));
2457
- }
1947
+ sjcl.hash.sha256.hash = function (data) {
1948
+ return new sjcl.hash.sha256().update(data).finalize();
1949
+ };
2458
1950
 
2459
- break;
1951
+ sjcl.hash.sha256.prototype = {
1952
+ /**
1953
+ * The hash's block size, in bits.
1954
+ * @constant
1955
+ */
1956
+ blockSize: 512,
2460
1957
 
2461
- case "string":
2462
- void 0 === b && (b = a.length);
2463
- this.c[g].update([d, this.N++, 3, b, f, a.length]);
2464
- this.c[g].update(a);
2465
- 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
+ },
2466
1968
 
2467
- default:
2468
- k = 1;
2469
- }
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
+ }
2470
1978
 
2471
- if (k) throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");
2472
- this.m[g] += b;
2473
- this.f += b;
2474
- h === this.u && (this.isReady() !== this.u && A("seeded", Math.max(this.o, this.f)), A("progress", this.getProgress()));
2475
- },
2476
- isReady: function isReady(a) {
2477
- a = this.T[void 0 !== a ? a : this.M];
2478
- 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;
2479
- },
2480
- getProgress: function getProgress(a) {
2481
- a = this.T[a ? a : this.M];
2482
- return this.o >= a ? 1 : this.f > a ? 1 : this.f / a;
2483
- },
2484
- startCollectors: function startCollectors() {
2485
- if (!this.D) {
2486
- this.a = {
2487
- loadTimeCollector: B(this, this.ma),
2488
- mouseCollector: B(this, this.oa),
2489
- keyboardCollector: B(this, this.la),
2490
- accelerometerCollector: B(this, this.ea),
2491
- touchCollector: B(this, this.qa)
2492
- };
2493
- 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");
2494
- this.D = !0;
2495
- }
2496
- },
2497
- stopCollectors: function stopCollectors() {
2498
- 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);
2499
- },
2500
- addEventListener: function addEventListener(a, b) {
2501
- this.K[a][this.ga++] = b;
2502
- },
2503
- removeEventListener: function removeEventListener(a, b) {
2504
- var c,
2505
- d,
2506
- e = this.K[a],
2507
- f = [];
2508
-
2509
- for (d in e) {
2510
- e.hasOwnProperty(d) && e[d] === b && f.push(d);
2511
- }
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);
2512
1983
 
2513
- for (c = 0; c < f.length; c++) {
2514
- d = f[c], delete e[d];
2515
- }
2516
- },
2517
- la: function la() {
2518
- C(this, 1);
2519
- },
2520
- oa: function oa(a) {
2521
- var b, c;
1984
+ if (nl > 9007199254740991) {
1985
+ throw new sjcl.exception.invalid('Cannot hash more than 2^53 - 1 bits');
1986
+ }
2522
1987
 
2523
- try {
2524
- b = a.x || a.clientX || a.offsetX || 0, c = a.y || a.clientY || a.offsetY || 0;
2525
- } catch (d) {
2526
- c = b = 0;
2527
- }
1988
+ if (typeof Uint32Array !== 'undefined') {
1989
+ var c = new Uint32Array(b);
1990
+ var j = 0;
2528
1991
 
2529
- 0 != b && 0 != c && this.addEntropy([b, c], 2, "mouse");
2530
- C(this, 0);
2531
- },
2532
- qa: function qa(a) {
2533
- a = a.touches[0] || a.changedTouches[0];
2534
- this.addEntropy([a.pageX || a.clientX, a.pageY || a.clientY], 1, "touch");
2535
- C(this, 0);
2536
- },
2537
- ma: function ma() {
2538
- C(this, 2);
2539
- },
2540
- ea: function ea(a) {
2541
- 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)));
2542
1994
 
2543
- if (window.orientation) {
2544
- var b = window.orientation;
2545
- "number" === typeof b && this.addEntropy(b, 1, "accelerometer");
1995
+ j += 1;
2546
1996
  }
2547
1997
 
2548
- a && this.addEntropy(a, 2, "accelerometer");
2549
- 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
+ }
2550
2003
  }
2551
- };
2552
2004
 
2553
- function A(a, b) {
2554
- var c,
2555
- d = sjcl.random.K[a],
2556
- e = [];
2005
+ return this;
2006
+ },
2557
2007
 
2558
- for (c in d) {
2559
- d.hasOwnProperty(c) && e.push(d[c]);
2560
- }
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
2561
2016
 
2562
- for (c = 0; c < e.length; c++) {
2563
- e[c](b);
2564
- }
2565
- }
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.
2566
2018
 
2567
- function C(a, b) {
2568
- "undefined" !== typeof window && window.performance && "function" === typeof window.performance.now ? a.addEntropy(window.performance.now(), b, "loadtime") : a.addEntropy(new Date().valueOf(), b, "loadtime");
2569
- }
2019
+ for (i = b.length + 2; i & 15; i++) {
2020
+ b.push(0);
2021
+ } // append the length
2570
2022
 
2571
- function y(a) {
2572
- a.b = z(a).concat(z(a));
2573
- a.L = new sjcl.cipher.aes(a.b);
2574
- }
2575
2023
 
2576
- function z(a) {
2577
- for (var b = 0; 4 > b && (a.h[b] = a.h[b] + 1 | 0, !a.h[b]); b++) {
2578
- }
2024
+ b.push(Math.floor(this._length / 0x100000000));
2025
+ b.push(this._length | 0);
2579
2026
 
2580
- return a.L.encrypt(a.h);
2581
- }
2582
-
2583
- function B(a, b) {
2584
- return function () {
2585
- b.apply(a, arguments);
2586
- };
2587
- }
2027
+ while (b.length) {
2028
+ this._block(b.splice(0, 16));
2029
+ }
2588
2030
 
2589
- sjcl.random = new sjcl.prng(6);
2031
+ this.reset();
2032
+ return h;
2033
+ },
2590
2034
 
2591
- a: try {
2592
- var D, E, F, G;
2035
+ /**
2036
+ * The SHA-256 initialization vector, to be precomputed.
2037
+ * @private
2038
+ */
2039
+ _init: [],
2593
2040
 
2594
- if (G = "undefined" !== 'object' && module.exports) {
2595
- var H;
2041
+ /*
2042
+ _init:[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19],
2043
+ */
2596
2044
 
2597
- try {
2598
- H = require$$0__default['default'];
2599
- } catch (a) {
2600
- H = null;
2601
- }
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
+ */
2602
2062
 
2603
- G = E = H;
2604
- }
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;
2605
2072
 
2606
- 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) {
2607
- F = new Uint32Array(32);
2608
- if (window.crypto && window.crypto.getRandomValues) window.crypto.getRandomValues(F);else if (window.msCrypto && window.msCrypto.getRandomValues) window.msCrypto.getRandomValues(F);else break a;
2609
- sjcl.random.addEntropy(F, 1024, "crypto['getRandomValues']");
2073
+ function frac(x) {
2074
+ return (x - Math.floor(x)) * 0x100000000 | 0;
2610
2075
  }
2611
- } catch (a) {
2612
- "undefined" !== typeof window && window.console && (console.log("There was an error collecting entropy from the browser:"), console.log(a));
2613
- }
2614
2076
 
2615
- sjcl.json = {
2616
- defaults: {
2617
- v: 1,
2618
- iter: 1E4,
2619
- ks: 128,
2620
- ts: 64,
2621
- mode: "ccm",
2622
- adata: "",
2623
- cipher: "aes"
2624
- },
2625
- ja: function ja(a, b, c, d) {
2626
- c = c || {};
2627
- d = d || {};
2628
- var e = sjcl.json,
2629
- f = e.g({
2630
- iv: sjcl.random.randomWords(4, 0)
2631
- }, e.defaults),
2632
- g;
2633
- e.g(f, c);
2634
- c = f.adata;
2635
- "string" === typeof f.salt && (f.salt = sjcl.codec.base64.toBits(f.salt));
2636
- "string" === typeof f.iv && (f.iv = sjcl.codec.base64.toBits(f.iv));
2637
- 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");
2638
- "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));
2639
- "string" === typeof b && (b = sjcl.codec.utf8String.toBits(b));
2640
- "string" === typeof c && (f.adata = c = sjcl.codec.utf8String.toBits(c));
2641
- g = new sjcl.cipher[f.cipher](a);
2642
- e.g(d, f);
2643
- d.key = a;
2644
- 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);
2645
- return f;
2646
- },
2647
- encrypt: function encrypt(a, b, c, d) {
2648
- var e = sjcl.json,
2649
- f = e.ja.apply(e, arguments);
2650
- return e.encode(f);
2651
- },
2652
- ia: function ia(a, b, c, d) {
2653
- c = c || {};
2654
- d = d || {};
2655
- var e = sjcl.json;
2656
- b = e.g(e.g(e.g({}, e.defaults), b), c, !0);
2657
- var f, g;
2658
- f = b.adata;
2659
- "string" === typeof b.salt && (b.salt = sjcl.codec.base64.toBits(b.salt));
2660
- "string" === typeof b.iv && (b.iv = sjcl.codec.base64.toBits(b.iv));
2661
- 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");
2662
- "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));
2663
- "string" === typeof f && (f = sjcl.codec.utf8String.toBits(f));
2664
- g = new sjcl.cipher[b.cipher](a);
2665
- 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);
2666
- e.g(d, b);
2667
- d.key = a;
2668
- return 1 === c.raw ? f : sjcl.codec.utf8String.fromBits(f);
2669
- },
2670
- decrypt: function decrypt(a, b, c, d) {
2671
- var e = sjcl.json;
2672
- return e.ia(a, e.decode(b), c, d);
2673
- },
2674
- encode: function encode(a) {
2675
- var b,
2676
- c = "{",
2677
- d = "";
2678
-
2679
- for (b in a) {
2680
- if (a.hasOwnProperty(b)) {
2681
- if (!b.match(/^[a-z0-9]+$/i)) throw new sjcl.exception.invalid("json encode: invalid property name");
2682
- c += d + '"' + b + '":';
2683
- d = ",";
2684
-
2685
- switch (_typeof(a[b])) {
2686
- case "number":
2687
- case "boolean":
2688
- c += a[b];
2689
- break;
2690
-
2691
- case "string":
2692
- c += '"' + escape(a[b]) + '"';
2693
- break;
2694
-
2695
- case "object":
2696
- c += '"' + sjcl.codec.base64.fromBits(a[b], 0) + '"';
2697
- break;
2077
+ for (; i < 64; prime++) {
2078
+ isPrime = true;
2698
2079
 
2699
- default:
2700
- throw new sjcl.exception.bug("json encode: unsupported type");
2701
- }
2080
+ for (factor = 2; factor * factor <= prime; factor++) {
2081
+ if (prime % factor === 0) {
2082
+ isPrime = false;
2083
+ break;
2702
2084
  }
2703
2085
  }
2704
2086
 
2705
- return c + "}";
2706
- },
2707
- decode: function decode(a) {
2708
- a = a.replace(/\s/g, "");
2709
- if (!a.match(/^\{.*\}$/)) throw new sjcl.exception.invalid("json decode: this isn't json!");
2710
- a = a.replace(/^\{|\}$/g, "").split(/,/);
2711
- var b = {},
2712
- c,
2713
- d;
2714
-
2715
- for (c = 0; c < a.length; c++) {
2716
- 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!");
2717
- 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]);
2718
- }
2719
-
2720
- return b;
2721
- },
2722
- g: function g(a, b, c) {
2723
- void 0 === a && (a = {});
2724
- if (void 0 === b) return a;
2725
-
2726
- for (var d in b) {
2727
- if (b.hasOwnProperty(d)) {
2728
- if (c && void 0 !== a[d] && a[d] !== b[d]) throw new sjcl.exception.invalid("required parameter overridden");
2729
- a[d] = b[d];
2087
+ if (isPrime) {
2088
+ if (i < 8) {
2089
+ this._init[i] = frac(Math.pow(prime, 1 / 2));
2730
2090
  }
2731
- }
2732
-
2733
- return a;
2734
- },
2735
- sa: function sa(a, b) {
2736
- var c = {},
2737
- d;
2738
2091
 
2739
- for (d in a) {
2740
- a.hasOwnProperty(d) && a[d] !== b[d] && (c[d] = a[d]);
2092
+ this._key[i] = frac(Math.pow(prime, 1 / 3));
2093
+ i++;
2741
2094
  }
2095
+ }
2096
+ },
2742
2097
 
2743
- return c;
2744
- },
2745
- ra: function ra(a, b) {
2746
- var c = {},
2747
- 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
+ */
2748
2131
 
2749
- for (d = 0; d < b.length; d++) {
2750
- 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;
2751
2140
  }
2752
2141
 
2753
- 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;
2754
2153
  }
2755
- };
2756
- sjcl.encrypt = sjcl.json.encrypt;
2757
- sjcl.decrypt = sjcl.json.decrypt;
2758
- sjcl.misc.pa = {};
2759
-
2760
- sjcl.misc.cachedPbkdf2 = function (a, b) {
2761
- var c = sjcl.misc.pa,
2762
- d;
2763
- b = b || {};
2764
- d = b.iter || 1E3;
2765
- c = c[a] = c[a] || {};
2766
- d = c[d] = c[d] || {
2767
- firstSalt: b.salt && b.salt.length ? b.salt.slice(0) : sjcl.random.randomWords(2, 0)
2768
- };
2769
- c = void 0 === b.salt ? d.firstSalt : b.salt;
2770
- d[c] = d[c] || sjcl.misc.pbkdf2(a, c, b.iter);
2771
- return {
2772
- key: d[c].slice(0),
2773
- salt: c.slice(0)
2774
- };
2775
- };
2776
2154
 
2777
- module.exports && (module.exports = sjcl);
2778
- });
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
+ };
2779
2165
 
2780
2166
  // eslint-disable-next-line require-jsdoc
2781
2167
  function base64URLEncode(str) {
@@ -2944,7 +2330,7 @@
2944
2330
 
2945
2331
  switch (localOptions.pkce.code_challange_method) {
2946
2332
  case 'S256':
2947
- var codeChallenge = sjcl_1.hash.sha256.hash(codeVerifier);
2333
+ var codeChallenge = sjcl.hash.sha256.hash(codeVerifier);
2948
2334
  Object.assign(params, {
2949
2335
  code_verifier: codeVerifier,
2950
2336
  code_challenge: encoding.base64URLEncode(codeChallenge),