@gardenfi/utils 2.0.4 → 2.0.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.
Files changed (237) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +33 -24
  3. package/dist/index10.cjs +1 -1
  4. package/dist/index10.js +24 -32
  5. package/dist/index100.cjs +1 -0
  6. package/dist/index100.js +130 -0
  7. package/dist/index101.cjs +1 -0
  8. package/dist/index101.js +115 -0
  9. package/dist/index102.cjs +1 -0
  10. package/dist/index102.js +81 -0
  11. package/dist/index103.cjs +1 -0
  12. package/dist/index103.js +4 -0
  13. package/dist/index104.cjs +1 -0
  14. package/dist/index104.js +20 -0
  15. package/dist/index105.cjs +1 -0
  16. package/dist/index105.js +21 -0
  17. package/dist/index106.cjs +1 -0
  18. package/dist/index106.js +19 -0
  19. package/dist/index107.cjs +1 -0
  20. package/dist/index107.js +226 -0
  21. package/dist/index108.cjs +2 -0
  22. package/dist/index108.js +5 -0
  23. package/dist/index109.cjs +1 -0
  24. package/dist/index109.js +37 -0
  25. package/dist/index11.cjs +1 -1
  26. package/dist/index11.js +136 -14
  27. package/dist/index110.cjs +1 -0
  28. package/dist/index110.js +21 -0
  29. package/dist/index111.cjs +1 -0
  30. package/dist/index111.js +72 -0
  31. package/dist/index112.cjs +1 -0
  32. package/dist/index112.js +70 -0
  33. package/dist/index113.cjs +1 -0
  34. package/dist/index113.js +4 -0
  35. package/dist/index114.cjs +1 -0
  36. package/dist/index114.js +43 -0
  37. package/dist/index115.cjs +1 -0
  38. package/dist/index115.js +646 -0
  39. package/dist/index116.cjs +1 -0
  40. package/dist/index116.js +234 -0
  41. package/dist/index117.cjs +1 -0
  42. package/dist/index117.js +175 -0
  43. package/dist/index12.cjs +1 -1
  44. package/dist/index12.js +9 -182
  45. package/dist/index13.cjs +1 -1
  46. package/dist/index13.js +2 -94
  47. package/dist/index14.cjs +1 -16
  48. package/dist/index14.js +32 -112
  49. package/dist/index15.cjs +1 -1
  50. package/dist/index15.js +18 -31
  51. package/dist/index16.cjs +1 -1
  52. package/dist/index16.js +188 -31
  53. package/dist/index17.cjs +1 -1
  54. package/dist/index17.js +93 -17
  55. package/dist/index18.cjs +1 -1
  56. package/dist/index18.js +35 -7
  57. package/dist/index19.cjs +1 -1
  58. package/dist/index19.js +31 -20
  59. package/dist/index20.cjs +16 -1
  60. package/dist/index20.js +113 -21
  61. package/dist/index21.cjs +1 -1
  62. package/dist/index21.js +31 -9
  63. package/dist/index22.cjs +1 -1
  64. package/dist/index22.js +17 -31
  65. package/dist/index23.cjs +1 -1
  66. package/dist/index23.js +7 -26
  67. package/dist/index24.cjs +1 -1
  68. package/dist/index24.js +41 -19
  69. package/dist/index25.cjs +1 -1
  70. package/dist/index25.js +19 -49
  71. package/dist/index26.cjs +1 -1
  72. package/dist/index26.js +8 -12
  73. package/dist/index27.cjs +1 -1
  74. package/dist/index27.js +30 -23
  75. package/dist/index28.cjs +1 -1
  76. package/dist/index28.js +25 -74
  77. package/dist/index29.cjs +2 -1
  78. package/dist/index29.js +62 -20
  79. package/dist/index3.cjs +1 -1
  80. package/dist/index3.js +30 -7
  81. package/dist/index30.cjs +1 -1
  82. package/dist/index30.js +51 -7
  83. package/dist/index31.cjs +1 -1
  84. package/dist/index31.js +12 -32
  85. package/dist/index32.cjs +1 -1
  86. package/dist/index32.js +24 -15
  87. package/dist/index33.cjs +1 -1
  88. package/dist/index33.js +76 -2
  89. package/dist/index34.cjs +1 -1
  90. package/dist/index34.js +23 -8
  91. package/dist/index35.cjs +1 -1
  92. package/dist/index35.js +7 -20
  93. package/dist/index36.cjs +1 -1
  94. package/dist/index36.js +32 -12
  95. package/dist/index37.cjs +1 -1
  96. package/dist/index37.js +15 -34
  97. package/dist/index38.cjs +1 -2
  98. package/dist/index38.js +2 -60
  99. package/dist/index39.cjs +1 -1
  100. package/dist/index39.js +9 -2
  101. package/dist/index4.cjs +1 -1
  102. package/dist/index4.js +2 -2
  103. package/dist/index40.cjs +1 -1
  104. package/dist/index40.js +20 -4
  105. package/dist/index41.cjs +1 -1
  106. package/dist/index41.js +12 -11
  107. package/dist/index42.cjs +1 -1
  108. package/dist/index42.js +34 -3
  109. package/dist/index43.cjs +2 -1
  110. package/dist/index43.js +58 -20
  111. package/dist/index44.cjs +1 -1
  112. package/dist/index44.js +2 -13
  113. package/dist/index45.cjs +1 -1
  114. package/dist/index45.js +5 -54
  115. package/dist/index46.cjs +1 -1
  116. package/dist/index46.js +6 -6
  117. package/dist/index47.cjs +1 -1
  118. package/dist/index47.js +4 -21
  119. package/dist/index48.cjs +1 -1
  120. package/dist/index48.js +11 -11
  121. package/dist/index49.cjs +5 -1
  122. package/dist/index49.js +56 -3
  123. package/dist/index50.cjs +2 -1
  124. package/dist/index50.js +32 -9
  125. package/dist/index51.cjs +1 -1
  126. package/dist/index51.js +5 -19
  127. package/dist/index52.cjs +1 -1
  128. package/dist/index52.js +3 -6
  129. package/dist/index53.cjs +1 -1
  130. package/dist/index53.js +21 -8
  131. package/dist/index54.cjs +1 -1
  132. package/dist/index54.js +11 -103
  133. package/dist/index55.cjs +1 -1
  134. package/dist/index55.js +51 -24
  135. package/dist/index56.cjs +1 -1
  136. package/dist/index56.js +8 -18
  137. package/dist/index57.cjs +1 -1
  138. package/dist/index57.js +20 -37
  139. package/dist/index58.cjs +1 -0
  140. package/dist/index58.js +14 -0
  141. package/dist/index59.cjs +1 -0
  142. package/dist/index59.js +11 -0
  143. package/dist/index60.cjs +1 -0
  144. package/dist/index60.js +13 -0
  145. package/dist/index61.cjs +1 -0
  146. package/dist/index61.js +14 -0
  147. package/dist/index62.cjs +1 -0
  148. package/dist/index62.js +9 -0
  149. package/dist/index63.cjs +1 -0
  150. package/dist/index63.js +16 -0
  151. package/dist/index64.cjs +1 -0
  152. package/dist/index64.js +35 -0
  153. package/dist/index65.cjs +1 -0
  154. package/dist/index65.js +17 -0
  155. package/dist/index66.cjs +1 -0
  156. package/dist/index66.js +67 -0
  157. package/dist/index67.cjs +1 -0
  158. package/dist/index67.js +30 -0
  159. package/dist/index68.cjs +1 -0
  160. package/dist/index68.js +5 -0
  161. package/dist/index69.cjs +1 -0
  162. package/dist/index69.js +6 -0
  163. package/dist/index7.cjs +1 -1
  164. package/dist/index7.js +2 -109
  165. package/dist/index70.cjs +1 -0
  166. package/dist/index70.js +16 -0
  167. package/dist/index71.cjs +1 -0
  168. package/dist/index71.js +44 -0
  169. package/dist/index72.cjs +1 -0
  170. package/dist/index72.js +8 -0
  171. package/dist/index73.cjs +1 -0
  172. package/dist/index73.js +11 -0
  173. package/dist/index74.cjs +1 -0
  174. package/dist/index74.js +106 -0
  175. package/dist/index75.cjs +1 -0
  176. package/dist/index75.js +194 -0
  177. package/dist/index76.cjs +1 -0
  178. package/dist/index76.js +21 -0
  179. package/dist/index77.cjs +1 -0
  180. package/dist/index77.js +14 -0
  181. package/dist/index78.cjs +1 -0
  182. package/dist/index78.js +22 -0
  183. package/dist/index79.cjs +1 -0
  184. package/dist/index79.js +15 -0
  185. package/dist/index8.cjs +1 -1
  186. package/dist/index8.js +95 -10
  187. package/dist/index80.cjs +1 -0
  188. package/dist/index80.js +28 -0
  189. package/dist/index81.cjs +1 -0
  190. package/dist/index81.js +9 -0
  191. package/dist/index82.cjs +1 -0
  192. package/dist/index82.js +16 -0
  193. package/dist/index83.cjs +1 -0
  194. package/dist/index83.js +18 -0
  195. package/dist/index84.cjs +1 -0
  196. package/dist/index84.js +8 -0
  197. package/dist/index85.cjs +1 -0
  198. package/dist/index85.js +16 -0
  199. package/dist/index86.cjs +1 -0
  200. package/dist/index86.js +13 -0
  201. package/dist/index87.cjs +1 -0
  202. package/dist/index87.js +19 -0
  203. package/dist/index88.cjs +1 -0
  204. package/dist/index88.js +174 -0
  205. package/dist/index89.cjs +1 -0
  206. package/dist/index89.js +41 -0
  207. package/dist/index9.cjs +1 -1
  208. package/dist/index9.js +44 -2
  209. package/dist/index90.cjs +1 -0
  210. package/dist/index90.js +11 -0
  211. package/dist/index91.cjs +1 -0
  212. package/dist/index91.js +7 -0
  213. package/dist/index92.cjs +1 -0
  214. package/dist/index92.js +13 -0
  215. package/dist/index93.cjs +1 -0
  216. package/dist/index93.js +4 -0
  217. package/dist/index94.cjs +1 -0
  218. package/dist/index94.js +107 -0
  219. package/dist/index95.cjs +1 -0
  220. package/dist/index95.js +45 -0
  221. package/dist/index96.cjs +1 -0
  222. package/dist/index96.js +23 -0
  223. package/dist/index97.cjs +1 -0
  224. package/dist/index97.js +9 -0
  225. package/dist/index98.cjs +1 -0
  226. package/dist/index98.js +7 -0
  227. package/dist/index99.cjs +1 -0
  228. package/dist/index99.js +40 -0
  229. package/dist/src/lib/auth/apikey/apikey.d.ts +12 -0
  230. package/dist/src/lib/auth/auth.types.d.ts +21 -8
  231. package/dist/src/lib/auth/index.d.ts +5 -1
  232. package/dist/src/lib/auth/passkey/passkey.d.ts +10 -0
  233. package/dist/src/lib/auth/passkey/passkey.types.d.ts +17 -0
  234. package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +37 -0
  235. package/dist/src/lib/auth/{siwe.d.ts → siwe/siwe.d.ts} +4 -15
  236. package/dist/src/lib/utils.d.ts +3 -0
  237. package/package.json +2 -1
package/dist/index55.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function i(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function n(e,...t){if(!i(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function s(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function a(e,t){n(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}exports.abytes=n;exports.aexists=s;exports.anumber=o;exports.aoutput=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index43.cjs"),l=require("./index69.cjs"),u=require("./index42.cjs"),f=require("./index34.cjs"),m=require("./index24.cjs"),h=new TextEncoder;function A(e,n={}){return typeof e=="number"||typeof e=="bigint"?B(e,n):typeof e=="boolean"?x(e,n):l.isHex(e)?c(e,n):T(e,n)}function x(e,n={}){const t=new Uint8Array(1);return t[0]=Number(e),typeof n.size=="number"?(f.assertSize(t,{size:n.size}),u.pad(t,{size:n.size})):t}const i={zero:48,nine:57,A:65,F:70,a:97,f:102};function g(e){if(e>=i.zero&&e<=i.nine)return e-i.zero;if(e>=i.A&&e<=i.F)return e-(i.A-10);if(e>=i.a&&e<=i.f)return e-(i.a-10)}function c(e,n={}){let t=e;n.size&&(f.assertSize(t,{size:n.size}),t=u.pad(t,{dir:"right",size:n.size}));let r=t.slice(2);r.length%2&&(r=`0${r}`);const d=r.length/2,y=new Uint8Array(d);for(let s=0,o=0;s<d;s++){const b=g(r.charCodeAt(o++)),z=g(r.charCodeAt(o++));if(b===void 0||z===void 0)throw new a.BaseError(`Invalid byte sequence ("${r[o-2]}${r[o-1]}" in "${r}").`);y[s]=b*16+z}return y}function B(e,n){const t=m.numberToHex(e,n);return c(t)}function T(e,n={}){const t=h.encode(e);return typeof n.size=="number"?(f.assertSize(t,{size:n.size}),u.pad(t,{dir:"right",size:n.size})):t}exports.boolToBytes=x;exports.hexToBytes=c;exports.numberToBytes=B;exports.stringToBytes=T;exports.toBytes=A;
package/dist/index55.js CHANGED
@@ -1,31 +1,58 @@
1
- function i(e) {
2
- if (!Number.isSafeInteger(e) || e < 0)
3
- throw new Error("positive integer expected, got " + e);
1
+ import { BaseError as g } from "./index43.js";
2
+ import { isHex as x } from "./index69.js";
3
+ import { pad as s } from "./index42.js";
4
+ import { assertSize as u } from "./index34.js";
5
+ import { numberToHex as h } from "./index24.js";
6
+ const A = /* @__PURE__ */ new TextEncoder();
7
+ function F(e, n = {}) {
8
+ return typeof e == "number" || typeof e == "bigint" ? T(e, n) : typeof e == "boolean" ? B(e, n) : x(e) ? y(e, n) : l(e, n);
4
9
  }
5
- function n(e) {
6
- return e instanceof Uint8Array || ArrayBuffer.isView(e) && e.constructor.name === "Uint8Array";
10
+ function B(e, n = {}) {
11
+ const r = new Uint8Array(1);
12
+ return r[0] = Number(e), typeof n.size == "number" ? (u(r, { size: n.size }), s(r, { size: n.size })) : r;
7
13
  }
8
- function o(e, ...t) {
9
- if (!n(e))
10
- throw new Error("Uint8Array expected");
11
- if (t.length > 0 && !t.includes(e.length))
12
- throw new Error("Uint8Array expected of length " + t + ", got length=" + e.length);
14
+ const t = {
15
+ zero: 48,
16
+ nine: 57,
17
+ A: 65,
18
+ F: 70,
19
+ a: 97,
20
+ f: 102
21
+ };
22
+ function m(e) {
23
+ if (e >= t.zero && e <= t.nine)
24
+ return e - t.zero;
25
+ if (e >= t.A && e <= t.F)
26
+ return e - (t.A - 10);
27
+ if (e >= t.a && e <= t.f)
28
+ return e - (t.a - 10);
29
+ }
30
+ function y(e, n = {}) {
31
+ let r = e;
32
+ n.size && (u(r, { size: n.size }), r = s(r, { dir: "right", size: n.size }));
33
+ let i = r.slice(2);
34
+ i.length % 2 && (i = `0${i}`);
35
+ const z = i.length / 2, d = new Uint8Array(z);
36
+ for (let f = 0, o = 0; f < z; f++) {
37
+ const b = m(i.charCodeAt(o++)), c = m(i.charCodeAt(o++));
38
+ if (b === void 0 || c === void 0)
39
+ throw new g(`Invalid byte sequence ("${i[o - 2]}${i[o - 1]}" in "${i}").`);
40
+ d[f] = b * 16 + c;
41
+ }
42
+ return d;
13
43
  }
14
- function s(e, t = !0) {
15
- if (e.destroyed)
16
- throw new Error("Hash instance has been destroyed");
17
- if (t && e.finished)
18
- throw new Error("Hash#digest() has already been called");
44
+ function T(e, n) {
45
+ const r = h(e, n);
46
+ return y(r);
19
47
  }
20
- function f(e, t) {
21
- o(e);
22
- const r = t.outputLen;
23
- if (e.length < r)
24
- throw new Error("digestInto() expects output buffer of length at least " + r);
48
+ function l(e, n = {}) {
49
+ const r = A.encode(e);
50
+ return typeof n.size == "number" ? (u(r, { size: n.size }), s(r, { dir: "right", size: n.size })) : r;
25
51
  }
26
52
  export {
27
- o as abytes,
28
- s as aexists,
29
- i as anumber,
30
- f as aoutput
53
+ B as boolToBytes,
54
+ y as hexToBytes,
55
+ T as numberToBytes,
56
+ l as stringToBytes,
57
+ F as toBytes
31
58
  };
package/dist/index56.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=BigInt(2**32-1),i=BigInt(32);function u(t,e=!1){return e?{h:Number(t&n),l:Number(t>>i&n)}:{h:Number(t>>i&n)|0,l:Number(t&n)|0}}function g(t,e=!1){let r=new Uint32Array(t.length),l=new Uint32Array(t.length);for(let o=0;o<t.length;o++){const{h:c,l:f}=u(t[o],e);[r[o],l[o]]=[c,f]}return[r,l]}const B=(t,e,r)=>t<<r|e>>>32-r,h=(t,e,r)=>e<<r|t>>>32-r,m=(t,e,r)=>e<<r-32|t>>>64-r,S=(t,e,r)=>t<<r-32|e>>>64-r;exports.fromBig=u;exports.rotlBH=m;exports.rotlBL=S;exports.rotlSH=B;exports.rotlSL=h;exports.split=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index94.cjs"),o=require("./index69.cjs"),i=require("./index55.cjs"),n=require("./index24.cjs");function u(e,r){const s=r||"hex",t=c.keccak_256(o.isHex(e,{strict:!1})?i.toBytes(e):e);return s==="bytes"?t:n.toHex(t)}exports.keccak256=u;
package/dist/index56.js CHANGED
@@ -1,21 +1,11 @@
1
- const o = /* @__PURE__ */ BigInt(4294967295), i = /* @__PURE__ */ BigInt(32);
2
- function f(t, r = !1) {
3
- return r ? { h: Number(t & o), l: Number(t >> i & o) } : { h: Number(t >> i & o) | 0, l: Number(t & o) | 0 };
1
+ import { keccak_256 as c } from "./index94.js";
2
+ import { isHex as i } from "./index69.js";
3
+ import { toBytes as m } from "./index55.js";
4
+ import { toHex as s } from "./index24.js";
5
+ function x(t, r) {
6
+ const e = r || "hex", o = c(i(t, { strict: !1 }) ? m(t) : t);
7
+ return e === "bytes" ? o : s(o);
4
8
  }
5
- function h(t, r = !1) {
6
- let n = new Uint32Array(t.length), l = new Uint32Array(t.length);
7
- for (let e = 0; e < t.length; e++) {
8
- const { h: c, l: u } = f(t[e], r);
9
- [n[e], l[e]] = [c, u];
10
- }
11
- return [n, l];
12
- }
13
- const g = (t, r, n) => t << n | r >>> 32 - n, m = (t, r, n) => r << n | t >>> 32 - n, A = (t, r, n) => r << n - 32 | t >>> 64 - n, B = (t, r, n) => t << n - 32 | r >>> 64 - n;
14
9
  export {
15
- f as fromBig,
16
- A as rotlBH,
17
- B as rotlBL,
18
- g as rotlSH,
19
- m as rotlSL,
20
- h as split
10
+ x as keccak256
21
11
  };
package/dist/index57.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index55.cjs");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function c(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}const s=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function o(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function y(t){for(let e=0;e<t.length;e++)t[e]=o(t[e])}function r(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function f(t){return typeof t=="string"&&(t=r(t)),i.abytes(t),t}class p{clone(){return this._cloneInto()}}function b(t){const e=u=>t().update(f(u)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}exports.Hash=p;exports.byteSwap=o;exports.byteSwap32=y;exports.isLE=s;exports.toBytes=f;exports.u32=c;exports.utf8ToBytes=r;exports.wrapConstructor=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class i extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&t!==void 0&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const s=this.keys().next().value;s&&this.delete(s)}return this}}exports.LruMap=i;
package/dist/index57.js CHANGED
@@ -1,41 +1,24 @@
1
- import { abytes as o } from "./index55.js";
2
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
- function y(t) {
4
- return new Uint32Array(t.buffer, t.byteOffset, Math.floor(t.byteLength / 4));
5
- }
6
- const p = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
7
- function r(t) {
8
- return t << 24 & 4278190080 | t << 8 & 16711680 | t >>> 8 & 65280 | t >>> 24 & 255;
9
- }
10
- function s(t) {
11
- for (let e = 0; e < t.length; e++)
12
- t[e] = r(t[e]);
13
- }
14
- function u(t) {
15
- if (typeof t != "string")
16
- throw new Error("utf8ToBytes expected string, got " + typeof t);
17
- return new Uint8Array(new TextEncoder().encode(t));
18
- }
19
- function i(t) {
20
- return typeof t == "string" && (t = u(t)), o(t), t;
21
- }
22
- class b {
23
- // Safe version that clones internal state
24
- clone() {
25
- return this._cloneInto();
1
+ class r extends Map {
2
+ constructor(e) {
3
+ super(), Object.defineProperty(this, "maxSize", {
4
+ enumerable: !0,
5
+ configurable: !0,
6
+ writable: !0,
7
+ value: void 0
8
+ }), this.maxSize = e;
9
+ }
10
+ get(e) {
11
+ const t = super.get(e);
12
+ return super.has(e) && t !== void 0 && (this.delete(e), super.set(e, t)), t;
13
+ }
14
+ set(e, t) {
15
+ if (super.set(e, t), this.maxSize && this.size > this.maxSize) {
16
+ const s = this.keys().next().value;
17
+ s && this.delete(s);
18
+ }
19
+ return this;
26
20
  }
27
- }
28
- function x(t) {
29
- const e = (f) => t().update(i(f)).digest(), n = t();
30
- return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
31
21
  }
32
22
  export {
33
- b as Hash,
34
- r as byteSwap,
35
- s as byteSwap32,
36
- p as isLE,
37
- i as toBytes,
38
- y as u32,
39
- u as utf8ToBytes,
40
- x as wrapConstructor
23
+ r as LruMap
41
24
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index57.cjs"),i=require("./index53.cjs"),o=/^0x[a-fA-F0-9]{40}$/,t=new c.LruMap(8192);function f(e,n){const{strict:s=!0}=n??{},r=`${e}.${s}`;if(t.has(r))return t.get(r);const u=o.test(e)?e.toLowerCase()===e?!0:s?i.checksumAddress(e)===e:!0:!1;return t.set(r,u),u}exports.isAddress=f;exports.isAddressCache=t;
@@ -0,0 +1,14 @@
1
+ import { LruMap as u } from "./index57.js";
2
+ import { checksumAddress as c } from "./index53.js";
3
+ const i = /^0x[a-fA-F0-9]{40}$/, r = /* @__PURE__ */ new u(8192);
4
+ function h(t, s) {
5
+ const { strict: n = !0 } = s ?? {}, e = `${t}.${n}`;
6
+ if (r.has(e))
7
+ return r.get(e);
8
+ const o = i.test(t) ? t.toLowerCase() === t ? !0 : n ? c(t) === t : !0 : !1;
9
+ return r.set(e, o), o;
10
+ }
11
+ export {
12
+ h as isAddress,
13
+ r as isAddressCache
14
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index55.cjs"),l=require("./index24.cjs");function c(o){const{kzg:s}=o,n=o.to??(typeof o.blobs[0]=="string"?"hex":"bytes"),e=typeof o.blobs[0]=="string"?o.blobs.map(t=>i.hexToBytes(t)):o.blobs,b=[];for(const t of e)b.push(Uint8Array.from(s.blobToKzgCommitment(t)));return n==="bytes"?b:b.map(t=>l.bytesToHex(t))}exports.blobsToCommitments=c;
@@ -0,0 +1,11 @@
1
+ import { hexToBytes as i } from "./index55.js";
2
+ import { bytesToHex as f } from "./index24.js";
3
+ function y(o) {
4
+ const { kzg: s } = o, n = o.to ?? (typeof o.blobs[0] == "string" ? "hex" : "bytes"), m = typeof o.blobs[0] == "string" ? o.blobs.map((t) => i(t)) : o.blobs, b = [];
5
+ for (const t of m)
6
+ b.push(Uint8Array.from(s.blobToKzgCommitment(t)));
7
+ return n === "bytes" ? b : b.map((t) => f(t));
8
+ }
9
+ export {
10
+ y as blobsToCommitments
11
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./index55.cjs"),y=require("./index24.cjs");function f(t){const{kzg:c}=t,e=t.to??(typeof t.blobs[0]=="string"?"hex":"bytes"),n=typeof t.blobs[0]=="string"?t.blobs.map(o=>b.hexToBytes(o)):t.blobs,i=typeof t.commitments[0]=="string"?t.commitments.map(o=>b.hexToBytes(o)):t.commitments,s=[];for(let o=0;o<n.length;o++){const l=n[o],m=i[o];s.push(Uint8Array.from(c.computeBlobKzgProof(l,m)))}return e==="bytes"?s:s.map(o=>y.bytesToHex(o))}exports.blobsToProofs=f;
@@ -0,0 +1,13 @@
1
+ import { hexToBytes as b } from "./index55.js";
2
+ import { bytesToHex as y } from "./index24.js";
3
+ function h(t) {
4
+ const { kzg: m } = t, c = t.to ?? (typeof t.blobs[0] == "string" ? "hex" : "bytes"), s = typeof t.blobs[0] == "string" ? t.blobs.map((o) => b(o)) : t.blobs, i = typeof t.commitments[0] == "string" ? t.commitments.map((o) => b(o)) : t.commitments, n = [];
5
+ for (let o = 0; o < s.length; o++) {
6
+ const f = s[o], l = i[o];
7
+ n.push(Uint8Array.from(m.computeBlobKzgProof(f, l)));
8
+ }
9
+ return c === "bytes" ? n : n.map((o) => y(o));
10
+ }
11
+ export {
12
+ h as blobsToProofs
13
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index62.cjs");function c(o){const{commitments:e,version:s}=o,n=o.to??(typeof e[0]=="string"?"hex":"bytes"),t=[];for(const m of e)t.push(i.commitmentToVersionedHash({commitment:m,to:n,version:s}));return t}exports.commitmentsToVersionedHashes=c;
@@ -0,0 +1,14 @@
1
+ import { commitmentToVersionedHash as i } from "./index62.js";
2
+ function r(o) {
3
+ const { commitments: t, version: n } = o, e = o.to ?? (typeof t[0] == "string" ? "hex" : "bytes"), s = [];
4
+ for (const m of t)
5
+ s.push(i({
6
+ commitment: m,
7
+ to: e,
8
+ version: n
9
+ }));
10
+ return s;
11
+ }
12
+ export {
13
+ r as commitmentsToVersionedHashes
14
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index24.cjs"),r=require("./index97.cjs");function c(t){const{commitment:o,version:s=1}=t,n=t.to??(typeof o=="string"?"hex":"bytes"),e=r.sha256(o);return e.set([s],0),n==="bytes"?e:i.bytesToHex(e)}exports.commitmentToVersionedHash=c;
@@ -0,0 +1,9 @@
1
+ import { bytesToHex as i } from "./index24.js";
2
+ import { sha256 as m } from "./index97.js";
3
+ function f(t) {
4
+ const { commitment: e, version: s = 1 } = t, n = t.to ?? (typeof e == "string" ? "hex" : "bytes"), o = m(e);
5
+ return o.set([s], 0), n === "bytes" ? o : i(o);
6
+ }
7
+ export {
8
+ f as commitmentToVersionedHash
9
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index59.cjs"),m=require("./index60.cjs"),u=require("./index64.cjs");function f(t){const{data:i,kzg:n,to:b}=t,s=t.blobs??u.toBlobs({data:i,to:b}),e=t.commitments??r.blobsToCommitments({blobs:s,kzg:n,to:b}),l=t.proofs??m.blobsToProofs({blobs:s,commitments:e,kzg:n,to:b}),c=[];for(let o=0;o<s.length;o++)c.push({blob:s[o],commitment:e[o],proof:l[o]});return c}exports.toBlobSidecars=f;
@@ -0,0 +1,16 @@
1
+ import { blobsToCommitments as f } from "./index59.js";
2
+ import { blobsToProofs as l } from "./index60.js";
3
+ import { toBlobs as p } from "./index64.js";
4
+ function k(t) {
5
+ const { data: i, kzg: n, to: m } = t, s = t.blobs ?? p({ data: i, to: m }), b = t.commitments ?? f({ blobs: s, kzg: n, to: m }), r = t.proofs ?? l({ blobs: s, commitments: b, kzg: n, to: m }), c = [];
6
+ for (let o = 0; o < s.length; o++)
7
+ c.push({
8
+ blob: s[o],
9
+ commitment: b[o],
10
+ proof: r[o]
11
+ });
12
+ return c;
13
+ }
14
+ export {
15
+ k as toBlobSidecars
16
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index98.cjs"),y=require("./index99.cjs"),u=require("./index100.cjs"),B=require("./index47.cjs"),h=require("./index55.cjs"),d=require("./index24.cjs");function f(t){const a=t.to??(typeof t.data=="string"?"hex":"bytes"),n=typeof t.data=="string"?h.hexToBytes(t.data):t.data,s=B.size(n);if(!s)throw new y.EmptyBlobError;if(s>o.maxBytesPerTransaction)throw new y.BlobSizeTooLargeError({maxSize:o.maxBytesPerTransaction,size:s});const r=[];let b=!0,i=0;for(;b;){const e=u.createCursor(new Uint8Array(o.bytesPerBlob));let l=0;for(;l<o.fieldElementsPerBlob;){const c=n.slice(i,i+(o.bytesPerFieldElement-1));if(e.pushByte(0),e.pushBytes(c),c.length<31){e.pushByte(128),b=!1;break}l++,i+=31}r.push(e)}return a==="bytes"?r.map(e=>e.bytes):r.map(e=>d.bytesToHex(e.bytes))}exports.toBlobs=f;
@@ -0,0 +1,35 @@
1
+ import { maxBytesPerTransaction as y, bytesPerBlob as a, fieldElementsPerBlob as f, bytesPerFieldElement as p } from "./index98.js";
2
+ import { EmptyBlobError as c, BlobSizeTooLargeError as h } from "./index99.js";
3
+ import { createCursor as B } from "./index100.js";
4
+ import { size as u } from "./index47.js";
5
+ import { hexToBytes as x } from "./index55.js";
6
+ import { bytesToHex as d } from "./index24.js";
7
+ function S(e) {
8
+ const m = e.to ?? (typeof e.data == "string" ? "hex" : "bytes"), i = typeof e.data == "string" ? x(e.data) : e.data, o = u(i);
9
+ if (!o)
10
+ throw new c();
11
+ if (o > y)
12
+ throw new h({
13
+ maxSize: y,
14
+ size: o
15
+ });
16
+ const s = [];
17
+ let n = !0, r = 0;
18
+ for (; n; ) {
19
+ const t = B(new Uint8Array(a));
20
+ let l = 0;
21
+ for (; l < f; ) {
22
+ const b = i.slice(r, r + (p - 1));
23
+ if (t.pushByte(0), t.pushBytes(b), b.length < 31) {
24
+ t.pushByte(128), n = !1;
25
+ break;
26
+ }
27
+ l++, r += 31;
28
+ }
29
+ s.push(t);
30
+ }
31
+ return m === "bytes" ? s.map((t) => t.bytes) : s.map((t) => d(t.bytes));
32
+ }
33
+ export {
34
+ S as toBlobs
35
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index29.cjs");function f(e){if(e.type)return e.type;if(typeof e.authorizationList<"u")return"eip7702";if(typeof e.blobs<"u"||typeof e.blobVersionedHashes<"u"||typeof e.maxFeePerBlobGas<"u"||typeof e.sidecars<"u")return"eip4844";if(typeof e.maxFeePerGas<"u"||typeof e.maxPriorityFeePerGas<"u")return"eip1559";if(typeof e.gasPrice<"u")return typeof e.accessList<"u"?"eip2930":"legacy";throw new i.InvalidSerializableTransactionError({transaction:e})}exports.getTransactionType=f;
@@ -0,0 +1,17 @@
1
+ import { InvalidSerializableTransactionError as f } from "./index29.js";
2
+ function d(e) {
3
+ if (e.type)
4
+ return e.type;
5
+ if (typeof e.authorizationList < "u")
6
+ return "eip7702";
7
+ if (typeof e.blobs < "u" || typeof e.blobVersionedHashes < "u" || typeof e.maxFeePerBlobGas < "u" || typeof e.sidecars < "u")
8
+ return "eip4844";
9
+ if (typeof e.maxFeePerGas < "u" || typeof e.maxPriorityFeePerGas < "u")
10
+ return "eip1559";
11
+ if (typeof e.gasPrice < "u")
12
+ return typeof e.accessList < "u" ? "eip2930" : "legacy";
13
+ throw new f({ transaction: e });
14
+ }
15
+ export {
16
+ d as getTransactionType
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./index49.cjs"),z=require("./index54.cjs"),o=require("./index67.cjs"),T=require("./index58.cjs"),u=require("./index47.cjs"),q=require("./index24.cjs"),g=require("./index68.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;
@@ -0,0 +1,67 @@
1
+ import { BytesSizeMismatchError as m } from "./index49.js";
2
+ import { InvalidAddressError as w } from "./index54.js";
3
+ import { InvalidDomainError as E, InvalidPrimaryTypeError as z, InvalidStructTypeError as D } from "./index67.js";
4
+ import { isAddress as T } from "./index58.js";
5
+ import { size as y } from "./index47.js";
6
+ import { numberToHex as x } from "./index24.js";
7
+ import { integerRegex as P, bytesRegex as S } from "./index68.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 });
63
+ }
64
+ export {
65
+ F as getTypesForEIP712Domain,
66
+ j as validateTypedData
67
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index38.cjs"),e=require("./index43.cjs");class i extends e.BaseError{constructor({domain:r}){super(`Invalid domain "${s.stringify(r)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class o extends e.BaseError{constructor({primaryType:r,types:a}){super(`Invalid primary type \`${r}\` must be one of \`${JSON.stringify(Object.keys(a))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class n extends e.BaseError{constructor({type:r}){super(`Struct type "${r}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}exports.InvalidDomainError=i;exports.InvalidPrimaryTypeError=o;exports.InvalidStructTypeError=n;
@@ -0,0 +1,30 @@
1
+ import { stringify as a } from "./index38.js";
2
+ import { BaseError as t } from "./index43.js";
3
+ class n extends t {
4
+ constructor({ domain: r }) {
5
+ super(`Invalid domain "${a(r)}".`, {
6
+ metaMessages: ["Must be a valid EIP-712 domain."]
7
+ });
8
+ }
9
+ }
10
+ class p extends t {
11
+ constructor({ primaryType: r, types: s }) {
12
+ super(`Invalid primary type \`${r}\` must be one of \`${JSON.stringify(Object.keys(s))}\`.`, {
13
+ docsPath: "/api/glossary/Errors#typeddatainvalidprimarytypeerror",
14
+ metaMessages: ["Check that the primary type is a key in `types`."]
15
+ });
16
+ }
17
+ }
18
+ class y extends t {
19
+ constructor({ type: r }) {
20
+ super(`Struct type "${r}" is invalid.`, {
21
+ metaMessages: ["Struct type must not be a Solidity type."],
22
+ name: "InvalidStructTypeError"
23
+ });
24
+ }
25
+ }
26
+ export {
27
+ n as InvalidDomainError,
28
+ p as InvalidPrimaryTypeError,
29
+ y as InvalidStructTypeError
30
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,t=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;exports.bytesRegex=e;exports.integerRegex=t;
@@ -0,0 +1,5 @@
1
+ const e = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/, t = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;
2
+ export {
3
+ e as bytesRegex,
4
+ t as integerRegex
5
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}exports.isHex=r;
@@ -0,0 +1,6 @@
1
+ function e(t, { strict: r = !0 } = {}) {
2
+ return !t || typeof t != "string" ? !1 : r ? /^0x[0-9a-fA-F]*$/.test(t) : t.startsWith("0x");
3
+ }
4
+ export {
5
+ e as isHex
6
+ };
package/dist/index7.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index12.cjs"),d=require("./index8.cjs"),l=require("./index9.cjs"),w=require("jwt-decode"),f=require("./index3.cjs"),g=require("./index6.cjs"),y=require("./index14.cjs");class m{constructor(t,n,e){this.API="https://api.garden.finance",this.url=new g.Url("/",t??this.API),this.walletClient=n,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)??new d.MemoryStorage}verifyToken(t,n){try{const e=u(t);if(!e)return r.Ok(!1);const i=Math.floor(Date.now()/1e3)+120;return r.Ok(e.exp>i&&e.user_id.toLowerCase()===n.toLowerCase())}catch{return r.Ok(!1)}}async getToken(){var a;if(!((a=this.walletClient.account)!=null&&a.address))return r.Err("Wallet client does not have an account");const t=this.store.getItem(l.StoreKeys.AUTH_TOKEN);if(t){const s=this.verifyToken(t,this.walletClient.account.address);if(s.ok&&s.val)return r.Ok(t)}const n=await this.signStatement();if(n.error)return r.Err(n.error);const e=await r.Fetcher.post(this.url.endpoint("verify"),{body:JSON.stringify({...n.val}),headers:{"Content-Type":"application/json"}});if(e.error)return r.Err(e.error);const i=e.result;if(!i)return r.Err("Failed to get token");if(!this.verifyToken(i,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(l.StoreKeys.AUTH_TOKEN,i),r.Ok(i)}async signStatement(){var h;if(!((h=this.walletClient.account)!=null&&h.address))return r.Err("Wallet client does not have a valid account");const t=new Date,n=new Date(t.getTime()+300*1e3),i=(await r.Fetcher.get(this.url.endpoint("nonce"))).result;if(!i)return r.Err("Failed to get nonce");const c=await this.walletClient.getChainId(),a=y.createSiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:i,uri:"https://"+this.domain,version:"1",chainId:c,notBefore:n}),s=await this.walletClient.signMessage({account:this.walletClient.account,message:a});return r.Ok({message:a,signature:s,nonce:i})}}const u=o=>{try{return w.jwtDecode(o)}catch{return}};class k{constructor(t){if(!t.siwe&&!t.apiKey)throw new Error("Either siwe or apiKey must be provided");this.siwe=t.siwe,this.apiKey=t.apiKey}async getAuthHeaders(){if(this.siwe){const t=await this.siwe.getToken();return t.error?r.Err(t.error):r.Ok({Authorization:f.Authorization(t.val)})}return this.apiKey?r.Ok({"api-key":this.apiKey}):r.Err("No authentication method available")}}exports.Auth=k;exports.Siwe=m;exports.parseJwt=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=(t=>(t.Authorization="Authorization",t.ApiKey="api-key",t))(e||{});exports.AuthHeaderEnum=e;
package/dist/index7.js CHANGED
@@ -1,111 +1,4 @@
1
- import { Ok as n, Err as a, Fetcher as u } from "./index12.js";
2
- import { MemoryStorage as f } from "./index8.js";
3
- import { StoreKeys as d } from "./index9.js";
4
- import { jwtDecode as m } from "jwt-decode";
5
- import { Authorization as w } from "./index3.js";
6
- import { Url as g } from "./index6.js";
7
- import { createSiweMessage as y } from "./index14.js";
8
- class I {
9
- constructor(e, r, t) {
10
- this.API = "https://api.garden.finance", this.url = new g("/", e ?? this.API), this.walletClient = r, 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) ?? new f();
11
- }
12
- verifyToken(e, r) {
13
- try {
14
- const t = p(e);
15
- if (!t) return n(!1);
16
- const i = Math.floor(Date.now() / 1e3) + 120;
17
- return n(
18
- t.exp > i && t.user_id.toLowerCase() === r.toLowerCase()
19
- );
20
- } catch {
21
- return n(!1);
22
- }
23
- }
24
- async getToken() {
25
- var s;
26
- if (!((s = this.walletClient.account) != null && s.address))
27
- return a("Wallet client does not have an account");
28
- const e = this.store.getItem(d.AUTH_TOKEN);
29
- if (e) {
30
- const o = this.verifyToken(
31
- e,
32
- this.walletClient.account.address
33
- );
34
- if (o.ok && o.val) return n(e);
35
- }
36
- const r = await this.signStatement();
37
- if (r.error)
38
- return a(r.error);
39
- const t = await u.post(
40
- this.url.endpoint("verify"),
41
- {
42
- body: JSON.stringify({
43
- ...r.val
44
- }),
45
- headers: {
46
- "Content-Type": "application/json"
47
- }
48
- }
49
- );
50
- if (t.error) return a(t.error);
51
- const i = t.result;
52
- if (!i) return a("Failed to get token");
53
- if (!this.verifyToken(i, this.walletClient.account.address).val)
54
- throw new Error("Token verification failed");
55
- return this.store.setItem(d.AUTH_TOKEN, i), n(i);
56
- }
57
- async signStatement() {
58
- var l;
59
- if (!((l = this.walletClient.account) != null && l.address))
60
- return a("Wallet client does not have a valid account");
61
- const e = /* @__PURE__ */ new Date(), r = new Date(e.getTime() + 300 * 1e3), i = (await u.get(
62
- this.url.endpoint("nonce")
63
- )).result;
64
- if (!i)
65
- return a("Failed to get nonce");
66
- const h = await this.walletClient.getChainId(), s = y({
67
- domain: this.domain,
68
- address: this.walletClient.account.address,
69
- statement: this.signingStatement,
70
- nonce: i,
71
- uri: "https://" + this.domain,
72
- version: "1",
73
- chainId: h,
74
- notBefore: r
75
- }), o = await this.walletClient.signMessage({
76
- account: this.walletClient.account,
77
- message: s
78
- });
79
- return n({
80
- message: s,
81
- signature: o,
82
- nonce: i
83
- });
84
- }
85
- }
86
- const p = (c) => {
87
- try {
88
- return m(c);
89
- } catch {
90
- return;
91
- }
92
- };
93
- class E {
94
- constructor(e) {
95
- if (!e.siwe && !e.apiKey)
96
- throw new Error("Either siwe or apiKey must be provided");
97
- this.siwe = e.siwe, this.apiKey = e.apiKey;
98
- }
99
- async getAuthHeaders() {
100
- if (this.siwe) {
101
- const e = await this.siwe.getToken();
102
- return e.error ? a(e.error) : n({ Authorization: w(e.val) });
103
- }
104
- return this.apiKey ? n({ "api-key": this.apiKey }) : a("No authentication method available");
105
- }
106
- }
1
+ var o = /* @__PURE__ */ ((i) => (i.Authorization = "Authorization", i.ApiKey = "api-key", i))(o || {});
107
2
  export {
108
- E as Auth,
109
- I as Siwe,
110
- p as parseJwt
3
+ o as AuthHeaderEnum
111
4
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index71.cjs"),n=require("./index34.cjs"),a=require("./index55.cjs");function g({r:i,s:o,to:u="hex",v:e,yParity:r}){const s=(()=>{if(r===0||r===1)return r;if(e&&(e===27n||e===28n||e>=35n))return e%2n===0n?1:0;throw new Error("Invalid `v` or `yParity` value")})(),t=`0x${new c.secp256k1.Signature(n.hexToBigInt(i),n.hexToBigInt(o)).toCompactHex()}${s===0?"1b":"1c"}`;return u==="hex"?t:a.hexToBytes(t)}exports.serializeSignature=g;