@sentio/sdk-bundle 4.0.1-rc.2 → 4.0.1-rc.4
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/assets/chainlink-oracles-sepolia.json +21 -0
- package/assets/chainlink-oracles.json +219 -0
- package/dist/{0x1-B_N1Dd6d.js → 0x1-CWhLCIJf.js} +30 -22
- package/dist/0x1-CWhLCIJf.js.map +1 -0
- package/dist/{AbstractKeylessAccount-dvYSW9Go.js → AbstractKeylessAccount-DE1e2Glg.js} +3 -2
- package/dist/{AbstractKeylessAccount-dvYSW9Go.js.map → AbstractKeylessAccount-DE1e2Glg.js.map} +1 -1
- package/dist/_md-CZAi2AzY.js +644 -0
- package/dist/_md-CZAi2AzY.js.map +1 -0
- package/dist/aptos/builtin/0x1.js +2 -2
- package/dist/aptos/builtin/0x3.js +3 -3
- package/dist/aptos/builtin/0x3.js.map +1 -1
- package/dist/aptos/builtin/0x4.js +3 -3
- package/dist/aptos/builtin/0x4.js.map +1 -1
- package/dist/aptos/builtin/index.js +1 -1
- package/dist/aptos/ext/index.js +2 -2
- package/dist/aptos/index.js +2 -2
- package/dist/{aptos-DPeebJ9j.js → aptos-Cgfa8IQj.js} +257 -47
- package/dist/{aptos-DPeebJ9j.js.map → aptos-Cgfa8IQj.js.map} +1 -1
- package/dist/{coin-DREiK-Br.js → coin-CBrx3CpG.js} +1514 -105
- package/dist/coin-CBrx3CpG.js.map +1 -0
- package/dist/{coin-CWRVUEBa.js → coin-Mht4Jgvj.js} +803 -4
- package/dist/coin-Mht4Jgvj.js.map +1 -0
- package/dist/eth/builtin/eacaggregatorproxy.js +1 -1
- package/dist/eth/builtin/erc1155.js +1 -1
- package/dist/eth/builtin/erc20.js +1 -1
- package/dist/eth/builtin/erc721.js +1 -1
- package/dist/eth/builtin/index.js +1 -1
- package/dist/eth/builtin/weth9.js +1 -1
- package/dist/eth/index.js +1 -1
- package/dist/iota/builtin/0x1.js +3 -3
- package/dist/iota/builtin/0x2.js +168 -5
- package/dist/iota/builtin/0x2.js.map +1 -1
- package/dist/iota/builtin/0x3.js +3 -3
- package/dist/iota/ext/index.js +1 -1
- package/dist/iota/index.js +3 -3
- package/dist/{keyless-B3QnUmtL.js → keyless-nGiRkJjM.js} +1278 -976
- package/dist/keyless-nGiRkJjM.js.map +1 -0
- package/dist/move/index.js +1 -1
- package/dist/{move-Dr-DL5zT.js → move-BVvdKH2Q.js} +7 -7
- package/dist/{move-Dr-DL5zT.js.map → move-BVvdKH2Q.js.map} +1 -1
- package/dist/sui/builtin/0x1.js +1 -1
- package/dist/sui/builtin/0x2.js +4 -4
- package/dist/sui/builtin/0x3.js +4 -4
- package/dist/sui/builtin/index.js +1 -1
- package/dist/sui/ext/index.js +1 -1
- package/dist/sui/index.js +3 -3
- package/dist/{sui-BbKeYXM3.js → sui-BcHp8IsJ.js} +17 -17
- package/dist/{sui-BbKeYXM3.js.map → sui-BcHp8IsJ.js.map} +1 -1
- package/dist/testing/index.js +6 -6
- package/dist/utils/index.js +1 -1
- package/dist/{utils-Jndk-n_F.js → utils-BQ0dnllb.js} +11 -903
- package/dist/utils-BQ0dnllb.js.map +1 -0
- package/package.json +2 -2
- package/assets/chainlink-oracles-sepolia.csv +0 -19
- package/assets/chainlink-oracles.csv +0 -217
- package/dist/0x1-B_N1Dd6d.js.map +0 -1
- package/dist/base-BvfRCgEy.js +0 -959
- package/dist/base-BvfRCgEy.js.map +0 -1
- package/dist/coin-CWRVUEBa.js.map +0 -1
- package/dist/coin-DREiK-Br.js.map +0 -1
- package/dist/dist-CA96PSzE.js +0 -824
- package/dist/dist-CA96PSzE.js.map +0 -1
- package/dist/keyless-B3QnUmtL.js.map +0 -1
- package/dist/utils-Jndk-n_F.js.map +0 -1
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import { a as __name } from "./bignumber-DddanwOv.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/utils.js
|
|
4
|
+
/**
|
|
5
|
+
* Checks if something is Uint8Array. Be careful: nodejs Buffer will return true.
|
|
6
|
+
* @param a - value to test
|
|
7
|
+
* @returns `true` when the value is a Uint8Array-compatible view.
|
|
8
|
+
* @example
|
|
9
|
+
* Check whether a value is a Uint8Array-compatible view.
|
|
10
|
+
* ```ts
|
|
11
|
+
* isBytes(new Uint8Array([1, 2, 3]));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function isBytes(a) {
|
|
15
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Asserts something is a non-negative integer.
|
|
19
|
+
* @param n - number to validate
|
|
20
|
+
* @param title - label included in thrown errors
|
|
21
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
22
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
23
|
+
* @example
|
|
24
|
+
* Validate a non-negative integer option.
|
|
25
|
+
* ```ts
|
|
26
|
+
* anumber(32, 'length');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function anumber(n, title = "") {
|
|
30
|
+
if (typeof n !== "number") {
|
|
31
|
+
const prefix = title && `"${title}" `;
|
|
32
|
+
throw new TypeError(`${prefix}expected number, got ${typeof n}`);
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
35
|
+
const prefix = title && `"${title}" `;
|
|
36
|
+
throw new RangeError(`${prefix}expected integer >= 0, got ${n}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Asserts something is Uint8Array.
|
|
41
|
+
* @param value - value to validate
|
|
42
|
+
* @param length - optional exact length constraint
|
|
43
|
+
* @param title - label included in thrown errors
|
|
44
|
+
* @returns The validated byte array.
|
|
45
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
46
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
47
|
+
* @example
|
|
48
|
+
* Validate that a value is a byte array.
|
|
49
|
+
* ```ts
|
|
50
|
+
* abytes(new Uint8Array([1, 2, 3]));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function abytes(value, length, title = "") {
|
|
54
|
+
const bytes = isBytes(value);
|
|
55
|
+
const len = value?.length;
|
|
56
|
+
const needsLen = length !== void 0;
|
|
57
|
+
if (!bytes || needsLen && len !== length) {
|
|
58
|
+
const prefix = title && `"${title}" `;
|
|
59
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
60
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
61
|
+
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
62
|
+
if (!bytes) throw new TypeError(message);
|
|
63
|
+
throw new RangeError(message);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Asserts something is a wrapped hash constructor.
|
|
69
|
+
* @param h - hash constructor to validate
|
|
70
|
+
* @throws On wrong argument types or invalid hash wrapper shape. {@link TypeError}
|
|
71
|
+
* @throws On invalid hash metadata ranges or values. {@link RangeError}
|
|
72
|
+
* @throws If the hash metadata allows empty outputs or block sizes. {@link Error}
|
|
73
|
+
* @example
|
|
74
|
+
* Validate a callable hash wrapper.
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { ahash } from '@noble/hashes/utils.js';
|
|
77
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
78
|
+
* ahash(sha256);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function ahash(h) {
|
|
82
|
+
if (typeof h !== "function" || typeof h.create !== "function") throw new TypeError("Hash must wrapped by utils.createHasher");
|
|
83
|
+
anumber(h.outputLen);
|
|
84
|
+
anumber(h.blockLen);
|
|
85
|
+
if (h.outputLen < 1) throw new Error("\"outputLen\" must be >= 1");
|
|
86
|
+
if (h.blockLen < 1) throw new Error("\"blockLen\" must be >= 1");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Asserts a hash instance has not been destroyed or finished.
|
|
90
|
+
* @param instance - hash instance to validate
|
|
91
|
+
* @param checkFinished - whether to reject finalized instances
|
|
92
|
+
* @throws If the hash instance has already been destroyed or finalized. {@link Error}
|
|
93
|
+
* @example
|
|
94
|
+
* Validate that a hash instance is still usable.
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { aexists } from '@noble/hashes/utils.js';
|
|
97
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
98
|
+
* const hash = sha256.create();
|
|
99
|
+
* aexists(hash);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function aexists(instance, checkFinished = true) {
|
|
103
|
+
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
104
|
+
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Asserts output is a sufficiently-sized byte array.
|
|
108
|
+
* @param out - destination buffer
|
|
109
|
+
* @param instance - hash instance providing output length
|
|
110
|
+
* Oversized buffers are allowed; downstream code only promises to fill the first `outputLen` bytes.
|
|
111
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
112
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
113
|
+
* @example
|
|
114
|
+
* Validate a caller-provided digest buffer.
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { aoutput } from '@noble/hashes/utils.js';
|
|
117
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
118
|
+
* const hash = sha256.create();
|
|
119
|
+
* aoutput(new Uint8Array(hash.outputLen), hash);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
function aoutput(out, instance) {
|
|
123
|
+
abytes(out, void 0, "digestInto() output");
|
|
124
|
+
const min = instance.outputLen;
|
|
125
|
+
if (out.length < min) throw new RangeError("\"digestInto() output\" expected to be of length >=" + min);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Casts a typed array view to Uint32Array.
|
|
129
|
+
* `arr.byteOffset` must already be 4-byte aligned or the platform
|
|
130
|
+
* Uint32Array constructor will throw.
|
|
131
|
+
* @param arr - source typed array
|
|
132
|
+
* @returns Uint32Array view over the same buffer.
|
|
133
|
+
* @example
|
|
134
|
+
* Reinterpret a byte array as 32-bit words.
|
|
135
|
+
* ```ts
|
|
136
|
+
* u32(new Uint8Array(8));
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
function u32(arr) {
|
|
140
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Zeroizes typed arrays in place. Warning: JS provides no guarantees.
|
|
144
|
+
* @param arrays - arrays to overwrite with zeros
|
|
145
|
+
* @example
|
|
146
|
+
* Zeroize sensitive buffers in place.
|
|
147
|
+
* ```ts
|
|
148
|
+
* clean(new Uint8Array([1, 2, 3]));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
function clean(...arrays) {
|
|
152
|
+
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Creates a DataView for byte-level manipulation.
|
|
156
|
+
* @param arr - source typed array
|
|
157
|
+
* @returns DataView over the same buffer region.
|
|
158
|
+
* @example
|
|
159
|
+
* Create a DataView over an existing buffer.
|
|
160
|
+
* ```ts
|
|
161
|
+
* createView(new Uint8Array(4));
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
function createView(arr) {
|
|
165
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Rotate-right operation for uint32 values.
|
|
169
|
+
* @param word - source word
|
|
170
|
+
* @param shift - shift amount in bits
|
|
171
|
+
* @returns Rotated word.
|
|
172
|
+
* @example
|
|
173
|
+
* Rotate a 32-bit word to the right.
|
|
174
|
+
* ```ts
|
|
175
|
+
* rotr(0x12345678, 8);
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
function rotr(word, shift) {
|
|
179
|
+
return word << 32 - shift | word >>> shift;
|
|
180
|
+
}
|
|
181
|
+
/** Whether the current platform is little-endian. */
|
|
182
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
183
|
+
/**
|
|
184
|
+
* Byte-swap operation for uint32 values.
|
|
185
|
+
* @param word - source word
|
|
186
|
+
* @returns Word with reversed byte order.
|
|
187
|
+
* @example
|
|
188
|
+
* Reverse the byte order of a 32-bit word.
|
|
189
|
+
* ```ts
|
|
190
|
+
* byteSwap(0x11223344);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
function byteSwap(word) {
|
|
194
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Conditionally byte-swaps one 32-bit word on big-endian platforms.
|
|
198
|
+
* @param n - source word
|
|
199
|
+
* @returns Original or byte-swapped word depending on platform endianness.
|
|
200
|
+
* @example
|
|
201
|
+
* Normalize a 32-bit word for host endianness.
|
|
202
|
+
* ```ts
|
|
203
|
+
* swap8IfBE(0x11223344);
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
const swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
207
|
+
/**
|
|
208
|
+
* Byte-swaps every word of a Uint32Array in place.
|
|
209
|
+
* @param arr - array to mutate
|
|
210
|
+
* @returns The same array after mutation; callers pass live state arrays here.
|
|
211
|
+
* @example
|
|
212
|
+
* Reverse the byte order of every word in place.
|
|
213
|
+
* ```ts
|
|
214
|
+
* byteSwap32(new Uint32Array([0x11223344]));
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
function byteSwap32(arr) {
|
|
218
|
+
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
219
|
+
return arr;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Conditionally byte-swaps a Uint32Array on big-endian platforms.
|
|
223
|
+
* @param u - array to normalize for host endianness
|
|
224
|
+
* @returns Original or byte-swapped array depending on platform endianness.
|
|
225
|
+
* On big-endian runtimes this mutates `u` in place via `byteSwap32(...)`.
|
|
226
|
+
* @example
|
|
227
|
+
* Normalize a word array for host endianness.
|
|
228
|
+
* ```ts
|
|
229
|
+
* swap32IfBE(new Uint32Array([0x11223344]));
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
233
|
+
const hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
234
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
235
|
+
/**
|
|
236
|
+
* Convert byte array to hex string.
|
|
237
|
+
* Uses the built-in function when available and assumes it matches the tested
|
|
238
|
+
* fallback semantics.
|
|
239
|
+
* @param bytes - bytes to encode
|
|
240
|
+
* @returns Lowercase hexadecimal string.
|
|
241
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
242
|
+
* @example
|
|
243
|
+
* Convert bytes to lowercase hexadecimal.
|
|
244
|
+
* ```ts
|
|
245
|
+
* bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])); // 'cafe0123'
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
function bytesToHex(bytes) {
|
|
249
|
+
abytes(bytes);
|
|
250
|
+
if (hasHexBuiltin) return bytes.toHex();
|
|
251
|
+
let hex = "";
|
|
252
|
+
for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
|
|
253
|
+
return hex;
|
|
254
|
+
}
|
|
255
|
+
const asciis = {
|
|
256
|
+
_0: 48,
|
|
257
|
+
_9: 57,
|
|
258
|
+
A: 65,
|
|
259
|
+
F: 70,
|
|
260
|
+
a: 97,
|
|
261
|
+
f: 102
|
|
262
|
+
};
|
|
263
|
+
function asciiToBase16(ch) {
|
|
264
|
+
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0;
|
|
265
|
+
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10);
|
|
266
|
+
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Convert hex string to byte array. Uses built-in function, when available.
|
|
270
|
+
* @param hex - hexadecimal string to decode
|
|
271
|
+
* @returns Decoded bytes.
|
|
272
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
273
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
274
|
+
* @example
|
|
275
|
+
* Decode lowercase hexadecimal into bytes.
|
|
276
|
+
* ```ts
|
|
277
|
+
* hexToBytes('cafe0123'); // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
function hexToBytes(hex) {
|
|
281
|
+
if (typeof hex !== "string") throw new TypeError("hex string expected, got " + typeof hex);
|
|
282
|
+
if (hasHexBuiltin) try {
|
|
283
|
+
return Uint8Array.fromHex(hex);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
if (error instanceof SyntaxError) throw new RangeError(error.message);
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
const hl = hex.length;
|
|
289
|
+
const al = hl / 2;
|
|
290
|
+
if (hl % 2) throw new RangeError("hex string expected, got unpadded hex of length " + hl);
|
|
291
|
+
const array = new Uint8Array(al);
|
|
292
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
293
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
294
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
295
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
296
|
+
const char = hex[hi] + hex[hi + 1];
|
|
297
|
+
throw new RangeError("hex string expected, got non-hex character \"" + char + "\" at index " + hi);
|
|
298
|
+
}
|
|
299
|
+
array[ai] = n1 * 16 + n2;
|
|
300
|
+
}
|
|
301
|
+
return array;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Copies several Uint8Arrays into one.
|
|
305
|
+
* @param arrays - arrays to concatenate
|
|
306
|
+
* @returns Concatenated byte array.
|
|
307
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
308
|
+
* @example
|
|
309
|
+
* Concatenate multiple byte arrays.
|
|
310
|
+
* ```ts
|
|
311
|
+
* concatBytes(new Uint8Array([1]), new Uint8Array([2]));
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
function concatBytes(...arrays) {
|
|
315
|
+
let sum = 0;
|
|
316
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
317
|
+
const a = arrays[i];
|
|
318
|
+
abytes(a);
|
|
319
|
+
sum += a.length;
|
|
320
|
+
}
|
|
321
|
+
const res = new Uint8Array(sum);
|
|
322
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
323
|
+
const a = arrays[i];
|
|
324
|
+
res.set(a, pad);
|
|
325
|
+
pad += a.length;
|
|
326
|
+
}
|
|
327
|
+
return res;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Creates a callable hash function from a stateful class constructor.
|
|
331
|
+
* @param hashCons - hash constructor or factory
|
|
332
|
+
* @param info - optional metadata such as DER OID
|
|
333
|
+
* @returns Frozen callable hash wrapper with `.create()`.
|
|
334
|
+
* Wrapper construction eagerly calls `hashCons(undefined)` once to read
|
|
335
|
+
* `outputLen` / `blockLen`, so constructor side effects happen at module
|
|
336
|
+
* init time.
|
|
337
|
+
* @example
|
|
338
|
+
* Wrap a stateful hash constructor into a callable helper.
|
|
339
|
+
* ```ts
|
|
340
|
+
* import { createHasher } from '@noble/hashes/utils.js';
|
|
341
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
342
|
+
* const wrapped = createHasher(sha256.create, { oid: sha256.oid });
|
|
343
|
+
* wrapped(new Uint8Array([1]));
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
function createHasher(hashCons, info = {}) {
|
|
347
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
348
|
+
const tmp = hashCons(void 0);
|
|
349
|
+
hashC.outputLen = tmp.outputLen;
|
|
350
|
+
hashC.blockLen = tmp.blockLen;
|
|
351
|
+
hashC.canXOF = tmp.canXOF;
|
|
352
|
+
hashC.create = (opts) => hashCons(opts);
|
|
353
|
+
Object.assign(hashC, info);
|
|
354
|
+
return Object.freeze(hashC);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Cryptographically secure PRNG backed by `crypto.getRandomValues`.
|
|
358
|
+
* @param bytesLength - number of random bytes to generate
|
|
359
|
+
* @returns Random bytes.
|
|
360
|
+
* The platform `getRandomValues()` implementation still defines any
|
|
361
|
+
* single-call length cap, and this helper rejects oversize requests
|
|
362
|
+
* with a stable library `RangeError` instead of host-specific errors.
|
|
363
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
364
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
365
|
+
* @throws If the current runtime does not provide `crypto.getRandomValues`. {@link Error}
|
|
366
|
+
* @example
|
|
367
|
+
* Generate a fresh random key or nonce.
|
|
368
|
+
* ```ts
|
|
369
|
+
* const key = randomBytes(16);
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
function randomBytes(bytesLength = 32) {
|
|
373
|
+
anumber(bytesLength, "bytesLength");
|
|
374
|
+
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
375
|
+
if (typeof cr?.getRandomValues !== "function") throw new Error("crypto.getRandomValues must be defined");
|
|
376
|
+
if (bytesLength > 65536) throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
|
|
377
|
+
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Creates OID metadata for NIST hashes with prefix `06 09 60 86 48 01 65 03 04 02`.
|
|
381
|
+
* @param suffix - final OID byte for the selected hash.
|
|
382
|
+
* The helper accepts any byte even though only the documented NIST hash
|
|
383
|
+
* suffixes are meaningful downstream.
|
|
384
|
+
* @returns Object containing the DER-encoded OID.
|
|
385
|
+
* @example
|
|
386
|
+
* Build OID metadata for a NIST hash.
|
|
387
|
+
* ```ts
|
|
388
|
+
* oidNist(0x01);
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
const oidNist = (suffix) => ({ oid: Uint8Array.from([
|
|
392
|
+
6,
|
|
393
|
+
9,
|
|
394
|
+
96,
|
|
395
|
+
134,
|
|
396
|
+
72,
|
|
397
|
+
1,
|
|
398
|
+
101,
|
|
399
|
+
3,
|
|
400
|
+
4,
|
|
401
|
+
2,
|
|
402
|
+
suffix
|
|
403
|
+
]) });
|
|
404
|
+
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/_u64.js
|
|
407
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
408
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
409
|
+
function fromBig(n, le = false) {
|
|
410
|
+
if (le) return {
|
|
411
|
+
h: Number(n & U32_MASK64),
|
|
412
|
+
l: Number(n >> _32n & U32_MASK64)
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
416
|
+
l: Number(n & U32_MASK64) | 0
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function split(lst, le = false) {
|
|
420
|
+
const len = lst.length;
|
|
421
|
+
let Ah = new Uint32Array(len);
|
|
422
|
+
let Al = new Uint32Array(len);
|
|
423
|
+
for (let i = 0; i < len; i++) {
|
|
424
|
+
const { h, l } = fromBig(lst[i], le);
|
|
425
|
+
[Ah[i], Al[i]] = [h, l];
|
|
426
|
+
}
|
|
427
|
+
return [Ah, Al];
|
|
428
|
+
}
|
|
429
|
+
const shrSH = (h, _l, s) => h >>> s;
|
|
430
|
+
const shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
431
|
+
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
432
|
+
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
433
|
+
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
434
|
+
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
435
|
+
const rotr32H = (_h, l) => l;
|
|
436
|
+
const rotr32L = (h, _l) => h;
|
|
437
|
+
const rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
438
|
+
const rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
439
|
+
const rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
440
|
+
const rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
441
|
+
function add(Ah, Al, Bh, Bl) {
|
|
442
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
443
|
+
return {
|
|
444
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
445
|
+
l: l | 0
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
449
|
+
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
450
|
+
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
451
|
+
const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
452
|
+
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
453
|
+
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
454
|
+
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@2.2.0/node_modules/@noble/hashes/_md.js
|
|
457
|
+
/**
|
|
458
|
+
* Internal Merkle-Damgard hash utils.
|
|
459
|
+
* @module
|
|
460
|
+
*/
|
|
461
|
+
/**
|
|
462
|
+
* Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
|
|
463
|
+
* Returns bits from `b` when `a` is set, otherwise from `c`.
|
|
464
|
+
* The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
|
|
465
|
+
* set the same bit.
|
|
466
|
+
* @param a - selector word
|
|
467
|
+
* @param b - word chosen when selector bit is set
|
|
468
|
+
* @param c - word chosen when selector bit is clear
|
|
469
|
+
* @returns Mixed 32-bit word.
|
|
470
|
+
* @example
|
|
471
|
+
* Combine three words with the shared 32-bit choice primitive.
|
|
472
|
+
* ```ts
|
|
473
|
+
* Chi(0xffffffff, 0x12345678, 0x87654321);
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
function Chi(a, b, c) {
|
|
477
|
+
return a & b ^ ~a & c;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
|
|
481
|
+
* Returns bits shared by at least two inputs.
|
|
482
|
+
* @param a - first input word
|
|
483
|
+
* @param b - second input word
|
|
484
|
+
* @param c - third input word
|
|
485
|
+
* @returns Mixed 32-bit word.
|
|
486
|
+
* @example
|
|
487
|
+
* Combine three words with the shared 32-bit majority primitive.
|
|
488
|
+
* ```ts
|
|
489
|
+
* Maj(0xffffffff, 0x12345678, 0x87654321);
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
function Maj(a, b, c) {
|
|
493
|
+
return a & b ^ a & c ^ b & c;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Merkle-Damgard hash construction base class.
|
|
497
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
498
|
+
* Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
|
|
499
|
+
* strings with partial-byte tails.
|
|
500
|
+
* @param blockLen - internal block size in bytes
|
|
501
|
+
* @param outputLen - digest size in bytes
|
|
502
|
+
* @param padOffset - trailing length field size in bytes
|
|
503
|
+
* @param isLE - whether length and state words are encoded in little-endian
|
|
504
|
+
* @example
|
|
505
|
+
* Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
|
|
506
|
+
* ```ts
|
|
507
|
+
* import { _SHA1 } from '@noble/hashes/legacy.js';
|
|
508
|
+
* const hash = new _SHA1();
|
|
509
|
+
* hash.update(new Uint8Array([97, 98, 99]));
|
|
510
|
+
* hash.digest();
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
var HashMD = class {
|
|
514
|
+
blockLen;
|
|
515
|
+
outputLen;
|
|
516
|
+
canXOF = false;
|
|
517
|
+
padOffset;
|
|
518
|
+
isLE;
|
|
519
|
+
buffer;
|
|
520
|
+
view;
|
|
521
|
+
finished = false;
|
|
522
|
+
length = 0;
|
|
523
|
+
pos = 0;
|
|
524
|
+
destroyed = false;
|
|
525
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
526
|
+
this.blockLen = blockLen;
|
|
527
|
+
this.outputLen = outputLen;
|
|
528
|
+
this.padOffset = padOffset;
|
|
529
|
+
this.isLE = isLE;
|
|
530
|
+
this.buffer = new Uint8Array(blockLen);
|
|
531
|
+
this.view = createView(this.buffer);
|
|
532
|
+
}
|
|
533
|
+
update(data) {
|
|
534
|
+
aexists(this);
|
|
535
|
+
abytes(data);
|
|
536
|
+
const { view, buffer, blockLen } = this;
|
|
537
|
+
const len = data.length;
|
|
538
|
+
for (let pos = 0; pos < len;) {
|
|
539
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
540
|
+
if (take === blockLen) {
|
|
541
|
+
const dataView = createView(data);
|
|
542
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
546
|
+
this.pos += take;
|
|
547
|
+
pos += take;
|
|
548
|
+
if (this.pos === blockLen) {
|
|
549
|
+
this.process(view, 0);
|
|
550
|
+
this.pos = 0;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
this.length += data.length;
|
|
554
|
+
this.roundClean();
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
digestInto(out) {
|
|
558
|
+
aexists(this);
|
|
559
|
+
aoutput(out, this);
|
|
560
|
+
this.finished = true;
|
|
561
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
562
|
+
let { pos } = this;
|
|
563
|
+
buffer[pos++] = 128;
|
|
564
|
+
clean(this.buffer.subarray(pos));
|
|
565
|
+
if (this.padOffset > blockLen - pos) {
|
|
566
|
+
this.process(view, 0);
|
|
567
|
+
pos = 0;
|
|
568
|
+
}
|
|
569
|
+
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
570
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
571
|
+
this.process(view, 0);
|
|
572
|
+
const oview = createView(out);
|
|
573
|
+
const len = this.outputLen;
|
|
574
|
+
if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
575
|
+
const outLen = len / 4;
|
|
576
|
+
const state = this.get();
|
|
577
|
+
if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
|
|
578
|
+
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
579
|
+
}
|
|
580
|
+
digest() {
|
|
581
|
+
const { buffer, outputLen } = this;
|
|
582
|
+
this.digestInto(buffer);
|
|
583
|
+
const res = buffer.slice(0, outputLen);
|
|
584
|
+
this.destroy();
|
|
585
|
+
return res;
|
|
586
|
+
}
|
|
587
|
+
_cloneInto(to) {
|
|
588
|
+
to ||= new this.constructor();
|
|
589
|
+
to.set(...this.get());
|
|
590
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
591
|
+
to.destroyed = destroyed;
|
|
592
|
+
to.finished = finished;
|
|
593
|
+
to.length = length;
|
|
594
|
+
to.pos = pos;
|
|
595
|
+
if (length % blockLen) to.buffer.set(buffer);
|
|
596
|
+
return to;
|
|
597
|
+
}
|
|
598
|
+
clone() {
|
|
599
|
+
return this._cloneInto();
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
/**
|
|
603
|
+
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
604
|
+
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
605
|
+
*/
|
|
606
|
+
/** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
|
|
607
|
+
* square roots of the first eight prime numbers. Exported as a shared table; callers must treat
|
|
608
|
+
* it as read-only because constructors copy words from it by index. */
|
|
609
|
+
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
610
|
+
1779033703,
|
|
611
|
+
3144134277,
|
|
612
|
+
1013904242,
|
|
613
|
+
2773480762,
|
|
614
|
+
1359893119,
|
|
615
|
+
2600822924,
|
|
616
|
+
528734635,
|
|
617
|
+
1541459225
|
|
618
|
+
]);
|
|
619
|
+
/** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen
|
|
620
|
+
* big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first
|
|
621
|
+
* eight prime numbers. Exported as a shared table; callers must treat it as read-only because
|
|
622
|
+
* constructors copy halves from it by index. */
|
|
623
|
+
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
624
|
+
1779033703,
|
|
625
|
+
4089235720,
|
|
626
|
+
3144134277,
|
|
627
|
+
2227873595,
|
|
628
|
+
1013904242,
|
|
629
|
+
4271175723,
|
|
630
|
+
2773480762,
|
|
631
|
+
1595750129,
|
|
632
|
+
1359893119,
|
|
633
|
+
2917565137,
|
|
634
|
+
2600822924,
|
|
635
|
+
725511199,
|
|
636
|
+
528734635,
|
|
637
|
+
4215389547,
|
|
638
|
+
1541459225,
|
|
639
|
+
327033209
|
|
640
|
+
]);
|
|
641
|
+
|
|
642
|
+
//#endregion
|
|
643
|
+
export { anumber as A, rotr as B, rotrSL as C, abytes as D, split as E, createHasher as F, swap8IfBE as H, hexToBytes as I, isBytes as L, bytesToHex as M, clean as N, aexists as O, concatBytes as P, oidNist as R, rotrSH as S, shrSL as T, u32 as U, swap32IfBE as V, rotlSL as _, SHA512_IV as a, rotrBH as b, add3L as c, add5H as d, add5L as f, rotlSH as g, rotlBL as h, SHA256_IV as i, aoutput as j, ahash as k, add4H as l, rotlBH as m, HashMD as n, add as o, fromBig as p, Maj as r, add3H as s, Chi as t, add4L as u, rotr32H as v, shrSH as w, rotrBL as x, rotr32L as y, randomBytes as z };
|
|
644
|
+
//# sourceMappingURL=_md-CZAi2AzY.js.map
|