@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/index9.js
CHANGED
|
@@ -1,56 +1,64 @@
|
|
|
1
|
-
import { CookieJar as
|
|
1
|
+
import { CookieJar as u } from "tough-cookie";
|
|
2
2
|
import m from "fetch-cookie";
|
|
3
|
-
import { Ok as
|
|
4
|
-
import { MemoryStorage as
|
|
5
|
-
import { StoreKeys as
|
|
6
|
-
import { createWalletClient as g, http as
|
|
7
|
-
import { add0x as
|
|
3
|
+
import { Ok as s, Err as r } from "./index17.js";
|
|
4
|
+
import { MemoryStorage as w } from "./index13.js";
|
|
5
|
+
import { StoreKeys as d } from "./index14.js";
|
|
6
|
+
import { createWalletClient as g, http as k } from "viem";
|
|
7
|
+
import { add0x as p, parseJwt as y, Authorization as C } from "./index3.js";
|
|
8
8
|
import { mainnet as T } from "./index20.js";
|
|
9
9
|
import { privateKeyToAccount as v } from "./index19.js";
|
|
10
10
|
import { createSiweMessage as S } from "./index21.js";
|
|
11
|
-
class
|
|
11
|
+
class f {
|
|
12
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
|
|
14
|
-
const i = new
|
|
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 w()), typeof window > "u") {
|
|
14
|
+
const i = new u();
|
|
15
15
|
this.fetchWithCookies = m(fetch, i);
|
|
16
16
|
} else
|
|
17
17
|
this.fetchWithCookies = window.fetch.bind(window);
|
|
18
18
|
}
|
|
19
19
|
static fromDigestKey(e, n, t) {
|
|
20
20
|
const i = g({
|
|
21
|
-
account: v(
|
|
22
|
-
transport:
|
|
21
|
+
account: v(p(n.digestKey)),
|
|
22
|
+
transport: k(),
|
|
23
23
|
chain: T
|
|
24
24
|
});
|
|
25
|
-
return new
|
|
25
|
+
return new f(e, i, t);
|
|
26
26
|
}
|
|
27
27
|
verifyToken(e, n) {
|
|
28
28
|
try {
|
|
29
29
|
const t = y(e);
|
|
30
|
-
if (!t) return
|
|
30
|
+
if (!t) return s(!1);
|
|
31
31
|
const i = Math.floor(Date.now() / 1e3) + 120;
|
|
32
|
-
return
|
|
32
|
+
return s(
|
|
33
33
|
t.exp > i && t.user_id.toLowerCase() === n.toLowerCase()
|
|
34
34
|
);
|
|
35
35
|
} catch {
|
|
36
|
-
return
|
|
36
|
+
return s(!1);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
async getToken() {
|
|
40
|
-
var
|
|
41
|
-
if (!((
|
|
40
|
+
var c;
|
|
41
|
+
if (!((c = this.walletClient.account) != null && c.address))
|
|
42
42
|
return r("Wallet client does not have an account");
|
|
43
|
-
const e =
|
|
44
|
-
if (e
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const e = this.store.getItem(d.AUTH_TOKEN);
|
|
44
|
+
if (e) {
|
|
45
|
+
const o = this.verifyToken(
|
|
46
|
+
e,
|
|
47
|
+
this.walletClient.account.address
|
|
48
|
+
);
|
|
49
|
+
if (o.ok && o.val) return s(e);
|
|
50
|
+
}
|
|
51
|
+
const n = await this.signStatement();
|
|
52
|
+
if (n.error)
|
|
53
|
+
return r(n.error);
|
|
54
|
+
let t;
|
|
47
55
|
try {
|
|
48
|
-
const
|
|
56
|
+
const a = await (await this.fetchWithCookies(
|
|
49
57
|
this.url.endpoint("tokens"),
|
|
50
58
|
{
|
|
51
59
|
method: "POST",
|
|
52
60
|
body: JSON.stringify({
|
|
53
|
-
...
|
|
61
|
+
...n.val
|
|
54
62
|
}),
|
|
55
63
|
headers: {
|
|
56
64
|
"Content-Type": "application/json"
|
|
@@ -58,37 +66,37 @@ class d {
|
|
|
58
66
|
credentials: "include"
|
|
59
67
|
}
|
|
60
68
|
)).json();
|
|
61
|
-
if (
|
|
62
|
-
return r(
|
|
63
|
-
|
|
64
|
-
} catch (
|
|
65
|
-
return r("Failed to get token",
|
|
69
|
+
if (a.error || !a.result)
|
|
70
|
+
return r(a.error ?? "Failed to get token");
|
|
71
|
+
t = a.result;
|
|
72
|
+
} catch (o) {
|
|
73
|
+
return r("Failed to get token", o);
|
|
66
74
|
}
|
|
67
|
-
if (!this.verifyToken(
|
|
75
|
+
if (!this.verifyToken(t, this.walletClient.account.address).val)
|
|
68
76
|
throw new Error("Token verification failed");
|
|
69
|
-
return this.store.setItem(
|
|
77
|
+
return this.store.setItem(d.AUTH_TOKEN, t), s(t);
|
|
70
78
|
}
|
|
71
79
|
async signStatement() {
|
|
72
|
-
var
|
|
73
|
-
if (!((
|
|
80
|
+
var a;
|
|
81
|
+
if (!((a = this.walletClient.account) != null && a.address))
|
|
74
82
|
return r("Wallet client does not have a valid account");
|
|
75
83
|
const e = /* @__PURE__ */ new Date(), n = new Date(e.getTime() + 300 * 1e3);
|
|
76
84
|
let t;
|
|
77
85
|
try {
|
|
78
|
-
const
|
|
86
|
+
const l = await (await this.fetchWithCookies(this.url.endpoint("challenges"), {
|
|
79
87
|
method: "POST",
|
|
80
88
|
headers: {
|
|
81
89
|
"Content-Type": "application/json"
|
|
82
90
|
},
|
|
83
91
|
credentials: "include"
|
|
84
92
|
})).json();
|
|
85
|
-
if (
|
|
93
|
+
if (l.error || !l.result)
|
|
86
94
|
return r("Failed to get nonce");
|
|
87
|
-
t =
|
|
95
|
+
t = l.result;
|
|
88
96
|
} catch (h) {
|
|
89
97
|
return r("Failed to get nonce", h);
|
|
90
98
|
}
|
|
91
|
-
const i = await this.walletClient.getChainId(),
|
|
99
|
+
const i = await this.walletClient.getChainId(), c = S({
|
|
92
100
|
domain: this.domain,
|
|
93
101
|
address: this.walletClient.account.address,
|
|
94
102
|
statement: this.signingStatement,
|
|
@@ -99,19 +107,19 @@ class d {
|
|
|
99
107
|
notBefore: n
|
|
100
108
|
}), o = await this.walletClient.signMessage({
|
|
101
109
|
account: this.walletClient.account,
|
|
102
|
-
message:
|
|
110
|
+
message: c
|
|
103
111
|
});
|
|
104
|
-
return
|
|
105
|
-
message:
|
|
112
|
+
return s({
|
|
113
|
+
message: c,
|
|
106
114
|
signature: o,
|
|
107
115
|
nonce: t
|
|
108
116
|
});
|
|
109
117
|
}
|
|
110
118
|
async getAuthHeaders() {
|
|
111
119
|
const e = await this.getToken();
|
|
112
|
-
return e.error ? r(e.error) :
|
|
120
|
+
return e.error ? r(e.error) : s({ Authorization: C(e.val) });
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
export {
|
|
116
|
-
|
|
124
|
+
f as Siwe
|
|
117
125
|
};
|
package/dist/index91.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index71.cjs");class i extends e.BaseError{constructor({chainId:r}){super(typeof r=="number"?`Chain ID "${r}" is invalid.`:"Chain ID is invalid.",{name:"InvalidChainIdError"})}}exports.InvalidChainIdError=i;
|
package/dist/index91.js
CHANGED
package/dist/index93.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index89.cjs"),n=require("./index71.cjs");class o extends n.BaseError{constructor({expectedLength:r,givenLength:e,type:t}){super([`ABI encoding array length mismatch for type ${t}.`,`Expected length: ${r}`,`Given length: ${e}`].join(`
|
|
2
2
|
`),{name:"AbiEncodingArrayLengthMismatchError"})}}class a extends n.BaseError{constructor({expectedSize:r,value:e}){super(`Size of bytes "${e}" (bytes${i.size(e)}) does not match expected size (bytes${r}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class c extends n.BaseError{constructor({expectedLength:r,givenLength:e}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${r}`,`Given length (values): ${e}`].join(`
|
|
3
3
|
`),{name:"AbiEncodingLengthMismatchError"})}}class d extends n.BaseError{constructor({expectedSize:r,givenSize:e}){super(`Expected bytes${r}, got bytes${e}.`,{name:"BytesSizeMismatchError"})}}class E extends n.BaseError{constructor(r,{docsPath:e}){super([`Type "${r}" is not a valid encoding type.`,"Please provide a valid ABI type."].join(`
|
|
4
4
|
`),{docsPath:e,name:"InvalidAbiEncodingType"})}}class g extends n.BaseError{constructor(r){super([`Value "${r}" is not a valid array.`].join(`
|
package/dist/index93.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { size as i } from "./
|
|
2
|
-
import { BaseError as n } from "./
|
|
1
|
+
import { size as i } from "./index89.js";
|
|
2
|
+
import { BaseError as n } from "./index71.js";
|
|
3
3
|
class c extends n {
|
|
4
4
|
constructor({ expectedLength: e, givenLength: r, type: s }) {
|
|
5
5
|
super([
|
package/dist/index94.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index95.cjs"),t=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index95.cjs"),t=require("./index71.cjs");class i extends t.BaseError{constructor({cause:r,maxFeePerGas:e}={}){super(`The fee cap (\`maxFeePerGas\`${e?` = ${a.formatGwei(e)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:r,name:"FeeCapTooHighError"})}}Object.defineProperty(i,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class n extends t.BaseError{constructor({cause:r,maxPriorityFeePerGas:e,maxFeePerGas:o}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${e?` = ${a.formatGwei(e)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${o?` = ${a.formatGwei(o)} gwei`:""}).`].join(`
|
|
2
2
|
`),{cause:r,name:"TipAboveFeeCapError"})}}Object.defineProperty(n,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});exports.FeeCapTooHighError=i;exports.TipAboveFeeCapError=n;
|
package/dist/index94.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { formatGwei as a } from "./index95.js";
|
|
2
|
-
import { BaseError as o } from "./
|
|
2
|
+
import { BaseError as o } from "./index71.js";
|
|
3
3
|
class n extends o {
|
|
4
4
|
constructor({ cause: r, maxFeePerGas: e } = {}) {
|
|
5
5
|
super(`The fee cap (\`maxFeePerGas\`${e ? ` = ${a(e)} gwei` : ""}) cannot be higher than the maximum allowed value (2^256-1).`, {
|
package/dist/index98.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index118.cjs"),y=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index118.cjs"),y=require("./index112.cjs"),u=require("./index108.cjs"),B=require("./index89.cjs"),h=require("./index36.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;
|
package/dist/index98.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { maxBytesPerTransaction as y, bytesPerBlob as a, fieldElementsPerBlob as f, bytesPerFieldElement as p } from "./index118.js";
|
|
2
|
-
import { EmptyBlobError as c, BlobSizeTooLargeError as h } from "./
|
|
2
|
+
import { EmptyBlobError as c, BlobSizeTooLargeError as h } from "./index112.js";
|
|
3
3
|
import { createCursor as B } from "./index108.js";
|
|
4
|
-
import { size as u } from "./
|
|
4
|
+
import { size as u } from "./index89.js";
|
|
5
5
|
import { hexToBytes as x } from "./index36.js";
|
|
6
6
|
import { bytesToHex as d } from "./index24.js";
|
|
7
7
|
function S(e) {
|
package/dist/index99.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index57.cjs"),e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index57.cjs"),e=require("./index71.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;
|
package/dist/index99.js
CHANGED