@gardenfi/utils 2.4.5 → 2.4.6
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/index119.cjs +1 -1
- package/dist/index119.js +1 -1
- package/dist/index195.cjs +1 -1
- package/dist/index195.js +3 -3
- package/dist/index225.cjs +1 -1
- package/dist/index225.js +2 -2
- package/dist/index228.cjs +1 -1
- package/dist/index228.js +2 -2
- package/dist/index229.cjs +1 -1
- package/dist/index229.js +1 -1
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +6 -6
- package/dist/index234.cjs +1 -1
- package/dist/index234.js +1 -1
- package/dist/index235.cjs +1 -1
- package/dist/index235.js +1 -1
- package/dist/index236.cjs +1 -1
- package/dist/index236.js +2 -2
- package/dist/index241.cjs +1 -1
- package/dist/index241.js +3 -3
- package/dist/index243.cjs +1 -1
- package/dist/index243.js +1 -1
- package/dist/index248.cjs +1 -1
- package/dist/index248.js +3 -3
- package/dist/index249.cjs +1 -1
- package/dist/index249.js +3 -3
- package/dist/index254.cjs +1 -1
- package/dist/index254.js +102 -24
- package/dist/index255.cjs +1 -1
- package/dist/index255.js +6 -13
- package/dist/index256.cjs +1 -1
- package/dist/index256.js +223 -14
- package/dist/index257.cjs +1 -1
- package/dist/index257.js +25 -5
- package/dist/index258.cjs +1 -1
- package/dist/index258.js +13 -13
- package/dist/index259.cjs +1 -1
- package/dist/index259.js +14 -9
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +2 -2
- package/dist/index260.cjs +1 -1
- package/dist/index260.js +5 -16
- package/dist/index261.cjs +1 -2
- package/dist/index261.js +13 -41
- package/dist/index262.cjs +1 -1
- package/dist/index262.js +11 -2
- package/dist/index263.cjs +1 -1
- package/dist/index263.js +16 -5
- package/dist/index264.cjs +2 -1
- package/dist/index264.js +40 -9
- package/dist/index265.cjs +1 -1
- package/dist/index265.js +2 -20
- package/dist/index266.cjs +1 -1
- package/dist/index266.js +5 -8
- package/dist/index267.cjs +1 -1
- package/dist/index267.js +9 -65
- package/dist/index268.cjs +1 -1
- package/dist/index268.js +17 -63
- package/dist/index269.cjs +1 -1
- package/dist/index269.js +8 -186
- package/dist/index270.cjs +1 -1
- package/dist/index270.js +66 -22
- package/dist/index271.cjs +1 -1
- package/dist/index271.js +61 -38
- package/dist/index272.cjs +1 -1
- package/dist/index272.js +179 -69
- package/dist/index273.cjs +1 -1
- package/dist/index273.js +21 -39
- package/dist/index274.cjs +1 -1
- package/dist/index274.js +35 -9
- package/dist/index275.cjs +1 -1
- package/dist/index275.js +70 -7
- package/dist/index276.cjs +1 -1
- package/dist/index276.js +40 -12
- package/dist/index277.cjs +1 -2
- package/dist/index277.js +16 -18
- package/dist/index278.cjs +1 -1
- package/dist/index278.js +12 -13
- package/dist/index279.cjs +1 -1
- package/dist/index279.js +12 -11
- package/dist/index280.cjs +2 -1
- package/dist/index280.js +18 -103
- package/dist/index281.cjs +1 -1
- package/dist/index281.js +14 -6
- package/dist/index282.cjs +1 -1
- package/dist/index282.js +152 -221
- package/dist/index283.cjs +1 -1
- package/dist/index283.js +9 -6
- package/dist/index284.cjs +1 -1
- package/dist/index284.js +114 -7
- package/dist/index285.cjs +2 -1
- package/dist/index285.js +132 -24
- package/dist/index286.cjs +1 -1
- package/dist/index286.js +11 -19
- package/dist/index287.cjs +1 -1
- package/dist/index287.js +6 -146
- package/dist/index288.cjs +1 -1
- package/dist/index288.js +7 -4
- package/dist/index289.cjs +1 -1
- package/dist/index289.js +23 -137
- package/dist/index290.cjs +1 -1
- package/dist/index290.js +17 -153
- package/dist/index291.cjs +1 -1
- package/dist/index291.js +146 -9
- package/dist/index292.cjs +1 -1
- package/dist/index292.js +3 -113
- package/dist/index293.cjs +1 -2
- package/dist/index293.js +128 -122
- package/dist/index294.cjs +1 -1
- package/dist/index294.js +73 -134
- package/dist/index295.cjs +1 -1
- package/dist/index295.js +2 -43
- package/dist/index296.cjs +1 -1
- package/dist/index296.js +693 -73
- package/dist/index297.cjs +1 -1
- package/dist/index297.js +140 -2
- package/dist/index298.cjs +1 -1
- package/dist/index298.js +41 -10
- package/dist/index299.cjs +1 -1
- package/dist/index299.js +201 -19
- package/dist/index301.cjs +2 -1
- package/dist/index301.js +63 -695
- package/dist/index302.cjs +1 -1
- package/dist/index302.js +4 -201
- package/dist/index303.cjs +1 -2
- package/dist/index303.js +39 -65
- package/dist/index304.cjs +1 -1
- package/dist/index304.js +7 -4
- package/dist/index305.cjs +1 -1
- package/dist/index305.js +60 -38
- package/dist/index306.cjs +1 -1
- package/dist/index306.js +77 -7
- package/dist/index307.cjs +1 -1
- package/dist/index307.js +4 -63
- package/dist/index308.cjs +1 -1
- package/dist/index308.js +181 -64
- package/dist/index309.cjs +1 -1
- package/dist/index309.js +12 -4
- package/dist/index310.cjs +1 -1
- package/dist/index310.js +19 -194
- package/dist/index311.cjs +1 -1
- package/dist/index311.js +63 -4
- package/dist/index312.cjs +1 -1
- package/dist/index312.js +40 -59
- package/dist/index313.cjs +1 -1
- package/dist/index313.js +4 -44
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +1 -1
- package/dist/index98.cjs +1 -1
- package/dist/index98.js +2 -2
- package/package.json +1 -1
package/dist/index278.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { BaseError as r } from "./index264.js";
|
|
2
|
+
class a extends r {
|
|
3
|
+
constructor({ type: e }) {
|
|
4
|
+
super("Circular reference detected.", {
|
|
5
|
+
metaMessages: [`Struct "${e}" is a circular reference.`]
|
|
6
|
+
}), Object.defineProperty(this, "name", {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
configurable: !0,
|
|
9
|
+
writable: !0,
|
|
10
|
+
value: "CircularReferenceError"
|
|
11
|
+
});
|
|
12
12
|
}
|
|
13
|
-
return !0;
|
|
14
13
|
}
|
|
15
14
|
export {
|
|
16
|
-
|
|
15
|
+
a as CircularReferenceError
|
|
17
16
|
};
|
package/dist/index279.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(){return{current:0,take(){return this.current++},reset(){this.current=0}}}const t=e();exports.idCache=t;
|
package/dist/index279.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
function r() {
|
|
2
|
+
return {
|
|
3
|
+
current: 0,
|
|
4
|
+
take() {
|
|
5
|
+
return this.current++;
|
|
6
|
+
},
|
|
7
|
+
reset() {
|
|
8
|
+
this.current = 0;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
10
11
|
}
|
|
12
|
+
const t = /* @__PURE__ */ r();
|
|
11
13
|
export {
|
|
12
|
-
t as
|
|
13
|
-
s as withDedupe
|
|
14
|
+
t as idCache
|
|
14
15
|
};
|
package/dist/index280.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function x(e){var c,d,f;const{scheme:n,statement:t,...p}=((c=e.match(h))==null?void 0:c.groups)??{},{chainId:s,expirationTime:i,issuedAt:o,notBefore:r,requestId:a,...m}=((d=e.match(A))==null?void 0:d.groups)??{},u=(f=e.split("Resources:")[1])==null?void 0:f.split(`
|
|
2
|
+
- `).slice(1);return{...p,...m,...s?{chainId:Number(s)}:{},...i?{expirationTime:new Date(i)}:{},...o?{issuedAt:new Date(o)}:{},...r?{notBefore:new Date(r)}:{},...a?{requestId:a}:{},...u?{resources:u}:{},...n?{scheme:n}:{},...t?{statement:t}:{}}}const h=/^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/,A=/(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;exports.parseSiweMessage=x;
|
package/dist/index280.js
CHANGED
|
@@ -1,106 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
2162078206,
|
|
18
|
-
2614888103,
|
|
19
|
-
3248222580,
|
|
20
|
-
3835390401,
|
|
21
|
-
4022224774,
|
|
22
|
-
264347078,
|
|
23
|
-
604807628,
|
|
24
|
-
770255983,
|
|
25
|
-
1249150122,
|
|
26
|
-
1555081692,
|
|
27
|
-
1996064986,
|
|
28
|
-
2554220882,
|
|
29
|
-
2821834349,
|
|
30
|
-
2952996808,
|
|
31
|
-
3210313671,
|
|
32
|
-
3336571891,
|
|
33
|
-
3584528711,
|
|
34
|
-
113926993,
|
|
35
|
-
338241895,
|
|
36
|
-
666307205,
|
|
37
|
-
773529912,
|
|
38
|
-
1294757372,
|
|
39
|
-
1396182291,
|
|
40
|
-
1695183700,
|
|
41
|
-
1986661051,
|
|
42
|
-
2177026350,
|
|
43
|
-
2456956037,
|
|
44
|
-
2730485921,
|
|
45
|
-
2820302411,
|
|
46
|
-
3259730800,
|
|
47
|
-
3345764771,
|
|
48
|
-
3516065817,
|
|
49
|
-
3600352804,
|
|
50
|
-
4094571909,
|
|
51
|
-
275423344,
|
|
52
|
-
430227734,
|
|
53
|
-
506948616,
|
|
54
|
-
659060556,
|
|
55
|
-
883997877,
|
|
56
|
-
958139571,
|
|
57
|
-
1322822218,
|
|
58
|
-
1537002063,
|
|
59
|
-
1747873779,
|
|
60
|
-
1955562222,
|
|
61
|
-
2024104815,
|
|
62
|
-
2227730452,
|
|
63
|
-
2361852424,
|
|
64
|
-
2428436474,
|
|
65
|
-
2756734187,
|
|
66
|
-
3204031479,
|
|
67
|
-
3329325298
|
|
68
|
-
]), h = /* @__PURE__ */ new Uint32Array(64);
|
|
69
|
-
class E extends D {
|
|
70
|
-
constructor(o = 32) {
|
|
71
|
-
super(64, o, 8, !1), this.A = b[0] | 0, this.B = b[1] | 0, this.C = b[2] | 0, this.D = b[3] | 0, this.E = b[4] | 0, this.F = b[5] | 0, this.G = b[6] | 0, this.H = b[7] | 0;
|
|
72
|
-
}
|
|
73
|
-
get() {
|
|
74
|
-
const { A: o, B: r, C: t, D: s, E: a, F: f, G: c, H: e } = this;
|
|
75
|
-
return [o, r, t, s, a, f, c, e];
|
|
76
|
-
}
|
|
77
|
-
// prettier-ignore
|
|
78
|
-
set(o, r, t, s, a, f, c, e) {
|
|
79
|
-
this.A = o | 0, this.B = r | 0, this.C = t | 0, this.D = s | 0, this.E = a | 0, this.F = f | 0, this.G = c | 0, this.H = e | 0;
|
|
80
|
-
}
|
|
81
|
-
process(o, r) {
|
|
82
|
-
for (let x = 0; x < 16; x++, r += 4)
|
|
83
|
-
h[x] = o.getUint32(r, !1);
|
|
84
|
-
for (let x = 16; x < 64; x++) {
|
|
85
|
-
const H = h[x - 15], d = h[x - 2], m = i(H, 7) ^ i(H, 18) ^ H >>> 3, l = i(d, 17) ^ i(d, 19) ^ d >>> 10;
|
|
86
|
-
h[x] = l + h[x - 7] + m + h[x - 16] | 0;
|
|
87
|
-
}
|
|
88
|
-
let { A: t, B: s, C: a, D: f, E: c, F: e, G: n, H: A } = this;
|
|
89
|
-
for (let x = 0; x < 64; x++) {
|
|
90
|
-
const H = i(c, 6) ^ i(c, 11) ^ i(c, 25), d = A + H + g(c, e, n) + B[x] + h[x] | 0, l = (i(t, 2) ^ i(t, 13) ^ i(t, 22)) + p(t, s, a) | 0;
|
|
91
|
-
A = n, n = e, e = c, c = f + d | 0, f = a, a = s, s = t, t = d + l | 0;
|
|
92
|
-
}
|
|
93
|
-
t = t + this.A | 0, s = s + this.B | 0, a = a + this.C | 0, f = f + this.D | 0, c = c + this.E | 0, e = e + this.F | 0, n = n + this.G | 0, A = A + this.H | 0, this.set(t, s, a, f, c, e, n, A);
|
|
94
|
-
}
|
|
95
|
-
roundClean() {
|
|
96
|
-
C(h);
|
|
97
|
-
}
|
|
98
|
-
destroy() {
|
|
99
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0), C(this.buffer);
|
|
100
|
-
}
|
|
1
|
+
function A(e) {
|
|
2
|
+
var c, d, f;
|
|
3
|
+
const { scheme: n, statement: t, ...p } = ((c = e.match(m)) == null ? void 0 : c.groups) ?? {}, { chainId: s, expirationTime: i, issuedAt: o, notBefore: r, requestId: a, ...x } = ((d = e.match(h)) == null ? void 0 : d.groups) ?? {}, u = (f = e.split("Resources:")[1]) == null ? void 0 : f.split(`
|
|
4
|
+
- `).slice(1);
|
|
5
|
+
return {
|
|
6
|
+
...p,
|
|
7
|
+
...x,
|
|
8
|
+
...s ? { chainId: Number(s) } : {},
|
|
9
|
+
...i ? { expirationTime: new Date(i) } : {},
|
|
10
|
+
...o ? { issuedAt: new Date(o) } : {},
|
|
11
|
+
...r ? { notBefore: new Date(r) } : {},
|
|
12
|
+
...a ? { requestId: a } : {},
|
|
13
|
+
...u ? { resources: u } : {},
|
|
14
|
+
...n ? { scheme: n } : {},
|
|
15
|
+
...t ? { statement: t } : {}
|
|
16
|
+
};
|
|
101
17
|
}
|
|
102
|
-
const
|
|
18
|
+
const m = /^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/, h = /(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;
|
|
103
19
|
export {
|
|
104
|
-
|
|
105
|
-
y as sha256
|
|
20
|
+
A as parseSiweMessage
|
|
106
21
|
};
|
package/dist/index281.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./index174.cjs"),f=require("./index184.cjs");function u(n){const{address:s,domain:r,message:e,nonce:t,scheme:i,time:a=new Date}=n;if(r&&e.domain!==r||t&&e.nonce!==t||i&&e.scheme!==i||e.expirationTime&&a>=e.expirationTime||e.notBefore&&a<e.notBefore)return!1;try{if(!e.address||!d.isAddress(e.address,{strict:!1})||s&&!f.isAddressEqual(e.address,s))return!1}catch{return!1}return!0}exports.validateSiweMessage=u;
|
package/dist/index281.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
import { isAddress as f } from "./index174.js";
|
|
2
|
+
import { isAddressEqual as o } from "./index184.js";
|
|
3
|
+
function l(n) {
|
|
4
|
+
const { address: r, domain: s, message: e, nonce: t, scheme: a, time: i = /* @__PURE__ */ new Date() } = n;
|
|
5
|
+
if (s && e.domain !== s || t && e.nonce !== t || a && e.scheme !== a || e.expirationTime && i >= e.expirationTime || e.notBefore && i < e.notBefore)
|
|
6
|
+
return !1;
|
|
7
|
+
try {
|
|
8
|
+
if (!e.address || !f(e.address, { strict: !1 }) || r && !o(e.address, r))
|
|
9
|
+
return !1;
|
|
10
|
+
} catch {
|
|
11
|
+
return !1;
|
|
12
|
+
}
|
|
13
|
+
return !0;
|
|
6
14
|
}
|
|
7
15
|
export {
|
|
8
|
-
|
|
16
|
+
l as validateSiweMessage
|
|
9
17
|
};
|
package/dist/index282.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index301.cjs"),$=require("./index302.cjs"),o=require("./index303.cjs"),E=new TextEncoder,h=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function x(r,e={}){const{strict:t=!1}=e;if(!r)throw new c(r);if(typeof r!="string")throw new c(r);if(t&&!/^0x[0-9a-fA-F]*$/.test(r))throw new f(r);if(!r.startsWith("0x"))throw new f(r)}function y(...r){return`0x${r.reduce((e,t)=>e+t.replace("0x",""),"")}`}function O(r,e={}){const t=`0x${Number(r)}`;return typeof e.size=="number"?(o.assertSize(t,e.size),l(t,e.size)):t}function b(r,e={}){let t="";for(let i=0;i<r.length;i++)t+=h[r[i]];const n=`0x${t}`;return typeof e.size=="number"?(o.assertSize(n,e.size),m(n,e.size)):n}function S(r,e={}){const{signed:t,size:n}=e,i=BigInt(r);let s;n?t?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof r=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const d=typeof s=="bigint"&&t?-s-1n:0;if(s&&i>s||i<d){const u=typeof r=="bigint"?"n":"";throw new p({max:s?`${s}${u}`:void 0,min:`${d}${u}`,signed:t,size:n,value:`${r}${u}`})}const g=`0x${(t&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?l(g,n):g}function z(r,e={}){return b(E.encode(r),e)}function l(r,e){return o.pad(r,{dir:"left",size:e})}function m(r,e){return o.pad(r,{dir:"right",size:e})}function w(r,e,t,n={}){const{strict:i}=n;o.assertStartOffset(r,e);const s=`0x${r.replace("0x","").slice((e??0)*2,(t??r.length)*2)}`;return i&&o.assertEndOffset(s,e,t),s}function B(r){return Math.ceil((r.length-2)/2)}function I(r,e={}){const{strict:t=!1}=e;try{return x(r,{strict:t}),!0}catch{return!1}}class p extends a.BaseError{constructor({max:e,min:t,signed:n,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${n?" signed":" unsigned"} integer range ${e?`(\`${t}\` to \`${e}\`)`:`(above \`${t}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class c extends a.BaseError{constructor(e){super(`Value \`${typeof e=="object"?$.stringify(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class f extends a.BaseError{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class H extends a.BaseError{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class v extends a.BaseError{constructor({offset:e,position:t,size:n}){super(`Slice ${t==="start"?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class P extends a.BaseError{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}exports.IntegerOutOfRangeError=p;exports.InvalidHexTypeError=c;exports.InvalidHexValueError=f;exports.SizeExceedsPaddingSizeError=P;exports.SizeOverflowError=H;exports.SliceOffsetOutOfBoundsError=v;exports.assert=x;exports.concat=y;exports.fromBoolean=O;exports.fromBytes=b;exports.fromNumber=S;exports.fromString=z;exports.padLeft=l;exports.padRight=m;exports.size=B;exports.slice=w;exports.validate=I;
|
package/dist/index282.js
CHANGED
|
@@ -1,227 +1,158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { BaseError as o } from "./index301.js";
|
|
2
|
+
import { stringify as b } from "./index302.js";
|
|
3
|
+
import { pad as d, assertEndOffset as m, assertSize as g, assertStartOffset as p } from "./index303.js";
|
|
4
|
+
const $ = /* @__PURE__ */ new TextEncoder(), h = /* @__PURE__ */ Array.from({ length: 256 }, (t, e) => e.toString(16).padStart(2, "0"));
|
|
5
|
+
function y(t, e = {}) {
|
|
6
|
+
const { strict: r = !1 } = e;
|
|
7
|
+
if (!t)
|
|
8
|
+
throw new f(t);
|
|
9
|
+
if (typeof t != "string")
|
|
10
|
+
throw new f(t);
|
|
11
|
+
if (r && !/^0x[0-9a-fA-F]*$/.test(t))
|
|
12
|
+
throw new l(t);
|
|
13
|
+
if (!t.startsWith("0x"))
|
|
14
|
+
throw new l(t);
|
|
15
|
+
}
|
|
16
|
+
function B(...t) {
|
|
17
|
+
return `0x${t.reduce((e, r) => e + r.replace("0x", ""), "")}`;
|
|
18
|
+
}
|
|
19
|
+
function P(t, e = {}) {
|
|
20
|
+
const r = `0x${Number(t)}`;
|
|
21
|
+
return typeof e.size == "number" ? (g(r, e.size), x(r, e.size)) : r;
|
|
22
|
+
}
|
|
23
|
+
function w(t, e = {}) {
|
|
24
|
+
let r = "";
|
|
25
|
+
for (let i = 0; i < t.length; i++)
|
|
26
|
+
r += h[t[i]];
|
|
27
|
+
const n = `0x${r}`;
|
|
28
|
+
return typeof e.size == "number" ? (g(n, e.size), E(n, e.size)) : n;
|
|
29
|
+
}
|
|
30
|
+
function V(t, e = {}) {
|
|
31
|
+
const { signed: r, size: n } = e, i = BigInt(t);
|
|
32
|
+
let s;
|
|
33
|
+
n ? r ? s = (1n << BigInt(n) * 8n - 1n) - 1n : s = 2n ** (BigInt(n) * 8n) - 1n : typeof t == "number" && (s = BigInt(Number.MAX_SAFE_INTEGER));
|
|
34
|
+
const u = typeof s == "bigint" && r ? -s - 1n : 0;
|
|
35
|
+
if (s && i > s || i < u) {
|
|
36
|
+
const a = typeof t == "bigint" ? "n" : "";
|
|
37
|
+
throw new O({
|
|
38
|
+
max: s ? `${s}${a}` : void 0,
|
|
39
|
+
min: `${u}${a}`,
|
|
40
|
+
signed: r,
|
|
41
|
+
size: n,
|
|
42
|
+
value: `${t}${a}`
|
|
43
|
+
});
|
|
24
44
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (t < BigInt(3))
|
|
43
|
-
throw new Error("sqrt is not defined for small field");
|
|
44
|
-
let n = t - d, o = 0;
|
|
45
|
-
for (; n % q === g; )
|
|
46
|
-
n /= q, o++;
|
|
47
|
-
let r = q;
|
|
48
|
-
const s = U(t);
|
|
49
|
-
for (; N(s, r) === 1; )
|
|
50
|
-
if (r++ > 1e3)
|
|
51
|
-
throw new Error("Cannot find square root: probably non-prime P");
|
|
52
|
-
if (o === 1)
|
|
53
|
-
return M;
|
|
54
|
-
let f = s.pow(r, n);
|
|
55
|
-
const c = (n + d) / q;
|
|
56
|
-
return function(i, w) {
|
|
57
|
-
if (i.is0(w))
|
|
58
|
-
return w;
|
|
59
|
-
if (N(i, w) !== 1)
|
|
60
|
-
throw new Error("Cannot find square root");
|
|
61
|
-
let e = o, l = i.mul(i.ONE, f), a = i.pow(w, n), b = i.pow(w, c);
|
|
62
|
-
for (; !i.eql(a, i.ONE); ) {
|
|
63
|
-
if (i.is0(a))
|
|
64
|
-
return i.ZERO;
|
|
65
|
-
let m = 1, E = i.sqr(a);
|
|
66
|
-
for (; !i.eql(E, i.ONE); )
|
|
67
|
-
if (m++, E = i.sqr(E), m === e)
|
|
68
|
-
throw new Error("Cannot find square root");
|
|
69
|
-
const C = d << BigInt(e - m - 1), v = i.pow(l, C);
|
|
70
|
-
e = m, l = i.sqr(v), a = i.mul(a, l), b = i.mul(b, v);
|
|
71
|
-
}
|
|
72
|
-
return b;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function Q(t) {
|
|
76
|
-
return t % x === V ? M : t % L === T ? H : K(t);
|
|
77
|
-
}
|
|
78
|
-
const Y = [
|
|
79
|
-
"create",
|
|
80
|
-
"isValid",
|
|
81
|
-
"is0",
|
|
82
|
-
"neg",
|
|
83
|
-
"inv",
|
|
84
|
-
"sqrt",
|
|
85
|
-
"sqr",
|
|
86
|
-
"eql",
|
|
87
|
-
"add",
|
|
88
|
-
"sub",
|
|
89
|
-
"mul",
|
|
90
|
-
"pow",
|
|
91
|
-
"div",
|
|
92
|
-
"addN",
|
|
93
|
-
"subN",
|
|
94
|
-
"mulN",
|
|
95
|
-
"sqrN"
|
|
96
|
-
];
|
|
97
|
-
function P(t) {
|
|
98
|
-
const n = {
|
|
99
|
-
ORDER: "bigint",
|
|
100
|
-
MASK: "bigint",
|
|
101
|
-
BYTES: "number",
|
|
102
|
-
BITS: "number"
|
|
103
|
-
}, o = Y.reduce((r, s) => (r[s] = "function", r), n);
|
|
104
|
-
return j(t, o), t;
|
|
105
|
-
}
|
|
106
|
-
function k(t, n, o) {
|
|
107
|
-
if (o < g)
|
|
108
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
109
|
-
if (o === g)
|
|
110
|
-
return t.ONE;
|
|
111
|
-
if (o === d)
|
|
112
|
-
return n;
|
|
113
|
-
let r = t.ONE, s = n;
|
|
114
|
-
for (; o > g; )
|
|
115
|
-
o & d && (r = t.mul(r, s)), s = t.sqr(s), o >>= d;
|
|
116
|
-
return r;
|
|
117
|
-
}
|
|
118
|
-
function G(t, n, o = !1) {
|
|
119
|
-
const r = new Array(n.length).fill(o ? t.ZERO : void 0), s = n.reduce((c, u, i) => t.is0(u) ? c : (r[i] = c, t.mul(c, u)), t.ONE), f = t.inv(s);
|
|
120
|
-
return n.reduceRight((c, u, i) => t.is0(u) ? c : (r[i] = t.mul(c, r[i]), t.mul(c, u)), f), r;
|
|
121
|
-
}
|
|
122
|
-
function N(t, n) {
|
|
123
|
-
const o = (t.ORDER - d) / q, r = t.pow(n, o), s = t.eql(r, t.ONE), f = t.eql(r, t.ZERO), c = t.eql(r, t.neg(t.ONE));
|
|
124
|
-
if (!s && !f && !c)
|
|
125
|
-
throw new Error("invalid Legendre symbol result");
|
|
126
|
-
return s ? 1 : f ? 0 : -1;
|
|
127
|
-
}
|
|
128
|
-
function J(t, n) {
|
|
129
|
-
n !== void 0 && z(n);
|
|
130
|
-
const o = n !== void 0 ? n : t.toString(2).length, r = Math.ceil(o / 8);
|
|
131
|
-
return { nBitLength: o, nByteLength: r };
|
|
132
|
-
}
|
|
133
|
-
function U(t, n, o = !1, r = {}) {
|
|
134
|
-
if (t <= g)
|
|
135
|
-
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
136
|
-
let s, f;
|
|
137
|
-
if (typeof n == "object" && n != null) {
|
|
138
|
-
if (r.sqrt || o)
|
|
139
|
-
throw new Error("cannot specify opts in two arguments");
|
|
140
|
-
const e = n;
|
|
141
|
-
e.BITS && (s = e.BITS), e.sqrt && (f = e.sqrt), typeof e.isLE == "boolean" && (o = e.isLE);
|
|
142
|
-
} else
|
|
143
|
-
typeof n == "number" && (s = n), r.sqrt && (f = r.sqrt);
|
|
144
|
-
const { nBitLength: c, nByteLength: u } = J(t, s);
|
|
145
|
-
if (u > 2048)
|
|
146
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
147
|
-
let i;
|
|
148
|
-
const w = Object.freeze({
|
|
149
|
-
ORDER: t,
|
|
150
|
-
isLE: o,
|
|
151
|
-
BITS: c,
|
|
152
|
-
BYTES: u,
|
|
153
|
-
MASK: Z(c),
|
|
154
|
-
ZERO: g,
|
|
155
|
-
ONE: d,
|
|
156
|
-
create: (e) => h(e, t),
|
|
157
|
-
isValid: (e) => {
|
|
158
|
-
if (typeof e != "bigint")
|
|
159
|
-
throw new Error("invalid field element: expected bigint, got " + typeof e);
|
|
160
|
-
return g <= e && e < t;
|
|
161
|
-
},
|
|
162
|
-
is0: (e) => e === g,
|
|
163
|
-
// is valid and invertible
|
|
164
|
-
isValidNot0: (e) => !w.is0(e) && w.isValid(e),
|
|
165
|
-
isOdd: (e) => (e & d) === d,
|
|
166
|
-
neg: (e) => h(-e, t),
|
|
167
|
-
eql: (e, l) => e === l,
|
|
168
|
-
sqr: (e) => h(e * e, t),
|
|
169
|
-
add: (e, l) => h(e + l, t),
|
|
170
|
-
sub: (e, l) => h(e - l, t),
|
|
171
|
-
mul: (e, l) => h(e * l, t),
|
|
172
|
-
pow: (e, l) => k(w, e, l),
|
|
173
|
-
div: (e, l) => h(e * B(l, t), t),
|
|
174
|
-
// Same as above, but doesn't normalize
|
|
175
|
-
sqrN: (e) => e * e,
|
|
176
|
-
addN: (e, l) => e + l,
|
|
177
|
-
subN: (e, l) => e - l,
|
|
178
|
-
mulN: (e, l) => e * l,
|
|
179
|
-
inv: (e) => B(e, t),
|
|
180
|
-
sqrt: f || ((e) => (i || (i = Q(t)), i(w, e))),
|
|
181
|
-
toBytes: (e) => o ? y(e, u) : I(e, u),
|
|
182
|
-
fromBytes: (e) => {
|
|
183
|
-
if (e.length !== u)
|
|
184
|
-
throw new Error("Field.fromBytes: expected " + u + " bytes, got " + e.length);
|
|
185
|
-
return o ? S(e) : _(e);
|
|
186
|
-
},
|
|
187
|
-
// TODO: we don't need it here, move out to separate fn
|
|
188
|
-
invertBatch: (e) => G(w, e),
|
|
189
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
190
|
-
// and it's unclear what to return in there.
|
|
191
|
-
cmov: (e, l, a) => a ? l : e
|
|
192
|
-
});
|
|
193
|
-
return Object.freeze(w);
|
|
45
|
+
const c = `0x${(r && i < 0 ? (1n << BigInt(n * 8)) + BigInt(i) : i).toString(16)}`;
|
|
46
|
+
return n ? x(c, n) : c;
|
|
47
|
+
}
|
|
48
|
+
function j(t, e = {}) {
|
|
49
|
+
return w($.encode(t), e);
|
|
50
|
+
}
|
|
51
|
+
function x(t, e) {
|
|
52
|
+
return d(t, { dir: "left", size: e });
|
|
53
|
+
}
|
|
54
|
+
function E(t, e) {
|
|
55
|
+
return d(t, { dir: "right", size: e });
|
|
56
|
+
}
|
|
57
|
+
function v(t, e, r, n = {}) {
|
|
58
|
+
const { strict: i } = n;
|
|
59
|
+
p(t, e);
|
|
60
|
+
const s = `0x${t.replace("0x", "").slice((e ?? 0) * 2, (r ?? t.length) * 2)}`;
|
|
61
|
+
return i && m(s, e, r), s;
|
|
194
62
|
}
|
|
195
63
|
function A(t) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
64
|
+
return Math.ceil((t.length - 2) / 2);
|
|
65
|
+
}
|
|
66
|
+
function N(t, e = {}) {
|
|
67
|
+
const { strict: r = !1 } = e;
|
|
68
|
+
try {
|
|
69
|
+
return y(t, { strict: r }), !0;
|
|
70
|
+
} catch {
|
|
71
|
+
return !1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class O extends o {
|
|
75
|
+
constructor({ max: e, min: r, signed: n, size: i, value: s }) {
|
|
76
|
+
super(`Number \`${s}\` is not in safe${i ? ` ${i * 8}-bit` : ""}${n ? " signed" : " unsigned"} integer range ${e ? `(\`${r}\` to \`${e}\`)` : `(above \`${r}\`)`}`), Object.defineProperty(this, "name", {
|
|
77
|
+
enumerable: !0,
|
|
78
|
+
configurable: !0,
|
|
79
|
+
writable: !0,
|
|
80
|
+
value: "Hex.IntegerOutOfRangeError"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
class f extends o {
|
|
85
|
+
constructor(e) {
|
|
86
|
+
super(`Value \`${typeof e == "object" ? b(e) : e}\` of type \`${typeof e}\` is an invalid hex type.`, {
|
|
87
|
+
metaMessages: ['Hex types must be represented as `"0x${string}"`.']
|
|
88
|
+
}), Object.defineProperty(this, "name", {
|
|
89
|
+
enumerable: !0,
|
|
90
|
+
configurable: !0,
|
|
91
|
+
writable: !0,
|
|
92
|
+
value: "Hex.InvalidHexTypeError"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class l extends o {
|
|
97
|
+
constructor(e) {
|
|
98
|
+
super(`Value \`${e}\` is an invalid hex value.`, {
|
|
99
|
+
metaMessages: [
|
|
100
|
+
'Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).'
|
|
101
|
+
]
|
|
102
|
+
}), Object.defineProperty(this, "name", {
|
|
103
|
+
enumerable: !0,
|
|
104
|
+
configurable: !0,
|
|
105
|
+
writable: !0,
|
|
106
|
+
value: "Hex.InvalidHexValueError"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class _ extends o {
|
|
111
|
+
constructor({ givenSize: e, maxSize: r }) {
|
|
112
|
+
super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`), Object.defineProperty(this, "name", {
|
|
113
|
+
enumerable: !0,
|
|
114
|
+
configurable: !0,
|
|
115
|
+
writable: !0,
|
|
116
|
+
value: "Hex.SizeOverflowError"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class M extends o {
|
|
121
|
+
constructor({ offset: e, position: r, size: n }) {
|
|
122
|
+
super(`Slice ${r === "start" ? "starting" : "ending"} at offset \`${e}\` is out-of-bounds (size: \`${n}\`).`), Object.defineProperty(this, "name", {
|
|
123
|
+
enumerable: !0,
|
|
124
|
+
configurable: !0,
|
|
125
|
+
writable: !0,
|
|
126
|
+
value: "Hex.SliceOffsetOutOfBoundsError"
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
class R extends o {
|
|
131
|
+
constructor({ size: e, targetSize: r, type: n }) {
|
|
132
|
+
super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`), Object.defineProperty(this, "name", {
|
|
133
|
+
enumerable: !0,
|
|
134
|
+
configurable: !0,
|
|
135
|
+
writable: !0,
|
|
136
|
+
value: "Hex.SizeExceedsPaddingSizeError"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
211
139
|
}
|
|
212
140
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
B as
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
141
|
+
O as IntegerOutOfRangeError,
|
|
142
|
+
f as InvalidHexTypeError,
|
|
143
|
+
l as InvalidHexValueError,
|
|
144
|
+
R as SizeExceedsPaddingSizeError,
|
|
145
|
+
_ as SizeOverflowError,
|
|
146
|
+
M as SliceOffsetOutOfBoundsError,
|
|
147
|
+
y as assert,
|
|
148
|
+
B as concat,
|
|
149
|
+
P as fromBoolean,
|
|
150
|
+
w as fromBytes,
|
|
151
|
+
V as fromNumber,
|
|
152
|
+
j as fromString,
|
|
153
|
+
x as padLeft,
|
|
154
|
+
E as padRight,
|
|
155
|
+
A as size,
|
|
156
|
+
v as slice,
|
|
157
|
+
N as validate
|
|
227
158
|
};
|