@chainflip/utils 0.1.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.
- package/dist/assertion.cjs +86 -0
- package/dist/assertion.d.cts +11 -0
- package/dist/assertion.d.ts +11 -0
- package/dist/assertion.js +23 -0
- package/dist/async.cjs +89 -0
- package/dist/async.d.cts +29 -0
- package/dist/async.d.ts +29 -0
- package/dist/async.js +61 -0
- package/dist/base58.cjs +75 -0
- package/dist/base58.d.cts +4 -0
- package/dist/base58.d.ts +4 -0
- package/dist/base58.js +11 -0
- package/dist/bytes.cjs +94 -0
- package/dist/bytes.d.cts +8 -0
- package/dist/bytes.d.ts +8 -0
- package/dist/bytes.js +14 -0
- package/dist/chunk-CZNX6EUV.js +23 -0
- package/dist/chunk-DGVZ5UDU.js +52 -0
- package/dist/chunk-MORKFLN4.js +14 -0
- package/dist/chunk-NYJKCZRI.js +52 -0
- package/dist/guard.cjs +55 -0
- package/dist/guard.d.cts +20 -0
- package/dist/guard.d.ts +20 -0
- package/dist/guard.js +22 -0
- package/dist/ss58.cjs +756 -0
- package/dist/ss58.d.cts +12 -0
- package/dist/ss58.d.ts +12 -0
- package/dist/ss58.js +680 -0
- package/dist/string.cjs +42 -0
- package/dist/string.d.cts +8 -0
- package/dist/string.d.ts +8 -0
- package/dist/string.js +13 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +3 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +0 -0
- package/package.json +32 -0
package/dist/ss58.cjs
ADDED
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ss58.ts
|
|
21
|
+
var ss58_exports = {};
|
|
22
|
+
__export(ss58_exports, {
|
|
23
|
+
decode: () => decode2,
|
|
24
|
+
encode: () => encode2
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(ss58_exports);
|
|
27
|
+
|
|
28
|
+
// src/guard.ts
|
|
29
|
+
var createIsGuard = (type) => (value) => typeof value === type;
|
|
30
|
+
var isString = createIsGuard("string");
|
|
31
|
+
var isNumber = createIsGuard("number");
|
|
32
|
+
var isBigInt = createIsGuard("bigint");
|
|
33
|
+
var isBoolean = createIsGuard("boolean");
|
|
34
|
+
var isSymbol = createIsGuard("symbol");
|
|
35
|
+
var isObject = createIsGuard("object");
|
|
36
|
+
var isUndefined = createIsGuard("undefined");
|
|
37
|
+
|
|
38
|
+
// src/assertion.ts
|
|
39
|
+
function assert(condition, message = "assertion failed", Constructor = Error) {
|
|
40
|
+
if (!condition) {
|
|
41
|
+
throw new Constructor(message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
|
|
46
|
+
function number(n) {
|
|
47
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
48
|
+
throw new Error(`positive integer expected, not ${n}`);
|
|
49
|
+
}
|
|
50
|
+
function isBytes(a) {
|
|
51
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
52
|
+
}
|
|
53
|
+
function bytes(b, ...lengths) {
|
|
54
|
+
if (!isBytes(b))
|
|
55
|
+
throw new Error("Uint8Array expected");
|
|
56
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
57
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
58
|
+
}
|
|
59
|
+
function exists(instance, checkFinished = true) {
|
|
60
|
+
if (instance.destroyed)
|
|
61
|
+
throw new Error("Hash instance has been destroyed");
|
|
62
|
+
if (checkFinished && instance.finished)
|
|
63
|
+
throw new Error("Hash#digest() has already been called");
|
|
64
|
+
}
|
|
65
|
+
function output(out, instance) {
|
|
66
|
+
bytes(out);
|
|
67
|
+
const min = instance.outputLen;
|
|
68
|
+
if (out.length < min) {
|
|
69
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
|
|
74
|
+
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
75
|
+
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
76
|
+
var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
77
|
+
var byteSwapIfBE = isLE ? (n) => n : (n) => byteSwap(n);
|
|
78
|
+
function byteSwap32(arr) {
|
|
79
|
+
for (let i = 0; i < arr.length; i++) {
|
|
80
|
+
arr[i] = byteSwap(arr[i]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function utf8ToBytes(str) {
|
|
84
|
+
if (typeof str !== "string")
|
|
85
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
86
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
87
|
+
}
|
|
88
|
+
function toBytes(data) {
|
|
89
|
+
if (typeof data === "string")
|
|
90
|
+
data = utf8ToBytes(data);
|
|
91
|
+
bytes(data);
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
var Hash = class {
|
|
95
|
+
// Safe version that clones internal state
|
|
96
|
+
clone() {
|
|
97
|
+
return this._cloneInto();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var toStr = {}.toString;
|
|
101
|
+
function wrapConstructorWithOpts(hashCons) {
|
|
102
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
103
|
+
const tmp = hashCons({});
|
|
104
|
+
hashC.outputLen = tmp.outputLen;
|
|
105
|
+
hashC.blockLen = tmp.blockLen;
|
|
106
|
+
hashC.create = (opts) => hashCons(opts);
|
|
107
|
+
return hashC;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_blake.js
|
|
111
|
+
var SIGMA = /* @__PURE__ */ new Uint8Array([
|
|
112
|
+
0,
|
|
113
|
+
1,
|
|
114
|
+
2,
|
|
115
|
+
3,
|
|
116
|
+
4,
|
|
117
|
+
5,
|
|
118
|
+
6,
|
|
119
|
+
7,
|
|
120
|
+
8,
|
|
121
|
+
9,
|
|
122
|
+
10,
|
|
123
|
+
11,
|
|
124
|
+
12,
|
|
125
|
+
13,
|
|
126
|
+
14,
|
|
127
|
+
15,
|
|
128
|
+
14,
|
|
129
|
+
10,
|
|
130
|
+
4,
|
|
131
|
+
8,
|
|
132
|
+
9,
|
|
133
|
+
15,
|
|
134
|
+
13,
|
|
135
|
+
6,
|
|
136
|
+
1,
|
|
137
|
+
12,
|
|
138
|
+
0,
|
|
139
|
+
2,
|
|
140
|
+
11,
|
|
141
|
+
7,
|
|
142
|
+
5,
|
|
143
|
+
3,
|
|
144
|
+
11,
|
|
145
|
+
8,
|
|
146
|
+
12,
|
|
147
|
+
0,
|
|
148
|
+
5,
|
|
149
|
+
2,
|
|
150
|
+
15,
|
|
151
|
+
13,
|
|
152
|
+
10,
|
|
153
|
+
14,
|
|
154
|
+
3,
|
|
155
|
+
6,
|
|
156
|
+
7,
|
|
157
|
+
1,
|
|
158
|
+
9,
|
|
159
|
+
4,
|
|
160
|
+
7,
|
|
161
|
+
9,
|
|
162
|
+
3,
|
|
163
|
+
1,
|
|
164
|
+
13,
|
|
165
|
+
12,
|
|
166
|
+
11,
|
|
167
|
+
14,
|
|
168
|
+
2,
|
|
169
|
+
6,
|
|
170
|
+
5,
|
|
171
|
+
10,
|
|
172
|
+
4,
|
|
173
|
+
0,
|
|
174
|
+
15,
|
|
175
|
+
8,
|
|
176
|
+
9,
|
|
177
|
+
0,
|
|
178
|
+
5,
|
|
179
|
+
7,
|
|
180
|
+
2,
|
|
181
|
+
4,
|
|
182
|
+
10,
|
|
183
|
+
15,
|
|
184
|
+
14,
|
|
185
|
+
1,
|
|
186
|
+
11,
|
|
187
|
+
12,
|
|
188
|
+
6,
|
|
189
|
+
8,
|
|
190
|
+
3,
|
|
191
|
+
13,
|
|
192
|
+
2,
|
|
193
|
+
12,
|
|
194
|
+
6,
|
|
195
|
+
10,
|
|
196
|
+
0,
|
|
197
|
+
11,
|
|
198
|
+
8,
|
|
199
|
+
3,
|
|
200
|
+
4,
|
|
201
|
+
13,
|
|
202
|
+
7,
|
|
203
|
+
5,
|
|
204
|
+
15,
|
|
205
|
+
14,
|
|
206
|
+
1,
|
|
207
|
+
9,
|
|
208
|
+
12,
|
|
209
|
+
5,
|
|
210
|
+
1,
|
|
211
|
+
15,
|
|
212
|
+
14,
|
|
213
|
+
13,
|
|
214
|
+
4,
|
|
215
|
+
10,
|
|
216
|
+
0,
|
|
217
|
+
7,
|
|
218
|
+
6,
|
|
219
|
+
3,
|
|
220
|
+
9,
|
|
221
|
+
2,
|
|
222
|
+
8,
|
|
223
|
+
11,
|
|
224
|
+
13,
|
|
225
|
+
11,
|
|
226
|
+
7,
|
|
227
|
+
14,
|
|
228
|
+
12,
|
|
229
|
+
1,
|
|
230
|
+
3,
|
|
231
|
+
9,
|
|
232
|
+
5,
|
|
233
|
+
0,
|
|
234
|
+
15,
|
|
235
|
+
4,
|
|
236
|
+
8,
|
|
237
|
+
6,
|
|
238
|
+
2,
|
|
239
|
+
10,
|
|
240
|
+
6,
|
|
241
|
+
15,
|
|
242
|
+
14,
|
|
243
|
+
9,
|
|
244
|
+
11,
|
|
245
|
+
3,
|
|
246
|
+
0,
|
|
247
|
+
8,
|
|
248
|
+
12,
|
|
249
|
+
2,
|
|
250
|
+
13,
|
|
251
|
+
7,
|
|
252
|
+
1,
|
|
253
|
+
4,
|
|
254
|
+
10,
|
|
255
|
+
5,
|
|
256
|
+
10,
|
|
257
|
+
2,
|
|
258
|
+
8,
|
|
259
|
+
4,
|
|
260
|
+
7,
|
|
261
|
+
6,
|
|
262
|
+
1,
|
|
263
|
+
5,
|
|
264
|
+
15,
|
|
265
|
+
11,
|
|
266
|
+
9,
|
|
267
|
+
14,
|
|
268
|
+
3,
|
|
269
|
+
12,
|
|
270
|
+
13,
|
|
271
|
+
0,
|
|
272
|
+
0,
|
|
273
|
+
1,
|
|
274
|
+
2,
|
|
275
|
+
3,
|
|
276
|
+
4,
|
|
277
|
+
5,
|
|
278
|
+
6,
|
|
279
|
+
7,
|
|
280
|
+
8,
|
|
281
|
+
9,
|
|
282
|
+
10,
|
|
283
|
+
11,
|
|
284
|
+
12,
|
|
285
|
+
13,
|
|
286
|
+
14,
|
|
287
|
+
15,
|
|
288
|
+
14,
|
|
289
|
+
10,
|
|
290
|
+
4,
|
|
291
|
+
8,
|
|
292
|
+
9,
|
|
293
|
+
15,
|
|
294
|
+
13,
|
|
295
|
+
6,
|
|
296
|
+
1,
|
|
297
|
+
12,
|
|
298
|
+
0,
|
|
299
|
+
2,
|
|
300
|
+
11,
|
|
301
|
+
7,
|
|
302
|
+
5,
|
|
303
|
+
3
|
|
304
|
+
]);
|
|
305
|
+
var BLAKE = class extends Hash {
|
|
306
|
+
constructor(blockLen, outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
307
|
+
super();
|
|
308
|
+
this.blockLen = blockLen;
|
|
309
|
+
this.outputLen = outputLen;
|
|
310
|
+
this.length = 0;
|
|
311
|
+
this.pos = 0;
|
|
312
|
+
this.finished = false;
|
|
313
|
+
this.destroyed = false;
|
|
314
|
+
number(blockLen);
|
|
315
|
+
number(outputLen);
|
|
316
|
+
number(keyLen);
|
|
317
|
+
if (outputLen < 0 || outputLen > keyLen)
|
|
318
|
+
throw new Error("outputLen bigger than keyLen");
|
|
319
|
+
if (opts.key !== void 0 && (opts.key.length < 1 || opts.key.length > keyLen))
|
|
320
|
+
throw new Error(`key must be up 1..${keyLen} byte long or undefined`);
|
|
321
|
+
if (opts.salt !== void 0 && opts.salt.length !== saltLen)
|
|
322
|
+
throw new Error(`salt must be ${saltLen} byte long or undefined`);
|
|
323
|
+
if (opts.personalization !== void 0 && opts.personalization.length !== persLen)
|
|
324
|
+
throw new Error(`personalization must be ${persLen} byte long or undefined`);
|
|
325
|
+
this.buffer32 = u32(this.buffer = new Uint8Array(blockLen));
|
|
326
|
+
}
|
|
327
|
+
update(data) {
|
|
328
|
+
exists(this);
|
|
329
|
+
const { blockLen, buffer, buffer32 } = this;
|
|
330
|
+
data = toBytes(data);
|
|
331
|
+
const len = data.length;
|
|
332
|
+
const offset = data.byteOffset;
|
|
333
|
+
const buf = data.buffer;
|
|
334
|
+
for (let pos = 0; pos < len; ) {
|
|
335
|
+
if (this.pos === blockLen) {
|
|
336
|
+
if (!isLE)
|
|
337
|
+
byteSwap32(buffer32);
|
|
338
|
+
this.compress(buffer32, 0, false);
|
|
339
|
+
if (!isLE)
|
|
340
|
+
byteSwap32(buffer32);
|
|
341
|
+
this.pos = 0;
|
|
342
|
+
}
|
|
343
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
344
|
+
const dataOffset = offset + pos;
|
|
345
|
+
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
346
|
+
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
347
|
+
if (!isLE)
|
|
348
|
+
byteSwap32(data32);
|
|
349
|
+
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
|
350
|
+
this.length += blockLen;
|
|
351
|
+
this.compress(data32, pos32, false);
|
|
352
|
+
}
|
|
353
|
+
if (!isLE)
|
|
354
|
+
byteSwap32(data32);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
358
|
+
this.pos += take;
|
|
359
|
+
this.length += take;
|
|
360
|
+
pos += take;
|
|
361
|
+
}
|
|
362
|
+
return this;
|
|
363
|
+
}
|
|
364
|
+
digestInto(out) {
|
|
365
|
+
exists(this);
|
|
366
|
+
output(out, this);
|
|
367
|
+
const { pos, buffer32 } = this;
|
|
368
|
+
this.finished = true;
|
|
369
|
+
this.buffer.subarray(pos).fill(0);
|
|
370
|
+
if (!isLE)
|
|
371
|
+
byteSwap32(buffer32);
|
|
372
|
+
this.compress(buffer32, 0, true);
|
|
373
|
+
if (!isLE)
|
|
374
|
+
byteSwap32(buffer32);
|
|
375
|
+
const out32 = u32(out);
|
|
376
|
+
this.get().forEach((v, i) => out32[i] = byteSwapIfBE(v));
|
|
377
|
+
}
|
|
378
|
+
digest() {
|
|
379
|
+
const { buffer, outputLen } = this;
|
|
380
|
+
this.digestInto(buffer);
|
|
381
|
+
const res = buffer.slice(0, outputLen);
|
|
382
|
+
this.destroy();
|
|
383
|
+
return res;
|
|
384
|
+
}
|
|
385
|
+
_cloneInto(to) {
|
|
386
|
+
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
387
|
+
to || (to = new this.constructor({ dkLen: outputLen }));
|
|
388
|
+
to.set(...this.get());
|
|
389
|
+
to.length = length;
|
|
390
|
+
to.finished = finished;
|
|
391
|
+
to.destroyed = destroyed;
|
|
392
|
+
to.outputLen = outputLen;
|
|
393
|
+
to.buffer.set(buffer);
|
|
394
|
+
to.pos = pos;
|
|
395
|
+
return to;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_u64.js
|
|
400
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
401
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
402
|
+
function fromBig(n, le = false) {
|
|
403
|
+
if (le)
|
|
404
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
405
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
406
|
+
}
|
|
407
|
+
function split(lst, le = false) {
|
|
408
|
+
let Ah = new Uint32Array(lst.length);
|
|
409
|
+
let Al = new Uint32Array(lst.length);
|
|
410
|
+
for (let i = 0; i < lst.length; i++) {
|
|
411
|
+
const { h, l } = fromBig(lst[i], le);
|
|
412
|
+
[Ah[i], Al[i]] = [h, l];
|
|
413
|
+
}
|
|
414
|
+
return [Ah, Al];
|
|
415
|
+
}
|
|
416
|
+
var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
|
|
417
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
418
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
419
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
420
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
421
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
422
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
423
|
+
var rotr32H = (_h, l) => l;
|
|
424
|
+
var rotr32L = (h, _l) => h;
|
|
425
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
426
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
427
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
428
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
429
|
+
function add(Ah, Al, Bh, Bl) {
|
|
430
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
431
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
432
|
+
}
|
|
433
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
434
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
435
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
436
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
437
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
438
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
439
|
+
var u64 = {
|
|
440
|
+
fromBig,
|
|
441
|
+
split,
|
|
442
|
+
toBig,
|
|
443
|
+
shrSH,
|
|
444
|
+
shrSL,
|
|
445
|
+
rotrSH,
|
|
446
|
+
rotrSL,
|
|
447
|
+
rotrBH,
|
|
448
|
+
rotrBL,
|
|
449
|
+
rotr32H,
|
|
450
|
+
rotr32L,
|
|
451
|
+
rotlSH,
|
|
452
|
+
rotlSL,
|
|
453
|
+
rotlBH,
|
|
454
|
+
rotlBL,
|
|
455
|
+
add,
|
|
456
|
+
add3L,
|
|
457
|
+
add3H,
|
|
458
|
+
add4L,
|
|
459
|
+
add4H,
|
|
460
|
+
add5H,
|
|
461
|
+
add5L
|
|
462
|
+
};
|
|
463
|
+
var u64_default = u64;
|
|
464
|
+
|
|
465
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/blake2b.js
|
|
466
|
+
var B2B_IV = /* @__PURE__ */ new Uint32Array([
|
|
467
|
+
4089235720,
|
|
468
|
+
1779033703,
|
|
469
|
+
2227873595,
|
|
470
|
+
3144134277,
|
|
471
|
+
4271175723,
|
|
472
|
+
1013904242,
|
|
473
|
+
1595750129,
|
|
474
|
+
2773480762,
|
|
475
|
+
2917565137,
|
|
476
|
+
1359893119,
|
|
477
|
+
725511199,
|
|
478
|
+
2600822924,
|
|
479
|
+
4215389547,
|
|
480
|
+
528734635,
|
|
481
|
+
327033209,
|
|
482
|
+
1541459225
|
|
483
|
+
]);
|
|
484
|
+
var BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
485
|
+
function G1b(a, b, c, d, msg, x) {
|
|
486
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
487
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
488
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
489
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
490
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
491
|
+
let ll = u64_default.add3L(Al, Bl, Xl);
|
|
492
|
+
Ah = u64_default.add3H(ll, Ah, Bh, Xh);
|
|
493
|
+
Al = ll | 0;
|
|
494
|
+
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
|
|
495
|
+
({ Dh, Dl } = { Dh: u64_default.rotr32H(Dh, Dl), Dl: u64_default.rotr32L(Dh, Dl) });
|
|
496
|
+
({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
|
|
497
|
+
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
|
|
498
|
+
({ Bh, Bl } = { Bh: u64_default.rotrSH(Bh, Bl, 24), Bl: u64_default.rotrSL(Bh, Bl, 24) });
|
|
499
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
500
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
501
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
502
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
503
|
+
}
|
|
504
|
+
function G2b(a, b, c, d, msg, x) {
|
|
505
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
506
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
507
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
508
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
509
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
510
|
+
let ll = u64_default.add3L(Al, Bl, Xl);
|
|
511
|
+
Ah = u64_default.add3H(ll, Ah, Bh, Xh);
|
|
512
|
+
Al = ll | 0;
|
|
513
|
+
({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
|
|
514
|
+
({ Dh, Dl } = { Dh: u64_default.rotrSH(Dh, Dl, 16), Dl: u64_default.rotrSL(Dh, Dl, 16) });
|
|
515
|
+
({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
|
|
516
|
+
({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
|
|
517
|
+
({ Bh, Bl } = { Bh: u64_default.rotrBH(Bh, Bl, 63), Bl: u64_default.rotrBL(Bh, Bl, 63) });
|
|
518
|
+
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
519
|
+
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
520
|
+
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
521
|
+
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
522
|
+
}
|
|
523
|
+
var BLAKE2b = class extends BLAKE {
|
|
524
|
+
constructor(opts = {}) {
|
|
525
|
+
super(128, opts.dkLen === void 0 ? 64 : opts.dkLen, opts, 64, 16, 16);
|
|
526
|
+
this.v0l = B2B_IV[0] | 0;
|
|
527
|
+
this.v0h = B2B_IV[1] | 0;
|
|
528
|
+
this.v1l = B2B_IV[2] | 0;
|
|
529
|
+
this.v1h = B2B_IV[3] | 0;
|
|
530
|
+
this.v2l = B2B_IV[4] | 0;
|
|
531
|
+
this.v2h = B2B_IV[5] | 0;
|
|
532
|
+
this.v3l = B2B_IV[6] | 0;
|
|
533
|
+
this.v3h = B2B_IV[7] | 0;
|
|
534
|
+
this.v4l = B2B_IV[8] | 0;
|
|
535
|
+
this.v4h = B2B_IV[9] | 0;
|
|
536
|
+
this.v5l = B2B_IV[10] | 0;
|
|
537
|
+
this.v5h = B2B_IV[11] | 0;
|
|
538
|
+
this.v6l = B2B_IV[12] | 0;
|
|
539
|
+
this.v6h = B2B_IV[13] | 0;
|
|
540
|
+
this.v7l = B2B_IV[14] | 0;
|
|
541
|
+
this.v7h = B2B_IV[15] | 0;
|
|
542
|
+
const keyLength = opts.key ? opts.key.length : 0;
|
|
543
|
+
this.v0l ^= this.outputLen | keyLength << 8 | 1 << 16 | 1 << 24;
|
|
544
|
+
if (opts.salt) {
|
|
545
|
+
const salt = u32(toBytes(opts.salt));
|
|
546
|
+
this.v4l ^= byteSwapIfBE(salt[0]);
|
|
547
|
+
this.v4h ^= byteSwapIfBE(salt[1]);
|
|
548
|
+
this.v5l ^= byteSwapIfBE(salt[2]);
|
|
549
|
+
this.v5h ^= byteSwapIfBE(salt[3]);
|
|
550
|
+
}
|
|
551
|
+
if (opts.personalization) {
|
|
552
|
+
const pers = u32(toBytes(opts.personalization));
|
|
553
|
+
this.v6l ^= byteSwapIfBE(pers[0]);
|
|
554
|
+
this.v6h ^= byteSwapIfBE(pers[1]);
|
|
555
|
+
this.v7l ^= byteSwapIfBE(pers[2]);
|
|
556
|
+
this.v7h ^= byteSwapIfBE(pers[3]);
|
|
557
|
+
}
|
|
558
|
+
if (opts.key) {
|
|
559
|
+
const tmp = new Uint8Array(this.blockLen);
|
|
560
|
+
tmp.set(toBytes(opts.key));
|
|
561
|
+
this.update(tmp);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// prettier-ignore
|
|
565
|
+
get() {
|
|
566
|
+
let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
|
|
567
|
+
return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];
|
|
568
|
+
}
|
|
569
|
+
// prettier-ignore
|
|
570
|
+
set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
|
|
571
|
+
this.v0l = v0l | 0;
|
|
572
|
+
this.v0h = v0h | 0;
|
|
573
|
+
this.v1l = v1l | 0;
|
|
574
|
+
this.v1h = v1h | 0;
|
|
575
|
+
this.v2l = v2l | 0;
|
|
576
|
+
this.v2h = v2h | 0;
|
|
577
|
+
this.v3l = v3l | 0;
|
|
578
|
+
this.v3h = v3h | 0;
|
|
579
|
+
this.v4l = v4l | 0;
|
|
580
|
+
this.v4h = v4h | 0;
|
|
581
|
+
this.v5l = v5l | 0;
|
|
582
|
+
this.v5h = v5h | 0;
|
|
583
|
+
this.v6l = v6l | 0;
|
|
584
|
+
this.v6h = v6h | 0;
|
|
585
|
+
this.v7l = v7l | 0;
|
|
586
|
+
this.v7h = v7h | 0;
|
|
587
|
+
}
|
|
588
|
+
compress(msg, offset, isLast) {
|
|
589
|
+
this.get().forEach((v, i) => BBUF[i] = v);
|
|
590
|
+
BBUF.set(B2B_IV, 16);
|
|
591
|
+
let { h, l } = u64_default.fromBig(BigInt(this.length));
|
|
592
|
+
BBUF[24] = B2B_IV[8] ^ l;
|
|
593
|
+
BBUF[25] = B2B_IV[9] ^ h;
|
|
594
|
+
if (isLast) {
|
|
595
|
+
BBUF[28] = ~BBUF[28];
|
|
596
|
+
BBUF[29] = ~BBUF[29];
|
|
597
|
+
}
|
|
598
|
+
let j = 0;
|
|
599
|
+
const s = SIGMA;
|
|
600
|
+
for (let i = 0; i < 12; i++) {
|
|
601
|
+
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
602
|
+
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
603
|
+
G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
604
|
+
G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
605
|
+
G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
606
|
+
G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
607
|
+
G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
608
|
+
G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
609
|
+
G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
610
|
+
G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
611
|
+
G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
612
|
+
G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
613
|
+
G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
614
|
+
G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
615
|
+
G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
616
|
+
G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
617
|
+
}
|
|
618
|
+
this.v0l ^= BBUF[0] ^ BBUF[16];
|
|
619
|
+
this.v0h ^= BBUF[1] ^ BBUF[17];
|
|
620
|
+
this.v1l ^= BBUF[2] ^ BBUF[18];
|
|
621
|
+
this.v1h ^= BBUF[3] ^ BBUF[19];
|
|
622
|
+
this.v2l ^= BBUF[4] ^ BBUF[20];
|
|
623
|
+
this.v2h ^= BBUF[5] ^ BBUF[21];
|
|
624
|
+
this.v3l ^= BBUF[6] ^ BBUF[22];
|
|
625
|
+
this.v3h ^= BBUF[7] ^ BBUF[23];
|
|
626
|
+
this.v4l ^= BBUF[8] ^ BBUF[24];
|
|
627
|
+
this.v4h ^= BBUF[9] ^ BBUF[25];
|
|
628
|
+
this.v5l ^= BBUF[10] ^ BBUF[26];
|
|
629
|
+
this.v5h ^= BBUF[11] ^ BBUF[27];
|
|
630
|
+
this.v6l ^= BBUF[12] ^ BBUF[28];
|
|
631
|
+
this.v6h ^= BBUF[13] ^ BBUF[29];
|
|
632
|
+
this.v7l ^= BBUF[14] ^ BBUF[30];
|
|
633
|
+
this.v7h ^= BBUF[15] ^ BBUF[31];
|
|
634
|
+
BBUF.fill(0);
|
|
635
|
+
}
|
|
636
|
+
destroy() {
|
|
637
|
+
this.destroyed = true;
|
|
638
|
+
this.buffer32.fill(0);
|
|
639
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
var blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
|
|
643
|
+
|
|
644
|
+
// src/bytes.ts
|
|
645
|
+
var hexToBytes = (input) => {
|
|
646
|
+
assert(/^0x[\da-f]*$/i.test(input) && input.length % 2 === 0, "Invalid hex string");
|
|
647
|
+
const hex = input.slice(2);
|
|
648
|
+
const bytes2 = new Uint8Array(hex.length / 2);
|
|
649
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
650
|
+
bytes2[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
|
|
651
|
+
}
|
|
652
|
+
return bytes2;
|
|
653
|
+
};
|
|
654
|
+
var convertBase = (bytes2, fromBase, toBase) => {
|
|
655
|
+
const result = [];
|
|
656
|
+
for (const byte of bytes2) {
|
|
657
|
+
let carry = byte;
|
|
658
|
+
for (let i = 0; i < result.length; i += 1) {
|
|
659
|
+
carry += result[i] * fromBase;
|
|
660
|
+
result[i] = carry % toBase;
|
|
661
|
+
carry = Math.floor(carry / toBase);
|
|
662
|
+
}
|
|
663
|
+
while (carry !== 0) {
|
|
664
|
+
result.push(carry % toBase);
|
|
665
|
+
carry = Math.floor(carry / toBase);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
let leadingZeros = 0;
|
|
669
|
+
while (bytes2[leadingZeros] === 0) {
|
|
670
|
+
leadingZeros += 1;
|
|
671
|
+
result.push(0);
|
|
672
|
+
}
|
|
673
|
+
return result.reverse();
|
|
674
|
+
};
|
|
675
|
+
var encodeBytesWithCharset = (bytes2, charset2) => convertBase(bytes2, 256, charset2.length).map((charCode) => charset2.charAt(charCode)).join("");
|
|
676
|
+
var decodeBytesWithCharset = (input, charset2) => {
|
|
677
|
+
const charMap = Object.fromEntries([...charset2].map((char, index) => [char, index]));
|
|
678
|
+
const bytes2 = input.split("").map((char) => charMap[char]);
|
|
679
|
+
return convertBase(bytes2, charset2.length, 256);
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
// src/base58.ts
|
|
683
|
+
var charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
684
|
+
var encode = (bytes2) => encodeBytesWithCharset(bytes2, charset);
|
|
685
|
+
var decode = (input) => decodeBytesWithCharset(input, charset);
|
|
686
|
+
|
|
687
|
+
// src/ss58.ts
|
|
688
|
+
var CHECKSUM_BYTE_LENGTH = 2;
|
|
689
|
+
var DATA_LENGTH = 32;
|
|
690
|
+
var MAX_SIMPLE_PREFIX = 63;
|
|
691
|
+
var MAX_PREFIX = 16383;
|
|
692
|
+
var RESERVED_PREFIXES = [46, 47];
|
|
693
|
+
var computeChecksum = (data) => {
|
|
694
|
+
const checksumPrefix = [83, 83, 53, 56, 80, 82, 69];
|
|
695
|
+
const checksum = blake2b(new Uint8Array([...checksumPrefix, ...data]));
|
|
696
|
+
return checksum.slice(0, CHECKSUM_BYTE_LENGTH);
|
|
697
|
+
};
|
|
698
|
+
var decode2 = (input) => {
|
|
699
|
+
const decodedBytes = decode(input);
|
|
700
|
+
let ss58FormatLen;
|
|
701
|
+
let ss58Format;
|
|
702
|
+
if ((decodedBytes[0] & 64) !== 0) {
|
|
703
|
+
ss58FormatLen = 2;
|
|
704
|
+
ss58Format = (decodedBytes[0] & 63) << 2 | decodedBytes[1] >> 6 | (decodedBytes[1] & 63) << 8;
|
|
705
|
+
} else {
|
|
706
|
+
ss58FormatLen = 1;
|
|
707
|
+
ss58Format = decodedBytes[0];
|
|
708
|
+
}
|
|
709
|
+
assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
|
|
710
|
+
const checksumBytes = decodedBytes.splice(-CHECKSUM_BYTE_LENGTH);
|
|
711
|
+
const data = decodedBytes.slice(ss58FormatLen);
|
|
712
|
+
assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`);
|
|
713
|
+
const checksum = computeChecksum(decodedBytes);
|
|
714
|
+
assert(
|
|
715
|
+
checksumBytes[0] === checksum[0],
|
|
716
|
+
`Invalid checksum: ${checksumBytes[0]} !== ${checksum[0]}`
|
|
717
|
+
);
|
|
718
|
+
assert(
|
|
719
|
+
checksumBytes[1] === checksum[1],
|
|
720
|
+
`Invalid checksum: ${checksumBytes[1]} !== ${checksum[1]}`
|
|
721
|
+
);
|
|
722
|
+
return {
|
|
723
|
+
data: new Uint8Array(data),
|
|
724
|
+
ss58Format
|
|
725
|
+
};
|
|
726
|
+
};
|
|
727
|
+
var encode2 = ({
|
|
728
|
+
data: input,
|
|
729
|
+
ss58Format
|
|
730
|
+
}) => {
|
|
731
|
+
const data = typeof input === "string" ? hexToBytes(input) : input;
|
|
732
|
+
assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`, RangeError);
|
|
733
|
+
assert(ss58Format >= 0 && ss58Format <= MAX_PREFIX, `Invalid prefix: ${ss58Format}`, RangeError);
|
|
734
|
+
assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
|
|
735
|
+
let prefixBytes;
|
|
736
|
+
if (ss58Format <= MAX_SIMPLE_PREFIX) {
|
|
737
|
+
prefixBytes = [ss58Format];
|
|
738
|
+
} else {
|
|
739
|
+
prefixBytes = [
|
|
740
|
+
(ss58Format & 252) >> 2 | 64,
|
|
741
|
+
ss58Format >> 8 | (ss58Format & 3) << 6
|
|
742
|
+
];
|
|
743
|
+
}
|
|
744
|
+
const checksum = computeChecksum(new Uint8Array([...prefixBytes, ...data]));
|
|
745
|
+
return encode([...prefixBytes, ...data, ...checksum]);
|
|
746
|
+
};
|
|
747
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
748
|
+
0 && (module.exports = {
|
|
749
|
+
decode,
|
|
750
|
+
encode
|
|
751
|
+
});
|
|
752
|
+
/*! Bundled license information:
|
|
753
|
+
|
|
754
|
+
@noble/hashes/esm/utils.js:
|
|
755
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
756
|
+
*/
|