@ocap/mcrypto 1.30.24 → 1.30.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/esm/crypter/aes-legacy.d.mts +11 -0
  2. package/esm/crypter/aes-legacy.mjs +67 -15
  3. package/esm/crypter/aes.d.mts +14 -2
  4. package/esm/crypter/aes.mjs +69 -3
  5. package/esm/encode.mjs +1 -1
  6. package/esm/hasher/keccak.mjs +7 -2
  7. package/esm/hasher/sha2.d.mts +1 -1
  8. package/esm/hasher/sha2.mjs +26 -11
  9. package/esm/hasher/sha3.d.mts +1 -1
  10. package/esm/hasher/sha3.mjs +21 -6
  11. package/esm/index.d.mts +1 -1
  12. package/esm/signer/ed25519.d.mts +1 -1
  13. package/esm/signer/ed25519.mjs +143 -16
  14. package/esm/signer/ethereum.mjs +7 -3
  15. package/esm/signer/secp256k1.mjs +3 -2
  16. package/esm/webauthn.d.mts +68 -2
  17. package/esm/webauthn.mjs +64 -16
  18. package/lib/_vendor/@noble/curves/LICENSE +21 -0
  19. package/lib/_vendor/@noble/curves/abstract/curve.cjs +373 -0
  20. package/lib/_vendor/@noble/curves/abstract/modular.cjs +616 -0
  21. package/lib/_vendor/@noble/curves/abstract/weierstrass.cjs +1020 -0
  22. package/lib/_vendor/@noble/curves/nist.cjs +91 -0
  23. package/lib/_vendor/@noble/curves/secp256k1.cjs +73 -0
  24. package/lib/_vendor/@noble/curves/utils.cjs +463 -0
  25. package/lib/_vendor/@noble/ed25519/LICENSE +21 -0
  26. package/lib/_vendor/@noble/ed25519/index.cjs +512 -0
  27. package/lib/_vendor/@noble/hashes/LICENSE +21 -0
  28. package/lib/_vendor/@noble/hashes/_md.cjs +230 -0
  29. package/lib/_vendor/@noble/hashes/_u64.cjs +67 -0
  30. package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
  31. package/lib/_vendor/@noble/hashes/sha2.cjs +477 -0
  32. package/lib/_vendor/@noble/hashes/sha3.cjs +329 -0
  33. package/lib/_vendor/@noble/hashes/utils.cjs +410 -0
  34. package/lib/crypter/aes-legacy.cjs +68 -21
  35. package/lib/crypter/aes-legacy.d.cts +11 -0
  36. package/lib/crypter/aes.cjs +69 -2
  37. package/lib/crypter/aes.d.cts +14 -2
  38. package/lib/encode.cjs +1 -1
  39. package/lib/hasher/keccak.cjs +13 -8
  40. package/lib/hasher/sha2.cjs +32 -17
  41. package/lib/hasher/sha2.d.cts +1 -1
  42. package/lib/hasher/sha3.cjs +27 -12
  43. package/lib/hasher/sha3.d.cts +1 -1
  44. package/lib/index.d.cts +1 -1
  45. package/lib/signer/ed25519.cjs +146 -20
  46. package/lib/signer/ed25519.d.cts +1 -1
  47. package/lib/signer/ethereum.cjs +16 -12
  48. package/lib/signer/secp256k1.cjs +11 -10
  49. package/lib/webauthn.cjs +80 -31
  50. package/lib/webauthn.d.cts +68 -2
  51. package/package.json +6 -7
@@ -0,0 +1,230 @@
1
+ const require_utils = require('./utils.cjs');
2
+
3
+ //#region ../../node_modules/@noble/hashes/_md.js
4
+ /**
5
+ * Internal Merkle-Damgard hash utils.
6
+ * @module
7
+ */
8
+ /**
9
+ * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
10
+ * Returns bits from `b` when `a` is set, otherwise from `c`.
11
+ * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
12
+ * set the same bit.
13
+ * @param a - selector word
14
+ * @param b - word chosen when selector bit is set
15
+ * @param c - word chosen when selector bit is clear
16
+ * @returns Mixed 32-bit word.
17
+ * @example
18
+ * Combine three words with the shared 32-bit choice primitive.
19
+ * ```ts
20
+ * Chi(0xffffffff, 0x12345678, 0x87654321);
21
+ * ```
22
+ */
23
+ function Chi(a, b, c) {
24
+ return a & b ^ ~a & c;
25
+ }
26
+ /**
27
+ * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
28
+ * Returns bits shared by at least two inputs.
29
+ * @param a - first input word
30
+ * @param b - second input word
31
+ * @param c - third input word
32
+ * @returns Mixed 32-bit word.
33
+ * @example
34
+ * Combine three words with the shared 32-bit majority primitive.
35
+ * ```ts
36
+ * Maj(0xffffffff, 0x12345678, 0x87654321);
37
+ * ```
38
+ */
39
+ function Maj(a, b, c) {
40
+ return a & b ^ a & c ^ b & c;
41
+ }
42
+ /**
43
+ * Merkle-Damgard hash construction base class.
44
+ * Could be used to create MD5, RIPEMD, SHA1, SHA2.
45
+ * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
46
+ * strings with partial-byte tails.
47
+ * @param blockLen - internal block size in bytes
48
+ * @param outputLen - digest size in bytes
49
+ * @param padOffset - trailing length field size in bytes
50
+ * @param isLE - whether length and state words are encoded in little-endian
51
+ * @example
52
+ * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
53
+ * ```ts
54
+ * import { _SHA1 } from '@noble/hashes/legacy.js';
55
+ * const hash = new _SHA1();
56
+ * hash.update(new Uint8Array([97, 98, 99]));
57
+ * hash.digest();
58
+ * ```
59
+ */
60
+ var HashMD = class {
61
+ blockLen;
62
+ outputLen;
63
+ canXOF = false;
64
+ padOffset;
65
+ isLE;
66
+ buffer;
67
+ view;
68
+ finished = false;
69
+ length = 0;
70
+ pos = 0;
71
+ destroyed = false;
72
+ constructor(blockLen, outputLen, padOffset, isLE) {
73
+ this.blockLen = blockLen;
74
+ this.outputLen = outputLen;
75
+ this.padOffset = padOffset;
76
+ this.isLE = isLE;
77
+ this.buffer = new Uint8Array(blockLen);
78
+ this.view = require_utils.createView(this.buffer);
79
+ }
80
+ update(data) {
81
+ require_utils.aexists(this);
82
+ require_utils.abytes(data);
83
+ const { view, buffer, blockLen } = this;
84
+ const len = data.length;
85
+ for (let pos = 0; pos < len;) {
86
+ const take = Math.min(blockLen - this.pos, len - pos);
87
+ if (take === blockLen) {
88
+ const dataView = require_utils.createView(data);
89
+ for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
90
+ continue;
91
+ }
92
+ buffer.set(data.subarray(pos, pos + take), this.pos);
93
+ this.pos += take;
94
+ pos += take;
95
+ if (this.pos === blockLen) {
96
+ this.process(view, 0);
97
+ this.pos = 0;
98
+ }
99
+ }
100
+ this.length += data.length;
101
+ this.roundClean();
102
+ return this;
103
+ }
104
+ digestInto(out) {
105
+ require_utils.aexists(this);
106
+ require_utils.aoutput(out, this);
107
+ this.finished = true;
108
+ const { buffer, view, blockLen, isLE } = this;
109
+ let { pos } = this;
110
+ buffer[pos++] = 128;
111
+ require_utils.clean(this.buffer.subarray(pos));
112
+ if (this.padOffset > blockLen - pos) {
113
+ this.process(view, 0);
114
+ pos = 0;
115
+ }
116
+ for (let i = pos; i < blockLen; i++) buffer[i] = 0;
117
+ view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
118
+ this.process(view, 0);
119
+ const oview = require_utils.createView(out);
120
+ const len = this.outputLen;
121
+ if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
122
+ const outLen = len / 4;
123
+ const state = this.get();
124
+ if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
125
+ for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
126
+ }
127
+ digest() {
128
+ const { buffer, outputLen } = this;
129
+ this.digestInto(buffer);
130
+ const res = buffer.slice(0, outputLen);
131
+ this.destroy();
132
+ return res;
133
+ }
134
+ _cloneInto(to) {
135
+ to ||= new this.constructor();
136
+ to.set(...this.get());
137
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
138
+ to.destroyed = destroyed;
139
+ to.finished = finished;
140
+ to.length = length;
141
+ to.pos = pos;
142
+ if (length % blockLen) to.buffer.set(buffer);
143
+ return to;
144
+ }
145
+ clone() {
146
+ return this._cloneInto();
147
+ }
148
+ };
149
+ /**
150
+ * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
151
+ * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
152
+ */
153
+ /** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
154
+ * square roots of the first eight prime numbers. Exported as a shared table; callers must treat
155
+ * it as read-only because constructors copy words from it by index. */
156
+ const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
157
+ 1779033703,
158
+ 3144134277,
159
+ 1013904242,
160
+ 2773480762,
161
+ 1359893119,
162
+ 2600822924,
163
+ 528734635,
164
+ 1541459225
165
+ ]);
166
+ /** Initial SHA224 state `H(0)` from RFC 6234 §6.1. Exported as a shared table; callers must
167
+ * treat it as read-only because constructors copy words from it by index. */
168
+ const SHA224_IV = /* @__PURE__ */ Uint32Array.from([
169
+ 3238371032,
170
+ 914150663,
171
+ 812702999,
172
+ 4144912697,
173
+ 4290775857,
174
+ 1750603025,
175
+ 1694076839,
176
+ 3204075428
177
+ ]);
178
+ /** Initial SHA384 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
179
+ * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the ninth
180
+ * through sixteenth prime numbers. Exported as a shared table; callers must treat it as read-only
181
+ * because constructors copy halves from it by index. */
182
+ const SHA384_IV = /* @__PURE__ */ Uint32Array.from([
183
+ 3418070365,
184
+ 3238371032,
185
+ 1654270250,
186
+ 914150663,
187
+ 2438529370,
188
+ 812702999,
189
+ 355462360,
190
+ 4144912697,
191
+ 1731405415,
192
+ 4290775857,
193
+ 2394180231,
194
+ 1750603025,
195
+ 3675008525,
196
+ 1694076839,
197
+ 1203062813,
198
+ 3204075428
199
+ ]);
200
+ /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
201
+ * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
202
+ * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
203
+ * constructors copy halves from it by index. */
204
+ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
205
+ 1779033703,
206
+ 4089235720,
207
+ 3144134277,
208
+ 2227873595,
209
+ 1013904242,
210
+ 4271175723,
211
+ 2773480762,
212
+ 1595750129,
213
+ 1359893119,
214
+ 2917565137,
215
+ 2600822924,
216
+ 725511199,
217
+ 528734635,
218
+ 4215389547,
219
+ 1541459225,
220
+ 327033209
221
+ ]);
222
+
223
+ //#endregion
224
+ exports.Chi = Chi;
225
+ exports.HashMD = HashMD;
226
+ exports.Maj = Maj;
227
+ exports.SHA224_IV = SHA224_IV;
228
+ exports.SHA256_IV = SHA256_IV;
229
+ exports.SHA384_IV = SHA384_IV;
230
+ exports.SHA512_IV = SHA512_IV;
@@ -0,0 +1,67 @@
1
+
2
+ //#region ../../node_modules/@noble/hashes/_u64.js
3
+ const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
4
+ const _32n = /* @__PURE__ */ BigInt(32);
5
+ function fromBig(n, le = false) {
6
+ if (le) return {
7
+ h: Number(n & U32_MASK64),
8
+ l: Number(n >> _32n & U32_MASK64)
9
+ };
10
+ return {
11
+ h: Number(n >> _32n & U32_MASK64) | 0,
12
+ l: Number(n & U32_MASK64) | 0
13
+ };
14
+ }
15
+ function split(lst, le = false) {
16
+ const len = lst.length;
17
+ let Ah = new Uint32Array(len);
18
+ let Al = new Uint32Array(len);
19
+ for (let i = 0; i < len; i++) {
20
+ const { h, l } = fromBig(lst[i], le);
21
+ [Ah[i], Al[i]] = [h, l];
22
+ }
23
+ return [Ah, Al];
24
+ }
25
+ const shrSH = (h, _l, s) => h >>> s;
26
+ const shrSL = (h, l, s) => h << 32 - s | l >>> s;
27
+ const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
28
+ const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
29
+ const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
30
+ const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
31
+ const rotlSH = (h, l, s) => h << s | l >>> 32 - s;
32
+ const rotlSL = (h, l, s) => l << s | h >>> 32 - s;
33
+ const rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
34
+ const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
35
+ function add(Ah, Al, Bh, Bl) {
36
+ const l = (Al >>> 0) + (Bl >>> 0);
37
+ return {
38
+ h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
39
+ l: l | 0
40
+ };
41
+ }
42
+ const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
43
+ const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
44
+ const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
45
+ const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
46
+ const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
47
+ const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
48
+
49
+ //#endregion
50
+ exports.add = add;
51
+ exports.add3H = add3H;
52
+ exports.add3L = add3L;
53
+ exports.add4H = add4H;
54
+ exports.add4L = add4L;
55
+ exports.add5H = add5H;
56
+ exports.add5L = add5L;
57
+ exports.rotlBH = rotlBH;
58
+ exports.rotlBL = rotlBL;
59
+ exports.rotlSH = rotlSH;
60
+ exports.rotlSL = rotlSL;
61
+ exports.rotrBH = rotrBH;
62
+ exports.rotrBL = rotrBL;
63
+ exports.rotrSH = rotrSH;
64
+ exports.rotrSL = rotrSL;
65
+ exports.shrSH = shrSH;
66
+ exports.shrSL = shrSL;
67
+ exports.split = split;
@@ -0,0 +1,86 @@
1
+ const require_utils = require('./utils.cjs');
2
+
3
+ //#region ../../node_modules/@noble/hashes/hmac.js
4
+ /**
5
+ * HMAC: RFC2104 message authentication code.
6
+ * @module
7
+ */
8
+ /**
9
+ * Internal class for HMAC.
10
+ * Accepts any byte key, although RFC 2104 §3 recommends keys at least
11
+ * `HashLen` bytes long.
12
+ */
13
+ var _HMAC = class {
14
+ oHash;
15
+ iHash;
16
+ blockLen;
17
+ outputLen;
18
+ canXOF = false;
19
+ finished = false;
20
+ destroyed = false;
21
+ constructor(hash, key) {
22
+ require_utils.ahash(hash);
23
+ require_utils.abytes(key, void 0, "key");
24
+ this.iHash = hash.create();
25
+ if (typeof this.iHash.update !== "function") throw new Error("Expected instance of class which extends utils.Hash");
26
+ this.blockLen = this.iHash.blockLen;
27
+ this.outputLen = this.iHash.outputLen;
28
+ const blockLen = this.blockLen;
29
+ const pad = new Uint8Array(blockLen);
30
+ pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
31
+ for (let i = 0; i < pad.length; i++) pad[i] ^= 54;
32
+ this.iHash.update(pad);
33
+ this.oHash = hash.create();
34
+ for (let i = 0; i < pad.length; i++) pad[i] ^= 106;
35
+ this.oHash.update(pad);
36
+ require_utils.clean(pad);
37
+ }
38
+ update(buf) {
39
+ require_utils.aexists(this);
40
+ this.iHash.update(buf);
41
+ return this;
42
+ }
43
+ digestInto(out) {
44
+ require_utils.aexists(this);
45
+ require_utils.aoutput(out, this);
46
+ this.finished = true;
47
+ const buf = out.subarray(0, this.outputLen);
48
+ this.iHash.digestInto(buf);
49
+ this.oHash.update(buf);
50
+ this.oHash.digestInto(buf);
51
+ this.destroy();
52
+ }
53
+ digest() {
54
+ const out = new Uint8Array(this.oHash.outputLen);
55
+ this.digestInto(out);
56
+ return out;
57
+ }
58
+ _cloneInto(to) {
59
+ to ||= Object.create(Object.getPrototypeOf(this), {});
60
+ const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
61
+ to = to;
62
+ to.finished = finished;
63
+ to.destroyed = destroyed;
64
+ to.blockLen = blockLen;
65
+ to.outputLen = outputLen;
66
+ to.oHash = oHash._cloneInto(to.oHash);
67
+ to.iHash = iHash._cloneInto(to.iHash);
68
+ return to;
69
+ }
70
+ clone() {
71
+ return this._cloneInto();
72
+ }
73
+ destroy() {
74
+ this.destroyed = true;
75
+ this.oHash.destroy();
76
+ this.iHash.destroy();
77
+ }
78
+ };
79
+ const hmac = /* @__PURE__ */ (() => {
80
+ const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
81
+ hmac_.create = (hash, key) => new _HMAC(hash, key);
82
+ return hmac_;
83
+ })();
84
+
85
+ //#endregion
86
+ exports.hmac = hmac;