@gardenfi/utils 2.0.6 → 2.1.0-beta.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.
Files changed (230) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +22 -20
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +37 -19
  5. package/dist/index100.cjs +1 -1
  6. package/dist/index100.js +26 -126
  7. package/dist/index101.cjs +1 -1
  8. package/dist/index101.js +3 -113
  9. package/dist/index102.cjs +1 -1
  10. package/dist/index102.js +10 -77
  11. package/dist/index103.cjs +1 -1
  12. package/dist/index103.js +20 -2
  13. package/dist/index104.cjs +1 -1
  14. package/dist/index104.js +11 -16
  15. package/dist/index105.cjs +1 -1
  16. package/dist/index105.js +17 -17
  17. package/dist/index106.cjs +1 -1
  18. package/dist/index106.js +639 -12
  19. package/dist/index107.cjs +1 -1
  20. package/dist/index107.js +161 -212
  21. package/dist/index109.cjs +1 -1
  22. package/dist/index109.js +127 -34
  23. package/dist/index11.cjs +1 -1
  24. package/dist/index11.js +19 -134
  25. package/dist/index110.cjs +1 -1
  26. package/dist/index110.js +2 -19
  27. package/dist/index111.cjs +1 -1
  28. package/dist/index111.js +2 -70
  29. package/dist/index112.cjs +1 -1
  30. package/dist/index112.js +33 -63
  31. package/dist/index113.cjs +1 -1
  32. package/dist/index113.js +39 -2
  33. package/dist/index114.cjs +1 -1
  34. package/dist/index114.js +5 -41
  35. package/dist/index115.cjs +1 -1
  36. package/dist/index115.js +10 -643
  37. package/dist/index116.cjs +1 -1
  38. package/dist/index116.js +6 -231
  39. package/dist/index117.cjs +1 -1
  40. package/dist/index117.js +17 -169
  41. package/dist/index118.cjs +1 -0
  42. package/dist/index118.js +7 -0
  43. package/dist/index12.cjs +1 -1
  44. package/dist/index12.js +136 -10
  45. package/dist/index13.cjs +1 -1
  46. package/dist/index13.js +15 -2
  47. package/dist/index14.cjs +1 -1
  48. package/dist/index14.js +2 -34
  49. package/dist/index15.cjs +1 -1
  50. package/dist/index15.js +32 -17
  51. package/dist/index16.cjs +1 -1
  52. package/dist/index16.js +14 -183
  53. package/dist/index17.cjs +1 -1
  54. package/dist/index17.js +187 -92
  55. package/dist/index18.cjs +1 -1
  56. package/dist/index18.js +92 -34
  57. package/dist/index19.cjs +1 -1
  58. package/dist/index19.js +36 -32
  59. package/dist/index20.cjs +1 -16
  60. package/dist/index20.js +30 -112
  61. package/dist/index21.cjs +16 -1
  62. package/dist/index21.js +113 -30
  63. package/dist/index22.cjs +1 -1
  64. package/dist/index22.js +31 -18
  65. package/dist/index23.cjs +1 -1
  66. package/dist/index23.js +41 -7
  67. package/dist/index24.cjs +1 -1
  68. package/dist/index24.js +3 -3
  69. package/dist/index25.cjs +1 -1
  70. package/dist/index25.js +23 -19
  71. package/dist/index26.cjs +1 -1
  72. package/dist/index26.js +6 -8
  73. package/dist/index27.cjs +1 -1
  74. package/dist/index27.js +12 -30
  75. package/dist/index28.cjs +1 -1
  76. package/dist/index28.js +15 -26
  77. package/dist/index29.cjs +1 -2
  78. package/dist/index29.js +5 -65
  79. package/dist/index30.cjs +1 -1
  80. package/dist/index30.js +13 -51
  81. package/dist/index31.cjs +1 -1
  82. package/dist/index31.js +10 -12
  83. package/dist/index32.cjs +1 -1
  84. package/dist/index32.js +12 -24
  85. package/dist/index33.cjs +1 -1
  86. package/dist/index33.js +11 -75
  87. package/dist/index34.cjs +1 -1
  88. package/dist/index34.js +13 -23
  89. package/dist/index35.cjs +1 -1
  90. package/dist/index35.js +23 -7
  91. package/dist/index36.cjs +1 -1
  92. package/dist/index36.js +55 -32
  93. package/dist/index37.cjs +1 -1
  94. package/dist/index37.js +16 -15
  95. package/dist/index38.cjs +1 -1
  96. package/dist/index38.js +6 -2
  97. package/dist/index39.cjs +1 -1
  98. package/dist/index39.js +8 -8
  99. package/dist/index4.cjs +1 -1
  100. package/dist/index4.js +2 -2
  101. package/dist/index40.cjs +1 -1
  102. package/dist/index40.js +171 -20
  103. package/dist/index41.cjs +1 -1
  104. package/dist/index41.js +100 -9
  105. package/dist/index42.cjs +1 -1
  106. package/dist/index42.js +20 -33
  107. package/dist/index43.cjs +1 -2
  108. package/dist/index43.js +17 -59
  109. package/dist/index44.cjs +1 -1
  110. package/dist/index44.js +8 -2
  111. package/dist/index45.cjs +1 -1
  112. package/dist/index45.js +21 -6
  113. package/dist/index46.cjs +1 -1
  114. package/dist/index46.js +8 -6
  115. package/dist/index47.cjs +1 -1
  116. package/dist/index47.js +31 -4
  117. package/dist/index48.cjs +1 -1
  118. package/dist/index48.js +26 -11
  119. package/dist/index49.cjs +2 -5
  120. package/dist/index49.js +53 -44
  121. package/dist/index50.cjs +1 -2
  122. package/dist/index50.js +50 -33
  123. package/dist/index51.cjs +1 -1
  124. package/dist/index51.js +12 -5
  125. package/dist/index52.cjs +1 -1
  126. package/dist/index52.js +24 -3
  127. package/dist/index53.cjs +1 -1
  128. package/dist/index53.js +75 -21
  129. package/dist/index54.cjs +1 -1
  130. package/dist/index54.js +7 -12
  131. package/dist/index55.cjs +1 -1
  132. package/dist/index55.js +32 -55
  133. package/dist/index56.cjs +1 -1
  134. package/dist/index56.js +15 -8
  135. package/dist/index57.cjs +1 -1
  136. package/dist/index57.js +2 -22
  137. package/dist/index58.cjs +1 -1
  138. package/dist/index58.js +8 -11
  139. package/dist/index59.cjs +1 -1
  140. package/dist/index59.js +20 -8
  141. package/dist/index6.cjs +1 -1
  142. package/dist/index6.js +40 -22
  143. package/dist/index60.cjs +1 -1
  144. package/dist/index60.js +11 -9
  145. package/dist/index61.cjs +1 -1
  146. package/dist/index61.js +34 -11
  147. package/dist/index62.cjs +1 -1
  148. package/dist/index62.js +40 -6
  149. package/dist/index63.cjs +1 -1
  150. package/dist/index63.js +34 -13
  151. package/dist/index64.cjs +1 -1
  152. package/dist/index64.js +68 -31
  153. package/dist/index65.cjs +1 -1
  154. package/dist/index65.js +112 -14
  155. package/dist/index66.cjs +1 -1
  156. package/dist/index66.js +64 -61
  157. package/dist/index67.cjs +1 -1
  158. package/dist/index67.js +2 -28
  159. package/dist/index68.cjs +1 -1
  160. package/dist/index68.js +17 -3
  161. package/dist/index69.cjs +1 -1
  162. package/dist/index69.js +223 -3
  163. package/dist/index7.cjs +1 -1
  164. package/dist/index7.js +24 -2
  165. package/dist/index70.cjs +1 -1
  166. package/dist/index70.js +231 -13
  167. package/dist/index71.cjs +2 -1
  168. package/dist/index71.js +59 -41
  169. package/dist/index72.cjs +1 -1
  170. package/dist/index72.js +21 -5
  171. package/dist/index73.cjs +1 -1
  172. package/dist/index73.js +4 -8
  173. package/dist/index74.cjs +1 -1
  174. package/dist/index74.js +3 -103
  175. package/dist/index75.cjs +1 -1
  176. package/dist/index75.js +8 -191
  177. package/dist/index76.cjs +1 -1
  178. package/dist/index76.js +102 -16
  179. package/dist/index77.cjs +1 -1
  180. package/dist/index77.js +16 -10
  181. package/dist/index78.cjs +1 -1
  182. package/dist/index78.js +8 -19
  183. package/dist/index79.cjs +1 -1
  184. package/dist/index79.js +9 -11
  185. package/dist/index8.cjs +1 -1
  186. package/dist/index8.js +2 -100
  187. package/dist/index80.cjs +1 -1
  188. package/dist/index80.js +11 -25
  189. package/dist/index81.cjs +1 -1
  190. package/dist/index81.js +13 -6
  191. package/dist/index82.cjs +1 -1
  192. package/dist/index82.js +18 -13
  193. package/dist/index83.cjs +1 -1
  194. package/dist/index83.js +6 -15
  195. package/dist/index84.cjs +1 -1
  196. package/dist/index84.js +42 -5
  197. package/dist/index85.cjs +1 -1
  198. package/dist/index85.js +78 -13
  199. package/dist/index86.cjs +1 -1
  200. package/dist/index86.js +14 -10
  201. package/dist/index87.cjs +1 -1
  202. package/dist/index87.js +18 -16
  203. package/dist/index88.cjs +1 -1
  204. package/dist/index88.js +182 -162
  205. package/dist/index89.cjs +1 -1
  206. package/dist/index89.js +62 -36
  207. package/dist/index9.cjs +1 -1
  208. package/dist/index9.js +105 -34
  209. package/dist/index91.cjs +1 -1
  210. package/dist/index91.js +2 -5
  211. package/dist/index92.cjs +1 -1
  212. package/dist/index92.js +6 -10
  213. package/dist/index93.cjs +1 -1
  214. package/dist/index93.js +12 -2
  215. package/dist/index94.cjs +5 -1
  216. package/dist/index94.js +49 -97
  217. package/dist/index95.cjs +2 -1
  218. package/dist/index95.js +33 -41
  219. package/dist/index96.cjs +1 -1
  220. package/dist/index96.js +5 -20
  221. package/dist/index97.cjs +1 -1
  222. package/dist/index97.js +3 -6
  223. package/dist/index98.cjs +1 -1
  224. package/dist/index98.js +7 -5
  225. package/dist/index99.cjs +1 -1
  226. package/dist/index99.js +30 -35
  227. package/dist/src/index.d.ts +1 -0
  228. package/dist/src/lib/auth/siwe/siwe.d.ts +3 -2
  229. package/dist/src/lib/digestKey/digestKey.d.ts +12 -0
  230. package/package.json +4 -1
package/dist/index88.js CHANGED
@@ -1,174 +1,194 @@
1
- import { InvalidLegacyVError as H } from "./index29.js";
2
- import { blobsToCommitments as g } from "./index59.js";
3
- import { blobsToProofs as B } from "./index60.js";
4
- import { commitmentsToVersionedHashes as V } from "./index61.js";
5
- import { toBlobSidecars as C } from "./index63.js";
6
- import { concatHex as h } from "./index76.js";
7
- import { trim as T } from "./index46.js";
8
- import { toHex as o, bytesToHex as k } from "./index24.js";
9
- import { toRlp as y } from "./index95.js";
10
- import { serializeAuthorizationList as w } from "./index104.js";
11
- import { assertTransactionEIP7702 as S, assertTransactionEIP4844 as _, assertTransactionEIP1559 as R, assertTransactionEIP2930 as Y, assertTransactionLegacy as j } from "./index102.js";
12
- import { getTransactionType as q } from "./index65.js";
13
- import { serializeAccessList as v } from "./index105.js";
14
- function te(e, r) {
15
- const i = q(e);
16
- return i === "eip1559" ? K(e, r) : i === "eip2930" ? M(e, r) : i === "eip4844" ? J(e, r) : i === "eip7702" ? D(e, r) : N(e, r);
1
+ import { AbiEncodingLengthMismatchError as y, InvalidAbiEncodingTypeError as u, InvalidArrayError as g, AbiEncodingArrayLengthMismatchError as l, AbiEncodingBytesSizeMismatchError as b } from "./index94.js";
2
+ import { InvalidAddressError as w } from "./index32.js";
3
+ import { BaseError as A } from "./index71.js";
4
+ import { IntegerOutOfRangeError as x } from "./index60.js";
5
+ import { isAddress as z } from "./index33.js";
6
+ import { concat as f } from "./index82.js";
7
+ import { padHex as d } from "./index61.js";
8
+ import { size as a } from "./index73.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 "./index101.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;
17
23
  }
18
- function D(e, r) {
19
- const { authorizationList: i, chainId: s, gas: n, nonce: c, to: f, value: a, maxFeePerGas: x, maxPriorityFeePerGas: t, accessList: p, data: l } = e;
20
- S(e);
21
- const d = v(p), m = w(i);
22
- return h([
23
- "0x04",
24
- y([
25
- o(s),
26
- c ? o(c) : "0x",
27
- t ? o(t) : "0x",
28
- x ? o(x) : "0x",
29
- n ? o(n) : "0x",
30
- f ?? "0x",
31
- a ? o(a) : "0x",
32
- l ?? "0x",
33
- d,
34
- m,
35
- ...I(e, r)
36
- ])
37
- ]);
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;
38
29
  }
39
- function J(e, r) {
40
- const { chainId: i, gas: s, nonce: n, to: c, value: f, maxFeePerBlobGas: a, maxFeePerGas: x, maxPriorityFeePerGas: t, accessList: p, data: l } = e;
41
- _(e);
42
- let d = e.blobVersionedHashes, m = e.sidecars;
43
- if (e.blobs && (typeof d > "u" || typeof m > "u")) {
44
- const u = typeof e.blobs[0] == "string" ? e.blobs : e.blobs.map((P) => k(P)), z = e.kzg, b = g({
45
- blobs: u,
46
- kzg: z
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)
47
49
  });
48
- if (typeof d > "u" && (d = V({
49
- commitments: b
50
- })), typeof m > "u") {
51
- const P = B({ blobs: u, commitments: b, kzg: z });
52
- m = C({ blobs: u, commitments: b, proofs: P });
53
- }
54
50
  }
55
- const L = v(p), E = [
56
- o(i),
57
- n ? o(n) : "0x",
58
- t ? o(t) : "0x",
59
- x ? o(x) : "0x",
60
- s ? o(s) : "0x",
61
- c ?? "0x",
62
- f ? o(f) : "0x",
63
- l ?? "0x",
64
- L,
65
- a ? o(a) : "0x",
66
- d ?? [],
67
- ...I(e, r)
68
- ], A = [], F = [], G = [];
69
- if (m)
70
- for (let u = 0; u < m.length; u++) {
71
- const { blob: z, commitment: b, proof: P } = m[u];
72
- A.push(z), F.push(b), G.push(P);
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
+ };
73
102
  }
74
- return h([
75
- "0x03",
76
- m ? (
77
- // If sidecars are enabled, envelope turns into a "wrapper":
78
- y([E, A, F, G])
79
- ) : (
80
- // If sidecars are disabled, standard envelope is used:
81
- y(E)
82
- )
83
- ]);
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" }) };
84
129
  }
85
- function K(e, r) {
86
- const { chainId: i, gas: s, nonce: n, to: c, value: f, maxFeePerGas: a, maxPriorityFeePerGas: x, accessList: t, data: p } = e;
87
- R(e);
88
- const l = v(t), d = [
89
- o(i),
90
- n ? o(n) : "0x",
91
- x ? o(x) : "0x",
92
- a ? o(a) : "0x",
93
- s ? o(s) : "0x",
94
- c ?? "0x",
95
- f ? o(f) : "0x",
96
- p ?? "0x",
97
- l,
98
- ...I(e, r)
99
- ];
100
- return h([
101
- "0x02",
102
- y(d)
103
- ]);
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)) };
104
134
  }
105
- function M(e, r) {
106
- const { chainId: i, gas: s, data: n, nonce: c, to: f, value: a, accessList: x, gasPrice: t } = e;
107
- Y(e);
108
- const p = v(x), l = [
109
- o(i),
110
- c ? o(c) : "0x",
111
- t ? o(t) : "0x",
112
- s ? o(s) : "0x",
113
- f ?? "0x",
114
- a ? o(a) : "0x",
115
- n ?? "0x",
116
- p,
117
- ...I(e, r)
118
- ];
119
- return h([
120
- "0x01",
121
- y(l)
122
- ]);
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
+ };
123
168
  }
124
- function N(e, r) {
125
- const { chainId: i = 0, gas: s, data: n, nonce: c, to: f, value: a, gasPrice: x } = e;
126
- j(e);
127
- let t = [
128
- c ? o(c) : "0x",
129
- x ? o(x) : "0x",
130
- s ? o(s) : "0x",
131
- f ?? "0x",
132
- a ? o(a) : "0x",
133
- n ?? "0x"
134
- ];
135
- if (r) {
136
- const p = (() => {
137
- if (r.v >= 35n)
138
- return (r.v - 35n) / 2n > 0 ? r.v : 27n + (r.v === 35n ? 0n : 1n);
139
- if (i > 0)
140
- return BigInt(i * 2) + BigInt(35n + r.v - 27n);
141
- const m = 27n + (r.v === 27n ? 0n : 1n);
142
- if (r.v !== m)
143
- throw new H({ v: r.v });
144
- return m;
145
- })(), l = T(r.r), d = T(r.s);
146
- t = [
147
- ...t,
148
- o(p),
149
- l === "0x00" ? "0x" : l,
150
- d === "0x00" ? "0x" : d
151
- ];
152
- } else i > 0 && (t = [
153
- ...t,
154
- o(i),
155
- "0x",
156
- "0x"
157
- ]);
158
- return y(t);
169
+ function H(e, { param: t }) {
170
+ let o = !1;
171
+ const n = [];
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);
178
+ }
179
+ return {
180
+ dynamic: o,
181
+ encoded: o ? h(n) : f(n.map(({ encoded: r }) => r))
182
+ };
159
183
  }
160
- function I(e, r) {
161
- const i = r ?? e, { v: s, yParity: n } = i;
162
- if (typeof i.r > "u")
163
- return [];
164
- if (typeof i.s > "u")
165
- return [];
166
- if (typeof s > "u" && typeof n > "u")
167
- return [];
168
- const c = T(i.r), f = T(i.s);
169
- return [typeof n == "number" ? n ? o(1) : "0x" : s === 0n ? "0x" : s === 1n ? o(1) : s === 27n ? "0x" : o(1), c === "0x00" ? "0x" : c, f === "0x00" ? "0x" : f];
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;
170
190
  }
171
191
  export {
172
- te as serializeTransaction,
173
- I as toYParitySignatureArray
192
+ K as encodeAbiParameters,
193
+ W as getArrayComponents
174
194
  };
package/dist/index89.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index79.cjs"),O=require("./index69.cjs"),n=require("./index47.cjs");function p(i,e,s,{strict:f}={}){return O.isHex(i,{strict:!1})?l(i,e,s,{strict:f}):u(i,e,s,{strict:f})}function r(i,e){if(typeof e=="number"&&e>0&&e>n.size(i)-1)throw new t.SliceOffsetOutOfBoundsError({offset:e,position:"start",size:n.size(i)})}function c(i,e,s){if(typeof e=="number"&&typeof s=="number"&&n.size(i)!==s-e)throw new t.SliceOffsetOutOfBoundsError({offset:s,position:"end",size:n.size(i)})}function u(i,e,s,{strict:f}={}){r(i,e);const o=i.slice(e,s);return f&&c(o,e,s),o}function l(i,e,s,{strict:f}={}){r(i,e);const o=`0x${i.replace("0x","").slice((e??0)*2,(s??i.length)*2)}`;return f&&c(o,e,s),o}exports.slice=p;exports.sliceBytes=u;exports.sliceHex=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./index94.cjs"),z=require("./index32.cjs"),o=require("./index100.cjs"),T=require("./index33.cjs"),u=require("./index73.cjs"),q=require("./index24.cjs"),g=require("./index101.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/index89.js CHANGED
@@ -1,41 +1,67 @@
1
- import { SliceOffsetOutOfBoundsError as t } from "./index79.js";
2
- import { isHex as p } from "./index69.js";
3
- import { size as r } from "./index47.js";
4
- function w(e, f, i, { strict: o } = {}) {
5
- return p(e, { strict: !1 }) ? u(e, f, i, {
6
- strict: o
7
- }) : m(e, f, i, {
8
- strict: o
9
- });
1
+ import { BytesSizeMismatchError as m } from "./index94.js";
2
+ import { InvalidAddressError as w } from "./index32.js";
3
+ import { InvalidDomainError as E, InvalidPrimaryTypeError as z, InvalidStructTypeError as D } from "./index100.js";
4
+ import { isAddress as T } from "./index33.js";
5
+ import { size as y } from "./index73.js";
6
+ import { numberToHex as x } from "./index24.js";
7
+ import { integerRegex as P, bytesRegex as S } from "./index101.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 });
10
44
  }
11
- function s(e, f) {
12
- if (typeof f == "number" && f > 0 && f > r(e) - 1)
13
- throw new t({
14
- offset: f,
15
- position: "start",
16
- size: r(e)
17
- });
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);
18
59
  }
19
- function c(e, f, i) {
20
- if (typeof f == "number" && typeof i == "number" && r(e) !== i - f)
21
- throw new t({
22
- offset: i,
23
- position: "end",
24
- size: r(e)
25
- });
26
- }
27
- function m(e, f, i, { strict: o } = {}) {
28
- s(e, f);
29
- const n = e.slice(f, i);
30
- return o && c(n, f, i), n;
31
- }
32
- function u(e, f, i, { strict: o } = {}) {
33
- s(e, f);
34
- const n = `0x${e.replace("0x", "").slice((f ?? 0) * 2, (i ?? e.length) * 2)}`;
35
- return o && c(n, f, i), n;
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 });
36
63
  }
37
64
  export {
38
- w as slice,
39
- m as sliceBytes,
40
- u as sliceHex
65
+ F as getTypesForEIP712Domain,
66
+ j as validateTypedData
41
67
  };
package/dist/index9.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index16.cjs"),l=require("./index7.cjs");class f{constructor(e){this.apiKey=e}async getToken(){const e=this.verifyToken();return e.error?t.Err(e.error):e.val?t.Ok(this.apiKey):t.Err("Token verification failed")}verifyToken(){const e=this.decodeBase64UrlSafe(this.apiKey),r=this.extractData(e);if(r.error)return t.Err(r.error);const{expiryTimestamp:i}=r.val;return i<new Date?t.Err("Token expired"):t.Ok(!0)}decodeBase64UrlSafe(e){let r=e.replace(/_/g,"/").replace(/-/g,"+");for(;r.length%4!==0;)r+="=";return Uint8Array.from(atob(r),i=>i.charCodeAt(0))}extractData(e){const r=new TextEncoder().encode("::"),i=e.findIndex((n,a)=>e.slice(a,a+r.length).every((u,d)=>u===r[d]));if(i===-1)return t.Err("Invalid format: delimiter not found");const o=e.slice(0,8),s=new DataView(o.buffer).getBigUint64(0,!1),c=e.slice(i+r.length);return t.Ok({expiryTimestamp:new Date(Number(s)*1e3),signature:Array.from(c).map(n=>n.toString(16).padStart(2,"0")).join("")})}async getAuthHeaders(){const e=await this.getToken();return e.ok?t.Ok({[l.AuthHeaderEnum.ApiKey]:e.val}):t.Err(e.error??"Failed to get auth token")}}exports.ApiKey=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("tough-cookie"),g=require("fetch-cookie"),n=require("./index17.cjs"),m=require("./index13.cjs"),k=require("./index14.cjs"),w=require("viem"),l=require("./index3.cjs"),y=require("./index20.cjs"),C=require("./index19.cjs"),T=require("./index21.cjs"),S=s=>s&&s.__esModule?s:{default:s},p=S(g);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 f.CookieJar;this.fetchWithCookies=p.default(fetch,r)}else this.fetchWithCookies=window.fetch.bind(window)}static fromDigestKey(t,i,e){const r=w.createWalletClient({account:C.privateKeyToAccount(l.add0x(i.digestKey)),transport:w.http(),chain:y.mainnet});return new d(t,r,e)}verifyToken(t,i){try{const e=l.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 r;if(!((r=this.walletClient.account)!=null&&r.address))return n.Err("Wallet client does not have an account");const t=await this.signStatement();if(t.error)return n.Err(t.error);let i;try{const o=await(await this.fetchWithCookies(this.url.endpoint("tokens"),{method:"POST",body:JSON.stringify({...t.val}),headers:{"Content-Type":"application/json"},credentials:"include"})).json();if(o.error||!o.result)return n.Err(o.error??"Failed to get token");i=o.result}catch(a){return n.Err("Failed to get token",a)}if(!this.verifyToken(i,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(k.StoreKeys.AUTH_TOKEN,i),n.Ok(i)}async signStatement(){var h;if(!((h=this.walletClient.account)!=null&&h.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 c=await(await this.fetchWithCookies(this.url.endpoint("challenges"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"})).json();if(c.error||!c.result)return n.Err("Failed to get nonce");e=c.result}catch(u){return n.Err("Failed to get nonce",u)}const r=await this.walletClient.getChainId(),a=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:a});return n.Ok({message:a,signature:o,nonce:e})}async getAuthHeaders(){const t=await this.getToken();return t.error?n.Err(t.error):n.Ok({Authorization:l.Authorization(t.val)})}}exports.Siwe=d;
package/dist/index9.js CHANGED
@@ -1,46 +1,117 @@
1
- import { Err as i, Ok as n } from "./index16.js";
2
- import { AuthHeaderEnum as u } from "./index7.js";
3
- class h {
4
- constructor(e) {
5
- this.apiKey = e;
1
+ import { CookieJar as f } from "tough-cookie";
2
+ import m from "fetch-cookie";
3
+ import { Ok as a, Err as r } from "./index17.js";
4
+ import { MemoryStorage as u } from "./index13.js";
5
+ import { StoreKeys as w } from "./index14.js";
6
+ import { createWalletClient as g, http as p } from "viem";
7
+ import { add0x as k, parseJwt as y, Authorization as C } from "./index3.js";
8
+ import { mainnet as T } from "./index20.js";
9
+ import { privateKeyToAccount as v } from "./index19.js";
10
+ import { createSiweMessage as S } from "./index21.js";
11
+ class d {
12
+ constructor(e, n, t) {
13
+ if (this.url = e.endpoint("siwe"), this.walletClient = n, this.domain = (t == null ? void 0 : t.domain) || "app.garden.finance", this.domain.startsWith("https://") && (this.domain = this.domain.split("https://")[1]), this.signingStatement = (t == null ? void 0 : t.signingStatement) ?? "Garden.fi", this.store = (t == null ? void 0 : t.store) ?? (typeof window < "u" ? window.localStorage : new u()), typeof window > "u") {
14
+ const i = new f();
15
+ this.fetchWithCookies = m(fetch, i);
16
+ } else
17
+ this.fetchWithCookies = window.fetch.bind(window);
6
18
  }
7
- async getToken() {
8
- const e = this.verifyToken();
9
- return e.error ? i(e.error) : e.val ? n(this.apiKey) : i("Token verification failed");
19
+ static fromDigestKey(e, n, t) {
20
+ const i = g({
21
+ account: v(k(n.digestKey)),
22
+ transport: p(),
23
+ chain: T
24
+ });
25
+ return new d(e, i, t);
10
26
  }
11
- verifyToken() {
12
- const e = this.decodeBase64UrlSafe(this.apiKey), r = this.extractData(e);
13
- if (r.error)
14
- return i(r.error);
15
- const { expiryTimestamp: t } = r.val;
16
- return t < /* @__PURE__ */ new Date() ? i("Token expired") : n(!0);
27
+ verifyToken(e, n) {
28
+ try {
29
+ const t = y(e);
30
+ if (!t) return a(!1);
31
+ const i = Math.floor(Date.now() / 1e3) + 120;
32
+ return a(
33
+ t.exp > i && t.user_id.toLowerCase() === n.toLowerCase()
34
+ );
35
+ } catch {
36
+ return a(!1);
37
+ }
17
38
  }
18
- decodeBase64UrlSafe(e) {
19
- let r = e.replace(/_/g, "/").replace(/-/g, "+");
20
- for (; r.length % 4 !== 0; )
21
- r += "=";
22
- return Uint8Array.from(atob(r), (t) => t.charCodeAt(0));
39
+ async getToken() {
40
+ var i;
41
+ if (!((i = this.walletClient.account) != null && i.address))
42
+ return r("Wallet client does not have an account");
43
+ const e = await this.signStatement();
44
+ if (e.error)
45
+ return r(e.error);
46
+ let n;
47
+ try {
48
+ const o = await (await this.fetchWithCookies(
49
+ this.url.endpoint("tokens"),
50
+ {
51
+ method: "POST",
52
+ body: JSON.stringify({
53
+ ...e.val
54
+ }),
55
+ headers: {
56
+ "Content-Type": "application/json"
57
+ },
58
+ credentials: "include"
59
+ }
60
+ )).json();
61
+ if (o.error || !o.result)
62
+ return r(o.error ?? "Failed to get token");
63
+ n = o.result;
64
+ } catch (s) {
65
+ return r("Failed to get token", s);
66
+ }
67
+ if (!this.verifyToken(n, this.walletClient.account.address).val)
68
+ throw new Error("Token verification failed");
69
+ return this.store.setItem(w.AUTH_TOKEN, n), a(n);
23
70
  }
24
- extractData(e) {
25
- const r = new TextEncoder().encode("::"), t = e.findIndex(
26
- (a, o) => e.slice(o, o + r.length).every((f, l) => f === r[l])
27
- );
28
- if (t === -1)
29
- return i("Invalid format: delimiter not found");
30
- const s = e.slice(0, 8), c = new DataView(s.buffer).getBigUint64(
31
- 0,
32
- !1
33
- ), d = e.slice(t + r.length);
34
- return n({
35
- expiryTimestamp: new Date(Number(c) * 1e3),
36
- signature: Array.from(d).map((a) => a.toString(16).padStart(2, "0")).join("")
71
+ async signStatement() {
72
+ var l;
73
+ if (!((l = this.walletClient.account) != null && l.address))
74
+ return r("Wallet client does not have a valid account");
75
+ const e = /* @__PURE__ */ new Date(), n = new Date(e.getTime() + 300 * 1e3);
76
+ let t;
77
+ try {
78
+ const c = await (await this.fetchWithCookies(this.url.endpoint("challenges"), {
79
+ method: "POST",
80
+ headers: {
81
+ "Content-Type": "application/json"
82
+ },
83
+ credentials: "include"
84
+ })).json();
85
+ if (c.error || !c.result)
86
+ return r("Failed to get nonce");
87
+ t = c.result;
88
+ } catch (h) {
89
+ return r("Failed to get nonce", h);
90
+ }
91
+ const i = await this.walletClient.getChainId(), s = S({
92
+ domain: this.domain,
93
+ address: this.walletClient.account.address,
94
+ statement: this.signingStatement,
95
+ nonce: t,
96
+ uri: "https://" + this.domain,
97
+ version: "1",
98
+ chainId: i,
99
+ notBefore: n
100
+ }), o = await this.walletClient.signMessage({
101
+ account: this.walletClient.account,
102
+ message: s
103
+ });
104
+ return a({
105
+ message: s,
106
+ signature: o,
107
+ nonce: t
37
108
  });
38
109
  }
39
110
  async getAuthHeaders() {
40
111
  const e = await this.getToken();
41
- return e.ok ? n({ [u.ApiKey]: e.val }) : i(e.error ?? "Failed to get auth token");
112
+ return e.error ? r(e.error) : a({ Authorization: C(e.val) });
42
113
  }
43
114
  }
44
115
  export {
45
- h as ApiKey
116
+ d as Siwe
46
117
  };
package/dist/index91.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={ether:-9,wei:9};exports.gweiUnits=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="2.26.3";exports.version=e;