@gardenfi/utils 2.0.0 → 2.0.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/index.cjs +1 -1
- package/dist/index.js +12 -11
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +186 -92
- package/dist/index12.cjs +1 -16
- package/dist/index12.js +93 -113
- package/dist/index13.cjs +16 -1
- package/dist/index13.js +112 -30
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +18 -17
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +31 -18
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +17 -7
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +6 -19
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +20 -22
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +21 -8
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +8 -31
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +31 -26
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +25 -22
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +22 -50
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +51 -12
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +12 -24
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +24 -75
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +74 -22
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +23 -7
- package/dist/index29.cjs +1 -1
- package/dist/index29.js +7 -29
- package/dist/index30.cjs +1 -1
- package/dist/index30.js +31 -14
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +16 -2
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +2 -9
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +8 -20
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +20 -12
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +10 -32
- package/dist/index36.cjs +1 -2
- package/dist/index36.js +33 -58
- package/dist/index37.cjs +2 -1
- package/dist/index37.js +60 -2
- package/dist/index38.cjs +1 -1
- package/dist/index38.js +2 -5
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +4 -11
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +15 -15
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +11 -3
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +3 -21
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +21 -12
- package/dist/index43.cjs +1 -1
- package/dist/index43.js +11 -54
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +55 -6
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +6 -21
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +21 -11
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +11 -3
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +3 -11
- package/dist/index49.cjs +1 -1
- package/dist/index49.js +11 -19
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +19 -8
- package/dist/index51.cjs +1 -1
- package/dist/index51.js +1 -1
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +8 -104
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +102 -27
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +27 -17
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +16 -30
- package/dist/index56.cjs +1 -0
- package/dist/index56.js +41 -0
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +65 -49
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +6 -6
- package/dist/src/lib/auth/auth.types.d.ts +9 -10
- package/dist/src/lib/auth/siwe.d.ts +13 -3
- package/package.json +2 -4
package/dist/index55.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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;
|
package/dist/index55.js
CHANGED
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function p(t) {
|
|
5
|
-
for (let e = 0; e < t.length; e++)
|
|
6
|
-
t[e] = r(t[e]);
|
|
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 };
|
|
7
4
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function u(t) {
|
|
14
|
-
return typeof t == "string" && (t = c(t)), f(t), t;
|
|
15
|
-
}
|
|
16
|
-
class b {
|
|
17
|
-
// Safe version that clones internal state
|
|
18
|
-
clone() {
|
|
19
|
-
return this._cloneInto();
|
|
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];
|
|
20
10
|
}
|
|
11
|
+
return [n, l];
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
const e = (o) => t().update(u(o)).digest(), n = t();
|
|
24
|
-
return e.outputLen = n.outputLen, e.blockLen = n.blockLen, e.create = () => t(), e;
|
|
25
|
-
}
|
|
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;
|
|
26
14
|
export {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
c as utf8ToBytes,
|
|
34
|
-
x as wrapConstructor
|
|
15
|
+
f as fromBig,
|
|
16
|
+
A as rotlBH,
|
|
17
|
+
B as rotlBL,
|
|
18
|
+
g as rotlSH,
|
|
19
|
+
m as rotlSL,
|
|
20
|
+
h as split
|
|
35
21
|
};
|
package/dist/index56.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index54.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;
|
package/dist/index56.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { abytes as o } from "./index54.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();
|
|
26
|
+
}
|
|
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
|
+
}
|
|
32
|
+
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
|
|
41
|
+
};
|
package/dist/index6.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index11.cjs"),d=require("./index7.cjs"),h=require("./index8.cjs"),w=require("jwt-decode"),f=require("./index3.cjs"),g=require("./index5.cjs"),y=require("./index13.cjs");class m{constructor(r,i,e){this.API="https://api.garden.finance",this.url=new g.Url("/",r??this.API),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)??new d.MemoryStorage}verifyToken(r,i){try{const e=u(r);if(!e)return t.Ok(!1);const n=Math.floor(Date.now()/1e3)+120;if(!e.address&&!e.user_id)return t.Ok(!1);const a=e.address?e.address.toLowerCase()===i.toLowerCase():!1,s=e.user_id?e.user_id.toLowerCase()===i.toLowerCase():!1;return t.Ok(e.exp>n&&a||s)}catch{return t.Ok(!1)}}async getToken(){var s;if(!((s=this.walletClient.account)!=null&&s.address))return t.Err("Wallet client does not have an account");const r=this.store.getItem(h.StoreKeys.AUTH_TOKEN);if(r){const o=this.verifyToken(r,this.walletClient.account.address);if(o.ok&&o.val)return t.Ok(r)}const i=await this.signStatement();if(i.error)return t.Err(i.error);const e=await t.Fetcher.post(this.url.endpoint("verify"),{body:JSON.stringify({...i.val}),headers:{"Content-Type":"application/json"}});if(e.error)return t.Err(e.error);const n=e.result;if(!n)return t.Err("Failed to get token");if(!this.verifyToken(n,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(h.StoreKeys.AUTH_TOKEN,n),t.Ok(n)}async signStatement(){var l;if(!((l=this.walletClient.account)!=null&&l.address))return t.Err("Wallet client does not have a valid account");const r=new Date,i=new Date(r.getTime()+300*1e3),n=(await t.Fetcher.get(this.url.endpoint("nonce"))).result;if(!n)return t.Err("Failed to get nonce");const a=await this.walletClient.getChainId(),s=y.createSiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:n,uri:"https://"+this.domain,version:"1",chainId:a,notBefore:i}),o=await this.walletClient.signMessage({account:this.walletClient.account,message:s});return t.Ok({message:s,signature:o,nonce:n})}}const u=c=>{try{return w.jwtDecode(c)}catch{return}};class k{constructor(r){if(!r.siwe&&!r.apiKey)throw new Error("Either siwe or apiKey must be provided");this.siwe=r.siwe,this.apiKey=r.apiKey}async getAuthHeaders(){if(this.siwe){const r=await this.siwe.getToken();return r.error?t.Err(r.error):t.Ok({Authorization:f.Authorization(r.val)})}return this.apiKey?t.Ok({"api-key":this.apiKey}):t.Err("No authentication method available")}}exports.Auth=k;exports.Siwe=m;exports.parseJwt=u;
|
package/dist/index6.js
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
import { Ok as
|
|
2
|
-
import { MemoryStorage as
|
|
3
|
-
import { StoreKeys as
|
|
4
|
-
import { jwtDecode as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Ok as n, Err as s, Fetcher as d } from "./index11.js";
|
|
2
|
+
import { MemoryStorage as f } from "./index7.js";
|
|
3
|
+
import { StoreKeys as u } from "./index8.js";
|
|
4
|
+
import { jwtDecode as w } from "jwt-decode";
|
|
5
|
+
import { Authorization as m } from "./index3.js";
|
|
6
|
+
import { Url as g } from "./index5.js";
|
|
7
|
+
import { createSiweMessage as y } from "./index13.js";
|
|
7
8
|
class I {
|
|
8
|
-
constructor(
|
|
9
|
-
this.API = "https://api.garden.finance", this.url = new
|
|
9
|
+
constructor(t, i, e) {
|
|
10
|
+
this.API = "https://api.garden.finance", this.url = new g("/", t ?? this.API), 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) ?? new f();
|
|
10
11
|
}
|
|
11
|
-
verifyToken(
|
|
12
|
+
verifyToken(t, i) {
|
|
12
13
|
try {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
);
|
|
14
|
+
const e = p(t);
|
|
15
|
+
if (!e) return n(!1);
|
|
16
|
+
const r = Math.floor(Date.now() / 1e3) + 120;
|
|
17
|
+
if (!e.address && !e.user_id) return n(!1);
|
|
18
|
+
const o = e.address ? e.address.toLowerCase() === i.toLowerCase() : !1, a = e.user_id ? e.user_id.toLowerCase() === i.toLowerCase() : !1;
|
|
19
|
+
return n(e.exp > r && o || a);
|
|
19
20
|
} catch {
|
|
20
|
-
return
|
|
21
|
+
return n(!1);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
async getToken() {
|
|
24
|
-
var
|
|
25
|
-
if (!((
|
|
26
|
-
return
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
|
|
25
|
+
var a;
|
|
26
|
+
if (!((a = this.walletClient.account) != null && a.address))
|
|
27
|
+
return s("Wallet client does not have an account");
|
|
28
|
+
const t = this.store.getItem(u.AUTH_TOKEN);
|
|
29
|
+
if (t) {
|
|
30
|
+
const c = this.verifyToken(
|
|
31
|
+
t,
|
|
31
32
|
this.walletClient.account.address
|
|
32
33
|
);
|
|
33
|
-
if (
|
|
34
|
+
if (c.ok && c.val) return n(t);
|
|
34
35
|
}
|
|
35
36
|
const i = await this.signStatement();
|
|
36
37
|
if (i.error)
|
|
37
|
-
return
|
|
38
|
-
const
|
|
38
|
+
return s(i.error);
|
|
39
|
+
const e = await d.post(
|
|
39
40
|
this.url.endpoint("verify"),
|
|
40
41
|
{
|
|
41
42
|
body: JSON.stringify({
|
|
@@ -46,50 +47,65 @@ class I {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
);
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
if (!this.verifyToken(
|
|
50
|
+
if (e.error) return s(e.error);
|
|
51
|
+
const r = e.result;
|
|
52
|
+
if (!r) return s("Failed to get token");
|
|
53
|
+
if (!this.verifyToken(r, this.walletClient.account.address).val)
|
|
53
54
|
throw new Error("Token verification failed");
|
|
54
|
-
return this.store.setItem(
|
|
55
|
+
return this.store.setItem(u.AUTH_TOKEN, r), n(r);
|
|
55
56
|
}
|
|
56
57
|
async signStatement() {
|
|
57
|
-
var
|
|
58
|
-
if (!((
|
|
59
|
-
return
|
|
60
|
-
const
|
|
58
|
+
var l;
|
|
59
|
+
if (!((l = this.walletClient.account) != null && l.address))
|
|
60
|
+
return s("Wallet client does not have a valid account");
|
|
61
|
+
const t = /* @__PURE__ */ new Date(), i = new Date(t.getTime() + 300 * 1e3), r = (await d.get(
|
|
61
62
|
this.url.endpoint("nonce")
|
|
62
63
|
)).result;
|
|
63
|
-
if (!
|
|
64
|
-
return
|
|
65
|
-
const
|
|
64
|
+
if (!r)
|
|
65
|
+
return s("Failed to get nonce");
|
|
66
|
+
const o = await this.walletClient.getChainId(), a = y({
|
|
66
67
|
domain: this.domain,
|
|
67
68
|
address: this.walletClient.account.address,
|
|
68
69
|
statement: this.signingStatement,
|
|
69
|
-
nonce:
|
|
70
|
+
nonce: r,
|
|
70
71
|
uri: "https://" + this.domain,
|
|
71
72
|
version: "1",
|
|
72
|
-
chainId:
|
|
73
|
+
chainId: o,
|
|
73
74
|
notBefore: i
|
|
74
|
-
}),
|
|
75
|
+
}), c = await this.walletClient.signMessage({
|
|
75
76
|
account: this.walletClient.account,
|
|
76
|
-
message:
|
|
77
|
+
message: a
|
|
77
78
|
});
|
|
78
|
-
return
|
|
79
|
-
message:
|
|
80
|
-
signature:
|
|
81
|
-
nonce:
|
|
79
|
+
return n({
|
|
80
|
+
message: a,
|
|
81
|
+
signature: c,
|
|
82
|
+
nonce: r
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
|
-
const
|
|
86
|
+
const p = (h) => {
|
|
86
87
|
try {
|
|
87
|
-
return
|
|
88
|
+
return w(h);
|
|
88
89
|
} catch {
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
91
92
|
};
|
|
93
|
+
class E {
|
|
94
|
+
constructor(t) {
|
|
95
|
+
if (!t.siwe && !t.apiKey)
|
|
96
|
+
throw new Error("Either siwe or apiKey must be provided");
|
|
97
|
+
this.siwe = t.siwe, this.apiKey = t.apiKey;
|
|
98
|
+
}
|
|
99
|
+
async getAuthHeaders() {
|
|
100
|
+
if (this.siwe) {
|
|
101
|
+
const t = await this.siwe.getToken();
|
|
102
|
+
return t.error ? s(t.error) : n({ Authorization: m(t.val) });
|
|
103
|
+
}
|
|
104
|
+
return this.apiKey ? n({ "api-key": this.apiKey }) : s("No authentication method available");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
92
107
|
export {
|
|
108
|
+
E as Auth,
|
|
93
109
|
I as Siwe,
|
|
94
|
-
|
|
110
|
+
p as parseJwt
|
|
95
111
|
};
|
package/dist/index9.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index11.cjs"),n=require("viem"),s=require("./index14.cjs"),l=require("./index15.cjs"),o={42161:s.mainnet,421614:l.sepolia},b=async e=>{const{chain:t}=e;if(!t)return r.Err("No chain found");const a=(u=>u in o)(t.id)?o[t.id]:t;return await i(a)},i=async e=>{const t=n.createPublicClient({chain:e,transport:n.http()});try{const c=await t.getBlockNumber();return r.Ok(Number(c))}catch(c){return r.Err("Failed to fetch evm block number",c)}},m=async e=>{try{const t=await e.getLatestTip();return r.Ok(t)}catch(t){return r.Err("Failed to fetch bitcoin block number",t)}};exports._fetchEVMBlockNumber=i;exports.fetchBitcoinBlockNumber=m;exports.fetchEVMBlockNumber=b;
|
package/dist/index9.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Err as o, Ok as n } from "
|
|
2
|
-
import { createPublicClient as
|
|
3
|
-
import { mainnet as u } from "./
|
|
4
|
-
import { sepolia as b } from "./
|
|
1
|
+
import { Err as o, Ok as n } from "./index11.js";
|
|
2
|
+
import { createPublicClient as s, http as m } from "viem";
|
|
3
|
+
import { mainnet as u } from "./index14.js";
|
|
4
|
+
import { sepolia as b } from "./index15.js";
|
|
5
5
|
const e = {
|
|
6
6
|
42161: u,
|
|
7
7
|
421614: b
|
|
@@ -11,9 +11,9 @@ const e = {
|
|
|
11
11
|
const i = ((a) => a in e)(t.id) ? e[t.id] : t;
|
|
12
12
|
return await l(i);
|
|
13
13
|
}, l = async (r) => {
|
|
14
|
-
const t =
|
|
14
|
+
const t = s({
|
|
15
15
|
chain: r,
|
|
16
|
-
transport:
|
|
16
|
+
transport: m()
|
|
17
17
|
});
|
|
18
18
|
try {
|
|
19
19
|
const c = await t.getBlockNumber();
|
|
@@ -6,16 +6,15 @@ export type SiweOpts = {
|
|
|
6
6
|
store?: IStore;
|
|
7
7
|
signingStatement?: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
9
|
+
export type AuthHeader = {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
12
|
+
export interface ISiwe {
|
|
14
13
|
getToken(): AsyncResult<string, string>;
|
|
15
|
-
/**
|
|
16
|
-
* Verify the token expiry and account
|
|
17
|
-
* @param token The token to verify
|
|
18
|
-
* @param account The account to verify the token against
|
|
19
|
-
*/
|
|
20
14
|
verifyToken(token: string, account: string): Result<boolean, string>;
|
|
21
15
|
}
|
|
16
|
+
export interface IAuth {
|
|
17
|
+
siwe?: ISiwe;
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
20
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IAuth, SiweOpts } from './auth.types';
|
|
1
|
+
import { AuthHeader, IAuth, ISiwe, SiweOpts } from './auth.types';
|
|
2
2
|
import { AsyncResult, Result } from '@catalogfi/utils';
|
|
3
3
|
import { Url } from '../url';
|
|
4
4
|
import { WalletClient } from 'viem';
|
|
5
5
|
|
|
6
|
-
export declare class Siwe implements
|
|
6
|
+
export declare class Siwe implements ISiwe {
|
|
7
7
|
private readonly API;
|
|
8
8
|
private readonly url;
|
|
9
9
|
private store;
|
|
@@ -16,6 +16,16 @@ export declare class Siwe implements IAuth {
|
|
|
16
16
|
private signStatement;
|
|
17
17
|
}
|
|
18
18
|
export declare const parseJwt: (token: string) => {
|
|
19
|
-
|
|
19
|
+
user_id?: string;
|
|
20
|
+
address?: string;
|
|
20
21
|
exp: number;
|
|
21
22
|
} | undefined;
|
|
23
|
+
export declare class Auth implements IAuth {
|
|
24
|
+
siwe?: ISiwe;
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
constructor(opts: {
|
|
27
|
+
siwe?: ISiwe;
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
});
|
|
30
|
+
getAuthHeaders(): AsyncResult<AuthHeader, string>;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -35,9 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@catalogfi/utils": "^0.1.11",
|
|
39
|
-
"axios": "^1.7.2",
|
|
40
38
|
"jwt-decode": "^4.0.0",
|
|
41
|
-
"viem": "^2.21.
|
|
39
|
+
"viem": "^2.21.23"
|
|
42
40
|
}
|
|
43
41
|
}
|