@chainflip/utils 0.8.6 → 0.8.8

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/consts.cjs CHANGED
@@ -130,6 +130,10 @@ var brokerAliasMap = {
130
130
  name: "SwapKit",
131
131
  twitter: "@SwapKitPowered"
132
132
  },
133
+ cFPDEjR88FyRi7V5NDatoMAyMCczgiyoXwiJA4LZLrR7e6RW4: {
134
+ name: "Bitget",
135
+ twitter: "@BitgetWallet"
136
+ },
133
137
  cFL4To8Uow6B1hk4dNrhWhvKpkBtnUTrVdWCEKCaXiXMMztjM: {
134
138
  name: "SwapKit",
135
139
  twitter: "@SwapKitPowered"
@@ -138,6 +142,10 @@ var brokerAliasMap = {
138
142
  name: "Cake Wallet",
139
143
  twitter: "@cakewallet"
140
144
  },
145
+ cFJibLYo59hWoy93d9AgGzR6NfvRywcPFN4SEzhJP2toA7Ffu: {
146
+ name: "Trust Wallet",
147
+ twitter: "@TrustWallet"
148
+ },
141
149
  cFLre1qinRDSoxnQ4sFEXRde58jkmkVMX7B2NFGkgZJ9pQLqF: {
142
150
  name: "Trust Wallet",
143
151
  twitter: "@TrustWallet"
@@ -157,6 +165,10 @@ var brokerAliasMap = {
157
165
  cFJZvt5AiEGwUiFFNxhDuLRcgC1WBR6tE7gaQQfe8dqbzoYkx: {
158
166
  name: "Symbiosis",
159
167
  twitter: "@symbiosis_fi"
168
+ },
169
+ cFLvH2ZA3J5dsDdrDuV1Eyh9Jk6yasijtKQagGhMDKoKBU3pc: {
170
+ name: "LeoDex",
171
+ twitter: "@leodexio"
160
172
  }
161
173
  };
162
174
  var lpAliasMap = {
package/dist/consts.js CHANGED
@@ -96,6 +96,10 @@ var brokerAliasMap = {
96
96
  name: "SwapKit",
97
97
  twitter: "@SwapKitPowered"
98
98
  },
99
+ cFPDEjR88FyRi7V5NDatoMAyMCczgiyoXwiJA4LZLrR7e6RW4: {
100
+ name: "Bitget",
101
+ twitter: "@BitgetWallet"
102
+ },
99
103
  cFL4To8Uow6B1hk4dNrhWhvKpkBtnUTrVdWCEKCaXiXMMztjM: {
100
104
  name: "SwapKit",
101
105
  twitter: "@SwapKitPowered"
@@ -104,6 +108,10 @@ var brokerAliasMap = {
104
108
  name: "Cake Wallet",
105
109
  twitter: "@cakewallet"
106
110
  },
111
+ cFJibLYo59hWoy93d9AgGzR6NfvRywcPFN4SEzhJP2toA7Ffu: {
112
+ name: "Trust Wallet",
113
+ twitter: "@TrustWallet"
114
+ },
107
115
  cFLre1qinRDSoxnQ4sFEXRde58jkmkVMX7B2NFGkgZJ9pQLqF: {
108
116
  name: "Trust Wallet",
109
117
  twitter: "@TrustWallet"
@@ -123,6 +131,10 @@ var brokerAliasMap = {
123
131
  cFJZvt5AiEGwUiFFNxhDuLRcgC1WBR6tE7gaQQfe8dqbzoYkx: {
124
132
  name: "Symbiosis",
125
133
  twitter: "@symbiosis_fi"
134
+ },
135
+ cFLvH2ZA3J5dsDdrDuV1Eyh9Jk6yasijtKQagGhMDKoKBU3pc: {
136
+ name: "LeoDex",
137
+ twitter: "@leodexio"
126
138
  }
127
139
  };
128
140
  var lpAliasMap = {
package/dist/number.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,73 +15,16 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/number.ts
31
21
  var number_exports = {};
32
22
  __export(number_exports, {
33
- formatUsdValue: () => formatUsdValue,
34
23
  hexEncodeNumber: () => hexEncodeNumber
35
24
  });
36
25
  module.exports = __toCommonJS(number_exports);
37
- var import_bignumber = __toESM(require("bignumber.js"), 1);
38
-
39
- // src/guard.ts
40
- var createIsGuard = (type) => (value) => typeof value === type;
41
- var isString = createIsGuard("string");
42
- var isNumber = createIsGuard("number");
43
- var isBigInt = createIsGuard("bigint");
44
- var isBoolean = createIsGuard("boolean");
45
- var isSymbol = createIsGuard("symbol");
46
- var isObject = createIsGuard("object");
47
- var isUndefined = createIsGuard("undefined");
48
-
49
- // src/assertion.ts
50
- function assert(condition, message = "assertion failed", Constructor = Error) {
51
- if (!condition) {
52
- throw new Constructor(message);
53
- }
54
- }
55
-
56
- // src/number.ts
57
26
  var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
58
- function formatUsdValue(value, precise = true) {
59
- if (value == null) return value;
60
- let usdAmount = new import_bignumber.default(value);
61
- assert(usdAmount.gte(0), "negative amounts not supported");
62
- if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
63
- let suffix = "";
64
- let decimals = 2;
65
- if (!precise) {
66
- if (usdAmount.gte(1e12)) {
67
- usdAmount = usdAmount.shiftedBy(-12);
68
- suffix = "T";
69
- } else if (usdAmount.gte(1e9)) {
70
- usdAmount = usdAmount.shiftedBy(-9);
71
- suffix = "B";
72
- } else if (usdAmount.gte(1e6)) {
73
- usdAmount = usdAmount.shiftedBy(-6);
74
- suffix = "M";
75
- }
76
- if (suffix === "" && usdAmount.gte(1e4)) {
77
- decimals = 0;
78
- } else if (suffix !== "") {
79
- decimals = void 0;
80
- }
81
- }
82
- usdAmount = usdAmount.decimalPlaces(2);
83
- return `$${usdAmount.toFormat(decimals)}${suffix}`;
84
- }
85
27
  // Annotate the CommonJS export names for ESM import in node:
86
28
  0 && (module.exports = {
87
- formatUsdValue,
88
29
  hexEncodeNumber
89
30
  });
package/dist/number.d.cts CHANGED
@@ -1,11 +1,6 @@
1
- import BigNumber from 'bignumber.js';
2
1
  import { HexString } from './types.cjs';
3
2
  import './chainflip.cjs';
4
3
 
5
4
  declare const hexEncodeNumber: (num: number | bigint) => HexString;
6
- declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
7
- declare function formatUsdValue(value: null, precise?: boolean): null;
8
- declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
9
- declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
10
5
 
11
- export { formatUsdValue, hexEncodeNumber };
6
+ export { hexEncodeNumber };
package/dist/number.d.ts CHANGED
@@ -1,11 +1,6 @@
1
- import BigNumber from 'bignumber.js';
2
1
  import { HexString } from './types.js';
3
2
  import './chainflip.js';
4
3
 
5
4
  declare const hexEncodeNumber: (num: number | bigint) => HexString;
6
- declare function formatUsdValue(value: BigNumber.Value, precise?: boolean): string;
7
- declare function formatUsdValue(value: null, precise?: boolean): null;
8
- declare function formatUsdValue(value: undefined, precise?: boolean): undefined;
9
- declare function formatUsdValue(value: BigNumber.Value | null | undefined, precise?: boolean): string | null | undefined;
10
5
 
11
- export { formatUsdValue, hexEncodeNumber };
6
+ export { hexEncodeNumber };
package/dist/number.js CHANGED
@@ -1,39 +1,5 @@
1
- import {
2
- assert
3
- } from "./chunk-ZHIKNZLU.js";
4
- import "./chunk-HBIFE4XN.js";
5
-
6
1
  // src/number.ts
7
- import BigNumber from "bignumber.js";
8
2
  var hexEncodeNumber = (num) => `0x${num.toString(16)}`;
9
- function formatUsdValue(value, precise = true) {
10
- if (value == null) return value;
11
- let usdAmount = new BigNumber(value);
12
- assert(usdAmount.gte(0), "negative amounts not supported");
13
- if (!usdAmount.eq(0) && usdAmount.lt(0.01)) return `<$0.01`;
14
- let suffix = "";
15
- let decimals = 2;
16
- if (!precise) {
17
- if (usdAmount.gte(1e12)) {
18
- usdAmount = usdAmount.shiftedBy(-12);
19
- suffix = "T";
20
- } else if (usdAmount.gte(1e9)) {
21
- usdAmount = usdAmount.shiftedBy(-9);
22
- suffix = "B";
23
- } else if (usdAmount.gte(1e6)) {
24
- usdAmount = usdAmount.shiftedBy(-6);
25
- suffix = "M";
26
- }
27
- if (suffix === "" && usdAmount.gte(1e4)) {
28
- decimals = 0;
29
- } else if (suffix !== "") {
30
- decimals = void 0;
31
- }
32
- }
33
- usdAmount = usdAmount.decimalPlaces(2);
34
- return `$${usdAmount.toFormat(decimals)}${suffix}`;
35
- }
36
3
  export {
37
- formatUsdValue,
38
4
  hexEncodeNumber
39
5
  };
package/dist/ss58.cjs CHANGED
@@ -26,14 +26,14 @@ __export(ss58_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(ss58_exports);
28
28
 
29
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_assert.js
29
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
30
+ function isBytes(a) {
31
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
32
+ }
30
33
  function anumber(n) {
31
34
  if (!Number.isSafeInteger(n) || n < 0)
32
35
  throw new Error("positive integer expected, got " + n);
33
36
  }
34
- function isBytes(a) {
35
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
36
- }
37
37
  function abytes(b, ...lengths) {
38
38
  if (!isBytes(b))
39
39
  throw new Error("Uint8Array expected");
@@ -53,24 +53,29 @@ function aoutput(out, instance) {
53
53
  throw new Error("digestInto() expects output buffer of length at least " + min);
54
54
  }
55
55
  }
56
-
57
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/utils.js
58
56
  function u32(arr) {
59
57
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
60
58
  }
59
+ function clean(...arrays) {
60
+ for (let i = 0; i < arrays.length; i++) {
61
+ arrays[i].fill(0);
62
+ }
63
+ }
61
64
  var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
62
65
  function byteSwap(word) {
63
66
  return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
64
67
  }
65
- var byteSwapIfBE = isLE ? (n) => n : (n) => byteSwap(n);
68
+ var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
66
69
  function byteSwap32(arr) {
67
70
  for (let i = 0; i < arr.length; i++) {
68
71
  arr[i] = byteSwap(arr[i]);
69
72
  }
73
+ return arr;
70
74
  }
75
+ var swap32IfBE = isLE ? (u) => u : byteSwap32;
71
76
  function utf8ToBytes(str) {
72
77
  if (typeof str !== "string")
73
- throw new Error("utf8ToBytes expected string, got " + typeof str);
78
+ throw new Error("string expected");
74
79
  return new Uint8Array(new TextEncoder().encode(str));
75
80
  }
76
81
  function toBytes(data) {
@@ -80,12 +85,8 @@ function toBytes(data) {
80
85
  return data;
81
86
  }
82
87
  var Hash = class {
83
- // Safe version that clones internal state
84
- clone() {
85
- return this._cloneInto();
86
- }
87
88
  };
88
- function wrapConstructorWithOpts(hashCons) {
89
+ function createOptHasher(hashCons) {
89
90
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
90
91
  const tmp = hashCons({});
91
92
  hashC.outputLen = tmp.outputLen;
@@ -94,8 +95,8 @@ function wrapConstructorWithOpts(hashCons) {
94
95
  return hashC;
95
96
  }
96
97
 
97
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_blake.js
98
- var SIGMA = /* @__PURE__ */ new Uint8Array([
98
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_blake.js
99
+ var BSIGMA = /* @__PURE__ */ Uint8Array.from([
99
100
  0,
100
101
  1,
101
102
  2,
@@ -354,102 +355,8 @@ var SIGMA = /* @__PURE__ */ new Uint8Array([
354
355
  1,
355
356
  9
356
357
  ]);
357
- var BLAKE = class extends Hash {
358
- constructor(blockLen, outputLen, opts = {}, keyLen, saltLen, persLen) {
359
- super();
360
- this.blockLen = blockLen;
361
- this.outputLen = outputLen;
362
- this.length = 0;
363
- this.pos = 0;
364
- this.finished = false;
365
- this.destroyed = false;
366
- anumber(blockLen);
367
- anumber(outputLen);
368
- anumber(keyLen);
369
- if (outputLen < 0 || outputLen > keyLen)
370
- throw new Error("outputLen bigger than keyLen");
371
- if (opts.key !== void 0 && (opts.key.length < 1 || opts.key.length > keyLen))
372
- throw new Error("key length must be undefined or 1.." + keyLen);
373
- if (opts.salt !== void 0 && opts.salt.length !== saltLen)
374
- throw new Error("salt must be undefined or " + saltLen);
375
- if (opts.personalization !== void 0 && opts.personalization.length !== persLen)
376
- throw new Error("personalization must be undefined or " + persLen);
377
- this.buffer = new Uint8Array(blockLen);
378
- this.buffer32 = u32(this.buffer);
379
- }
380
- update(data) {
381
- aexists(this);
382
- const { blockLen, buffer, buffer32 } = this;
383
- data = toBytes(data);
384
- const len = data.length;
385
- const offset = data.byteOffset;
386
- const buf = data.buffer;
387
- for (let pos = 0; pos < len; ) {
388
- if (this.pos === blockLen) {
389
- if (!isLE)
390
- byteSwap32(buffer32);
391
- this.compress(buffer32, 0, false);
392
- if (!isLE)
393
- byteSwap32(buffer32);
394
- this.pos = 0;
395
- }
396
- const take = Math.min(blockLen - this.pos, len - pos);
397
- const dataOffset = offset + pos;
398
- if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
399
- const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
400
- if (!isLE)
401
- byteSwap32(data32);
402
- for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
403
- this.length += blockLen;
404
- this.compress(data32, pos32, false);
405
- }
406
- if (!isLE)
407
- byteSwap32(data32);
408
- continue;
409
- }
410
- buffer.set(data.subarray(pos, pos + take), this.pos);
411
- this.pos += take;
412
- this.length += take;
413
- pos += take;
414
- }
415
- return this;
416
- }
417
- digestInto(out) {
418
- aexists(this);
419
- aoutput(out, this);
420
- const { pos, buffer32 } = this;
421
- this.finished = true;
422
- this.buffer.subarray(pos).fill(0);
423
- if (!isLE)
424
- byteSwap32(buffer32);
425
- this.compress(buffer32, 0, true);
426
- if (!isLE)
427
- byteSwap32(buffer32);
428
- const out32 = u32(out);
429
- this.get().forEach((v, i) => out32[i] = byteSwapIfBE(v));
430
- }
431
- digest() {
432
- const { buffer, outputLen } = this;
433
- this.digestInto(buffer);
434
- const res = buffer.slice(0, outputLen);
435
- this.destroy();
436
- return res;
437
- }
438
- _cloneInto(to) {
439
- const { buffer, length, finished, destroyed, outputLen, pos } = this;
440
- to || (to = new this.constructor({ dkLen: outputLen }));
441
- to.set(...this.get());
442
- to.length = length;
443
- to.finished = finished;
444
- to.destroyed = destroyed;
445
- to.outputLen = outputLen;
446
- to.buffer.set(buffer);
447
- to.pos = pos;
448
- return to;
449
- }
450
- };
451
358
 
452
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_u64.js
359
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
453
360
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
454
361
  var _32n = /* @__PURE__ */ BigInt(32);
455
362
  function fromBig(n, le = false) {
@@ -457,66 +364,21 @@ function fromBig(n, le = false) {
457
364
  return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
458
365
  return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
459
366
  }
460
- function split(lst, le = false) {
461
- let Ah = new Uint32Array(lst.length);
462
- let Al = new Uint32Array(lst.length);
463
- for (let i = 0; i < lst.length; i++) {
464
- const { h, l } = fromBig(lst[i], le);
465
- [Ah[i], Al[i]] = [h, l];
466
- }
467
- return [Ah, Al];
468
- }
469
- var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
470
- var shrSH = (h, _l, s) => h >>> s;
471
- var shrSL = (h, l, s) => h << 32 - s | l >>> s;
472
367
  var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
473
368
  var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
474
369
  var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
475
370
  var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
476
371
  var rotr32H = (_h, l) => l;
477
372
  var rotr32L = (h, _l) => h;
478
- var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
479
- var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
480
- var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
481
- var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
482
373
  function add(Ah, Al, Bh, Bl) {
483
374
  const l = (Al >>> 0) + (Bl >>> 0);
484
375
  return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
485
376
  }
486
377
  var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
487
378
  var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
488
- var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
489
- var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
490
- var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
491
- var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
492
- var u64 = {
493
- fromBig,
494
- split,
495
- toBig,
496
- shrSH,
497
- shrSL,
498
- rotrSH,
499
- rotrSL,
500
- rotrBH,
501
- rotrBL,
502
- rotr32H,
503
- rotr32L,
504
- rotlSH,
505
- rotlSL,
506
- rotlBH,
507
- rotlBL,
508
- add,
509
- add3L,
510
- add3H,
511
- add4L,
512
- add4H,
513
- add5H,
514
- add5L
515
- };
516
- var u64_default = u64;
517
379
 
518
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/blake2b.js
519
- var B2B_IV = /* @__PURE__ */ new Uint32Array([
380
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/blake2.js
381
+ var B2B_IV = /* @__PURE__ */ Uint32Array.from([
520
382
  4089235720,
521
383
  1779033703,
522
384
  2227873595,
@@ -541,14 +403,14 @@ function G1b(a, b, c, d, msg, x) {
541
403
  let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
542
404
  let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
543
405
  let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
544
- let ll = u64_default.add3L(Al, Bl, Xl);
545
- Ah = u64_default.add3H(ll, Ah, Bh, Xh);
406
+ let ll = add3L(Al, Bl, Xl);
407
+ Ah = add3H(ll, Ah, Bh, Xh);
546
408
  Al = ll | 0;
547
409
  ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
548
- ({ Dh, Dl } = { Dh: u64_default.rotr32H(Dh, Dl), Dl: u64_default.rotr32L(Dh, Dl) });
549
- ({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
410
+ ({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh, Dl) });
411
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
550
412
  ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
551
- ({ Bh, Bl } = { Bh: u64_default.rotrSH(Bh, Bl, 24), Bl: u64_default.rotrSL(Bh, Bl, 24) });
413
+ ({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
552
414
  BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
553
415
  BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
554
416
  BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
@@ -560,22 +422,118 @@ function G2b(a, b, c, d, msg, x) {
560
422
  let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
561
423
  let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
562
424
  let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
563
- let ll = u64_default.add3L(Al, Bl, Xl);
564
- Ah = u64_default.add3H(ll, Ah, Bh, Xh);
425
+ let ll = add3L(Al, Bl, Xl);
426
+ Ah = add3H(ll, Ah, Bh, Xh);
565
427
  Al = ll | 0;
566
428
  ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
567
- ({ Dh, Dl } = { Dh: u64_default.rotrSH(Dh, Dl, 16), Dl: u64_default.rotrSL(Dh, Dl, 16) });
568
- ({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
429
+ ({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
430
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
569
431
  ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
570
- ({ Bh, Bl } = { Bh: u64_default.rotrBH(Bh, Bl, 63), Bl: u64_default.rotrBL(Bh, Bl, 63) });
432
+ ({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });
571
433
  BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
572
434
  BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
573
435
  BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
574
436
  BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
575
437
  }
576
- var BLAKE2b = class extends BLAKE {
438
+ function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
439
+ anumber(keyLen);
440
+ if (outputLen < 0 || outputLen > keyLen)
441
+ throw new Error("outputLen bigger than keyLen");
442
+ const { key, salt, personalization } = opts;
443
+ if (key !== void 0 && (key.length < 1 || key.length > keyLen))
444
+ throw new Error("key length must be undefined or 1.." + keyLen);
445
+ if (salt !== void 0 && salt.length !== saltLen)
446
+ throw new Error("salt must be undefined or " + saltLen);
447
+ if (personalization !== void 0 && personalization.length !== persLen)
448
+ throw new Error("personalization must be undefined or " + persLen);
449
+ }
450
+ var BLAKE2 = class extends Hash {
451
+ constructor(blockLen, outputLen) {
452
+ super();
453
+ this.finished = false;
454
+ this.destroyed = false;
455
+ this.length = 0;
456
+ this.pos = 0;
457
+ anumber(blockLen);
458
+ anumber(outputLen);
459
+ this.blockLen = blockLen;
460
+ this.outputLen = outputLen;
461
+ this.buffer = new Uint8Array(blockLen);
462
+ this.buffer32 = u32(this.buffer);
463
+ }
464
+ update(data) {
465
+ aexists(this);
466
+ data = toBytes(data);
467
+ abytes(data);
468
+ const { blockLen, buffer, buffer32 } = this;
469
+ const len = data.length;
470
+ const offset = data.byteOffset;
471
+ const buf = data.buffer;
472
+ for (let pos = 0; pos < len; ) {
473
+ if (this.pos === blockLen) {
474
+ swap32IfBE(buffer32);
475
+ this.compress(buffer32, 0, false);
476
+ swap32IfBE(buffer32);
477
+ this.pos = 0;
478
+ }
479
+ const take = Math.min(blockLen - this.pos, len - pos);
480
+ const dataOffset = offset + pos;
481
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
482
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
483
+ swap32IfBE(data32);
484
+ for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
485
+ this.length += blockLen;
486
+ this.compress(data32, pos32, false);
487
+ }
488
+ swap32IfBE(data32);
489
+ continue;
490
+ }
491
+ buffer.set(data.subarray(pos, pos + take), this.pos);
492
+ this.pos += take;
493
+ this.length += take;
494
+ pos += take;
495
+ }
496
+ return this;
497
+ }
498
+ digestInto(out) {
499
+ aexists(this);
500
+ aoutput(out, this);
501
+ const { pos, buffer32 } = this;
502
+ this.finished = true;
503
+ clean(this.buffer.subarray(pos));
504
+ swap32IfBE(buffer32);
505
+ this.compress(buffer32, 0, true);
506
+ swap32IfBE(buffer32);
507
+ const out32 = u32(out);
508
+ this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
509
+ }
510
+ digest() {
511
+ const { buffer, outputLen } = this;
512
+ this.digestInto(buffer);
513
+ const res = buffer.slice(0, outputLen);
514
+ this.destroy();
515
+ return res;
516
+ }
517
+ _cloneInto(to) {
518
+ const { buffer, length, finished, destroyed, outputLen, pos } = this;
519
+ to || (to = new this.constructor({ dkLen: outputLen }));
520
+ to.set(...this.get());
521
+ to.buffer.set(buffer);
522
+ to.destroyed = destroyed;
523
+ to.finished = finished;
524
+ to.length = length;
525
+ to.pos = pos;
526
+ to.outputLen = outputLen;
527
+ return to;
528
+ }
529
+ clone() {
530
+ return this._cloneInto();
531
+ }
532
+ };
533
+ var BLAKE2b = class extends BLAKE2 {
577
534
  constructor(opts = {}) {
578
- super(128, opts.dkLen === void 0 ? 64 : opts.dkLen, opts, 64, 16, 16);
535
+ const olen = opts.dkLen === void 0 ? 64 : opts.dkLen;
536
+ super(128, olen);
579
537
  this.v0l = B2B_IV[0] | 0;
580
538
  this.v0h = B2B_IV[1] | 0;
581
539
  this.v1l = B2B_IV[2] | 0;
@@ -592,25 +550,33 @@ var BLAKE2b = class extends BLAKE {
592
550
  this.v6h = B2B_IV[13] | 0;
593
551
  this.v7l = B2B_IV[14] | 0;
594
552
  this.v7h = B2B_IV[15] | 0;
595
- const keyLength = opts.key ? opts.key.length : 0;
553
+ checkBlake2Opts(olen, opts, 64, 16, 16);
554
+ let { key, personalization, salt } = opts;
555
+ let keyLength = 0;
556
+ if (key !== void 0) {
557
+ key = toBytes(key);
558
+ keyLength = key.length;
559
+ }
596
560
  this.v0l ^= this.outputLen | keyLength << 8 | 1 << 16 | 1 << 24;
597
- if (opts.salt) {
598
- const salt = u32(toBytes(opts.salt));
599
- this.v4l ^= byteSwapIfBE(salt[0]);
600
- this.v4h ^= byteSwapIfBE(salt[1]);
601
- this.v5l ^= byteSwapIfBE(salt[2]);
602
- this.v5h ^= byteSwapIfBE(salt[3]);
561
+ if (salt !== void 0) {
562
+ salt = toBytes(salt);
563
+ const slt = u32(salt);
564
+ this.v4l ^= swap8IfBE(slt[0]);
565
+ this.v4h ^= swap8IfBE(slt[1]);
566
+ this.v5l ^= swap8IfBE(slt[2]);
567
+ this.v5h ^= swap8IfBE(slt[3]);
603
568
  }
604
- if (opts.personalization) {
605
- const pers = u32(toBytes(opts.personalization));
606
- this.v6l ^= byteSwapIfBE(pers[0]);
607
- this.v6h ^= byteSwapIfBE(pers[1]);
608
- this.v7l ^= byteSwapIfBE(pers[2]);
609
- this.v7h ^= byteSwapIfBE(pers[3]);
569
+ if (personalization !== void 0) {
570
+ personalization = toBytes(personalization);
571
+ const pers = u32(personalization);
572
+ this.v6l ^= swap8IfBE(pers[0]);
573
+ this.v6h ^= swap8IfBE(pers[1]);
574
+ this.v7l ^= swap8IfBE(pers[2]);
575
+ this.v7h ^= swap8IfBE(pers[3]);
610
576
  }
611
- if (opts.key) {
577
+ if (key !== void 0) {
612
578
  const tmp = new Uint8Array(this.blockLen);
613
- tmp.set(toBytes(opts.key));
579
+ tmp.set(key);
614
580
  this.update(tmp);
615
581
  }
616
582
  }
@@ -641,7 +607,7 @@ var BLAKE2b = class extends BLAKE {
641
607
  compress(msg, offset, isLast) {
642
608
  this.get().forEach((v, i) => BBUF[i] = v);
643
609
  BBUF.set(B2B_IV, 16);
644
- let { h, l } = u64_default.fromBig(BigInt(this.length));
610
+ let { h, l } = fromBig(BigInt(this.length));
645
611
  BBUF[24] = B2B_IV[8] ^ l;
646
612
  BBUF[25] = B2B_IV[9] ^ h;
647
613
  if (isLast) {
@@ -649,7 +615,7 @@ var BLAKE2b = class extends BLAKE {
649
615
  BBUF[29] = ~BBUF[29];
650
616
  }
651
617
  let j = 0;
652
- const s = SIGMA;
618
+ const s = BSIGMA;
653
619
  for (let i = 0; i < 12; i++) {
654
620
  G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
655
621
  G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
@@ -684,15 +650,18 @@ var BLAKE2b = class extends BLAKE {
684
650
  this.v6h ^= BBUF[13] ^ BBUF[29];
685
651
  this.v7l ^= BBUF[14] ^ BBUF[30];
686
652
  this.v7h ^= BBUF[15] ^ BBUF[31];
687
- BBUF.fill(0);
653
+ clean(BBUF);
688
654
  }
689
655
  destroy() {
690
656
  this.destroyed = true;
691
- this.buffer32.fill(0);
657
+ clean(this.buffer32);
692
658
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
693
659
  }
694
660
  };
695
- var blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
661
+ var blake2b = /* @__PURE__ */ createOptHasher((opts) => new BLAKE2b(opts));
662
+
663
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/blake2b.js
664
+ var blake2b2 = blake2b;
696
665
 
697
666
  // src/guard.ts
698
667
  var createIsGuard = (type) => (value) => typeof value === type;
@@ -768,7 +737,7 @@ var MAX_PREFIX = 16383;
768
737
  var RESERVED_PREFIXES = [46, 47];
769
738
  var computeChecksum = (data) => {
770
739
  const checksumPrefix = [83, 83, 53, 56, 80, 82, 69];
771
- const checksum = blake2b(new Uint8Array([...checksumPrefix, ...data]));
740
+ const checksum = blake2b2(new Uint8Array([...checksumPrefix, ...data]));
772
741
  return checksum.slice(0, CHECKSUM_BYTE_LENGTH);
773
742
  };
774
743
  var decode2 = (input) => {
package/dist/ss58.js CHANGED
@@ -11,14 +11,14 @@ import {
11
11
  } from "./chunk-ZHIKNZLU.js";
12
12
  import "./chunk-HBIFE4XN.js";
13
13
 
14
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_assert.js
14
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js
15
+ function isBytes(a) {
16
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
17
+ }
15
18
  function anumber(n) {
16
19
  if (!Number.isSafeInteger(n) || n < 0)
17
20
  throw new Error("positive integer expected, got " + n);
18
21
  }
19
- function isBytes(a) {
20
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
21
- }
22
22
  function abytes(b, ...lengths) {
23
23
  if (!isBytes(b))
24
24
  throw new Error("Uint8Array expected");
@@ -38,24 +38,29 @@ function aoutput(out, instance) {
38
38
  throw new Error("digestInto() expects output buffer of length at least " + min);
39
39
  }
40
40
  }
41
-
42
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/utils.js
43
41
  function u32(arr) {
44
42
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
45
43
  }
44
+ function clean(...arrays) {
45
+ for (let i = 0; i < arrays.length; i++) {
46
+ arrays[i].fill(0);
47
+ }
48
+ }
46
49
  var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
47
50
  function byteSwap(word) {
48
51
  return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
49
52
  }
50
- var byteSwapIfBE = isLE ? (n) => n : (n) => byteSwap(n);
53
+ var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
51
54
  function byteSwap32(arr) {
52
55
  for (let i = 0; i < arr.length; i++) {
53
56
  arr[i] = byteSwap(arr[i]);
54
57
  }
58
+ return arr;
55
59
  }
60
+ var swap32IfBE = isLE ? (u) => u : byteSwap32;
56
61
  function utf8ToBytes(str) {
57
62
  if (typeof str !== "string")
58
- throw new Error("utf8ToBytes expected string, got " + typeof str);
63
+ throw new Error("string expected");
59
64
  return new Uint8Array(new TextEncoder().encode(str));
60
65
  }
61
66
  function toBytes(data) {
@@ -65,12 +70,8 @@ function toBytes(data) {
65
70
  return data;
66
71
  }
67
72
  var Hash = class {
68
- // Safe version that clones internal state
69
- clone() {
70
- return this._cloneInto();
71
- }
72
73
  };
73
- function wrapConstructorWithOpts(hashCons) {
74
+ function createOptHasher(hashCons) {
74
75
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
75
76
  const tmp = hashCons({});
76
77
  hashC.outputLen = tmp.outputLen;
@@ -79,8 +80,8 @@ function wrapConstructorWithOpts(hashCons) {
79
80
  return hashC;
80
81
  }
81
82
 
82
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_blake.js
83
- var SIGMA = /* @__PURE__ */ new Uint8Array([
83
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_blake.js
84
+ var BSIGMA = /* @__PURE__ */ Uint8Array.from([
84
85
  0,
85
86
  1,
86
87
  2,
@@ -339,102 +340,8 @@ var SIGMA = /* @__PURE__ */ new Uint8Array([
339
340
  1,
340
341
  9
341
342
  ]);
342
- var BLAKE = class extends Hash {
343
- constructor(blockLen, outputLen, opts = {}, keyLen, saltLen, persLen) {
344
- super();
345
- this.blockLen = blockLen;
346
- this.outputLen = outputLen;
347
- this.length = 0;
348
- this.pos = 0;
349
- this.finished = false;
350
- this.destroyed = false;
351
- anumber(blockLen);
352
- anumber(outputLen);
353
- anumber(keyLen);
354
- if (outputLen < 0 || outputLen > keyLen)
355
- throw new Error("outputLen bigger than keyLen");
356
- if (opts.key !== void 0 && (opts.key.length < 1 || opts.key.length > keyLen))
357
- throw new Error("key length must be undefined or 1.." + keyLen);
358
- if (opts.salt !== void 0 && opts.salt.length !== saltLen)
359
- throw new Error("salt must be undefined or " + saltLen);
360
- if (opts.personalization !== void 0 && opts.personalization.length !== persLen)
361
- throw new Error("personalization must be undefined or " + persLen);
362
- this.buffer = new Uint8Array(blockLen);
363
- this.buffer32 = u32(this.buffer);
364
- }
365
- update(data) {
366
- aexists(this);
367
- const { blockLen, buffer, buffer32 } = this;
368
- data = toBytes(data);
369
- const len = data.length;
370
- const offset = data.byteOffset;
371
- const buf = data.buffer;
372
- for (let pos = 0; pos < len; ) {
373
- if (this.pos === blockLen) {
374
- if (!isLE)
375
- byteSwap32(buffer32);
376
- this.compress(buffer32, 0, false);
377
- if (!isLE)
378
- byteSwap32(buffer32);
379
- this.pos = 0;
380
- }
381
- const take = Math.min(blockLen - this.pos, len - pos);
382
- const dataOffset = offset + pos;
383
- if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
384
- const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
385
- if (!isLE)
386
- byteSwap32(data32);
387
- for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
388
- this.length += blockLen;
389
- this.compress(data32, pos32, false);
390
- }
391
- if (!isLE)
392
- byteSwap32(data32);
393
- continue;
394
- }
395
- buffer.set(data.subarray(pos, pos + take), this.pos);
396
- this.pos += take;
397
- this.length += take;
398
- pos += take;
399
- }
400
- return this;
401
- }
402
- digestInto(out) {
403
- aexists(this);
404
- aoutput(out, this);
405
- const { pos, buffer32 } = this;
406
- this.finished = true;
407
- this.buffer.subarray(pos).fill(0);
408
- if (!isLE)
409
- byteSwap32(buffer32);
410
- this.compress(buffer32, 0, true);
411
- if (!isLE)
412
- byteSwap32(buffer32);
413
- const out32 = u32(out);
414
- this.get().forEach((v, i) => out32[i] = byteSwapIfBE(v));
415
- }
416
- digest() {
417
- const { buffer, outputLen } = this;
418
- this.digestInto(buffer);
419
- const res = buffer.slice(0, outputLen);
420
- this.destroy();
421
- return res;
422
- }
423
- _cloneInto(to) {
424
- const { buffer, length, finished, destroyed, outputLen, pos } = this;
425
- to || (to = new this.constructor({ dkLen: outputLen }));
426
- to.set(...this.get());
427
- to.length = length;
428
- to.finished = finished;
429
- to.destroyed = destroyed;
430
- to.outputLen = outputLen;
431
- to.buffer.set(buffer);
432
- to.pos = pos;
433
- return to;
434
- }
435
- };
436
343
 
437
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/_u64.js
344
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
438
345
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
439
346
  var _32n = /* @__PURE__ */ BigInt(32);
440
347
  function fromBig(n, le = false) {
@@ -442,66 +349,21 @@ function fromBig(n, le = false) {
442
349
  return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
443
350
  return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
444
351
  }
445
- function split(lst, le = false) {
446
- let Ah = new Uint32Array(lst.length);
447
- let Al = new Uint32Array(lst.length);
448
- for (let i = 0; i < lst.length; i++) {
449
- const { h, l } = fromBig(lst[i], le);
450
- [Ah[i], Al[i]] = [h, l];
451
- }
452
- return [Ah, Al];
453
- }
454
- var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
455
- var shrSH = (h, _l, s) => h >>> s;
456
- var shrSL = (h, l, s) => h << 32 - s | l >>> s;
457
352
  var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
458
353
  var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
459
354
  var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
460
355
  var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
461
356
  var rotr32H = (_h, l) => l;
462
357
  var rotr32L = (h, _l) => h;
463
- var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
464
- var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
465
- var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
466
- var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
467
358
  function add(Ah, Al, Bh, Bl) {
468
359
  const l = (Al >>> 0) + (Bl >>> 0);
469
360
  return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
470
361
  }
471
362
  var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
472
363
  var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
473
- var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
474
- var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
475
- var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
476
- var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
477
- var u64 = {
478
- fromBig,
479
- split,
480
- toBig,
481
- shrSH,
482
- shrSL,
483
- rotrSH,
484
- rotrSL,
485
- rotrBH,
486
- rotrBL,
487
- rotr32H,
488
- rotr32L,
489
- rotlSH,
490
- rotlSL,
491
- rotlBH,
492
- rotlBL,
493
- add,
494
- add3L,
495
- add3H,
496
- add4L,
497
- add4H,
498
- add5H,
499
- add5L
500
- };
501
- var u64_default = u64;
502
364
 
503
- // ../../node_modules/.pnpm/@noble+hashes@1.7.1/node_modules/@noble/hashes/esm/blake2b.js
504
- var B2B_IV = /* @__PURE__ */ new Uint32Array([
365
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/blake2.js
366
+ var B2B_IV = /* @__PURE__ */ Uint32Array.from([
505
367
  4089235720,
506
368
  1779033703,
507
369
  2227873595,
@@ -526,14 +388,14 @@ function G1b(a, b, c, d, msg, x) {
526
388
  let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
527
389
  let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
528
390
  let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
529
- let ll = u64_default.add3L(Al, Bl, Xl);
530
- Ah = u64_default.add3H(ll, Ah, Bh, Xh);
391
+ let ll = add3L(Al, Bl, Xl);
392
+ Ah = add3H(ll, Ah, Bh, Xh);
531
393
  Al = ll | 0;
532
394
  ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
533
- ({ Dh, Dl } = { Dh: u64_default.rotr32H(Dh, Dl), Dl: u64_default.rotr32L(Dh, Dl) });
534
- ({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
395
+ ({ Dh, Dl } = { Dh: rotr32H(Dh, Dl), Dl: rotr32L(Dh, Dl) });
396
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
535
397
  ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
536
- ({ Bh, Bl } = { Bh: u64_default.rotrSH(Bh, Bl, 24), Bl: u64_default.rotrSL(Bh, Bl, 24) });
398
+ ({ Bh, Bl } = { Bh: rotrSH(Bh, Bl, 24), Bl: rotrSL(Bh, Bl, 24) });
537
399
  BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
538
400
  BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
539
401
  BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
@@ -545,22 +407,118 @@ function G2b(a, b, c, d, msg, x) {
545
407
  let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
546
408
  let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
547
409
  let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
548
- let ll = u64_default.add3L(Al, Bl, Xl);
549
- Ah = u64_default.add3H(ll, Ah, Bh, Xh);
410
+ let ll = add3L(Al, Bl, Xl);
411
+ Ah = add3H(ll, Ah, Bh, Xh);
550
412
  Al = ll | 0;
551
413
  ({ Dh, Dl } = { Dh: Dh ^ Ah, Dl: Dl ^ Al });
552
- ({ Dh, Dl } = { Dh: u64_default.rotrSH(Dh, Dl, 16), Dl: u64_default.rotrSL(Dh, Dl, 16) });
553
- ({ h: Ch, l: Cl } = u64_default.add(Ch, Cl, Dh, Dl));
414
+ ({ Dh, Dl } = { Dh: rotrSH(Dh, Dl, 16), Dl: rotrSL(Dh, Dl, 16) });
415
+ ({ h: Ch, l: Cl } = add(Ch, Cl, Dh, Dl));
554
416
  ({ Bh, Bl } = { Bh: Bh ^ Ch, Bl: Bl ^ Cl });
555
- ({ Bh, Bl } = { Bh: u64_default.rotrBH(Bh, Bl, 63), Bl: u64_default.rotrBL(Bh, Bl, 63) });
417
+ ({ Bh, Bl } = { Bh: rotrBH(Bh, Bl, 63), Bl: rotrBL(Bh, Bl, 63) });
556
418
  BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
557
419
  BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
558
420
  BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
559
421
  BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
560
422
  }
561
- var BLAKE2b = class extends BLAKE {
423
+ function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
424
+ anumber(keyLen);
425
+ if (outputLen < 0 || outputLen > keyLen)
426
+ throw new Error("outputLen bigger than keyLen");
427
+ const { key, salt, personalization } = opts;
428
+ if (key !== void 0 && (key.length < 1 || key.length > keyLen))
429
+ throw new Error("key length must be undefined or 1.." + keyLen);
430
+ if (salt !== void 0 && salt.length !== saltLen)
431
+ throw new Error("salt must be undefined or " + saltLen);
432
+ if (personalization !== void 0 && personalization.length !== persLen)
433
+ throw new Error("personalization must be undefined or " + persLen);
434
+ }
435
+ var BLAKE2 = class extends Hash {
436
+ constructor(blockLen, outputLen) {
437
+ super();
438
+ this.finished = false;
439
+ this.destroyed = false;
440
+ this.length = 0;
441
+ this.pos = 0;
442
+ anumber(blockLen);
443
+ anumber(outputLen);
444
+ this.blockLen = blockLen;
445
+ this.outputLen = outputLen;
446
+ this.buffer = new Uint8Array(blockLen);
447
+ this.buffer32 = u32(this.buffer);
448
+ }
449
+ update(data) {
450
+ aexists(this);
451
+ data = toBytes(data);
452
+ abytes(data);
453
+ const { blockLen, buffer, buffer32 } = this;
454
+ const len = data.length;
455
+ const offset = data.byteOffset;
456
+ const buf = data.buffer;
457
+ for (let pos = 0; pos < len; ) {
458
+ if (this.pos === blockLen) {
459
+ swap32IfBE(buffer32);
460
+ this.compress(buffer32, 0, false);
461
+ swap32IfBE(buffer32);
462
+ this.pos = 0;
463
+ }
464
+ const take = Math.min(blockLen - this.pos, len - pos);
465
+ const dataOffset = offset + pos;
466
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
467
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
468
+ swap32IfBE(data32);
469
+ for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
470
+ this.length += blockLen;
471
+ this.compress(data32, pos32, false);
472
+ }
473
+ swap32IfBE(data32);
474
+ continue;
475
+ }
476
+ buffer.set(data.subarray(pos, pos + take), this.pos);
477
+ this.pos += take;
478
+ this.length += take;
479
+ pos += take;
480
+ }
481
+ return this;
482
+ }
483
+ digestInto(out) {
484
+ aexists(this);
485
+ aoutput(out, this);
486
+ const { pos, buffer32 } = this;
487
+ this.finished = true;
488
+ clean(this.buffer.subarray(pos));
489
+ swap32IfBE(buffer32);
490
+ this.compress(buffer32, 0, true);
491
+ swap32IfBE(buffer32);
492
+ const out32 = u32(out);
493
+ this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
494
+ }
495
+ digest() {
496
+ const { buffer, outputLen } = this;
497
+ this.digestInto(buffer);
498
+ const res = buffer.slice(0, outputLen);
499
+ this.destroy();
500
+ return res;
501
+ }
502
+ _cloneInto(to) {
503
+ const { buffer, length, finished, destroyed, outputLen, pos } = this;
504
+ to || (to = new this.constructor({ dkLen: outputLen }));
505
+ to.set(...this.get());
506
+ to.buffer.set(buffer);
507
+ to.destroyed = destroyed;
508
+ to.finished = finished;
509
+ to.length = length;
510
+ to.pos = pos;
511
+ to.outputLen = outputLen;
512
+ return to;
513
+ }
514
+ clone() {
515
+ return this._cloneInto();
516
+ }
517
+ };
518
+ var BLAKE2b = class extends BLAKE2 {
562
519
  constructor(opts = {}) {
563
- super(128, opts.dkLen === void 0 ? 64 : opts.dkLen, opts, 64, 16, 16);
520
+ const olen = opts.dkLen === void 0 ? 64 : opts.dkLen;
521
+ super(128, olen);
564
522
  this.v0l = B2B_IV[0] | 0;
565
523
  this.v0h = B2B_IV[1] | 0;
566
524
  this.v1l = B2B_IV[2] | 0;
@@ -577,25 +535,33 @@ var BLAKE2b = class extends BLAKE {
577
535
  this.v6h = B2B_IV[13] | 0;
578
536
  this.v7l = B2B_IV[14] | 0;
579
537
  this.v7h = B2B_IV[15] | 0;
580
- const keyLength = opts.key ? opts.key.length : 0;
538
+ checkBlake2Opts(olen, opts, 64, 16, 16);
539
+ let { key, personalization, salt } = opts;
540
+ let keyLength = 0;
541
+ if (key !== void 0) {
542
+ key = toBytes(key);
543
+ keyLength = key.length;
544
+ }
581
545
  this.v0l ^= this.outputLen | keyLength << 8 | 1 << 16 | 1 << 24;
582
- if (opts.salt) {
583
- const salt = u32(toBytes(opts.salt));
584
- this.v4l ^= byteSwapIfBE(salt[0]);
585
- this.v4h ^= byteSwapIfBE(salt[1]);
586
- this.v5l ^= byteSwapIfBE(salt[2]);
587
- this.v5h ^= byteSwapIfBE(salt[3]);
546
+ if (salt !== void 0) {
547
+ salt = toBytes(salt);
548
+ const slt = u32(salt);
549
+ this.v4l ^= swap8IfBE(slt[0]);
550
+ this.v4h ^= swap8IfBE(slt[1]);
551
+ this.v5l ^= swap8IfBE(slt[2]);
552
+ this.v5h ^= swap8IfBE(slt[3]);
588
553
  }
589
- if (opts.personalization) {
590
- const pers = u32(toBytes(opts.personalization));
591
- this.v6l ^= byteSwapIfBE(pers[0]);
592
- this.v6h ^= byteSwapIfBE(pers[1]);
593
- this.v7l ^= byteSwapIfBE(pers[2]);
594
- this.v7h ^= byteSwapIfBE(pers[3]);
554
+ if (personalization !== void 0) {
555
+ personalization = toBytes(personalization);
556
+ const pers = u32(personalization);
557
+ this.v6l ^= swap8IfBE(pers[0]);
558
+ this.v6h ^= swap8IfBE(pers[1]);
559
+ this.v7l ^= swap8IfBE(pers[2]);
560
+ this.v7h ^= swap8IfBE(pers[3]);
595
561
  }
596
- if (opts.key) {
562
+ if (key !== void 0) {
597
563
  const tmp = new Uint8Array(this.blockLen);
598
- tmp.set(toBytes(opts.key));
564
+ tmp.set(key);
599
565
  this.update(tmp);
600
566
  }
601
567
  }
@@ -626,7 +592,7 @@ var BLAKE2b = class extends BLAKE {
626
592
  compress(msg, offset, isLast) {
627
593
  this.get().forEach((v, i) => BBUF[i] = v);
628
594
  BBUF.set(B2B_IV, 16);
629
- let { h, l } = u64_default.fromBig(BigInt(this.length));
595
+ let { h, l } = fromBig(BigInt(this.length));
630
596
  BBUF[24] = B2B_IV[8] ^ l;
631
597
  BBUF[25] = B2B_IV[9] ^ h;
632
598
  if (isLast) {
@@ -634,7 +600,7 @@ var BLAKE2b = class extends BLAKE {
634
600
  BBUF[29] = ~BBUF[29];
635
601
  }
636
602
  let j = 0;
637
- const s = SIGMA;
603
+ const s = BSIGMA;
638
604
  for (let i = 0; i < 12; i++) {
639
605
  G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
640
606
  G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
@@ -669,15 +635,18 @@ var BLAKE2b = class extends BLAKE {
669
635
  this.v6h ^= BBUF[13] ^ BBUF[29];
670
636
  this.v7l ^= BBUF[14] ^ BBUF[30];
671
637
  this.v7h ^= BBUF[15] ^ BBUF[31];
672
- BBUF.fill(0);
638
+ clean(BBUF);
673
639
  }
674
640
  destroy() {
675
641
  this.destroyed = true;
676
- this.buffer32.fill(0);
642
+ clean(this.buffer32);
677
643
  this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
678
644
  }
679
645
  };
680
- var blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
646
+ var blake2b = /* @__PURE__ */ createOptHasher((opts) => new BLAKE2b(opts));
647
+
648
+ // ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/blake2b.js
649
+ var blake2b2 = blake2b;
681
650
 
682
651
  // src/ss58.ts
683
652
  var CHECKSUM_BYTE_LENGTH = 2;
@@ -687,7 +656,7 @@ var MAX_PREFIX = 16383;
687
656
  var RESERVED_PREFIXES = [46, 47];
688
657
  var computeChecksum = (data) => {
689
658
  const checksumPrefix = [83, 83, 53, 56, 80, 82, 69];
690
- const checksum = blake2b(new Uint8Array([...checksumPrefix, ...data]));
659
+ const checksum = blake2b2(new Uint8Array([...checksumPrefix, ...data]));
691
660
  return checksum.slice(0, CHECKSUM_BYTE_LENGTH);
692
661
  };
693
662
  var decode2 = (input) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -19,12 +19,12 @@
19
19
  }
20
20
  },
21
21
  "devDependencies": {
22
- "@noble/hashes": "^1.7.1",
22
+ "@noble/hashes": "^1.8.0",
23
23
  "@vitest/ui": "3.1.1"
24
24
  },
25
25
  "dependencies": {
26
26
  "@date-fns/utc": "^2.1.0",
27
- "bignumber.js": "^9.2.0",
27
+ "bignumber.js": "^9.3.0",
28
28
  "date-fns": "4.1.0"
29
29
  },
30
30
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",