@protontech/openpgp 6.0.0-beta.1 → 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.
@@ -1,8 +1,9 @@
1
- /*! OpenPGP.js v6.0.0-beta.1 - 2024-05-17 - 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
  import { createRequire } from 'module';
5
5
  import * as nc from 'node:crypto';
6
+ import * as nodeCrypto$b from 'crypto';
6
7
 
7
8
  const doneWritingPromise = Symbol('doneWritingPromise');
8
9
  const doneWritingResolve = Symbol('doneWritingResolve');
@@ -546,9 +547,10 @@ function transformRaw(input, options) {
546
547
  * @param {Function} cancel
547
548
  * @returns {TransformStream}
548
549
  */
549
- function transformWithCancel(cancel) {
550
+ function transformWithCancel(customCancel) {
550
551
  let pulled = false;
551
- let backpressureChangePromiseResolve;
552
+ let cancelled = false;
553
+ let backpressureChangePromiseResolve, backpressureChangePromiseReject;
552
554
  let outputController;
553
555
  return {
554
556
  readable: new ReadableStream({
@@ -562,16 +564,29 @@ function transformWithCancel(cancel) {
562
564
  pulled = true;
563
565
  }
564
566
  },
565
- cancel
567
+ async cancel(reason) {
568
+ cancelled = true;
569
+ if (customCancel) {
570
+ await customCancel(reason);
571
+ }
572
+ if (backpressureChangePromiseReject) {
573
+ backpressureChangePromiseReject(reason);
574
+ }
575
+ }
566
576
  }, {highWaterMark: 0}),
567
577
  writable: new WritableStream({
568
578
  write: async function(chunk) {
579
+ if (cancelled) {
580
+ throw new Error('Stream is cancelled');
581
+ }
569
582
  outputController.enqueue(chunk);
570
583
  if (!pulled) {
571
- await new Promise(resolve => {
584
+ await new Promise((resolve, reject) => {
572
585
  backpressureChangePromiseResolve = resolve;
586
+ backpressureChangePromiseReject = reject;
573
587
  });
574
588
  backpressureChangePromiseResolve = null;
589
+ backpressureChangePromiseReject = null;
575
590
  } else {
576
591
  pulled = false;
577
592
  }
@@ -1507,6 +1522,14 @@ var config = {
1507
1522
  * @property {Boolean} v6Keys
1508
1523
  */
1509
1524
  v6Keys: false,
1525
+ /**
1526
+ * Enable parsing v5 keys and v5 signatures (which is different from the AEAD-encrypted SEIPDv2 packet).
1527
+ * These are non-standard entities, which in the crypto-refresh have been superseded
1528
+ * by v6 keys and v6 signatures, respectively.
1529
+ * However, generation of v5 entities was supported behind config flag in OpenPGP.js v5, and some other libraries,
1530
+ * hence parsing them might be necessary in some cases.
1531
+ */
1532
+ enableParsingV5Entities: false,
1510
1533
  /**
1511
1534
  * S2K (String to Key) type, used for key derivation in the context of secret key encryption
1512
1535
  * and password-encrypted data. Weaker s2k options are not allowed.
@@ -1663,7 +1686,7 @@ var config = {
1663
1686
  * @memberof module:config
1664
1687
  * @property {String} versionString A version string to be included in armored messages
1665
1688
  */
1666
- versionString: 'OpenPGP.js 6.0.0-beta.1',
1689
+ versionString: 'OpenPGP.js 6.0.0-beta.2',
1667
1690
  /**
1668
1691
  * @memberof module:config
1669
1692
  * @property {String} commentString A comment string to be included in armored messages
@@ -5836,8 +5859,8 @@ var mode = {
5836
5859
  };
5837
5860
 
5838
5861
  // Operations are not constant time, but we try and limit timing leakage where we can
5839
- const _0n$8 = BigInt(0);
5840
- const _1n$d = BigInt(1);
5862
+ const _0n$9 = BigInt(0);
5863
+ const _1n$e = BigInt(1);
5841
5864
  function uint8ArrayToBigInt(bytes) {
5842
5865
  const hexAlphabet = '0123456789ABCDEF';
5843
5866
  let s = '';
@@ -5846,9 +5869,9 @@ function uint8ArrayToBigInt(bytes) {
5846
5869
  });
5847
5870
  return BigInt('0x0' + s);
5848
5871
  }
5849
- function mod$2(a, m) {
5872
+ function mod$3(a, m) {
5850
5873
  const reduced = a % m;
5851
- return reduced < _0n$8 ? reduced + m : reduced;
5874
+ return reduced < _0n$9 ? reduced + m : reduced;
5852
5875
  }
5853
5876
  /**
5854
5877
  * Compute modular exponentiation using square and multiply
@@ -5858,19 +5881,19 @@ function mod$2(a, m) {
5858
5881
  * @returns {BigInt} b ** e mod n.
5859
5882
  */
5860
5883
  function modExp(b, e, n) {
5861
- if (n === _0n$8)
5884
+ if (n === _0n$9)
5862
5885
  throw Error('Modulo cannot be zero');
5863
- if (n === _1n$d)
5886
+ if (n === _1n$e)
5864
5887
  return BigInt(0);
5865
- if (e < _0n$8)
5888
+ if (e < _0n$9)
5866
5889
  throw Error('Unsopported negative exponent');
5867
5890
  let exp = e;
5868
5891
  let x = b;
5869
5892
  x %= n;
5870
5893
  let r = BigInt(1);
5871
- while (exp > _0n$8) {
5872
- const lsb = exp & _1n$d;
5873
- exp >>= _1n$d; // e / 2
5894
+ while (exp > _0n$9) {
5895
+ const lsb = exp & _1n$e;
5896
+ exp >>= _1n$e; // e / 2
5874
5897
  // Always compute multiplication step, to reduce timing leakage
5875
5898
  const rx = (r * x) % n;
5876
5899
  // Update r only if lsb is 1 (odd exponent)
@@ -5880,7 +5903,7 @@ function modExp(b, e, n) {
5880
5903
  return r;
5881
5904
  }
5882
5905
  function abs(x) {
5883
- return x >= _0n$8 ? x : -x;
5906
+ return x >= _0n$9 ? x : -x;
5884
5907
  }
5885
5908
  /**
5886
5909
  * Extended Eucleadian algorithm (http://anh.cs.luc.edu/331/notes/xgcd.pdf)
@@ -5900,9 +5923,9 @@ function _egcd(aInput, bInput) {
5900
5923
  // See https://math.stackexchange.com/questions/37806/extended-euclidean-algorithm-with-negative-numbers
5901
5924
  let a = abs(aInput);
5902
5925
  let b = abs(bInput);
5903
- const aNegated = aInput < _0n$8;
5904
- const bNegated = bInput < _0n$8;
5905
- while (b !== _0n$8) {
5926
+ const aNegated = aInput < _0n$9;
5927
+ const bNegated = bInput < _0n$9;
5928
+ while (b !== _0n$9) {
5906
5929
  const q = a / b;
5907
5930
  let tmp = x;
5908
5931
  x = xPrev - q * x;
@@ -5930,10 +5953,10 @@ function _egcd(aInput, bInput) {
5930
5953
  */
5931
5954
  function modInv(a, n) {
5932
5955
  const { gcd, x } = _egcd(a, n);
5933
- if (gcd !== _1n$d) {
5956
+ if (gcd !== _1n$e) {
5934
5957
  throw new Error('Inverse does not exist');
5935
5958
  }
5936
- return mod$2(x + n, n);
5959
+ return mod$3(x + n, n);
5937
5960
  }
5938
5961
  /**
5939
5962
  * Compute greatest common divisor between this and n
@@ -5944,7 +5967,7 @@ function modInv(a, n) {
5944
5967
  function gcd(aInput, bInput) {
5945
5968
  let a = aInput;
5946
5969
  let b = bInput;
5947
- while (b !== _0n$8) {
5970
+ while (b !== _0n$9) {
5948
5971
  const tmp = b;
5949
5972
  b = a % b;
5950
5973
  a = tmp;
@@ -5971,8 +5994,8 @@ function bigIntToNumber(x) {
5971
5994
  * @returns {Number} Bit value.
5972
5995
  */
5973
5996
  function getBit(x, i) {
5974
- const bit = (x >> BigInt(i)) & _1n$d;
5975
- return bit === _0n$8 ? 0 : 1;
5997
+ const bit = (x >> BigInt(i)) & _1n$e;
5998
+ return bit === _0n$9 ? 0 : 1;
5976
5999
  }
5977
6000
  /**
5978
6001
  * Compute bit length
@@ -5980,11 +6003,11 @@ function getBit(x, i) {
5980
6003
  function bitLength(x) {
5981
6004
  // -1n >> -1n is -1n
5982
6005
  // 1n >> 1n is 0n
5983
- const target = x < _0n$8 ? BigInt(-1) : _0n$8;
6006
+ const target = x < _0n$9 ? BigInt(-1) : _0n$9;
5984
6007
  let bitlen = 1;
5985
6008
  let tmp = x;
5986
6009
  // eslint-disable-next-line no-cond-assign
5987
- while ((tmp >>= _1n$d) !== target) {
6010
+ while ((tmp >>= _1n$e) !== target) {
5988
6011
  bitlen++;
5989
6012
  }
5990
6013
  return bitlen;
@@ -5993,7 +6016,7 @@ function bitLength(x) {
5993
6016
  * Compute byte length
5994
6017
  */
5995
6018
  function byteLength(x) {
5996
- const target = x < _0n$8 ? BigInt(-1) : _0n$8;
6019
+ const target = x < _0n$9 ? BigInt(-1) : _0n$9;
5997
6020
  const _8n = BigInt(8);
5998
6021
  let len = 1;
5999
6022
  let tmp = x;
@@ -6088,7 +6111,7 @@ function getRandomBigInteger(min, max) {
6088
6111
  // However, we request 64 extra random bits so that the bias is negligible.
6089
6112
  // Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
6090
6113
  const r = uint8ArrayToBigInt(getRandomBytes(bytes + 8));
6091
- return mod$2(r, modulus) + min;
6114
+ return mod$3(r, modulus) + min;
6092
6115
  }
6093
6116
 
6094
6117
  var random = /*#__PURE__*/Object.freeze({
@@ -6117,7 +6140,7 @@ var random = /*#__PURE__*/Object.freeze({
6117
6140
  * @fileoverview Algorithms for probabilistic random prime generation
6118
6141
  * @module crypto/public_key/prime
6119
6142
  */
6120
- const _1n$c = BigInt(1);
6143
+ const _1n$d = BigInt(1);
6121
6144
  /**
6122
6145
  * Generate a probably prime random number
6123
6146
  * @param bits - Bit length of the prime
@@ -6126,7 +6149,7 @@ const _1n$c = BigInt(1);
6126
6149
  */
6127
6150
  function randomProbablePrime(bits, e, k) {
6128
6151
  const _30n = BigInt(30);
6129
- const min = _1n$c << BigInt(bits - 1);
6152
+ const min = _1n$d << BigInt(bits - 1);
6130
6153
  /*
6131
6154
  * We can avoid any multiples of 3 and 5 by looking at n mod 30
6132
6155
  * 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
@@ -6134,16 +6157,16 @@ function randomProbablePrime(bits, e, k) {
6134
6157
  * 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
6135
6158
  */
6136
6159
  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];
6137
- let n = getRandomBigInteger(min, min << _1n$c);
6138
- let i = bigIntToNumber(mod$2(n, _30n));
6160
+ let n = getRandomBigInteger(min, min << _1n$d);
6161
+ let i = bigIntToNumber(mod$3(n, _30n));
6139
6162
  do {
6140
6163
  n += BigInt(adds[i]);
6141
6164
  i = (i + adds[i]) % adds.length;
6142
6165
  // If reached the maximum, go back to the minimum.
6143
6166
  if (bitLength(n) > bits) {
6144
- n = mod$2(n, min << _1n$c);
6167
+ n = mod$3(n, min << _1n$d);
6145
6168
  n += min;
6146
- i = bigIntToNumber(mod$2(n, _30n));
6169
+ i = bigIntToNumber(mod$3(n, _30n));
6147
6170
  }
6148
6171
  } while (!isProbablePrime(n, e, k));
6149
6172
  return n;
@@ -6155,7 +6178,7 @@ function randomProbablePrime(bits, e, k) {
6155
6178
  * @param k - Optional number of iterations of Miller-Rabin test
6156
6179
  */
6157
6180
  function isProbablePrime(n, e, k) {
6158
- if (e && gcd(n - _1n$c, e) !== _1n$c) {
6181
+ if (e && gcd(n - _1n$d, e) !== _1n$d) {
6159
6182
  return false;
6160
6183
  }
6161
6184
  if (!divisionTest(n)) {
@@ -6178,11 +6201,11 @@ function isProbablePrime(n, e, k) {
6178
6201
  * @param b - Optional Fermat test base
6179
6202
  */
6180
6203
  function fermat(n, b = BigInt(2)) {
6181
- return modExp(b, n - _1n$c, n) === _1n$c;
6204
+ return modExp(b, n - _1n$d, n) === _1n$d;
6182
6205
  }
6183
6206
  function divisionTest(n) {
6184
6207
  const _0n = BigInt(0);
6185
- return smallPrimes.every(m => mod$2(n, m) !== _0n);
6208
+ return smallPrimes.every(m => mod$3(n, m) !== _0n);
6186
6209
  }
6187
6210
  // https://github.com/gpg/libgcrypt/blob/master/cipher/primegen.c
6188
6211
  const smallPrimes = [
@@ -6306,7 +6329,7 @@ function millerRabin(n, k, rand) {
6306
6329
  if (!k) {
6307
6330
  k = Math.max(1, (len / 48) | 0);
6308
6331
  }
6309
- const n1 = n - _1n$c; // n - 1
6332
+ const n1 = n - _1n$d; // n - 1
6310
6333
  // Find d and s, (n - 1) = (2 ^ s) * d;
6311
6334
  let s = 0;
6312
6335
  while (!getBit(n1, s)) {
@@ -6316,13 +6339,13 @@ function millerRabin(n, k, rand) {
6316
6339
  for (; k > 0; k--) {
6317
6340
  const a = getRandomBigInteger(BigInt(2), n1);
6318
6341
  let x = modExp(a, d, n);
6319
- if (x === _1n$c || x === n1) {
6342
+ if (x === _1n$d || x === n1) {
6320
6343
  continue;
6321
6344
  }
6322
6345
  let i;
6323
6346
  for (i = 1; i < s; i++) {
6324
- x = mod$2(x * x, n);
6325
- if (x === _1n$c) {
6347
+ x = mod$3(x * x, n);
6348
+ if (x === _1n$d) {
6326
6349
  return false;
6327
6350
  }
6328
6351
  if (x === n1) {
@@ -6516,7 +6539,7 @@ var pkcs1 = /*#__PURE__*/Object.freeze({
6516
6539
 
6517
6540
  const webCrypto$6 = util.getWebCrypto();
6518
6541
  const nodeCrypto$4 = util.getNodeCrypto();
6519
- const _1n$b = BigInt(1);
6542
+ const _1n$c = BigInt(1);
6520
6543
 
6521
6544
  /** Create signature
6522
6545
  * @param {module:enums.hash} hashAlgo - Hash algorithm
@@ -6557,7 +6580,7 @@ async function sign$7(hashAlgo, data, n, e, d, p, q, u, hashed) {
6557
6580
  * @returns {Boolean}
6558
6581
  * @async
6559
6582
  */
6560
- async function verify$7(hashAlgo, data, s, n, e, hashed) {
6583
+ async function verify$8(hashAlgo, data, s, n, e, hashed) {
6561
6584
  if (data && !util.isStream(data)) {
6562
6585
  if (util.getWebCrypto()) {
6563
6586
  try {
@@ -6680,7 +6703,7 @@ async function generate$5(bits, e) {
6680
6703
  n = p * q;
6681
6704
  } while (bitLength(n) !== bits);
6682
6705
 
6683
- const phi = (p - _1n$b) * (q - _1n$b);
6706
+ const phi = (p - _1n$c) * (q - _1n$c);
6684
6707
 
6685
6708
  if (q < p) {
6686
6709
  [p, q] = [q, p];
@@ -6722,7 +6745,7 @@ async function validateParams$9(n, e, d, p, q, u) {
6722
6745
  const _2n = BigInt(2);
6723
6746
  // expect p*u = 1 mod q
6724
6747
  u = uint8ArrayToBigInt(u);
6725
- if (mod$2(p * u, q) !== BigInt(1)) {
6748
+ if (mod$3(p * u, q) !== BigInt(1)) {
6726
6749
  return false;
6727
6750
  }
6728
6751
 
@@ -6739,7 +6762,7 @@ async function validateParams$9(n, e, d, p, q, u) {
6739
6762
  const r = getRandomBigInteger(_2n, _2n << nSizeOver3); // r in [ 2, 2^{|n|/3} ) < p and q
6740
6763
  const rde = r * d * e;
6741
6764
 
6742
- const areInverses = mod$2(rde, p - _1n$b) === r && mod$2(rde, q - _1n$b) === r;
6765
+ const areInverses = mod$3(rde, p - _1n$c) === r && mod$3(rde, q - _1n$c) === r;
6743
6766
  if (!areInverses) {
6744
6767
  return false;
6745
6768
  }
@@ -6858,20 +6881,20 @@ async function bnDecrypt(data, n, e, d, p, q, u, randomPayload) {
6858
6881
  if (data >= n) {
6859
6882
  throw new Error('Data too large.');
6860
6883
  }
6861
- const dq = mod$2(d, q - _1n$b); // d mod (q-1)
6862
- const dp = mod$2(d, p - _1n$b); // d mod (p-1)
6884
+ const dq = mod$3(d, q - _1n$c); // d mod (q-1)
6885
+ const dp = mod$3(d, p - _1n$c); // d mod (p-1)
6863
6886
 
6864
6887
  const unblinder = getRandomBigInteger(BigInt(2), n);
6865
6888
  const blinder = modExp(modInv(unblinder, n), e, n);
6866
- data = mod$2(data * blinder, n);
6889
+ data = mod$3(data * blinder, n);
6867
6890
 
6868
6891
  const mp = modExp(data, dp, p); // data**{d mod (q-1)} mod p
6869
6892
  const mq = modExp(data, dq, q); // data**{d mod (p-1)} mod q
6870
- const h = mod$2(u * (mq - mp), q); // u * (mq-mp) mod q (operands already < q)
6893
+ const h = mod$3(u * (mq - mp), q); // u * (mq-mp) mod q (operands already < q)
6871
6894
 
6872
6895
  let result = h * p + mp; // result < n due to relations above
6873
6896
 
6874
- result = mod$2(result * unblinder, n);
6897
+ result = mod$3(result * unblinder, n);
6875
6898
 
6876
6899
  return emeDecode(bigIntToUint8Array(result, 'be', byteLength(n)), randomPayload);
6877
6900
  }
@@ -6891,8 +6914,8 @@ async function privateToJWK$1(n, e, d, p, q, u) {
6891
6914
  const qNum = uint8ArrayToBigInt(q);
6892
6915
  const dNum = uint8ArrayToBigInt(d);
6893
6916
 
6894
- let dq = mod$2(dNum, qNum - _1n$b); // d mod (q-1)
6895
- let dp = mod$2(dNum, pNum - _1n$b); // d mod (p-1)
6917
+ let dq = mod$3(dNum, qNum - _1n$c); // d mod (q-1)
6918
+ let dp = mod$3(dNum, pNum - _1n$c); // d mod (p-1)
6896
6919
  dp = bigIntToUint8Array(dp);
6897
6920
  dq = bigIntToUint8Array(dq);
6898
6921
  return {
@@ -6947,7 +6970,7 @@ var rsa = /*#__PURE__*/Object.freeze({
6947
6970
  generate: generate$5,
6948
6971
  sign: sign$7,
6949
6972
  validateParams: validateParams$9,
6950
- verify: verify$7
6973
+ verify: verify$8
6951
6974
  });
6952
6975
 
6953
6976
  // GPG4Browsers - An OpenPGP implementation in javascript
@@ -6968,7 +6991,7 @@ var rsa = /*#__PURE__*/Object.freeze({
6968
6991
  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6969
6992
 
6970
6993
 
6971
- const _1n$a = BigInt(1);
6994
+ const _1n$b = BigInt(1);
6972
6995
 
6973
6996
  /**
6974
6997
  * ElGamal Encryption function
@@ -6990,10 +7013,10 @@ async function encrypt$3(data, p, g, y) {
6990
7013
 
6991
7014
  // OpenPGP uses a "special" version of ElGamal where g is generator of the full group Z/pZ*
6992
7015
  // hence g has order p-1, and to avoid that k = 0 mod p-1, we need to pick k in [1, p-2]
6993
- const k = getRandomBigInteger(_1n$a, p - _1n$a);
7016
+ const k = getRandomBigInteger(_1n$b, p - _1n$b);
6994
7017
  return {
6995
7018
  c1: bigIntToUint8Array(modExp(g, k, p)),
6996
- c2: bigIntToUint8Array(mod$2(modExp(y, k, p) * m, p))
7019
+ c2: bigIntToUint8Array(mod$3(modExp(y, k, p) * m, p))
6997
7020
  };
6998
7021
  }
6999
7022
 
@@ -7015,7 +7038,7 @@ async function decrypt$3(c1, c2, p, x, randomPayload) {
7015
7038
  p = uint8ArrayToBigInt(p);
7016
7039
  x = uint8ArrayToBigInt(x);
7017
7040
 
7018
- const padded = mod$2(modInv(modExp(c1, x, p), p) * c2, p);
7041
+ const padded = mod$3(modInv(modExp(c1, x, p), p) * c2, p);
7019
7042
  return emeDecode(bigIntToUint8Array(padded, 'be', byteLength(p)), randomPayload);
7020
7043
  }
7021
7044
 
@@ -7034,7 +7057,7 @@ async function validateParams$8(p, g, y, x) {
7034
7057
  y = uint8ArrayToBigInt(y);
7035
7058
 
7036
7059
  // Check that 1 < g < p
7037
- if (g <= _1n$a || g >= p) {
7060
+ if (g <= _1n$b || g >= p) {
7038
7061
  return false;
7039
7062
  }
7040
7063
 
@@ -7049,7 +7072,7 @@ async function validateParams$8(p, g, y, x) {
7049
7072
  * g should have order p-1
7050
7073
  * Check that g ** (p-1) = 1 mod p
7051
7074
  */
7052
- if (modExp(g, p - _1n$a, p) !== _1n$a) {
7075
+ if (modExp(g, p - _1n$b, p) !== _1n$b) {
7053
7076
  return false;
7054
7077
  }
7055
7078
 
@@ -7064,8 +7087,8 @@ async function validateParams$8(p, g, y, x) {
7064
7087
  const _2n = BigInt(2);
7065
7088
  const threshold = _2n << BigInt(17); // we want order > threshold
7066
7089
  while (i < threshold) {
7067
- res = mod$2(res * g, p);
7068
- if (res === _1n$a) {
7090
+ res = mod$3(res * g, p);
7091
+ if (res === _1n$b) {
7069
7092
  return false;
7070
7093
  }
7071
7094
  i++;
@@ -7078,8 +7101,8 @@ async function validateParams$8(p, g, y, x) {
7078
7101
  * Blinded exponentiation computes g**{r(p-1) + x} to compare to y
7079
7102
  */
7080
7103
  x = uint8ArrayToBigInt(x);
7081
- const r = getRandomBigInteger(_2n << (pSize - _1n$a), _2n << pSize); // draw r of same size as p-1
7082
- const rqx = (p - _1n$a) * r + x;
7104
+ const r = getRandomBigInteger(_2n << (pSize - _1n$b), _2n << pSize); // draw r of same size as p-1
7105
+ const rqx = (p - _1n$b) * r + x;
7083
7106
  if (y !== modExp(g, rqx, p)) {
7084
7107
  return false;
7085
7108
  }
@@ -7096,7 +7119,7 @@ var elgamal = /*#__PURE__*/Object.freeze({
7096
7119
 
7097
7120
  // We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
7098
7121
  // See utils.ts for details.
7099
- const crypto$3 =
7122
+ const crypto$4 =
7100
7123
  nc && typeof nc === 'object' && 'webcrypto' in nc ? nc.webcrypto : undefined;
7101
7124
 
7102
7125
  const nacl = {};
@@ -8459,13 +8482,13 @@ nacl.setPRNG = function(fn) {
8459
8482
  (function() {
8460
8483
  // Initialize PRNG if environment provides CSPRNG.
8461
8484
  // If not, methods calling randombytes will throw.
8462
- if (crypto$3 && crypto$3.getRandomValues) {
8485
+ if (crypto$4 && crypto$4.getRandomValues) {
8463
8486
  // Browsers and Node v16+
8464
8487
  var QUOTA = 65536;
8465
8488
  nacl.setPRNG(function(x, n) {
8466
8489
  var i, v = new Uint8Array(n);
8467
8490
  for (i = 0; i < n; i += QUOTA) {
8468
- crypto$3.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
8491
+ crypto$4.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
8469
8492
  }
8470
8493
  for (i = 0; i < n; i++) x[i] = v[i];
8471
8494
  cleanup(v);
@@ -8943,7 +8966,8 @@ const curves = {
8943
8966
  node: nodeCurves[enums.curve.nistP256],
8944
8967
  web: webCurves[enums.curve.nistP256],
8945
8968
  payloadSize: 32,
8946
- sharedSize: 256
8969
+ sharedSize: 256,
8970
+ wireFormatLeadingByte: 0x04
8947
8971
  },
8948
8972
  [enums.curve.nistP384]: {
8949
8973
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22],
@@ -8953,7 +8977,8 @@ const curves = {
8953
8977
  node: nodeCurves[enums.curve.nistP384],
8954
8978
  web: webCurves[enums.curve.nistP384],
8955
8979
  payloadSize: 48,
8956
- sharedSize: 384
8980
+ sharedSize: 384,
8981
+ wireFormatLeadingByte: 0x04
8957
8982
  },
8958
8983
  [enums.curve.nistP521]: {
8959
8984
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23],
@@ -8963,7 +8988,8 @@ const curves = {
8963
8988
  node: nodeCurves[enums.curve.nistP521],
8964
8989
  web: webCurves[enums.curve.nistP521],
8965
8990
  payloadSize: 66,
8966
- sharedSize: 528
8991
+ sharedSize: 528,
8992
+ wireFormatLeadingByte: 0x04
8967
8993
  },
8968
8994
  [enums.curve.secp256k1]: {
8969
8995
  oid: [0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x0A],
@@ -8971,14 +8997,16 @@ const curves = {
8971
8997
  hash: enums.hash.sha256,
8972
8998
  cipher: enums.symmetric.aes128,
8973
8999
  node: nodeCurves[enums.curve.secp256k1],
8974
- payloadSize: 32
9000
+ payloadSize: 32,
9001
+ wireFormatLeadingByte: 0x04
8975
9002
  },
8976
9003
  [enums.curve.ed25519Legacy]: {
8977
9004
  oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
8978
9005
  keyType: enums.publicKey.eddsaLegacy,
8979
9006
  hash: enums.hash.sha512,
8980
9007
  node: false, // nodeCurves.ed25519 TODO
8981
- payloadSize: 32
9008
+ payloadSize: 32,
9009
+ wireFormatLeadingByte: 0x40
8982
9010
  },
8983
9011
  [enums.curve.curve25519Legacy]: {
8984
9012
  oid: [0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01],
@@ -8986,7 +9014,8 @@ const curves = {
8986
9014
  hash: enums.hash.sha256,
8987
9015
  cipher: enums.symmetric.aes128,
8988
9016
  node: false, // nodeCurves.curve25519 TODO
8989
- payloadSize: 32
9017
+ payloadSize: 32,
9018
+ wireFormatLeadingByte: 0x40
8990
9019
  },
8991
9020
  [enums.curve.brainpoolP256r1]: {
8992
9021
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07],
@@ -8994,7 +9023,8 @@ const curves = {
8994
9023
  hash: enums.hash.sha256,
8995
9024
  cipher: enums.symmetric.aes128,
8996
9025
  node: nodeCurves[enums.curve.brainpoolP256r1],
8997
- payloadSize: 32
9026
+ payloadSize: 32,
9027
+ wireFormatLeadingByte: 0x04
8998
9028
  },
8999
9029
  [enums.curve.brainpoolP384r1]: {
9000
9030
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B],
@@ -9002,7 +9032,8 @@ const curves = {
9002
9032
  hash: enums.hash.sha384,
9003
9033
  cipher: enums.symmetric.aes192,
9004
9034
  node: nodeCurves[enums.curve.brainpoolP384r1],
9005
- payloadSize: 48
9035
+ payloadSize: 48,
9036
+ wireFormatLeadingByte: 0x04
9006
9037
  },
9007
9038
  [enums.curve.brainpoolP512r1]: {
9008
9039
  oid: [0x06, 0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D],
@@ -9010,7 +9041,8 @@ const curves = {
9010
9041
  hash: enums.hash.sha512,
9011
9042
  cipher: enums.symmetric.aes256,
9012
9043
  node: nodeCurves[enums.curve.brainpoolP512r1],
9013
- payloadSize: 64
9044
+ payloadSize: 64,
9045
+ wireFormatLeadingByte: 0x04
9014
9046
  }
9015
9047
  };
9016
9048
 
@@ -9034,6 +9066,7 @@ class CurveWithOID {
9034
9066
  this.web = params.web;
9035
9067
  this.payloadSize = params.payloadSize;
9036
9068
  this.sharedSize = params.sharedSize;
9069
+ this.wireFormatLeadingByte = params.wireFormatLeadingByte;
9037
9070
  if (this.web && util.getWebCrypto()) {
9038
9071
  this.type = 'web';
9039
9072
  } else if (this.node && util.getNodeCrypto()) {
@@ -9049,7 +9082,7 @@ class CurveWithOID {
9049
9082
  switch (this.type) {
9050
9083
  case 'web':
9051
9084
  try {
9052
- return await webGenKeyPair(this.name);
9085
+ return await webGenKeyPair(this.name, this.wireFormatLeadingByte);
9053
9086
  } catch (err) {
9054
9087
  util.printDebugError('Browser did not support generating ec key ' + err.message);
9055
9088
  return jsGenKeyPair(this.name);
@@ -9062,13 +9095,13 @@ class CurveWithOID {
9062
9095
  privateKey[31] &= 248;
9063
9096
  const secretKey = privateKey.slice().reverse();
9064
9097
  const { publicKey: rawPublicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
9065
- const publicKey = util.concatUint8Array([new Uint8Array([0x40]), rawPublicKey]);
9098
+ const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), rawPublicKey]);
9066
9099
  return { publicKey, privateKey };
9067
9100
  }
9068
9101
  case 'ed25519Legacy': {
9069
9102
  const privateKey = getRandomBytes(32);
9070
9103
  const keyPair = nacl.sign.keyPair.fromSeed(privateKey);
9071
- const publicKey = util.concatUint8Array([new Uint8Array([0x40]), keyPair.publicKey]);
9104
+ const publicKey = util.concatUint8Array([new Uint8Array([this.wireFormatLeadingByte]), keyPair.publicKey]);
9072
9105
  return { publicKey, privateKey };
9073
9106
  }
9074
9107
  default:
@@ -9154,6 +9187,20 @@ async function validateStandardParams(algo, oid, Q, d) {
9154
9187
  return true;
9155
9188
  }
9156
9189
 
9190
+ /**
9191
+ * Check whether the public point has a valid encoding.
9192
+ * NB: this function does not check e.g. whether the point belongs to the curve.
9193
+ */
9194
+ function checkPublicPointEnconding(curve, V) {
9195
+ const { payloadSize, wireFormatLeadingByte, name: curveName } = curve;
9196
+
9197
+ const pointSize = (curveName === enums.curve.curve25519Legacy || curveName === enums.curve.ed25519Legacy) ? payloadSize : payloadSize * 2;
9198
+
9199
+ if (V[0] !== wireFormatLeadingByte || V.length !== pointSize + 1) {
9200
+ throw new Error('Invalid point encoding');
9201
+ }
9202
+ }
9203
+
9157
9204
  //////////////////////////
9158
9205
  // //
9159
9206
  // Helper functions //
@@ -9166,7 +9213,7 @@ async function jsGenKeyPair(name) {
9166
9213
  return { publicKey, privateKey };
9167
9214
  }
9168
9215
 
9169
- async function webGenKeyPair(name) {
9216
+ async function webGenKeyPair(name, wireFormatLeadingByte) {
9170
9217
  // Note: keys generated with ECDSA and ECDH are structurally equivalent
9171
9218
  const webCryptoKey = await webCrypto$5.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']);
9172
9219
 
@@ -9174,7 +9221,7 @@ async function webGenKeyPair(name) {
9174
9221
  const publicKey = await webCrypto$5.exportKey('jwk', webCryptoKey.publicKey);
9175
9222
 
9176
9223
  return {
9177
- publicKey: jwkToRawPublic(publicKey),
9224
+ publicKey: jwkToRawPublic(publicKey, wireFormatLeadingByte),
9178
9225
  privateKey: b64ToUint8Array(privateKey.d)
9179
9226
  };
9180
9227
  }
@@ -9200,11 +9247,11 @@ async function nodeGenKeyPair(name) {
9200
9247
  *
9201
9248
  * @returns {Uint8Array} Raw public key.
9202
9249
  */
9203
- function jwkToRawPublic(jwk) {
9250
+ function jwkToRawPublic(jwk, wireFormatLeadingByte) {
9204
9251
  const bufX = b64ToUint8Array(jwk.x);
9205
9252
  const bufY = b64ToUint8Array(jwk.y);
9206
9253
  const publicKey = new Uint8Array(bufX.length + bufY.length + 1);
9207
- publicKey[0] = 0x04;
9254
+ publicKey[0] = wireFormatLeadingByte;
9208
9255
  publicKey.set(bufX, 1);
9209
9256
  publicKey.set(bufY, bufX.length + 1);
9210
9257
  return publicKey;
@@ -9283,6 +9330,7 @@ const nodeCrypto$2 = util.getNodeCrypto();
9283
9330
  */
9284
9331
  async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9285
9332
  const curve = new CurveWithOID(oid);
9333
+ checkPublicPointEnconding(curve, publicKey);
9286
9334
  if (message && !util.isStream(message)) {
9287
9335
  const keyPair = { publicKey, privateKey };
9288
9336
  switch (curve.type) {
@@ -9327,8 +9375,9 @@ async function sign$6(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9327
9375
  * @returns {Boolean}
9328
9376
  * @async
9329
9377
  */
9330
- async function verify$6(oid, hashAlgo, signature, message, publicKey, hashed) {
9378
+ async function verify$7(oid, hashAlgo, signature, message, publicKey, hashed) {
9331
9379
  const curve = new CurveWithOID(oid);
9380
+ checkPublicPointEnconding(curve, publicKey);
9332
9381
  // See https://github.com/openpgpjs/openpgpjs/pull/948.
9333
9382
  // NB: the impact was more likely limited to Brainpool curves, since thanks
9334
9383
  // to WebCrypto availability, NIST curve should not have been affected.
@@ -9395,7 +9444,7 @@ async function validateParams$7(oid, Q, d) {
9395
9444
  try {
9396
9445
  const signature = await sign$6(oid, hashAlgo, message, Q, d, hashed);
9397
9446
  // eslint-disable-next-line @typescript-eslint/return-await
9398
- return await verify$6(oid, hashAlgo, signature, message, Q, hashed);
9447
+ return await verify$7(oid, hashAlgo, signature, message, Q, hashed);
9399
9448
  } catch (err) {
9400
9449
  return false;
9401
9450
  }
@@ -9528,7 +9577,766 @@ var ecdsa = /*#__PURE__*/Object.freeze({
9528
9577
  __proto__: null,
9529
9578
  sign: sign$6,
9530
9579
  validateParams: validateParams$7,
9531
- verify: verify$6
9580
+ verify: verify$7
9581
+ });
9582
+
9583
+ /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
9584
+ const _0n$8 = BigInt(0);
9585
+ const _1n$a = BigInt(1);
9586
+ const _2n$6 = BigInt(2);
9587
+ const _8n$2 = BigInt(8);
9588
+ const CU_O = BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989');
9589
+ const CURVE$1 = Object.freeze({
9590
+ a: BigInt(-1),
9591
+ d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
9592
+ P: BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819949'),
9593
+ l: CU_O,
9594
+ n: CU_O,
9595
+ h: BigInt(8),
9596
+ Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
9597
+ Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
9598
+ });
9599
+ const POW_2_256 = BigInt('0x10000000000000000000000000000000000000000000000000000000000000000');
9600
+ const SQRT_M1 = BigInt('19681161376707505956807079304988542015446066515923890162744021073123829784752');
9601
+ BigInt('6853475219497561581579357271197624642482790079785650197046958215289687604742');
9602
+ const SQRT_AD_MINUS_ONE = BigInt('25063068953384623474111414158702152701244531502492656460079210482610430750235');
9603
+ const INVSQRT_A_MINUS_D = BigInt('54469307008909316920995813868745141605393597292927456921205312896311721017578');
9604
+ const ONE_MINUS_D_SQ = BigInt('1159843021668779879193775521855586647937357759715417654439879720876111806838');
9605
+ const D_MINUS_ONE_SQ = BigInt('40440834346308536858101042469323190826248399146238708352240133220865137265952');
9606
+ class ExtendedPoint {
9607
+ constructor(x, y, z, t) {
9608
+ this.x = x;
9609
+ this.y = y;
9610
+ this.z = z;
9611
+ this.t = t;
9612
+ }
9613
+ static fromAffine(p) {
9614
+ if (!(p instanceof Point)) {
9615
+ throw new TypeError('ExtendedPoint#fromAffine: expected Point');
9616
+ }
9617
+ if (p.equals(Point.ZERO))
9618
+ return ExtendedPoint.ZERO;
9619
+ return new ExtendedPoint(p.x, p.y, _1n$a, mod$2(p.x * p.y));
9620
+ }
9621
+ static toAffineBatch(points) {
9622
+ const toInv = invertBatch(points.map((p) => p.z));
9623
+ return points.map((p, i) => p.toAffine(toInv[i]));
9624
+ }
9625
+ static normalizeZ(points) {
9626
+ return this.toAffineBatch(points).map(this.fromAffine);
9627
+ }
9628
+ equals(other) {
9629
+ assertExtPoint(other);
9630
+ const { x: X1, y: Y1, z: Z1 } = this;
9631
+ const { x: X2, y: Y2, z: Z2 } = other;
9632
+ const X1Z2 = mod$2(X1 * Z2);
9633
+ const X2Z1 = mod$2(X2 * Z1);
9634
+ const Y1Z2 = mod$2(Y1 * Z2);
9635
+ const Y2Z1 = mod$2(Y2 * Z1);
9636
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
9637
+ }
9638
+ negate() {
9639
+ return new ExtendedPoint(mod$2(-this.x), this.y, this.z, mod$2(-this.t));
9640
+ }
9641
+ double() {
9642
+ const { x: X1, y: Y1, z: Z1 } = this;
9643
+ const { a } = CURVE$1;
9644
+ const A = mod$2(X1 * X1);
9645
+ const B = mod$2(Y1 * Y1);
9646
+ const C = mod$2(_2n$6 * mod$2(Z1 * Z1));
9647
+ const D = mod$2(a * A);
9648
+ const x1y1 = X1 + Y1;
9649
+ const E = mod$2(mod$2(x1y1 * x1y1) - A - B);
9650
+ const G = D + B;
9651
+ const F = G - C;
9652
+ const H = D - B;
9653
+ const X3 = mod$2(E * F);
9654
+ const Y3 = mod$2(G * H);
9655
+ const T3 = mod$2(E * H);
9656
+ const Z3 = mod$2(F * G);
9657
+ return new ExtendedPoint(X3, Y3, Z3, T3);
9658
+ }
9659
+ add(other) {
9660
+ assertExtPoint(other);
9661
+ const { x: X1, y: Y1, z: Z1, t: T1 } = this;
9662
+ const { x: X2, y: Y2, z: Z2, t: T2 } = other;
9663
+ const A = mod$2((Y1 - X1) * (Y2 + X2));
9664
+ const B = mod$2((Y1 + X1) * (Y2 - X2));
9665
+ const F = mod$2(B - A);
9666
+ if (F === _0n$8)
9667
+ return this.double();
9668
+ const C = mod$2(Z1 * _2n$6 * T2);
9669
+ const D = mod$2(T1 * _2n$6 * Z2);
9670
+ const E = D + C;
9671
+ const G = B + A;
9672
+ const H = D - C;
9673
+ const X3 = mod$2(E * F);
9674
+ const Y3 = mod$2(G * H);
9675
+ const T3 = mod$2(E * H);
9676
+ const Z3 = mod$2(F * G);
9677
+ return new ExtendedPoint(X3, Y3, Z3, T3);
9678
+ }
9679
+ subtract(other) {
9680
+ return this.add(other.negate());
9681
+ }
9682
+ precomputeWindow(W) {
9683
+ const windows = 1 + 256 / W;
9684
+ const points = [];
9685
+ let p = this;
9686
+ let base = p;
9687
+ for (let window = 0; window < windows; window++) {
9688
+ base = p;
9689
+ points.push(base);
9690
+ for (let i = 1; i < 2 ** (W - 1); i++) {
9691
+ base = base.add(p);
9692
+ points.push(base);
9693
+ }
9694
+ p = base.double();
9695
+ }
9696
+ return points;
9697
+ }
9698
+ wNAF(n, affinePoint) {
9699
+ if (!affinePoint && this.equals(ExtendedPoint.BASE))
9700
+ affinePoint = Point.BASE;
9701
+ const W = (affinePoint && affinePoint._WINDOW_SIZE) || 1;
9702
+ if (256 % W) {
9703
+ throw new Error('Point#wNAF: Invalid precomputation window, must be power of 2');
9704
+ }
9705
+ let precomputes = affinePoint && pointPrecomputes.get(affinePoint);
9706
+ if (!precomputes) {
9707
+ precomputes = this.precomputeWindow(W);
9708
+ if (affinePoint && W !== 1) {
9709
+ precomputes = ExtendedPoint.normalizeZ(precomputes);
9710
+ pointPrecomputes.set(affinePoint, precomputes);
9711
+ }
9712
+ }
9713
+ let p = ExtendedPoint.ZERO;
9714
+ let f = ExtendedPoint.BASE;
9715
+ const windows = 1 + 256 / W;
9716
+ const windowSize = 2 ** (W - 1);
9717
+ const mask = BigInt(2 ** W - 1);
9718
+ const maxNumber = 2 ** W;
9719
+ const shiftBy = BigInt(W);
9720
+ for (let window = 0; window < windows; window++) {
9721
+ const offset = window * windowSize;
9722
+ let wbits = Number(n & mask);
9723
+ n >>= shiftBy;
9724
+ if (wbits > windowSize) {
9725
+ wbits -= maxNumber;
9726
+ n += _1n$a;
9727
+ }
9728
+ const offset1 = offset;
9729
+ const offset2 = offset + Math.abs(wbits) - 1;
9730
+ const cond1 = window % 2 !== 0;
9731
+ const cond2 = wbits < 0;
9732
+ if (wbits === 0) {
9733
+ f = f.add(constTimeNegate(cond1, precomputes[offset1]));
9734
+ }
9735
+ else {
9736
+ p = p.add(constTimeNegate(cond2, precomputes[offset2]));
9737
+ }
9738
+ }
9739
+ return ExtendedPoint.normalizeZ([p, f])[0];
9740
+ }
9741
+ multiply(scalar, affinePoint) {
9742
+ return this.wNAF(normalizeScalar(scalar, CURVE$1.l), affinePoint);
9743
+ }
9744
+ multiplyUnsafe(scalar) {
9745
+ let n = normalizeScalar(scalar, CURVE$1.l, false);
9746
+ const G = ExtendedPoint.BASE;
9747
+ const P0 = ExtendedPoint.ZERO;
9748
+ if (n === _0n$8)
9749
+ return P0;
9750
+ if (this.equals(P0) || n === _1n$a)
9751
+ return this;
9752
+ if (this.equals(G))
9753
+ return this.wNAF(n);
9754
+ let p = P0;
9755
+ let d = this;
9756
+ while (n > _0n$8) {
9757
+ if (n & _1n$a)
9758
+ p = p.add(d);
9759
+ d = d.double();
9760
+ n >>= _1n$a;
9761
+ }
9762
+ return p;
9763
+ }
9764
+ isSmallOrder() {
9765
+ return this.multiplyUnsafe(CURVE$1.h).equals(ExtendedPoint.ZERO);
9766
+ }
9767
+ isTorsionFree() {
9768
+ let p = this.multiplyUnsafe(CURVE$1.l / _2n$6).double();
9769
+ if (CURVE$1.l % _2n$6)
9770
+ p = p.add(this);
9771
+ return p.equals(ExtendedPoint.ZERO);
9772
+ }
9773
+ toAffine(invZ) {
9774
+ const { x, y, z } = this;
9775
+ const is0 = this.equals(ExtendedPoint.ZERO);
9776
+ if (invZ == null)
9777
+ invZ = is0 ? _8n$2 : invert$1(z);
9778
+ const ax = mod$2(x * invZ);
9779
+ const ay = mod$2(y * invZ);
9780
+ const zz = mod$2(z * invZ);
9781
+ if (is0)
9782
+ return Point.ZERO;
9783
+ if (zz !== _1n$a)
9784
+ throw new Error('invZ was invalid');
9785
+ return new Point(ax, ay);
9786
+ }
9787
+ fromRistrettoBytes() {
9788
+ legacyRist();
9789
+ }
9790
+ toRistrettoBytes() {
9791
+ legacyRist();
9792
+ }
9793
+ fromRistrettoHash() {
9794
+ legacyRist();
9795
+ }
9796
+ }
9797
+ ExtendedPoint.BASE = new ExtendedPoint(CURVE$1.Gx, CURVE$1.Gy, _1n$a, mod$2(CURVE$1.Gx * CURVE$1.Gy));
9798
+ ExtendedPoint.ZERO = new ExtendedPoint(_0n$8, _1n$a, _1n$a, _0n$8);
9799
+ function constTimeNegate(condition, item) {
9800
+ const neg = item.negate();
9801
+ return condition ? neg : item;
9802
+ }
9803
+ function assertExtPoint(other) {
9804
+ if (!(other instanceof ExtendedPoint))
9805
+ throw new TypeError('ExtendedPoint expected');
9806
+ }
9807
+ function assertRstPoint(other) {
9808
+ if (!(other instanceof RistrettoPoint))
9809
+ throw new TypeError('RistrettoPoint expected');
9810
+ }
9811
+ function legacyRist() {
9812
+ throw new Error('Legacy method: switch to RistrettoPoint');
9813
+ }
9814
+ class RistrettoPoint {
9815
+ constructor(ep) {
9816
+ this.ep = ep;
9817
+ }
9818
+ static calcElligatorRistrettoMap(r0) {
9819
+ const { d } = CURVE$1;
9820
+ const r = mod$2(SQRT_M1 * r0 * r0);
9821
+ const Ns = mod$2((r + _1n$a) * ONE_MINUS_D_SQ);
9822
+ let c = BigInt(-1);
9823
+ const D = mod$2((c - d * r) * mod$2(r + d));
9824
+ let { isValid: Ns_D_is_sq, value: s } = uvRatio$1(Ns, D);
9825
+ let s_ = mod$2(s * r0);
9826
+ if (!edIsNegative(s_))
9827
+ s_ = mod$2(-s_);
9828
+ if (!Ns_D_is_sq)
9829
+ s = s_;
9830
+ if (!Ns_D_is_sq)
9831
+ c = r;
9832
+ const Nt = mod$2(c * (r - _1n$a) * D_MINUS_ONE_SQ - D);
9833
+ const s2 = s * s;
9834
+ const W0 = mod$2((s + s) * D);
9835
+ const W1 = mod$2(Nt * SQRT_AD_MINUS_ONE);
9836
+ const W2 = mod$2(_1n$a - s2);
9837
+ const W3 = mod$2(_1n$a + s2);
9838
+ return new ExtendedPoint(mod$2(W0 * W3), mod$2(W2 * W1), mod$2(W1 * W3), mod$2(W0 * W2));
9839
+ }
9840
+ static hashToCurve(hex) {
9841
+ hex = ensureBytes$1(hex, 64);
9842
+ const r1 = bytes255ToNumberLE(hex.slice(0, 32));
9843
+ const R1 = this.calcElligatorRistrettoMap(r1);
9844
+ const r2 = bytes255ToNumberLE(hex.slice(32, 64));
9845
+ const R2 = this.calcElligatorRistrettoMap(r2);
9846
+ return new RistrettoPoint(R1.add(R2));
9847
+ }
9848
+ static fromHex(hex) {
9849
+ hex = ensureBytes$1(hex, 32);
9850
+ const { a, d } = CURVE$1;
9851
+ const emsg = 'RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint';
9852
+ const s = bytes255ToNumberLE(hex);
9853
+ if (!equalBytes$1(numberTo32BytesLE(s), hex) || edIsNegative(s))
9854
+ throw new Error(emsg);
9855
+ const s2 = mod$2(s * s);
9856
+ const u1 = mod$2(_1n$a + a * s2);
9857
+ const u2 = mod$2(_1n$a - a * s2);
9858
+ const u1_2 = mod$2(u1 * u1);
9859
+ const u2_2 = mod$2(u2 * u2);
9860
+ const v = mod$2(a * d * u1_2 - u2_2);
9861
+ const { isValid, value: I } = invertSqrt(mod$2(v * u2_2));
9862
+ const Dx = mod$2(I * u2);
9863
+ const Dy = mod$2(I * Dx * v);
9864
+ let x = mod$2((s + s) * Dx);
9865
+ if (edIsNegative(x))
9866
+ x = mod$2(-x);
9867
+ const y = mod$2(u1 * Dy);
9868
+ const t = mod$2(x * y);
9869
+ if (!isValid || edIsNegative(t) || y === _0n$8)
9870
+ throw new Error(emsg);
9871
+ return new RistrettoPoint(new ExtendedPoint(x, y, _1n$a, t));
9872
+ }
9873
+ toRawBytes() {
9874
+ let { x, y, z, t } = this.ep;
9875
+ const u1 = mod$2(mod$2(z + y) * mod$2(z - y));
9876
+ const u2 = mod$2(x * y);
9877
+ const u2sq = mod$2(u2 * u2);
9878
+ const { value: invsqrt } = invertSqrt(mod$2(u1 * u2sq));
9879
+ const D1 = mod$2(invsqrt * u1);
9880
+ const D2 = mod$2(invsqrt * u2);
9881
+ const zInv = mod$2(D1 * D2 * t);
9882
+ let D;
9883
+ if (edIsNegative(t * zInv)) {
9884
+ let _x = mod$2(y * SQRT_M1);
9885
+ let _y = mod$2(x * SQRT_M1);
9886
+ x = _x;
9887
+ y = _y;
9888
+ D = mod$2(D1 * INVSQRT_A_MINUS_D);
9889
+ }
9890
+ else {
9891
+ D = D2;
9892
+ }
9893
+ if (edIsNegative(x * zInv))
9894
+ y = mod$2(-y);
9895
+ let s = mod$2((z - y) * D);
9896
+ if (edIsNegative(s))
9897
+ s = mod$2(-s);
9898
+ return numberTo32BytesLE(s);
9899
+ }
9900
+ toHex() {
9901
+ return bytesToHex$1(this.toRawBytes());
9902
+ }
9903
+ toString() {
9904
+ return this.toHex();
9905
+ }
9906
+ equals(other) {
9907
+ assertRstPoint(other);
9908
+ const a = this.ep;
9909
+ const b = other.ep;
9910
+ const one = mod$2(a.x * b.y) === mod$2(a.y * b.x);
9911
+ const two = mod$2(a.y * b.y) === mod$2(a.x * b.x);
9912
+ return one || two;
9913
+ }
9914
+ add(other) {
9915
+ assertRstPoint(other);
9916
+ return new RistrettoPoint(this.ep.add(other.ep));
9917
+ }
9918
+ subtract(other) {
9919
+ assertRstPoint(other);
9920
+ return new RistrettoPoint(this.ep.subtract(other.ep));
9921
+ }
9922
+ multiply(scalar) {
9923
+ return new RistrettoPoint(this.ep.multiply(scalar));
9924
+ }
9925
+ multiplyUnsafe(scalar) {
9926
+ return new RistrettoPoint(this.ep.multiplyUnsafe(scalar));
9927
+ }
9928
+ }
9929
+ RistrettoPoint.BASE = new RistrettoPoint(ExtendedPoint.BASE);
9930
+ RistrettoPoint.ZERO = new RistrettoPoint(ExtendedPoint.ZERO);
9931
+ const pointPrecomputes = new WeakMap();
9932
+ class Point {
9933
+ constructor(x, y) {
9934
+ this.x = x;
9935
+ this.y = y;
9936
+ }
9937
+ _setWindowSize(windowSize) {
9938
+ this._WINDOW_SIZE = windowSize;
9939
+ pointPrecomputes.delete(this);
9940
+ }
9941
+ static fromHex(hex, strict = true) {
9942
+ const { d, P } = CURVE$1;
9943
+ hex = ensureBytes$1(hex, 32);
9944
+ const normed = hex.slice();
9945
+ normed[31] = hex[31] & ~0x80;
9946
+ const y = bytesToNumberLE$1(normed);
9947
+ if (strict && y >= P)
9948
+ throw new Error('Expected 0 < hex < P');
9949
+ if (!strict && y >= POW_2_256)
9950
+ throw new Error('Expected 0 < hex < 2**256');
9951
+ const y2 = mod$2(y * y);
9952
+ const u = mod$2(y2 - _1n$a);
9953
+ const v = mod$2(d * y2 + _1n$a);
9954
+ let { isValid, value: x } = uvRatio$1(u, v);
9955
+ if (!isValid)
9956
+ throw new Error('Point.fromHex: invalid y coordinate');
9957
+ const isXOdd = (x & _1n$a) === _1n$a;
9958
+ const isLastByteOdd = (hex[31] & 0x80) !== 0;
9959
+ if (isLastByteOdd !== isXOdd) {
9960
+ x = mod$2(-x);
9961
+ }
9962
+ return new Point(x, y);
9963
+ }
9964
+ static async fromPrivateKey(privateKey) {
9965
+ return (await getExtendedPublicKey(privateKey)).point;
9966
+ }
9967
+ toRawBytes() {
9968
+ const bytes = numberTo32BytesLE(this.y);
9969
+ bytes[31] |= this.x & _1n$a ? 0x80 : 0;
9970
+ return bytes;
9971
+ }
9972
+ toHex() {
9973
+ return bytesToHex$1(this.toRawBytes());
9974
+ }
9975
+ toX25519() {
9976
+ const { y } = this;
9977
+ const u = mod$2((_1n$a + y) * invert$1(_1n$a - y));
9978
+ return numberTo32BytesLE(u);
9979
+ }
9980
+ isTorsionFree() {
9981
+ return ExtendedPoint.fromAffine(this).isTorsionFree();
9982
+ }
9983
+ equals(other) {
9984
+ return this.x === other.x && this.y === other.y;
9985
+ }
9986
+ negate() {
9987
+ return new Point(mod$2(-this.x), this.y);
9988
+ }
9989
+ add(other) {
9990
+ return ExtendedPoint.fromAffine(this).add(ExtendedPoint.fromAffine(other)).toAffine();
9991
+ }
9992
+ subtract(other) {
9993
+ return this.add(other.negate());
9994
+ }
9995
+ multiply(scalar) {
9996
+ return ExtendedPoint.fromAffine(this).multiply(scalar, this).toAffine();
9997
+ }
9998
+ }
9999
+ Point.BASE = new Point(CURVE$1.Gx, CURVE$1.Gy);
10000
+ Point.ZERO = new Point(_0n$8, _1n$a);
10001
+ let Signature$1 = class Signature {
10002
+ constructor(r, s) {
10003
+ this.r = r;
10004
+ this.s = s;
10005
+ this.assertValidity();
10006
+ }
10007
+ static fromHex(hex) {
10008
+ const bytes = ensureBytes$1(hex, 64);
10009
+ const r = Point.fromHex(bytes.slice(0, 32), false);
10010
+ const s = bytesToNumberLE$1(bytes.slice(32, 64));
10011
+ return new Signature(r, s);
10012
+ }
10013
+ assertValidity() {
10014
+ const { r, s } = this;
10015
+ if (!(r instanceof Point))
10016
+ throw new Error('Expected Point instance');
10017
+ normalizeScalar(s, CURVE$1.l, false);
10018
+ return this;
10019
+ }
10020
+ toRawBytes() {
10021
+ const u8 = new Uint8Array(64);
10022
+ u8.set(this.r.toRawBytes());
10023
+ u8.set(numberTo32BytesLE(this.s), 32);
10024
+ return u8;
10025
+ }
10026
+ toHex() {
10027
+ return bytesToHex$1(this.toRawBytes());
10028
+ }
10029
+ };
10030
+ function concatBytes$2(...arrays) {
10031
+ if (!arrays.every((a) => a instanceof Uint8Array))
10032
+ throw new Error('Expected Uint8Array list');
10033
+ if (arrays.length === 1)
10034
+ return arrays[0];
10035
+ const length = arrays.reduce((a, arr) => a + arr.length, 0);
10036
+ const result = new Uint8Array(length);
10037
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
10038
+ const arr = arrays[i];
10039
+ result.set(arr, pad);
10040
+ pad += arr.length;
10041
+ }
10042
+ return result;
10043
+ }
10044
+ const hexes$1 = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
10045
+ function bytesToHex$1(uint8a) {
10046
+ if (!(uint8a instanceof Uint8Array))
10047
+ throw new Error('Uint8Array expected');
10048
+ let hex = '';
10049
+ for (let i = 0; i < uint8a.length; i++) {
10050
+ hex += hexes$1[uint8a[i]];
10051
+ }
10052
+ return hex;
10053
+ }
10054
+ function hexToBytes$1(hex) {
10055
+ if (typeof hex !== 'string') {
10056
+ throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
10057
+ }
10058
+ if (hex.length % 2)
10059
+ throw new Error('hexToBytes: received invalid unpadded hex');
10060
+ const array = new Uint8Array(hex.length / 2);
10061
+ for (let i = 0; i < array.length; i++) {
10062
+ const j = i * 2;
10063
+ const hexByte = hex.slice(j, j + 2);
10064
+ const byte = Number.parseInt(hexByte, 16);
10065
+ if (Number.isNaN(byte) || byte < 0)
10066
+ throw new Error('Invalid byte sequence');
10067
+ array[i] = byte;
10068
+ }
10069
+ return array;
10070
+ }
10071
+ function numberTo32BytesBE(num) {
10072
+ const length = 32;
10073
+ const hex = num.toString(16).padStart(length * 2, '0');
10074
+ return hexToBytes$1(hex);
10075
+ }
10076
+ function numberTo32BytesLE(num) {
10077
+ return numberTo32BytesBE(num).reverse();
10078
+ }
10079
+ function edIsNegative(num) {
10080
+ return (mod$2(num) & _1n$a) === _1n$a;
10081
+ }
10082
+ function bytesToNumberLE$1(uint8a) {
10083
+ if (!(uint8a instanceof Uint8Array))
10084
+ throw new Error('Expected Uint8Array');
10085
+ return BigInt('0x' + bytesToHex$1(Uint8Array.from(uint8a).reverse()));
10086
+ }
10087
+ const MAX_255B = BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
10088
+ function bytes255ToNumberLE(bytes) {
10089
+ return mod$2(bytesToNumberLE$1(bytes) & MAX_255B);
10090
+ }
10091
+ function mod$2(a, b = CURVE$1.P) {
10092
+ const res = a % b;
10093
+ return res >= _0n$8 ? res : b + res;
10094
+ }
10095
+ function invert$1(number, modulo = CURVE$1.P) {
10096
+ if (number === _0n$8 || modulo <= _0n$8) {
10097
+ throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
10098
+ }
10099
+ let a = mod$2(number, modulo);
10100
+ let b = modulo;
10101
+ let x = _0n$8, u = _1n$a;
10102
+ while (a !== _0n$8) {
10103
+ const q = b / a;
10104
+ const r = b % a;
10105
+ const m = x - u * q;
10106
+ b = a, a = r, x = u, u = m;
10107
+ }
10108
+ const gcd = b;
10109
+ if (gcd !== _1n$a)
10110
+ throw new Error('invert: does not exist');
10111
+ return mod$2(x, modulo);
10112
+ }
10113
+ function invertBatch(nums, p = CURVE$1.P) {
10114
+ const tmp = new Array(nums.length);
10115
+ const lastMultiplied = nums.reduce((acc, num, i) => {
10116
+ if (num === _0n$8)
10117
+ return acc;
10118
+ tmp[i] = acc;
10119
+ return mod$2(acc * num, p);
10120
+ }, _1n$a);
10121
+ const inverted = invert$1(lastMultiplied, p);
10122
+ nums.reduceRight((acc, num, i) => {
10123
+ if (num === _0n$8)
10124
+ return acc;
10125
+ tmp[i] = mod$2(acc * tmp[i], p);
10126
+ return mod$2(acc * num, p);
10127
+ }, inverted);
10128
+ return tmp;
10129
+ }
10130
+ function pow2$1(x, power) {
10131
+ const { P } = CURVE$1;
10132
+ let res = x;
10133
+ while (power-- > _0n$8) {
10134
+ res *= res;
10135
+ res %= P;
10136
+ }
10137
+ return res;
10138
+ }
10139
+ function pow_2_252_3(x) {
10140
+ const { P } = CURVE$1;
10141
+ const _5n = BigInt(5);
10142
+ const _10n = BigInt(10);
10143
+ const _20n = BigInt(20);
10144
+ const _40n = BigInt(40);
10145
+ const _80n = BigInt(80);
10146
+ const x2 = (x * x) % P;
10147
+ const b2 = (x2 * x) % P;
10148
+ const b4 = (pow2$1(b2, _2n$6) * b2) % P;
10149
+ const b5 = (pow2$1(b4, _1n$a) * x) % P;
10150
+ const b10 = (pow2$1(b5, _5n) * b5) % P;
10151
+ const b20 = (pow2$1(b10, _10n) * b10) % P;
10152
+ const b40 = (pow2$1(b20, _20n) * b20) % P;
10153
+ const b80 = (pow2$1(b40, _40n) * b40) % P;
10154
+ const b160 = (pow2$1(b80, _80n) * b80) % P;
10155
+ const b240 = (pow2$1(b160, _80n) * b80) % P;
10156
+ const b250 = (pow2$1(b240, _10n) * b10) % P;
10157
+ const pow_p_5_8 = (pow2$1(b250, _2n$6) * x) % P;
10158
+ return { pow_p_5_8, b2 };
10159
+ }
10160
+ function uvRatio$1(u, v) {
10161
+ const v3 = mod$2(v * v * v);
10162
+ const v7 = mod$2(v3 * v3 * v);
10163
+ const pow = pow_2_252_3(u * v7).pow_p_5_8;
10164
+ let x = mod$2(u * v3 * pow);
10165
+ const vx2 = mod$2(v * x * x);
10166
+ const root1 = x;
10167
+ const root2 = mod$2(x * SQRT_M1);
10168
+ const useRoot1 = vx2 === u;
10169
+ const useRoot2 = vx2 === mod$2(-u);
10170
+ const noRoot = vx2 === mod$2(-u * SQRT_M1);
10171
+ if (useRoot1)
10172
+ x = root1;
10173
+ if (useRoot2 || noRoot)
10174
+ x = root2;
10175
+ if (edIsNegative(x))
10176
+ x = mod$2(-x);
10177
+ return { isValid: useRoot1 || useRoot2, value: x };
10178
+ }
10179
+ function invertSqrt(number) {
10180
+ return uvRatio$1(_1n$a, number);
10181
+ }
10182
+ function modlLE(hash) {
10183
+ return mod$2(bytesToNumberLE$1(hash), CURVE$1.l);
10184
+ }
10185
+ function equalBytes$1(b1, b2) {
10186
+ if (b1.length !== b2.length) {
10187
+ return false;
10188
+ }
10189
+ for (let i = 0; i < b1.length; i++) {
10190
+ if (b1[i] !== b2[i]) {
10191
+ return false;
10192
+ }
10193
+ }
10194
+ return true;
10195
+ }
10196
+ function ensureBytes$1(hex, expectedLength) {
10197
+ const bytes = hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes$1(hex);
10198
+ if (typeof expectedLength === 'number' && bytes.length !== expectedLength)
10199
+ throw new Error(`Expected ${expectedLength} bytes`);
10200
+ return bytes;
10201
+ }
10202
+ function normalizeScalar(num, max, strict = true) {
10203
+ if (!max)
10204
+ throw new TypeError('Specify max value');
10205
+ if (typeof num === 'number' && Number.isSafeInteger(num))
10206
+ num = BigInt(num);
10207
+ if (typeof num === 'bigint' && num < max) {
10208
+ if (strict) {
10209
+ if (_0n$8 < num)
10210
+ return num;
10211
+ }
10212
+ else {
10213
+ if (_0n$8 <= num)
10214
+ return num;
10215
+ }
10216
+ }
10217
+ throw new TypeError('Expected valid scalar: 0 < scalar < max');
10218
+ }
10219
+ function adjustBytes25519(bytes) {
10220
+ bytes[0] &= 248;
10221
+ bytes[31] &= 127;
10222
+ bytes[31] |= 64;
10223
+ return bytes;
10224
+ }
10225
+ function checkPrivateKey(key) {
10226
+ key =
10227
+ typeof key === 'bigint' || typeof key === 'number'
10228
+ ? numberTo32BytesBE(normalizeScalar(key, POW_2_256))
10229
+ : ensureBytes$1(key);
10230
+ if (key.length !== 32)
10231
+ throw new Error(`Expected 32 bytes`);
10232
+ return key;
10233
+ }
10234
+ function getKeyFromHash(hashed) {
10235
+ const head = adjustBytes25519(hashed.slice(0, 32));
10236
+ const prefix = hashed.slice(32, 64);
10237
+ const scalar = modlLE(head);
10238
+ const point = Point.BASE.multiply(scalar);
10239
+ const pointBytes = point.toRawBytes();
10240
+ return { head, prefix, scalar, point, pointBytes };
10241
+ }
10242
+ let _sha512Sync;
10243
+ async function getExtendedPublicKey(key) {
10244
+ return getKeyFromHash(await utils.sha512(checkPrivateKey(key)));
10245
+ }
10246
+ function prepareVerification(sig, message, publicKey) {
10247
+ message = ensureBytes$1(message);
10248
+ if (!(publicKey instanceof Point))
10249
+ publicKey = Point.fromHex(publicKey, false);
10250
+ const { r, s } = sig instanceof Signature$1 ? sig.assertValidity() : Signature$1.fromHex(sig);
10251
+ const SB = ExtendedPoint.BASE.multiplyUnsafe(s);
10252
+ return { r, s, SB, pub: publicKey, msg: message };
10253
+ }
10254
+ function finishVerification(publicKey, r, SB, hashed) {
10255
+ const k = modlLE(hashed);
10256
+ const kA = ExtendedPoint.fromAffine(publicKey).multiplyUnsafe(k);
10257
+ const RkA = ExtendedPoint.fromAffine(r).add(kA);
10258
+ return RkA.subtract(SB).multiplyUnsafe(CURVE$1.h).equals(ExtendedPoint.ZERO);
10259
+ }
10260
+ async function verify$6(sig, message, publicKey) {
10261
+ const { r, SB, msg, pub } = prepareVerification(sig, message, publicKey);
10262
+ const hashed = await utils.sha512(r.toRawBytes(), pub.toRawBytes(), msg);
10263
+ return finishVerification(pub, r, SB, hashed);
10264
+ }
10265
+ Point.BASE._setWindowSize(8);
10266
+ const crypto$3 = {
10267
+ node: nodeCrypto$b,
10268
+ web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,
10269
+ };
10270
+ const utils = {
10271
+ bytesToHex: bytesToHex$1,
10272
+ hexToBytes: hexToBytes$1,
10273
+ concatBytes: concatBytes$2,
10274
+ getExtendedPublicKey,
10275
+ mod: mod$2,
10276
+ invert: invert$1,
10277
+ TORSION_SUBGROUP: [
10278
+ '0100000000000000000000000000000000000000000000000000000000000000',
10279
+ 'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
10280
+ '0000000000000000000000000000000000000000000000000000000000000080',
10281
+ '26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05',
10282
+ 'ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f',
10283
+ '26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85',
10284
+ '0000000000000000000000000000000000000000000000000000000000000000',
10285
+ 'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
10286
+ ],
10287
+ hashToPrivateScalar: (hash) => {
10288
+ hash = ensureBytes$1(hash);
10289
+ if (hash.length < 40 || hash.length > 1024)
10290
+ throw new Error('Expected 40-1024 bytes of private key as per FIPS 186');
10291
+ return mod$2(bytesToNumberLE$1(hash), CURVE$1.l - _1n$a) + _1n$a;
10292
+ },
10293
+ randomBytes: (bytesLength = 32) => {
10294
+ if (crypto$3.web) {
10295
+ return crypto$3.web.getRandomValues(new Uint8Array(bytesLength));
10296
+ }
10297
+ else if (crypto$3.node) {
10298
+ const { randomBytes } = crypto$3.node;
10299
+ return new Uint8Array(randomBytes(bytesLength).buffer);
10300
+ }
10301
+ else {
10302
+ throw new Error("The environment doesn't have randomBytes function");
10303
+ }
10304
+ },
10305
+ randomPrivateKey: () => {
10306
+ return utils.randomBytes(32);
10307
+ },
10308
+ sha512: async (...messages) => {
10309
+ const message = concatBytes$2(...messages);
10310
+ if (crypto$3.web) {
10311
+ const buffer = await crypto$3.web.subtle.digest('SHA-512', message.buffer);
10312
+ return new Uint8Array(buffer);
10313
+ }
10314
+ else if (crypto$3.node) {
10315
+ return Uint8Array.from(crypto$3.node.createHash('sha512').update(message).digest());
10316
+ }
10317
+ else {
10318
+ throw new Error("The environment doesn't have sha512 function");
10319
+ }
10320
+ },
10321
+ precompute(windowSize = 8, point = Point.BASE) {
10322
+ const cached = point.equals(Point.BASE) ? point : new Point(point.x, point.y);
10323
+ cached._setWindowSize(windowSize);
10324
+ cached.multiply(_2n$6);
10325
+ return cached;
10326
+ },
10327
+ sha512Sync: undefined,
10328
+ };
10329
+ Object.defineProperties(utils, {
10330
+ sha512Sync: {
10331
+ configurable: false,
10332
+ get() {
10333
+ return _sha512Sync;
10334
+ },
10335
+ set(val) {
10336
+ if (!_sha512Sync)
10337
+ _sha512Sync = val;
10338
+ },
10339
+ },
9532
10340
  });
9533
10341
 
9534
10342
  // OpenPGP.js - An OpenPGP implementation in javascript
@@ -9564,6 +10372,8 @@ var ecdsa = /*#__PURE__*/Object.freeze({
9564
10372
  * @async
9565
10373
  */
9566
10374
  async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
10375
+ const curve = new CurveWithOID(oid);
10376
+ checkPublicPointEnconding(curve, publicKey);
9567
10377
  if (hash$1.getHashByteLength(hashAlgo) < hash$1.getHashByteLength(enums.hash.sha256)) {
9568
10378
  // see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
9569
10379
  throw new Error('Hash algorithm too weak for EdDSA.');
@@ -9590,11 +10400,13 @@ async function sign$5(oid, hashAlgo, message, publicKey, privateKey, hashed) {
9590
10400
  * @async
9591
10401
  */
9592
10402
  async function verify$5(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
10403
+ const curve = new CurveWithOID(oid);
10404
+ checkPublicPointEnconding(curve, publicKey);
9593
10405
  if (hash$1.getHashByteLength(hashAlgo) < hash$1.getHashByteLength(enums.hash.sha256)) {
9594
10406
  throw new Error('Hash algorithm too weak for EdDSA.');
9595
10407
  }
9596
10408
  const signature = util.concatUint8Array([r, s]);
9597
- return nacl.sign.detached.verify(hashed, signature, publicKey.subarray(1));
10409
+ return verify$6(signature, hashed, publicKey.subarray(1));
9598
10410
  }
9599
10411
  /**
9600
10412
  * Validate legacy EdDSA parameters
@@ -9720,7 +10532,7 @@ async function verify$4(algo, hashAlgo, { RS }, m, publicKey, hashed) {
9720
10532
  }
9721
10533
  switch (algo) {
9722
10534
  case enums.publicKey.ed25519:
9723
- return nacl.sign.detached.verify(hashed, RS, publicKey);
10535
+ return verify$6(RS, hashed, publicKey);
9724
10536
  case enums.publicKey.ed448: {
9725
10537
  const ed448 = await util.getNobleCurve(enums.publicKey.ed448);
9726
10538
  return ed448.verify(RS, hashed, publicKey);
@@ -10084,7 +10896,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) {
10084
10896
  new Uint8Array([public_algo]),
10085
10897
  kdfParams.write(true),
10086
10898
  util.stringToUint8Array('Anonymous Sender '),
10087
- kdfParams.replacementFingerprint || fingerprint.subarray(0, 20)
10899
+ kdfParams.replacementFingerprint || fingerprint
10088
10900
  ]);
10089
10901
  }
10090
10902
 
@@ -10126,7 +10938,7 @@ async function genPublicEphemeralKey(curve, Q) {
10126
10938
  const d = getRandomBytes(32);
10127
10939
  const { secretKey, sharedKey } = await genPrivateEphemeralKey(curve, Q, null, d);
10128
10940
  let { publicKey } = nacl.box.keyPair.fromSecretKey(secretKey);
10129
- publicKey = util.concatUint8Array([new Uint8Array([0x40]), publicKey]);
10941
+ publicKey = util.concatUint8Array([new Uint8Array([curve.wireFormatLeadingByte]), publicKey]);
10130
10942
  return { publicKey, sharedKey }; // Note: sharedKey is little-endian here, unlike below
10131
10943
  }
10132
10944
  case 'web':
@@ -10154,7 +10966,7 @@ async function genPublicEphemeralKey(curve, Q) {
10154
10966
  * @param {module:type/kdf_params} kdfParams - KDF params including cipher and algorithm to use
10155
10967
  * @param {Uint8Array} data - Unpadded session key data
10156
10968
  * @param {Uint8Array} Q - Recipient public key
10157
- * @param {Uint8Array} fingerprint - Recipient fingerprint
10969
+ * @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
10158
10970
  * @returns {Promise<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}
10159
10971
  * @async
10160
10972
  */
@@ -10162,6 +10974,7 @@ async function encrypt$2(oid, kdfParams, data, Q, fingerprint) {
10162
10974
  const m = encode(data);
10163
10975
 
10164
10976
  const curve = new CurveWithOID(oid);
10977
+ checkPublicPointEnconding(curve, Q);
10165
10978
  const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
10166
10979
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
10167
10980
  const { keySize } = getCipherParams(kdfParams.cipher);
@@ -10218,12 +11031,14 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
10218
11031
  * @param {Uint8Array} C - Encrypted and wrapped value derived from session key
10219
11032
  * @param {Uint8Array} Q - Recipient public key
10220
11033
  * @param {Uint8Array} d - Recipient private key
10221
- * @param {Uint8Array} fingerprint - Recipient fingerprint
11034
+ * @param {Uint8Array} fingerprint - Recipient fingerprint, already truncated depending on the key version
10222
11035
  * @returns {Promise<Uint8Array>} Value derived from session key.
10223
11036
  * @async
10224
11037
  */
10225
11038
  async function decrypt$2(oid, kdfParams, V, C, Q, d, fingerprint) {
10226
11039
  const curve = new CurveWithOID(oid);
11040
+ checkPublicPointEnconding(curve, Q);
11041
+ checkPublicPointEnconding(curve, V);
10227
11042
  const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
10228
11043
  const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
10229
11044
  const { keySize } = getCipherParams(kdfParams.cipher);
@@ -10355,7 +11170,7 @@ async function webPublicEphemeralKey(curve, Q) {
10355
11170
  );
10356
11171
  [s, p] = await Promise.all([s, p]);
10357
11172
  const sharedKey = new Uint8Array(s);
10358
- const publicKey = new Uint8Array(jwkToRawPublic(p));
11173
+ const publicKey = new Uint8Array(jwkToRawPublic(p, curve.wireFormatLeadingByte));
10359
11174
  return { publicKey, sharedKey };
10360
11175
  }
10361
11176
 
@@ -10678,14 +11493,14 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10678
11493
  let r;
10679
11494
  let s;
10680
11495
  let t;
10681
- g = mod$2(g, p);
10682
- x = mod$2(x, q);
11496
+ g = mod$3(g, p);
11497
+ x = mod$3(x, q);
10683
11498
  // If the output size of the chosen hash is larger than the number of
10684
11499
  // bits of q, the hash result is truncated to fit by taking the number
10685
11500
  // of leftmost bits equal to the number of bits of q. This (possibly
10686
11501
  // truncated) hash function result is treated as a number and used
10687
11502
  // directly in the DSA signature algorithm.
10688
- const h = mod$2(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
11503
+ const h = mod$3(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
10689
11504
  // FIPS-186-4, section 4.6:
10690
11505
  // The values of r and s shall be checked to determine if r = 0 or s = 0.
10691
11506
  // If either r = 0 or s = 0, a new value of k shall be generated, and the
@@ -10694,13 +11509,13 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
10694
11509
  while (true) {
10695
11510
  // See Appendix B here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
10696
11511
  k = getRandomBigInteger(_1n$9, q); // returns in [1, q-1]
10697
- r = mod$2(modExp(g, k, p), q); // (g**k mod p) mod q
11512
+ r = mod$3(modExp(g, k, p), q); // (g**k mod p) mod q
10698
11513
  if (r === _0n) {
10699
11514
  continue;
10700
11515
  }
10701
- const xr = mod$2(x * r, q);
10702
- t = mod$2(h + xr, q); // H(m) + x*r mod q
10703
- s = mod$2(modInv(k, q) * t, q); // k**-1 * (H(m) + x*r) mod q
11516
+ const xr = mod$3(x * r, q);
11517
+ t = mod$3(h + xr, q); // H(m) + x*r mod q
11518
+ s = mod$3(modInv(k, q) * t, q); // k**-1 * (H(m) + x*r) mod q
10704
11519
  if (s === _0n) {
10705
11520
  continue;
10706
11521
  }
@@ -10739,20 +11554,20 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
10739
11554
  util.printDebug('invalid DSA Signature');
10740
11555
  return false;
10741
11556
  }
10742
- const h = mod$2(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
11557
+ const h = mod$3(uint8ArrayToBigInt(hashed.subarray(0, byteLength(q))), q);
10743
11558
  const w = modInv(s, q); // s**-1 mod q
10744
11559
  if (w === _0n$7) {
10745
11560
  util.printDebug('invalid DSA Signature');
10746
11561
  return false;
10747
11562
  }
10748
11563
 
10749
- g = mod$2(g, p);
10750
- y = mod$2(y, p);
10751
- const u1 = mod$2(h * w, q); // H(m) * w mod q
10752
- const u2 = mod$2(r * w, q); // r * w mod q
11564
+ g = mod$3(g, p);
11565
+ y = mod$3(y, p);
11566
+ const u1 = mod$3(h * w, q); // H(m) * w mod q
11567
+ const u2 = mod$3(r * w, q); // r * w mod q
10753
11568
  const t1 = modExp(g, u1, p); // g**u1 mod p
10754
11569
  const t2 = modExp(y, u2, p); // y**u2 mod p
10755
- const v = mod$2(mod$2(t1 * t2, p), q); // (g**u1 * y**u2 mod p) mod q
11570
+ const v = mod$3(mod$3(t1 * t2, p), q); // (g**u1 * y**u2 mod p) mod q
10756
11571
  return v === r;
10757
11572
  }
10758
11573
 
@@ -10779,7 +11594,7 @@ async function validateParams$2(p, q, g, y, x) {
10779
11594
  /**
10780
11595
  * Check that subgroup order q divides p-1
10781
11596
  */
10782
- if (mod$2(p - _1n$9, q) !== _0n$7) {
11597
+ if (mod$3(p - _1n$9, q) !== _0n$7) {
10783
11598
  return false;
10784
11599
  }
10785
11600
 
@@ -11576,6 +12391,9 @@ function parsePublicKeyParams(algo, bytes) {
11576
12391
  case enums.publicKey.eddsaLegacy: {
11577
12392
  const oid = new OID(); read += oid.read(bytes);
11578
12393
  checkSupportedCurve(oid);
12394
+ if (oid.getName() !== enums.curve.ed25519Legacy) {
12395
+ throw new Error('Unexpected OID for eddsaLegacy');
12396
+ }
11579
12397
  let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
11580
12398
  Q = util.leftPad(Q, 33);
11581
12399
  return { read: read, publicParams: { oid, Q } };
@@ -11639,6 +12457,9 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
11639
12457
  }
11640
12458
  case enums.publicKey.eddsaLegacy: {
11641
12459
  const payloadSize = getCurvePayloadSize(algo, publicParams.oid);
12460
+ if (publicParams.oid.getName() !== enums.curve.ed25519Legacy) {
12461
+ throw new Error('Unexpected OID for eddsaLegacy');
12462
+ }
11642
12463
  let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
11643
12464
  seed = util.leftPad(seed, payloadSize);
11644
12465
  return { read, privateParams: { seed } };
@@ -14477,6 +15298,7 @@ class SignaturePacket {
14477
15298
 
14478
15299
  this.signatureData = null;
14479
15300
  this.unhashedSubpackets = [];
15301
+ this.unknownSubpackets = [];
14480
15302
  this.signedHashValue = null;
14481
15303
  this.salt = null;
14482
15304
 
@@ -14526,9 +15348,12 @@ class SignaturePacket {
14526
15348
  * @param {String} bytes - Payload of a tag 2 packet
14527
15349
  * @returns {SignaturePacket} Object representation.
14528
15350
  */
14529
- read(bytes) {
15351
+ read(bytes, config$1 = config) {
14530
15352
  let i = 0;
14531
15353
  this.version = bytes[i++];
15354
+ if (this.version === 5 && !config$1.enableParsingV5Entities) {
15355
+ throw new UnsupportedError('Support for v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
15356
+ }
14532
15357
 
14533
15358
  if (this.version !== 4 && this.version !== 5 && this.version !== 6) {
14534
15359
  throw new UnsupportedError(`Version ${this.version} of the signature packet is unsupported.`);
@@ -14805,10 +15630,8 @@ class SignaturePacket {
14805
15630
  * @returns {Uint8Array} Subpacket data.
14806
15631
  */
14807
15632
  writeUnhashedSubPackets() {
14808
- const arr = [];
14809
- this.unhashedSubpackets.forEach(data => {
14810
- arr.push(writeSimpleLength(data.length));
14811
- arr.push(data);
15633
+ const arr = this.unhashedSubpackets.map(({ type, critical, body }) => {
15634
+ return writeSubPacket(type, critical, body);
14812
15635
  });
14813
15636
 
14814
15637
  const result = util.concat(arr);
@@ -14817,7 +15640,7 @@ class SignaturePacket {
14817
15640
  return util.concat([length, result]);
14818
15641
  }
14819
15642
 
14820
- // V4 signature sub packets
15643
+ // Signature subpackets
14821
15644
  readSubPacket(bytes, hashed = true) {
14822
15645
  let mypos = 0;
14823
15646
 
@@ -14825,15 +15648,19 @@ class SignaturePacket {
14825
15648
  const critical = !!(bytes[mypos] & 0x80);
14826
15649
  const type = bytes[mypos] & 0x7F;
14827
15650
 
15651
+ mypos++;
15652
+
14828
15653
  if (!hashed) {
14829
- this.unhashedSubpackets.push(bytes.subarray(mypos, bytes.length));
15654
+ this.unhashedSubpackets.push({
15655
+ type,
15656
+ critical,
15657
+ body: bytes.subarray(mypos, bytes.length)
15658
+ });
14830
15659
  if (!allowedUnhashedSubpackets.has(type)) {
14831
15660
  return;
14832
15661
  }
14833
15662
  }
14834
15663
 
14835
- mypos++;
14836
-
14837
15664
  // subpacket type
14838
15665
  switch (type) {
14839
15666
  case enums.signatureSubpacket.signatureCreationTime:
@@ -15005,14 +15832,13 @@ class SignaturePacket {
15005
15832
  this.preferredCipherSuites.push([bytes[i], bytes[i + 1]]);
15006
15833
  }
15007
15834
  break;
15008
- default: {
15009
- const err = new Error(`Unknown signature subpacket type ${type}`);
15010
- if (critical) {
15011
- throw err;
15012
- } else {
15013
- util.printDebug(err);
15014
- }
15015
- }
15835
+ default:
15836
+ this.unknownSubpackets.push({
15837
+ type,
15838
+ critical,
15839
+ body: bytes.subarray(mypos, bytes.length)
15840
+ });
15841
+ break;
15016
15842
  }
15017
15843
  }
15018
15844
 
@@ -15212,6 +16038,11 @@ class SignaturePacket {
15212
16038
  [enums.signature.binary, enums.signature.text].includes(this.signatureType)) {
15213
16039
  throw new Error('Insecure message hash algorithm: ' + enums.read(enums.hash, this.hashAlgorithm).toUpperCase());
15214
16040
  }
16041
+ this.unknownSubpackets.forEach(({ type, critical }) => {
16042
+ if (critical) {
16043
+ throw new Error(`Unknown critical signature subpacket type ${type}`);
16044
+ }
16045
+ });
15215
16046
  this.rawNotations.forEach(({ name, critical }) => {
15216
16047
  if (critical && (config$1.knownNotations.indexOf(name) < 0)) {
15217
16048
  throw new Error(`Unknown critical notation: ${name}`);
@@ -16511,10 +17342,11 @@ class PublicKeyEncryptedSessionKeyPacket {
16511
17342
  // No symmetric encryption algorithm identifier is passed to the public-key algorithm for a
16512
17343
  // v6 PKESK packet, as it is included in the v2 SEIPD packet.
16513
17344
  const sessionKeyAlgorithm = this.version === 3 ? this.sessionKeyAlgorithm : null;
17345
+ const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
16514
17346
  const encoded = encodeSessionKey(this.version, algo, sessionKeyAlgorithm, this.sessionKey);
16515
17347
  const privateParams = algo === enums.publicKey.aead ? key.privateParams : null;
16516
17348
  this.encrypted = await mod$1.publicKeyEncrypt(
16517
- algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded, key.getFingerprintBytes());
17349
+ algo, sessionKeyAlgorithm, key.publicParams, privateParams, encoded, fingerprint);
16518
17350
  }
16519
17351
 
16520
17352
  /**
@@ -16534,7 +17366,8 @@ class PublicKeyEncryptedSessionKeyPacket {
16534
17366
  const randomPayload = randomSessionKey ?
16535
17367
  encodeSessionKey(this.version, this.publicKeyAlgorithm, randomSessionKey.sessionKeyAlgorithm, randomSessionKey.sessionKey) :
16536
17368
  null;
16537
- const decryptedData = await mod$1.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
17369
+ const fingerprint = key.version === 5 ? key.getFingerprintBytes().subarray(0, 20) : key.getFingerprintBytes();
17370
+ const decryptedData = await mod$1.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, fingerprint, randomPayload);
16538
17371
 
16539
17372
  const { sessionKey, sessionKeyAlgorithm } = decodeSessionKey(this.version, this.publicKeyAlgorithm, decryptedData, randomSessionKey);
16540
17373
 
@@ -16939,10 +17772,13 @@ class PublicKeyPacket {
16939
17772
  * @returns {Object} This object with attributes set by the parser
16940
17773
  * @async
16941
17774
  */
16942
- async read(bytes) {
17775
+ async read(bytes, config$1 = config) {
16943
17776
  let pos = 0;
16944
17777
  // A one-octet version number (4, 5 or 6).
16945
17778
  this.version = bytes[pos++];
17779
+ if (this.version === 5 && !config$1.enableParsingV5Entities) {
17780
+ throw new UnsupportedError('Support for parsing v5 entities is disabled; turn on `config.enableParsingV5Entities` if needed');
17781
+ }
16946
17782
 
16947
17783
  if (this.version === 4 || this.version === 5 || this.version === 6) {
16948
17784
  // - A four-octet number denoting the time that the key was created.
@@ -17534,7 +18370,7 @@ class SecretKeyPacket extends PublicKeyPacket {
17534
18370
  */
17535
18371
  async read(bytes, config$1 = config) {
17536
18372
  // - A Public-Key or Public-Subkey packet, as described above.
17537
- let i = await this.readPublicKey(bytes);
18373
+ let i = await this.readPublicKey(bytes, config$1);
17538
18374
  const startOfSecretKeyData = i;
17539
18375
 
17540
18376
  // - One octet indicating string-to-key usage conventions. Zero
@@ -17824,13 +18660,13 @@ class SecretKeyPacket extends PublicKeyPacket {
17824
18660
 
17825
18661
  if (config$1.aeadProtect) {
17826
18662
  this.s2kUsage = 253;
17827
- this.aead = enums.aead.eax;
18663
+ this.aead = config$1.preferredAEADAlgorithm;
17828
18664
  const mode = mod$1.getAEADMode(this.aead);
17829
18665
  this.isLegacyAEAD = this.version === 5; // v4 is always re-encrypted with standard format instead.
17830
18666
  this.usedModernAEAD = !this.isLegacyAEAD; // legacy AEAD does not guarantee integrity of public key material
17831
18667
 
17832
18668
  const serializedPacketTag = writeTag(this.constructor.tag);
17833
- const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag);
18669
+ const key = await produceEncryptionKey(this.version, this.s2k, passphrase, this.symmetric, this.aead, serializedPacketTag, this.isLegacyAEAD);
17834
18670
 
17835
18671
  const modeInstance = await mode(this.symmetric, key);
17836
18672
  this.iv = this.isLegacyAEAD ? mod$1.random.getRandomBytes(blockSize) : mod$1.random.getRandomBytes(mode.ivLength);
@@ -18000,6 +18836,12 @@ class SecretKeyPacket extends PublicKeyPacket {
18000
18836
  * @returns encryption key
18001
18837
  */
18002
18838
  async function produceEncryptionKey(keyVersion, s2k, passphrase, cipherAlgo, aeadMode, serializedPacketTag, isLegacyAEAD) {
18839
+ if (s2k.type === 'argon2' && !aeadMode) {
18840
+ throw new Error('Using Argon2 S2K without AEAD is not allowed');
18841
+ }
18842
+ if (s2k.type === 'simple' && keyVersion === 6) {
18843
+ throw new Error('Using Simple S2K with version 6 keys is not allowed');
18844
+ }
18003
18845
  const { keySize } = mod$1.getCipherParams(cipherAlgo);
18004
18846
  const derivedKey = await s2k.produceKey(passphrase, keySize);
18005
18847
  if (!aeadMode || keyVersion === 5 || isLegacyAEAD) {
@@ -18378,6 +19220,8 @@ async function generateSecretKey(options, config) {
18378
19220
  * Returns the valid and non-expired signature that has the latest creation date, while ignoring signatures created in the future.
18379
19221
  * @param {Array<SignaturePacket>} signatures - List of signatures
18380
19222
  * @param {PublicKeyPacket|PublicSubkeyPacket} publicKey - Public key packet to verify the signature
19223
+ * @param {module:enums.signature} signatureType - Signature type to determine how to hash the data (NB: for userID signatures,
19224
+ * `enums.signatures.certGeneric` should be given regardless of the actual trust level)
18381
19225
  * @param {Date} date - Use the given date instead of the current time
18382
19226
  * @param {Object} config - full configuration
18383
19227
  * @returns {Promise<SignaturePacket>} The latest valid signature.
@@ -18626,8 +19470,14 @@ async function isDataRevoked(primaryKey, signatureType, dataToVerify, revocation
18626
19470
  // `verifyAllCertifications`.)
18627
19471
  !signature || revocationSignature.issuerKeyID.equals(signature.issuerKeyID)
18628
19472
  ) {
19473
+ const isHardRevocation = ![
19474
+ enums.reasonForRevocation.keyRetired,
19475
+ enums.reasonForRevocation.keySuperseded,
19476
+ enums.reasonForRevocation.userIDInvalid
19477
+ ].includes(revocationSignature.reasonForRevocationFlag);
19478
+
18629
19479
  await revocationSignature.verify(
18630
- key, signatureType, dataToVerify, date, false, config
19480
+ key, signatureType, dataToVerify, isHardRevocation ? null : date, false, config
18631
19481
  );
18632
19482
 
18633
19483
  // TODO get an identifier of the revoked object instead
@@ -20614,7 +21464,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
20614
21464
  key: secretKeyPacket
20615
21465
  };
20616
21466
  const signatureProperties = secretKeyPacket.version !== 6 ? getKeySignatureProperties() : {};
20617
- signatureProperties.signatureType = enums.signature.certGeneric;
21467
+ signatureProperties.signatureType = enums.signature.certPositive;
20618
21468
  if (index === 0) {
20619
21469
  signatureProperties.isPrimaryUserID = true;
20620
21470
  }
@@ -22439,7 +23289,7 @@ async function verify({ message, verificationKeys, expectSigned = false, format
22439
23289
  result.signatures = await message.verify(verificationKeys, date, config$1);
22440
23290
  }
22441
23291
  result.data = format === 'binary' ? message.getLiteralData() : message.getText();
22442
- if (message.fromStream) linkStreams(result, message);
23292
+ if (message.fromStream && !signature) linkStreams(result, message);
22443
23293
  if (expectSigned) {
22444
23294
  if (result.signatures.length === 0) {
22445
23295
  throw new Error('Message is not signed');