@mnemom/mnemom 0.17.36 → 0.17.38-next.0

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 (121) hide show
  1. package/dist/commands/agent-run.d.ts +11 -0
  2. package/dist/commands/agent-run.js +37 -0
  3. package/dist/commands/agent-share-render.d.ts +5 -5
  4. package/dist/commands/agent-share-render.js +9 -7
  5. package/dist/commands/agent-share-test-issuer.d.ts +1 -1
  6. package/dist/commands/agent-share-test-issuer.js +1 -1
  7. package/dist/commands/agent.d.ts +8 -1
  8. package/dist/commands/agent.js +14 -3
  9. package/dist/commands/scan.d.ts +15 -2
  10. package/dist/commands/scan.js +48 -3
  11. package/dist/host/commands.js +4 -1
  12. package/dist/host/owner.d.ts +2 -0
  13. package/dist/host/verbs.d.ts +16 -1
  14. package/dist/host/verbs.js +45 -3
  15. package/dist/index.js +1 -1
  16. package/dist/lib/commit-report.d.ts +7 -13
  17. package/dist/lib/commit-report.js +12 -5
  18. package/dist/lib/conduct-receipt.d.ts +8 -3
  19. package/dist/lib/conduct-receipt.js +29 -7
  20. package/dist/lib/experimental.d.ts +1 -1
  21. package/dist/lib/experimental.js +1 -12
  22. package/dist/lib/runner/executor-client.d.ts +5 -0
  23. package/dist/lib/runner/executor-client.js +8 -0
  24. package/dist/lib/runner/job.d.ts +37 -0
  25. package/dist/lib/runner/job.js +74 -1
  26. package/dist/lib/runner/phases.d.ts +7 -2
  27. package/dist/lib/runner/phases.js +7 -2
  28. package/dist/lib/runner/proxy.d.ts +26 -2
  29. package/dist/lib/runner/proxy.js +33 -1
  30. package/dist/lib/runner/record-commit.d.ts +16 -0
  31. package/dist/lib/runner/record-commit.js +7 -0
  32. package/dist/lib/scan/spend/anthropic-usage.d.ts +20 -1
  33. package/dist/lib/scan/spend/anthropic-usage.js +32 -7
  34. package/dist/lib/scan/spend/anthropic-wif.d.ts +42 -0
  35. package/dist/lib/scan/spend/anthropic-wif.js +153 -0
  36. package/dist/vendor/durable-contract/index.js +6 -3
  37. package/dist/vendor/shared/durable-contract/cli-surface.js +2 -2
  38. package/dist/vendor/shared/durable-contract/codes.js +4 -1
  39. package/package.json +2 -5
  40. package/node_modules/@mnemom/aip-verifier/LICENSE +0 -190
  41. package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.cts +0 -478
  42. package/node_modules/@mnemom/aip-verifier/dist/claim-lint-CVITIRcU.d.ts +0 -478
  43. package/node_modules/@mnemom/aip-verifier/dist/index.cjs +0 -971
  44. package/node_modules/@mnemom/aip-verifier/dist/index.cjs.map +0 -1
  45. package/node_modules/@mnemom/aip-verifier/dist/index.d.cts +0 -330
  46. package/node_modules/@mnemom/aip-verifier/dist/index.d.ts +0 -330
  47. package/node_modules/@mnemom/aip-verifier/dist/index.js +0 -933
  48. package/node_modules/@mnemom/aip-verifier/dist/index.js.map +0 -1
  49. package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs +0 -879
  50. package/node_modules/@mnemom/aip-verifier/dist/render-lines.cjs.map +0 -1
  51. package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.cts +0 -96
  52. package/node_modules/@mnemom/aip-verifier/dist/render-lines.d.ts +0 -96
  53. package/node_modules/@mnemom/aip-verifier/dist/render-lines.js +0 -875
  54. package/node_modules/@mnemom/aip-verifier/dist/render-lines.js.map +0 -1
  55. package/node_modules/@mnemom/aip-verifier/package.json +0 -86
  56. package/node_modules/@noble/ed25519/LICENSE +0 -21
  57. package/node_modules/@noble/ed25519/README.md +0 -371
  58. package/node_modules/@noble/ed25519/index.d.ts +0 -391
  59. package/node_modules/@noble/ed25519/index.js +0 -933
  60. package/node_modules/@noble/ed25519/index.ts +0 -1134
  61. package/node_modules/@noble/ed25519/package.json +0 -54
  62. package/node_modules/@noble/hashes/LICENSE +0 -21
  63. package/node_modules/@noble/hashes/README.md +0 -478
  64. package/node_modules/@noble/hashes/_blake.d.ts +0 -20
  65. package/node_modules/@noble/hashes/_blake.js +0 -59
  66. package/node_modules/@noble/hashes/_md.d.ts +0 -95
  67. package/node_modules/@noble/hashes/_md.js +0 -209
  68. package/node_modules/@noble/hashes/_u64.d.ts +0 -36
  69. package/node_modules/@noble/hashes/_u64.js +0 -77
  70. package/node_modules/@noble/hashes/argon2.d.ts +0 -148
  71. package/node_modules/@noble/hashes/argon2.js +0 -577
  72. package/node_modules/@noble/hashes/blake1.d.ts +0 -162
  73. package/node_modules/@noble/hashes/blake1.js +0 -630
  74. package/node_modules/@noble/hashes/blake2.d.ts +0 -203
  75. package/node_modules/@noble/hashes/blake2.js +0 -573
  76. package/node_modules/@noble/hashes/blake3.d.ts +0 -68
  77. package/node_modules/@noble/hashes/blake3.js +0 -310
  78. package/node_modules/@noble/hashes/eskdf.d.ts +0 -91
  79. package/node_modules/@noble/hashes/eskdf.js +0 -225
  80. package/node_modules/@noble/hashes/hkdf.d.ts +0 -70
  81. package/node_modules/@noble/hashes/hkdf.js +0 -152
  82. package/node_modules/@noble/hashes/hmac.d.ts +0 -50
  83. package/node_modules/@noble/hashes/hmac.js +0 -93
  84. package/node_modules/@noble/hashes/index.d.ts +0 -1
  85. package/node_modules/@noble/hashes/index.js +0 -34
  86. package/node_modules/@noble/hashes/legacy.d.ts +0 -107
  87. package/node_modules/@noble/hashes/legacy.js +0 -348
  88. package/node_modules/@noble/hashes/package.json +0 -91
  89. package/node_modules/@noble/hashes/pbkdf2.d.ts +0 -66
  90. package/node_modules/@noble/hashes/pbkdf2.js +0 -176
  91. package/node_modules/@noble/hashes/scrypt.d.ts +0 -98
  92. package/node_modules/@noble/hashes/scrypt.js +0 -304
  93. package/node_modules/@noble/hashes/sha2.d.ts +0 -176
  94. package/node_modules/@noble/hashes/sha2.js +0 -446
  95. package/node_modules/@noble/hashes/sha3-addons.d.ts +0 -533
  96. package/node_modules/@noble/hashes/sha3-addons.js +0 -973
  97. package/node_modules/@noble/hashes/sha3.d.ts +0 -208
  98. package/node_modules/@noble/hashes/sha3.js +0 -475
  99. package/node_modules/@noble/hashes/src/_blake.ts +0 -67
  100. package/node_modules/@noble/hashes/src/_md.ts +0 -227
  101. package/node_modules/@noble/hashes/src/_u64.ts +0 -111
  102. package/node_modules/@noble/hashes/src/argon2.ts +0 -693
  103. package/node_modules/@noble/hashes/src/blake1.ts +0 -677
  104. package/node_modules/@noble/hashes/src/blake2.ts +0 -648
  105. package/node_modules/@noble/hashes/src/blake3.ts +0 -344
  106. package/node_modules/@noble/hashes/src/eskdf.ts +0 -265
  107. package/node_modules/@noble/hashes/src/hkdf.ts +0 -161
  108. package/node_modules/@noble/hashes/src/hmac.ts +0 -130
  109. package/node_modules/@noble/hashes/src/index.ts +0 -33
  110. package/node_modules/@noble/hashes/src/legacy.ts +0 -361
  111. package/node_modules/@noble/hashes/src/pbkdf2.ts +0 -219
  112. package/node_modules/@noble/hashes/src/scrypt.ts +0 -375
  113. package/node_modules/@noble/hashes/src/sha2.ts +0 -486
  114. package/node_modules/@noble/hashes/src/sha3-addons.ts +0 -1157
  115. package/node_modules/@noble/hashes/src/sha3.ts +0 -525
  116. package/node_modules/@noble/hashes/src/utils.ts +0 -978
  117. package/node_modules/@noble/hashes/src/webcrypto.ts +0 -283
  118. package/node_modules/@noble/hashes/utils.d.ts +0 -560
  119. package/node_modules/@noble/hashes/utils.js +0 -687
  120. package/node_modules/@noble/hashes/webcrypto.d.ts +0 -121
  121. package/node_modules/@noble/hashes/webcrypto.js +0 -228
@@ -1,95 +0,0 @@
1
- import { type Hash, type TArg, type TRet } from './utils.ts';
2
- /**
3
- * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
4
- * Returns bits from `b` when `a` is set, otherwise from `c`.
5
- * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
6
- * set the same bit.
7
- * @param a - selector word
8
- * @param b - word chosen when selector bit is set
9
- * @param c - word chosen when selector bit is clear
10
- * @returns Mixed 32-bit word.
11
- * @example
12
- * Combine three words with the shared 32-bit choice primitive.
13
- * ```ts
14
- * Chi(0xffffffff, 0x12345678, 0x87654321);
15
- * ```
16
- */
17
- export declare function Chi(a: number, b: number, c: number): number;
18
- /**
19
- * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
20
- * Returns bits shared by at least two inputs.
21
- * @param a - first input word
22
- * @param b - second input word
23
- * @param c - third input word
24
- * @returns Mixed 32-bit word.
25
- * @example
26
- * Combine three words with the shared 32-bit majority primitive.
27
- * ```ts
28
- * Maj(0xffffffff, 0x12345678, 0x87654321);
29
- * ```
30
- */
31
- export declare function Maj(a: number, b: number, c: number): number;
32
- /**
33
- * Merkle-Damgard hash construction base class.
34
- * Could be used to create MD5, RIPEMD, SHA1, SHA2.
35
- * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
36
- * strings with partial-byte tails.
37
- * @param blockLen - internal block size in bytes
38
- * @param outputLen - digest size in bytes
39
- * @param padOffset - trailing length field size in bytes
40
- * @param isLE - whether length and state words are encoded in little-endian
41
- * @example
42
- * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
43
- * ```ts
44
- * import { _SHA1 } from '@noble/hashes/legacy.js';
45
- * const hash = new _SHA1();
46
- * hash.update(new Uint8Array([97, 98, 99]));
47
- * hash.digest();
48
- * ```
49
- */
50
- export declare abstract class HashMD<T extends HashMD<T>> implements Hash<T> {
51
- protected abstract process(buf: DataView, offset: number): void;
52
- protected abstract get(): number[];
53
- protected abstract set(...args: number[]): void;
54
- abstract _cloneInto(to?: T): T;
55
- abstract destroy(): void;
56
- protected abstract roundClean(): void;
57
- readonly blockLen: number;
58
- readonly outputLen: number;
59
- readonly canXOF = false;
60
- readonly padOffset: number;
61
- readonly isLE: boolean;
62
- protected buffer: Uint8Array;
63
- protected view: DataView;
64
- protected finished: boolean;
65
- protected length: number;
66
- protected pos: number;
67
- protected destroyed: boolean;
68
- constructor(blockLen: number, outputLen: number, padOffset: number, isLE: boolean);
69
- update(data: TArg<Uint8Array>): this;
70
- digestInto(out: TArg<Uint8Array>): void;
71
- digest(): TRet<Uint8Array>;
72
- protected _cloneIntoMeta(to: T): T;
73
- clone(): T;
74
- }
75
- /**
76
- * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
77
- * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
78
- */
79
- /** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
80
- * square roots of the first eight prime numbers. Exported as a shared table; callers must treat
81
- * it as read-only because constructors copy words from it by index. */
82
- export declare const SHA256_IV: TRet<Uint32Array>;
83
- /** Initial SHA224 state `H(0)` from RFC 6234 §6.1. Exported as a shared table; callers must
84
- * treat it as read-only because constructors copy words from it by index. */
85
- export declare const SHA224_IV: TRet<Uint32Array>;
86
- /** Initial SHA384 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
87
- * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the ninth
88
- * through sixteenth prime numbers. Exported as a shared table; callers must treat it as read-only
89
- * because constructors copy halves from it by index. */
90
- export declare const SHA384_IV: TRet<Uint32Array>;
91
- /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
92
- * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
93
- * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
94
- * constructors copy halves from it by index. */
95
- export declare const SHA512_IV: TRet<Uint32Array>;
@@ -1,209 +0,0 @@
1
- /**
2
- * Internal Merkle-Damgard hash utils.
3
- * @module
4
- */
5
- import { setU64FromNum } from "./_u64.js";
6
- import { abytes, aexists, aoutput, createView } from "./utils.js";
7
- /**
8
- * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
9
- * Returns bits from `b` when `a` is set, otherwise from `c`.
10
- * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
11
- * set the same bit.
12
- * @param a - selector word
13
- * @param b - word chosen when selector bit is set
14
- * @param c - word chosen when selector bit is clear
15
- * @returns Mixed 32-bit word.
16
- * @example
17
- * Combine three words with the shared 32-bit choice primitive.
18
- * ```ts
19
- * Chi(0xffffffff, 0x12345678, 0x87654321);
20
- * ```
21
- */
22
- export function Chi(a, b, c) {
23
- return (a & b) ^ (~a & c);
24
- }
25
- /**
26
- * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
27
- * Returns bits shared by at least two inputs.
28
- * @param a - first input word
29
- * @param b - second input word
30
- * @param c - third input word
31
- * @returns Mixed 32-bit word.
32
- * @example
33
- * Combine three words with the shared 32-bit majority primitive.
34
- * ```ts
35
- * Maj(0xffffffff, 0x12345678, 0x87654321);
36
- * ```
37
- */
38
- export function Maj(a, b, c) {
39
- return (a & b) ^ (a & c) ^ (b & c);
40
- }
41
- /**
42
- * Merkle-Damgard hash construction base class.
43
- * Could be used to create MD5, RIPEMD, SHA1, SHA2.
44
- * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
45
- * strings with partial-byte tails.
46
- * @param blockLen - internal block size in bytes
47
- * @param outputLen - digest size in bytes
48
- * @param padOffset - trailing length field size in bytes
49
- * @param isLE - whether length and state words are encoded in little-endian
50
- * @example
51
- * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
52
- * ```ts
53
- * import { _SHA1 } from '@noble/hashes/legacy.js';
54
- * const hash = new _SHA1();
55
- * hash.update(new Uint8Array([97, 98, 99]));
56
- * hash.digest();
57
- * ```
58
- */
59
- export class HashMD {
60
- blockLen;
61
- outputLen;
62
- canXOF = false;
63
- padOffset;
64
- isLE;
65
- // For partial updates less than block size
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 = createView(this.buffer);
79
- }
80
- update(data) {
81
- aexists(this);
82
- abytes(data);
83
- const { view, buffer, blockLen } = this;
84
- const len = data.length;
85
- let processed = false;
86
- for (let pos = 0; pos < len;) {
87
- const take = Math.min(blockLen - this.pos, len - pos);
88
- // Fast path only when there is no buffered partial block: `take === blockLen` implies
89
- // `this.pos === 0`, so we can process full blocks directly from the input view.
90
- if (take === blockLen) {
91
- const dataView = createView(data);
92
- for (; blockLen <= len - pos; pos += blockLen)
93
- this.process(dataView, pos);
94
- processed = true;
95
- continue;
96
- }
97
- // When the whole input is buffered in one go (common for short messages), passing `data`
98
- // directly avoids allocating a subarray view.
99
- buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
100
- this.pos += take;
101
- pos += take;
102
- if (this.pos === blockLen) {
103
- this.process(view, 0);
104
- this.pos = 0;
105
- processed = true;
106
- }
107
- }
108
- this.length += data.length;
109
- // Shared schedule buffers only pick up input-derived words inside process(); if everything
110
- // was buffered without processing, there is nothing to zero.
111
- if (processed)
112
- this.roundClean();
113
- return this;
114
- }
115
- digestInto(out) {
116
- aexists(this);
117
- aoutput(out, this);
118
- this.finished = true;
119
- // Padding
120
- // We can avoid allocation of buffer for padding completely if it
121
- // was previously not allocated here. But it won't change performance.
122
- const { buffer, view, blockLen, isLE } = this;
123
- let { pos } = this;
124
- // append the bit '1' to the message, then zero-pad the rest of the block
125
- buffer[pos++] = 0b10000000;
126
- buffer.fill(0, pos);
127
- // we have less than padOffset left in buffer, so we cannot put length in
128
- // current block, need process it and pad again
129
- if (this.padOffset > blockLen - pos) {
130
- this.process(view, 0);
131
- buffer.fill(0);
132
- }
133
- // `padOffset` reserves the whole length field. For SHA-384/512 the high 64 bits stay zero from
134
- // the padding fill above, and JS will overflow before user input can make that half non-zero.
135
- // So we only need to write the low 64 bits here (`length * 8` only scales the exponent of an
136
- // integer below 2**53, so the split inside the helper stays exact).
137
- setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
138
- this.process(view, 0);
139
- // The final block above is processed outside update(), so the shared message-schedule
140
- // buffers (e.g. SHA256_W) would otherwise retain input-derived words after digest().
141
- this.roundClean();
142
- // digest() passes our own `buffer` as `out`; reuse its cached view instead of allocating one.
143
- const oview = out === buffer ? view : createView(out);
144
- const len = this.outputLen;
145
- // NOTE: we do division by 4 later, which must be fused in single op with modulo by JIT
146
- const outLen = len / 4;
147
- const state = this.get();
148
- // Subclass-misconfiguration invariant: outputLen must be 32-bit aligned and fit the state.
149
- if (len % 4 || outLen > state.length)
150
- throw new Error('invalid outputLen');
151
- for (let i = 0; i < outLen; i++)
152
- oview.setUint32(4 * i, state[i], isLE);
153
- }
154
- digest() {
155
- const { buffer, outputLen } = this;
156
- this.digestInto(buffer);
157
- // Copy before destroy(): subclasses wipe `buffer` during cleanup, but `digest()` must return
158
- // fresh bytes to the caller.
159
- const res = buffer.slice(0, outputLen);
160
- this.destroy();
161
- return res;
162
- }
163
- _cloneIntoMeta(to) {
164
- const { buffer, length, finished, destroyed, pos } = this;
165
- to.destroyed = destroyed;
166
- to.finished = finished;
167
- to.length = length;
168
- to.pos = pos;
169
- // Only partial-block bytes need copying: when `length % blockLen === 0`, `pos === 0` and
170
- // later `update()` / `digestInto()` overwrite `to.buffer` from the start before reading it.
171
- if (pos)
172
- to.buffer.set(buffer); // Avoid a hot modulo guard.
173
- return to;
174
- }
175
- clone() {
176
- return this._cloneInto();
177
- }
178
- }
179
- /**
180
- * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
181
- * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
182
- */
183
- /** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
184
- * square roots of the first eight prime numbers. Exported as a shared table; callers must treat
185
- * it as read-only because constructors copy words from it by index. */
186
- export const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
187
- 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
188
- ]);
189
- /** Initial SHA224 state `H(0)` from RFC 6234 §6.1. Exported as a shared table; callers must
190
- * treat it as read-only because constructors copy words from it by index. */
191
- export const SHA224_IV = /* @__PURE__ */ Uint32Array.from([
192
- 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
193
- ]);
194
- /** Initial SHA384 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
195
- * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the ninth
196
- * through sixteenth prime numbers. Exported as a shared table; callers must treat it as read-only
197
- * because constructors copy halves from it by index. */
198
- export const SHA384_IV = /* @__PURE__ */ Uint32Array.from([
199
- 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,
200
- 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,
201
- ]);
202
- /** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
203
- * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
204
- * eight prime numbers. Exported as a shared table; callers must treat it as read-only because
205
- * constructors copy halves from it by index. */
206
- export const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
207
- 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,
208
- 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
209
- ]);
@@ -1,36 +0,0 @@
1
- /**
2
- * Internal helpers for u64.
3
- * BigUint64Array is too slow as per 2026, so we implement it using
4
- * Uint32Array.
5
- * @privateRemarks TODO: re-check {@link https://issues.chromium.org/issues/42212588}
6
- * @module
7
- */
8
- import type { TRet } from './utils.ts';
9
- declare function fromBig(n: bigint, le?: boolean): {
10
- h: number;
11
- l: number;
12
- };
13
- declare function split(lst: bigint[], le?: boolean): TRet<Uint32Array[]>;
14
- declare const toBig: (h: number, l: number) => bigint;
15
- declare const fromNumH: (n: number) => number;
16
- declare const fromNumL: (n: number) => number;
17
- declare function setU64FromNum(view: DataView, byteOffset: number, n: number, isLE: boolean): void;
18
- declare const shrSH: (h: number, _l: number, s: number) => number;
19
- declare const shrSL: (h: number, l: number, s: number) => number;
20
- declare const rotrSH: (h: number, l: number, s: number) => number;
21
- declare const rotrSL: (h: number, l: number, s: number) => number;
22
- declare const rotrBH: (h: number, l: number, s: number) => number;
23
- declare const rotrBL: (h: number, l: number, s: number) => number;
24
- declare const rotr32H: (_h: number, l: number) => number;
25
- declare const rotr32L: (h: number, _l: number) => number;
26
- declare function add(Ah: number, Al: number, Bh: number, Bl: number): {
27
- h: number;
28
- l: number;
29
- };
30
- declare const add3L: (Al: number, Bl: number, Cl: number) => number;
31
- declare const add3H: (low: number, Ah: number, Bh: number, Ch: number) => number;
32
- declare const add4L: (Al: number, Bl: number, Cl: number, Dl: number) => number;
33
- declare const add4H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number) => number;
34
- declare const add5L: (Al: number, Bl: number, Cl: number, Dl: number, El: number) => number;
35
- declare const add5H: (low: number, Ah: number, Bh: number, Ch: number, Dh: number, Eh: number) => number;
36
- export { add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, fromNumH, fromNumL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, setU64FromNum, shrSH, shrSL, split, toBig };
@@ -1,77 +0,0 @@
1
- const U32_MASK64 = /* @__PURE__ */ (() => BigInt(2 ** 32 - 1))();
2
- const _32n = /* @__PURE__ */ BigInt(32);
3
- // Split bigint into two 32-bit halves. With `le=true`, returned fields become `{ h: low, l: high
4
- // }` to match little-endian word order rather than the property names.
5
- function fromBig(n, le = false) {
6
- if (le)
7
- return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
8
- return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
9
- }
10
- // Split bigint list into `[highWords, lowWords]` when `le=false`; with `le=true`, the first array
11
- // holds the low halves because `fromBig(...)` swaps the semantic meaning of `h` and `l`.
12
- function split(lst, le = false) {
13
- const len = lst.length;
14
- let Ah = new Uint32Array(len);
15
- let Al = new Uint32Array(len);
16
- for (let i = 0; i < len; i++) {
17
- const { h, l } = fromBig(lst[i], le);
18
- [Ah[i], Al[i]] = [h, l];
19
- }
20
- return [Ah, Al];
21
- }
22
- // Combine explicit `(high, low)` 32-bit halves into a bigint; `>>> 0` normalizes signed JS
23
- // bitwise results back to uint32 first, and little-endian callers must swap.
24
- const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
25
- // Split a JS number into u32 halves without a BigInt allocation. Exact only for integers
26
- // `0 <= n < 2**53`; callers use it on byte / bit counters, which JS length math caps far below
27
- // that (an ArrayBuffer cannot exceed 2**53 - 1 bytes).
28
- const fromNumH = (n) => (n / 2 ** 32) | 0;
29
- const fromNumL = (n) => n >>> 0;
30
- // Drop-in replacement for `view.setBigUint64(byteOffset, BigInt(n), isLE)` without the per-call
31
- // BigInt allocation. Same `n < 2**53` precondition as `fromNumH`/`fromNumL`.
32
- function setU64FromNum(view, byteOffset, n, isLE) {
33
- const h = fromNumH(n);
34
- const l = fromNumL(n);
35
- view.setUint32(byteOffset, isLE ? l : h, isLE);
36
- view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
37
- }
38
- // High 32-bit half of a 64-bit logical right shift for `s` in `0..31`.
39
- const shrSH = (h, _l, s) => h >>> s;
40
- // Low 32-bit half of a 64-bit logical right shift, valid for `s` in `1..31`.
41
- const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
42
- // High 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
43
- const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
44
- // Low 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.
45
- const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
46
- // High 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
47
- const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
48
- // Low 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.
49
- const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
50
- // High 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped low half.
51
- const rotr32H = (_h, l) => l;
52
- // Low 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped high half.
53
- const rotr32L = (h, _l) => h;
54
- // 64-bit left rotates (rotl*) are not defined here: sha3.ts, their only consumer, keeps
55
- // local copies so V8 inlines them into keccakP.
56
- // Add two split 64-bit words and return the split `{ h, l }` sum.
57
- // JS uses 32-bit signed integers for bitwise operations, so we cannot simply shift the carry out
58
- // of the low sum and instead use division.
59
- function add(Ah, Al, Bh, Bl) {
60
- const l = (Al >>> 0) + (Bl >>> 0);
61
- return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
62
- }
63
- // Addition with more than 2 elements
64
- // Unmasked low-word accumulator for 3-way addition; pass the raw result into `add3H(...)`.
65
- const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
66
- // High-word finalize step for 3-way addition; `low` must be the untruncated output of `add3L(...)`.
67
- const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
68
- // Unmasked low-word accumulator for 4-way addition; pass the raw result into `add4H(...)`.
69
- const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
70
- // High-word finalize step for 4-way addition; `low` must be the untruncated output of `add4L(...)`.
71
- const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
72
- // Unmasked low-word accumulator for 5-way addition; pass the raw result into `add5H(...)`.
73
- const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
74
- // High-word finalize step for 5-way addition; `low` must be the untruncated output of `add5L(...)`.
75
- const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
76
- // prettier-ignore
77
- export { add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, fromNumH, fromNumL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, setU64FromNum, shrSH, shrSL, split, toBig };
@@ -1,148 +0,0 @@
1
- import { type KDFInput, type TArg, type TRet } from './utils.ts';
2
- /** Argon2 cost, output, and optional secret/personalization inputs. */
3
- export type ArgonOpts = {
4
- /** Time cost measured in iterations. Defaults to `3`. */
5
- t?: number;
6
- /** Memory cost in kibibytes. Defaults to `1024 ** 2` (1 GiB). */
7
- m?: number;
8
- /** Parallelization parameter. Defaults to `1`. */
9
- p?: number;
10
- /** Argon2 version number. Defaults to `0x13`. */
11
- version?: number;
12
- /** Optional secret key mixed into initialization. */
13
- key?: KDFInput;
14
- /** Optional personalization string or bytes. */
15
- personalization?: KDFInput;
16
- /** Desired output length in bytes. RFC 9106 §3.1 requires `T` in the 4..(2^32 - 1) range. */
17
- dkLen?: number;
18
- /** Max scheduler block time in milliseconds for the async variants. */
19
- asyncTick?: number;
20
- /** Maximum temporary memory budget in bytes. Defaults to 1 GiB. */
21
- maxmem?: number;
22
- /**
23
- * Optional progress callback invoked during long-running derivations.
24
- * @param progress - completion fraction in the `0..1` range
25
- */
26
- onProgress?: (progress: number) => void;
27
- };
28
- /**
29
- * Argon2d GPU-resistant version.
30
- * @param password - password or input key material
31
- * @param salt - unique salt value
32
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
33
- * @returns Derived key bytes.
34
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
35
- * @example
36
- * Derive a key with Argon2d.
37
- * ```ts
38
- * argon2d('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
39
- * ```
40
- * @example
41
- * Derive a key with optional secret and scheduler controls.
42
- * ```ts
43
- * const progressLog: number[] = [];
44
- * argon2d('password', 'salt1234', {
45
- * t: 1,
46
- * m: 8,
47
- * p: 1,
48
- * dkLen: 32,
49
- * version: 0x13,
50
- * key: 'secret',
51
- * personalization: 'application',
52
- * maxmem: 1024 * 1024,
53
- * asyncTick: 1,
54
- * onProgress(progress) {
55
- * progressLog.push(progress);
56
- * },
57
- * });
58
- * ```
59
- */
60
- export declare const argon2d: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => TRet<Uint8Array>;
61
- /**
62
- * Argon2i side-channel-resistant version.
63
- * @param password - password or input key material
64
- * @param salt - unique salt value
65
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
66
- * @returns Derived key bytes.
67
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
68
- * @example
69
- * Derive a key with Argon2i.
70
- * ```ts
71
- * argon2i('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
72
- * ```
73
- */
74
- export declare const argon2i: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => TRet<Uint8Array>;
75
- /**
76
- * Argon2id, combining i+d, the most popular version from RFC 9106.
77
- * @param password - password or input key material
78
- * @param salt - unique salt value
79
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
80
- * @returns Derived key bytes.
81
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
82
- * @example
83
- * Derive a key with Argon2id.
84
- * ```ts
85
- * argon2id('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
86
- * ```
87
- */
88
- export declare const argon2id: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => TRet<Uint8Array>;
89
- /**
90
- * Argon2d async GPU-resistant version.
91
- * @param password - password or input key material
92
- * @param salt - unique salt value
93
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
94
- * @returns Promise resolving to derived key bytes.
95
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
96
- * @example
97
- * Derive a key with Argon2d asynchronously.
98
- * ```ts
99
- * await argon2dAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
100
- * ```
101
- * @example
102
- * Derive a key asynchronously with optional secret and scheduler controls.
103
- * ```ts
104
- * await argon2dAsync('password', 'salt1234', {
105
- * t: 1,
106
- * m: 8,
107
- * p: 1,
108
- * dkLen: 32,
109
- * version: 0x13,
110
- * key: 'secret',
111
- * personalization: 'application',
112
- * maxmem: 1024 * 1024,
113
- * asyncTick: 1,
114
- * onProgress(progress) {
115
- * if (progress > 1) throw new Error('invalid progress');
116
- * },
117
- * });
118
- * ```
119
- */
120
- export declare const argon2dAsync: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => Promise<TRet<Uint8Array>>;
121
- /**
122
- * Argon2i async side-channel-resistant version.
123
- * @param password - password or input key material
124
- * @param salt - unique salt value
125
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
126
- * @returns Promise resolving to derived key bytes.
127
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
128
- * @example
129
- * Derive a key with Argon2i asynchronously.
130
- * ```ts
131
- * await argon2iAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
132
- * ```
133
- */
134
- export declare const argon2iAsync: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => Promise<TRet<Uint8Array>>;
135
- /**
136
- * Argon2id async, combining i+d, the most popular version from RFC 9106.
137
- * @param password - password or input key material
138
- * @param salt - unique salt value
139
- * @param opts - Argon2 cost and optional tuning parameters. See {@link ArgonOpts}.
140
- * @returns Promise resolving to derived key bytes.
141
- * @throws If the Argon2 input or cost parameters are invalid. {@link Error}
142
- * @example
143
- * Derive a key with Argon2id asynchronously.
144
- * ```ts
145
- * await argon2idAsync('password', 'salt1234', { t: 1, m: 8, p: 1, dkLen: 32 });
146
- * ```
147
- */
148
- export declare const argon2idAsync: (password: TArg<KDFInput>, salt: TArg<KDFInput>, opts?: TArg<ArgonOpts>) => Promise<TRet<Uint8Array>>;