@chainflip/utils 0.11.3 → 2.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/addresses.cjs +15 -40
  3. package/dist/addresses.d.ts +4 -3
  4. package/dist/addresses.js +14 -15
  5. package/dist/assertion.cjs +23 -82
  6. package/dist/assertion.d.ts +3 -2
  7. package/dist/assertion.js +32 -22
  8. package/dist/async.cjs +96 -115
  9. package/dist/async.d.ts +24 -21
  10. package/dist/async.js +92 -87
  11. package/dist/base58.cjs +9 -93
  12. package/dist/base58.d.ts +4 -4
  13. package/dist/base58.js +9 -13
  14. package/dist/bytes.cjs +49 -97
  15. package/dist/bytes.d.ts +4 -4
  16. package/dist/bytes.js +51 -15
  17. package/dist/chainflip.cjs +428 -327
  18. package/dist/chainflip.d.ts +188 -185
  19. package/dist/chainflip.js +425 -41
  20. package/dist/consts.cjs +306 -277
  21. package/dist/consts.d.ts +18 -17
  22. package/dist/consts.js +296 -243
  23. package/dist/date.cjs +74 -131
  24. package/dist/date.d.ts +9 -8
  25. package/dist/date.js +60 -95
  26. package/dist/guard.cjs +28 -63
  27. package/dist/guard.d.ts +10 -9
  28. package/dist/guard.js +17 -28
  29. package/dist/math.cjs +7 -32
  30. package/dist/math.d.ts +3 -2
  31. package/dist/math.js +6 -7
  32. package/dist/number.cjs +5 -29
  33. package/dist/number.d.ts +4 -4
  34. package/dist/number.js +5 -5
  35. package/dist/ss58.cjs +62 -794
  36. package/dist/ss58.d.ts +12 -9
  37. package/dist/ss58.js +59 -712
  38. package/dist/string.cjs +29 -66
  39. package/dist/string.d.ts +4 -4
  40. package/dist/string.js +20 -33
  41. package/dist/tickMath.cjs +32 -232
  42. package/dist/tickMath.d.ts +7 -6
  43. package/dist/tickMath.js +24 -29
  44. package/dist/types.cjs +0 -18
  45. package/dist/types.d.ts +35 -34
  46. package/dist/types.js +1 -0
  47. package/dist/url.cjs +16 -37
  48. package/dist/url.d.ts +5 -4
  49. package/dist/url.js +16 -13
  50. package/package.json +5 -5
  51. package/dist/addresses.d.cts +0 -6
  52. package/dist/assertion.d.cts +0 -11
  53. package/dist/async.d.cts +0 -33
  54. package/dist/base58.d.cts +0 -8
  55. package/dist/bytes.d.cts +0 -11
  56. package/dist/chainflip.d.cts +0 -236
  57. package/dist/chunk-3P6TXYEI.js +0 -15
  58. package/dist/chunk-HBIFE4XN.js +0 -29
  59. package/dist/chunk-LJJH7U4M.js +0 -302
  60. package/dist/chunk-XGNPN5CY.js +0 -61
  61. package/dist/chunk-ZHIKNZLU.js +0 -66
  62. package/dist/consts.d.cts +0 -33
  63. package/dist/date.d.cts +0 -26
  64. package/dist/guard.d.cts +0 -23
  65. package/dist/math.d.cts +0 -4
  66. package/dist/number.d.cts +0 -6
  67. package/dist/ss58.d.cts +0 -14
  68. package/dist/string.d.cts +0 -16
  69. package/dist/tickMath.d.cts +0 -15
  70. package/dist/types.d.cts +0 -41
  71. package/dist/url.d.cts +0 -6
package/dist/ss58.js CHANGED
@@ -1,717 +1,64 @@
1
- import {
2
- decode,
3
- encode
4
- } from "./chunk-3P6TXYEI.js";
5
- import {
6
- bytesToHex,
7
- hexToBytes
8
- } from "./chunk-XGNPN5CY.js";
9
- import {
10
- assert
11
- } from "./chunk-ZHIKNZLU.js";
12
- import "./chunk-HBIFE4XN.js";
1
+ import { assert } from "./assertion.js";
2
+ import { bytesToHex, hexToBytes } from "./bytes.js";
3
+ import { decode as decode$1, encode as encode$1 } from "./base58.js";
4
+ import { blake2b } from "@noble/hashes/blake2.js";
13
5
 
14
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
15
- function isBytes(a) {
16
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
17
- }
18
- function anumber(n, title = "") {
19
- if (!Number.isSafeInteger(n) || n < 0) {
20
- const prefix = title && `"${title}" `;
21
- throw new Error(`${prefix}expected integer >= 0, got ${n}`);
22
- }
23
- }
24
- function abytes(value, length, title = "") {
25
- const bytes = isBytes(value);
26
- const len = value?.length;
27
- const needsLen = length !== void 0;
28
- if (!bytes || needsLen && len !== length) {
29
- const prefix = title && `"${title}" `;
30
- const ofLen = needsLen ? ` of length ${length}` : "";
31
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
32
- throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
33
- }
34
- return value;
35
- }
36
- function aexists(instance, checkFinished = true) {
37
- if (instance.destroyed)
38
- throw new Error("Hash instance has been destroyed");
39
- if (checkFinished && instance.finished)
40
- throw new Error("Hash#digest() has already been called");
41
- }
42
- function aoutput(out, instance) {
43
- abytes(out, void 0, "digestInto() output");
44
- const min = instance.outputLen;
45
- if (out.length < min) {
46
- throw new Error('"digestInto() output" expected to be of length >=' + min);
47
- }
48
- }
49
- function u32(arr) {
50
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
51
- }
52
- function clean(...arrays) {
53
- for (let i = 0; i < arrays.length; i++) {
54
- arrays[i].fill(0);
55
- }
56
- }
57
- var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
58
- function byteSwap(word) {
59
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
60
- }
61
- var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
62
- function byteSwap32(arr) {
63
- for (let i = 0; i < arr.length; i++) {
64
- arr[i] = byteSwap(arr[i]);
65
- }
66
- return arr;
67
- }
68
- var swap32IfBE = isLE ? (u) => u : byteSwap32;
69
- function createHasher(hashCons, info = {}) {
70
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
71
- const tmp = hashCons(void 0);
72
- hashC.outputLen = tmp.outputLen;
73
- hashC.blockLen = tmp.blockLen;
74
- hashC.create = (opts) => hashCons(opts);
75
- Object.assign(hashC, info);
76
- return Object.freeze(hashC);
77
- }
78
-
79
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_blake.js
80
- var BSIGMA = /* @__PURE__ */ Uint8Array.from([
81
- 0,
82
- 1,
83
- 2,
84
- 3,
85
- 4,
86
- 5,
87
- 6,
88
- 7,
89
- 8,
90
- 9,
91
- 10,
92
- 11,
93
- 12,
94
- 13,
95
- 14,
96
- 15,
97
- 14,
98
- 10,
99
- 4,
100
- 8,
101
- 9,
102
- 15,
103
- 13,
104
- 6,
105
- 1,
106
- 12,
107
- 0,
108
- 2,
109
- 11,
110
- 7,
111
- 5,
112
- 3,
113
- 11,
114
- 8,
115
- 12,
116
- 0,
117
- 5,
118
- 2,
119
- 15,
120
- 13,
121
- 10,
122
- 14,
123
- 3,
124
- 6,
125
- 7,
126
- 1,
127
- 9,
128
- 4,
129
- 7,
130
- 9,
131
- 3,
132
- 1,
133
- 13,
134
- 12,
135
- 11,
136
- 14,
137
- 2,
138
- 6,
139
- 5,
140
- 10,
141
- 4,
142
- 0,
143
- 15,
144
- 8,
145
- 9,
146
- 0,
147
- 5,
148
- 7,
149
- 2,
150
- 4,
151
- 10,
152
- 15,
153
- 14,
154
- 1,
155
- 11,
156
- 12,
157
- 6,
158
- 8,
159
- 3,
160
- 13,
161
- 2,
162
- 12,
163
- 6,
164
- 10,
165
- 0,
166
- 11,
167
- 8,
168
- 3,
169
- 4,
170
- 13,
171
- 7,
172
- 5,
173
- 15,
174
- 14,
175
- 1,
176
- 9,
177
- 12,
178
- 5,
179
- 1,
180
- 15,
181
- 14,
182
- 13,
183
- 4,
184
- 10,
185
- 0,
186
- 7,
187
- 6,
188
- 3,
189
- 9,
190
- 2,
191
- 8,
192
- 11,
193
- 13,
194
- 11,
195
- 7,
196
- 14,
197
- 12,
198
- 1,
199
- 3,
200
- 9,
201
- 5,
202
- 0,
203
- 15,
204
- 4,
205
- 8,
206
- 6,
207
- 2,
208
- 10,
209
- 6,
210
- 15,
211
- 14,
212
- 9,
213
- 11,
214
- 3,
215
- 0,
216
- 8,
217
- 12,
218
- 2,
219
- 13,
220
- 7,
221
- 1,
222
- 4,
223
- 10,
224
- 5,
225
- 10,
226
- 2,
227
- 8,
228
- 4,
229
- 7,
230
- 6,
231
- 1,
232
- 5,
233
- 15,
234
- 11,
235
- 9,
236
- 14,
237
- 3,
238
- 12,
239
- 13,
240
- 0,
241
- 0,
242
- 1,
243
- 2,
244
- 3,
245
- 4,
246
- 5,
247
- 6,
248
- 7,
249
- 8,
250
- 9,
251
- 10,
252
- 11,
253
- 12,
254
- 13,
255
- 14,
256
- 15,
257
- 14,
258
- 10,
259
- 4,
260
- 8,
261
- 9,
262
- 15,
263
- 13,
264
- 6,
265
- 1,
266
- 12,
267
- 0,
268
- 2,
269
- 11,
270
- 7,
271
- 5,
272
- 3,
273
- // Blake1, unused in others
274
- 11,
275
- 8,
276
- 12,
277
- 0,
278
- 5,
279
- 2,
280
- 15,
281
- 13,
282
- 10,
283
- 14,
284
- 3,
285
- 6,
286
- 7,
287
- 1,
288
- 9,
289
- 4,
290
- 7,
291
- 9,
292
- 3,
293
- 1,
294
- 13,
295
- 12,
296
- 11,
297
- 14,
298
- 2,
299
- 6,
300
- 5,
301
- 10,
302
- 4,
303
- 0,
304
- 15,
305
- 8,
306
- 9,
307
- 0,
308
- 5,
309
- 7,
310
- 2,
311
- 4,
312
- 10,
313
- 15,
314
- 14,
315
- 1,
316
- 11,
317
- 12,
318
- 6,
319
- 8,
320
- 3,
321
- 13,
322
- 2,
323
- 12,
324
- 6,
325
- 10,
326
- 0,
327
- 11,
328
- 8,
329
- 3,
330
- 4,
331
- 13,
332
- 7,
333
- 5,
334
- 15,
335
- 14,
336
- 1,
337
- 9
338
- ]);
339
-
340
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
341
- var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
342
- var _32n = /* @__PURE__ */ BigInt(32);
343
- function fromBig(n, le = false) {
344
- if (le)
345
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
346
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
347
- }
348
- var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
349
- var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
350
- var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
351
- var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
352
- var rotr32H = (_h, l) => l;
353
- var rotr32L = (h, _l) => h;
354
- function add(Ah, Al, Bh, Bl) {
355
- const l = (Al >>> 0) + (Bl >>> 0);
356
- return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
357
- }
358
- var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
359
- var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
360
-
361
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/blake2.js
362
- var B2B_IV = /* @__PURE__ */ Uint32Array.from([
363
- 4089235720,
364
- 1779033703,
365
- 2227873595,
366
- 3144134277,
367
- 4271175723,
368
- 1013904242,
369
- 1595750129,
370
- 2773480762,
371
- 2917565137,
372
- 1359893119,
373
- 725511199,
374
- 2600822924,
375
- 4215389547,
376
- 528734635,
377
- 327033209,
378
- 1541459225
379
- ]);
380
- var BBUF = /* @__PURE__ */ new Uint32Array(32);
381
- function G1b(a, b, c, d, msg, x) {
382
- const Xl = msg[x], Xh = msg[x + 1];
383
- let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
384
- let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
385
- let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
386
- let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
387
- let ll = add3L(Al, Bl, Xl);
388
- Ah = add3H(ll, Ah, Bh, Xh);
389
- Al = ll | 0;
390
- ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
391
- ({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh, Dl) });
392
- ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
393
- ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
394
- ({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
395
- BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
396
- BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
397
- BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
398
- BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
399
- }
400
- function G2b(a, b, c, d, msg, x) {
401
- const Xl = msg[x], Xh = msg[x + 1];
402
- let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
403
- let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
404
- let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
405
- let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
406
- let ll = add3L(Al, Bl, Xl);
407
- Ah = add3H(ll, Ah, Bh, Xh);
408
- Al = ll | 0;
409
- ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
410
- ({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
411
- ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
412
- ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
413
- ({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });
414
- BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
415
- BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
416
- BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
417
- BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
418
- }
419
- function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
420
- anumber(keyLen);
421
- if (outputLen < 0 || outputLen > keyLen)
422
- throw new Error("outputLen bigger than keyLen");
423
- const { key, salt, personalization } = opts;
424
- if (key !== void 0 && (key.length < 1 || key.length > keyLen))
425
- throw new Error('"key" expected to be undefined or of length=1..' + keyLen);
426
- if (salt !== void 0)
427
- abytes(salt, saltLen, "salt");
428
- if (personalization !== void 0)
429
- abytes(personalization, persLen, "personalization");
430
- }
431
- var _BLAKE2 = class {
432
- buffer;
433
- buffer32;
434
- finished = false;
435
- destroyed = false;
436
- length = 0;
437
- pos = 0;
438
- blockLen;
439
- outputLen;
440
- constructor(blockLen, outputLen) {
441
- anumber(blockLen);
442
- anumber(outputLen);
443
- this.blockLen = blockLen;
444
- this.outputLen = outputLen;
445
- this.buffer = new Uint8Array(blockLen);
446
- this.buffer32 = u32(this.buffer);
447
- }
448
- update(data) {
449
- aexists(this);
450
- abytes(data);
451
- const { blockLen, buffer, buffer32 } = this;
452
- const len = data.length;
453
- const offset = data.byteOffset;
454
- const buf = data.buffer;
455
- for (let pos = 0; pos < len; ) {
456
- if (this.pos === blockLen) {
457
- swap32IfBE(buffer32);
458
- this.compress(buffer32, 0, false);
459
- swap32IfBE(buffer32);
460
- this.pos = 0;
461
- }
462
- const take = Math.min(blockLen - this.pos, len - pos);
463
- const dataOffset = offset + pos;
464
- if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
465
- const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
466
- swap32IfBE(data32);
467
- for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
468
- this.length += blockLen;
469
- this.compress(data32, pos32, false);
470
- }
471
- swap32IfBE(data32);
472
- continue;
473
- }
474
- buffer.set(data.subarray(pos, pos + take), this.pos);
475
- this.pos += take;
476
- this.length += take;
477
- pos += take;
478
- }
479
- return this;
480
- }
481
- digestInto(out) {
482
- aexists(this);
483
- aoutput(out, this);
484
- const { pos, buffer32 } = this;
485
- this.finished = true;
486
- clean(this.buffer.subarray(pos));
487
- swap32IfBE(buffer32);
488
- this.compress(buffer32, 0, true);
489
- swap32IfBE(buffer32);
490
- const out32 = u32(out);
491
- this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
492
- }
493
- digest() {
494
- const { buffer, outputLen } = this;
495
- this.digestInto(buffer);
496
- const res = buffer.slice(0, outputLen);
497
- this.destroy();
498
- return res;
499
- }
500
- _cloneInto(to) {
501
- const { buffer, length, finished, destroyed, outputLen, pos } = this;
502
- to ||= new this.constructor({ dkLen: outputLen });
503
- to.set(...this.get());
504
- to.buffer.set(buffer);
505
- to.destroyed = destroyed;
506
- to.finished = finished;
507
- to.length = length;
508
- to.pos = pos;
509
- to.outputLen = outputLen;
510
- return to;
511
- }
512
- clone() {
513
- return this._cloneInto();
514
- }
515
- };
516
- var _BLAKE2b = class extends _BLAKE2 {
517
- // Same as SHA-512, but LE
518
- v0l = B2B_IV[0] | 0;
519
- v0h = B2B_IV[1] | 0;
520
- v1l = B2B_IV[2] | 0;
521
- v1h = B2B_IV[3] | 0;
522
- v2l = B2B_IV[4] | 0;
523
- v2h = B2B_IV[5] | 0;
524
- v3l = B2B_IV[6] | 0;
525
- v3h = B2B_IV[7] | 0;
526
- v4l = B2B_IV[8] | 0;
527
- v4h = B2B_IV[9] | 0;
528
- v5l = B2B_IV[10] | 0;
529
- v5h = B2B_IV[11] | 0;
530
- v6l = B2B_IV[12] | 0;
531
- v6h = B2B_IV[13] | 0;
532
- v7l = B2B_IV[14] | 0;
533
- v7h = B2B_IV[15] | 0;
534
- constructor(opts = {}) {
535
- const olen = opts.dkLen === void 0 ? 64 : opts.dkLen;
536
- super(128, olen);
537
- checkBlake2Opts(olen, opts, 64, 16, 16);
538
- let { key, personalization, salt } = opts;
539
- let keyLength = 0;
540
- if (key !== void 0) {
541
- abytes(key, void 0, "key");
542
- keyLength = key.length;
543
- }
544
- this.v0l ^= this.outputLen | keyLength << 8 | 1 << 16 | 1 << 24;
545
- if (salt !== void 0) {
546
- abytes(salt, void 0, "salt");
547
- const slt = u32(salt);
548
- this.v4l ^= swap8IfBE(slt[0]);
549
- this.v4h ^= swap8IfBE(slt[1]);
550
- this.v5l ^= swap8IfBE(slt[2]);
551
- this.v5h ^= swap8IfBE(slt[3]);
552
- }
553
- if (personalization !== void 0) {
554
- abytes(personalization, void 0, "personalization");
555
- const pers = u32(personalization);
556
- this.v6l ^= swap8IfBE(pers[0]);
557
- this.v6h ^= swap8IfBE(pers[1]);
558
- this.v7l ^= swap8IfBE(pers[2]);
559
- this.v7h ^= swap8IfBE(pers[3]);
560
- }
561
- if (key !== void 0) {
562
- const tmp = new Uint8Array(this.blockLen);
563
- tmp.set(key);
564
- this.update(tmp);
565
- }
566
- }
567
- // prettier-ignore
568
- get() {
569
- let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
570
- return [v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h];
571
- }
572
- // prettier-ignore
573
- set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
574
- this.v0l = v0l | 0;
575
- this.v0h = v0h | 0;
576
- this.v1l = v1l | 0;
577
- this.v1h = v1h | 0;
578
- this.v2l = v2l | 0;
579
- this.v2h = v2h | 0;
580
- this.v3l = v3l | 0;
581
- this.v3h = v3h | 0;
582
- this.v4l = v4l | 0;
583
- this.v4h = v4h | 0;
584
- this.v5l = v5l | 0;
585
- this.v5h = v5h | 0;
586
- this.v6l = v6l | 0;
587
- this.v6h = v6h | 0;
588
- this.v7l = v7l | 0;
589
- this.v7h = v7h | 0;
590
- }
591
- compress(msg, offset, isLast) {
592
- this.get().forEach((v, i) => BBUF[i] = v);
593
- BBUF.set(B2B_IV, 16);
594
- let { h, l } = fromBig(BigInt(this.length));
595
- BBUF[24] = B2B_IV[8] ^ l;
596
- BBUF[25] = B2B_IV[9] ^ h;
597
- if (isLast) {
598
- BBUF[28] = ~BBUF[28];
599
- BBUF[29] = ~BBUF[29];
600
- }
601
- let j = 0;
602
- const s = BSIGMA;
603
- for (let i = 0; i < 12; i++) {
604
- G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
605
- G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
606
- G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
607
- G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
608
- G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
609
- G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
610
- G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
611
- G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
612
- G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
613
- G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
614
- G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
615
- G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
616
- G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
617
- G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
618
- G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
619
- G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
620
- }
621
- this.v0l ^= BBUF[0] ^ BBUF[16];
622
- this.v0h ^= BBUF[1] ^ BBUF[17];
623
- this.v1l ^= BBUF[2] ^ BBUF[18];
624
- this.v1h ^= BBUF[3] ^ BBUF[19];
625
- this.v2l ^= BBUF[4] ^ BBUF[20];
626
- this.v2h ^= BBUF[5] ^ BBUF[21];
627
- this.v3l ^= BBUF[6] ^ BBUF[22];
628
- this.v3h ^= BBUF[7] ^ BBUF[23];
629
- this.v4l ^= BBUF[8] ^ BBUF[24];
630
- this.v4h ^= BBUF[9] ^ BBUF[25];
631
- this.v5l ^= BBUF[10] ^ BBUF[26];
632
- this.v5h ^= BBUF[11] ^ BBUF[27];
633
- this.v6l ^= BBUF[12] ^ BBUF[28];
634
- this.v6h ^= BBUF[13] ^ BBUF[29];
635
- this.v7l ^= BBUF[14] ^ BBUF[30];
636
- this.v7h ^= BBUF[15] ^ BBUF[31];
637
- clean(BBUF);
638
- }
639
- destroy() {
640
- this.destroyed = true;
641
- clean(this.buffer32);
642
- this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
643
- }
644
- };
645
- var blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
646
-
647
- // src/ss58.ts
648
- var CHECKSUM_BYTE_LENGTH = 2;
649
- var DATA_LENGTH = 32;
650
- var MAX_SIMPLE_PREFIX = 63;
651
- var MAX_PREFIX = 16383;
652
- var RESERVED_PREFIXES = [46, 47];
653
- var computeChecksum = (data) => {
654
- const checksumPrefix = [83, 83, 53, 56, 80, 82, 69];
655
- const checksum = blake2b(new Uint8Array([...checksumPrefix, ...data]));
656
- return checksum.slice(0, CHECKSUM_BYTE_LENGTH);
657
- };
658
- var decode2 = (input) => {
659
- const decodedBytes = decode(input);
660
- let ss58FormatLen;
661
- let ss58Format;
662
- if ((decodedBytes[0] & 64) !== 0) {
663
- ss58FormatLen = 2;
664
- ss58Format = (decodedBytes[0] & 63) << 2 | decodedBytes[1] >> 6 | (decodedBytes[1] & 63) << 8;
665
- } else {
666
- ss58FormatLen = 1;
667
- [ss58Format] = decodedBytes;
668
- }
669
- assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
670
- const checksumBytes = decodedBytes.slice(-CHECKSUM_BYTE_LENGTH);
671
- const data = decodedBytes.slice(ss58FormatLen, -CHECKSUM_BYTE_LENGTH);
672
- assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`);
673
- const checksum = computeChecksum(decodedBytes.slice(0, -CHECKSUM_BYTE_LENGTH));
674
- assert(
675
- checksumBytes[0] === checksum[0],
676
- `Invalid checksum: ${checksumBytes[0]} !== ${checksum[0]}`
677
- );
678
- assert(
679
- checksumBytes[1] === checksum[1],
680
- `Invalid checksum: ${checksumBytes[1]} !== ${checksum[1]}`
681
- );
682
- return {
683
- data: new Uint8Array(data),
684
- ss58Format
685
- };
6
+ //#region src/ss58.ts
7
+ const CHECKSUM_BYTE_LENGTH = 2;
8
+ const DATA_LENGTH = 32;
9
+ const MAX_SIMPLE_PREFIX = 63;
10
+ const MAX_PREFIX = 16383;
11
+ const RESERVED_PREFIXES = [46, 47];
12
+ const computeChecksum = (data) => {
13
+ return blake2b(new Uint8Array([...[
14
+ 83,
15
+ 83,
16
+ 53,
17
+ 56,
18
+ 80,
19
+ 82,
20
+ 69
21
+ ], ...data])).slice(0, CHECKSUM_BYTE_LENGTH);
686
22
  };
687
- var encode2 = ({
688
- data: input,
689
- ss58Format
690
- }) => {
691
- const data = typeof input === "string" ? hexToBytes(input) : input;
692
- assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`, RangeError);
693
- assert(ss58Format >= 0 && ss58Format <= MAX_PREFIX, `Invalid prefix: ${ss58Format}`, RangeError);
694
- assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
695
- let prefixBytes;
696
- if (ss58Format <= MAX_SIMPLE_PREFIX) {
697
- prefixBytes = [ss58Format];
698
- } else {
699
- prefixBytes = [
700
- (ss58Format & 252) >> 2 | 64,
701
- ss58Format >> 8 | (ss58Format & 3) << 6
702
- ];
703
- }
704
- const checksum = computeChecksum(new Uint8Array([...prefixBytes, ...data]));
705
- return encode([...prefixBytes, ...data, ...checksum]);
23
+ const decode = (input) => {
24
+ const decodedBytes = decode$1(input);
25
+ let ss58FormatLen;
26
+ let ss58Format;
27
+ if ((decodedBytes[0] & 64) !== 0) {
28
+ ss58FormatLen = 2;
29
+ ss58Format = (decodedBytes[0] & 63) << 2 | decodedBytes[1] >> 6 | (decodedBytes[1] & 63) << 8;
30
+ } else {
31
+ ss58FormatLen = 1;
32
+ [ss58Format] = decodedBytes;
33
+ }
34
+ assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
35
+ const checksumBytes = decodedBytes.slice(-CHECKSUM_BYTE_LENGTH);
36
+ const data = decodedBytes.slice(ss58FormatLen, -CHECKSUM_BYTE_LENGTH);
37
+ assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`);
38
+ const checksum = computeChecksum(decodedBytes.slice(0, -CHECKSUM_BYTE_LENGTH));
39
+ assert(checksumBytes[0] === checksum[0], `Invalid checksum: ${checksumBytes[0]} !== ${checksum[0]}`);
40
+ assert(checksumBytes[1] === checksum[1], `Invalid checksum: ${checksumBytes[1]} !== ${checksum[1]}`);
41
+ return {
42
+ data: new Uint8Array(data),
43
+ ss58Format
44
+ };
706
45
  };
707
- var toPublicKey = (address) => bytesToHex(decode2(address).data);
708
- export {
709
- decode2 as decode,
710
- encode2 as encode,
711
- toPublicKey
46
+ const encode = ({ data: input, ss58Format }) => {
47
+ const data = typeof input === "string" ? hexToBytes(input) : input;
48
+ assert(data.length === DATA_LENGTH, `Invalid data length: ${data.length}`, RangeError);
49
+ assert(ss58Format >= 0 && ss58Format <= MAX_PREFIX, `Invalid prefix: ${ss58Format}`, RangeError);
50
+ assert(!RESERVED_PREFIXES.includes(ss58Format), `Reserved prefix: ${ss58Format}`);
51
+ let prefixBytes;
52
+ if (ss58Format <= MAX_SIMPLE_PREFIX) prefixBytes = [ss58Format];
53
+ else prefixBytes = [(ss58Format & 252) >> 2 | 64, ss58Format >> 8 | (ss58Format & 3) << 6];
54
+ const checksum = computeChecksum(new Uint8Array([...prefixBytes, ...data]));
55
+ return encode$1([
56
+ ...prefixBytes,
57
+ ...data,
58
+ ...checksum
59
+ ]);
712
60
  };
713
- /*! Bundled license information:
61
+ const toPublicKey = (address) => bytesToHex(decode(address).data);
714
62
 
715
- @noble/hashes/utils.js:
716
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
717
- */
63
+ //#endregion
64
+ export { decode, encode, toPublicKey };