@protontech/openpgp 6.0.0-beta.0.patch.0 → 6.0.0-beta.2

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.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/dist/lightweight/argon2id.min.mjs +2 -2
  3. package/dist/lightweight/argon2id.min.mjs.map +1 -1
  4. package/dist/lightweight/argon2id.mjs +5 -28
  5. package/dist/lightweight/legacy_ciphers.min.mjs +2 -2
  6. package/dist/lightweight/legacy_ciphers.min.mjs.map +1 -1
  7. package/dist/lightweight/legacy_ciphers.mjs +6 -51
  8. package/dist/lightweight/noble_curves.min.mjs +11 -11
  9. package/dist/lightweight/noble_curves.min.mjs.map +1 -1
  10. package/dist/lightweight/noble_curves.mjs +477 -465
  11. package/dist/lightweight/noble_hashes.min.mjs +2 -2
  12. package/dist/lightweight/noble_hashes.min.mjs.map +1 -1
  13. package/dist/lightweight/noble_hashes.mjs +19 -31
  14. package/dist/lightweight/openpgp.min.mjs +3 -2
  15. package/dist/lightweight/openpgp.min.mjs.map +1 -1
  16. package/dist/lightweight/openpgp.mjs +1529 -552
  17. package/dist/lightweight/sha3.min.mjs +3 -3
  18. package/dist/lightweight/sha3.min.mjs.map +1 -1
  19. package/dist/lightweight/sha3.mjs +80 -80
  20. package/dist/node/openpgp.cjs +2199 -5545
  21. package/dist/node/openpgp.min.cjs +12 -12
  22. package/dist/node/openpgp.min.cjs.map +1 -1
  23. package/dist/node/openpgp.min.mjs +12 -12
  24. package/dist/node/openpgp.min.mjs.map +1 -1
  25. package/dist/node/openpgp.mjs +2198 -5545
  26. package/dist/openpgp.js +2188 -5542
  27. package/dist/openpgp.min.js +12 -12
  28. package/dist/openpgp.min.js.map +1 -1
  29. package/dist/openpgp.min.mjs +12 -12
  30. package/dist/openpgp.min.mjs.map +1 -1
  31. package/dist/openpgp.mjs +2188 -5542
  32. package/openpgp.d.ts +69 -61
  33. package/package.json +20 -13
  34. package/dist/lightweight/bn.interface.min.mjs +0 -3
  35. package/dist/lightweight/bn.interface.min.mjs.map +0 -1
  36. package/dist/lightweight/bn.interface.mjs +0 -3807
  37. package/dist/lightweight/interface.min.mjs +0 -3
  38. package/dist/lightweight/interface.min.mjs.map +0 -1
  39. package/dist/lightweight/interface.mjs +0 -16
  40. package/dist/lightweight/native.interface.min.mjs +0 -3
  41. package/dist/lightweight/native.interface.min.mjs.map +0 -1
  42. package/dist/lightweight/native.interface.mjs +0 -456
@@ -1,4 +1,4 @@
1
- /*! OpenPGP.js v6.0.0-beta.0.patch.0 - 2024-04-19 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
1
+ /*! OpenPGP.js v6.0.0-beta.2 - 2024-07-05 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
2
2
  const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3
3
 
4
4
  const doneWritingPromise = Symbol('doneWritingPromise');
@@ -543,9 +543,10 @@ function transformRaw(input, options) {
543
543
  * @param {Function} cancel
544
544
  * @returns {TransformStream}
545
545
  */
546
- function transformWithCancel(cancel) {
546
+ function transformWithCancel(customCancel) {
547
547
  let pulled = false;
548
- let backpressureChangePromiseResolve;
548
+ let cancelled = false;
549
+ let backpressureChangePromiseResolve, backpressureChangePromiseReject;
549
550
  let outputController;
550
551
  return {
551
552
  readable: new ReadableStream({
@@ -559,16 +560,29 @@ function transformWithCancel(cancel) {
559
560
  pulled = true;
560
561
  }
561
562
  },
562
- cancel
563
+ async cancel(reason) {
564
+ cancelled = true;
565
+ if (customCancel) {
566
+ await customCancel(reason);
567
+ }
568
+ if (backpressureChangePromiseReject) {
569
+ backpressureChangePromiseReject(reason);
570
+ }
571
+ }
563
572
  }, {highWaterMark: 0}),
564
573
  writable: new WritableStream({
565
574
  write: async function(chunk) {
575
+ if (cancelled) {
576
+ throw new Error('Stream is cancelled');
577
+ }
566
578
  outputController.enqueue(chunk);
567
579
  if (!pulled) {
568
- await new Promise(resolve => {
580
+ await new Promise((resolve, reject) => {
569
581
  backpressureChangePromiseResolve = resolve;
582
+ backpressureChangePromiseReject = reject;
570
583
  });
571
584
  backpressureChangePromiseResolve = null;
585
+ backpressureChangePromiseReject = null;
572
586
  } else {
573
587
  pulled = false;
574
588
  }
@@ -1504,6 +1518,14 @@ var config = {
1504
1518
  * @property {Boolean} v6Keys
1505
1519
  */
1506
1520
  v6Keys: false,
1521
+ /**
1522
+ * Enable parsing v5 keys and v5 signatures (which is different from the AEAD-encrypted SEIPDv2 packet).
1523
+ * These are non-standard entities, which in the crypto-refresh have been superseded
1524
+ * by v6 keys and v6 signatures, respectively.
1525
+ * However, generation of v5 entities was supported behind config flag in OpenPGP.js v5, and some other libraries,
1526
+ * hence parsing them might be necessary in some cases.
1527
+ */
1528
+ enableParsingV5Entities: false,
1507
1529
  /**
1508
1530
  * S2K (String to Key) type, used for key derivation in the context of secret key encryption
1509
1531
  * and password-encrypted data. Weaker s2k options are not allowed.
@@ -1660,7 +1682,7 @@ var config = {
1660
1682
  * @memberof module:config
1661
1683
  * @property {String} versionString A version string to be included in armored messages
1662
1684
  */
1663
- versionString: 'OpenPGP.js 6.0.0-beta.0.patch.0',
1685
+ versionString: 'OpenPGP.js 6.0.0-beta.2',
1664
1686
  /**
1665
1687
  * @memberof module:config
1666
1688
  * @property {String} commentString A comment string to be included in armored messages
@@ -1721,27 +1743,6 @@ var config = {
1721
1743
  rejectCurves: new Set([enums.curve.secp256k1])
1722
1744
  };
1723
1745
 
1724
- /**
1725
- * We don't use the BigIntegerInterface wrapper from noble-hashes because:
1726
- * - importing the instance results in it being shared with noble-hashes, which separately calls `setImplementation()`
1727
- * on load, causing it to throw due to duplicate initialization.
1728
- * - even duplicating the interface code here to keep a separate instance requires handing a race-conditions the first time
1729
- * `getBigInteger` is called, when the code needs to check if the implementation is set, and initialize it if not.
1730
- * Ultimately, the interface provides no advantages and it's only needed because of TS.
1731
- */
1732
- const detectBigInt = () => typeof BigInt !== 'undefined';
1733
- async function getBigInteger() {
1734
- if (detectBigInt()) {
1735
- // NativeBigInteger is small, so it's imported in isolation (it could also be imported at the top level)
1736
- const { default: NativeBigInteger } = await import('./native.interface.mjs');
1737
- return NativeBigInteger;
1738
- } else {
1739
- // FallbackBigInteger relies on large BN.js lib, which is also used by noble-hashes and noble-curves
1740
- const { default: FallbackBigInteger } = await import('./bn.interface.mjs');
1741
- return FallbackBigInteger;
1742
- }
1743
- }
1744
-
1745
1746
  // GPG4Browsers - An OpenPGP implementation in javascript
1746
1747
  // Copyright (C) 2011 Recurity Labs GmbH
1747
1748
  //
@@ -1783,8 +1784,6 @@ const util = {
1783
1784
 
1784
1785
  isStream: isStream,
1785
1786
 
1786
- getBigInteger,
1787
-
1788
1787
  /**
1789
1788
  * Load noble-curves lib on demand and return the requested curve function
1790
1789
  * @param {enums.publicKey} publicKeyAlgo
@@ -2506,7 +2505,7 @@ function b64ToUint8Array(base64) {
2506
2505
  */
2507
2506
  function uint8ArrayToB64(bytes, url) {
2508
2507
  let encoded = encode$1(bytes).replace(/[\r\n]/g, '');
2509
- if (url) {
2508
+ {
2510
2509
  encoded = encoded.replace(/[+]/g, '-').replace(/[/]/g, '_').replace(/[=]/g, '');
2511
2510
  }
2512
2511
  return encoded;
@@ -3205,15 +3204,15 @@ function add32(a, b) {
3205
3204
 
3206
3205
 
3207
3206
  const webCrypto$b = util.getWebCrypto();
3208
- const nodeCrypto$a = util.getNodeCrypto();
3209
- const nodeCryptoHashes = nodeCrypto$a && nodeCrypto$a.getHashes();
3207
+ const nodeCrypto$b = util.getNodeCrypto();
3208
+ const nodeCryptoHashes = nodeCrypto$b && nodeCrypto$b.getHashes();
3210
3209
 
3211
3210
  function nodeHash(type) {
3212
- if (!nodeCrypto$a || !nodeCryptoHashes.includes(type)) {
3211
+ if (!nodeCrypto$b || !nodeCryptoHashes.includes(type)) {
3213
3212
  return;
3214
3213
  }
3215
3214
  return async function (data) {
3216
- const shasum = nodeCrypto$a.createHash(type);
3215
+ const shasum = nodeCrypto$b.createHash(type);
3217
3216
  return transform(data, value => {
3218
3217
  shasum.update(value);
3219
3218
  }, () => new Uint8Array(shasum.digest()));
@@ -4293,7 +4292,7 @@ function is_bytes(a) {
4293
4292
  return a instanceof Uint8Array;
4294
4293
  }
4295
4294
  function _heap_init(heap, heapSize) {
4296
- const size = heap ? heap.byteLength : heapSize || 65536;
4295
+ const size = heap ? heap.byteLength : 65536;
4297
4296
  if (size & 0xfff || size <= 0)
4298
4297
  throw new Error('heap size must be a positive integer and a multiple of 4096');
4299
4298
  heap = heap || new Uint8Array(new ArrayBuffer(size));
@@ -4560,9 +4559,9 @@ class AES_CFB {
4560
4559
 
4561
4560
 
4562
4561
  const webCrypto$a = util.getWebCrypto();
4563
- const nodeCrypto$9 = util.getNodeCrypto();
4562
+ const nodeCrypto$a = util.getNodeCrypto();
4564
4563
 
4565
- const knownAlgos = nodeCrypto$9 ? nodeCrypto$9.getCiphers() : [];
4564
+ const knownAlgos = nodeCrypto$a ? nodeCrypto$a.getCiphers() : [];
4566
4565
  const nodeAlgos = {
4567
4566
  idea: knownAlgos.includes('idea-cfb') ? 'idea-cfb' : undefined, /* Unused, not implemented */
4568
4567
  tripledes: knownAlgos.includes('des-ede3-cfb') ? 'des-ede3-cfb' : undefined,
@@ -4628,7 +4627,7 @@ async function encrypt$5(algo, key, plaintext, iv, config) {
4628
4627
  */
4629
4628
  async function decrypt$5(algo, key, ciphertext, iv) {
4630
4629
  const algoName = enums.read(enums.symmetric, algo);
4631
- if (nodeCrypto$9 && nodeAlgos[algoName]) { // Node crypto library.
4630
+ if (nodeCrypto$a && nodeAlgos[algoName]) { // Node crypto library.
4632
4631
  return nodeDecrypt$1(algo, key, ciphertext, iv);
4633
4632
  }
4634
4633
  if (util.isAES(algo)) {
@@ -4796,13 +4795,13 @@ function xorMut$1(a, b) {
4796
4795
 
4797
4796
  function nodeEncrypt$1(algo, key, pt, iv) {
4798
4797
  const algoName = enums.read(enums.symmetric, algo);
4799
- const cipherObj = new nodeCrypto$9.createCipheriv(nodeAlgos[algoName], key, iv);
4798
+ const cipherObj = new nodeCrypto$a.createCipheriv(nodeAlgos[algoName], key, iv);
4800
4799
  return transform(pt, value => new Uint8Array(cipherObj.update(value)));
4801
4800
  }
4802
4801
 
4803
4802
  function nodeDecrypt$1(algo, key, ct, iv) {
4804
4803
  const algoName = enums.read(enums.symmetric, algo);
4805
- const decipherObj = new nodeCrypto$9.createDecipheriv(nodeAlgos[algoName], key, iv);
4804
+ const decipherObj = new nodeCrypto$a.createDecipheriv(nodeAlgos[algoName], key, iv);
4806
4805
  return transform(ct, value => new Uint8Array(decipherObj.update(value)));
4807
4806
  }
4808
4807
 
@@ -4895,7 +4894,7 @@ class AES_CBC {
4895
4894
 
4896
4895
 
4897
4896
  const webCrypto$9 = util.getWebCrypto();
4898
- const nodeCrypto$8 = util.getNodeCrypto();
4897
+ const nodeCrypto$9 = util.getNodeCrypto();
4899
4898
 
4900
4899
 
4901
4900
  /**
@@ -4961,7 +4960,7 @@ async function CMAC(key) {
4961
4960
  async function CBC(key) {
4962
4961
  if (util.getNodeCrypto()) { // Node crypto library
4963
4962
  return async function(pt) {
4964
- const en = new nodeCrypto$8.createCipheriv('aes-' + (key.length * 8) + '-cbc', key, zeroBlock$1);
4963
+ const en = new nodeCrypto$9.createCipheriv('aes-' + (key.length * 8) + '-cbc', key, zeroBlock$1);
4965
4964
  const ct = en.update(pt);
4966
4965
  return new Uint8Array(ct);
4967
4966
  };
@@ -5009,7 +5008,7 @@ async function CBC(key) {
5009
5008
 
5010
5009
 
5011
5010
  const webCrypto$8 = util.getWebCrypto();
5012
- const nodeCrypto$7 = util.getNodeCrypto();
5011
+ const nodeCrypto$8 = util.getNodeCrypto();
5013
5012
  const Buffer$1 = util.getNodeBuffer();
5014
5013
 
5015
5014
 
@@ -5031,7 +5030,7 @@ async function OMAC(key) {
5031
5030
  async function CTR(key) {
5032
5031
  if (util.getNodeCrypto()) { // Node crypto library
5033
5032
  return async function(pt, iv) {
5034
- const en = new nodeCrypto$7.createCipheriv('aes-' + (key.length * 8) + '-ctr', key, iv);
5033
+ const en = new nodeCrypto$8.createCipheriv('aes-' + (key.length * 8) + '-ctr', key, iv);
5035
5034
  const ct = Buffer$1.concat([en.update(pt), en.final()]);
5036
5035
  return new Uint8Array(ct);
5037
5036
  };
@@ -5722,7 +5721,7 @@ class AES_GCM {
5722
5721
 
5723
5722
 
5724
5723
  const webCrypto$7 = util.getWebCrypto();
5725
- const nodeCrypto$6 = util.getNodeCrypto();
5724
+ const nodeCrypto$7 = util.getNodeCrypto();
5726
5725
  const Buffer = util.getNodeBuffer();
5727
5726
 
5728
5727
  const blockLength = 16;
@@ -5745,14 +5744,14 @@ async function GCM(cipher, key) {
5745
5744
  if (util.getNodeCrypto()) { // Node crypto library
5746
5745
  return {
5747
5746
  encrypt: async function(pt, iv, adata = new Uint8Array()) {
5748
- const en = new nodeCrypto$6.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
5747
+ const en = new nodeCrypto$7.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
5749
5748
  en.setAAD(adata);
5750
5749
  const ct = Buffer.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
5751
5750
  return new Uint8Array(ct);
5752
5751
  },
5753
5752
 
5754
5753
  decrypt: async function(ct, iv, adata = new Uint8Array()) {
5755
- const de = new nodeCrypto$6.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
5754
+ const de = new nodeCrypto$7.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
5756
5755
  de.setAAD(adata);
5757
5756
  de.setAuthTag(ct.slice(ct.length - tagLength, ct.length)); // read auth tag at end of ciphertext
5758
5757
  const pt = Buffer.concat([de.update(ct.slice(0, ct.length - tagLength)), de.final()]);
@@ -5850,6 +5849,202 @@ var mode = {
5850
5849
  ocb: OCB
5851
5850
  };
5852
5851
 
5852
+ // Operations are not constant time, but we try and limit timing leakage where we can
5853
+ const _0n$2 = BigInt(0);
5854
+ const _1n$5 = BigInt(1);
5855
+ function uint8ArrayToBigInt(bytes) {
5856
+ const hexAlphabet = '0123456789ABCDEF';
5857
+ let s = '';
5858
+ bytes.forEach(v => {
5859
+ s += hexAlphabet[v >> 4] + hexAlphabet[v & 15];
5860
+ });
5861
+ return BigInt('0x0' + s);
5862
+ }
5863
+ function mod$2(a, m) {
5864
+ const reduced = a % m;
5865
+ return reduced < _0n$2 ? reduced + m : reduced;
5866
+ }
5867
+ /**
5868
+ * Compute modular exponentiation using square and multiply
5869
+ * @param {BigInt} a - Base
5870
+ * @param {BigInt} e - Exponent
5871
+ * @param {BigInt} n - Modulo
5872
+ * @returns {BigInt} b ** e mod n.
5873
+ */
5874
+ function modExp(b, e, n) {
5875
+ if (n === _0n$2)
5876
+ throw Error('Modulo cannot be zero');
5877
+ if (n === _1n$5)
5878
+ return BigInt(0);
5879
+ if (e < _0n$2)
5880
+ throw Error('Unsopported negative exponent');
5881
+ let exp = e;
5882
+ let x = b;
5883
+ x %= n;
5884
+ let r = BigInt(1);
5885
+ while (exp > _0n$2) {
5886
+ const lsb = exp & _1n$5;
5887
+ exp >>= _1n$5; // e / 2
5888
+ // Always compute multiplication step, to reduce timing leakage
5889
+ const rx = (r * x) % n;
5890
+ // Update r only if lsb is 1 (odd exponent)
5891
+ r = lsb ? rx : r;
5892
+ x = (x * x) % n; // Square
5893
+ }
5894
+ return r;
5895
+ }
5896
+ function abs(x) {
5897
+ return x >= _0n$2 ? x : -x;
5898
+ }
5899
+ /**
5900
+ * Extended Eucleadian algorithm (http://anh.cs.luc.edu/331/notes/xgcd.pdf)
5901
+ * Given a and b, compute (x, y) such that ax + by = gdc(a, b).
5902
+ * Negative numbers are also supported.
5903
+ * @param {BigInt} a - First operand
5904
+ * @param {BigInt} b - Second operand
5905
+ * @returns {{ gcd, x, y: bigint }}
5906
+ */
5907
+ function _egcd(aInput, bInput) {
5908
+ let x = BigInt(0);
5909
+ let y = BigInt(1);
5910
+ let xPrev = BigInt(1);
5911
+ let yPrev = BigInt(0);
5912
+ // Deal with negative numbers: run algo over absolute values,
5913
+ // and "move" the sign to the returned x and/or y.
5914
+ // See https://math.stackexchange.com/questions/37806/extended-euclidean-algorithm-with-negative-numbers
5915
+ let a = abs(aInput);
5916
+ let b = abs(bInput);
5917
+ const aNegated = aInput < _0n$2;
5918
+ const bNegated = bInput < _0n$2;
5919
+ while (b !== _0n$2) {
5920
+ const q = a / b;
5921
+ let tmp = x;
5922
+ x = xPrev - q * x;
5923
+ xPrev = tmp;
5924
+ tmp = y;
5925
+ y = yPrev - q * y;
5926
+ yPrev = tmp;
5927
+ tmp = b;
5928
+ b = a % b;
5929
+ a = tmp;
5930
+ }
5931
+ return {
5932
+ x: aNegated ? -xPrev : xPrev,
5933
+ y: bNegated ? -yPrev : yPrev,
5934
+ gcd: a
5935
+ };
5936
+ }
5937
+ /**
5938
+ * Compute the inverse of `a` modulo `n`
5939
+ * Note: `a` and and `n` must be relatively prime
5940
+ * @param {BigInt} a
5941
+ * @param {BigInt} n - Modulo
5942
+ * @returns {BigInt} x such that a*x = 1 mod n
5943
+ * @throws {Error} if the inverse does not exist
5944
+ */
5945
+ function modInv(a, n) {
5946
+ const { gcd, x } = _egcd(a, n);
5947
+ if (gcd !== _1n$5) {
5948
+ throw new Error('Inverse does not exist');
5949
+ }
5950
+ return mod$2(x + n, n);
5951
+ }
5952
+ /**
5953
+ * Compute greatest common divisor between this and n
5954
+ * @param {BigInt} aInput - Operand
5955
+ * @param {BigInt} bInput - Operand
5956
+ * @returns {BigInt} gcd
5957
+ */
5958
+ function gcd(aInput, bInput) {
5959
+ let a = aInput;
5960
+ let b = bInput;
5961
+ while (b !== _0n$2) {
5962
+ const tmp = b;
5963
+ b = a % b;
5964
+ a = tmp;
5965
+ }
5966
+ return a;
5967
+ }
5968
+ /**
5969
+ * Get this value as an exact Number (max 53 bits)
5970
+ * Fails if this value is too large
5971
+ * @returns {Number}
5972
+ */
5973
+ function bigIntToNumber(x) {
5974
+ const number = Number(x);
5975
+ if (number > Number.MAX_SAFE_INTEGER) {
5976
+ // We throw and error to conform with the bn.js implementation
5977
+ throw new Error('Number can only safely store up to 53 bits');
5978
+ }
5979
+ return number;
5980
+ }
5981
+ /**
5982
+ * Get value of i-th bit
5983
+ * @param {BigInt} x
5984
+ * @param {Number} i - Bit index
5985
+ * @returns {Number} Bit value.
5986
+ */
5987
+ function getBit(x, i) {
5988
+ const bit = (x >> BigInt(i)) & _1n$5;
5989
+ return bit === _0n$2 ? 0 : 1;
5990
+ }
5991
+ /**
5992
+ * Compute bit length
5993
+ */
5994
+ function bitLength(x) {
5995
+ // -1n >> -1n is -1n
5996
+ // 1n >> 1n is 0n
5997
+ const target = x < _0n$2 ? BigInt(-1) : _0n$2;
5998
+ let bitlen = 1;
5999
+ let tmp = x;
6000
+ // eslint-disable-next-line no-cond-assign
6001
+ while ((tmp >>= _1n$5) !== target) {
6002
+ bitlen++;
6003
+ }
6004
+ return bitlen;
6005
+ }
6006
+ /**
6007
+ * Compute byte length
6008
+ */
6009
+ function byteLength(x) {
6010
+ const target = x < _0n$2 ? BigInt(-1) : _0n$2;
6011
+ const _8n = BigInt(8);
6012
+ let len = 1;
6013
+ let tmp = x;
6014
+ // eslint-disable-next-line no-cond-assign
6015
+ while ((tmp >>= _8n) !== target) {
6016
+ len++;
6017
+ }
6018
+ return len;
6019
+ }
6020
+ /**
6021
+ * Get Uint8Array representation of this number
6022
+ * @param {String} endian - Endianess of output array (defaults to 'be')
6023
+ * @param {Number} length - Of output array
6024
+ * @returns {Uint8Array}
6025
+ */
6026
+ function bigIntToUint8Array(x, endian = 'be', length) {
6027
+ // we get and parse the hex string (https://coolaj86.com/articles/convert-js-bigints-to-typedarrays/)
6028
+ // this is faster than shift+mod iterations
6029
+ let hex = x.toString(16);
6030
+ if (hex.length % 2 === 1) {
6031
+ hex = '0' + hex;
6032
+ }
6033
+ const rawLength = hex.length / 2;
6034
+ const bytes = new Uint8Array(length || rawLength);
6035
+ // parse hex
6036
+ const offset = length ? length - rawLength : 0;
6037
+ let i = 0;
6038
+ while (i < rawLength) {
6039
+ bytes[i + offset] = parseInt(hex.slice(2 * i, 2 * i + 2), 16);
6040
+ i++;
6041
+ }
6042
+ if (endian !== 'be') {
6043
+ bytes.reverse();
6044
+ }
6045
+ return bytes;
6046
+ }
6047
+
5853
6048
  // GPG4Browsers - An OpenPGP implementation in javascript
5854
6049
  // Copyright (C) 2011 Recurity Labs GmbH
5855
6050
  //
@@ -5868,7 +6063,7 @@ var mode = {
5868
6063
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5869
6064
 
5870
6065
 
5871
- const nodeCrypto$5 = util.getNodeCrypto();
6066
+ const nodeCrypto$6 = util.getNodeCrypto();
5872
6067
 
5873
6068
  /**
5874
6069
  * Retrieve secure random byte array of the specified length
@@ -5877,8 +6072,8 @@ const nodeCrypto$5 = util.getNodeCrypto();
5877
6072
  */
5878
6073
  function getRandomBytes(length) {
5879
6074
  const buf = new Uint8Array(length);
5880
- if (nodeCrypto$5) {
5881
- const bytes = nodeCrypto$5.randomBytes(buf.length);
6075
+ if (nodeCrypto$6) {
6076
+ const bytes = nodeCrypto$6.randomBytes(buf.length);
5882
6077
  buf.set(bytes);
5883
6078
  } else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
5884
6079
  crypto.getRandomValues(buf);
@@ -5889,27 +6084,25 @@ function getRandomBytes(length) {
5889
6084
  }
5890
6085
 
5891
6086
  /**
5892
- * Create a secure random BigInteger that is greater than or equal to min and less than max.
5893
- * @param {module:BigInteger} min - Lower bound, included
5894
- * @param {module:BigInteger} max - Upper bound, excluded
5895
- * @returns {Promise<module:BigInteger>} Random BigInteger.
6087
+ * Create a secure random BigInt that is greater than or equal to min and less than max.
6088
+ * @param {bigint} min - Lower bound, included
6089
+ * @param {bigint} max - Upper bound, excluded
6090
+ * @returns {bigint} Random BigInt.
5896
6091
  * @async
5897
6092
  */
5898
- async function getRandomBigInteger(min, max) {
5899
- const BigInteger = await util.getBigInteger();
5900
-
5901
- if (max.lt(min)) {
6093
+ function getRandomBigInteger(min, max) {
6094
+ if (max < min) {
5902
6095
  throw new Error('Illegal parameter value: max <= min');
5903
6096
  }
5904
6097
 
5905
- const modulus = max.sub(min);
5906
- const bytes = modulus.byteLength();
6098
+ const modulus = max - min;
6099
+ const bytes = byteLength(modulus);
5907
6100
 
5908
6101
  // Using a while loop is necessary to avoid bias introduced by the mod operation.
5909
6102
  // However, we request 64 extra random bits so that the bias is negligible.
5910
6103
  // Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
5911
- const r = new BigInteger(getRandomBytes(bytes + 8));
5912
- return r.mod(modulus).add(min);
6104
+ const r = uint8ArrayToBigInt(getRandomBytes(bytes + 8));
6105
+ return mod$2(r, modulus) + min;
5913
6106
  }
5914
6107
 
5915
6108
  var random = /*#__PURE__*/Object.freeze({
@@ -5934,177 +6127,159 @@ var random = /*#__PURE__*/Object.freeze({
5934
6127
  // You should have received a copy of the GNU Lesser General Public
5935
6128
  // License along with this library; if not, write to the Free Software
5936
6129
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5937
-
5938
-
6130
+ /**
6131
+ * @fileoverview Algorithms for probabilistic random prime generation
6132
+ * @module crypto/public_key/prime
6133
+ */
6134
+ const _1n$4 = BigInt(1);
5939
6135
  /**
5940
6136
  * Generate a probably prime random number
5941
- * @param {Integer} bits - Bit length of the prime
5942
- * @param {BigInteger} e - Optional RSA exponent to check against the prime
5943
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
5944
- * @returns BigInteger
5945
- * @async
6137
+ * @param bits - Bit length of the prime
6138
+ * @param e - Optional RSA exponent to check against the prime
6139
+ * @param k - Optional number of iterations of Miller-Rabin test
5946
6140
  */
5947
- async function randomProbablePrime(bits, e, k) {
5948
- const BigInteger = await util.getBigInteger();
5949
-
5950
- const one = new BigInteger(1);
5951
- const min = one.leftShift(new BigInteger(bits - 1));
5952
- const thirty = new BigInteger(30);
5953
- /*
5954
- * We can avoid any multiples of 3 and 5 by looking at n mod 30
5955
- * n mod 30 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
5956
- * the next possible prime is mod 30:
5957
- * 1 7 7 7 7 7 7 11 11 11 11 13 13 17 17 17 17 19 19 23 23 23 23 29 29 29 29 29 29 1
5958
- */
5959
- const adds = [1, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2];
5960
-
5961
- const n = await getRandomBigInteger(min, min.leftShift(one));
5962
- let i = n.mod(thirty).toNumber();
5963
-
5964
- do {
5965
- n.iadd(new BigInteger(adds[i]));
5966
- i = (i + adds[i]) % adds.length;
5967
- // If reached the maximum, go back to the minimum.
5968
- if (n.bitLength() > bits) {
5969
- n.imod(min.leftShift(one)).iadd(min);
5970
- i = n.mod(thirty).toNumber();
5971
- }
5972
- } while (!await isProbablePrime(n, e, k));
5973
- return n;
6141
+ function randomProbablePrime(bits, e, k) {
6142
+ const _30n = BigInt(30);
6143
+ const min = _1n$4 << BigInt(bits - 1);
6144
+ /*
6145
+ * We can avoid any multiples of 3 and 5 by looking at n mod 30
6146
+ * n mod 30 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
6147
+ * the next possible prime is mod 30:
6148
+ * 1 7 7 7 7 7 7 11 11 11 11 13 13 17 17 17 17 19 19 23 23 23 23 29 29 29 29 29 29 1
6149
+ */
6150
+ const adds = [1, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 2, 1, 4, 3, 2, 1, 6, 5, 4, 3, 2, 1, 2];
6151
+ let n = getRandomBigInteger(min, min << _1n$4);
6152
+ let i = bigIntToNumber(mod$2(n, _30n));
6153
+ do {
6154
+ n += BigInt(adds[i]);
6155
+ i = (i + adds[i]) % adds.length;
6156
+ // If reached the maximum, go back to the minimum.
6157
+ if (bitLength(n) > bits) {
6158
+ n = mod$2(n, min << _1n$4);
6159
+ n += min;
6160
+ i = bigIntToNumber(mod$2(n, _30n));
6161
+ }
6162
+ } while (!isProbablePrime(n, e, k));
6163
+ return n;
5974
6164
  }
5975
-
5976
6165
  /**
5977
6166
  * Probabilistic primality testing
5978
- * @param {BigInteger} n - Number to test
5979
- * @param {BigInteger} e - Optional RSA exponent to check against the prime
5980
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
5981
- * @returns {boolean}
5982
- * @async
6167
+ * @param n - Number to test
6168
+ * @param e - Optional RSA exponent to check against the prime
6169
+ * @param k - Optional number of iterations of Miller-Rabin test
5983
6170
  */
5984
- async function isProbablePrime(n, e, k) {
5985
- if (e && !n.dec().gcd(e).isOne()) {
5986
- return false;
5987
- }
5988
- if (!await divisionTest(n)) {
5989
- return false;
5990
- }
5991
- if (!await fermat(n)) {
5992
- return false;
5993
- }
5994
- if (!await millerRabin(n, k)) {
5995
- return false;
5996
- }
5997
- // TODO implement the Lucas test
5998
- // See Section C.3.3 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
5999
- return true;
6171
+ function isProbablePrime(n, e, k) {
6172
+ if (e && gcd(n - _1n$4, e) !== _1n$4) {
6173
+ return false;
6174
+ }
6175
+ if (!divisionTest(n)) {
6176
+ return false;
6177
+ }
6178
+ if (!fermat(n)) {
6179
+ return false;
6180
+ }
6181
+ if (!millerRabin(n, k)) {
6182
+ return false;
6183
+ }
6184
+ // TODO implement the Lucas test
6185
+ // See Section C.3.3 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
6186
+ return true;
6000
6187
  }
6001
-
6002
6188
  /**
6003
6189
  * Tests whether n is probably prime or not using Fermat's test with b = 2.
6004
6190
  * Fails if b^(n-1) mod n != 1.
6005
- * @param {BigInteger} n - Number to test
6006
- * @param {BigInteger} b - Optional Fermat test base
6007
- * @returns {boolean}
6191
+ * @param n - Number to test
6192
+ * @param b - Optional Fermat test base
6008
6193
  */
6009
- async function fermat(n, b) {
6010
- const BigInteger = await util.getBigInteger();
6011
-
6012
- b = b || new BigInteger(2);
6013
- return b.modExp(n.dec(), n).isOne();
6194
+ function fermat(n, b = BigInt(2)) {
6195
+ return modExp(b, n - _1n$4, n) === _1n$4;
6014
6196
  }
6015
-
6016
- async function divisionTest(n) {
6017
- const BigInteger = await util.getBigInteger();
6018
-
6019
- return smallPrimes.every(m => {
6020
- return n.mod(new BigInteger(m)) !== 0;
6021
- });
6197
+ function divisionTest(n) {
6198
+ const _0n = BigInt(0);
6199
+ return smallPrimes.every(m => mod$2(n, m) !== _0n);
6022
6200
  }
6023
-
6024
6201
  // https://github.com/gpg/libgcrypt/blob/master/cipher/primegen.c
6025
6202
  const smallPrimes = [
6026
- 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
6027
- 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
6028
- 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
6029
- 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
6030
- 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
6031
- 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
6032
- 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
6033
- 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
6034
- 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
6035
- 509, 521, 523, 541, 547, 557, 563, 569, 571, 577,
6036
- 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
6037
- 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
6038
- 709, 719, 727, 733, 739, 743, 751, 757, 761, 769,
6039
- 773, 787, 797, 809, 811, 821, 823, 827, 829, 839,
6040
- 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
6041
- 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
6042
- 991, 997, 1009, 1013, 1019, 1021, 1031, 1033,
6043
- 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
6044
- 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151,
6045
- 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213,
6046
- 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277,
6047
- 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307,
6048
- 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399,
6049
- 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451,
6050
- 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493,
6051
- 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559,
6052
- 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609,
6053
- 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667,
6054
- 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
6055
- 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789,
6056
- 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871,
6057
- 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931,
6058
- 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997,
6059
- 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053,
6060
- 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111,
6061
- 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161,
6062
- 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243,
6063
- 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297,
6064
- 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
6065
- 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411,
6066
- 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473,
6067
- 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551,
6068
- 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633,
6069
- 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687,
6070
- 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729,
6071
- 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791,
6072
- 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851,
6073
- 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917,
6074
- 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999,
6075
- 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061,
6076
- 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137,
6077
- 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209,
6078
- 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
6079
- 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331,
6080
- 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391,
6081
- 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467,
6082
- 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533,
6083
- 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583,
6084
- 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643,
6085
- 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709,
6086
- 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779,
6087
- 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851,
6088
- 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917,
6089
- 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989,
6090
- 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049,
6091
- 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111,
6092
- 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
6093
- 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243,
6094
- 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297,
6095
- 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391,
6096
- 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457,
6097
- 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519,
6098
- 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
6099
- 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657,
6100
- 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729,
6101
- 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799,
6102
- 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889,
6103
- 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951,
6104
- 4957, 4967, 4969, 4973, 4987, 4993, 4999
6105
- ];
6106
-
6107
-
6203
+ 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
6204
+ 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
6205
+ 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
6206
+ 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
6207
+ 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
6208
+ 269, 271, 277, 281, 283, 293, 307, 311, 313, 317,
6209
+ 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
6210
+ 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
6211
+ 449, 457, 461, 463, 467, 479, 487, 491, 499, 503,
6212
+ 509, 521, 523, 541, 547, 557, 563, 569, 571, 577,
6213
+ 587, 593, 599, 601, 607, 613, 617, 619, 631, 641,
6214
+ 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
6215
+ 709, 719, 727, 733, 739, 743, 751, 757, 761, 769,
6216
+ 773, 787, 797, 809, 811, 821, 823, 827, 829, 839,
6217
+ 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
6218
+ 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
6219
+ 991, 997, 1009, 1013, 1019, 1021, 1031, 1033,
6220
+ 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091,
6221
+ 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151,
6222
+ 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213,
6223
+ 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277,
6224
+ 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307,
6225
+ 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399,
6226
+ 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451,
6227
+ 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493,
6228
+ 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559,
6229
+ 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609,
6230
+ 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667,
6231
+ 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
6232
+ 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789,
6233
+ 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871,
6234
+ 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931,
6235
+ 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997,
6236
+ 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053,
6237
+ 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111,
6238
+ 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161,
6239
+ 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243,
6240
+ 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297,
6241
+ 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
6242
+ 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411,
6243
+ 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473,
6244
+ 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551,
6245
+ 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633,
6246
+ 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687,
6247
+ 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729,
6248
+ 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791,
6249
+ 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851,
6250
+ 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917,
6251
+ 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999,
6252
+ 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061,
6253
+ 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137,
6254
+ 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209,
6255
+ 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
6256
+ 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331,
6257
+ 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391,
6258
+ 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467,
6259
+ 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533,
6260
+ 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583,
6261
+ 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643,
6262
+ 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709,
6263
+ 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779,
6264
+ 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851,
6265
+ 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917,
6266
+ 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989,
6267
+ 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049,
6268
+ 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111,
6269
+ 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
6270
+ 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243,
6271
+ 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297,
6272
+ 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391,
6273
+ 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457,
6274
+ 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519,
6275
+ 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
6276
+ 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657,
6277
+ 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729,
6278
+ 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799,
6279
+ 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889,
6280
+ 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951,
6281
+ 4957, 4967, 4969, 4973, 4987, 4993, 4999
6282
+ ].map(n => BigInt(n));
6108
6283
  // Miller-Rabin - Miller Rabin algorithm for primality test
6109
6284
  // Copyright Fedor Indutny, 2014.
6110
6285
  //
@@ -6128,63 +6303,51 @@ const smallPrimes = [
6128
6303
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
6129
6304
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
6130
6305
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
6131
-
6132
6306
  // Adapted on Jan 2018 from version 4.0.1 at https://github.com/indutny/miller-rabin
6133
-
6134
6307
  // Sample syntax for Fixed-Base Miller-Rabin:
6135
6308
  // millerRabin(n, k, () => new BN(small_primes[Math.random() * small_primes.length | 0]))
6136
-
6137
6309
  /**
6138
6310
  * Tests whether n is probably prime or not using the Miller-Rabin test.
6139
6311
  * See HAC Remark 4.28.
6140
- * @param {BigInteger} n - Number to test
6141
- * @param {Integer} k - Optional number of iterations of Miller-Rabin test
6142
- * @param {Function} rand - Optional function to generate potential witnesses
6312
+ * @param n - Number to test
6313
+ * @param k - Optional number of iterations of Miller-Rabin test
6314
+ * @param rand - Optional function to generate potential witnesses
6143
6315
  * @returns {boolean}
6144
6316
  * @async
6145
6317
  */
6146
- async function millerRabin(n, k, rand) {
6147
- const BigInteger = await util.getBigInteger();
6148
-
6149
- const len = n.bitLength();
6150
-
6151
- if (!k) {
6152
- k = Math.max(1, (len / 48) | 0);
6153
- }
6154
-
6155
- const n1 = n.dec(); // n - 1
6156
-
6157
- // Find d and s, (n - 1) = (2 ^ s) * d;
6158
- let s = 0;
6159
- while (!n1.getBit(s)) { s++; }
6160
- const d = n.rightShift(new BigInteger(s));
6161
-
6162
- for (; k > 0; k--) {
6163
- const a = rand ? rand() : await getRandomBigInteger(new BigInteger(2), n1);
6164
-
6165
- let x = a.modExp(d, n);
6166
- if (x.isOne() || x.equal(n1)) {
6167
- continue;
6318
+ function millerRabin(n, k, rand) {
6319
+ const len = bitLength(n);
6320
+ if (!k) {
6321
+ k = Math.max(1, (len / 48) | 0);
6168
6322
  }
6169
-
6170
- let i;
6171
- for (i = 1; i < s; i++) {
6172
- x = x.mul(x).mod(n);
6173
-
6174
- if (x.isOne()) {
6175
- return false;
6176
- }
6177
- if (x.equal(n1)) {
6178
- break;
6179
- }
6180
- }
6181
-
6182
- if (i === s) {
6183
- return false;
6323
+ const n1 = n - _1n$4; // n - 1
6324
+ // Find d and s, (n - 1) = (2 ^ s) * d;
6325
+ let s = 0;
6326
+ while (!getBit(n1, s)) {
6327
+ s++;
6328
+ }
6329
+ const d = n >> BigInt(s);
6330
+ for (; k > 0; k--) {
6331
+ const a = getRandomBigInteger(BigInt(2), n1);
6332
+ let x = modExp(a, d, n);
6333
+ if (x === _1n$4 || x === n1) {
6334
+ continue;
6335
+ }
6336
+ let i;
6337
+ for (i = 1; i < s; i++) {
6338
+ x = mod$2(x * x, n);
6339
+ if (x === _1n$4) {
6340
+ return false;
6341
+ }
6342
+ if (x === n1) {
6343
+ break;
6344
+ }
6345
+ }
6346
+ if (i === s) {
6347
+ return false;
6348
+ }
6184
6349
  }
6185
- }
6186
-
6187
- return true;
6350
+ return true;
6188
6351
  }
6189
6352
 
6190
6353
  // GPG4Browsers - An OpenPGP implementation in javascript
@@ -6310,7 +6473,7 @@ function emeDecode(encoded, randomPayload) {
6310
6473
  * @param {Integer} emLen - Intended length in octets of the encoded message
6311
6474
  * @returns {Uint8Array} Encoded message.
6312
6475
  */
6313
- async function emsaEncode(algo, hashed, emLen) {
6476
+ function emsaEncode(algo, hashed, emLen) {
6314
6477
  let i;
6315
6478
  if (hashed.length !== hash.getHashByteLength(algo)) {
6316
6479
  throw new Error('Invalid hash length');
@@ -6366,7 +6529,8 @@ var pkcs1 = /*#__PURE__*/Object.freeze({
6366
6529
 
6367
6530
 
6368
6531
  const webCrypto$6 = util.getWebCrypto();
6369
- const nodeCrypto$4 = util.getNodeCrypto();
6532
+ const nodeCrypto$5 = util.getNodeCrypto();
6533
+ const _1n$3 = BigInt(1);
6370
6534
 
6371
6535
  /** Create signature
6372
6536
  * @param {module:enums.hash} hashAlgo - Hash algorithm
@@ -6407,7 +6571,7 @@ async function sign$7(hashAlgo, data, n, e, d, p, q, u, hashed) {
6407
6571
  * @returns {Boolean}
6408
6572
  * @async
6409
6573
  */
6410
- async function verify$7(hashAlgo, data, s, n, e, hashed) {
6574
+ async function verify$8(hashAlgo, data, s, n, e, hashed) {
6411
6575
  if (data && !util.isStream(data)) {
6412
6576
  if (util.getWebCrypto()) {
6413
6577
  try {
@@ -6480,16 +6644,14 @@ async function decrypt$4(data, n, e, d, p, q, u, randomPayload) {
6480
6644
  * @async
6481
6645
  */
6482
6646
  async function generate$5(bits, e) {
6483
- const BigInteger = await util.getBigInteger();
6484
-
6485
- e = new BigInteger(e);
6647
+ e = BigInt(e);
6486
6648
 
6487
6649
  // Native RSA keygen using Web Crypto
6488
6650
  if (util.getWebCrypto()) {
6489
6651
  const keyGenOpt = {
6490
6652
  name: 'RSASSA-PKCS1-v1_5',
6491
6653
  modulusLength: bits, // the specified keysize in bits
6492
- publicExponent: e.toUint8Array(), // take three bytes (max 65537) for exponent
6654
+ publicExponent: bigIntToUint8Array(e), // take three bytes (max 65537) for exponent
6493
6655
  hash: {
6494
6656
  name: 'SHA-1' // not required for actual RSA keys, but for crypto api 'sign' and 'verify'
6495
6657
  }
@@ -6504,12 +6666,12 @@ async function generate$5(bits, e) {
6504
6666
  } else if (util.getNodeCrypto()) {
6505
6667
  const opts = {
6506
6668
  modulusLength: bits,
6507
- publicExponent: e.toNumber(),
6669
+ publicExponent: bigIntToNumber(e),
6508
6670
  publicKeyEncoding: { type: 'pkcs1', format: 'jwk' },
6509
6671
  privateKeyEncoding: { type: 'pkcs1', format: 'jwk' }
6510
6672
  };
6511
6673
  const jwk = await new Promise((resolve, reject) => {
6512
- nodeCrypto$4.generateKeyPair('rsa', opts, (err, _, jwkPrivateKey) => {
6674
+ nodeCrypto$5.generateKeyPair('rsa', opts, (err, _, jwkPrivateKey) => {
6513
6675
  if (err) {
6514
6676
  reject(err);
6515
6677
  } else {
@@ -6527,26 +6689,26 @@ async function generate$5(bits, e) {
6527
6689
  let q;
6528
6690
  let n;
6529
6691
  do {
6530
- q = await randomProbablePrime(bits - (bits >> 1), e, 40);
6531
- p = await randomProbablePrime(bits >> 1, e, 40);
6532
- n = p.mul(q);
6533
- } while (n.bitLength() !== bits);
6692
+ q = randomProbablePrime(bits - (bits >> 1), e, 40);
6693
+ p = randomProbablePrime(bits >> 1, e, 40);
6694
+ n = p * q;
6695
+ } while (bitLength(n) !== bits);
6534
6696
 
6535
- const phi = p.dec().imul(q.dec());
6697
+ const phi = (p - _1n$3) * (q - _1n$3);
6536
6698
 
6537
- if (q.lt(p)) {
6699
+ if (q < p) {
6538
6700
  [p, q] = [q, p];
6539
6701
  }
6540
6702
 
6541
6703
  return {
6542
- n: n.toUint8Array(),
6543
- e: e.toUint8Array(),
6544
- d: e.modInv(phi).toUint8Array(),
6545
- p: p.toUint8Array(),
6546
- q: q.toUint8Array(),
6704
+ n: bigIntToUint8Array(n),
6705
+ e: bigIntToUint8Array(e),
6706
+ d: bigIntToUint8Array(modInv(e, phi)),
6707
+ p: bigIntToUint8Array(p),
6708
+ q: bigIntToUint8Array(q),
6547
6709
  // dp: d.mod(p.subn(1)),
6548
6710
  // dq: d.mod(q.subn(1)),
6549
- u: p.modInv(q).toUint8Array()
6711
+ u: bigIntToUint8Array(modInv(p, q))
6550
6712
  };
6551
6713
  }
6552
6714
 
@@ -6562,26 +6724,24 @@ async function generate$5(bits, e) {
6562
6724
  * @async
6563
6725
  */
6564
6726
  async function validateParams$8(n, e, d, p, q, u) {
6565
- const BigInteger = await util.getBigInteger();
6566
-
6567
- n = new BigInteger(n);
6568
- p = new BigInteger(p);
6569
- q = new BigInteger(q);
6727
+ n = uint8ArrayToBigInt(n);
6728
+ p = uint8ArrayToBigInt(p);
6729
+ q = uint8ArrayToBigInt(q);
6570
6730
 
6571
6731
  // expect pq = n
6572
- if (!p.mul(q).equal(n)) {
6732
+ if ((p * q) !== n) {
6573
6733
  return false;
6574
6734
  }
6575
6735
 
6576
- const two = new BigInteger(2);
6736
+ const _2n = BigInt(2);
6577
6737
  // expect p*u = 1 mod q
6578
- u = new BigInteger(u);
6579
- if (!p.mul(u).mod(q).isOne()) {
6738
+ u = uint8ArrayToBigInt(u);
6739
+ if (mod$2(p * u, q) !== BigInt(1)) {
6580
6740
  return false;
6581
6741
  }
6582
6742
 
6583
- e = new BigInteger(e);
6584
- d = new BigInteger(d);
6743
+ e = uint8ArrayToBigInt(e);
6744
+ d = uint8ArrayToBigInt(d);
6585
6745
  /**
6586
6746
  * In RSA pkcs#1 the exponents (d, e) are inverses modulo lcm(p-1, q-1)
6587
6747
  * We check that [de = 1 mod (p-1)] and [de = 1 mod (q-1)]
@@ -6589,11 +6749,11 @@ async function validateParams$8(n, e, d, p, q, u) {
6589
6749
  *
6590
6750
  * We blind the multiplication with r, and check that rde = r mod lcm(p-1, q-1)
6591
6751
  */
6592
- const nSizeOver3 = new BigInteger(Math.floor(n.bitLength() / 3));
6593
- const r = await getRandomBigInteger(two, two.leftShift(nSizeOver3)); // r in [ 2, 2^{|n|/3} ) < p and q
6594
- const rde = r.mul(d).mul(e);
6752
+ const nSizeOver3 = BigInt(Math.floor(bitLength(n) / 3));
6753
+ const r = getRandomBigInteger(_2n, _2n << nSizeOver3); // r in [ 2, 2^{|n|/3} ) < p and q
6754
+ const rde = r * d * e;
6595
6755
 
6596
- const areInverses = rde.mod(p.dec()).equal(r) && rde.mod(q.dec()).equal(r);
6756
+ const areInverses = mod$2(rde, p - _1n$3) === r && mod$2(rde, q - _1n$3) === r;
6597
6757
  if (!areInverses) {
6598
6758
  return false;
6599
6759
  }
@@ -6602,15 +6762,13 @@ async function validateParams$8(n, e, d, p, q, u) {
6602
6762
  }
6603
6763
 
6604
6764
  async function bnSign(hashAlgo, n, d, hashed) {
6605
- const BigInteger = await util.getBigInteger();
6606
-
6607
- n = new BigInteger(n);
6608
- const m = new BigInteger(await emsaEncode(hashAlgo, hashed, n.byteLength()));
6609
- d = new BigInteger(d);
6610
- if (m.gte(n)) {
6765
+ n = uint8ArrayToBigInt(n);
6766
+ const m = uint8ArrayToBigInt(emsaEncode(hashAlgo, hashed, byteLength(n)));
6767
+ d = uint8ArrayToBigInt(d);
6768
+ if (m >= n) {
6611
6769
  throw new Error('Message size cannot exceed modulus size');
6612
6770
  }
6613
- return m.modExp(d, n).toUint8Array('be', n.byteLength());
6771
+ return bigIntToUint8Array(modExp(m, d, n), 'be', byteLength(n));
6614
6772
  }
6615
6773
 
6616
6774
  async function webSign$1(hashName, data, n, e, d, p, q, u) {
@@ -6631,7 +6789,7 @@ async function webSign$1(hashName, data, n, e, d, p, q, u) {
6631
6789
  }
6632
6790
 
6633
6791
  async function nodeSign$1(hashAlgo, data, n, e, d, p, q, u) {
6634
- const sign = nodeCrypto$4.createSign(enums.read(enums.hash, hashAlgo));
6792
+ const sign = nodeCrypto$5.createSign(enums.read(enums.hash, hashAlgo));
6635
6793
  sign.write(data);
6636
6794
  sign.end();
6637
6795
 
@@ -6640,16 +6798,14 @@ async function nodeSign$1(hashAlgo, data, n, e, d, p, q, u) {
6640
6798
  }
6641
6799
 
6642
6800
  async function bnVerify(hashAlgo, s, n, e, hashed) {
6643
- const BigInteger = await util.getBigInteger();
6644
-
6645
- n = new BigInteger(n);
6646
- s = new BigInteger(s);
6647
- e = new BigInteger(e);
6648
- if (s.gte(n)) {
6801
+ n = uint8ArrayToBigInt(n);
6802
+ s = uint8ArrayToBigInt(s);
6803
+ e = uint8ArrayToBigInt(e);
6804
+ if (s >= n) {
6649
6805
  throw new Error('Signature size cannot exceed modulus size');
6650
6806
  }
6651
- const EM1 = s.modExp(e, n).toUint8Array('be', n.byteLength());
6652
- const EM2 = await emsaEncode(hashAlgo, hashed, n.byteLength());
6807
+ const EM1 = bigIntToUint8Array(modExp(s, e, n), 'be', byteLength(n));
6808
+ const EM2 = emsaEncode(hashAlgo, hashed, byteLength(n));
6653
6809
  return util.equalsUint8Array(EM1, EM2);
6654
6810
  }
6655
6811
 
@@ -6666,12 +6822,12 @@ async function nodeVerify$1(hashAlgo, data, s, n, e) {
6666
6822
  const jwk = publicToJWK(n, e);
6667
6823
  const key = { key: jwk, format: 'jwk', type: 'pkcs1' };
6668
6824
 
6669
- const verify = nodeCrypto$4.createVerify(enums.read(enums.hash, hashAlgo));
6825
+ const verify = nodeCrypto$5.createVerify(enums.read(enums.hash, hashAlgo));
6670
6826
  verify.write(data);
6671
6827
  verify.end();
6672
6828
 
6673
6829
  try {
6674
- return await verify.verify(key, s);
6830
+ return verify.verify(key, s);
6675
6831
  } catch (err) {
6676
6832
  return false;
6677
6833
  }
@@ -6679,65 +6835,59 @@ async function nodeVerify$1(hashAlgo, data, s, n, e) {
6679
6835
 
6680
6836
  async function nodeEncrypt(data, n, e) {
6681
6837
  const jwk = publicToJWK(n, e);
6682
- const key = { key: jwk, format: 'jwk', type: 'pkcs1', padding: nodeCrypto$4.constants.RSA_PKCS1_PADDING };
6838
+ const key = { key: jwk, format: 'jwk', type: 'pkcs1', padding: nodeCrypto$5.constants.RSA_PKCS1_PADDING };
6683
6839
 
6684
- return new Uint8Array(nodeCrypto$4.publicEncrypt(key, data));
6840
+ return new Uint8Array(nodeCrypto$5.publicEncrypt(key, data));
6685
6841
  }
6686
6842
 
6687
6843
  async function bnEncrypt(data, n, e) {
6688
- const BigInteger = await util.getBigInteger();
6689
-
6690
- n = new BigInteger(n);
6691
- data = new BigInteger(emeEncode(data, n.byteLength()));
6692
- e = new BigInteger(e);
6693
- if (data.gte(n)) {
6844
+ n = uint8ArrayToBigInt(n);
6845
+ data = uint8ArrayToBigInt(emeEncode(data, byteLength(n)));
6846
+ e = uint8ArrayToBigInt(e);
6847
+ if (data >= n) {
6694
6848
  throw new Error('Message size cannot exceed modulus size');
6695
6849
  }
6696
- return data.modExp(e, n).toUint8Array('be', n.byteLength());
6850
+ return bigIntToUint8Array(modExp(data, e, n), 'be', byteLength(n));
6697
6851
  }
6698
6852
 
6699
6853
  async function nodeDecrypt(data, n, e, d, p, q, u) {
6700
6854
  const jwk = await privateToJWK$1(n, e, d, p, q, u);
6701
- const key = { key: jwk, format: 'jwk' , type: 'pkcs1', padding: nodeCrypto$4.constants.RSA_PKCS1_PADDING };
6855
+ const key = { key: jwk, format: 'jwk' , type: 'pkcs1', padding: nodeCrypto$5.constants.RSA_PKCS1_PADDING };
6702
6856
 
6703
6857
  try {
6704
- return new Uint8Array(nodeCrypto$4.privateDecrypt(key, data));
6858
+ return new Uint8Array(nodeCrypto$5.privateDecrypt(key, data));
6705
6859
  } catch (err) {
6706
6860
  throw new Error('Decryption error');
6707
6861
  }
6708
6862
  }
6709
6863
 
6710
6864
  async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
6711
- const BigInteger = await util.getBigInteger();
6712
-
6713
- data = new BigInteger(data);
6714
- n = new BigInteger(n);
6715
- e = new BigInteger(e);
6716
- d = new BigInteger(d);
6717
- p = new BigInteger(p);
6718
- q = new BigInteger(q);
6719
- u = new BigInteger(u);
6720
- if (data.gte(n)) {
6865
+ data = uint8ArrayToBigInt(data);
6866
+ n = uint8ArrayToBigInt(n);
6867
+ e = uint8ArrayToBigInt(e);
6868
+ d = uint8ArrayToBigInt(d);
6869
+ p = uint8ArrayToBigInt(p);
6870
+ q = uint8ArrayToBigInt(q);
6871
+ u = uint8ArrayToBigInt(u);
6872
+ if (data >= n) {
6721
6873
  throw new Error('Data too large.');
6722
6874
  }
6723
- const dq = d.mod(q.dec()); // d mod (q-1)
6724
- const dp = d.mod(p.dec()); // d mod (p-1)
6725
-
6726
- const unblinder = (await getRandomBigInteger(new BigInteger(2), n)).mod(n);
6727
- const blinder = unblinder.modInv(n).modExp(e, n);
6728
- data = data.mul(blinder).mod(n);
6729
-
6875
+ const dq = mod$2(d, q - _1n$3); // d mod (q-1)
6876
+ const dp = mod$2(d, p - _1n$3); // d mod (p-1)
6730
6877
 
6731
- const mp = data.modExp(dp, p); // data**{d mod (q-1)} mod p
6732
- const mq = data.modExp(dq, q); // data**{d mod (p-1)} mod q
6733
- const h = u.mul(mq.sub(mp)).mod(q); // u * (mq-mp) mod q (operands already < q)
6878
+ const unblinder = getRandomBigInteger(BigInt(2), n);
6879
+ const blinder = modExp(modInv(unblinder, n), e, n);
6880
+ data = mod$2(data * blinder, n);
6734
6881
 
6735
- let result = h.mul(p).add(mp); // result < n due to relations above
6882
+ const mp = modExp(data, dp, p); // data**{d mod (q-1)} mod p
6883
+ const mq = modExp(data, dq, q); // data**{d mod (p-1)} mod q
6884
+ const h = mod$2(u * (mq - mp), q); // u * (mq-mp) mod q (operands already < q)
6736
6885
 
6737
- result = result.mul(unblinder).mod(n);
6886
+ let result = h * p + mp; // result < n due to relations above
6738
6887
 
6888
+ result = mod$2(result * unblinder, n);
6739
6889
 
6740
- return emeDecode(result.toUint8Array('be', n.byteLength()), randomPayload);
6890
+ return emeDecode(bigIntToUint8Array(result, 'be', byteLength(n)), randomPayload);
6741
6891
  }
6742
6892
 
6743
6893
  /** Convert Openpgp private key params to jwk key according to
@@ -6751,28 +6901,26 @@ async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
6751
6901
  * @param {Uint8Array} u
6752
6902
  */
6753
6903
  async function privateToJWK$1(n, e, d, p, q, u) {
6754
- const BigInteger = await util.getBigInteger();
6755
-
6756
- const pNum = new BigInteger(p);
6757
- const qNum = new BigInteger(q);
6758
- const dNum = new BigInteger(d);
6759
-
6760
- let dq = dNum.mod(qNum.dec()); // d mod (q-1)
6761
- let dp = dNum.mod(pNum.dec()); // d mod (p-1)
6762
- dp = dp.toUint8Array();
6763
- dq = dq.toUint8Array();
6904
+ const pNum = uint8ArrayToBigInt(p);
6905
+ const qNum = uint8ArrayToBigInt(q);
6906
+ const dNum = uint8ArrayToBigInt(d);
6907
+
6908
+ let dq = mod$2(dNum, qNum - _1n$3); // d mod (q-1)
6909
+ let dp = mod$2(dNum, pNum - _1n$3); // d mod (p-1)
6910
+ dp = bigIntToUint8Array(dp);
6911
+ dq = bigIntToUint8Array(dq);
6764
6912
  return {
6765
6913
  kty: 'RSA',
6766
- n: uint8ArrayToB64(n, true),
6767
- e: uint8ArrayToB64(e, true),
6768
- d: uint8ArrayToB64(d, true),
6914
+ n: uint8ArrayToB64(n),
6915
+ e: uint8ArrayToB64(e),
6916
+ d: uint8ArrayToB64(d),
6769
6917
  // switch p and q
6770
- p: uint8ArrayToB64(q, true),
6771
- q: uint8ArrayToB64(p, true),
6918
+ p: uint8ArrayToB64(q),
6919
+ q: uint8ArrayToB64(p),
6772
6920
  // switch dp and dq
6773
- dp: uint8ArrayToB64(dq, true),
6774
- dq: uint8ArrayToB64(dp, true),
6775
- qi: uint8ArrayToB64(u, true),
6921
+ dp: uint8ArrayToB64(dq),
6922
+ dq: uint8ArrayToB64(dp),
6923
+ qi: uint8ArrayToB64(u),
6776
6924
  ext: true
6777
6925
  };
6778
6926
  }
@@ -6786,8 +6934,8 @@ async function privateToJWK$1(n, e, d, p, q, u) {
6786
6934
  function publicToJWK(n, e) {
6787
6935
  return {
6788
6936
  kty: 'RSA',
6789
- n: uint8ArrayToB64(n, true),
6790
- e: uint8ArrayToB64(e, true),
6937
+ n: uint8ArrayToB64(n),
6938
+ e: uint8ArrayToB64(e),
6791
6939
  ext: true
6792
6940
  };
6793
6941
  }
@@ -6796,7 +6944,7 @@ function publicToJWK(n, e) {
6796
6944
  function jwkToPrivate(jwk, e) {
6797
6945
  return {
6798
6946
  n: b64ToUint8Array(jwk.n),
6799
- e: e.toUint8Array(),
6947
+ e: bigIntToUint8Array(e),
6800
6948
  d: b64ToUint8Array(jwk.d),
6801
6949
  // switch p and q
6802
6950
  p: b64ToUint8Array(jwk.q),
@@ -6813,7 +6961,7 @@ var rsa = /*#__PURE__*/Object.freeze({
6813
6961
  generate: generate$5,
6814
6962
  sign: sign$7,
6815
6963
  validateParams: validateParams$8,
6816
- verify: verify$7
6964
+ verify: verify$8
6817
6965
  });
6818
6966
 
6819
6967
  // GPG4Browsers - An OpenPGP implementation in javascript
@@ -6834,6 +6982,8 @@ var rsa = /*#__PURE__*/Object.freeze({
6834
6982
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6835
6983
 
6836
6984
 
6985
+ const _1n$2 = BigInt(1);
6986
+
6837
6987
  /**
6838
6988
  * ElGamal Encryption function
6839
6989
  * Note that in OpenPGP, the message needs to be padded with PKCS#1 (same as RSA)
@@ -6845,21 +6995,19 @@ var rsa = /*#__PURE__*/Object.freeze({
6845
6995
  * @async
6846
6996
  */
6847
6997
  async function encrypt$3(data, p, g, y) {
6848
- const BigInteger = await util.getBigInteger();
6849
-
6850
- p = new BigInteger(p);
6851
- g = new BigInteger(g);
6852
- y = new BigInteger(y);
6998
+ p = uint8ArrayToBigInt(p);
6999
+ g = uint8ArrayToBigInt(g);
7000
+ y = uint8ArrayToBigInt(y);
6853
7001
 
6854
- const padded = emeEncode(data, p.byteLength());
6855
- const m = new BigInteger(padded);
7002
+ const padded = emeEncode(data, byteLength(p));
7003
+ const m = uint8ArrayToBigInt(padded);
6856
7004
 
6857
7005
  // OpenPGP uses a "special" version of ElGamal where g is generator of the full group Z/pZ*
6858
7006
  // hence g has order p-1, and to avoid that k = 0 mod p-1, we need to pick k in [1, p-2]
6859
- const k = await getRandomBigInteger(new BigInteger(1), p.dec());
7007
+ const k = getRandomBigInteger(_1n$2, p - _1n$2);
6860
7008
  return {
6861
- c1: g.modExp(k, p).toUint8Array(),
6862
- c2: y.modExp(k, p).imul(m).imod(p).toUint8Array()
7009
+ c1: bigIntToUint8Array(modExp(g, k, p)),
7010
+ c2: bigIntToUint8Array(mod$2(modExp(y, k, p) * m, p))
6863
7011
  };
6864
7012
  }
6865
7013
 
@@ -6876,15 +7024,13 @@ async function encrypt$3(data, p, g, y) {
6876
7024
  * @async
6877
7025
  */
6878
7026
  async function decrypt$3(c1, c2, p, x, randomPayload) {
6879
- const BigInteger = await util.getBigInteger();
7027
+ c1 = uint8ArrayToBigInt(c1);
7028
+ c2 = uint8ArrayToBigInt(c2);
7029
+ p = uint8ArrayToBigInt(p);
7030
+ x = uint8ArrayToBigInt(x);
6880
7031
 
6881
- c1 = new BigInteger(c1);
6882
- c2 = new BigInteger(c2);
6883
- p = new BigInteger(p);
6884
- x = new BigInteger(x);
6885
-
6886
- const padded = c1.modExp(x, p).modInv(p).imul(c2).imod(p);
6887
- return emeDecode(padded.toUint8Array('be', p.byteLength()), randomPayload);
7032
+ const padded = mod$2(modInv(modExp(c1, x, p), p) * c2, p);
7033
+ return emeDecode(bigIntToUint8Array(padded, 'be', byteLength(p)), randomPayload);
6888
7034
  }
6889
7035
 
6890
7036
  /**
@@ -6897,22 +7043,19 @@ async function decrypt$3(c1, c2, p, x, randomPayload) {
6897
7043
  * @async
6898
7044
  */
6899
7045
  async function validateParams$7(p, g, y, x) {
6900
- const BigInteger = await util.getBigInteger();
6901
-
6902
- p = new BigInteger(p);
6903
- g = new BigInteger(g);
6904
- y = new BigInteger(y);
7046
+ p = uint8ArrayToBigInt(p);
7047
+ g = uint8ArrayToBigInt(g);
7048
+ y = uint8ArrayToBigInt(y);
6905
7049
 
6906
- const one = new BigInteger(1);
6907
7050
  // Check that 1 < g < p
6908
- if (g.lte(one) || g.gte(p)) {
7051
+ if (g <= _1n$2 || g >= p) {
6909
7052
  return false;
6910
7053
  }
6911
7054
 
6912
7055
  // Expect p-1 to be large
6913
- const pSize = new BigInteger(p.bitLength());
6914
- const n1023 = new BigInteger(1023);
6915
- if (pSize.lt(n1023)) {
7056
+ const pSize = BigInt(bitLength(p));
7057
+ const _1023n = BigInt(1023);
7058
+ if (pSize < _1023n) {
6916
7059
  return false;
6917
7060
  }
6918
7061
 
@@ -6920,7 +7063,7 @@ async function validateParams$7(p, g, y, x) {
6920
7063
  * g should have order p-1
6921
7064
  * Check that g ** (p-1) = 1 mod p
6922
7065
  */
6923
- if (!g.modExp(p.dec(), p).isOne()) {
7066
+ if (modExp(g, p - _1n$2, p) !== _1n$2) {
6924
7067
  return false;
6925
7068
  }
6926
7069
 
@@ -6931,14 +7074,15 @@ async function validateParams$7(p, g, y, x) {
6931
7074
  * We just check g**i != 1 for all i up to a threshold
6932
7075
  */
6933
7076
  let res = g;
6934
- const i = new BigInteger(1);
6935
- const threshold = new BigInteger(2).leftShift(new BigInteger(17)); // we want order > threshold
6936
- while (i.lt(threshold)) {
6937
- res = res.mul(g).imod(p);
6938
- if (res.isOne()) {
7077
+ let i = BigInt(1);
7078
+ const _2n = BigInt(2);
7079
+ const threshold = _2n << BigInt(17); // we want order > threshold
7080
+ while (i < threshold) {
7081
+ res = mod$2(res * g, p);
7082
+ if (res === _1n$2) {
6939
7083
  return false;
6940
7084
  }
6941
- i.iinc();
7085
+ i++;
6942
7086
  }
6943
7087
 
6944
7088
  /**
@@ -6947,11 +7091,10 @@ async function validateParams$7(p, g, y, x) {
6947
7091
  *
6948
7092
  * Blinded exponentiation computes g**{r(p-1) + x} to compare to y
6949
7093
  */
6950
- x = new BigInteger(x);
6951
- const two = new BigInteger(2);
6952
- const r = await getRandomBigInteger(two.leftShift(pSize.dec()), two.leftShift(pSize)); // draw r of same size as p-1
6953
- const rqx = p.dec().imul(r).iadd(x);
6954
- if (!y.equal(g.modExp(rqx, p))) {
7094
+ x = uint8ArrayToBigInt(x);
7095
+ const r = getRandomBigInteger(_2n << (pSize - _1n$2), _2n << pSize); // draw r of same size as p-1
7096
+ const rqx = (p - _1n$2) * r + x;
7097
+ if (y !== modExp(g, rqx, p)) {
6955
7098
  return false;
6956
7099
  }
6957
7100
 
@@ -6966,7 +7109,7 @@ var elgamal = /*#__PURE__*/Object.freeze({
6966
7109
  });
6967
7110
 
6968
7111
  // declare const globalThis: Record<string, any> | undefined;
6969
- const crypto$2 =
7112
+ const crypto$3 =
6970
7113
  typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
6971
7114
 
6972
7115
  const nacl = {};
@@ -8329,13 +8472,13 @@ nacl.setPRNG = function(fn) {
8329
8472
  (function() {
8330
8473
  // Initialize PRNG if environment provides CSPRNG.
8331
8474
  // If not, methods calling randombytes will throw.
8332
- if (crypto$2 && crypto$2.getRandomValues) {
8475
+ if (crypto$3 && crypto$3.getRandomValues) {
8333
8476
  // Browsers and Node v16+
8334
8477
  var QUOTA = 65536;
8335
8478
  nacl.setPRNG(function(x, n) {
8336
8479
  var i, v = new Uint8Array(n);
8337
8480
  for (i = 0; i < n; i += QUOTA) {
8338
- crypto$2.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
8481
+ crypto$3.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
8339
8482
  }
8340
8483
  for (i = 0; i < n; i++) x[i] = v[i];
8341
8484
  cleanup(v);
@@ -8784,15 +8927,15 @@ class UnparseablePacket {
8784
8927
 
8785
8928
 
8786
8929
  const webCrypto$5 = util.getWebCrypto();
8787
- const nodeCrypto$3 = util.getNodeCrypto();
8930
+ const nodeCrypto$4 = util.getNodeCrypto();
8788
8931
 
8789
8932
  const webCurves = {
8790
8933
  [enums.curve.nistP256]: 'P-256',
8791
8934
  [enums.curve.nistP384]: 'P-384',
8792
8935
  [enums.curve.nistP521]: 'P-521'
8793
8936
  };
8794
- const knownCurves = nodeCrypto$3 ? nodeCrypto$3.getCurves() : [];
8795
- const nodeCurves = nodeCrypto$3 ? {
8937
+ const knownCurves = nodeCrypto$4 ? nodeCrypto$4.getCurves() : [];
8938
+ const nodeCurves = nodeCrypto$4 ? {
8796
8939
  [enums.curve.secp256k1]: knownCurves.includes('secp256k1') ? 'secp256k1' : undefined,
8797
8940
  [enums.curve.nistP256]: knownCurves.includes('prime256v1') ? 'prime256v1' : undefined,
8798
8941
  [enums.curve.nistP384]: knownCurves.includes('secp384r1') ? 'secp384r1' : undefined,
@@ -8813,7 +8956,8 @@ const curves = {
8813
8956
  node: nodeCurves[enums.curve.nistP256],
8814
8957
  web: webCurves[enums.curve.nistP256],
8815
8958
  payloadSize: 32,
8816
- sharedSize: 256
8959
+ sharedSize: 256,
8960
+ wireFormatLeadingByte: 0x04
8817
8961
  },
8818
8962
  [enums.curve.nistP384]: {
8819
8963
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22],
@@ -8823,7 +8967,8 @@ const curves = {
8823
8967
  node: nodeCurves[enums.curve.nistP384],
8824
8968
  web: webCurves[enums.curve.nistP384],
8825
8969
  payloadSize: 48,
8826
- sharedSize: 384
8970
+ sharedSize: 384,
8971
+ wireFormatLeadingByte: 0x04
8827
8972
  },
8828
8973
  [enums.curve.nistP521]: {
8829
8974
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23],
@@ -8833,7 +8978,8 @@ const curves = {
8833
8978
  node: nodeCurves[enums.curve.nistP521],
8834
8979
  web: webCurves[enums.curve.nistP521],
8835
8980
  payloadSize: 66,
8836
- sharedSize: 528
8981
+ sharedSize: 528,
8982
+ wireFormatLeadingByte: 0x04
8837
8983
  },
8838
8984
  [enums.curve.secp256k1]: {
8839
8985
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x0A],
@@ -8841,14 +8987,16 @@ const curves = {
8841
8987
  hash: enums.hash.sha256,
8842
8988
  cipher: enums.symmetric.aes128,
8843
8989
  node: nodeCurves[enums.curve.secp256k1],
8844
- payloadSize: 32
8990
+ payloadSize: 32,
8991
+ wireFormatLeadingByte: 0x04
8845
8992
  },
8846
8993
  [enums.curve.ed25519Legacy]: {
8847
8994
  oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
8848
8995
  keyType: enums.publicKey.eddsaLegacy,
8849
8996
  hash: enums.hash.sha512,
8850
8997
  node: false, // nodeCurves.ed25519 TODO
8851
- payloadSize: 32
8998
+ payloadSize: 32,
8999
+ wireFormatLeadingByte: 0x40
8852
9000
  },
8853
9001
  [enums.curve.curve25519Legacy]: {
8854
9002
  oid: [0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01],
@@ -8856,7 +9004,8 @@ const curves = {
8856
9004
  hash: enums.hash.sha256,
8857
9005
  cipher: enums.symmetric.aes128,
8858
9006
  node: false, // nodeCurves.curve25519 TODO
8859
- payloadSize: 32
9007
+ payloadSize: 32,
9008
+ wireFormatLeadingByte: 0x40
8860
9009
  },
8861
9010
  [enums.curve.brainpoolP256r1]: {
8862
9011
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07],
@@ -8864,7 +9013,8 @@ const curves = {
8864
9013
  hash: enums.hash.sha256,
8865
9014
  cipher: enums.symmetric.aes128,
8866
9015
  node: nodeCurves[enums.curve.brainpoolP256r1],
8867
- payloadSize: 32
9016
+ payloadSize: 32,
9017
+ wireFormatLeadingByte: 0x04
8868
9018
  },
8869
9019
  [enums.curve.brainpoolP384r1]: {
8870
9020
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B],
@@ -8872,7 +9022,8 @@ const curves = {
8872
9022
  hash: enums.hash.sha384,
8873
9023
  cipher: enums.symmetric.aes192,
8874
9024
  node: nodeCurves[enums.curve.brainpoolP384r1],
8875
- payloadSize: 48
9025
+ payloadSize: 48,
9026
+ wireFormatLeadingByte: 0x04
8876
9027
  },
8877
9028
  [enums.curve.brainpoolP512r1]: {
8878
9029
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D],
@@ -8880,7 +9031,8 @@ const curves = {
8880
9031
  hash: enums.hash.sha512,
8881
9032
  cipher: enums.symmetric.aes256,
8882
9033
  node: nodeCurves[enums.curve.brainpoolP512r1],
8883
- payloadSize: 64
9034
+ payloadSize: 64,
9035
+ wireFormatLeadingByte: 0x04
8884
9036
  }
8885
9037
  };
8886
9038
 
@@ -8904,6 +9056,7 @@ class CurveWithOID {
8904
9056
  this.web = params.web;
8905
9057
  this.payloadSize = params.payloadSize;
8906
9058
  this.sharedSize = params.sharedSize;
9059
+ this.wireFormatLeadingByte = params.wireFormatLeadingByte;
8907
9060
  if (this.web && util.getWebCrypto()) {
8908
9061
  this.type = 'web';
8909
9062
  } else if (this.node && util.getNodeCrypto()) {
@@ -8919,7 +9072,7 @@ class CurveWithOID {
8919
9072
  switch (this.type) {
8920
9073
  case 'web':
8921
9074
  try {
8922
- return await webGenKeyPair(this.name);
9075
+ return await webGenKeyPair(this.name, this.wireFormatLeadingByte);
8923
9076
  } catch (err) {
8924
9077
  util.printDebugError('Browser did not support generating ec key ' + err.message);
8925
9078
  return jsGenKeyPair(this.name);
@@ -8932,13 +9085,13 @@ class CurveWithOID {
8932
9085
  privateKey[31] &= 248;
8933
9086
  const secretKey = privateKey.slice().reverse();
8934
9087
  const { publicKey: rawPublicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
8935
- const publicKey = util.concatUint8Array([new Uint8Array([0x40]), rawPublicKey]);
9088
+ const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), rawPublicKey]);
8936
9089
  return { publicKey, privateKey };
8937
9090
  }
8938
9091
  case 'ed25519Legacy': {
8939
9092
  const privateKey = getRandomBytes(32);
8940
9093
  const keyPair = nacl.sign.keyPair.fromSeed(privateKey);
8941
- const publicKey = util.concatUint8Array([new Uint8Array([0x40]), keyPair.publicKey]);
9094
+ const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), keyPair.publicKey]);
8942
9095
  return { publicKey, privateKey };
8943
9096
  }
8944
9097
  default:
@@ -9024,6 +9177,20 @@ async function validateStandardParams(algo, oid, Q, d) {
9024
9177
  return true;
9025
9178
  }
9026
9179
 
9180
+ /**
9181
+ * Check whether the public point has a valid encoding.
9182
+ * NB: this function does not check e.g. whether the point belongs to the curve.
9183
+ */
9184
+ function checkPublicPointEnconding(curve, V) {
9185
+ const { payloadSize, wireFormatLeadingByte, name: curveName } = curve;
9186
+
9187
+ const pointSize = (curveName === enums.curve.curve25519Legacy || curveName === enums.curve.ed25519Legacy) ? payloadSize : payloadSize * 2;
9188
+
9189
+ if (V[0] !== wireFormatLeadingByte || V.length !== pointSize + 1) {
9190
+ throw new Error('Invalid point encoding');
9191
+ }
9192
+ }
9193
+
9027
9194
  //////////////////////////
9028
9195
  // //
9029
9196
  // Helper functions //
@@ -9036,7 +9203,7 @@ async function jsGenKeyPair(name) {
9036
9203
  return { publicKey, privateKey };
9037
9204
  }
9038
9205
 
9039
- async function webGenKeyPair(name) {
9206
+ async function webGenKeyPair(name, wireFormatLeadingByte) {
9040
9207
  // Note: keys generated with ECDSA and ECDH are structurally equivalent
9041
9208
  const webCryptoKey = await webCrypto$5.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']);
9042
9209
 
@@ -9044,14 +9211,14 @@ async function webGenKeyPair(name) {
9044
9211
  const publicKey = await webCrypto$5.exportKey('jwk', webCryptoKey.publicKey);
9045
9212
 
9046
9213
  return {
9047
- publicKey: jwkToRawPublic(publicKey),
9214
+ publicKey: jwkToRawPublic(publicKey, wireFormatLeadingByte),
9048
9215
  privateKey: b64ToUint8Array(privateKey.d)
9049
9216
  };
9050
9217
  }
9051
9218
 
9052
9219
  async function nodeGenKeyPair(name) {
9053
9220
  // Note: ECDSA and ECDH key generation is structurally equivalent
9054
- const ecdh = nodeCrypto$3.createECDH(nodeCurves[name]);
9221
+ const ecdh = nodeCrypto$4.createECDH(nodeCurves[name]);
9055
9222
  await ecdh.generateKeys();
9056
9223
  return {
9057
9224
  publicKey: new Uint8Array(ecdh.getPublicKey()),
@@ -9070,11 +9237,11 @@ async function nodeGenKeyPair(name) {
9070
9237
  *
9071
9238
  * @returns {Uint8Array} Raw public key.
9072
9239
  */
9073
- function jwkToRawPublic(jwk) {
9240
+ function jwkToRawPublic(jwk, wireFormatLeadingByte) {
9074
9241
  const bufX = b64ToUint8Array(jwk.x);
9075
9242
  const bufY = b64ToUint8Array(jwk.y);
9076
9243
  const publicKey = new Uint8Array(bufX.length + bufY.length + 1);
9077
- publicKey[0] = 0x04;
9244
+ publicKey[0] = wireFormatLeadingByte;
9078
9245
  publicKey.set(bufX, 1);
9079
9246
  publicKey.set(bufY, bufX.length + 1);
9080
9247
  return publicKey;
@@ -9095,8 +9262,8 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
9095
9262
  const jwk = {
9096
9263
  kty: 'EC',
9097
9264
  crv: name,
9098
- x: uint8ArrayToB64(bufX, true),
9099
- y: uint8ArrayToB64(bufY, true),
9265
+ x: uint8ArrayToB64(bufX),
9266
+ y: uint8ArrayToB64(bufY),
9100
9267
  ext: true
9101
9268
  };
9102
9269
  return jwk;
@@ -9112,7 +9279,7 @@ function rawPublicToJWK(payloadSize, name, publicKey) {
9112
9279
  */
9113
9280
  function privateToJWK(payloadSize, name, publicKey, privateKey) {
9114
9281
  const jwk = rawPublicToJWK(payloadSize, name, publicKey);
9115
- jwk.d = uint8ArrayToB64(privateKey, true);
9282
+ jwk.d = uint8ArrayToB64(privateKey);
9116
9283
  return jwk;
9117
9284
  }
9118
9285
 
@@ -9135,7 +9302,7 @@ function privateToJWK(payloadSize, name, publicKey, privateKey) {
9135
9302
 
9136
9303
 
9137
9304
  const webCrypto$4 = util.getWebCrypto();
9138
- const nodeCrypto$2 = util.getNodeCrypto();
9305
+ const nodeCrypto$3 = util.getNodeCrypto();
9139
9306
 
9140
9307
  /**
9141
9308
  * Sign a message using the provided key
@@ -9153,6 +9320,7 @@ const nodeCrypto$2 = util.getNodeCrypto();
9153
9320
  */
9154
9321
  async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9155
9322
  const curve = new CurveWithOID(oid);
9323
+ checkPublicPointEnconding(curve, publicKey);
9156
9324
  if (message && !util.isStream(message)) {
9157
9325
  const keyPair = { publicKey, privateKey };
9158
9326
  switch (curve.type) {
@@ -9180,8 +9348,8 @@ async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9180
9348
  // lowS: non-canonical sig: https://stackoverflow.com/questions/74338846/ecdsa-signature-verification-mismatch
9181
9349
  const signature = nobleCurve.sign(hashed, privateKey, { lowS: false });
9182
9350
  return {
9183
- r: signature.r.toUint8Array('be', curve.payloadSize),
9184
- s: signature.s.toUint8Array('be', curve.payloadSize)
9351
+ r: bigIntToUint8Array(signature.r, 'be', curve.payloadSize),
9352
+ s: bigIntToUint8Array(signature.s, 'be', curve.payloadSize)
9185
9353
  };
9186
9354
  }
9187
9355
 
@@ -9197,8 +9365,9 @@ async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9197
9365
  * @returns {Boolean}
9198
9366
  * @async
9199
9367
  */
9200
- async function verify$6(oid, hashAlgo, signature, message, publicKey, hashed) {
9368
+ async function verify$7(oid, hashAlgo, signature, message, publicKey, hashed) {
9201
9369
  const curve = new CurveWithOID(oid);
9370
+ checkPublicPointEnconding(curve, publicKey);
9202
9371
  // See https://github.com/openpgpjs/openpgpjs/pull/948.
9203
9372
  // NB: the impact was more likely limited to Brainpool curves, since thanks
9204
9373
  // to WebCrypto availability, NIST curve should not have been affected.
@@ -9264,7 +9433,8 @@ async function validateParams$6(oid, Q, d) {
9264
9433
  const hashed = await hash.digest(hashAlgo, message);
9265
9434
  try {
9266
9435
  const signature = await sign$6(oid, hashAlgo, message, Q, d, hashed);
9267
- return await verify$6(oid, hashAlgo, signature, message, Q, hashed);
9436
+ // eslint-disable-next-line @typescript-eslint/return-await
9437
+ return await verify$7(oid, hashAlgo, signature, message, Q, hashed);
9268
9438
  } catch (err) {
9269
9439
  return false;
9270
9440
  }
@@ -9359,7 +9529,7 @@ async function nodeSign(curve, hashAlgo, message, privateKey) {
9359
9529
  privateKey: nodeBuffer.from(privateKey)
9360
9530
  });
9361
9531
 
9362
- const sign = nodeCrypto$2.createSign(enums.read(enums.hash, hashAlgo));
9532
+ const sign = nodeCrypto$3.createSign(enums.read(enums.hash, hashAlgo));
9363
9533
  sign.write(message);
9364
9534
  sign.end();
9365
9535
 
@@ -9380,7 +9550,7 @@ async function nodeVerify(curve, hashAlgo, { r, s }, message, publicKey) {
9380
9550
  publicKey: nodeBuffer.from(publicKey)
9381
9551
  });
9382
9552
 
9383
- const verify = nodeCrypto$2.createVerify(enums.read(enums.hash, hashAlgo));
9553
+ const verify = nodeCrypto$3.createVerify(enums.read(enums.hash, hashAlgo));
9384
9554
  verify.write(message);
9385
9555
  verify.end();
9386
9556
 
@@ -9397,7 +9567,760 @@ var ecdsa = /*#__PURE__*/Object.freeze({
9397
9567
  __proto__: null,
9398
9568
  sign: sign$6,
9399
9569
  validateParams: validateParams$6,
9400
- verify: verify$6
9570
+ verify: verify$7
9571
+ });
9572
+
9573
+ /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
9574
+ const nodeCrypto$2 = null;
9575
+ const _0n$1 = BigInt(0);
9576
+ const _1n$1 = BigInt(1);
9577
+ const _2n = BigInt(2);
9578
+ const _8n = BigInt(8);
9579
+ const CU_O = BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989');
9580
+ const CURVE = Object.freeze({
9581
+ a: BigInt(-1),
9582
+ d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
9583
+ P: BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819949'),
9584
+ l: CU_O,
9585
+ n: CU_O,
9586
+ h: BigInt(8),
9587
+ Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
9588
+ Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
9589
+ });
9590
+ const POW_2_256 = BigInt('0x10000000000000000000000000000000000000000000000000000000000000000');
9591
+ const SQRT_M1 = BigInt('19681161376707505956807079304988542015446066515923890162744021073123829784752');
9592
+ BigInt('6853475219497561581579357271197624642482790079785650197046958215289687604742');
9593
+ const SQRT_AD_MINUS_ONE = BigInt('25063068953384623474111414158702152701244531502492656460079210482610430750235');
9594
+ const INVSQRT_A_MINUS_D = BigInt('54469307008909316920995813868745141605393597292927456921205312896311721017578');
9595
+ const ONE_MINUS_D_SQ = BigInt('1159843021668779879193775521855586647937357759715417654439879720876111806838');
9596
+ const D_MINUS_ONE_SQ = BigInt('40440834346308536858101042469323190826248399146238708352240133220865137265952');
9597
+ class ExtendedPoint {
9598
+ constructor(x, y, z, t) {
9599
+ this.x = x;
9600
+ this.y = y;
9601
+ this.z = z;
9602
+ this.t = t;
9603
+ }
9604
+ static fromAffine(p) {
9605
+ if (!(p instanceof Point)) {
9606
+ throw new TypeError('ExtendedPoint#fromAffine: expected Point');
9607
+ }
9608
+ if (p.equals(Point.ZERO))
9609
+ return ExtendedPoint.ZERO;
9610
+ return new ExtendedPoint(p.x, p.y, _1n$1, mod$1(p.x * p.y));
9611
+ }
9612
+ static toAffineBatch(points) {
9613
+ const toInv = invertBatch(points.map((p) => p.z));
9614
+ return points.map((p, i) => p.toAffine(toInv[i]));
9615
+ }
9616
+ static normalizeZ(points) {
9617
+ return this.toAffineBatch(points).map(this.fromAffine);
9618
+ }
9619
+ equals(other) {
9620
+ assertExtPoint(other);
9621
+ const { x: X1, y: Y1, z: Z1 } = this;
9622
+ const { x: X2, y: Y2, z: Z2 } = other;
9623
+ const X1Z2 = mod$1(X1 * Z2);
9624
+ const X2Z1 = mod$1(X2 * Z1);
9625
+ const Y1Z2 = mod$1(Y1 * Z2);
9626
+ const Y2Z1 = mod$1(Y2 * Z1);
9627
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
9628
+ }
9629
+ negate() {
9630
+ return new ExtendedPoint(mod$1(-this.x), this.y, this.z, mod$1(-this.t));
9631
+ }
9632
+ double() {
9633
+ const { x: X1, y: Y1, z: Z1 } = this;
9634
+ const { a } = CURVE;
9635
+ const A = mod$1(X1 * X1);
9636
+ const B = mod$1(Y1 * Y1);
9637
+ const C = mod$1(_2n * mod$1(Z1 * Z1));
9638
+ const D = mod$1(a * A);
9639
+ const x1y1 = X1 + Y1;
9640
+ const E = mod$1(mod$1(x1y1 * x1y1) - A - B);
9641
+ const G = D + B;
9642
+ const F = G - C;
9643
+ const H = D - B;
9644
+ const X3 = mod$1(E * F);
9645
+ const Y3 = mod$1(G * H);
9646
+ const T3 = mod$1(E * H);
9647
+ const Z3 = mod$1(F * G);
9648
+ return new ExtendedPoint(X3, Y3, Z3, T3);
9649
+ }
9650
+ add(other) {
9651
+ assertExtPoint(other);
9652
+ const { x: X1, y: Y1, z: Z1, t: T1 } = this;
9653
+ const { x: X2, y: Y2, z: Z2, t: T2 } = other;
9654
+ const A = mod$1((Y1 - X1) * (Y2 + X2));
9655
+ const B = mod$1((Y1 + X1) * (Y2 - X2));
9656
+ const F = mod$1(B - A);
9657
+ if (F === _0n$1)
9658
+ return this.double();
9659
+ const C = mod$1(Z1 * _2n * T2);
9660
+ const D = mod$1(T1 * _2n * Z2);
9661
+ const E = D + C;
9662
+ const G = B + A;
9663
+ const H = D - C;
9664
+ const X3 = mod$1(E * F);
9665
+ const Y3 = mod$1(G * H);
9666
+ const T3 = mod$1(E * H);
9667
+ const Z3 = mod$1(F * G);
9668
+ return new ExtendedPoint(X3, Y3, Z3, T3);
9669
+ }
9670
+ subtract(other) {
9671
+ return this.add(other.negate());
9672
+ }
9673
+ precomputeWindow(W) {
9674
+ const windows = 1 + 256 / W;
9675
+ const points = [];
9676
+ let p = this;
9677
+ let base = p;
9678
+ for (let window = 0; window < windows; window++) {
9679
+ base = p;
9680
+ points.push(base);
9681
+ for (let i = 1; i < 2 ** (W - 1); i++) {
9682
+ base = base.add(p);
9683
+ points.push(base);
9684
+ }
9685
+ p = base.double();
9686
+ }
9687
+ return points;
9688
+ }
9689
+ wNAF(n, affinePoint) {
9690
+ if (!affinePoint && this.equals(ExtendedPoint.BASE))
9691
+ affinePoint = Point.BASE;
9692
+ const W = (affinePoint && affinePoint._WINDOW_SIZE) || 1;
9693
+ if (256 % W) {
9694
+ throw new Error('Point#wNAF: Invalid precomputation window, must be power of 2');
9695
+ }
9696
+ let precomputes = affinePoint && pointPrecomputes.get(affinePoint);
9697
+ if (!precomputes) {
9698
+ precomputes = this.precomputeWindow(W);
9699
+ if (affinePoint && W !== 1) {
9700
+ precomputes = ExtendedPoint.normalizeZ(precomputes);
9701
+ pointPrecomputes.set(affinePoint, precomputes);
9702
+ }
9703
+ }
9704
+ let p = ExtendedPoint.ZERO;
9705
+ let f = ExtendedPoint.BASE;
9706
+ const windows = 1 + 256 / W;
9707
+ const windowSize = 2 ** (W - 1);
9708
+ const mask = BigInt(2 ** W - 1);
9709
+ const maxNumber = 2 ** W;
9710
+ const shiftBy = BigInt(W);
9711
+ for (let window = 0; window < windows; window++) {
9712
+ const offset = window * windowSize;
9713
+ let wbits = Number(n & mask);
9714
+ n >>= shiftBy;
9715
+ if (wbits > windowSize) {
9716
+ wbits -= maxNumber;
9717
+ n += _1n$1;
9718
+ }
9719
+ const offset1 = offset;
9720
+ const offset2 = offset + Math.abs(wbits) - 1;
9721
+ const cond1 = window % 2 !== 0;
9722
+ const cond2 = wbits < 0;
9723
+ if (wbits === 0) {
9724
+ f = f.add(constTimeNegate(cond1, precomputes[offset1]));
9725
+ }
9726
+ else {
9727
+ p = p.add(constTimeNegate(cond2, precomputes[offset2]));
9728
+ }
9729
+ }
9730
+ return ExtendedPoint.normalizeZ([p, f])[0];
9731
+ }
9732
+ multiply(scalar, affinePoint) {
9733
+ return this.wNAF(normalizeScalar(scalar, CURVE.l), affinePoint);
9734
+ }
9735
+ multiplyUnsafe(scalar) {
9736
+ let n = normalizeScalar(scalar, CURVE.l, false);
9737
+ const G = ExtendedPoint.BASE;
9738
+ const P0 = ExtendedPoint.ZERO;
9739
+ if (n === _0n$1)
9740
+ return P0;
9741
+ if (this.equals(P0) || n === _1n$1)
9742
+ return this;
9743
+ if (this.equals(G))
9744
+ return this.wNAF(n);
9745
+ let p = P0;
9746
+ let d = this;
9747
+ while (n > _0n$1) {
9748
+ if (n & _1n$1)
9749
+ p = p.add(d);
9750
+ d = d.double();
9751
+ n >>= _1n$1;
9752
+ }
9753
+ return p;
9754
+ }
9755
+ isSmallOrder() {
9756
+ return this.multiplyUnsafe(CURVE.h).equals(ExtendedPoint.ZERO);
9757
+ }
9758
+ isTorsionFree() {
9759
+ let p = this.multiplyUnsafe(CURVE.l / _2n).double();
9760
+ if (CURVE.l % _2n)
9761
+ p = p.add(this);
9762
+ return p.equals(ExtendedPoint.ZERO);
9763
+ }
9764
+ toAffine(invZ) {
9765
+ const { x, y, z } = this;
9766
+ const is0 = this.equals(ExtendedPoint.ZERO);
9767
+ if (invZ == null)
9768
+ invZ = is0 ? _8n : invert(z);
9769
+ const ax = mod$1(x * invZ);
9770
+ const ay = mod$1(y * invZ);
9771
+ const zz = mod$1(z * invZ);
9772
+ if (is0)
9773
+ return Point.ZERO;
9774
+ if (zz !== _1n$1)
9775
+ throw new Error('invZ was invalid');
9776
+ return new Point(ax, ay);
9777
+ }
9778
+ fromRistrettoBytes() {
9779
+ legacyRist();
9780
+ }
9781
+ toRistrettoBytes() {
9782
+ legacyRist();
9783
+ }
9784
+ fromRistrettoHash() {
9785
+ legacyRist();
9786
+ }
9787
+ }
9788
+ ExtendedPoint.BASE = new ExtendedPoint(CURVE.Gx, CURVE.Gy, _1n$1, mod$1(CURVE.Gx * CURVE.Gy));
9789
+ ExtendedPoint.ZERO = new ExtendedPoint(_0n$1, _1n$1, _1n$1, _0n$1);
9790
+ function constTimeNegate(condition, item) {
9791
+ const neg = item.negate();
9792
+ return condition ? neg : item;
9793
+ }
9794
+ function assertExtPoint(other) {
9795
+ if (!(other instanceof ExtendedPoint))
9796
+ throw new TypeError('ExtendedPoint expected');
9797
+ }
9798
+ function assertRstPoint(other) {
9799
+ if (!(other instanceof RistrettoPoint))
9800
+ throw new TypeError('RistrettoPoint expected');
9801
+ }
9802
+ function legacyRist() {
9803
+ throw new Error('Legacy method: switch to RistrettoPoint');
9804
+ }
9805
+ class RistrettoPoint {
9806
+ constructor(ep) {
9807
+ this.ep = ep;
9808
+ }
9809
+ static calcElligatorRistrettoMap(r0) {
9810
+ const { d } = CURVE;
9811
+ const r = mod$1(SQRT_M1 * r0 * r0);
9812
+ const Ns = mod$1((r + _1n$1) * ONE_MINUS_D_SQ);
9813
+ let c = BigInt(-1);
9814
+ const D = mod$1((c - d * r) * mod$1(r + d));
9815
+ let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
9816
+ let s_ = mod$1(s * r0);
9817
+ if (!edIsNegative(s_))
9818
+ s_ = mod$1(-s_);
9819
+ if (!Ns_D_is_sq)
9820
+ s = s_;
9821
+ if (!Ns_D_is_sq)
9822
+ c = r;
9823
+ const Nt = mod$1(c * (r - _1n$1) * D_MINUS_ONE_SQ - D);
9824
+ const s2 = s * s;
9825
+ const W0 = mod$1((s + s) * D);
9826
+ const W1 = mod$1(Nt * SQRT_AD_MINUS_ONE);
9827
+ const W2 = mod$1(_1n$1 - s2);
9828
+ const W3 = mod$1(_1n$1 + s2);
9829
+ return new ExtendedPoint(mod$1(W0 * W3), mod$1(W2 * W1), mod$1(W1 * W3), mod$1(W0 * W2));
9830
+ }
9831
+ static hashToCurve(hex) {
9832
+ hex = ensureBytes(hex, 64);
9833
+ const r1 = bytes255ToNumberLE(hex.slice(0, 32));
9834
+ const R1 = this.calcElligatorRistrettoMap(r1);
9835
+ const r2 = bytes255ToNumberLE(hex.slice(32, 64));
9836
+ const R2 = this.calcElligatorRistrettoMap(r2);
9837
+ return new RistrettoPoint(R1.add(R2));
9838
+ }
9839
+ static fromHex(hex) {
9840
+ hex = ensureBytes(hex, 32);
9841
+ const { a, d } = CURVE;
9842
+ const emsg = 'RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint';
9843
+ const s = bytes255ToNumberLE(hex);
9844
+ if (!equalBytes(numberTo32BytesLE(s), hex) || edIsNegative(s))
9845
+ throw new Error(emsg);
9846
+ const s2 = mod$1(s * s);
9847
+ const u1 = mod$1(_1n$1 + a * s2);
9848
+ const u2 = mod$1(_1n$1 - a * s2);
9849
+ const u1_2 = mod$1(u1 * u1);
9850
+ const u2_2 = mod$1(u2 * u2);
9851
+ const v = mod$1(a * d * u1_2 - u2_2);
9852
+ const { isValid, value: I } = invertSqrt(mod$1(v * u2_2));
9853
+ const Dx = mod$1(I * u2);
9854
+ const Dy = mod$1(I * Dx * v);
9855
+ let x = mod$1((s + s) * Dx);
9856
+ if (edIsNegative(x))
9857
+ x = mod$1(-x);
9858
+ const y = mod$1(u1 * Dy);
9859
+ const t = mod$1(x * y);
9860
+ if (!isValid || edIsNegative(t) || y === _0n$1)
9861
+ throw new Error(emsg);
9862
+ return new RistrettoPoint(new ExtendedPoint(x, y, _1n$1, t));
9863
+ }
9864
+ toRawBytes() {
9865
+ let { x, y, z, t } = this.ep;
9866
+ const u1 = mod$1(mod$1(z + y) * mod$1(z - y));
9867
+ const u2 = mod$1(x * y);
9868
+ const u2sq = mod$1(u2 * u2);
9869
+ const { value: invsqrt } = invertSqrt(mod$1(u1 * u2sq));
9870
+ const D1 = mod$1(invsqrt * u1);
9871
+ const D2 = mod$1(invsqrt * u2);
9872
+ const zInv = mod$1(D1 * D2 * t);
9873
+ let D;
9874
+ if (edIsNegative(t * zInv)) {
9875
+ let _x = mod$1(y * SQRT_M1);
9876
+ let _y = mod$1(x * SQRT_M1);
9877
+ x = _x;
9878
+ y = _y;
9879
+ D = mod$1(D1 * INVSQRT_A_MINUS_D);
9880
+ }
9881
+ else {
9882
+ D = D2;
9883
+ }
9884
+ if (edIsNegative(x * zInv))
9885
+ y = mod$1(-y);
9886
+ let s = mod$1((z - y) * D);
9887
+ if (edIsNegative(s))
9888
+ s = mod$1(-s);
9889
+ return numberTo32BytesLE(s);
9890
+ }
9891
+ toHex() {
9892
+ return bytesToHex(this.toRawBytes());
9893
+ }
9894
+ toString() {
9895
+ return this.toHex();
9896
+ }
9897
+ equals(other) {
9898
+ assertRstPoint(other);
9899
+ const a = this.ep;
9900
+ const b = other.ep;
9901
+ const one = mod$1(a.x * b.y) === mod$1(a.y * b.x);
9902
+ const two = mod$1(a.y * b.y) === mod$1(a.x * b.x);
9903
+ return one || two;
9904
+ }
9905
+ add(other) {
9906
+ assertRstPoint(other);
9907
+ return new RistrettoPoint(this.ep.add(other.ep));
9908
+ }
9909
+ subtract(other) {
9910
+ assertRstPoint(other);
9911
+ return new RistrettoPoint(this.ep.subtract(other.ep));
9912
+ }
9913
+ multiply(scalar) {
9914
+ return new RistrettoPoint(this.ep.multiply(scalar));
9915
+ }
9916
+ multiplyUnsafe(scalar) {
9917
+ return new RistrettoPoint(this.ep.multiplyUnsafe(scalar));
9918
+ }
9919
+ }
9920
+ RistrettoPoint.BASE = new RistrettoPoint(ExtendedPoint.BASE);
9921
+ RistrettoPoint.ZERO = new RistrettoPoint(ExtendedPoint.ZERO);
9922
+ const pointPrecomputes = new WeakMap();
9923
+ class Point {
9924
+ constructor(x, y) {
9925
+ this.x = x;
9926
+ this.y = y;
9927
+ }
9928
+ _setWindowSize(windowSize) {
9929
+ this._WINDOW_SIZE = windowSize;
9930
+ pointPrecomputes.delete(this);
9931
+ }
9932
+ static fromHex(hex, strict = true) {
9933
+ const { d, P } = CURVE;
9934
+ hex = ensureBytes(hex, 32);
9935
+ const normed = hex.slice();
9936
+ normed[31] = hex[31] & ~0x80;
9937
+ const y = bytesToNumberLE(normed);
9938
+ if (strict && y >= P)
9939
+ throw new Error('Expected 0 < hex < P');
9940
+ if (!strict && y >= POW_2_256)
9941
+ throw new Error('Expected 0 < hex < 2**256');
9942
+ const y2 = mod$1(y * y);
9943
+ const u = mod$1(y2 - _1n$1);
9944
+ const v = mod$1(d * y2 + _1n$1);
9945
+ let { isValid, value: x } = uvRatio(u, v);
9946
+ if (!isValid)
9947
+ throw new Error('Point.fromHex: invalid y coordinate');
9948
+ const isXOdd = (x & _1n$1) === _1n$1;
9949
+ const isLastByteOdd = (hex[31] & 0x80) !== 0;
9950
+ if (isLastByteOdd !== isXOdd) {
9951
+ x = mod$1(-x);
9952
+ }
9953
+ return new Point(x, y);
9954
+ }
9955
+ static async fromPrivateKey(privateKey) {
9956
+ return (await getExtendedPublicKey(privateKey)).point;
9957
+ }
9958
+ toRawBytes() {
9959
+ const bytes = numberTo32BytesLE(this.y);
9960
+ bytes[31] |= this.x & _1n$1 ? 0x80 : 0;
9961
+ return bytes;
9962
+ }
9963
+ toHex() {
9964
+ return bytesToHex(this.toRawBytes());
9965
+ }
9966
+ toX25519() {
9967
+ const { y } = this;
9968
+ const u = mod$1((_1n$1 + y) * invert(_1n$1 - y));
9969
+ return numberTo32BytesLE(u);
9970
+ }
9971
+ isTorsionFree() {
9972
+ return ExtendedPoint.fromAffine(this).isTorsionFree();
9973
+ }
9974
+ equals(other) {
9975
+ return this.x === other.x && this.y === other.y;
9976
+ }
9977
+ negate() {
9978
+ return new Point(mod$1(-this.x), this.y);
9979
+ }
9980
+ add(other) {
9981
+ return ExtendedPoint.fromAffine(this).add(ExtendedPoint.fromAffine(other)).toAffine();
9982
+ }
9983
+ subtract(other) {
9984
+ return this.add(other.negate());
9985
+ }
9986
+ multiply(scalar) {
9987
+ return ExtendedPoint.fromAffine(this).multiply(scalar, this).toAffine();
9988
+ }
9989
+ }
9990
+ Point.BASE = new Point(CURVE.Gx, CURVE.Gy);
9991
+ Point.ZERO = new Point(_0n$1, _1n$1);
9992
+ let Signature$1 = class Signature {
9993
+ constructor(r, s) {
9994
+ this.r = r;
9995
+ this.s = s;
9996
+ this.assertValidity();
9997
+ }
9998
+ static fromHex(hex) {
9999
+ const bytes = ensureBytes(hex, 64);
10000
+ const r = Point.fromHex(bytes.slice(0, 32), false);
10001
+ const s = bytesToNumberLE(bytes.slice(32, 64));
10002
+ return new Signature(r, s);
10003
+ }
10004
+ assertValidity() {
10005
+ const { r, s } = this;
10006
+ if (!(r instanceof Point))
10007
+ throw new Error('Expected Point instance');
10008
+ normalizeScalar(s, CURVE.l, false);
10009
+ return this;
10010
+ }
10011
+ toRawBytes() {
10012
+ const u8 = new Uint8Array(64);
10013
+ u8.set(this.r.toRawBytes());
10014
+ u8.set(numberTo32BytesLE(this.s), 32);
10015
+ return u8;
10016
+ }
10017
+ toHex() {
10018
+ return bytesToHex(this.toRawBytes());
10019
+ }
10020
+ };
10021
+ function concatBytes(...arrays) {
10022
+ if (!arrays.every((a) => a instanceof Uint8Array))
10023
+ throw new Error('Expected Uint8Array list');
10024
+ if (arrays.length === 1)
10025
+ return arrays[0];
10026
+ const length = arrays.reduce((a, arr) => a + arr.length, 0);
10027
+ const result = new Uint8Array(length);
10028
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
10029
+ const arr = arrays[i];
10030
+ result.set(arr, pad);
10031
+ pad += arr.length;
10032
+ }
10033
+ return result;
10034
+ }
10035
+ const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
10036
+ function bytesToHex(uint8a) {
10037
+ if (!(uint8a instanceof Uint8Array))
10038
+ throw new Error('Uint8Array expected');
10039
+ let hex = '';
10040
+ for (let i = 0; i < uint8a.length; i++) {
10041
+ hex += hexes[uint8a[i]];
10042
+ }
10043
+ return hex;
10044
+ }
10045
+ function hexToBytes(hex) {
10046
+ if (typeof hex !== 'string') {
10047
+ throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
10048
+ }
10049
+ if (hex.length % 2)
10050
+ throw new Error('hexToBytes: received invalid unpadded hex');
10051
+ const array = new Uint8Array(hex.length / 2);
10052
+ for (let i = 0; i < array.length; i++) {
10053
+ const j = i * 2;
10054
+ const hexByte = hex.slice(j, j + 2);
10055
+ const byte = Number.parseInt(hexByte, 16);
10056
+ if (Number.isNaN(byte) || byte < 0)
10057
+ throw new Error('Invalid byte sequence');
10058
+ array[i] = byte;
10059
+ }
10060
+ return array;
10061
+ }
10062
+ function numberTo32BytesBE(num) {
10063
+ const length = 32;
10064
+ const hex = num.toString(16).padStart(length * 2, '0');
10065
+ return hexToBytes(hex);
10066
+ }
10067
+ function numberTo32BytesLE(num) {
10068
+ return numberTo32BytesBE(num).reverse();
10069
+ }
10070
+ function edIsNegative(num) {
10071
+ return (mod$1(num) & _1n$1) === _1n$1;
10072
+ }
10073
+ function bytesToNumberLE(uint8a) {
10074
+ if (!(uint8a instanceof Uint8Array))
10075
+ throw new Error('Expected Uint8Array');
10076
+ return BigInt('0x' + bytesToHex(Uint8Array.from(uint8a).reverse()));
10077
+ }
10078
+ const MAX_255B = BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
10079
+ function bytes255ToNumberLE(bytes) {
10080
+ return mod$1(bytesToNumberLE(bytes) & MAX_255B);
10081
+ }
10082
+ function mod$1(a, b = CURVE.P) {
10083
+ const res = a % b;
10084
+ return res >= _0n$1 ? res : b + res;
10085
+ }
10086
+ function invert(number, modulo = CURVE.P) {
10087
+ if (number === _0n$1 || modulo <= _0n$1) {
10088
+ throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
10089
+ }
10090
+ let a = mod$1(number, modulo);
10091
+ let b = modulo;
10092
+ let x = _0n$1, u = _1n$1;
10093
+ while (a !== _0n$1) {
10094
+ const q = b / a;
10095
+ const r = b % a;
10096
+ const m = x - u * q;
10097
+ b = a, a = r, x = u, u = m;
10098
+ }
10099
+ const gcd = b;
10100
+ if (gcd !== _1n$1)
10101
+ throw new Error('invert: does not exist');
10102
+ return mod$1(x, modulo);
10103
+ }
10104
+ function invertBatch(nums, p = CURVE.P) {
10105
+ const tmp = new Array(nums.length);
10106
+ const lastMultiplied = nums.reduce((acc, num, i) => {
10107
+ if (num === _0n$1)
10108
+ return acc;
10109
+ tmp[i] = acc;
10110
+ return mod$1(acc * num, p);
10111
+ }, _1n$1);
10112
+ const inverted = invert(lastMultiplied, p);
10113
+ nums.reduceRight((acc, num, i) => {
10114
+ if (num === _0n$1)
10115
+ return acc;
10116
+ tmp[i] = mod$1(acc * tmp[i], p);
10117
+ return mod$1(acc * num, p);
10118
+ }, inverted);
10119
+ return tmp;
10120
+ }
10121
+ function pow2(x, power) {
10122
+ const { P } = CURVE;
10123
+ let res = x;
10124
+ while (power-- > _0n$1) {
10125
+ res *= res;
10126
+ res %= P;
10127
+ }
10128
+ return res;
10129
+ }
10130
+ function pow_2_252_3(x) {
10131
+ const { P } = CURVE;
10132
+ const _5n = BigInt(5);
10133
+ const _10n = BigInt(10);
10134
+ const _20n = BigInt(20);
10135
+ const _40n = BigInt(40);
10136
+ const _80n = BigInt(80);
10137
+ const x2 = (x * x) % P;
10138
+ const b2 = (x2 * x) % P;
10139
+ const b4 = (pow2(b2, _2n) * b2) % P;
10140
+ const b5 = (pow2(b4, _1n$1) * x) % P;
10141
+ const b10 = (pow2(b5, _5n) * b5) % P;
10142
+ const b20 = (pow2(b10, _10n) * b10) % P;
10143
+ const b40 = (pow2(b20, _20n) * b20) % P;
10144
+ const b80 = (pow2(b40, _40n) * b40) % P;
10145
+ const b160 = (pow2(b80, _80n) * b80) % P;
10146
+ const b240 = (pow2(b160, _80n) * b80) % P;
10147
+ const b250 = (pow2(b240, _10n) * b10) % P;
10148
+ const pow_p_5_8 = (pow2(b250, _2n) * x) % P;
10149
+ return { pow_p_5_8, b2 };
10150
+ }
10151
+ function uvRatio(u, v) {
10152
+ const v3 = mod$1(v * v * v);
10153
+ const v7 = mod$1(v3 * v3 * v);
10154
+ const pow = pow_2_252_3(u * v7).pow_p_5_8;
10155
+ let x = mod$1(u * v3 * pow);
10156
+ const vx2 = mod$1(v * x * x);
10157
+ const root1 = x;
10158
+ const root2 = mod$1(x * SQRT_M1);
10159
+ const useRoot1 = vx2 === u;
10160
+ const useRoot2 = vx2 === mod$1(-u);
10161
+ const noRoot = vx2 === mod$1(-u * SQRT_M1);
10162
+ if (useRoot1)
10163
+ x = root1;
10164
+ if (useRoot2 || noRoot)
10165
+ x = root2;
10166
+ if (edIsNegative(x))
10167
+ x = mod$1(-x);
10168
+ return { isValid: useRoot1 || useRoot2, value: x };
10169
+ }
10170
+ function invertSqrt(number) {
10171
+ return uvRatio(_1n$1, number);
10172
+ }
10173
+ function modlLE(hash) {
10174
+ return mod$1(bytesToNumberLE(hash), CURVE.l);
10175
+ }
10176
+ function equalBytes(b1, b2) {
10177
+ if (b1.length !== b2.length) {
10178
+ return false;
10179
+ }
10180
+ for (let i = 0; i < b1.length; i++) {
10181
+ if (b1[i] !== b2[i]) {
10182
+ return false;
10183
+ }
10184
+ }
10185
+ return true;
10186
+ }
10187
+ function ensureBytes(hex, expectedLength) {
10188
+ const bytes = hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes(hex);
10189
+ if (typeof expectedLength === 'number' && bytes.length !== expectedLength)
10190
+ throw new Error(`Expected ${expectedLength} bytes`);
10191
+ return bytes;
10192
+ }
10193
+ function normalizeScalar(num, max, strict = true) {
10194
+ if (!max)
10195
+ throw new TypeError('Specify max value');
10196
+ if (typeof num === 'number' && Number.isSafeInteger(num))
10197
+ num = BigInt(num);
10198
+ if (typeof num === 'bigint' && num < max) {
10199
+ if (strict) {
10200
+ if (_0n$1 < num)
10201
+ return num;
10202
+ }
10203
+ else {
10204
+ if (_0n$1 <= num)
10205
+ return num;
10206
+ }
10207
+ }
10208
+ throw new TypeError('Expected valid scalar: 0 < scalar < max');
10209
+ }
10210
+ function adjustBytes25519(bytes) {
10211
+ bytes[0] &= 248;
10212
+ bytes[31] &= 127;
10213
+ bytes[31] |= 64;
10214
+ return bytes;
10215
+ }
10216
+ function checkPrivateKey(key) {
10217
+ key =
10218
+ typeof key === 'bigint' || typeof key === 'number'
10219
+ ? numberTo32BytesBE(normalizeScalar(key, POW_2_256))
10220
+ : ensureBytes(key);
10221
+ if (key.length !== 32)
10222
+ throw new Error(`Expected 32 bytes`);
10223
+ return key;
10224
+ }
10225
+ function getKeyFromHash(hashed) {
10226
+ const head = adjustBytes25519(hashed.slice(0, 32));
10227
+ const prefix = hashed.slice(32, 64);
10228
+ const scalar = modlLE(head);
10229
+ const point = Point.BASE.multiply(scalar);
10230
+ const pointBytes = point.toRawBytes();
10231
+ return { head, prefix, scalar, point, pointBytes };
10232
+ }
10233
+ let _sha512Sync;
10234
+ async function getExtendedPublicKey(key) {
10235
+ return getKeyFromHash(await utils.sha512(checkPrivateKey(key)));
10236
+ }
10237
+ function prepareVerification(sig, message, publicKey) {
10238
+ message = ensureBytes(message);
10239
+ if (!(publicKey instanceof Point))
10240
+ publicKey = Point.fromHex(publicKey, false);
10241
+ const { r, s } = sig instanceof Signature$1 ? sig.assertValidity() : Signature$1.fromHex(sig);
10242
+ const SB = ExtendedPoint.BASE.multiplyUnsafe(s);
10243
+ return { r, s, SB, pub: publicKey, msg: message };
10244
+ }
10245
+ function finishVerification(publicKey, r, SB, hashed) {
10246
+ const k = modlLE(hashed);
10247
+ const kA = ExtendedPoint.fromAffine(publicKey).multiplyUnsafe(k);
10248
+ const RkA = ExtendedPoint.fromAffine(r).add(kA);
10249
+ return RkA.subtract(SB).multiplyUnsafe(CURVE.h).equals(ExtendedPoint.ZERO);
10250
+ }
10251
+ async function verify$6(sig, message, publicKey) {
10252
+ const { r, SB, msg, pub } = prepareVerification(sig, message, publicKey);
10253
+ const hashed = await utils.sha512(r.toRawBytes(), pub.toRawBytes(), msg);
10254
+ return finishVerification(pub, r, SB, hashed);
10255
+ }
10256
+ Point.BASE._setWindowSize(8);
10257
+ const crypto$2 = {
10258
+ node: nodeCrypto$2,
10259
+ web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,
10260
+ };
10261
+ const utils = {
10262
+ bytesToHex,
10263
+ hexToBytes,
10264
+ concatBytes,
10265
+ getExtendedPublicKey,
10266
+ mod: mod$1,
10267
+ invert,
10268
+ TORSION_SUBGROUP: [
10269
+ '0100000000000000000000000000000000000000000000000000000000000000',
10270
+ 'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
10271
+ '0000000000000000000000000000000000000000000000000000000000000080',
10272
+ '26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05',
10273
+ 'ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f',
10274
+ '26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85',
10275
+ '0000000000000000000000000000000000000000000000000000000000000000',
10276
+ 'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
10277
+ ],
10278
+ hashToPrivateScalar: (hash) => {
10279
+ hash = ensureBytes(hash);
10280
+ if (hash.length < 40 || hash.length > 1024)
10281
+ throw new Error('Expected 40-1024 bytes of private key as per FIPS 186');
10282
+ return mod$1(bytesToNumberLE(hash), CURVE.l - _1n$1) + _1n$1;
10283
+ },
10284
+ randomBytes: (bytesLength = 32) => {
10285
+ if (crypto$2.web) {
10286
+ return crypto$2.web.getRandomValues(new Uint8Array(bytesLength));
10287
+ }
10288
+ else {
10289
+ throw new Error("The environment doesn't have randomBytes function");
10290
+ }
10291
+ },
10292
+ randomPrivateKey: () => {
10293
+ return utils.randomBytes(32);
10294
+ },
10295
+ sha512: async (...messages) => {
10296
+ const message = concatBytes(...messages);
10297
+ if (crypto$2.web) {
10298
+ const buffer = await crypto$2.web.subtle.digest('SHA-512', message.buffer);
10299
+ return new Uint8Array(buffer);
10300
+ }
10301
+ else {
10302
+ throw new Error("The environment doesn't have sha512 function");
10303
+ }
10304
+ },
10305
+ precompute(windowSize = 8, point = Point.BASE) {
10306
+ const cached = point.equals(Point.BASE) ? point : new Point(point.x, point.y);
10307
+ cached._setWindowSize(windowSize);
10308
+ cached.multiply(_2n);
10309
+ return cached;
10310
+ },
10311
+ sha512Sync: undefined,
10312
+ };
10313
+ Object.defineProperties(utils, {
10314
+ sha512Sync: {
10315
+ configurable: false,
10316
+ get() {
10317
+ return _sha512Sync;
10318
+ },
10319
+ set(val) {
10320
+ if (!_sha512Sync)
10321
+ _sha512Sync = val;
10322
+ },
10323
+ },
9401
10324
  });
9402
10325
 
9403
10326
  // OpenPGP.js - An OpenPGP implementation in javascript
@@ -9433,6 +10356,8 @@ var ecdsa = /*#__PURE__*/Object.freeze({
9433
10356
  * @async
9434
10357
  */
9435
10358
  async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
10359
+ const curve = new CurveWithOID(oid);
10360
+ checkPublicPointEnconding(curve, publicKey);
9436
10361
  if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
9437
10362
  // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
9438
10363
  throw new Error('Hash algorithm too weak for EdDSA.');
@@ -9459,11 +10384,13 @@ async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9459
10384
  * @async
9460
10385
  */
9461
10386
  async function verify$5(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
10387
+ const curve = new CurveWithOID(oid);
10388
+ checkPublicPointEnconding(curve, publicKey);
9462
10389
  if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
9463
10390
  throw new Error('Hash algorithm too weak for EdDSA.');
9464
10391
  }
9465
10392
  const signature = util.concatUint8Array([r, s]);
9466
- return nacl.sign.detached.verify(hashed, signature, publicKey.subarray(1));
10393
+ return verify$6(signature, hashed, publicKey.subarray(1));
9467
10394
  }
9468
10395
  /**
9469
10396
  * Validate legacy EdDSA parameters
@@ -9589,7 +10516,7 @@ async function verify$4(algo, hashAlgo, { RS }, m, publicKey, hashed) {
9589
10516
  }
9590
10517
  switch (algo) {
9591
10518
  case enums.publicKey.ed25519:
9592
- return nacl.sign.detached.verify(hashed, RS, publicKey);
10519
+ return verify$6(RS, hashed, publicKey);
9593
10520
  case enums.publicKey.ed448: {
9594
10521
  const ed448 = await util.getNobleCurve(enums.publicKey.ed448);
9595
10522
  return ed448.verify(RS, hashed, publicKey);
@@ -9953,7 +10880,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) {
9953
10880
  new Uint8Array([public_algo]),
9954
10881
  kdfParams.write(true),
9955
10882
  util.stringToUint8Array('Anonymous Sender '),
9956
- kdfParams.replacementFingerprint || fingerprint.subarray(0, 20)
10883
+ kdfParams.replacementFingerprint || fingerprint
9957
10884
  ]);
9958
10885
  }
9959
10886
 
@@ -9995,7 +10922,7 @@ async function genPublicEphemeralKey(curve, Q) {
9995
10922
  const d = getRandomBytes(32);
9996
10923
  const { secretKey, sharedKey } = await genPrivateEphemeralKey(curve, Q, null, d);
9997
10924
  let { publicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
9998
- publicKey = util.concatUint8Array([new Uint8Array([0x40]), publicKey]);
10925
+ publicKey = util.concatUint8Array([new Uint8Array([curve.wireFormatLeadingByte]), publicKey]);
9999
10926
  return { publicKey, sharedKey }; // Note: sharedKey is little-endian here, unlike below
10000
10927
  }
10001
10928
  case 'web':
@@ -10023,7 +10950,7 @@ async function genPublicEphemeralKey(curve, Q) {
10023
10950
  * @param {module:type/kdf_params} kdfParams - KDF params including cipher and algorithm to use
10024
10951
  * @param {Uint8Array} data - Unpadded session key data
10025
10952
  * @param {Uint8Array} Q - Recipient public key
10026
- * @param {Uint8Array} fingerprint - Recipient fingerprint
10953
+ * @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
10027
10954
  * @returns {Promise<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}
10028
10955
  * @async
10029
10956
  */
@@ -10031,6 +10958,7 @@ async function encrypt$2(oid, kdfParams, data, Q, fingerprint) {
10031
10958
  const m = encode(data);
10032
10959
 
10033
10960
  const curve = new CurveWithOID(oid);
10961
+ checkPublicPointEnconding(curve, Q);
10034
10962
  const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
10035
10963
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
10036
10964
  const { keySize } = getCipherParams(kdfParams.cipher);
@@ -10087,12 +11015,14 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
10087
11015
  * @param {Uint8Array} C - Encrypted and wrapped value derived from session key
10088
11016
  * @param {Uint8Array} Q - Recipient public key
10089
11017
  * @param {Uint8Array} d - Recipient private key
10090
- * @param {Uint8Array} fingerprint - Recipient fingerprint
11018
+ * @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
10091
11019
  * @returns {Promise<Uint8Array>} Value derived from session key.
10092
11020
  * @async
10093
11021
  */
10094
11022
  async function decrypt$2(oid, kdfParams, V, C, Q, d, fingerprint) {
10095
11023
  const curve = new CurveWithOID(oid);
11024
+ checkPublicPointEnconding(curve, Q);
11025
+ checkPublicPointEnconding(curve, V);
10096
11026
  const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
10097
11027
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
10098
11028
  const { keySize } = getCipherParams(kdfParams.cipher);
@@ -10224,7 +11154,7 @@ async function webPublicEphemeralKey(curve, Q) {
10224
11154
  );
10225
11155
  [s, p] = await Promise.all([s, p]);
10226
11156
  const sharedKey = new Uint8Array(s);
10227
- const publicKey = new Uint8Array(jwkToRawPublic(p));
11157
+ const publicKey = new Uint8Array(jwkToRawPublic(p, curve.wireFormatLeadingByte));
10228
11158
  return { publicKey, sharedKey };
10229
11159
  }
10230
11160
 
@@ -10522,6 +11452,9 @@ var elliptic = /*#__PURE__*/Object.freeze({
10522
11452
  https://tools.ietf.org/html/rfc4880#section-14
10523
11453
  */
10524
11454
 
11455
+ const _0n = BigInt(0);
11456
+ const _1n = BigInt(1);
11457
+
10525
11458
  /**
10526
11459
  * DSA Sign function
10527
11460
  * @param {Integer} hashAlgo
@@ -10534,26 +11467,24 @@ var elliptic = /*#__PURE__*/Object.freeze({
10534
11467
  * @async
10535
11468
  */
10536
11469
  async function sign$3(hashAlgo, hashed, g, p, q, x) {
10537
- const BigInteger = await util.getBigInteger();
10538
-
10539
- const one = new BigInteger(1);
10540
- p = new BigInteger(p);
10541
- q = new BigInteger(q);
10542
- g = new BigInteger(g);
10543
- x = new BigInteger(x);
11470
+ const _0n = BigInt(0);
11471
+ p = uint8ArrayToBigInt(p);
11472
+ q = uint8ArrayToBigInt(q);
11473
+ g = uint8ArrayToBigInt(g);
11474
+ x = uint8ArrayToBigInt(x);
10544
11475
 
10545
11476
  let k;
10546
11477
  let r;
10547
11478
  let s;
10548
11479
  let t;
10549
- g = g.mod(p);
10550
- x = x.mod(q);
11480
+ g = mod$2(g, p);
11481
+ x = mod$2(x, q);
10551
11482
  // If the output size of the chosen hash is larger than the number of
10552
11483
  // bits of q, the hash result is truncated to fit by taking the number
10553
11484
  // of leftmost bits equal to the number of bits of q. This (possibly
10554
11485
  // truncated) hash function result is treated as a number and used
10555
11486
  // directly in the DSA signature algorithm.
10556
- const h = new BigInteger(hashed.subarray(0, q.byteLength())).mod(q);
11487
+ const h = mod$2(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
10557
11488
  // FIPS-186-4, section 4.6:
10558
11489
  // The values of r and s shall be checked to determine if r = 0 or s = 0.
10559
11490
  // If either r = 0 or s = 0, a new value of k shall be generated, and the
@@ -10561,22 +11492,22 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10561
11492
  // or s = 0 if signatures are generated properly.
10562
11493
  while (true) {
10563
11494
  // See Appendix B here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
10564
- k = await getRandomBigInteger(one, q); // returns in [1, q-1]
10565
- r = g.modExp(k, p).imod(q); // (g**k mod p) mod q
10566
- if (r.isZero()) {
11495
+ k = getRandomBigInteger(_1n, q); // returns in [1, q-1]
11496
+ r = mod$2(modExp(g, k, p), q); // (g**k mod p) mod q
11497
+ if (r === _0n) {
10567
11498
  continue;
10568
11499
  }
10569
- const xr = x.mul(r).imod(q);
10570
- t = h.add(xr).imod(q); // H(m) + x*r mod q
10571
- s = k.modInv(q).imul(t).imod(q); // k**-1 * (H(m) + x*r) mod q
10572
- if (s.isZero()) {
11500
+ const xr = mod$2(x * r, q);
11501
+ t = mod$2(h + xr, q); // H(m) + x*r mod q
11502
+ s = mod$2(modInv(k, q) * t, q); // k**-1 * (H(m) + x*r) mod q
11503
+ if (s === _0n) {
10573
11504
  continue;
10574
11505
  }
10575
11506
  break;
10576
11507
  }
10577
11508
  return {
10578
- r: r.toUint8Array('be', q.byteLength()),
10579
- s: s.toUint8Array('be', q.byteLength())
11509
+ r: bigIntToUint8Array(r, 'be', byteLength(p)),
11510
+ s: bigIntToUint8Array(s, 'be', byteLength(p))
10580
11511
  };
10581
11512
  }
10582
11513
 
@@ -10594,37 +11525,34 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10594
11525
  * @async
10595
11526
  */
10596
11527
  async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
10597
- const BigInteger = await util.getBigInteger();
11528
+ r = uint8ArrayToBigInt(r);
11529
+ s = uint8ArrayToBigInt(s);
10598
11530
 
10599
- const zero = new BigInteger(0);
10600
- r = new BigInteger(r);
10601
- s = new BigInteger(s);
11531
+ p = uint8ArrayToBigInt(p);
11532
+ q = uint8ArrayToBigInt(q);
11533
+ g = uint8ArrayToBigInt(g);
11534
+ y = uint8ArrayToBigInt(y);
10602
11535
 
10603
- p = new BigInteger(p);
10604
- q = new BigInteger(q);
10605
- g = new BigInteger(g);
10606
- y = new BigInteger(y);
10607
-
10608
- if (r.lte(zero) || r.gte(q) ||
10609
- s.lte(zero) || s.gte(q)) {
11536
+ if (r <= _0n || r >= q ||
11537
+ s <= _0n || s >= q) {
10610
11538
  util.printDebug('invalid DSA Signature');
10611
11539
  return false;
10612
11540
  }
10613
- const h = new BigInteger(hashed.subarray(0, q.byteLength())).imod(q);
10614
- const w = s.modInv(q); // s**-1 mod q
10615
- if (w.isZero()) {
11541
+ const h = mod$2(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
11542
+ const w = modInv(s, q); // s**-1 mod q
11543
+ if (w === _0n) {
10616
11544
  util.printDebug('invalid DSA Signature');
10617
11545
  return false;
10618
11546
  }
10619
11547
 
10620
- g = g.mod(p);
10621
- y = y.mod(p);
10622
- const u1 = h.mul(w).imod(q); // H(m) * w mod q
10623
- const u2 = r.mul(w).imod(q); // r * w mod q
10624
- const t1 = g.modExp(u1, p); // g**u1 mod p
10625
- const t2 = y.modExp(u2, p); // y**u2 mod p
10626
- const v = t1.mul(t2).imod(p).imod(q); // (g**u1 * y**u2 mod p) mod q
10627
- return v.equal(r);
11548
+ g = mod$2(g, p);
11549
+ y = mod$2(y, p);
11550
+ const u1 = mod$2(h * w, q); // H(m) * w mod q
11551
+ const u2 = mod$2(r * w, q); // r * w mod q
11552
+ const t1 = modExp(g, u1, p); // g**u1 mod p
11553
+ const t2 = modExp(y, u2, p); // y**u2 mod p
11554
+ const v = mod$2(mod$2(t1 * t2, p), q); // (g**u1 * y**u2 mod p) mod q
11555
+ return v === r;
10628
11556
  }
10629
11557
 
10630
11558
  /**
@@ -10638,22 +11566,19 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
10638
11566
  * @async
10639
11567
  */
10640
11568
  async function validateParams$1(p, q, g, y, x) {
10641
- const BigInteger = await util.getBigInteger();
10642
-
10643
- p = new BigInteger(p);
10644
- q = new BigInteger(q);
10645
- g = new BigInteger(g);
10646
- y = new BigInteger(y);
10647
- const one = new BigInteger(1);
11569
+ p = uint8ArrayToBigInt(p);
11570
+ q = uint8ArrayToBigInt(q);
11571
+ g = uint8ArrayToBigInt(g);
11572
+ y = uint8ArrayToBigInt(y);
10648
11573
  // Check that 1 < g < p
10649
- if (g.lte(one) || g.gte(p)) {
11574
+ if (g <= _1n || g >= p) {
10650
11575
  return false;
10651
11576
  }
10652
11577
 
10653
11578
  /**
10654
11579
  * Check that subgroup order q divides p-1
10655
11580
  */
10656
- if (!p.dec().mod(q).isZero()) {
11581
+ if (mod$2(p - _1n, q) !== _0n) {
10657
11582
  return false;
10658
11583
  }
10659
11584
 
@@ -10661,16 +11586,16 @@ async function validateParams$1(p, q, g, y, x) {
10661
11586
  * g has order q
10662
11587
  * Check that g ** q = 1 mod p
10663
11588
  */
10664
- if (!g.modExp(q, p).isOne()) {
11589
+ if (modExp(g, q, p) !== _1n) {
10665
11590
  return false;
10666
11591
  }
10667
11592
 
10668
11593
  /**
10669
11594
  * Check q is large and probably prime (we mainly want to avoid small factors)
10670
11595
  */
10671
- const qSize = new BigInteger(q.bitLength());
10672
- const n150 = new BigInteger(150);
10673
- if (qSize.lt(n150) || !(await isProbablePrime(q, null, 32))) {
11596
+ const qSize = BigInt(bitLength(q));
11597
+ const _150n = BigInt(150);
11598
+ if (qSize < _150n || !isProbablePrime(q, null, 32)) {
10674
11599
  return false;
10675
11600
  }
10676
11601
 
@@ -10680,11 +11605,11 @@ async function validateParams$1(p, q, g, y, x) {
10680
11605
  *
10681
11606
  * Blinded exponentiation computes g**{rq + x} to compare to y
10682
11607
  */
10683
- x = new BigInteger(x);
10684
- const two = new BigInteger(2);
10685
- const r = await getRandomBigInteger(two.leftShift(qSize.dec()), two.leftShift(qSize)); // draw r of same size as q
10686
- const rqx = q.mul(r).add(x);
10687
- if (!y.equal(g.modExp(rqx, p))) {
11608
+ x = uint8ArrayToBigInt(x);
11609
+ const _2n = BigInt(2);
11610
+ const r = getRandomBigInteger(_2n << (qSize - _1n), _2n << qSize); // draw r of same size as q
11611
+ const rqx = q * r + x;
11612
+ if (y !== modExp(g, rqx, p)) {
10688
11613
  return false;
10689
11614
  }
10690
11615
 
@@ -11450,6 +12375,9 @@ function parsePublicKeyParams(algo, bytes) {
11450
12375
  case enums.publicKey.eddsaLegacy: {
11451
12376
  const oid = new OID(); read += oid.read(bytes);
11452
12377
  checkSupportedCurve(oid);
12378
+ if (oid.getName() !== enums.curve.ed25519Legacy) {
12379
+ throw new Error('Unexpected OID for eddsaLegacy');
12380
+ }
11453
12381
  let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
11454
12382
  Q = util.leftPad(Q, 33);
11455
12383
  return { read: read, publicParams: { oid, Q } };
@@ -11513,6 +12441,9 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
11513
12441
  }
11514
12442
  case enums.publicKey.eddsaLegacy: {
11515
12443
  const payloadSize = getCurvePayloadSize(algo, publicParams.oid);
12444
+ if (publicParams.oid.getName() !== enums.curve.ed25519Legacy) {
12445
+ throw new Error('Unexpected OID for eddsaLegacy');
12446
+ }
11516
12447
  let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
11517
12448
  seed = util.leftPad(seed, payloadSize);
11518
12449
  return { read, privateParams: { seed } };
@@ -14343,6 +15274,7 @@ class SignaturePacket {
14343
15274
 
14344
15275
  this.signatureData = null;
14345
15276
  this.unhashedSubpackets = [];
15277
+ this.unknownSubpackets = [];
14346
15278
  this.signedHashValue = null;
14347
15279
  this.salt = null;
14348
15280
 
@@ -14392,9 +15324,12 @@ class SignaturePacket {
14392
15324
  * @param {String} bytes - Payload of a tag 2 packet
14393
15325
  * @returns {SignaturePacket} Object representation.
14394
15326
  */
14395
- read(bytes) {
15327
+ read(bytes, config$1 = config) {
14396
15328
  let i = 0;
14397
15329
  this.version = bytes[i++];
15330
+ if (this.version === 5 && !config$1.enableParsingV5Entities) {
15331
+ throw new UnsupportedError('Support for v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
15332
+ }
14398
15333
 
14399
15334
  if (this.version !== 4 && this.version !== 5 && this.version !== 6) {
14400
15335
  throw new UnsupportedError(`Version ${this.version} of the signature packet is unsupported.`);
@@ -14671,10 +15606,8 @@ class SignaturePacket {
14671
15606
  * @returns {Uint8Array} Subpacket data.
14672
15607
  */
14673
15608
  writeUnhashedSubPackets() {
14674
- const arr = [];
14675
- this.unhashedSubpackets.forEach(data => {
14676
- arr.push(writeSimpleLength(data.length));
14677
- arr.push(data);
15609
+ const arr = this.unhashedSubpackets.map(({ type, critical, body }) => {
15610
+ return writeSubPacket(type, critical, body);
14678
15611
  });
14679
15612
 
14680
15613
  const result = util.concat(arr);
@@ -14683,7 +15616,7 @@ class SignaturePacket {
14683
15616
  return util.concat([length, result]);
14684
15617
  }
14685
15618
 
14686
- // V4 signature sub packets
15619
+ // Signature subpackets
14687
15620
  readSubPacket(bytes, hashed = true) {
14688
15621
  let mypos = 0;
14689
15622
 
@@ -14691,15 +15624,19 @@ class SignaturePacket {
14691
15624
  const critical = !!(bytes[mypos] & 0x80);
14692
15625
  const type = bytes[mypos] & 0x7F;
14693
15626
 
15627
+ mypos++;
15628
+
14694
15629
  if (!hashed) {
14695
- this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
15630
+ this.unhashedSubpackets.push({
15631
+ type,
15632
+ critical,
15633
+ body: bytes.subarray(mypos, bytes.length)
15634
+ });
14696
15635
  if (!allowedUnhashedSubpackets.has(type)) {
14697
15636
  return;
14698
15637
  }
14699
15638
  }
14700
15639
 
14701
- mypos++;
14702
-
14703
15640
  // subpacket type
14704
15641
  switch (type) {
14705
15642
  case enums.signatureSubpacket.signatureCreationTime:
@@ -14871,14 +15808,13 @@ class SignaturePacket {
14871
15808
  this.preferredCipherSuites.push([bytes[i], bytes[i + 1]]);
14872
15809
  }
14873
15810
  break;
14874
- default: {
14875
- const err = new Error(`Unknown signature subpacket type ${type}`);
14876
- if (critical) {
14877
- throw err;
14878
- } else {
14879
- util.printDebug(err);
14880
- }
14881
- }
15811
+ default:
15812
+ this.unknownSubpackets.push({
15813
+ type,
15814
+ critical,
15815
+ body: bytes.subarray(mypos, bytes.length)
15816
+ });
15817
+ break;
14882
15818
  }
14883
15819
  }
14884
15820
 
@@ -15078,6 +16014,11 @@ class SignaturePacket {
15078
16014
  [enums.signature.binary, enums.signature.text].includes(this.signatureType)) {
15079
16015
  throw new Error('Insecure message hash algorithm: ' + enums.read(enums.hash, this.hashAlgorithm).toUpperCase());
15080
16016
  }
16017
+ this.unknownSubpackets.forEach(({ type, critical }) => {
16018
+ if (critical) {
16019
+ throw new Error(`Unknown critical signature subpacket type ${type}`);
16020
+ }
16021
+ });
15081
16022
  this.rawNotations.forEach(({ name, critical }) => {
15082
16023
  if (critical && (config$1.knownNotations.indexOf(name) < 0)) {
15083
16024
  throw new Error(`Unknown critical notation: ${name}`);
@@ -16057,7 +16998,7 @@ async function runAEAD(packet, fn, key, data) {
16057
16998
  done = true;
16058
16999
  }
16059
17000
  cryptedBytes += chunk.length - tagLengthIfDecrypting;
16060
- // eslint-disable-next-line no-loop-func
17001
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
16061
17002
  latestPromise = latestPromise.then(() => cryptedPromise).then(async crypted => {
16062
17003
  await writer.ready;
16063
17004
  await writer.write(crypted);
@@ -16377,10 +17318,11 @@ class PublicKeyEncryptedSessionKeyPacket {
16377
17318
  // No symmetric encryption algorithm identifier is passed to the public-key algorithm for a
16378
17319
  // v6 PKESK packet, as it is included in the v2 SEIPD packet.
16379
17320
  const sessionKeyAlgorithm = this.version === 3 ? this.sessionKeyAlgorithm : null;
17321
+ const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
16380
17322
  const encoded = encodeSessionKey(this.version, algo, sessionKeyAlgorithm, this.sessionKey);
16381
17323
  const privateParams = algo === enums.publicKey.aead ? key.privateParams : null;
16382
17324
  this.encrypted = await mod.publicKeyEncrypt(
16383
- algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded, key.getFingerprintBytes());
17325
+ algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded, fingerprint);
16384
17326
  }
16385
17327
 
16386
17328
  /**
@@ -16400,7 +17342,8 @@ class PublicKeyEncryptedSessionKeyPacket {
16400
17342
  const randomPayload = randomSessionKey ?
16401
17343
  encodeSessionKey(this.version, this.publicKeyAlgorithm, randomSessionKey.sessionKeyAlgorithm, randomSessionKey.sessionKey) :
16402
17344
  null;
16403
- const decryptedData = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
17345
+ const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
17346
+ const decryptedData = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, fingerprint, randomPayload);
16404
17347
 
16405
17348
  const { sessionKey, sessionKeyAlgorithm } = decodeSessionKey(this.version, this.publicKeyAlgorithm, decryptedData, randomSessionKey);
16406
17349
 
@@ -16805,10 +17748,13 @@ class PublicKeyPacket {
16805
17748
  * @returns {Object} This object with attributes set by the parser
16806
17749
  * @async
16807
17750
  */
16808
- async read(bytes) {
17751
+ async read(bytes, config$1 = config) {
16809
17752
  let pos = 0;
16810
17753
  // A one-octet version number (4, 5 or 6).
16811
17754
  this.version = bytes[pos++];
17755
+ if (this.version === 5 && !config$1.enableParsingV5Entities) {
17756
+ throw new UnsupportedError('Support for parsing v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
17757
+ }
16812
17758
 
16813
17759
  if (this.version === 4 || this.version === 5 || this.version === 6) {
16814
17760
  // - A four-octet number denoting the time that the key was created.
@@ -17193,7 +18139,7 @@ class PublicSubkeyPacket extends PublicKeyPacket {
17193
18139
  * @param {Date} [date] - Creation date
17194
18140
  * @param {Object} [config] - Full configuration, defaults to openpgp.config
17195
18141
  */
17196
- // eslint-disable-next-line no-useless-constructor
18142
+ // eslint-disable-next-line @typescript-eslint/no-useless-constructor
17197
18143
  constructor(date, config) {
17198
18144
  super(date, config);
17199
18145
  }
@@ -17400,7 +18346,7 @@ class SecretKeyPacket extends PublicKeyPacket {
17400
18346
  */
17401
18347
  async read(bytes, config$1 = config) {
17402
18348
  // - A Public-Key or Public-Subkey packet, as described above.
17403
- let i = await this.readPublicKey(bytes);
18349
+ let i = await this.readPublicKey(bytes, config$1);
17404
18350
  const startOfSecretKeyData = i;
17405
18351
 
17406
18352
  // - One octet indicating string-to-key usage conventions. Zero
@@ -17690,13 +18636,13 @@ class SecretKeyPacket extends PublicKeyPacket {
17690
18636
 
17691
18637
  if (config$1.aeadProtect) {
17692
18638
  this.s2kUsage = 253;
17693
- this.aead = enums.aead.eax;
18639
+ this.aead = config$1.preferredAEADAlgorithm;
17694
18640
  const mode = mod.getAEADMode(this.aead);
17695
18641
  this.isLegacyAEAD = this.version === 5; // v4 is always re-encrypted with standard format instead.
17696
18642
  this.usedModernAEAD = !this.isLegacyAEAD; // legacy AEAD does not guarantee integrity of public key material
17697
18643
 
17698
18644
  const serializedPacketTag = writeTag(this.constructor.tag);
17699
- const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag);
18645
+ const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag, this.isLegacyAEAD);
17700
18646
 
17701
18647
  const modeInstance = await mode(this.symmetric, key);
17702
18648
  this.iv = this.isLegacyAEAD ? mod.random.getRandomBytes(blockSize) : mod.random.getRandomBytes(mode.ivLength);
@@ -17866,6 +18812,12 @@ class SecretKeyPacket extends PublicKeyPacket {
17866
18812
  * @returns encryption key
17867
18813
  */
17868
18814
  async function produceEncryptionKey(keyVersion, s2k, passphrase, cipherAlgo, aeadMode, serializedPacketTag, isLegacyAEAD) {
18815
+ if (s2k.type === 'argon2' && !aeadMode) {
18816
+ throw new Error('Using Argon2 S2K without AEAD is not allowed');
18817
+ }
18818
+ if (s2k.type === 'simple' && keyVersion === 6) {
18819
+ throw new Error('Using Simple S2K with version 6 keys is not allowed');
18820
+ }
17869
18821
  const { keySize } = mod.getCipherParams(cipherAlgo);
17870
18822
  const derivedKey = await s2k.produceKey(passphrase, keySize);
17871
18823
  if (!aeadMode || keyVersion === 5 || isLegacyAEAD) {
@@ -18098,7 +19050,7 @@ class PaddingPacket {
18098
19050
  * Read a padding packet
18099
19051
  * @param {Uint8Array | ReadableStream<Uint8Array>} bytes
18100
19052
  */
18101
- read(bytes) { // eslint-disable-line no-unused-vars
19053
+ read(bytes) { // eslint-disable-line @typescript-eslint/no-unused-vars
18102
19054
  // Padding packets are ignored, so this function is never called.
18103
19055
  }
18104
19056
 
@@ -18244,6 +19196,8 @@ async function generateSecretKey(options, config) {
18244
19196
  * Returns the valid and non-expired signature that has the latest creation date, while ignoring signatures created in the future.
18245
19197
  * @param {Array<SignaturePacket>} signatures - List of signatures
18246
19198
  * @param {PublicKeyPacket|PublicSubkeyPacket} publicKey - Public key packet to verify the signature
19199
+ * @param {module:enums.signature} signatureType - Signature type to determine how to hash the data (NB: for userID signatures,
19200
+ * `enums.signatures.certGeneric` should be given regardless of the actual trust level)
18247
19201
  * @param {Date} date - Use the given date instead of the current time
18248
19202
  * @param {Object} config - full configuration
18249
19203
  * @returns {Promise<SignaturePacket>} The latest valid signature.
@@ -18492,8 +19446,14 @@ async function isDataRevoked(primaryKey, signatureType, dataToVerify, revocation
18492
19446
  // `verifyAllCertifications`.)
18493
19447
  !signature || revocationSignature.issuerKeyID.equals(signature.issuerKeyID)
18494
19448
  ) {
19449
+ const isHardRevocation = ![
19450
+ enums.reasonForRevocation.keyRetired,
19451
+ enums.reasonForRevocation.keySuperseded,
19452
+ enums.reasonForRevocation.userIDInvalid
19453
+ ].includes(revocationSignature.reasonForRevocationFlag);
19454
+
18495
19455
  await revocationSignature.verify(
18496
- key, signatureType, dataToVerify, date, false, config
19456
+ key, signatureType, dataToVerify, isHardRevocation ? null : date, false, config
18497
19457
  );
18498
19458
 
18499
19459
  // TODO get an identifier of the revoked object instead
@@ -19652,6 +20612,7 @@ class Key {
19652
20612
  }
19653
20613
  }
19654
20614
  if (!users.length) {
20615
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
19655
20616
  throw exception || new Error('Could not find primary user');
19656
20617
  }
19657
20618
  await Promise.all(users.map(async function (a) {
@@ -20479,7 +21440,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
20479
21440
  key: secretKeyPacket
20480
21441
  };
20481
21442
  const signatureProperties = secretKeyPacket.version !== 6 ? getKeySignatureProperties() : {};
20482
- signatureProperties.signatureType = enums.signature.certGeneric;
21443
+ signatureProperties.signatureType = enums.signature.certPositive;
20483
21444
  if (index === 0) {
20484
21445
  signatureProperties.isPrimaryUserID = true;
20485
21446
  }
@@ -20562,7 +21523,12 @@ async function readKey({ armoredKey, binaryKey, config: config$1, ...rest }) {
20562
21523
  input = binaryKey;
20563
21524
  }
20564
21525
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20565
- return createKey(packetlist);
21526
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
21527
+ if (keyIndex.length === 0) {
21528
+ throw new Error('No key packet found');
21529
+ }
21530
+ const firstKeyPacketList = packetlist.slice(keyIndex[0], keyIndex[1]);
21531
+ return createKey(firstKeyPacketList);
20566
21532
  }
20567
21533
 
20568
21534
  /**
@@ -20599,7 +21565,15 @@ async function readPrivateKey({ armoredKey, binaryKey, config: config$1, ...rest
20599
21565
  input = binaryKey;
20600
21566
  }
20601
21567
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20602
- return new PrivateKey(packetlist);
21568
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
21569
+ for (let i = 0; i < keyIndex.length; i++) {
21570
+ if (packetlist[keyIndex[i]].constructor.tag === enums.packet.publicKey) {
21571
+ continue;
21572
+ }
21573
+ const firstPrivateKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
21574
+ return new PrivateKey(firstPrivateKeyList);
21575
+ }
21576
+ throw new Error('No secret key packet found');
20603
21577
  }
20604
21578
 
20605
21579
  /**
@@ -20678,15 +21652,18 @@ async function readPrivateKeys({ armoredKeys, binaryKeys, config: config$1 }) {
20678
21652
  }
20679
21653
  const keys = [];
20680
21654
  const packetlist = await PacketList.fromBinary(input, allowedKeyPackets, config$1);
20681
- const keyIndex = packetlist.indexOfTag(enums.packet.secretKey);
20682
- if (keyIndex.length === 0) {
20683
- throw new Error('No secret key packet found');
20684
- }
21655
+ const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
20685
21656
  for (let i = 0; i < keyIndex.length; i++) {
21657
+ if (packetlist[keyIndex[i]].constructor.tag === enums.packet.publicKey) {
21658
+ continue;
21659
+ }
20686
21660
  const oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
20687
21661
  const newKey = new PrivateKey(oneKeyList);
20688
21662
  keys.push(newKey);
20689
21663
  }
21664
+ if (keys.length === 0) {
21665
+ throw new Error('No secret key packet found');
21666
+ }
20690
21667
  return keys;
20691
21668
  }
20692
21669
 
@@ -22100,7 +23077,7 @@ async function encrypt({ message, encryptionKeys, signingKeys, passwords, sessio
22100
23077
  // serialize data
22101
23078
  const armor = format === 'armored';
22102
23079
  const data = armor ? message.armor(config$1) : message.write();
22103
- return convertStream(data);
23080
+ return await convertStream(data);
22104
23081
  } catch (err) {
22105
23082
  throw util.wrapError('Error encrypting message', err);
22106
23083
  }
@@ -22237,7 +23214,7 @@ async function sign({ message, signingKeys, format = 'armored', detached = false
22237
23214
  ]);
22238
23215
  });
22239
23216
  }
22240
- return convertStream(signature);
23217
+ return await convertStream(signature);
22241
23218
  } catch (err) {
22242
23219
  throw util.wrapError('Error signing message', err);
22243
23220
  }
@@ -22288,7 +23265,7 @@ async function verify({ message, verificationKeys, expectSigned = false, format
22288
23265
  result.signatures = await message.verify(verificationKeys, date, config$1);
22289
23266
  }
22290
23267
  result.data = format === 'binary' ? message.getLiteralData() : message.getText();
22291
- if (message.fromStream) linkStreams(result, message);
23268
+ if (message.fromStream && !signature) linkStreams(result, message);
22292
23269
  if (expectSigned) {
22293
23270
  if (result.signatures.length === 0) {
22294
23271
  throw new Error('Message is not signed');
@@ -22420,12 +23397,12 @@ async function decryptSessionKeys({ message, decryptionKeys, passwords, date = n
22420
23397
  */
22421
23398
  function checkString(data, name) {
22422
23399
  if (!util.isString(data)) {
22423
- throw new Error('Parameter [' + (name || 'data') + '] must be of type String');
23400
+ throw new Error('Parameter [' + (name ) + '] must be of type String');
22424
23401
  }
22425
23402
  }
22426
23403
  function checkBinary(data, name) {
22427
23404
  if (!util.isUint8Array(data)) {
22428
- throw new Error('Parameter [' + (name || 'data') + '] must be of type Uint8Array');
23405
+ throw new Error('Parameter [' + ('data') + '] must be of type Uint8Array');
22429
23406
  }
22430
23407
  }
22431
23408
  function checkMessage(message) {