@gardenfi/utils 2.1.1 → 2.1.2
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/index101.cjs +1 -1
- package/dist/index101.js +1 -1
- package/dist/index104.cjs +1 -1
- package/dist/index104.js +16 -10
- package/dist/index105.cjs +1 -1
- package/dist/index105.js +3 -3
- package/dist/index106.cjs +1 -1
- package/dist/index106.js +2 -2
- package/dist/index107.cjs +1 -1
- package/dist/index107.js +10 -16
- package/dist/index109.cjs +2 -1
- package/dist/index109.js +3 -2
- package/dist/index110.cjs +1 -1
- package/dist/index110.js +2 -2
- package/dist/index111.cjs +1 -1
- package/dist/index111.js +2 -38
- package/dist/index112.cjs +1 -1
- package/dist/index112.js +33 -34
- package/dist/index113.cjs +1 -2
- package/dist/index113.js +39 -3
- package/dist/index116.cjs +1 -1
- package/dist/index116.js +2 -2
- package/dist/index117.cjs +1 -1
- package/dist/index117.js +1 -1
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +3 -3
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +2 -2
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +1 -1
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +1 -1
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +2 -2
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +3 -3
- package/dist/index38.cjs +1 -1
- package/dist/index38.js +1 -1
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +2 -2
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +9 -9
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +2 -2
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +1 -1
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +1 -1
- package/dist/index49.cjs +1 -1
- package/dist/index49.js +1 -1
- package/dist/index60.cjs +1 -1
- package/dist/index60.js +38 -10
- package/dist/index61.cjs +1 -1
- package/dist/index61.js +32 -32
- package/dist/index62.cjs +1 -1
- package/dist/index62.js +66 -109
- package/dist/index63.cjs +1 -1
- package/dist/index63.js +112 -16
- package/dist/index64.cjs +1 -1
- package/dist/index64.js +60 -216
- package/dist/index65.cjs +1 -2
- package/dist/index65.js +2 -60
- package/dist/index66.cjs +1 -1
- package/dist/index66.js +16 -21
- package/dist/index67.cjs +1 -1
- package/dist/index67.js +219 -36
- package/dist/index68.cjs +1 -1
- package/dist/index68.js +229 -32
- package/dist/index69.cjs +1 -1
- package/dist/index69.js +9 -66
- package/dist/index70.cjs +1 -1
- package/dist/index70.js +31 -64
- package/dist/index71.cjs +2 -1
- package/dist/index71.js +60 -2
- package/dist/index72.cjs +1 -1
- package/dist/index72.js +18 -228
- package/dist/index74.cjs +1 -1
- package/dist/index74.js +1 -1
- package/dist/index75.cjs +1 -1
- package/dist/index75.js +8 -4
- package/dist/index76.cjs +1 -1
- package/dist/index76.js +104 -3
- package/dist/index77.cjs +1 -1
- package/dist/index77.js +3 -8
- package/dist/index78.cjs +1 -1
- package/dist/index78.js +17 -104
- package/dist/index79.cjs +1 -1
- package/dist/index79.js +8 -17
- package/dist/index80.cjs +1 -1
- package/dist/index80.js +10 -8
- package/dist/index81.cjs +1 -1
- package/dist/index81.js +11 -10
- package/dist/index82.cjs +1 -1
- package/dist/index82.js +13 -11
- package/dist/index83.cjs +1 -1
- package/dist/index83.js +6 -13
- package/dist/index84.cjs +1 -1
- package/dist/index84.js +78 -6
- package/dist/index85.cjs +1 -1
- package/dist/index85.js +14 -78
- package/dist/index86.cjs +1 -1
- package/dist/index86.js +18 -14
- package/dist/index87.cjs +1 -1
- package/dist/index87.js +189 -16
- package/dist/index88.cjs +1 -1
- package/dist/index88.js +58 -185
- package/dist/index89.cjs +1 -1
- package/dist/index89.js +4 -64
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +49 -41
- package/dist/index91.cjs +1 -1
- package/dist/index91.js +1 -1
- package/dist/index93.cjs +1 -1
- package/dist/index93.js +2 -2
- package/dist/index94.cjs +1 -1
- package/dist/index94.js +1 -1
- package/dist/index98.cjs +1 -1
- package/dist/index98.js +2 -2
- package/dist/index99.cjs +1 -1
- package/dist/index99.js +1 -1
- package/package.json +1 -1
package/dist/index87.js
CHANGED
|
@@ -1,21 +1,194 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { AbiEncodingLengthMismatchError as y, InvalidAbiEncodingTypeError as u, InvalidArrayError as g, AbiEncodingArrayLengthMismatchError as l, AbiEncodingBytesSizeMismatchError as b } from "./index93.js";
|
|
2
|
+
import { InvalidAddressError as w } from "./index32.js";
|
|
3
|
+
import { BaseError as A } from "./index71.js";
|
|
4
|
+
import { IntegerOutOfRangeError as x } from "./index69.js";
|
|
5
|
+
import { isAddress as z } from "./index33.js";
|
|
6
|
+
import { concat as f } from "./index73.js";
|
|
7
|
+
import { padHex as d } from "./index70.js";
|
|
8
|
+
import { size as a } from "./index89.js";
|
|
9
|
+
import { slice as E } from "./index113.js";
|
|
10
|
+
import { numberToHex as m, boolToHex as P, stringToHex as S } from "./index24.js";
|
|
11
|
+
import { integerRegex as I } from "./index100.js";
|
|
12
|
+
function K(e, t) {
|
|
13
|
+
if (e.length !== t.length)
|
|
14
|
+
throw new y({
|
|
15
|
+
expectedLength: e.length,
|
|
16
|
+
givenLength: t.length
|
|
17
|
+
});
|
|
18
|
+
const o = L({
|
|
19
|
+
params: e,
|
|
20
|
+
values: t
|
|
21
|
+
}), n = h(o);
|
|
22
|
+
return n.length === 0 ? "0x" : n;
|
|
23
|
+
}
|
|
24
|
+
function L({ params: e, values: t }) {
|
|
25
|
+
const o = [];
|
|
26
|
+
for (let n = 0; n < e.length; n++)
|
|
27
|
+
o.push(p({ param: e[n], value: t[n] }));
|
|
28
|
+
return o;
|
|
29
|
+
}
|
|
30
|
+
function p({ param: e, value: t }) {
|
|
31
|
+
const o = W(e.type);
|
|
32
|
+
if (o) {
|
|
33
|
+
const [n, r] = o;
|
|
34
|
+
return M(t, { length: n, param: { ...e, type: r } });
|
|
35
|
+
}
|
|
36
|
+
if (e.type === "tuple")
|
|
37
|
+
return H(t, {
|
|
38
|
+
param: e
|
|
39
|
+
});
|
|
40
|
+
if (e.type === "address")
|
|
41
|
+
return B(t);
|
|
42
|
+
if (e.type === "bool")
|
|
43
|
+
return T(t);
|
|
44
|
+
if (e.type.startsWith("uint") || e.type.startsWith("int")) {
|
|
45
|
+
const n = e.type.startsWith("int"), [, , r = "256"] = I.exec(e.type) ?? [];
|
|
46
|
+
return $(t, {
|
|
47
|
+
signed: n,
|
|
48
|
+
size: Number(r)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (e.type.startsWith("bytes"))
|
|
52
|
+
return N(t, { param: e });
|
|
53
|
+
if (e.type === "string")
|
|
54
|
+
return C(t);
|
|
55
|
+
throw new u(e.type, {
|
|
56
|
+
docsPath: "/docs/contract/encodeAbiParameters"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function h(e) {
|
|
60
|
+
let t = 0;
|
|
61
|
+
for (let i = 0; i < e.length; i++) {
|
|
62
|
+
const { dynamic: c, encoded: s } = e[i];
|
|
63
|
+
c ? t += 32 : t += a(s);
|
|
64
|
+
}
|
|
65
|
+
const o = [], n = [];
|
|
66
|
+
let r = 0;
|
|
67
|
+
for (let i = 0; i < e.length; i++) {
|
|
68
|
+
const { dynamic: c, encoded: s } = e[i];
|
|
69
|
+
c ? (o.push(m(t + r, { size: 32 })), n.push(s), r += a(s)) : o.push(s);
|
|
70
|
+
}
|
|
71
|
+
return f([...o, ...n]);
|
|
72
|
+
}
|
|
73
|
+
function B(e) {
|
|
74
|
+
if (!z(e))
|
|
75
|
+
throw new w({ address: e });
|
|
76
|
+
return { dynamic: !1, encoded: d(e.toLowerCase()) };
|
|
77
|
+
}
|
|
78
|
+
function M(e, { length: t, param: o }) {
|
|
79
|
+
const n = t === null;
|
|
80
|
+
if (!Array.isArray(e))
|
|
81
|
+
throw new g(e);
|
|
82
|
+
if (!n && e.length !== t)
|
|
83
|
+
throw new l({
|
|
84
|
+
expectedLength: t,
|
|
85
|
+
givenLength: e.length,
|
|
86
|
+
type: `${o.type}[${t}]`
|
|
87
|
+
});
|
|
88
|
+
let r = !1;
|
|
89
|
+
const i = [];
|
|
90
|
+
for (let c = 0; c < e.length; c++) {
|
|
91
|
+
const s = p({ param: o, value: e[c] });
|
|
92
|
+
s.dynamic && (r = !0), i.push(s);
|
|
93
|
+
}
|
|
94
|
+
if (n || r) {
|
|
95
|
+
const c = h(i);
|
|
96
|
+
if (n) {
|
|
97
|
+
const s = m(i.length, { size: 32 });
|
|
98
|
+
return {
|
|
99
|
+
dynamic: !0,
|
|
100
|
+
encoded: i.length > 0 ? f([s, c]) : s
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (r)
|
|
104
|
+
return { dynamic: !0, encoded: c };
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
dynamic: !1,
|
|
108
|
+
encoded: f(i.map(({ encoded: c }) => c))
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function N(e, { param: t }) {
|
|
112
|
+
const [, o] = t.type.split("bytes"), n = a(e);
|
|
113
|
+
if (!o) {
|
|
114
|
+
let r = e;
|
|
115
|
+
return n % 32 !== 0 && (r = d(r, {
|
|
116
|
+
dir: "right",
|
|
117
|
+
size: Math.ceil((e.length - 2) / 2 / 32) * 32
|
|
118
|
+
})), {
|
|
119
|
+
dynamic: !0,
|
|
120
|
+
encoded: f([d(m(n, { size: 32 })), r])
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (n !== Number.parseInt(o))
|
|
124
|
+
throw new b({
|
|
125
|
+
expectedSize: Number.parseInt(o),
|
|
126
|
+
value: e
|
|
127
|
+
});
|
|
128
|
+
return { dynamic: !1, encoded: d(e, { dir: "right" }) };
|
|
129
|
+
}
|
|
130
|
+
function T(e) {
|
|
131
|
+
if (typeof e != "boolean")
|
|
132
|
+
throw new A(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);
|
|
133
|
+
return { dynamic: !1, encoded: d(P(e)) };
|
|
134
|
+
}
|
|
135
|
+
function $(e, { signed: t, size: o = 256 }) {
|
|
136
|
+
if (typeof o == "number") {
|
|
137
|
+
const n = 2n ** (BigInt(o) - (t ? 1n : 0n)) - 1n, r = t ? -n - 1n : 0n;
|
|
138
|
+
if (e > n || e < r)
|
|
139
|
+
throw new x({
|
|
140
|
+
max: n.toString(),
|
|
141
|
+
min: r.toString(),
|
|
142
|
+
signed: t,
|
|
143
|
+
size: o / 8,
|
|
144
|
+
value: e.toString()
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
dynamic: !1,
|
|
149
|
+
encoded: m(e, {
|
|
150
|
+
size: 32,
|
|
151
|
+
signed: t
|
|
152
|
+
})
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function C(e) {
|
|
156
|
+
const t = S(e), o = Math.ceil(a(t) / 32), n = [];
|
|
157
|
+
for (let r = 0; r < o; r++)
|
|
158
|
+
n.push(d(E(t, r * 32, (r + 1) * 32), {
|
|
159
|
+
dir: "right"
|
|
160
|
+
}));
|
|
161
|
+
return {
|
|
162
|
+
dynamic: !0,
|
|
163
|
+
encoded: f([
|
|
164
|
+
d(m(a(t), { size: 32 })),
|
|
165
|
+
...n
|
|
166
|
+
])
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function H(e, { param: t }) {
|
|
170
|
+
let o = !1;
|
|
7
171
|
const n = [];
|
|
8
|
-
for (let
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
throw new s({ address: i });
|
|
15
|
-
n.push([i, e]);
|
|
172
|
+
for (let r = 0; r < t.components.length; r++) {
|
|
173
|
+
const i = t.components[r], c = Array.isArray(e) ? r : i.name, s = p({
|
|
174
|
+
param: i,
|
|
175
|
+
value: e[c]
|
|
176
|
+
});
|
|
177
|
+
n.push(s), s.dynamic && (o = !0);
|
|
16
178
|
}
|
|
17
|
-
return
|
|
179
|
+
return {
|
|
180
|
+
dynamic: o,
|
|
181
|
+
encoded: o ? h(n) : f(n.map(({ encoded: r }) => r))
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function W(e) {
|
|
185
|
+
const t = e.match(/^(.*)\[(\d+)?\]$/);
|
|
186
|
+
return t ? (
|
|
187
|
+
// Return `null` if the array is dynamic.
|
|
188
|
+
[t[2] ? Number(t[2]) : null, t[1]]
|
|
189
|
+
) : void 0;
|
|
18
190
|
}
|
|
19
191
|
export {
|
|
20
|
-
|
|
192
|
+
K as encodeAbiParameters,
|
|
193
|
+
W as getArrayComponents
|
|
21
194
|
};
|
package/dist/index88.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 E=require("./index93.cjs"),z=require("./index32.cjs"),o=require("./index99.cjs"),T=require("./index33.cjs"),u=require("./index89.cjs"),q=require("./index24.cjs"),g=require("./index100.cjs");function P(e){const{domain:n,message:b,primaryType:a,types:r}=e,c=(l,h)=>{for(const v of l){const{name:I,type:s}=v,t=h[I],y=s.match(g.integerRegex);if(y&&(typeof t=="number"||typeof t=="bigint")){const[w,i,D]=y;q.numberToHex(t,{signed:i==="int",size:Number.parseInt(D)/8})}if(s==="address"&&typeof t=="string"&&!T.isAddress(t))throw new z.InvalidAddressError({address:t});const f=s.match(g.bytesRegex);if(f){const[w,i]=f;if(i&&u.size(t)!==Number.parseInt(i))throw new E.BytesSizeMismatchError({expectedSize:Number.parseInt(i),givenSize:u.size(t)})}const p=r[s];p&&(x(s),c(p,t))}};if(r.EIP712Domain&&n){if(typeof n!="object")throw new o.InvalidDomainError({domain:n});c(r.EIP712Domain,n)}if(a!=="EIP712Domain")if(r[a])c(r[a],b);else throw new o.InvalidPrimaryTypeError({primaryType:a,types:r})}function d({domain:e}){return[typeof(e==null?void 0:e.name)=="string"&&{name:"name",type:"string"},(e==null?void 0:e.version)&&{name:"version",type:"string"},(typeof(e==null?void 0:e.chainId)=="number"||typeof(e==null?void 0:e.chainId)=="bigint")&&{name:"chainId",type:"uint256"},(e==null?void 0:e.verifyingContract)&&{name:"verifyingContract",type:"address"},(e==null?void 0:e.salt)&&{name:"salt",type:"bytes32"}].filter(Boolean)}function x(e){if(e==="address"||e==="bool"||e==="string"||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new o.InvalidStructTypeError({type:e})}exports.getTypesForEIP712Domain=d;exports.validateTypedData=P;
|
package/dist/index88.js
CHANGED
|
@@ -1,194 +1,67 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BytesSizeMismatchError as m } from "./index93.js";
|
|
2
2
|
import { InvalidAddressError as w } from "./index32.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (o) {
|
|
33
|
-
const [n, r] = o;
|
|
34
|
-
return M(t, { length: n, param: { ...e, type: r } });
|
|
35
|
-
}
|
|
36
|
-
if (e.type === "tuple")
|
|
37
|
-
return H(t, {
|
|
38
|
-
param: e
|
|
39
|
-
});
|
|
40
|
-
if (e.type === "address")
|
|
41
|
-
return B(t);
|
|
42
|
-
if (e.type === "bool")
|
|
43
|
-
return T(t);
|
|
44
|
-
if (e.type.startsWith("uint") || e.type.startsWith("int")) {
|
|
45
|
-
const n = e.type.startsWith("int"), [, , r = "256"] = I.exec(e.type) ?? [];
|
|
46
|
-
return $(t, {
|
|
47
|
-
signed: n,
|
|
48
|
-
size: Number(r)
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (e.type.startsWith("bytes"))
|
|
52
|
-
return N(t, { param: e });
|
|
53
|
-
if (e.type === "string")
|
|
54
|
-
return C(t);
|
|
55
|
-
throw new u(e.type, {
|
|
56
|
-
docsPath: "/docs/contract/encodeAbiParameters"
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function h(e) {
|
|
60
|
-
let t = 0;
|
|
61
|
-
for (let i = 0; i < e.length; i++) {
|
|
62
|
-
const { dynamic: c, encoded: s } = e[i];
|
|
63
|
-
c ? t += 32 : t += a(s);
|
|
64
|
-
}
|
|
65
|
-
const o = [], n = [];
|
|
66
|
-
let r = 0;
|
|
67
|
-
for (let i = 0; i < e.length; i++) {
|
|
68
|
-
const { dynamic: c, encoded: s } = e[i];
|
|
69
|
-
c ? (o.push(m(t + r, { size: 32 })), n.push(s), r += a(s)) : o.push(s);
|
|
70
|
-
}
|
|
71
|
-
return f([...o, ...n]);
|
|
72
|
-
}
|
|
73
|
-
function B(e) {
|
|
74
|
-
if (!z(e))
|
|
75
|
-
throw new w({ address: e });
|
|
76
|
-
return { dynamic: !1, encoded: d(e.toLowerCase()) };
|
|
77
|
-
}
|
|
78
|
-
function M(e, { length: t, param: o }) {
|
|
79
|
-
const n = t === null;
|
|
80
|
-
if (!Array.isArray(e))
|
|
81
|
-
throw new g(e);
|
|
82
|
-
if (!n && e.length !== t)
|
|
83
|
-
throw new l({
|
|
84
|
-
expectedLength: t,
|
|
85
|
-
givenLength: e.length,
|
|
86
|
-
type: `${o.type}[${t}]`
|
|
87
|
-
});
|
|
88
|
-
let r = !1;
|
|
89
|
-
const i = [];
|
|
90
|
-
for (let c = 0; c < e.length; c++) {
|
|
91
|
-
const s = p({ param: o, value: e[c] });
|
|
92
|
-
s.dynamic && (r = !0), i.push(s);
|
|
93
|
-
}
|
|
94
|
-
if (n || r) {
|
|
95
|
-
const c = h(i);
|
|
96
|
-
if (n) {
|
|
97
|
-
const s = m(i.length, { size: 32 });
|
|
98
|
-
return {
|
|
99
|
-
dynamic: !0,
|
|
100
|
-
encoded: i.length > 0 ? f([s, c]) : s
|
|
101
|
-
};
|
|
3
|
+
import { InvalidDomainError as E, InvalidPrimaryTypeError as z, InvalidStructTypeError as D } from "./index99.js";
|
|
4
|
+
import { isAddress as T } from "./index33.js";
|
|
5
|
+
import { size as y } from "./index89.js";
|
|
6
|
+
import { numberToHex as x } from "./index24.js";
|
|
7
|
+
import { integerRegex as P, bytesRegex as S } from "./index100.js";
|
|
8
|
+
function j(e) {
|
|
9
|
+
const { domain: n, message: g, primaryType: o, types: r } = e, f = (h, b) => {
|
|
10
|
+
for (const u of h) {
|
|
11
|
+
const { name: l, type: s } = u, t = b[l], a = s.match(P);
|
|
12
|
+
if (a && (typeof t == "number" || typeof t == "bigint")) {
|
|
13
|
+
const [I, i, v] = a;
|
|
14
|
+
x(t, {
|
|
15
|
+
signed: i === "int",
|
|
16
|
+
size: Number.parseInt(v) / 8
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (s === "address" && typeof t == "string" && !T(t))
|
|
20
|
+
throw new w({ address: t });
|
|
21
|
+
const p = s.match(S);
|
|
22
|
+
if (p) {
|
|
23
|
+
const [I, i] = p;
|
|
24
|
+
if (i && y(t) !== Number.parseInt(i))
|
|
25
|
+
throw new m({
|
|
26
|
+
expectedSize: Number.parseInt(i),
|
|
27
|
+
givenSize: y(t)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const c = r[s];
|
|
31
|
+
c && (_(s), f(c, t));
|
|
102
32
|
}
|
|
103
|
-
if (r)
|
|
104
|
-
return { dynamic: !0, encoded: c };
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
dynamic: !1,
|
|
108
|
-
encoded: f(i.map(({ encoded: c }) => c))
|
|
109
33
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let r = e;
|
|
115
|
-
return n % 32 !== 0 && (r = d(r, {
|
|
116
|
-
dir: "right",
|
|
117
|
-
size: Math.ceil((e.length - 2) / 2 / 32) * 32
|
|
118
|
-
})), {
|
|
119
|
-
dynamic: !0,
|
|
120
|
-
encoded: f([d(m(n, { size: 32 })), r])
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
if (n !== Number.parseInt(o))
|
|
124
|
-
throw new b({
|
|
125
|
-
expectedSize: Number.parseInt(o),
|
|
126
|
-
value: e
|
|
127
|
-
});
|
|
128
|
-
return { dynamic: !1, encoded: d(e, { dir: "right" }) };
|
|
129
|
-
}
|
|
130
|
-
function T(e) {
|
|
131
|
-
if (typeof e != "boolean")
|
|
132
|
-
throw new A(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);
|
|
133
|
-
return { dynamic: !1, encoded: d(P(e)) };
|
|
134
|
-
}
|
|
135
|
-
function $(e, { signed: t, size: o = 256 }) {
|
|
136
|
-
if (typeof o == "number") {
|
|
137
|
-
const n = 2n ** (BigInt(o) - (t ? 1n : 0n)) - 1n, r = t ? -n - 1n : 0n;
|
|
138
|
-
if (e > n || e < r)
|
|
139
|
-
throw new x({
|
|
140
|
-
max: n.toString(),
|
|
141
|
-
min: r.toString(),
|
|
142
|
-
signed: t,
|
|
143
|
-
size: o / 8,
|
|
144
|
-
value: e.toString()
|
|
145
|
-
});
|
|
34
|
+
if (r.EIP712Domain && n) {
|
|
35
|
+
if (typeof n != "object")
|
|
36
|
+
throw new E({ domain: n });
|
|
37
|
+
f(r.EIP712Domain, n);
|
|
146
38
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function C(e) {
|
|
156
|
-
const t = S(e), o = Math.ceil(a(t) / 32), n = [];
|
|
157
|
-
for (let r = 0; r < o; r++)
|
|
158
|
-
n.push(d(E(t, r * 32, (r + 1) * 32), {
|
|
159
|
-
dir: "right"
|
|
160
|
-
}));
|
|
161
|
-
return {
|
|
162
|
-
dynamic: !0,
|
|
163
|
-
encoded: f([
|
|
164
|
-
d(m(a(t), { size: 32 })),
|
|
165
|
-
...n
|
|
166
|
-
])
|
|
167
|
-
};
|
|
39
|
+
if (o !== "EIP712Domain")
|
|
40
|
+
if (r[o])
|
|
41
|
+
f(r[o], g);
|
|
42
|
+
else
|
|
43
|
+
throw new z({ primaryType: o, types: r });
|
|
168
44
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
45
|
+
function F({ domain: e }) {
|
|
46
|
+
return [
|
|
47
|
+
typeof (e == null ? void 0 : e.name) == "string" && { name: "name", type: "string" },
|
|
48
|
+
(e == null ? void 0 : e.version) && { name: "version", type: "string" },
|
|
49
|
+
(typeof (e == null ? void 0 : e.chainId) == "number" || typeof (e == null ? void 0 : e.chainId) == "bigint") && {
|
|
50
|
+
name: "chainId",
|
|
51
|
+
type: "uint256"
|
|
52
|
+
},
|
|
53
|
+
(e == null ? void 0 : e.verifyingContract) && {
|
|
54
|
+
name: "verifyingContract",
|
|
55
|
+
type: "address"
|
|
56
|
+
},
|
|
57
|
+
(e == null ? void 0 : e.salt) && { name: "salt", type: "bytes32" }
|
|
58
|
+
].filter(Boolean);
|
|
183
59
|
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// Return `null` if the array is dynamic.
|
|
188
|
-
[t[2] ? Number(t[2]) : null, t[1]]
|
|
189
|
-
) : void 0;
|
|
60
|
+
function _(e) {
|
|
61
|
+
if (e === "address" || e === "bool" || e === "string" || e.startsWith("bytes") || e.startsWith("uint") || e.startsWith("int"))
|
|
62
|
+
throw new D({ type: e });
|
|
190
63
|
}
|
|
191
64
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
65
|
+
F as getTypesForEIP712Domain,
|
|
66
|
+
j as validateTypedData
|
|
194
67
|
};
|
package/dist/index89.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 t=require("./index77.cjs");function i(e){return t.isHex(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}exports.size=i;
|
package/dist/index89.js
CHANGED
|
@@ -1,67 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { isAddress as T } from "./index33.js";
|
|
5
|
-
import { size as y } from "./index75.js";
|
|
6
|
-
import { numberToHex as x } from "./index24.js";
|
|
7
|
-
import { integerRegex as P, bytesRegex as S } from "./index100.js";
|
|
8
|
-
function j(e) {
|
|
9
|
-
const { domain: n, message: g, primaryType: o, types: r } = e, f = (h, b) => {
|
|
10
|
-
for (const u of h) {
|
|
11
|
-
const { name: l, type: s } = u, t = b[l], a = s.match(P);
|
|
12
|
-
if (a && (typeof t == "number" || typeof t == "bigint")) {
|
|
13
|
-
const [I, i, v] = a;
|
|
14
|
-
x(t, {
|
|
15
|
-
signed: i === "int",
|
|
16
|
-
size: Number.parseInt(v) / 8
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (s === "address" && typeof t == "string" && !T(t))
|
|
20
|
-
throw new w({ address: t });
|
|
21
|
-
const p = s.match(S);
|
|
22
|
-
if (p) {
|
|
23
|
-
const [I, i] = p;
|
|
24
|
-
if (i && y(t) !== Number.parseInt(i))
|
|
25
|
-
throw new m({
|
|
26
|
-
expectedSize: Number.parseInt(i),
|
|
27
|
-
givenSize: y(t)
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const c = r[s];
|
|
31
|
-
c && (_(s), f(c, t));
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
if (r.EIP712Domain && n) {
|
|
35
|
-
if (typeof n != "object")
|
|
36
|
-
throw new E({ domain: n });
|
|
37
|
-
f(r.EIP712Domain, n);
|
|
38
|
-
}
|
|
39
|
-
if (o !== "EIP712Domain")
|
|
40
|
-
if (r[o])
|
|
41
|
-
f(r[o], g);
|
|
42
|
-
else
|
|
43
|
-
throw new z({ primaryType: o, types: r });
|
|
44
|
-
}
|
|
45
|
-
function F({ domain: e }) {
|
|
46
|
-
return [
|
|
47
|
-
typeof (e == null ? void 0 : e.name) == "string" && { name: "name", type: "string" },
|
|
48
|
-
(e == null ? void 0 : e.version) && { name: "version", type: "string" },
|
|
49
|
-
(typeof (e == null ? void 0 : e.chainId) == "number" || typeof (e == null ? void 0 : e.chainId) == "bigint") && {
|
|
50
|
-
name: "chainId",
|
|
51
|
-
type: "uint256"
|
|
52
|
-
},
|
|
53
|
-
(e == null ? void 0 : e.verifyingContract) && {
|
|
54
|
-
name: "verifyingContract",
|
|
55
|
-
type: "address"
|
|
56
|
-
},
|
|
57
|
-
(e == null ? void 0 : e.salt) && { name: "salt", type: "bytes32" }
|
|
58
|
-
].filter(Boolean);
|
|
59
|
-
}
|
|
60
|
-
function _(e) {
|
|
61
|
-
if (e === "address" || e === "bool" || e === "string" || e.startsWith("bytes") || e.startsWith("uint") || e.startsWith("int"))
|
|
62
|
-
throw new D({ type: e });
|
|
1
|
+
import { isHex as r } from "./index77.js";
|
|
2
|
+
function i(t) {
|
|
3
|
+
return r(t, { strict: !1 }) ? Math.ceil((t.length - 2) / 2) : t.length;
|
|
63
4
|
}
|
|
64
5
|
export {
|
|
65
|
-
|
|
66
|
-
j as validateTypedData
|
|
6
|
+
i as size
|
|
67
7
|
};
|
package/dist/index9.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 g=require("tough-cookie"),k=require("fetch-cookie"),n=require("./index17.cjs"),m=require("./index13.cjs"),f=require("./index14.cjs"),w=require("viem"),h=require("./index3.cjs"),y=require("./index20.cjs"),C=require("./index19.cjs"),T=require("./index21.cjs"),v=c=>c&&c.__esModule?c:{default:c},S=v(k);class d{constructor(t,i,e){if(this.url=t.endpoint("siwe"),this.walletClient=i,this.domain=(e==null?void 0:e.domain)||"app.garden.finance",this.domain.startsWith("https://")&&(this.domain=this.domain.split("https://")[1]),this.signingStatement=(e==null?void 0:e.signingStatement)??"Garden.fi",this.store=(e==null?void 0:e.store)??(typeof window<"u"?window.localStorage:new m.MemoryStorage),typeof window>"u"){const r=new g.CookieJar;this.fetchWithCookies=S.default(fetch,r)}else this.fetchWithCookies=window.fetch.bind(window)}static fromDigestKey(t,i,e){const r=w.createWalletClient({account:C.privateKeyToAccount(h.add0x(i.digestKey)),transport:w.http(),chain:y.mainnet});return new d(t,r,e)}verifyToken(t,i){try{const e=h.parseJwt(t);if(!e)return n.Ok(!1);const r=Math.floor(Date.now()/1e3)+120;return n.Ok(e.exp>r&&e.user_id.toLowerCase()===i.toLowerCase())}catch{return n.Ok(!1)}}async getToken(){var s;if(!((s=this.walletClient.account)!=null&&s.address))return n.Err("Wallet client does not have an account");const t=this.store.getItem(f.StoreKeys.AUTH_TOKEN);if(t){const o=this.verifyToken(t,this.walletClient.account.address);if(o.ok&&o.val)return n.Ok(t)}const i=await this.signStatement();if(i.error)return n.Err(i.error);let e;try{const a=await(await this.fetchWithCookies(this.url.endpoint("tokens"),{method:"POST",body:JSON.stringify({...i.val}),headers:{"Content-Type":"application/json"},credentials:"include"})).json();if(a.error||!a.result)return n.Err(a.error??"Failed to get token");e=a.result}catch(o){return n.Err("Failed to get token",o)}if(!this.verifyToken(e,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(f.StoreKeys.AUTH_TOKEN,e),n.Ok(e)}async signStatement(){var a;if(!((a=this.walletClient.account)!=null&&a.address))return n.Err("Wallet client does not have a valid account");const t=new Date,i=new Date(t.getTime()+300*1e3);let e;try{const l=await(await this.fetchWithCookies(this.url.endpoint("challenges"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"})).json();if(l.error||!l.result)return n.Err("Failed to get nonce");e=l.result}catch(u){return n.Err("Failed to get nonce",u)}const r=await this.walletClient.getChainId(),s=T.createSiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:e,uri:"https://"+this.domain,version:"1",chainId:r,notBefore:i}),o=await this.walletClient.signMessage({account:this.walletClient.account,message:s});return n.Ok({message:s,signature:o,nonce:e})}async getAuthHeaders(){const t=await this.getToken();return t.error?n.Err(t.error):n.Ok({Authorization:h.Authorization(t.val)})}}exports.Siwe=d;
|