@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.
- package/README.md +2 -2
- package/dist/lightweight/argon2id.min.mjs +2 -2
- package/dist/lightweight/argon2id.min.mjs.map +1 -1
- package/dist/lightweight/argon2id.mjs +5 -28
- package/dist/lightweight/legacy_ciphers.min.mjs +2 -2
- package/dist/lightweight/legacy_ciphers.min.mjs.map +1 -1
- package/dist/lightweight/legacy_ciphers.mjs +6 -51
- package/dist/lightweight/noble_curves.min.mjs +11 -11
- package/dist/lightweight/noble_curves.min.mjs.map +1 -1
- package/dist/lightweight/noble_curves.mjs +477 -465
- package/dist/lightweight/noble_hashes.min.mjs +2 -2
- package/dist/lightweight/noble_hashes.min.mjs.map +1 -1
- package/dist/lightweight/noble_hashes.mjs +19 -31
- package/dist/lightweight/openpgp.min.mjs +3 -2
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +1529 -552
- package/dist/lightweight/sha3.min.mjs +3 -3
- package/dist/lightweight/sha3.min.mjs.map +1 -1
- package/dist/lightweight/sha3.mjs +80 -80
- package/dist/node/openpgp.cjs +2199 -5545
- package/dist/node/openpgp.min.cjs +12 -12
- package/dist/node/openpgp.min.cjs.map +1 -1
- package/dist/node/openpgp.min.mjs +12 -12
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +2198 -5545
- package/dist/openpgp.js +2188 -5542
- package/dist/openpgp.min.js +12 -12
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +12 -12
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +2188 -5542
- package/openpgp.d.ts +69 -61
- package/package.json +20 -13
- package/dist/lightweight/bn.interface.min.mjs +0 -3
- package/dist/lightweight/bn.interface.min.mjs.map +0 -1
- package/dist/lightweight/bn.interface.mjs +0 -3807
- package/dist/lightweight/interface.min.mjs +0 -3
- package/dist/lightweight/interface.min.mjs.map +0 -1
- package/dist/lightweight/interface.mjs +0 -16
- package/dist/lightweight/native.interface.min.mjs +0 -3
- package/dist/lightweight/native.interface.min.mjs.map +0 -1
- package/dist/lightweight/native.interface.mjs +0 -456
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
/*! OpenPGP.js v6.0.0-beta.
|
|
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
|
-
import { B as BigInteger } from './interface.mjs';
|
|
5
|
-
import NativeBigInteger from './native.interface.mjs';
|
|
6
|
-
import BNBigInteger from './bn.interface.mjs';
|
|
7
|
-
|
|
8
4
|
function number(n) {
|
|
9
5
|
if (!Number.isSafeInteger(n) || n < 0)
|
|
10
|
-
throw new Error(`
|
|
6
|
+
throw new Error(`positive integer expected, not ${n}`);
|
|
11
7
|
}
|
|
12
8
|
// copied from utils
|
|
13
|
-
function isBytes
|
|
9
|
+
function isBytes(a) {
|
|
14
10
|
return (a instanceof Uint8Array ||
|
|
15
11
|
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
|
16
12
|
}
|
|
17
13
|
function bytes(b, ...lengths) {
|
|
18
|
-
if (!isBytes
|
|
19
|
-
throw new Error('
|
|
14
|
+
if (!isBytes(b))
|
|
15
|
+
throw new Error('Uint8Array expected');
|
|
20
16
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
21
|
-
throw new Error(`
|
|
17
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
22
18
|
}
|
|
23
|
-
function hash(
|
|
24
|
-
if (typeof
|
|
19
|
+
function hash(h) {
|
|
20
|
+
if (typeof h !== 'function' || typeof h.create !== 'function')
|
|
25
21
|
throw new Error('Hash should be wrapped by utils.wrapConstructor');
|
|
26
|
-
number(
|
|
27
|
-
number(
|
|
22
|
+
number(h.outputLen);
|
|
23
|
+
number(h.blockLen);
|
|
28
24
|
}
|
|
29
25
|
function exists(instance, checkFinished = true) {
|
|
30
26
|
if (instance.destroyed)
|
|
@@ -40,7 +36,6 @@ function output(out, instance) {
|
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
// declare const globalThis: Record<string, any> | undefined;
|
|
44
39
|
const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
45
40
|
|
|
46
41
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -51,21 +46,24 @@ const crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? global
|
|
|
51
46
|
// Makes the utils un-importable in browsers without a bundler.
|
|
52
47
|
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
53
48
|
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
54
|
-
function isBytes(a) {
|
|
55
|
-
return (a instanceof Uint8Array ||
|
|
56
|
-
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
|
57
|
-
}
|
|
58
49
|
// Cast array to view
|
|
59
50
|
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
60
51
|
// The rotate right (circular right shift) operation for uint32
|
|
61
52
|
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
// Other libraries would silently corrupt the data instead of throwing an error,
|
|
65
|
-
// when they don't support it.
|
|
53
|
+
// The rotate left (circular left shift) operation for uint32
|
|
54
|
+
const rotl = (word, shift) => (word << shift) | ((word >>> (32 - shift)) >>> 0);
|
|
66
55
|
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
// The byte swap operation for uint32
|
|
57
|
+
const byteSwap = (word) => ((word << 24) & 0xff000000) |
|
|
58
|
+
((word << 8) & 0xff0000) |
|
|
59
|
+
((word >>> 8) & 0xff00) |
|
|
60
|
+
((word >>> 24) & 0xff);
|
|
61
|
+
// In place byte swap for Uint32Array
|
|
62
|
+
function byteSwap32(arr) {
|
|
63
|
+
for (let i = 0; i < arr.length; i++) {
|
|
64
|
+
arr[i] = byteSwap(arr[i]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
69
67
|
/**
|
|
70
68
|
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
71
69
|
*/
|
|
@@ -82,8 +80,7 @@ function utf8ToBytes(str) {
|
|
|
82
80
|
function toBytes(data) {
|
|
83
81
|
if (typeof data === 'string')
|
|
84
82
|
data = utf8ToBytes(data);
|
|
85
|
-
|
|
86
|
-
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
83
|
+
bytes(data);
|
|
87
84
|
return data;
|
|
88
85
|
}
|
|
89
86
|
/**
|
|
@@ -93,8 +90,7 @@ function concatBytes(...arrays) {
|
|
|
93
90
|
let sum = 0;
|
|
94
91
|
for (let i = 0; i < arrays.length; i++) {
|
|
95
92
|
const a = arrays[i];
|
|
96
|
-
|
|
97
|
-
throw new Error('Uint8Array expected');
|
|
93
|
+
bytes(a);
|
|
98
94
|
sum += a.length;
|
|
99
95
|
}
|
|
100
96
|
const res = new Uint8Array(sum);
|
|
@@ -138,26 +134,28 @@ function randomBytes(bytesLength = 32) {
|
|
|
138
134
|
throw new Error('crypto.getRandomValues must be defined');
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
|
|
142
|
-
BigInteger.setImplementation(detectBigInt() ? NativeBigInteger : BNBigInteger);
|
|
143
|
-
// About BigInteger interface and bigint replacement:
|
|
144
|
-
// - some functions get a bigint and change its value without reassingment (eg i++). Note that with BigIntegers, you must clone the value before doing so!!!
|
|
145
|
-
|
|
146
|
-
// Polyfill for Safari <= 14
|
|
137
|
+
// Polyfill for Safari 14
|
|
147
138
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
148
139
|
if (typeof view.setBigUint64 === 'function')
|
|
149
|
-
return view.setBigUint64(byteOffset,
|
|
150
|
-
const _32n =
|
|
151
|
-
const _u32_max =
|
|
152
|
-
const wh = value
|
|
153
|
-
const wl = value
|
|
140
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
141
|
+
const _32n = BigInt(32);
|
|
142
|
+
const _u32_max = BigInt(0xffffffff);
|
|
143
|
+
const wh = Number((value >> _32n) & _u32_max);
|
|
144
|
+
const wl = Number(value & _u32_max);
|
|
154
145
|
const h = isLE ? 4 : 0;
|
|
155
146
|
const l = isLE ? 0 : 4;
|
|
156
147
|
view.setUint32(byteOffset + h, wh, isLE);
|
|
157
148
|
view.setUint32(byteOffset + l, wl, isLE);
|
|
158
149
|
}
|
|
159
|
-
//
|
|
160
|
-
|
|
150
|
+
// Choice: a ? b : c
|
|
151
|
+
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
152
|
+
// Majority function, true if any two inpust is true
|
|
153
|
+
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
154
|
+
/**
|
|
155
|
+
* Merkle-Damgard hash construction base class.
|
|
156
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
157
|
+
*/
|
|
158
|
+
class HashMD extends Hash {
|
|
161
159
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
162
160
|
super();
|
|
163
161
|
this.blockLen = blockLen;
|
|
@@ -209,7 +207,8 @@ class SHA2 extends Hash {
|
|
|
209
207
|
// append the bit '1' to the message
|
|
210
208
|
buffer[pos++] = 0b10000000;
|
|
211
209
|
this.buffer.subarray(pos).fill(0);
|
|
212
|
-
// we have less than padOffset left in buffer, so we cannot put length in
|
|
210
|
+
// we have less than padOffset left in buffer, so we cannot put length in
|
|
211
|
+
// current block, need process it and pad again
|
|
213
212
|
if (this.padOffset > blockLen - pos) {
|
|
214
213
|
this.process(view, 0);
|
|
215
214
|
pos = 0;
|
|
@@ -220,7 +219,7 @@ class SHA2 extends Hash {
|
|
|
220
219
|
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
221
220
|
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
222
221
|
// So we just write lowest 64 bits of that value.
|
|
223
|
-
setBigUint64(view, blockLen - 8,
|
|
222
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
224
223
|
this.process(view, 0);
|
|
225
224
|
const oview = createView(out);
|
|
226
225
|
const len = this.outputLen;
|
|
@@ -257,10 +256,6 @@ class SHA2 extends Hash {
|
|
|
257
256
|
|
|
258
257
|
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
|
259
258
|
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
|
260
|
-
// Choice: a ? b : c
|
|
261
|
-
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
262
|
-
// Majority function, true if any two inpust is true
|
|
263
|
-
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
264
259
|
// Round constants:
|
|
265
260
|
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
266
261
|
// prettier-ignore
|
|
@@ -274,27 +269,28 @@ const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
|
274
269
|
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
275
270
|
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
276
271
|
]);
|
|
277
|
-
// Initial state
|
|
272
|
+
// Initial state:
|
|
273
|
+
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19
|
|
278
274
|
// prettier-ignore
|
|
279
|
-
const
|
|
275
|
+
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
|
280
276
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
281
277
|
]);
|
|
282
278
|
// Temporary buffer, not used to store anything between runs
|
|
283
279
|
// Named this way because it matches specification.
|
|
284
280
|
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
285
|
-
class SHA256 extends
|
|
281
|
+
class SHA256 extends HashMD {
|
|
286
282
|
constructor() {
|
|
287
283
|
super(64, 32, 8, false);
|
|
288
284
|
// We cannot use array here since array allows indexing by variable
|
|
289
285
|
// which means optimizer/compiler cannot use registers.
|
|
290
|
-
this.A =
|
|
291
|
-
this.B =
|
|
292
|
-
this.C =
|
|
293
|
-
this.D =
|
|
294
|
-
this.E =
|
|
295
|
-
this.F =
|
|
296
|
-
this.G =
|
|
297
|
-
this.H =
|
|
286
|
+
this.A = SHA256_IV[0] | 0;
|
|
287
|
+
this.B = SHA256_IV[1] | 0;
|
|
288
|
+
this.C = SHA256_IV[2] | 0;
|
|
289
|
+
this.D = SHA256_IV[3] | 0;
|
|
290
|
+
this.E = SHA256_IV[4] | 0;
|
|
291
|
+
this.F = SHA256_IV[5] | 0;
|
|
292
|
+
this.G = SHA256_IV[6] | 0;
|
|
293
|
+
this.H = SHA256_IV[7] | 0;
|
|
298
294
|
}
|
|
299
295
|
get() {
|
|
300
296
|
const { A, B, C, D, E, F, G, H } = this;
|
|
@@ -379,13 +375,13 @@ class SHA224 extends SHA256 {
|
|
|
379
375
|
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
380
376
|
const sha224 = /* @__PURE__ */ wrapConstructor(() => new SHA224());
|
|
381
377
|
|
|
382
|
-
const U32_MASK64 =
|
|
383
|
-
const _32n =
|
|
378
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
379
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
384
380
|
// We are not using BigUint64Array, because they are extremely slow as per 2022
|
|
385
381
|
function fromBig(n, le = false) {
|
|
386
382
|
if (le)
|
|
387
|
-
return { h: n
|
|
388
|
-
return { h: n
|
|
383
|
+
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
384
|
+
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
389
385
|
}
|
|
390
386
|
function split(lst, le = false) {
|
|
391
387
|
let Ah = new Uint32Array(lst.length);
|
|
@@ -396,9 +392,7 @@ function split(lst, le = false) {
|
|
|
396
392
|
}
|
|
397
393
|
return [Ah, Al];
|
|
398
394
|
}
|
|
399
|
-
const toBig = (h, l) => (
|
|
400
|
-
.ileftShift(_32n)
|
|
401
|
-
.ibitwiseOr(BigInteger.new(l >>> 0)));
|
|
395
|
+
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
|
|
402
396
|
// for Shift in [0, 32)
|
|
403
397
|
const shrSH = (h, _l, s) => h >>> s;
|
|
404
398
|
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
@@ -463,11 +457,11 @@ const [SHA512_Kh, SHA512_Kl] = /* @__PURE__ */ (() => u64.split([
|
|
|
463
457
|
'0x06f067aa72176fba', '0x0a637dc5a2c898a6', '0x113f9804bef90dae', '0x1b710b35131c471b',
|
|
464
458
|
'0x28db77f523047d84', '0x32caab7b40c72493', '0x3c9ebe0a15c9bebc', '0x431d67c49c100d4c',
|
|
465
459
|
'0x4cc5d4becb3e42b6', '0x597f299cfc657e2a', '0x5fcb6fab3ad6faec', '0x6c44198c4a475817'
|
|
466
|
-
].map(n =>
|
|
460
|
+
].map(n => BigInt(n))))();
|
|
467
461
|
// Temporary buffer, not used to store anything between runs
|
|
468
462
|
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
469
463
|
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
470
|
-
class SHA512 extends
|
|
464
|
+
class SHA512 extends HashMD {
|
|
471
465
|
constructor() {
|
|
472
466
|
super(128, 64, 16, false);
|
|
473
467
|
// We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
|
|
@@ -623,13 +617,15 @@ const sha384 = /* @__PURE__ */ wrapConstructor(() => new SHA384());
|
|
|
623
617
|
// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
|
|
624
618
|
// It's called a sponge function.
|
|
625
619
|
// Various per round constants calculations
|
|
626
|
-
const
|
|
627
|
-
const
|
|
628
|
-
const
|
|
629
|
-
const
|
|
630
|
-
const
|
|
631
|
-
const
|
|
632
|
-
const
|
|
620
|
+
const SHA3_PI = [];
|
|
621
|
+
const SHA3_ROTL = [];
|
|
622
|
+
const _SHA3_IOTA = [];
|
|
623
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
624
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
625
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
626
|
+
const _7n = /* @__PURE__ */ BigInt(7);
|
|
627
|
+
const _256n = /* @__PURE__ */ BigInt(256);
|
|
628
|
+
const _0x71n = /* @__PURE__ */ BigInt(0x71);
|
|
633
629
|
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
634
630
|
// Pi
|
|
635
631
|
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
@@ -637,11 +633,11 @@ for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
|
637
633
|
// Rotational
|
|
638
634
|
SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
|
|
639
635
|
// Iota
|
|
640
|
-
|
|
636
|
+
let t = _0n;
|
|
641
637
|
for (let j = 0; j < 7; j++) {
|
|
642
|
-
R = R
|
|
643
|
-
if (
|
|
644
|
-
t
|
|
638
|
+
R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
|
|
639
|
+
if (R & _2n)
|
|
640
|
+
t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
|
|
645
641
|
}
|
|
646
642
|
_SHA3_IOTA.push(t);
|
|
647
643
|
}
|
|
@@ -717,7 +713,11 @@ class Keccak extends Hash {
|
|
|
717
713
|
this.state32 = u32(this.state);
|
|
718
714
|
}
|
|
719
715
|
keccak() {
|
|
716
|
+
if (!isLE)
|
|
717
|
+
byteSwap32(this.state32);
|
|
720
718
|
keccakP(this.state32, this.rounds);
|
|
719
|
+
if (!isLE)
|
|
720
|
+
byteSwap32(this.state32);
|
|
721
721
|
this.posOut = 0;
|
|
722
722
|
this.pos = 0;
|
|
723
723
|
}
|
|
@@ -814,4 +814,4 @@ const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8);
|
|
|
814
814
|
const genShake = (suffix, blockLen, outputLen) => wrapXOFConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
|
|
815
815
|
const shake256 = /* @__PURE__ */ genShake(0x1f, 136, 256 / 8);
|
|
816
816
|
|
|
817
|
-
export { Hash as H,
|
|
817
|
+
export { Chi as C, Hash as H, Maj as M, sha384 as a, bytes as b, concatBytes as c, sha512 as d, exists as e, shake256 as f, HashMD as g, hash as h, rotl as i, sha224 as j, sha3_256 as k, sha3_512 as l, randomBytes as r, sha256 as s, toBytes as t, utf8ToBytes as u, wrapConstructor as w };
|