@gardenfi/utils 2.2.1-beta.1 → 2.2.1-beta.3
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 +24 -24
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +124 -2
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +34 -114
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +19 -37
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +135 -19
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +10 -137
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +2 -15
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +27 -2
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +18 -26
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +102 -14
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +12 -26
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +58 -8
- package/dist/index26.cjs +16 -1
- package/dist/index26.js +113 -12
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +32 -58
- package/dist/index28.cjs +1 -16
- package/dist/index28.js +24 -111
- package/dist/index29.cjs +1 -1
- package/dist/index29.js +7 -31
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +8 -105
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +22 -8
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +2 -24
- package/dist/src/index.d.ts +2 -2
- package/dist/src/lib/approve.d.ts +1 -1
- package/dist/src/lib/auth/apikey/apikey.d.ts +1 -1
- package/dist/src/lib/auth/auth.types.d.ts +1 -1
- package/dist/src/lib/auth/passkey/passkey.d.ts +1 -1
- package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +1 -1
- package/dist/src/lib/auth/siwe/siwe.d.ts +1 -1
- package/dist/src/lib/blockNumber/blockNumber.d.ts +1 -1
- package/dist/src/lib/digestKey/digestKey.d.ts +1 -1
- package/dist/src/lib/fetcher/index.d.ts +1 -0
- package/dist/src/lib/result/index.d.ts +1 -0
- package/dist/src/lib/tryCatch/index.d.ts +1 -0
- package/dist/src/lib/{tryCatch.d.ts → tryCatch/tryCatch.d.ts} +1 -1
- package/package.json +1 -1
- /package/dist/src/lib/{fetcher.d.ts → fetcher/fetcher.d.ts} +0 -0
- /package/dist/src/lib/{safeParseJson.d.ts → fetcher/safeParseJson.d.ts} +0 -0
- /package/dist/src/lib/{result.d.ts → result/result.d.ts} +0 -0
package/dist/index13.js
CHANGED
|
@@ -1,28 +1,144 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
class
|
|
5
|
-
constructor(t) {
|
|
6
|
-
this.
|
|
1
|
+
import { startRegistration as d, startAuthentication as u } from "@simplewebauthn/browser";
|
|
2
|
+
import { Ok as l, Err as e } from "./index5.js";
|
|
3
|
+
import { Fetcher as c } from "./index18.js";
|
|
4
|
+
class y {
|
|
5
|
+
constructor(t, r) {
|
|
6
|
+
if (this.storeKey = "passkey-auth", !window)
|
|
7
|
+
throw new Error("Passkey is only supported in the browser environment.");
|
|
8
|
+
this.url = t.endpoint("passkey"), this.store = r;
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
getPasskeyFromStore() {
|
|
11
|
+
if (this.token && this.userName)
|
|
12
|
+
return l({ token: this.token, gardenUserName: this.userName });
|
|
13
|
+
const t = this.store.getItem(this.storeKey);
|
|
14
|
+
if (t) {
|
|
15
|
+
const r = JSON.parse(t);
|
|
16
|
+
return l(r);
|
|
17
|
+
}
|
|
18
|
+
return e("Passkey is not set");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validates the username according to predefined rules.
|
|
22
|
+
* @param username The username to validate.
|
|
23
|
+
* @returns Result<string, string> - Ok if valid, Err with message if invalid.
|
|
24
|
+
*/
|
|
25
|
+
validateUsername(t) {
|
|
26
|
+
return !t || t.length === 0 ? e("Username cannot be empty") : t.length < 3 || t.length > 32 ? e("Username must be between 3 and 32 characters") : t.includes(" ") ? e("Username cannot contain spaces") : l(t.trim().toLowerCase());
|
|
10
27
|
}
|
|
11
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Handles user registration using WebAuthn passkeys.
|
|
30
|
+
* @param username The username to register.
|
|
31
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
32
|
+
*/
|
|
33
|
+
async register(t) {
|
|
34
|
+
var i;
|
|
35
|
+
const r = this.validateUsername(t);
|
|
36
|
+
if (r.error) return e(r.error);
|
|
12
37
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
38
|
+
const n = await c.post(this.url.endpoint("register/begin"), {
|
|
39
|
+
body: JSON.stringify({ username: r }),
|
|
40
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
41
|
+
});
|
|
42
|
+
if (n.error)
|
|
43
|
+
return e("Failed to start registration", n.error);
|
|
44
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
45
|
+
if (!s) return e("No challenge found");
|
|
46
|
+
if (!s.publicKey.authenticatorSelection)
|
|
47
|
+
return e("No authenticator selection found");
|
|
48
|
+
s.publicKey.authenticatorSelection.requireResidentKey = !0, s.publicKey.authenticatorSelection.residentKey = "required";
|
|
49
|
+
const a = await d({
|
|
50
|
+
optionsJSON: s.publicKey
|
|
51
|
+
}), o = await c.post(
|
|
52
|
+
this.url.endpoint("register/finish"),
|
|
53
|
+
{
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
username: r,
|
|
56
|
+
credential: a
|
|
57
|
+
}),
|
|
58
|
+
headers: {
|
|
59
|
+
credentials: "include",
|
|
60
|
+
"Content-Type": "application/json"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
return o.error ? e("Failed to verify registration: " + o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
65
|
+
} catch (n) {
|
|
66
|
+
return e("Registration error", n);
|
|
19
67
|
}
|
|
20
68
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Handles user login using WebAuthn passkeys.
|
|
71
|
+
* @param username The username to log in.
|
|
72
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
73
|
+
*/
|
|
74
|
+
async login(t) {
|
|
75
|
+
var i;
|
|
76
|
+
const r = this.validateUsername(t);
|
|
77
|
+
if (r.error) return e(r.error);
|
|
78
|
+
try {
|
|
79
|
+
const n = await c.post(this.url.endpoint("login/begin"), {
|
|
80
|
+
body: JSON.stringify({ username: r }),
|
|
81
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
82
|
+
});
|
|
83
|
+
if (n.error)
|
|
84
|
+
return e("Failed to start login", n.error);
|
|
85
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
86
|
+
if (!s) return e("No challenge found");
|
|
87
|
+
const a = await u({
|
|
88
|
+
optionsJSON: s.publicKey
|
|
89
|
+
}), o = await c.post(
|
|
90
|
+
this.url.endpoint("login/finish"),
|
|
91
|
+
{
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
username: r,
|
|
94
|
+
credential: a
|
|
95
|
+
}),
|
|
96
|
+
headers: {
|
|
97
|
+
credentials: "include",
|
|
98
|
+
"Content-Type": "application/json"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
return o.error ? e("Failed to verify login", o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
103
|
+
} catch (n) {
|
|
104
|
+
return e("Login error", n);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Handles conditional login (without username) for existing users.
|
|
109
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
110
|
+
*/
|
|
111
|
+
async conditionalLogin() {
|
|
112
|
+
var t, r;
|
|
113
|
+
try {
|
|
114
|
+
const i = await c.get(this.url.endpoint("conditional-login/begin"), {
|
|
115
|
+
headers: { credentials: "include" }
|
|
116
|
+
});
|
|
117
|
+
if (i.error)
|
|
118
|
+
return e("Failed to start login", i.error);
|
|
119
|
+
const n = (t = i.result) == null ? void 0 : t.challenge;
|
|
120
|
+
if (!n) return e("No challenge found");
|
|
121
|
+
const s = await u({
|
|
122
|
+
optionsJSON: n.publicKey
|
|
123
|
+
}), a = await c.post(
|
|
124
|
+
this.url.endpoint("conditional-login/finish"),
|
|
125
|
+
{
|
|
126
|
+
body: JSON.stringify({
|
|
127
|
+
login_id: (r = i.result) == null ? void 0 : r.login_id,
|
|
128
|
+
credential: s
|
|
129
|
+
}),
|
|
130
|
+
headers: {
|
|
131
|
+
credentials: "include",
|
|
132
|
+
"Content-Type": "application/json"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
return a.error ? e("Failed to verify login", a.error) : a.result ? (this.token = a.result.token, this.userName = a.result.gardenUserName, l(a.result)) : e("No verification result found");
|
|
137
|
+
} catch (i) {
|
|
138
|
+
return e("Conditional login error", i);
|
|
139
|
+
}
|
|
24
140
|
}
|
|
25
141
|
}
|
|
26
142
|
export {
|
|
27
|
-
|
|
143
|
+
y as PasskeyLogin
|
|
28
144
|
};
|
package/dist/index14.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r{constructor(){this.memory=new Map}getItem(e){return this.memory.has(e)?this.memory.get(e):null}setItem(e,t){this.memory.set(e,t)}removeItem(e){this.memory.has(e)&&this.memory.delete(e)}}exports.MemoryStorage=r;
|
package/dist/index14.js
CHANGED
|
@@ -1,144 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class y {
|
|
5
|
-
constructor(t, r) {
|
|
6
|
-
if (this.storeKey = "passkey-auth", !window)
|
|
7
|
-
throw new Error("Passkey is only supported in the browser environment.");
|
|
8
|
-
this.url = t.endpoint("passkey"), this.store = r;
|
|
1
|
+
class m {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.memory = /* @__PURE__ */ new Map();
|
|
9
4
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return l({ token: this.token, gardenUserName: this.userName });
|
|
13
|
-
const t = this.store.getItem(this.storeKey);
|
|
14
|
-
if (t) {
|
|
15
|
-
const r = JSON.parse(t);
|
|
16
|
-
return l(r);
|
|
17
|
-
}
|
|
18
|
-
return e("Passkey is not set");
|
|
5
|
+
getItem(e) {
|
|
6
|
+
return this.memory.has(e) ? this.memory.get(e) : null;
|
|
19
7
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @param username The username to validate.
|
|
23
|
-
* @returns Result<string, string> - Ok if valid, Err with message if invalid.
|
|
24
|
-
*/
|
|
25
|
-
validateUsername(t) {
|
|
26
|
-
return !t || t.length === 0 ? e("Username cannot be empty") : t.length < 3 || t.length > 32 ? e("Username must be between 3 and 32 characters") : t.includes(" ") ? e("Username cannot contain spaces") : l(t.trim().toLowerCase());
|
|
8
|
+
setItem(e, t) {
|
|
9
|
+
this.memory.set(e, t);
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @param username The username to register.
|
|
31
|
-
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
32
|
-
*/
|
|
33
|
-
async register(t) {
|
|
34
|
-
var i;
|
|
35
|
-
const r = this.validateUsername(t);
|
|
36
|
-
if (r.error) return e(r.error);
|
|
37
|
-
try {
|
|
38
|
-
const n = await c.post(this.url.endpoint("register/begin"), {
|
|
39
|
-
body: JSON.stringify({ username: r }),
|
|
40
|
-
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
41
|
-
});
|
|
42
|
-
if (n.error)
|
|
43
|
-
return e("Failed to start registration", n.error);
|
|
44
|
-
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
45
|
-
if (!s) return e("No challenge found");
|
|
46
|
-
if (!s.publicKey.authenticatorSelection)
|
|
47
|
-
return e("No authenticator selection found");
|
|
48
|
-
s.publicKey.authenticatorSelection.requireResidentKey = !0, s.publicKey.authenticatorSelection.residentKey = "required";
|
|
49
|
-
const a = await d({
|
|
50
|
-
optionsJSON: s.publicKey
|
|
51
|
-
}), o = await c.post(
|
|
52
|
-
this.url.endpoint("register/finish"),
|
|
53
|
-
{
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
username: r,
|
|
56
|
-
credential: a
|
|
57
|
-
}),
|
|
58
|
-
headers: {
|
|
59
|
-
credentials: "include",
|
|
60
|
-
"Content-Type": "application/json"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
return o.error ? e("Failed to verify registration: " + o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
65
|
-
} catch (n) {
|
|
66
|
-
return e("Registration error", n);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Handles user login using WebAuthn passkeys.
|
|
71
|
-
* @param username The username to log in.
|
|
72
|
-
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
73
|
-
*/
|
|
74
|
-
async login(t) {
|
|
75
|
-
var i;
|
|
76
|
-
const r = this.validateUsername(t);
|
|
77
|
-
if (r.error) return e(r.error);
|
|
78
|
-
try {
|
|
79
|
-
const n = await c.post(this.url.endpoint("login/begin"), {
|
|
80
|
-
body: JSON.stringify({ username: r }),
|
|
81
|
-
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
82
|
-
});
|
|
83
|
-
if (n.error)
|
|
84
|
-
return e("Failed to start login", n.error);
|
|
85
|
-
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
86
|
-
if (!s) return e("No challenge found");
|
|
87
|
-
const a = await u({
|
|
88
|
-
optionsJSON: s.publicKey
|
|
89
|
-
}), o = await c.post(
|
|
90
|
-
this.url.endpoint("login/finish"),
|
|
91
|
-
{
|
|
92
|
-
body: JSON.stringify({
|
|
93
|
-
username: r,
|
|
94
|
-
credential: a
|
|
95
|
-
}),
|
|
96
|
-
headers: {
|
|
97
|
-
credentials: "include",
|
|
98
|
-
"Content-Type": "application/json"
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
return o.error ? e("Failed to verify login", o.error) : o.result ? (this.token = o.result.token, this.userName = r.val, l(o.result)) : e("No verification result found");
|
|
103
|
-
} catch (n) {
|
|
104
|
-
return e("Login error", n);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Handles conditional login (without username) for existing users.
|
|
109
|
-
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
110
|
-
*/
|
|
111
|
-
async conditionalLogin() {
|
|
112
|
-
var t, r;
|
|
113
|
-
try {
|
|
114
|
-
const i = await c.get(this.url.endpoint("conditional-login/begin"), {
|
|
115
|
-
headers: { credentials: "include" }
|
|
116
|
-
});
|
|
117
|
-
if (i.error)
|
|
118
|
-
return e("Failed to start login", i.error);
|
|
119
|
-
const n = (t = i.result) == null ? void 0 : t.challenge;
|
|
120
|
-
if (!n) return e("No challenge found");
|
|
121
|
-
const s = await u({
|
|
122
|
-
optionsJSON: n.publicKey
|
|
123
|
-
}), a = await c.post(
|
|
124
|
-
this.url.endpoint("conditional-login/finish"),
|
|
125
|
-
{
|
|
126
|
-
body: JSON.stringify({
|
|
127
|
-
login_id: (r = i.result) == null ? void 0 : r.login_id,
|
|
128
|
-
credential: s
|
|
129
|
-
}),
|
|
130
|
-
headers: {
|
|
131
|
-
credentials: "include",
|
|
132
|
-
"Content-Type": "application/json"
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
return a.error ? e("Failed to verify login", a.error) : a.result ? (this.token = a.result.token, this.userName = a.result.gardenUserName, l(a.result)) : e("No verification result found");
|
|
137
|
-
} catch (i) {
|
|
138
|
-
return e("Conditional login error", i);
|
|
139
|
-
}
|
|
11
|
+
removeItem(e) {
|
|
12
|
+
this.memory.has(e) && this.memory.delete(e);
|
|
140
13
|
}
|
|
141
14
|
}
|
|
142
15
|
export {
|
|
143
|
-
|
|
16
|
+
m as MemoryStorage
|
|
144
17
|
};
|
package/dist/index15.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.AUTH_TOKEN="auth_token",e))(t||{});exports.StoreKeys=t;
|
package/dist/index15.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
constructor() {
|
|
3
|
-
this.memory = /* @__PURE__ */ new Map();
|
|
4
|
-
}
|
|
5
|
-
getItem(e) {
|
|
6
|
-
return this.memory.has(e) ? this.memory.get(e) : null;
|
|
7
|
-
}
|
|
8
|
-
setItem(e, t) {
|
|
9
|
-
this.memory.set(e, t);
|
|
10
|
-
}
|
|
11
|
-
removeItem(e) {
|
|
12
|
-
this.memory.has(e) && this.memory.delete(e);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
|
|
15
2
|
export {
|
|
16
|
-
|
|
3
|
+
t as StoreKeys
|
|
17
4
|
};
|
package/dist/index16.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./index5.cjs"),a=require("./index30.cjs"),s=require("./index27.cjs"),l=require("./index31.cjs"),b=require("./index25.cjs"),n={42161:s.mainnet,421614:a.sepolia},h=async r=>{const{chain:e}=r;if(!e)return c.Err("No chain found");const o=(u=>u in n)(e.id)?n[e.id]:e;return await i(o)},i=async r=>{const e=l.createPublicClient({chain:r,transport:b.http()});try{const t=await e.getBlockNumber();return c.Ok(Number(t))}catch(t){return c.Err("Failed to fetch evm block number",t)}};exports._fetchEVMBlockNumber=i;exports.fetchEVMBlockNumber=h;
|
package/dist/index16.js
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { Err as c, Ok as a } from "./index5.js";
|
|
2
|
+
import { sepolia as m } from "./index30.js";
|
|
3
|
+
import { mainnet as s } from "./index27.js";
|
|
4
|
+
import { createPublicClient as u } from "./index31.js";
|
|
5
|
+
import { http as l } from "./index25.js";
|
|
6
|
+
const n = {
|
|
7
|
+
42161: s,
|
|
8
|
+
421614: m
|
|
9
|
+
}, C = async (o) => {
|
|
10
|
+
const { chain: t } = o;
|
|
11
|
+
if (!t) return c("No chain found");
|
|
12
|
+
const e = ((i) => i in n)(t.id) ? n[t.id] : t;
|
|
13
|
+
return await b(e);
|
|
14
|
+
}, b = async (o) => {
|
|
15
|
+
const t = u({
|
|
16
|
+
chain: o,
|
|
17
|
+
transport: l()
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
const r = await t.getBlockNumber();
|
|
21
|
+
return a(Number(r));
|
|
22
|
+
} catch (r) {
|
|
23
|
+
return c("Failed to fetch evm block number", r);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
2
26
|
export {
|
|
3
|
-
|
|
27
|
+
b as _fetchEVMBlockNumber,
|
|
28
|
+
C as fetchEVMBlockNumber
|
|
4
29
|
};
|
package/dist/index17.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class n{constructor(){this.listeners=new Map}emit(e,...t){(this.listeners.get(e)??[]).forEach(i=>{i(...t)})}on(e,t){const s=this.listeners.get(e)??[];s.push(t),this.listeners.set(e,s)}off(e,t){const s=this.listeners.get(e)??[],i=s.indexOf(t);i!==-1&&s.splice(i,1)}}exports.EventBroker=n;
|
package/dist/index17.js
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { createPublicClient as u } from "./index31.js";
|
|
5
|
-
import { http as l } from "./index27.js";
|
|
6
|
-
const n = {
|
|
7
|
-
42161: s,
|
|
8
|
-
421614: m
|
|
9
|
-
}, C = async (o) => {
|
|
10
|
-
const { chain: t } = o;
|
|
11
|
-
if (!t) return c("No chain found");
|
|
12
|
-
const e = ((i) => i in n)(t.id) ? n[t.id] : t;
|
|
13
|
-
return await b(e);
|
|
14
|
-
}, b = async (o) => {
|
|
15
|
-
const t = u({
|
|
16
|
-
chain: o,
|
|
17
|
-
transport: l()
|
|
18
|
-
});
|
|
19
|
-
try {
|
|
20
|
-
const r = await t.getBlockNumber();
|
|
21
|
-
return a(Number(r));
|
|
22
|
-
} catch (r) {
|
|
23
|
-
return c("Failed to fetch evm block number", r);
|
|
1
|
+
class r {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
24
4
|
}
|
|
25
|
-
|
|
5
|
+
emit(s, ...t) {
|
|
6
|
+
(this.listeners.get(s) ?? []).forEach((i) => {
|
|
7
|
+
i(...t);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
on(s, t) {
|
|
11
|
+
const e = this.listeners.get(s) ?? [];
|
|
12
|
+
e.push(t), this.listeners.set(s, e);
|
|
13
|
+
}
|
|
14
|
+
off(s, t) {
|
|
15
|
+
const e = this.listeners.get(s) ?? [], i = e.indexOf(t);
|
|
16
|
+
i !== -1 && e.splice(i, 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
26
19
|
export {
|
|
27
|
-
|
|
28
|
-
C as fetchEVMBlockNumber
|
|
20
|
+
r as EventBroker
|
|
29
21
|
};
|
package/dist/index18.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index28.cjs"),u=require("./index29.cjs");class l{static async _postWithFallback(a,t){let r="";for(const n of a)try{const s=await fetch(n,{method:"POST",...t});if(s.status>=500){r=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){r=o(s);continue}throw new Error(r||"All APIs failed")}static async postWithFallback(a,t){return await c(t).retry(()=>this._postWithFallback(a,t))}static async _getWithFallback(a,t){let r="";for(const n of a)try{const s=await fetch(n,t);if(s.status>=500){r=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){r=o(s);continue}throw new Error(r||"All APIs failed")}static async getWithFallback(a,t){return await c(t).retry(()=>this._getWithFallback(a,t))}static async _get(a,t){return await this.parse(await fetch(a,t))}static async get(a,t){return await c(t).retry(()=>this._get(a,t))}static async _post(a,t){return await this.parse(await fetch(a,{method:"POST",...t}))}static async post(a,t){return await c(t).retry(()=>this._post(a,t))}static async parse(a){const t=await a.text();if(a.status>=200&&a.status<300)return u.safeParseJson(t);throw new Error(t)}}function o(e){return(e==null?void 0:e.message)||(e==null?void 0:e.toString())||"unknown error"}const c=e=>new i.Retry((e==null?void 0:e.retryCount)??2,(e==null?void 0:e.retryDelay)??1e3);exports.Fetcher=l;
|
package/dist/index18.js
CHANGED
|
@@ -1,21 +1,109 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Retry as h } from "./index28.js";
|
|
2
|
+
import { safeParseJson as i } from "./index29.js";
|
|
3
|
+
class w {
|
|
4
|
+
static async _postWithFallback(a, t) {
|
|
5
|
+
let r = "";
|
|
6
|
+
for (const o of a)
|
|
7
|
+
try {
|
|
8
|
+
const e = await fetch(o, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
...t
|
|
11
|
+
});
|
|
12
|
+
if (e.status >= 500) {
|
|
13
|
+
r = await (e.text() || e.json());
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
return await this.parse(e);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
r = n(e);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(r || "All APIs failed");
|
|
4
22
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Asynchronously sends a POST request to multiple URLs with fallback logic.
|
|
25
|
+
*
|
|
26
|
+
* @param {string[]} input - array of URLs to send the POST request to
|
|
27
|
+
* @param {RequestInit} [init] - optional request initialization options
|
|
28
|
+
* @return {Promise<T>} a Promise that resolves to the parsed response data
|
|
29
|
+
*/
|
|
30
|
+
static async postWithFallback(a, t) {
|
|
31
|
+
return await c(t).retry(
|
|
32
|
+
() => this._postWithFallback(a, t)
|
|
33
|
+
);
|
|
9
34
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
static async _getWithFallback(a, t) {
|
|
36
|
+
let r = "";
|
|
37
|
+
for (const o of a)
|
|
38
|
+
try {
|
|
39
|
+
const e = await fetch(o, t);
|
|
40
|
+
if (e.status >= 500) {
|
|
41
|
+
r = await (e.text() || e.json());
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
return await this.parse(e);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
r = n(e);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
throw new Error(r || "All APIs failed");
|
|
13
50
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Asynchronously sends a POST request to multiple URLs with fallback mechanism.
|
|
53
|
+
*
|
|
54
|
+
* @param {string[]} input - An array of URLs to retrieve data from.
|
|
55
|
+
* @param {RequestInit} [init] - Optional request options.
|
|
56
|
+
* @return {Promise<T>} A promise that resolves to the retrieved data.
|
|
57
|
+
*/
|
|
58
|
+
static async getWithFallback(a, t) {
|
|
59
|
+
return await c(t).retry(
|
|
60
|
+
() => this._getWithFallback(a, t)
|
|
61
|
+
);
|
|
17
62
|
}
|
|
63
|
+
static async _get(a, t) {
|
|
64
|
+
return await this.parse(await fetch(a, t));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Asynchronously retrieves data of type T from the specified URL or RequestInfo, with optional initialization options.
|
|
68
|
+
*
|
|
69
|
+
* @param {RequestInfo | URL} input - The URL or RequestInfo to fetch data from
|
|
70
|
+
* @param {RequestInit} init - Optional initialization options for the fetch request
|
|
71
|
+
* @return {Promise<T>} The retrieved data of type T
|
|
72
|
+
*/
|
|
73
|
+
static async get(a, t) {
|
|
74
|
+
return await c(t).retry(() => this._get(a, t));
|
|
75
|
+
}
|
|
76
|
+
static async _post(a, t) {
|
|
77
|
+
return await this.parse(
|
|
78
|
+
await fetch(a, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
...t
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Asynchronously sends a POST request to the specified URL or RequestInfo, with optional initialization options.
|
|
86
|
+
*/
|
|
87
|
+
static async post(a, t) {
|
|
88
|
+
return await c(t).retry(() => this._post(a, t));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Parses the response and returns the result as the specified type.
|
|
92
|
+
*
|
|
93
|
+
* @param {Response} res - the response object to be parsed
|
|
94
|
+
* @return {Promise<T>} the parsed result of type T
|
|
95
|
+
*/
|
|
96
|
+
static async parse(a) {
|
|
97
|
+
const t = await a.text();
|
|
98
|
+
if (a.status >= 200 && a.status < 300)
|
|
99
|
+
return i(t);
|
|
100
|
+
throw new Error(t);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function n(s) {
|
|
104
|
+
return (s == null ? void 0 : s.message) || (s == null ? void 0 : s.toString()) || "unknown error";
|
|
18
105
|
}
|
|
106
|
+
const c = (s) => new h((s == null ? void 0 : s.retryCount) ?? 2, (s == null ? void 0 : s.retryDelay) ?? 1e3);
|
|
19
107
|
export {
|
|
20
|
-
|
|
108
|
+
w as Fetcher
|
|
21
109
|
};
|
package/dist/index24.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 i=require("./index47.cjs"),c=require("./index101.cjs");function r(e){const{key:t="wallet",name:l="Wallet Client",transport:n}=e;return i.createClient({...e,key:t,name:l,transport:n,type:"walletClient"}).extend(c.walletActions)}exports.createWalletClient=r;
|
package/dist/index24.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @param {() => Promise<T>} fn - The function to retry
|
|
14
|
-
* @return {Promise<T>} a Promise that resolves to the result of the function
|
|
15
|
-
*/
|
|
16
|
-
async retry(e) {
|
|
17
|
-
let t = 0, r;
|
|
18
|
-
for (; t < this.maxRetries + 1; )
|
|
19
|
-
try {
|
|
20
|
-
return await e();
|
|
21
|
-
} catch (a) {
|
|
22
|
-
t++, r = a, await s(this.delay * t);
|
|
23
|
-
}
|
|
24
|
-
throw r;
|
|
25
|
-
}
|
|
1
|
+
import { createClient as i } from "./index47.js";
|
|
2
|
+
import { walletActions as o } from "./index101.js";
|
|
3
|
+
function m(t) {
|
|
4
|
+
const { key: e = "wallet", name: l = "Wallet Client", transport: n } = t;
|
|
5
|
+
return i({
|
|
6
|
+
...t,
|
|
7
|
+
key: e,
|
|
8
|
+
name: l,
|
|
9
|
+
transport: n,
|
|
10
|
+
type: "walletClient"
|
|
11
|
+
}).extend(o);
|
|
26
12
|
}
|
|
27
13
|
export {
|
|
28
|
-
|
|
14
|
+
m as createWalletClient
|
|
29
15
|
};
|
package/dist/index25.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("./index50.cjs"),E=require("./index51.cjs"),F=require("./index52.cjs"),H=require("./index53.cjs"),U=require("./index54.cjs");function _(k,r={}){const{batch:o,fetchOptions:u,key:l="http",methods:h,name:q="HTTP JSON-RPC",onFetchRequest:d,onFetchResponse:y,retryDelay:R,raw:f}=r;return({chain:n,retryCount:w,timeout:S})=>{const{batchSize:m=1e3,wait:C=0}=typeof o=="object"?o:{},b=r.retryCount??w,c=S??r.timeout??1e4,e=n==null?void 0:n.rpcUrls.default.http[0];if(!e)throw new E.UrlRequiredError;const a=H.getHttpRpcClient(e,{fetchOptions:u,onRequest:d,onResponse:y,timeout:c});return U.createTransport({key:l,methods:h,name:q,async request({method:T,params:B}){const i={method:T,params:B},{schedule:O}=F.createBatchScheduler({id:e,wait:C,shouldSplitBatch(t){return t.length>m},fn:t=>a.request({body:t}),sort:(t,g)=>t.id-g.id}),P=async t=>o?O(t):[await a.request({body:t})],[{error:s,result:p}]=await P(i);if(f)return{error:s,result:p};if(s)throw new j.RpcRequestError({body:i,error:s,url:e});return p},retryCount:b,retryDelay:R,timeout:c,type:"http"},{fetchOptions:u,url:e})}}exports.http=_;
|