@ocap/mcrypto 1.30.24 → 1.30.25
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/esm/crypter/aes-legacy.d.mts +11 -0
- package/esm/crypter/aes-legacy.mjs +67 -15
- package/esm/crypter/aes.d.mts +14 -2
- package/esm/crypter/aes.mjs +69 -3
- package/esm/encode.mjs +1 -1
- package/esm/hasher/keccak.mjs +7 -2
- package/esm/hasher/sha2.d.mts +1 -1
- package/esm/hasher/sha2.mjs +26 -11
- package/esm/hasher/sha3.d.mts +1 -1
- package/esm/hasher/sha3.mjs +21 -6
- package/esm/index.d.mts +1 -1
- package/esm/signer/ed25519.d.mts +1 -1
- package/esm/signer/ed25519.mjs +143 -16
- package/esm/signer/ethereum.mjs +7 -3
- package/esm/signer/secp256k1.mjs +3 -2
- package/esm/webauthn.d.mts +68 -2
- package/esm/webauthn.mjs +64 -16
- package/lib/_vendor/@noble/curves/LICENSE +21 -0
- package/lib/_vendor/@noble/curves/abstract/curve.cjs +373 -0
- package/lib/_vendor/@noble/curves/abstract/modular.cjs +616 -0
- package/lib/_vendor/@noble/curves/abstract/weierstrass.cjs +1020 -0
- package/lib/_vendor/@noble/curves/nist.cjs +91 -0
- package/lib/_vendor/@noble/curves/secp256k1.cjs +73 -0
- package/lib/_vendor/@noble/curves/utils.cjs +463 -0
- package/lib/_vendor/@noble/ed25519/LICENSE +21 -0
- package/lib/_vendor/@noble/ed25519/index.cjs +512 -0
- package/lib/_vendor/@noble/hashes/LICENSE +21 -0
- package/lib/_vendor/@noble/hashes/_md.cjs +230 -0
- package/lib/_vendor/@noble/hashes/_u64.cjs +67 -0
- package/lib/_vendor/@noble/hashes/hmac.cjs +86 -0
- package/lib/_vendor/@noble/hashes/sha2.cjs +477 -0
- package/lib/_vendor/@noble/hashes/sha3.cjs +329 -0
- package/lib/_vendor/@noble/hashes/utils.cjs +410 -0
- package/lib/crypter/aes-legacy.cjs +68 -21
- package/lib/crypter/aes-legacy.d.cts +11 -0
- package/lib/crypter/aes.cjs +69 -2
- package/lib/crypter/aes.d.cts +14 -2
- package/lib/encode.cjs +1 -1
- package/lib/hasher/keccak.cjs +13 -8
- package/lib/hasher/sha2.cjs +32 -17
- package/lib/hasher/sha2.d.cts +1 -1
- package/lib/hasher/sha3.cjs +27 -12
- package/lib/hasher/sha3.d.cts +1 -1
- package/lib/index.d.cts +1 -1
- package/lib/signer/ed25519.cjs +146 -20
- package/lib/signer/ed25519.d.cts +1 -1
- package/lib/signer/ethereum.cjs +16 -12
- package/lib/signer/secp256k1.cjs +11 -10
- package/lib/webauthn.cjs +80 -31
- package/lib/webauthn.d.cts +68 -2
- package/package.json +6 -7
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
const require__u64 = require('./_u64.cjs');
|
|
2
|
+
const require_utils = require('./utils.cjs');
|
|
3
|
+
|
|
4
|
+
//#region ../../node_modules/@noble/hashes/sha3.js
|
|
5
|
+
/**
|
|
6
|
+
* SHA3 (keccak) hash function, based on a new "Sponge function" design.
|
|
7
|
+
* Different from older hashes, the internal state is bigger than output size.
|
|
8
|
+
*
|
|
9
|
+
* Check out
|
|
10
|
+
* {@link https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf | FIPS-202},
|
|
11
|
+
* {@link https://keccak.team/keccak.html | Website}, and
|
|
12
|
+
* {@link https://crypto.stackexchange.com/q/15727 | the differences between
|
|
13
|
+
* SHA-3 and Keccak}.
|
|
14
|
+
*
|
|
15
|
+
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
const _0n = BigInt(0);
|
|
19
|
+
const _1n = BigInt(1);
|
|
20
|
+
const _2n = BigInt(2);
|
|
21
|
+
const _7n = BigInt(7);
|
|
22
|
+
const _256n = BigInt(256);
|
|
23
|
+
const _0x71n = BigInt(113);
|
|
24
|
+
const SHA3_PI = [];
|
|
25
|
+
const SHA3_ROTL = [];
|
|
26
|
+
const _SHA3_IOTA = [];
|
|
27
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
28
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
29
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
30
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
31
|
+
let t = _0n;
|
|
32
|
+
for (let j = 0; j < 7; j++) {
|
|
33
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
34
|
+
if (R & _2n) t ^= _1n << (_1n << BigInt(j)) - _1n;
|
|
35
|
+
}
|
|
36
|
+
_SHA3_IOTA.push(t);
|
|
37
|
+
}
|
|
38
|
+
const IOTAS = require__u64.split(_SHA3_IOTA, true);
|
|
39
|
+
const SHA3_IOTA_H = IOTAS[0];
|
|
40
|
+
const SHA3_IOTA_L = IOTAS[1];
|
|
41
|
+
const rotlH = (h, l, s) => s > 32 ? require__u64.rotlBH(h, l, s) : require__u64.rotlSH(h, l, s);
|
|
42
|
+
const rotlL = (h, l, s) => s > 32 ? require__u64.rotlBL(h, l, s) : require__u64.rotlSL(h, l, s);
|
|
43
|
+
/**
|
|
44
|
+
* `keccakf1600` internal permutation, additionally allows adjusting the round count.
|
|
45
|
+
* @param s - 5x5 Keccak state encoded as 25 lanes split into 50 uint32 words
|
|
46
|
+
* in this file's local little-endian lane-word order
|
|
47
|
+
* @param rounds - number of rounds to execute
|
|
48
|
+
* @throws If `rounds` is outside the supported `1..24` range. {@link Error}
|
|
49
|
+
* @example
|
|
50
|
+
* Permute a Keccak state with the default 24 rounds.
|
|
51
|
+
* ```ts
|
|
52
|
+
* keccakP(new Uint32Array(50));
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function keccakP(s, rounds = 24) {
|
|
56
|
+
require_utils.anumber(rounds, "rounds");
|
|
57
|
+
if (rounds < 1 || rounds > 24) throw new Error("\"rounds\" expected integer 1..24");
|
|
58
|
+
const B = new Uint32Array(10);
|
|
59
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
60
|
+
for (let x = 0; x < 10; x++) B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
61
|
+
for (let x = 0; x < 10; x += 2) {
|
|
62
|
+
const idx1 = (x + 8) % 10;
|
|
63
|
+
const idx0 = (x + 2) % 10;
|
|
64
|
+
const B0 = B[idx0];
|
|
65
|
+
const B1 = B[idx0 + 1];
|
|
66
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
67
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
68
|
+
for (let y = 0; y < 50; y += 10) {
|
|
69
|
+
s[x + y] ^= Th;
|
|
70
|
+
s[x + y + 1] ^= Tl;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let curH = s[2];
|
|
74
|
+
let curL = s[3];
|
|
75
|
+
for (let t = 0; t < 24; t++) {
|
|
76
|
+
const shift = SHA3_ROTL[t];
|
|
77
|
+
const Th = rotlH(curH, curL, shift);
|
|
78
|
+
const Tl = rotlL(curH, curL, shift);
|
|
79
|
+
const PI = SHA3_PI[t];
|
|
80
|
+
curH = s[PI];
|
|
81
|
+
curL = s[PI + 1];
|
|
82
|
+
s[PI] = Th;
|
|
83
|
+
s[PI + 1] = Tl;
|
|
84
|
+
}
|
|
85
|
+
for (let y = 0; y < 50; y += 10) {
|
|
86
|
+
const b0 = s[y], b1 = s[y + 1], b2 = s[y + 2], b3 = s[y + 3];
|
|
87
|
+
s[y] ^= ~s[y + 2] & s[y + 4];
|
|
88
|
+
s[y + 1] ^= ~s[y + 3] & s[y + 5];
|
|
89
|
+
s[y + 2] ^= ~s[y + 4] & s[y + 6];
|
|
90
|
+
s[y + 3] ^= ~s[y + 5] & s[y + 7];
|
|
91
|
+
s[y + 4] ^= ~s[y + 6] & s[y + 8];
|
|
92
|
+
s[y + 5] ^= ~s[y + 7] & s[y + 9];
|
|
93
|
+
s[y + 6] ^= ~s[y + 8] & b0;
|
|
94
|
+
s[y + 7] ^= ~s[y + 9] & b1;
|
|
95
|
+
s[y + 8] ^= ~b0 & b2;
|
|
96
|
+
s[y + 9] ^= ~b1 & b3;
|
|
97
|
+
}
|
|
98
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
99
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
100
|
+
}
|
|
101
|
+
require_utils.clean(B);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Keccak sponge function.
|
|
105
|
+
* @param blockLen - absorb/squeeze rate in bytes
|
|
106
|
+
* @param suffix - domain separation suffix byte
|
|
107
|
+
* @param outputLen - default digest length in bytes. This base sponge only
|
|
108
|
+
* requires a non-negative integer; wrappers that need positive output
|
|
109
|
+
* lengths must enforce that themselves.
|
|
110
|
+
* @param enableXOF - whether XOF output is allowed
|
|
111
|
+
* @param rounds - number of Keccak-f rounds
|
|
112
|
+
* @example
|
|
113
|
+
* Build a sponge state, absorb bytes, then finalize a digest.
|
|
114
|
+
* ```ts
|
|
115
|
+
* const hash = new Keccak(136, 0x06, 32);
|
|
116
|
+
* hash.update(new Uint8Array([1, 2, 3]));
|
|
117
|
+
* hash.digest();
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
var Keccak = class Keccak {
|
|
121
|
+
state;
|
|
122
|
+
pos = 0;
|
|
123
|
+
posOut = 0;
|
|
124
|
+
finished = false;
|
|
125
|
+
state32;
|
|
126
|
+
destroyed = false;
|
|
127
|
+
blockLen;
|
|
128
|
+
suffix;
|
|
129
|
+
outputLen;
|
|
130
|
+
canXOF;
|
|
131
|
+
enableXOF = false;
|
|
132
|
+
rounds;
|
|
133
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
134
|
+
this.blockLen = blockLen;
|
|
135
|
+
this.suffix = suffix;
|
|
136
|
+
this.outputLen = outputLen;
|
|
137
|
+
this.enableXOF = enableXOF;
|
|
138
|
+
this.canXOF = enableXOF;
|
|
139
|
+
this.rounds = rounds;
|
|
140
|
+
require_utils.anumber(outputLen, "outputLen");
|
|
141
|
+
if (!(0 < blockLen && blockLen < 200)) throw new Error("only keccak-f1600 function is supported");
|
|
142
|
+
this.state = new Uint8Array(200);
|
|
143
|
+
this.state32 = require_utils.u32(this.state);
|
|
144
|
+
}
|
|
145
|
+
clone() {
|
|
146
|
+
return this._cloneInto();
|
|
147
|
+
}
|
|
148
|
+
keccak() {
|
|
149
|
+
require_utils.swap32IfBE(this.state32);
|
|
150
|
+
keccakP(this.state32, this.rounds);
|
|
151
|
+
require_utils.swap32IfBE(this.state32);
|
|
152
|
+
this.posOut = 0;
|
|
153
|
+
this.pos = 0;
|
|
154
|
+
}
|
|
155
|
+
update(data) {
|
|
156
|
+
require_utils.aexists(this);
|
|
157
|
+
require_utils.abytes(data);
|
|
158
|
+
const { blockLen, state } = this;
|
|
159
|
+
const len = data.length;
|
|
160
|
+
for (let pos = 0; pos < len;) {
|
|
161
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
162
|
+
for (let i = 0; i < take; i++) state[this.pos++] ^= data[pos++];
|
|
163
|
+
if (this.pos === blockLen) this.keccak();
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
finish() {
|
|
168
|
+
if (this.finished) return;
|
|
169
|
+
this.finished = true;
|
|
170
|
+
const { state, suffix, pos, blockLen } = this;
|
|
171
|
+
state[pos] ^= suffix;
|
|
172
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1) this.keccak();
|
|
173
|
+
state[blockLen - 1] ^= 128;
|
|
174
|
+
this.keccak();
|
|
175
|
+
}
|
|
176
|
+
writeInto(out) {
|
|
177
|
+
require_utils.aexists(this, false);
|
|
178
|
+
require_utils.abytes(out);
|
|
179
|
+
this.finish();
|
|
180
|
+
const bufferOut = this.state;
|
|
181
|
+
const { blockLen } = this;
|
|
182
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
183
|
+
if (this.posOut >= blockLen) this.keccak();
|
|
184
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
185
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
186
|
+
this.posOut += take;
|
|
187
|
+
pos += take;
|
|
188
|
+
}
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
xofInto(out) {
|
|
192
|
+
if (!this.enableXOF) throw new Error("XOF is not possible for this instance");
|
|
193
|
+
return this.writeInto(out);
|
|
194
|
+
}
|
|
195
|
+
xof(bytes) {
|
|
196
|
+
require_utils.anumber(bytes);
|
|
197
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
198
|
+
}
|
|
199
|
+
digestInto(out) {
|
|
200
|
+
require_utils.aoutput(out, this);
|
|
201
|
+
if (this.finished) throw new Error("digest() was already called");
|
|
202
|
+
this.writeInto(out.subarray(0, this.outputLen));
|
|
203
|
+
this.destroy();
|
|
204
|
+
}
|
|
205
|
+
digest() {
|
|
206
|
+
const out = new Uint8Array(this.outputLen);
|
|
207
|
+
this.digestInto(out);
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
destroy() {
|
|
211
|
+
this.destroyed = true;
|
|
212
|
+
require_utils.clean(this.state);
|
|
213
|
+
}
|
|
214
|
+
_cloneInto(to) {
|
|
215
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
216
|
+
to ||= new Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
217
|
+
to.blockLen = blockLen;
|
|
218
|
+
to.state32.set(this.state32);
|
|
219
|
+
to.pos = this.pos;
|
|
220
|
+
to.posOut = this.posOut;
|
|
221
|
+
to.finished = this.finished;
|
|
222
|
+
to.rounds = rounds;
|
|
223
|
+
to.suffix = suffix;
|
|
224
|
+
to.outputLen = outputLen;
|
|
225
|
+
to.enableXOF = enableXOF;
|
|
226
|
+
to.canXOF = this.canXOF;
|
|
227
|
+
to.destroyed = this.destroyed;
|
|
228
|
+
return to;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const genKeccak = (suffix, blockLen, outputLen, info = {}) => require_utils.createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
|
|
232
|
+
/**
|
|
233
|
+
* SHA3-224 hash function.
|
|
234
|
+
* @param msg - message bytes to hash
|
|
235
|
+
* @returns Digest bytes.
|
|
236
|
+
* @example
|
|
237
|
+
* Hash a message with SHA3-224.
|
|
238
|
+
* ```ts
|
|
239
|
+
* sha3_224(new Uint8Array([97, 98, 99]));
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
const sha3_224 = /* @__PURE__ */ genKeccak(6, 144, 28, /* @__PURE__ */ require_utils.oidNist(7));
|
|
243
|
+
/**
|
|
244
|
+
* SHA3-256 hash function. Different from keccak-256.
|
|
245
|
+
* @param msg - message bytes to hash
|
|
246
|
+
* @returns Digest bytes.
|
|
247
|
+
* @example
|
|
248
|
+
* Hash a message with SHA3-256.
|
|
249
|
+
* ```ts
|
|
250
|
+
* sha3_256(new Uint8Array([97, 98, 99]));
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
const sha3_256 = /* @__PURE__ */ genKeccak(6, 136, 32, /* @__PURE__ */ require_utils.oidNist(8));
|
|
254
|
+
/**
|
|
255
|
+
* SHA3-384 hash function.
|
|
256
|
+
* @param msg - message bytes to hash
|
|
257
|
+
* @returns Digest bytes.
|
|
258
|
+
* @example
|
|
259
|
+
* Hash a message with SHA3-384.
|
|
260
|
+
* ```ts
|
|
261
|
+
* sha3_384(new Uint8Array([97, 98, 99]));
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
const sha3_384 = /* @__PURE__ */ genKeccak(6, 104, 48, /* @__PURE__ */ require_utils.oidNist(9));
|
|
265
|
+
/**
|
|
266
|
+
* SHA3-512 hash function.
|
|
267
|
+
* @param msg - message bytes to hash
|
|
268
|
+
* @returns Digest bytes.
|
|
269
|
+
* @example
|
|
270
|
+
* Hash a message with SHA3-512.
|
|
271
|
+
* ```ts
|
|
272
|
+
* sha3_512(new Uint8Array([97, 98, 99]));
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
const sha3_512 = /* @__PURE__ */ genKeccak(6, 72, 64, /* @__PURE__ */ require_utils.oidNist(10));
|
|
276
|
+
/**
|
|
277
|
+
* Keccak-224 hash function.
|
|
278
|
+
* @param msg - message bytes to hash
|
|
279
|
+
* @returns Digest bytes.
|
|
280
|
+
* @example
|
|
281
|
+
* Hash a message with Keccak-224.
|
|
282
|
+
* ```ts
|
|
283
|
+
* keccak_224(new Uint8Array([97, 98, 99]));
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
const keccak_224 = /* @__PURE__ */ genKeccak(1, 144, 28);
|
|
287
|
+
/**
|
|
288
|
+
* Keccak-256 hash function. Different from SHA3-256.
|
|
289
|
+
* @param msg - message bytes to hash
|
|
290
|
+
* @returns Digest bytes.
|
|
291
|
+
* @example
|
|
292
|
+
* Hash a message with Keccak-256.
|
|
293
|
+
* ```ts
|
|
294
|
+
* keccak_256(new Uint8Array([97, 98, 99]));
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
const keccak_256 = /* @__PURE__ */ genKeccak(1, 136, 32);
|
|
298
|
+
/**
|
|
299
|
+
* Keccak-384 hash function.
|
|
300
|
+
* @param msg - message bytes to hash
|
|
301
|
+
* @returns Digest bytes.
|
|
302
|
+
* @example
|
|
303
|
+
* Hash a message with Keccak-384.
|
|
304
|
+
* ```ts
|
|
305
|
+
* keccak_384(new Uint8Array([97, 98, 99]));
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
const keccak_384 = /* @__PURE__ */ genKeccak(1, 104, 48);
|
|
309
|
+
/**
|
|
310
|
+
* Keccak-512 hash function.
|
|
311
|
+
* @param msg - message bytes to hash
|
|
312
|
+
* @returns Digest bytes.
|
|
313
|
+
* @example
|
|
314
|
+
* Hash a message with Keccak-512.
|
|
315
|
+
* ```ts
|
|
316
|
+
* keccak_512(new Uint8Array([97, 98, 99]));
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
const keccak_512 = /* @__PURE__ */ genKeccak(1, 72, 64);
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
exports.keccak_224 = keccak_224;
|
|
323
|
+
exports.keccak_256 = keccak_256;
|
|
324
|
+
exports.keccak_384 = keccak_384;
|
|
325
|
+
exports.keccak_512 = keccak_512;
|
|
326
|
+
exports.sha3_224 = sha3_224;
|
|
327
|
+
exports.sha3_256 = sha3_256;
|
|
328
|
+
exports.sha3_384 = sha3_384;
|
|
329
|
+
exports.sha3_512 = sha3_512;
|