@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
package/dist/base-BvfRCgEy.js
DELETED
|
@@ -1,959 +0,0 @@
|
|
|
1
|
-
import { a as __name } from "./bignumber-DddanwOv.js";
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
|
|
4
|
-
/**
|
|
5
|
-
* Utilities for hex, bytes, CSPRNG.
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
-
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
10
|
-
function isBytes$1(a) {
|
|
11
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
12
|
-
}
|
|
13
|
-
__name(isBytes$1, "isBytes");
|
|
14
|
-
/** Asserts something is positive integer. */
|
|
15
|
-
function anumber$1(n, title = "") {
|
|
16
|
-
if (!Number.isSafeInteger(n) || n < 0) {
|
|
17
|
-
const prefix = title && `"${title}" `;
|
|
18
|
-
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
__name(anumber$1, "anumber");
|
|
22
|
-
/** Asserts something is Uint8Array. */
|
|
23
|
-
function abytes$1(value, length, title = "") {
|
|
24
|
-
const bytes = isBytes$1(value);
|
|
25
|
-
const len = value?.length;
|
|
26
|
-
const needsLen = length !== void 0;
|
|
27
|
-
if (!bytes || needsLen && len !== length) {
|
|
28
|
-
const prefix = title && `"${title}" `;
|
|
29
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
30
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
31
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
__name(abytes$1, "abytes");
|
|
36
|
-
/** Asserts something is hash */
|
|
37
|
-
function ahash(h) {
|
|
38
|
-
if (typeof h !== "function" || typeof h.create !== "function") throw new Error("Hash must wrapped by utils.createHasher");
|
|
39
|
-
anumber$1(h.outputLen);
|
|
40
|
-
anumber$1(h.blockLen);
|
|
41
|
-
}
|
|
42
|
-
/** Asserts a hash instance has not been destroyed / finished */
|
|
43
|
-
function aexists(instance, checkFinished = true) {
|
|
44
|
-
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
45
|
-
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
46
|
-
}
|
|
47
|
-
/** Asserts output is properly-sized byte array */
|
|
48
|
-
function aoutput(out, instance) {
|
|
49
|
-
abytes$1(out, void 0, "digestInto() output");
|
|
50
|
-
const min = instance.outputLen;
|
|
51
|
-
if (out.length < min) throw new Error("\"digestInto() output\" expected to be of length >=" + min);
|
|
52
|
-
}
|
|
53
|
-
/** Cast u8 / u16 / u32 to u32. */
|
|
54
|
-
function u32(arr) {
|
|
55
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
56
|
-
}
|
|
57
|
-
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
58
|
-
function clean(...arrays) {
|
|
59
|
-
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
60
|
-
}
|
|
61
|
-
/** Create DataView of an array for easy byte-level manipulation. */
|
|
62
|
-
function createView(arr) {
|
|
63
|
-
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
64
|
-
}
|
|
65
|
-
/** The rotate right (circular right shift) operation for uint32 */
|
|
66
|
-
function rotr(word, shift) {
|
|
67
|
-
return word << 32 - shift | word >>> shift;
|
|
68
|
-
}
|
|
69
|
-
/** The rotate left (circular left shift) operation for uint32 */
|
|
70
|
-
function rotl(word, shift) {
|
|
71
|
-
return word << shift | word >>> 32 - shift >>> 0;
|
|
72
|
-
}
|
|
73
|
-
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
74
|
-
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
75
|
-
/** The byte swap operation for uint32 */
|
|
76
|
-
function byteSwap(word) {
|
|
77
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
78
|
-
}
|
|
79
|
-
/** Conditionally byte swap if on a big-endian platform */
|
|
80
|
-
const swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
|
|
81
|
-
/** In place byte swap for Uint32Array */
|
|
82
|
-
function byteSwap32(arr) {
|
|
83
|
-
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
84
|
-
return arr;
|
|
85
|
-
}
|
|
86
|
-
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
87
|
-
const hasHexBuiltin$1 = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
88
|
-
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
89
|
-
/**
|
|
90
|
-
* Convert byte array to hex string. Uses built-in function, when available.
|
|
91
|
-
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
92
|
-
*/
|
|
93
|
-
function bytesToHex(bytes) {
|
|
94
|
-
abytes$1(bytes);
|
|
95
|
-
if (hasHexBuiltin$1) return bytes.toHex();
|
|
96
|
-
let hex = "";
|
|
97
|
-
for (let i = 0; i < bytes.length; i++) hex += hexes[bytes[i]];
|
|
98
|
-
return hex;
|
|
99
|
-
}
|
|
100
|
-
const asciis = {
|
|
101
|
-
_0: 48,
|
|
102
|
-
_9: 57,
|
|
103
|
-
A: 65,
|
|
104
|
-
F: 70,
|
|
105
|
-
a: 97,
|
|
106
|
-
f: 102
|
|
107
|
-
};
|
|
108
|
-
function asciiToBase16(ch) {
|
|
109
|
-
if (ch >= asciis._0 && ch <= asciis._9) return ch - asciis._0;
|
|
110
|
-
if (ch >= asciis.A && ch <= asciis.F) return ch - (asciis.A - 10);
|
|
111
|
-
if (ch >= asciis.a && ch <= asciis.f) return ch - (asciis.a - 10);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Convert hex string to byte array. Uses built-in function, when available.
|
|
115
|
-
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
116
|
-
*/
|
|
117
|
-
function hexToBytes(hex) {
|
|
118
|
-
if (typeof hex !== "string") throw new Error("hex string expected, got " + typeof hex);
|
|
119
|
-
if (hasHexBuiltin$1) return Uint8Array.fromHex(hex);
|
|
120
|
-
const hl = hex.length;
|
|
121
|
-
const al = hl / 2;
|
|
122
|
-
if (hl % 2) throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
123
|
-
const array = new Uint8Array(al);
|
|
124
|
-
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
125
|
-
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
126
|
-
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
127
|
-
if (n1 === void 0 || n2 === void 0) {
|
|
128
|
-
const char = hex[hi] + hex[hi + 1];
|
|
129
|
-
throw new Error("hex string expected, got non-hex character \"" + char + "\" at index " + hi);
|
|
130
|
-
}
|
|
131
|
-
array[ai] = n1 * 16 + n2;
|
|
132
|
-
}
|
|
133
|
-
return array;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Converts string to bytes using UTF8 encoding.
|
|
137
|
-
* Built-in doesn't validate input to be string: we do the check.
|
|
138
|
-
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
139
|
-
*/
|
|
140
|
-
function utf8ToBytes(str) {
|
|
141
|
-
if (typeof str !== "string") throw new Error("string expected");
|
|
142
|
-
return new Uint8Array(new TextEncoder().encode(str));
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Helper for KDFs: consumes uint8array or string.
|
|
146
|
-
* When string is passed, does utf8 decoding, using TextDecoder.
|
|
147
|
-
*/
|
|
148
|
-
function kdfInputToBytes(data, errorTitle = "") {
|
|
149
|
-
if (typeof data === "string") return utf8ToBytes(data);
|
|
150
|
-
return abytes$1(data, void 0, errorTitle);
|
|
151
|
-
}
|
|
152
|
-
/** Copies several Uint8Arrays into one. */
|
|
153
|
-
function concatBytes(...arrays) {
|
|
154
|
-
let sum = 0;
|
|
155
|
-
for (let i = 0; i < arrays.length; i++) {
|
|
156
|
-
const a = arrays[i];
|
|
157
|
-
abytes$1(a);
|
|
158
|
-
sum += a.length;
|
|
159
|
-
}
|
|
160
|
-
const res = new Uint8Array(sum);
|
|
161
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
162
|
-
const a = arrays[i];
|
|
163
|
-
res.set(a, pad);
|
|
164
|
-
pad += a.length;
|
|
165
|
-
}
|
|
166
|
-
return res;
|
|
167
|
-
}
|
|
168
|
-
/** Merges default options and passed options. */
|
|
169
|
-
function checkOpts(defaults, opts) {
|
|
170
|
-
if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]") throw new Error("options must be object or undefined");
|
|
171
|
-
return Object.assign(defaults, opts);
|
|
172
|
-
}
|
|
173
|
-
/** Creates function with outputLen, blockLen, create properties from a class constructor. */
|
|
174
|
-
function createHasher(hashCons, info = {}) {
|
|
175
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
176
|
-
const tmp = hashCons(void 0);
|
|
177
|
-
hashC.outputLen = tmp.outputLen;
|
|
178
|
-
hashC.blockLen = tmp.blockLen;
|
|
179
|
-
hashC.create = (opts) => hashCons(opts);
|
|
180
|
-
Object.assign(hashC, info);
|
|
181
|
-
return Object.freeze(hashC);
|
|
182
|
-
}
|
|
183
|
-
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
184
|
-
function randomBytes(bytesLength = 32) {
|
|
185
|
-
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
186
|
-
if (typeof cr?.getRandomValues !== "function") throw new Error("crypto.getRandomValues must be defined");
|
|
187
|
-
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
188
|
-
}
|
|
189
|
-
/** Creates OID opts for NIST hashes, with prefix 06 09 60 86 48 01 65 03 04 02. */
|
|
190
|
-
const oidNist = (suffix) => ({ oid: Uint8Array.from([
|
|
191
|
-
6,
|
|
192
|
-
9,
|
|
193
|
-
96,
|
|
194
|
-
134,
|
|
195
|
-
72,
|
|
196
|
-
1,
|
|
197
|
-
101,
|
|
198
|
-
3,
|
|
199
|
-
4,
|
|
200
|
-
2,
|
|
201
|
-
suffix
|
|
202
|
-
]) });
|
|
203
|
-
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
|
|
206
|
-
/**
|
|
207
|
-
* Internal Merkle-Damgard hash utils.
|
|
208
|
-
* @module
|
|
209
|
-
*/
|
|
210
|
-
/** Choice: a ? b : c */
|
|
211
|
-
function Chi(a, b, c) {
|
|
212
|
-
return a & b ^ ~a & c;
|
|
213
|
-
}
|
|
214
|
-
/** Majority function, true if any two inputs is true. */
|
|
215
|
-
function Maj(a, b, c) {
|
|
216
|
-
return a & b ^ a & c ^ b & c;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Merkle-Damgard hash construction base class.
|
|
220
|
-
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
221
|
-
*/
|
|
222
|
-
var HashMD = class {
|
|
223
|
-
blockLen;
|
|
224
|
-
outputLen;
|
|
225
|
-
padOffset;
|
|
226
|
-
isLE;
|
|
227
|
-
buffer;
|
|
228
|
-
view;
|
|
229
|
-
finished = false;
|
|
230
|
-
length = 0;
|
|
231
|
-
pos = 0;
|
|
232
|
-
destroyed = false;
|
|
233
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
234
|
-
this.blockLen = blockLen;
|
|
235
|
-
this.outputLen = outputLen;
|
|
236
|
-
this.padOffset = padOffset;
|
|
237
|
-
this.isLE = isLE;
|
|
238
|
-
this.buffer = new Uint8Array(blockLen);
|
|
239
|
-
this.view = createView(this.buffer);
|
|
240
|
-
}
|
|
241
|
-
update(data) {
|
|
242
|
-
aexists(this);
|
|
243
|
-
abytes$1(data);
|
|
244
|
-
const { view, buffer, blockLen } = this;
|
|
245
|
-
const len = data.length;
|
|
246
|
-
for (let pos = 0; pos < len;) {
|
|
247
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
248
|
-
if (take === blockLen) {
|
|
249
|
-
const dataView = createView(data);
|
|
250
|
-
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
254
|
-
this.pos += take;
|
|
255
|
-
pos += take;
|
|
256
|
-
if (this.pos === blockLen) {
|
|
257
|
-
this.process(view, 0);
|
|
258
|
-
this.pos = 0;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
this.length += data.length;
|
|
262
|
-
this.roundClean();
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
digestInto(out) {
|
|
266
|
-
aexists(this);
|
|
267
|
-
aoutput(out, this);
|
|
268
|
-
this.finished = true;
|
|
269
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
270
|
-
let { pos } = this;
|
|
271
|
-
buffer[pos++] = 128;
|
|
272
|
-
clean(this.buffer.subarray(pos));
|
|
273
|
-
if (this.padOffset > blockLen - pos) {
|
|
274
|
-
this.process(view, 0);
|
|
275
|
-
pos = 0;
|
|
276
|
-
}
|
|
277
|
-
for (let i = pos; i < blockLen; i++) buffer[i] = 0;
|
|
278
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
279
|
-
this.process(view, 0);
|
|
280
|
-
const oview = createView(out);
|
|
281
|
-
const len = this.outputLen;
|
|
282
|
-
if (len % 4) throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
283
|
-
const outLen = len / 4;
|
|
284
|
-
const state = this.get();
|
|
285
|
-
if (outLen > state.length) throw new Error("_sha2: outputLen bigger than state");
|
|
286
|
-
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
287
|
-
}
|
|
288
|
-
digest() {
|
|
289
|
-
const { buffer, outputLen } = this;
|
|
290
|
-
this.digestInto(buffer);
|
|
291
|
-
const res = buffer.slice(0, outputLen);
|
|
292
|
-
this.destroy();
|
|
293
|
-
return res;
|
|
294
|
-
}
|
|
295
|
-
_cloneInto(to) {
|
|
296
|
-
to ||= new this.constructor();
|
|
297
|
-
to.set(...this.get());
|
|
298
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
299
|
-
to.destroyed = destroyed;
|
|
300
|
-
to.finished = finished;
|
|
301
|
-
to.length = length;
|
|
302
|
-
to.pos = pos;
|
|
303
|
-
if (length % blockLen) to.buffer.set(buffer);
|
|
304
|
-
return to;
|
|
305
|
-
}
|
|
306
|
-
clone() {
|
|
307
|
-
return this._cloneInto();
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
312
|
-
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
313
|
-
*/
|
|
314
|
-
/** Initial SHA256 state. Bits 0..32 of frac part of sqrt of primes 2..19 */
|
|
315
|
-
const SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
316
|
-
1779033703,
|
|
317
|
-
3144134277,
|
|
318
|
-
1013904242,
|
|
319
|
-
2773480762,
|
|
320
|
-
1359893119,
|
|
321
|
-
2600822924,
|
|
322
|
-
528734635,
|
|
323
|
-
1541459225
|
|
324
|
-
]);
|
|
325
|
-
/** Initial SHA512 state. Bits 0..64 of frac part of sqrt of primes 2..19 */
|
|
326
|
-
const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
327
|
-
1779033703,
|
|
328
|
-
4089235720,
|
|
329
|
-
3144134277,
|
|
330
|
-
2227873595,
|
|
331
|
-
1013904242,
|
|
332
|
-
4271175723,
|
|
333
|
-
2773480762,
|
|
334
|
-
1595750129,
|
|
335
|
-
1359893119,
|
|
336
|
-
2917565137,
|
|
337
|
-
2600822924,
|
|
338
|
-
725511199,
|
|
339
|
-
528734635,
|
|
340
|
-
4215389547,
|
|
341
|
-
1541459225,
|
|
342
|
-
327033209
|
|
343
|
-
]);
|
|
344
|
-
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
|
|
347
|
-
/**
|
|
348
|
-
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
349
|
-
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
350
|
-
* @module
|
|
351
|
-
*/
|
|
352
|
-
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
353
|
-
const _32n = /* @__PURE__ */ BigInt(32);
|
|
354
|
-
function fromBig(n, le = false) {
|
|
355
|
-
if (le) return {
|
|
356
|
-
h: Number(n & U32_MASK64),
|
|
357
|
-
l: Number(n >> _32n & U32_MASK64)
|
|
358
|
-
};
|
|
359
|
-
return {
|
|
360
|
-
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
361
|
-
l: Number(n & U32_MASK64) | 0
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function split(lst, le = false) {
|
|
365
|
-
const len = lst.length;
|
|
366
|
-
let Ah = new Uint32Array(len);
|
|
367
|
-
let Al = new Uint32Array(len);
|
|
368
|
-
for (let i = 0; i < len; i++) {
|
|
369
|
-
const { h, l } = fromBig(lst[i], le);
|
|
370
|
-
[Ah[i], Al[i]] = [h, l];
|
|
371
|
-
}
|
|
372
|
-
return [Ah, Al];
|
|
373
|
-
}
|
|
374
|
-
const shrSH = (h, _l, s) => h >>> s;
|
|
375
|
-
const shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
376
|
-
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
377
|
-
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
378
|
-
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
379
|
-
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
380
|
-
const rotr32H = (_h, l) => l;
|
|
381
|
-
const rotr32L = (h, _l) => h;
|
|
382
|
-
function add(Ah, Al, Bh, Bl) {
|
|
383
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
384
|
-
return {
|
|
385
|
-
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
386
|
-
l: l | 0
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
390
|
-
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
391
|
-
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
392
|
-
const add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
393
|
-
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
394
|
-
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
395
|
-
|
|
396
|
-
//#endregion
|
|
397
|
-
//#region ../../node_modules/.pnpm/@scure+base@2.0.0/node_modules/@scure/base/index.js
|
|
398
|
-
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
399
|
-
function isBytes(a) {
|
|
400
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
401
|
-
}
|
|
402
|
-
/** Asserts something is Uint8Array. */
|
|
403
|
-
function abytes(b) {
|
|
404
|
-
if (!isBytes(b)) throw new Error("Uint8Array expected");
|
|
405
|
-
}
|
|
406
|
-
function isArrayOf(isString, arr) {
|
|
407
|
-
if (!Array.isArray(arr)) return false;
|
|
408
|
-
if (arr.length === 0) return true;
|
|
409
|
-
if (isString) return arr.every((item) => typeof item === "string");
|
|
410
|
-
else return arr.every((item) => Number.isSafeInteger(item));
|
|
411
|
-
}
|
|
412
|
-
function afn(input) {
|
|
413
|
-
if (typeof input !== "function") throw new Error("function expected");
|
|
414
|
-
return true;
|
|
415
|
-
}
|
|
416
|
-
function astr(label, input) {
|
|
417
|
-
if (typeof input !== "string") throw new Error(`${label}: string expected`);
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
420
|
-
function anumber(n) {
|
|
421
|
-
if (!Number.isSafeInteger(n)) throw new Error(`invalid integer: ${n}`);
|
|
422
|
-
}
|
|
423
|
-
function aArr(input) {
|
|
424
|
-
if (!Array.isArray(input)) throw new Error("array expected");
|
|
425
|
-
}
|
|
426
|
-
function astrArr(label, input) {
|
|
427
|
-
if (!isArrayOf(true, input)) throw new Error(`${label}: array of strings expected`);
|
|
428
|
-
}
|
|
429
|
-
function anumArr(label, input) {
|
|
430
|
-
if (!isArrayOf(false, input)) throw new Error(`${label}: array of numbers expected`);
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* @__NO_SIDE_EFFECTS__
|
|
434
|
-
*/
|
|
435
|
-
function chain(...args) {
|
|
436
|
-
const id = (a) => a;
|
|
437
|
-
const wrap = (a, b) => (c) => a(b(c));
|
|
438
|
-
return {
|
|
439
|
-
encode: args.map((x) => x.encode).reduceRight(wrap, id),
|
|
440
|
-
decode: args.map((x) => x.decode).reduce(wrap, id)
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Encodes integer radix representation to array of strings using alphabet and back.
|
|
445
|
-
* Could also be array of strings.
|
|
446
|
-
* @__NO_SIDE_EFFECTS__
|
|
447
|
-
*/
|
|
448
|
-
function alphabet(letters) {
|
|
449
|
-
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
450
|
-
const len = lettersA.length;
|
|
451
|
-
astrArr("alphabet", lettersA);
|
|
452
|
-
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
453
|
-
return {
|
|
454
|
-
encode: (digits) => {
|
|
455
|
-
aArr(digits);
|
|
456
|
-
return digits.map((i) => {
|
|
457
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= len) throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
458
|
-
return lettersA[i];
|
|
459
|
-
});
|
|
460
|
-
},
|
|
461
|
-
decode: (input) => {
|
|
462
|
-
aArr(input);
|
|
463
|
-
return input.map((letter) => {
|
|
464
|
-
astr("alphabet.decode", letter);
|
|
465
|
-
const i = indexes.get(letter);
|
|
466
|
-
if (i === void 0) throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
467
|
-
return i;
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* @__NO_SIDE_EFFECTS__
|
|
474
|
-
*/
|
|
475
|
-
function join(separator = "") {
|
|
476
|
-
astr("join", separator);
|
|
477
|
-
return {
|
|
478
|
-
encode: (from) => {
|
|
479
|
-
astrArr("join.decode", from);
|
|
480
|
-
return from.join(separator);
|
|
481
|
-
},
|
|
482
|
-
decode: (to) => {
|
|
483
|
-
astr("join.decode", to);
|
|
484
|
-
return to.split(separator);
|
|
485
|
-
}
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Pad strings array so it has integer number of bits
|
|
490
|
-
* @__NO_SIDE_EFFECTS__
|
|
491
|
-
*/
|
|
492
|
-
function padding(bits, chr = "=") {
|
|
493
|
-
anumber(bits);
|
|
494
|
-
astr("padding", chr);
|
|
495
|
-
return {
|
|
496
|
-
encode(data) {
|
|
497
|
-
astrArr("padding.encode", data);
|
|
498
|
-
while (data.length * bits % 8) data.push(chr);
|
|
499
|
-
return data;
|
|
500
|
-
},
|
|
501
|
-
decode(input) {
|
|
502
|
-
astrArr("padding.decode", input);
|
|
503
|
-
let end = input.length;
|
|
504
|
-
if (end * bits % 8) throw new Error("padding: invalid, string should have whole number of bytes");
|
|
505
|
-
for (; end > 0 && input[end - 1] === chr; end--) if ((end - 1) * bits % 8 === 0) throw new Error("padding: invalid, string has too much padding");
|
|
506
|
-
return input.slice(0, end);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* @__NO_SIDE_EFFECTS__
|
|
512
|
-
*/
|
|
513
|
-
function normalize(fn) {
|
|
514
|
-
afn(fn);
|
|
515
|
-
return {
|
|
516
|
-
encode: (from) => from,
|
|
517
|
-
decode: (to) => fn(to)
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Slow: O(n^2) time complexity
|
|
522
|
-
*/
|
|
523
|
-
function convertRadix(data, from, to) {
|
|
524
|
-
if (from < 2) throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
525
|
-
if (to < 2) throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
526
|
-
aArr(data);
|
|
527
|
-
if (!data.length) return [];
|
|
528
|
-
let pos = 0;
|
|
529
|
-
const res = [];
|
|
530
|
-
const digits = Array.from(data, (d) => {
|
|
531
|
-
anumber(d);
|
|
532
|
-
if (d < 0 || d >= from) throw new Error(`invalid integer: ${d}`);
|
|
533
|
-
return d;
|
|
534
|
-
});
|
|
535
|
-
const dlen = digits.length;
|
|
536
|
-
while (true) {
|
|
537
|
-
let carry = 0;
|
|
538
|
-
let done = true;
|
|
539
|
-
for (let i = pos; i < dlen; i++) {
|
|
540
|
-
const digit = digits[i];
|
|
541
|
-
const fromCarry = from * carry;
|
|
542
|
-
const digitBase = fromCarry + digit;
|
|
543
|
-
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) throw new Error("convertRadix: carry overflow");
|
|
544
|
-
const div = digitBase / to;
|
|
545
|
-
carry = digitBase % to;
|
|
546
|
-
const rounded = Math.floor(div);
|
|
547
|
-
digits[i] = rounded;
|
|
548
|
-
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase) throw new Error("convertRadix: carry overflow");
|
|
549
|
-
if (!done) continue;
|
|
550
|
-
else if (!rounded) pos = i;
|
|
551
|
-
else done = false;
|
|
552
|
-
}
|
|
553
|
-
res.push(carry);
|
|
554
|
-
if (done) break;
|
|
555
|
-
}
|
|
556
|
-
for (let i = 0; i < data.length - 1 && data[i] === 0; i++) res.push(0);
|
|
557
|
-
return res.reverse();
|
|
558
|
-
}
|
|
559
|
-
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
560
|
-
const radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
561
|
-
const powers = /* @__PURE__ */ (() => {
|
|
562
|
-
let res = [];
|
|
563
|
-
for (let i = 0; i < 40; i++) res.push(2 ** i);
|
|
564
|
-
return res;
|
|
565
|
-
})();
|
|
566
|
-
/**
|
|
567
|
-
* Implemented with numbers, because BigInt is 5x slower
|
|
568
|
-
*/
|
|
569
|
-
function convertRadix2(data, from, to, padding) {
|
|
570
|
-
aArr(data);
|
|
571
|
-
if (from <= 0 || from > 32) throw new Error(`convertRadix2: wrong from=${from}`);
|
|
572
|
-
if (to <= 0 || to > 32) throw new Error(`convertRadix2: wrong to=${to}`);
|
|
573
|
-
if (/* @__PURE__ */ radix2carry(from, to) > 32) throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
574
|
-
let carry = 0;
|
|
575
|
-
let pos = 0;
|
|
576
|
-
const max = powers[from];
|
|
577
|
-
const mask = powers[to] - 1;
|
|
578
|
-
const res = [];
|
|
579
|
-
for (const n of data) {
|
|
580
|
-
anumber(n);
|
|
581
|
-
if (n >= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
582
|
-
carry = carry << from | n;
|
|
583
|
-
if (pos + from > 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
584
|
-
pos += from;
|
|
585
|
-
for (; pos >= to; pos -= to) res.push((carry >> pos - to & mask) >>> 0);
|
|
586
|
-
const pow = powers[pos];
|
|
587
|
-
if (pow === void 0) throw new Error("invalid carry");
|
|
588
|
-
carry &= pow - 1;
|
|
589
|
-
}
|
|
590
|
-
carry = carry << to - pos & mask;
|
|
591
|
-
if (!padding && pos >= from) throw new Error("Excess padding");
|
|
592
|
-
if (!padding && carry > 0) throw new Error(`Non-zero padding: ${carry}`);
|
|
593
|
-
if (padding && pos > 0) res.push(carry >>> 0);
|
|
594
|
-
return res;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* @__NO_SIDE_EFFECTS__
|
|
598
|
-
*/
|
|
599
|
-
function radix(num) {
|
|
600
|
-
anumber(num);
|
|
601
|
-
const _256 = 2 ** 8;
|
|
602
|
-
return {
|
|
603
|
-
encode: (bytes) => {
|
|
604
|
-
if (!isBytes(bytes)) throw new Error("radix.encode input should be Uint8Array");
|
|
605
|
-
return convertRadix(Array.from(bytes), _256, num);
|
|
606
|
-
},
|
|
607
|
-
decode: (digits) => {
|
|
608
|
-
anumArr("radix.decode", digits);
|
|
609
|
-
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* If both bases are power of same number (like `2**8 <-> 2**64`),
|
|
615
|
-
* there is a linear algorithm. For now we have implementation for power-of-two bases only.
|
|
616
|
-
* @__NO_SIDE_EFFECTS__
|
|
617
|
-
*/
|
|
618
|
-
function radix2(bits, revPadding = false) {
|
|
619
|
-
anumber(bits);
|
|
620
|
-
if (bits <= 0 || bits > 32) throw new Error("radix2: bits should be in (0..32]");
|
|
621
|
-
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32) throw new Error("radix2: carry overflow");
|
|
622
|
-
return {
|
|
623
|
-
encode: (bytes) => {
|
|
624
|
-
if (!isBytes(bytes)) throw new Error("radix2.encode input should be Uint8Array");
|
|
625
|
-
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
626
|
-
},
|
|
627
|
-
decode: (digits) => {
|
|
628
|
-
anumArr("radix2.decode", digits);
|
|
629
|
-
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
function unsafeWrapper(fn) {
|
|
634
|
-
afn(fn);
|
|
635
|
-
return function(...args) {
|
|
636
|
-
try {
|
|
637
|
-
return fn.apply(null, args);
|
|
638
|
-
} catch (e) {}
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
function checksum(len, fn) {
|
|
642
|
-
anumber(len);
|
|
643
|
-
afn(fn);
|
|
644
|
-
return {
|
|
645
|
-
encode(data) {
|
|
646
|
-
if (!isBytes(data)) throw new Error("checksum.encode: input should be Uint8Array");
|
|
647
|
-
const sum = fn(data).slice(0, len);
|
|
648
|
-
const res = new Uint8Array(data.length + len);
|
|
649
|
-
res.set(data);
|
|
650
|
-
res.set(sum, data.length);
|
|
651
|
-
return res;
|
|
652
|
-
},
|
|
653
|
-
decode(data) {
|
|
654
|
-
if (!isBytes(data)) throw new Error("checksum.decode: input should be Uint8Array");
|
|
655
|
-
const payload = data.slice(0, -len);
|
|
656
|
-
const oldChecksum = data.slice(-len);
|
|
657
|
-
const newChecksum = fn(payload).slice(0, len);
|
|
658
|
-
for (let i = 0; i < len; i++) if (newChecksum[i] !== oldChecksum[i]) throw new Error("Invalid checksum");
|
|
659
|
-
return payload;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* base16 encoding from RFC 4648.
|
|
665
|
-
* @example
|
|
666
|
-
* ```js
|
|
667
|
-
* base16.encode(Uint8Array.from([0x12, 0xab]));
|
|
668
|
-
* // => '12AB'
|
|
669
|
-
* ```
|
|
670
|
-
*/
|
|
671
|
-
const base16 = chain(radix2(4), alphabet("0123456789ABCDEF"), join(""));
|
|
672
|
-
/**
|
|
673
|
-
* base32 encoding from RFC 4648. Has padding.
|
|
674
|
-
* Use `base32nopad` for unpadded version.
|
|
675
|
-
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
676
|
-
* @example
|
|
677
|
-
* ```js
|
|
678
|
-
* base32.encode(Uint8Array.from([0x12, 0xab]));
|
|
679
|
-
* // => 'CKVQ===='
|
|
680
|
-
* base32.decode('CKVQ====');
|
|
681
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
682
|
-
* ```
|
|
683
|
-
*/
|
|
684
|
-
const base32 = chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), padding(5), join(""));
|
|
685
|
-
/**
|
|
686
|
-
* base32 encoding from RFC 4648. No padding.
|
|
687
|
-
* Use `base32` for padded version.
|
|
688
|
-
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
689
|
-
* @example
|
|
690
|
-
* ```js
|
|
691
|
-
* base32nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
692
|
-
* // => 'CKVQ'
|
|
693
|
-
* base32nopad.decode('CKVQ');
|
|
694
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
695
|
-
* ```
|
|
696
|
-
*/
|
|
697
|
-
const base32nopad = chain(radix2(5), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), join(""));
|
|
698
|
-
/**
|
|
699
|
-
* base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.
|
|
700
|
-
* Use `base32hexnopad` for unpadded version.
|
|
701
|
-
* @example
|
|
702
|
-
* ```js
|
|
703
|
-
* base32hex.encode(Uint8Array.from([0x12, 0xab]));
|
|
704
|
-
* // => '2ALG===='
|
|
705
|
-
* base32hex.decode('2ALG====');
|
|
706
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
707
|
-
* ```
|
|
708
|
-
*/
|
|
709
|
-
const base32hex = chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), padding(5), join(""));
|
|
710
|
-
/**
|
|
711
|
-
* base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.
|
|
712
|
-
* Use `base32hex` for padded version.
|
|
713
|
-
* @example
|
|
714
|
-
* ```js
|
|
715
|
-
* base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
716
|
-
* // => '2ALG'
|
|
717
|
-
* base32hexnopad.decode('2ALG');
|
|
718
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
719
|
-
* ```
|
|
720
|
-
*/
|
|
721
|
-
const base32hexnopad = chain(radix2(5), alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), join(""));
|
|
722
|
-
/**
|
|
723
|
-
* base32 encoding from RFC 4648. Doug Crockford's version.
|
|
724
|
-
* https://www.crockford.com/base32.html
|
|
725
|
-
* @example
|
|
726
|
-
* ```js
|
|
727
|
-
* base32crockford.encode(Uint8Array.from([0x12, 0xab]));
|
|
728
|
-
* // => '2ANG'
|
|
729
|
-
* base32crockford.decode('2ANG');
|
|
730
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
731
|
-
* ```
|
|
732
|
-
*/
|
|
733
|
-
const base32crockford = chain(radix2(5), alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), join(""), normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
734
|
-
const hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
|
|
735
|
-
const decodeBase64Builtin = (s, isUrl) => {
|
|
736
|
-
astr("base64", s);
|
|
737
|
-
const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
|
|
738
|
-
const alphabet = isUrl ? "base64url" : "base64";
|
|
739
|
-
if (s.length > 0 && !re.test(s)) throw new Error("invalid base64");
|
|
740
|
-
return Uint8Array.fromBase64(s, {
|
|
741
|
-
alphabet,
|
|
742
|
-
lastChunkHandling: "strict"
|
|
743
|
-
});
|
|
744
|
-
};
|
|
745
|
-
/**
|
|
746
|
-
* base64 from RFC 4648. Padded.
|
|
747
|
-
* Use `base64nopad` for unpadded version.
|
|
748
|
-
* Also check out `base64url`, `base64urlnopad`.
|
|
749
|
-
* Falls back to built-in function, when available.
|
|
750
|
-
* @example
|
|
751
|
-
* ```js
|
|
752
|
-
* base64.encode(Uint8Array.from([0x12, 0xab]));
|
|
753
|
-
* // => 'Eqs='
|
|
754
|
-
* base64.decode('Eqs=');
|
|
755
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
756
|
-
* ```
|
|
757
|
-
*/
|
|
758
|
-
const base64 = hasBase64Builtin ? {
|
|
759
|
-
encode(b) {
|
|
760
|
-
abytes(b);
|
|
761
|
-
return b.toBase64();
|
|
762
|
-
},
|
|
763
|
-
decode(s) {
|
|
764
|
-
return decodeBase64Builtin(s, false);
|
|
765
|
-
}
|
|
766
|
-
} : chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), padding(6), join(""));
|
|
767
|
-
/**
|
|
768
|
-
* base64 from RFC 4648. No padding.
|
|
769
|
-
* Use `base64` for padded version.
|
|
770
|
-
* @example
|
|
771
|
-
* ```js
|
|
772
|
-
* base64nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
773
|
-
* // => 'Eqs'
|
|
774
|
-
* base64nopad.decode('Eqs');
|
|
775
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
776
|
-
* ```
|
|
777
|
-
*/
|
|
778
|
-
const base64nopad = chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), join(""));
|
|
779
|
-
/**
|
|
780
|
-
* base64 from RFC 4648, using URL-safe alphabet. Padded.
|
|
781
|
-
* Use `base64urlnopad` for unpadded version.
|
|
782
|
-
* Falls back to built-in function, when available.
|
|
783
|
-
* @example
|
|
784
|
-
* ```js
|
|
785
|
-
* base64url.encode(Uint8Array.from([0x12, 0xab]));
|
|
786
|
-
* // => 'Eqs='
|
|
787
|
-
* base64url.decode('Eqs=');
|
|
788
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
789
|
-
* ```
|
|
790
|
-
*/
|
|
791
|
-
const base64url = hasBase64Builtin ? {
|
|
792
|
-
encode(b) {
|
|
793
|
-
abytes(b);
|
|
794
|
-
return b.toBase64({ alphabet: "base64url" });
|
|
795
|
-
},
|
|
796
|
-
decode(s) {
|
|
797
|
-
return decodeBase64Builtin(s, true);
|
|
798
|
-
}
|
|
799
|
-
} : chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), padding(6), join(""));
|
|
800
|
-
/**
|
|
801
|
-
* base64 from RFC 4648, using URL-safe alphabet. No padding.
|
|
802
|
-
* Use `base64url` for padded version.
|
|
803
|
-
* @example
|
|
804
|
-
* ```js
|
|
805
|
-
* base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
806
|
-
* // => 'Eqs'
|
|
807
|
-
* base64urlnopad.decode('Eqs');
|
|
808
|
-
* // => Uint8Array.from([0x12, 0xab])
|
|
809
|
-
* ```
|
|
810
|
-
*/
|
|
811
|
-
const base64urlnopad = chain(radix2(6), alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), join(""));
|
|
812
|
-
const genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => chain(radix(58), alphabet(abc), join(""));
|
|
813
|
-
/**
|
|
814
|
-
* base58: base64 without ambigous characters +, /, 0, O, I, l.
|
|
815
|
-
* Quadratic (O(n^2)) - so, can't be used on large inputs.
|
|
816
|
-
* @example
|
|
817
|
-
* ```js
|
|
818
|
-
* base58.decode('01abcdef');
|
|
819
|
-
* // => '3UhJW'
|
|
820
|
-
* ```
|
|
821
|
-
*/
|
|
822
|
-
const base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
823
|
-
/**
|
|
824
|
-
* Method, which creates base58check encoder.
|
|
825
|
-
* Requires function, calculating sha256.
|
|
826
|
-
*/
|
|
827
|
-
const createBase58check = (sha256) => chain(checksum(4, (data) => sha256(sha256(data))), base58);
|
|
828
|
-
const BECH_ALPHABET = chain(alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), join(""));
|
|
829
|
-
const POLYMOD_GENERATORS = [
|
|
830
|
-
996825010,
|
|
831
|
-
642813549,
|
|
832
|
-
513874426,
|
|
833
|
-
1027748829,
|
|
834
|
-
705979059
|
|
835
|
-
];
|
|
836
|
-
function bech32Polymod(pre) {
|
|
837
|
-
const b = pre >> 25;
|
|
838
|
-
let chk = (pre & 33554431) << 5;
|
|
839
|
-
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) if ((b >> i & 1) === 1) chk ^= POLYMOD_GENERATORS[i];
|
|
840
|
-
return chk;
|
|
841
|
-
}
|
|
842
|
-
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
843
|
-
const len = prefix.length;
|
|
844
|
-
let chk = 1;
|
|
845
|
-
for (let i = 0; i < len; i++) {
|
|
846
|
-
const c = prefix.charCodeAt(i);
|
|
847
|
-
if (c < 33 || c > 126) throw new Error(`Invalid prefix (${prefix})`);
|
|
848
|
-
chk = bech32Polymod(chk) ^ c >> 5;
|
|
849
|
-
}
|
|
850
|
-
chk = bech32Polymod(chk);
|
|
851
|
-
for (let i = 0; i < len; i++) chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
852
|
-
for (let v of words) chk = bech32Polymod(chk) ^ v;
|
|
853
|
-
for (let i = 0; i < 6; i++) chk = bech32Polymod(chk);
|
|
854
|
-
chk ^= encodingConst;
|
|
855
|
-
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* @__NO_SIDE_EFFECTS__
|
|
859
|
-
*/
|
|
860
|
-
function genBech32(encoding) {
|
|
861
|
-
const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
|
|
862
|
-
const _words = radix2(5);
|
|
863
|
-
const fromWords = _words.decode;
|
|
864
|
-
const toWords = _words.encode;
|
|
865
|
-
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
866
|
-
function encode(prefix, words, limit = 90) {
|
|
867
|
-
astr("bech32.encode prefix", prefix);
|
|
868
|
-
if (isBytes(words)) words = Array.from(words);
|
|
869
|
-
anumArr("bech32.encode", words);
|
|
870
|
-
const plen = prefix.length;
|
|
871
|
-
if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);
|
|
872
|
-
const actualLength = plen + 7 + words.length;
|
|
873
|
-
if (limit !== false && actualLength > limit) throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
874
|
-
const lowered = prefix.toLowerCase();
|
|
875
|
-
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
876
|
-
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
877
|
-
}
|
|
878
|
-
function decode(str, limit = 90) {
|
|
879
|
-
astr("bech32.decode input", str);
|
|
880
|
-
const slen = str.length;
|
|
881
|
-
if (slen < 8 || limit !== false && slen > limit) throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
882
|
-
const lowered = str.toLowerCase();
|
|
883
|
-
if (str !== lowered && str !== str.toUpperCase()) throw new Error(`String must be lowercase or uppercase`);
|
|
884
|
-
const sepIndex = lowered.lastIndexOf("1");
|
|
885
|
-
if (sepIndex === 0 || sepIndex === -1) throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
886
|
-
const prefix = lowered.slice(0, sepIndex);
|
|
887
|
-
const data = lowered.slice(sepIndex + 1);
|
|
888
|
-
if (data.length < 6) throw new Error("Data must be at least 6 characters long");
|
|
889
|
-
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
890
|
-
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
891
|
-
if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
892
|
-
return {
|
|
893
|
-
prefix,
|
|
894
|
-
words
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
const decodeUnsafe = unsafeWrapper(decode);
|
|
898
|
-
function decodeToBytes(str) {
|
|
899
|
-
const { prefix, words } = decode(str, false);
|
|
900
|
-
return {
|
|
901
|
-
prefix,
|
|
902
|
-
words,
|
|
903
|
-
bytes: fromWords(words)
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
function encodeFromBytes(prefix, bytes) {
|
|
907
|
-
return encode(prefix, toWords(bytes));
|
|
908
|
-
}
|
|
909
|
-
return {
|
|
910
|
-
encode,
|
|
911
|
-
decode,
|
|
912
|
-
encodeFromBytes,
|
|
913
|
-
decodeToBytes,
|
|
914
|
-
decodeUnsafe,
|
|
915
|
-
fromWords,
|
|
916
|
-
fromWordsUnsafe,
|
|
917
|
-
toWords
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* bech32 from BIP 173. Operates on words.
|
|
922
|
-
* For high-level, check out scure-btc-signer:
|
|
923
|
-
* https://github.com/paulmillr/scure-btc-signer.
|
|
924
|
-
*/
|
|
925
|
-
const bech32 = genBech32("bech32");
|
|
926
|
-
/**
|
|
927
|
-
* bech32m from BIP 350. Operates on words.
|
|
928
|
-
* It was to mitigate `bech32` weaknesses.
|
|
929
|
-
* For high-level, check out scure-btc-signer:
|
|
930
|
-
* https://github.com/paulmillr/scure-btc-signer.
|
|
931
|
-
*/
|
|
932
|
-
const bech32m = genBech32("bech32m");
|
|
933
|
-
const hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
934
|
-
const hexBuiltin = {
|
|
935
|
-
encode(data) {
|
|
936
|
-
abytes(data);
|
|
937
|
-
return data.toHex();
|
|
938
|
-
},
|
|
939
|
-
decode(s) {
|
|
940
|
-
astr("hex", s);
|
|
941
|
-
return Uint8Array.fromHex(s);
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
/**
|
|
945
|
-
* hex string decoder. Uses built-in function, when available.
|
|
946
|
-
* @example
|
|
947
|
-
* ```js
|
|
948
|
-
* const b = hex.decode("0102ff"); // => new Uint8Array([ 1, 2, 255 ])
|
|
949
|
-
* const str = hex.encode(b); // "0102ff"
|
|
950
|
-
* ```
|
|
951
|
-
*/
|
|
952
|
-
const hex = hasHexBuiltin ? hexBuiltin : chain(radix2(4), alphabet("0123456789abcdef"), join(""), normalize((s) => {
|
|
953
|
-
if (typeof s !== "string" || s.length % 2 !== 0) throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
|
|
954
|
-
return s.toLowerCase();
|
|
955
|
-
}));
|
|
956
|
-
|
|
957
|
-
//#endregion
|
|
958
|
-
export { bytesToHex as A, randomBytes as B, SHA256_IV as C, ahash as D, aexists as E, createView as F, u32 as G, rotr as H, hexToBytes as I, isBytes$1 as L, clean as M, concatBytes as N, anumber$1 as O, createHasher as P, kdfInputToBytes as R, Maj as S, abytes$1 as T, swap32IfBE as U, rotl as V, swap8IfBE as W, shrSH as _, add3L as a, Chi as b, add5H as c, rotr32H as d, rotr32L as f, rotrSL as g, rotrSH as h, add3H as i, checkOpts as j, aoutput as k, add5L as l, rotrBL as m, createBase58check as n, add4H as o, rotrBH as p, add as r, add4L as s, base58 as t, fromBig as u, shrSL as v, SHA512_IV as w, HashMD as x, split as y, oidNist as z };
|
|
959
|
-
//# sourceMappingURL=base-BvfRCgEy.js.map
|