@gardenfi/utils 2.0.4 → 2.0.6-beta.1
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 +35 -24
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +42 -32
- package/dist/index100.cjs +1 -0
- package/dist/index100.js +4 -0
- package/dist/index101.cjs +1 -0
- package/dist/index101.js +7 -0
- package/dist/index102.cjs +1 -0
- package/dist/index102.js +13 -0
- package/dist/index103.cjs +1 -0
- package/dist/index103.js +23 -0
- package/dist/index104.cjs +1 -0
- package/dist/index104.js +9 -0
- package/dist/index105.cjs +1 -0
- package/dist/index105.js +7 -0
- package/dist/index106.cjs +1 -0
- package/dist/index106.js +40 -0
- package/dist/index107.cjs +1 -0
- package/dist/index107.js +130 -0
- package/dist/index108.cjs +1 -0
- package/dist/index108.js +4 -0
- package/dist/index109.cjs +2 -0
- package/dist/index109.js +5 -0
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +21 -14
- package/dist/index110.cjs +1 -0
- package/dist/index110.js +70 -0
- package/dist/index111.cjs +1 -0
- package/dist/index111.js +72 -0
- package/dist/index112.cjs +1 -0
- package/dist/index112.js +4 -0
- package/dist/index113.cjs +1 -0
- package/dist/index113.js +37 -0
- package/dist/index114.cjs +1 -0
- package/dist/index114.js +43 -0
- package/dist/index115.cjs +1 -0
- package/dist/index115.js +646 -0
- package/dist/index116.cjs +1 -0
- package/dist/index116.js +234 -0
- package/dist/index117.cjs +1 -0
- package/dist/index117.js +175 -0
- package/dist/index118.cjs +1 -0
- package/dist/index118.js +21 -0
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +126 -173
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +14 -93
- package/dist/index14.cjs +1 -16
- package/dist/index14.js +2 -114
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +33 -31
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +19 -31
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +188 -17
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +93 -7
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +35 -20
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +32 -22
- package/dist/index21.cjs +16 -1
- package/dist/index21.js +113 -8
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +30 -31
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +17 -26
- package/dist/index24.cjs +1 -1
- package/dist/index24.js +6 -22
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +44 -50
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +21 -12
- package/dist/index27.cjs +1 -1
- package/dist/index27.js +8 -24
- package/dist/index28.cjs +1 -1
- package/dist/index28.js +31 -75
- package/dist/index29.cjs +1 -1
- package/dist/index29.js +25 -22
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +30 -7
- package/dist/index30.cjs +2 -1
- package/dist/index30.js +65 -7
- package/dist/index31.cjs +1 -1
- package/dist/index31.js +51 -32
- package/dist/index32.cjs +1 -1
- package/dist/index32.js +12 -15
- package/dist/index33.cjs +1 -1
- package/dist/index33.js +25 -2
- package/dist/index34.cjs +1 -1
- package/dist/index34.js +75 -8
- package/dist/index35.cjs +1 -1
- package/dist/index35.js +23 -20
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +7 -12
- package/dist/index37.cjs +1 -1
- package/dist/index37.js +32 -34
- package/dist/index38.cjs +1 -2
- package/dist/index38.js +15 -59
- package/dist/index39.cjs +1 -1
- package/dist/index39.js +2 -2
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +2 -2
- package/dist/index40.cjs +1 -1
- package/dist/index40.js +8 -4
- package/dist/index41.cjs +1 -1
- package/dist/index41.js +20 -11
- package/dist/index42.cjs +1 -1
- package/dist/index42.js +41 -3
- package/dist/index43.cjs +1 -1
- package/dist/index43.js +25 -21
- package/dist/index44.cjs +1 -1
- package/dist/index44.js +6 -12
- package/dist/index45.cjs +1 -1
- package/dist/index45.js +13 -55
- package/dist/index46.cjs +1 -1
- package/dist/index46.js +15 -6
- package/dist/index47.cjs +1 -1
- package/dist/index47.js +5 -21
- package/dist/index48.cjs +1 -1
- package/dist/index48.js +13 -11
- package/dist/index49.cjs +1 -1
- package/dist/index49.js +10 -3
- package/dist/index50.cjs +1 -1
- package/dist/index50.js +10 -9
- package/dist/index51.cjs +1 -1
- package/dist/index51.js +11 -19
- package/dist/index52.cjs +1 -1
- package/dist/index52.js +13 -6
- package/dist/index53.cjs +1 -1
- package/dist/index53.js +55 -8
- package/dist/index54.cjs +1 -1
- package/dist/index54.js +16 -104
- package/dist/index55.cjs +1 -1
- package/dist/index55.js +5 -28
- package/dist/index56.cjs +1 -1
- package/dist/index56.js +8 -18
- package/dist/index57.cjs +1 -1
- package/dist/index57.js +165 -32
- package/dist/index58.cjs +1 -0
- package/dist/index58.js +106 -0
- package/dist/index59.cjs +1 -0
- package/dist/index59.js +24 -0
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +45 -22
- package/dist/index60.cjs +1 -0
- package/dist/index60.js +15 -0
- package/dist/index61.cjs +1 -0
- package/dist/index61.js +37 -0
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +9 -0
- package/dist/index63.cjs +2 -0
- package/dist/index63.js +62 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +4 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +9 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +7 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +14 -0
- package/dist/index68.cjs +5 -0
- package/dist/index68.js +59 -0
- package/dist/index69.cjs +2 -0
- package/dist/index69.js +37 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +19 -104
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +8 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +6 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +24 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +11 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +13 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +14 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +9 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +16 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +35 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +17 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +2 -15
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +67 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +30 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +5 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +194 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +21 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +6 -0
- package/dist/index86.cjs +1 -0
- package/dist/index86.js +11 -0
- package/dist/index87.cjs +1 -0
- package/dist/index87.js +115 -0
- package/dist/index88.cjs +1 -0
- package/dist/index88.js +19 -0
- package/dist/index89.cjs +1 -0
- package/dist/index89.js +226 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +100 -2
- package/dist/index90.cjs +1 -0
- package/dist/index90.js +45 -0
- package/dist/index91.cjs +1 -0
- package/dist/index91.js +107 -0
- package/dist/index92.cjs +1 -0
- package/dist/index92.js +20 -0
- package/dist/index93.cjs +1 -0
- package/dist/index93.js +81 -0
- package/dist/index94.cjs +1 -0
- package/dist/index94.js +21 -0
- package/dist/index95.cjs +1 -0
- package/dist/index95.js +11 -0
- package/dist/index96.cjs +1 -0
- package/dist/index96.js +15 -0
- package/dist/index97.cjs +1 -0
- package/dist/index97.js +14 -0
- package/dist/index98.cjs +1 -0
- package/dist/index98.js +22 -0
- package/dist/index99.cjs +1 -0
- package/dist/index99.js +41 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/auth/apikey/apikey.d.ts +12 -0
- package/dist/src/lib/auth/auth.types.d.ts +21 -8
- package/dist/src/lib/auth/index.d.ts +5 -1
- package/dist/src/lib/auth/passkey/passkey.d.ts +10 -0
- package/dist/src/lib/auth/passkey/passkey.types.d.ts +17 -0
- package/dist/src/lib/auth/passkey/passkeyLogin.d.ts +37 -0
- package/dist/src/lib/auth/{siwe.d.ts → siwe/siwe.d.ts} +5 -15
- package/dist/src/lib/digestKey/digestKey.d.ts +12 -0
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +3 -1
package/dist/index12.js
CHANGED
|
@@ -1,190 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { Ok as l, Err as e, Fetcher as c } from "./index17.js";
|
|
2
|
+
import { startRegistration as d, startAuthentication as u } from "@simplewebauthn/browser";
|
|
3
|
+
class f {
|
|
4
|
+
constructor(t, r) {
|
|
5
|
+
if (this.storeKey = "passkey-auth", !window)
|
|
6
|
+
throw new Error("Passkey is only supported in the browser environment.");
|
|
7
|
+
this.url = t.endpoint("passkey"), this.store = r;
|
|
8
|
+
}
|
|
9
|
+
getPasskeyFromStore() {
|
|
10
|
+
if (this.token && this.userName)
|
|
11
|
+
return l({ token: this.token, gardenUserName: this.userName });
|
|
12
|
+
const t = this.store.getItem(this.storeKey);
|
|
13
|
+
if (t) {
|
|
14
|
+
const r = JSON.parse(t);
|
|
15
|
+
return l(r);
|
|
16
|
+
}
|
|
17
|
+
return e("Passkey is not set");
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
* @return {Promise<T>} a Promise that resolves to the result of the function
|
|
20
|
+
* Validates the username according to predefined rules.
|
|
21
|
+
* @param username The username to validate.
|
|
22
|
+
* @returns Result<string, string> - Ok if valid, Err with message if invalid.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (; a < this.maxRetries + 1; )
|
|
27
|
-
try {
|
|
28
|
-
return await t();
|
|
29
|
-
} catch (i) {
|
|
30
|
-
a++, r = i, await d(this.delay * a);
|
|
31
|
-
}
|
|
32
|
-
throw r;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const v = (e) => {
|
|
36
|
-
try {
|
|
37
|
-
return JSON.parse(e);
|
|
38
|
-
} catch {
|
|
39
|
-
return e;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
class m {
|
|
43
|
-
static async _postWithFallback(t, a) {
|
|
44
|
-
let r = "";
|
|
45
|
-
for (const i of t)
|
|
46
|
-
try {
|
|
47
|
-
const s = await fetch(i, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
...a
|
|
50
|
-
});
|
|
51
|
-
if (s.status >= 500) {
|
|
52
|
-
r = await (s.text() || s.json());
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
return await this.parse(s);
|
|
56
|
-
} catch (s) {
|
|
57
|
-
r = y(s);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
throw new Error(r || "All APIs failed");
|
|
24
|
+
validateUsername(t) {
|
|
25
|
+
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());
|
|
61
26
|
}
|
|
62
27
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
66
|
-
* @param {RequestInit} [init] - optional request initialization options
|
|
67
|
-
* @return {Promise<T>} a Promise that resolves to the parsed response data
|
|
28
|
+
* Handles user registration using WebAuthn passkeys.
|
|
29
|
+
* @param username The username to register.
|
|
30
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
68
31
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
32
|
+
async register(t) {
|
|
33
|
+
var i;
|
|
34
|
+
const r = this.validateUsername(t);
|
|
35
|
+
if (r.error) return e(r.error);
|
|
36
|
+
try {
|
|
37
|
+
const n = await c.post(this.url.endpoint("register/begin"), {
|
|
38
|
+
body: JSON.stringify({ username: r }),
|
|
39
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
40
|
+
});
|
|
41
|
+
if (n.error)
|
|
42
|
+
return e("Failed to start registration", n.error);
|
|
43
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
44
|
+
if (!s) return e("No challenge found");
|
|
45
|
+
if (!s.publicKey.authenticatorSelection)
|
|
46
|
+
return e("No authenticator selection found");
|
|
47
|
+
s.publicKey.authenticatorSelection.requireResidentKey = !0, s.publicKey.authenticatorSelection.residentKey = "required";
|
|
48
|
+
const a = await d({
|
|
49
|
+
optionsJSON: s.publicKey
|
|
50
|
+
}), o = await c.post(
|
|
51
|
+
this.url.endpoint("register/finish"),
|
|
52
|
+
{
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
username: r,
|
|
55
|
+
credential: a
|
|
56
|
+
}),
|
|
57
|
+
headers: {
|
|
58
|
+
credentials: "include",
|
|
59
|
+
"Content-Type": "application/json"
|
|
60
|
+
}
|
|
82
61
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
throw new Error(r || "All APIs failed");
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Asynchronously sends a POST request to multiple URLs with fallback mechanism.
|
|
92
|
-
*
|
|
93
|
-
* @param {string[]} input - An array of URLs to retrieve data from.
|
|
94
|
-
* @param {RequestInit} [init] - Optional request options.
|
|
95
|
-
* @return {Promise<T>} A promise that resolves to the retrieved data.
|
|
96
|
-
*/
|
|
97
|
-
static async getWithFallback(t, a) {
|
|
98
|
-
return await n(a).retry(
|
|
99
|
-
() => this._getWithFallback(t, a)
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
static async _get(t, a) {
|
|
103
|
-
return await this.parse(await fetch(t, a));
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Asynchronously retrieves data of type T from the specified URL or RequestInfo, with optional initialization options.
|
|
107
|
-
*
|
|
108
|
-
* @param {RequestInfo | URL} input - The URL or RequestInfo to fetch data from
|
|
109
|
-
* @param {RequestInit} init - Optional initialization options for the fetch request
|
|
110
|
-
* @return {Promise<T>} The retrieved data of type T
|
|
111
|
-
*/
|
|
112
|
-
static async get(t, a) {
|
|
113
|
-
return await n(a).retry(() => this._get(t, a));
|
|
114
|
-
}
|
|
115
|
-
static async _post(t, a) {
|
|
116
|
-
return await this.parse(
|
|
117
|
-
await fetch(t, {
|
|
118
|
-
method: "POST",
|
|
119
|
-
...a
|
|
120
|
-
})
|
|
121
|
-
);
|
|
62
|
+
);
|
|
63
|
+
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");
|
|
64
|
+
} catch (n) {
|
|
65
|
+
return e("Registration error", n);
|
|
66
|
+
}
|
|
122
67
|
}
|
|
123
68
|
/**
|
|
124
|
-
*
|
|
69
|
+
* Handles user login using WebAuthn passkeys.
|
|
70
|
+
* @param username The username to log in.
|
|
71
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
125
72
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
73
|
+
async login(t) {
|
|
74
|
+
var i;
|
|
75
|
+
const r = this.validateUsername(t);
|
|
76
|
+
if (r.error) return e(r.error);
|
|
77
|
+
try {
|
|
78
|
+
const n = await c.post(this.url.endpoint("login/begin"), {
|
|
79
|
+
body: JSON.stringify({ username: r }),
|
|
80
|
+
headers: { credentials: "include", "Content-Type": "application/json" }
|
|
81
|
+
});
|
|
82
|
+
if (n.error)
|
|
83
|
+
return e("Failed to start login", n.error);
|
|
84
|
+
const s = (i = n.result) == null ? void 0 : i.challenge;
|
|
85
|
+
if (!s) return e("No challenge found");
|
|
86
|
+
const a = await u({
|
|
87
|
+
optionsJSON: s.publicKey
|
|
88
|
+
}), o = await c.post(
|
|
89
|
+
this.url.endpoint("login/finish"),
|
|
90
|
+
{
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
username: r,
|
|
93
|
+
credential: a
|
|
94
|
+
}),
|
|
95
|
+
headers: {
|
|
96
|
+
credentials: "include",
|
|
97
|
+
"Content-Type": "application/json"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
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");
|
|
102
|
+
} catch (n) {
|
|
103
|
+
return e("Login error", n);
|
|
104
|
+
}
|
|
128
105
|
}
|
|
129
106
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param {Response} res - the response object to be parsed
|
|
133
|
-
* @return {Promise<T>} the parsed result of type T
|
|
107
|
+
* Handles conditional login (without username) for existing users.
|
|
108
|
+
* @returns AsyncResult<PasskeyToken, string> - Ok if successful, Err if failed.
|
|
134
109
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
110
|
+
async conditionalLogin() {
|
|
111
|
+
var t, r;
|
|
112
|
+
try {
|
|
113
|
+
const i = await c.get(this.url.endpoint("conditional-login/begin"), {
|
|
114
|
+
headers: { credentials: "include" }
|
|
115
|
+
});
|
|
116
|
+
if (i.error)
|
|
117
|
+
return e("Failed to start login", i.error);
|
|
118
|
+
const n = (t = i.result) == null ? void 0 : t.challenge;
|
|
119
|
+
if (!n) return e("No challenge found");
|
|
120
|
+
const s = await u({
|
|
121
|
+
optionsJSON: n.publicKey
|
|
122
|
+
}), a = await c.post(
|
|
123
|
+
this.url.endpoint("conditional-login/finish"),
|
|
124
|
+
{
|
|
125
|
+
body: JSON.stringify({
|
|
126
|
+
login_id: (r = i.result) == null ? void 0 : r.login_id,
|
|
127
|
+
credential: s
|
|
128
|
+
}),
|
|
129
|
+
headers: {
|
|
130
|
+
credentials: "include",
|
|
131
|
+
"Content-Type": "application/json"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
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");
|
|
136
|
+
} catch (i) {
|
|
137
|
+
return e("Conditional login error", i);
|
|
138
|
+
}
|
|
159
139
|
}
|
|
160
140
|
}
|
|
161
|
-
o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap();
|
|
162
|
-
const k = (e) => new f(!0, e), W = (e, ...t) => {
|
|
163
|
-
if (typeof e == "string" && t && t.length > 0) {
|
|
164
|
-
let a = [e, ...t].map((r) => {
|
|
165
|
-
if (r) {
|
|
166
|
-
if (r instanceof Error)
|
|
167
|
-
return r.message;
|
|
168
|
-
if (typeof r == "string")
|
|
169
|
-
return r;
|
|
170
|
-
if (r != null && r.toString)
|
|
171
|
-
return r.toString();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
return new f(
|
|
175
|
-
!1,
|
|
176
|
-
null,
|
|
177
|
-
a.filter((r) => r !== void 0).join(" ")
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
return new f(!1, null, e);
|
|
181
|
-
};
|
|
182
141
|
export {
|
|
183
|
-
|
|
184
|
-
m as Fetcher,
|
|
185
|
-
k as Ok,
|
|
186
|
-
f as Result,
|
|
187
|
-
g as Retry,
|
|
188
|
-
v as safeParseJson,
|
|
189
|
-
d as sleep
|
|
142
|
+
f as PasskeyLogin
|
|
190
143
|
};
|
package/dist/index13.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/index13.js
CHANGED
|
@@ -1,96 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
hash: m,
|
|
15
|
-
onReplaced: y,
|
|
16
|
-
pollingInterval: B = o.pollingInterval,
|
|
17
|
-
retryCount: k = 6,
|
|
18
|
-
retryDelay: N = ({ count: b }) => ~~(1 << b) * 200,
|
|
19
|
-
// exponential backoff
|
|
20
|
-
timeout: w = 18e4
|
|
21
|
-
}) {
|
|
22
|
-
const b = G(["waitForTransactionReceipt", o.uid, m]);
|
|
23
|
-
let c, n, r, i = !1;
|
|
24
|
-
const { promise: h, resolve: F, reject: g } = z(), E = w ? setTimeout(() => g(new M({ hash: m })), w) : void 0, _ = q(b, { onReplaced: y, resolve: F, reject: g }, (t) => {
|
|
25
|
-
const j = f(o, K, "watchBlockNumber")({
|
|
26
|
-
emitMissed: !0,
|
|
27
|
-
emitOnBegin: !0,
|
|
28
|
-
poll: !0,
|
|
29
|
-
pollingInterval: B,
|
|
30
|
-
async onBlockNumber(I) {
|
|
31
|
-
const l = (p) => {
|
|
32
|
-
clearTimeout(E), j(), p(), _();
|
|
33
|
-
};
|
|
34
|
-
let u = I;
|
|
35
|
-
if (!i)
|
|
36
|
-
try {
|
|
37
|
-
if (r) {
|
|
38
|
-
if (a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a))
|
|
39
|
-
return;
|
|
40
|
-
l(() => t.resolve(r));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
if (c || (i = !0, await v(async () => {
|
|
44
|
-
c = await f(o, J, "getTransaction")({ hash: m }), c.blockNumber && (u = c.blockNumber);
|
|
45
|
-
}, {
|
|
46
|
-
delay: N,
|
|
47
|
-
retryCount: k
|
|
48
|
-
}), i = !1), r = await f(o, R, "getTransactionReceipt")({ hash: m }), a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a))
|
|
49
|
-
return;
|
|
50
|
-
l(() => t.resolve(r));
|
|
51
|
-
} catch (p) {
|
|
52
|
-
if (p instanceof O || p instanceof W) {
|
|
53
|
-
if (!c) {
|
|
54
|
-
i = !1;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
n = c, i = !0;
|
|
59
|
-
const d = await v(() => f(o, H, "getBlock")({
|
|
60
|
-
blockNumber: u,
|
|
61
|
-
includeTransactions: !0
|
|
62
|
-
}), {
|
|
63
|
-
delay: N,
|
|
64
|
-
retryCount: k,
|
|
65
|
-
shouldRetry: ({ error: s }) => s instanceof A
|
|
66
|
-
});
|
|
67
|
-
i = !1;
|
|
68
|
-
const e = d.transactions.find(({ from: s, nonce: x }) => s === n.from && x === n.nonce);
|
|
69
|
-
if (!e || (r = await f(o, R, "getTransactionReceipt")({
|
|
70
|
-
hash: e.hash
|
|
71
|
-
}), a > 1 && (!r.blockNumber || u - r.blockNumber + 1n < a)))
|
|
72
|
-
return;
|
|
73
|
-
let T = "replaced";
|
|
74
|
-
e.to === n.to && e.value === n.value && e.input === n.input ? T = "repriced" : e.from === e.to && e.value === 0n && (T = "cancelled"), l(() => {
|
|
75
|
-
var s;
|
|
76
|
-
(s = t.onReplaced) == null || s.call(t, {
|
|
77
|
-
reason: T,
|
|
78
|
-
replacedTransaction: n,
|
|
79
|
-
transaction: e,
|
|
80
|
-
transactionReceipt: r
|
|
81
|
-
}), t.resolve(r);
|
|
82
|
-
});
|
|
83
|
-
} catch (d) {
|
|
84
|
-
l(() => t.reject(d));
|
|
85
|
-
}
|
|
86
|
-
} else
|
|
87
|
-
l(() => t.reject(p));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
return h;
|
|
1
|
+
class m {
|
|
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
|
+
}
|
|
93
14
|
}
|
|
94
15
|
export {
|
|
95
|
-
|
|
16
|
+
m as MemoryStorage
|
|
96
17
|
};
|
package/dist/index14.cjs
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
2
|
-
`))throw new e.SiweInvalidMessageFieldError({field:"statement",metaMessages:["- Statement must not include '\\n'.","",`Provided value: ${t}`]})}const $=M.getAddress(r.address),v=i?`${i}://${s}`:s,I=r.statement?`${r.statement}
|
|
3
|
-
`:"",S=`${v} wants you to sign in with your Ethereum account:
|
|
4
|
-
${$}
|
|
5
|
-
|
|
6
|
-
${I}`;let n=`URI: ${c}
|
|
7
|
-
Version: ${d}
|
|
8
|
-
Chain ID: ${o}
|
|
9
|
-
Nonce: ${a}
|
|
10
|
-
Issued At: ${m.toISOString()}`;if(l&&(n+=`
|
|
11
|
-
Expiration Time: ${l.toISOString()}`),f&&(n+=`
|
|
12
|
-
Not Before: ${f.toISOString()}`),w&&(n+=`
|
|
13
|
-
Request ID: ${w}`),g){let t=`
|
|
14
|
-
Resources:`;for(const u of g){if(!h.isUri(u))throw new e.SiweInvalidMessageFieldError({field:"resources",metaMessages:["- Every resource must be a RFC 3986 URI.","- See https://www.rfc-editor.org/rfc/rfc3986","",`Provided value: ${u}`]});t+=`
|
|
15
|
-
- ${u}`}n+=t}return`${S}
|
|
16
|
-
${n}`}const E=/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/,F=/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/,b=/^localhost(:[0-9]{1,5})?$/,A=/^[a-zA-Z0-9]{8,}$/,P=/^([a-zA-Z][a-zA-Z0-9+-.]*)$/;exports.createSiweMessage=R;
|
|
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/index14.js
CHANGED
|
@@ -1,116 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { getAddress as S } from "./index43.js";
|
|
3
|
-
import { isUri as $ } from "./index51.js";
|
|
4
|
-
function C(n) {
|
|
5
|
-
const { chainId: i, domain: s, expirationTime: u, issuedAt: g = /* @__PURE__ */ new Date(), nonce: a, notBefore: m, requestId: h, resources: w, scheme: o, uri: c, version: f } = n;
|
|
6
|
-
{
|
|
7
|
-
if (i !== Math.floor(i))
|
|
8
|
-
throw new e({
|
|
9
|
-
field: "chainId",
|
|
10
|
-
metaMessages: [
|
|
11
|
-
"- Chain ID must be a EIP-155 chain ID.",
|
|
12
|
-
"- See https://eips.ethereum.org/EIPS/eip-155",
|
|
13
|
-
"",
|
|
14
|
-
`Provided value: ${i}`
|
|
15
|
-
]
|
|
16
|
-
});
|
|
17
|
-
if (!(p.test(s) || M.test(s) || x.test(s)))
|
|
18
|
-
throw new e({
|
|
19
|
-
field: "domain",
|
|
20
|
-
metaMessages: [
|
|
21
|
-
"- Domain must be an RFC 3986 authority.",
|
|
22
|
-
"- See https://www.rfc-editor.org/rfc/rfc3986",
|
|
23
|
-
"",
|
|
24
|
-
`Provided value: ${s}`
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
if (!A.test(a))
|
|
28
|
-
throw new e({
|
|
29
|
-
field: "nonce",
|
|
30
|
-
metaMessages: [
|
|
31
|
-
"- Nonce must be at least 8 characters.",
|
|
32
|
-
"- Nonce must be alphanumeric.",
|
|
33
|
-
"",
|
|
34
|
-
`Provided value: ${a}`
|
|
35
|
-
]
|
|
36
|
-
});
|
|
37
|
-
if (!$(c))
|
|
38
|
-
throw new e({
|
|
39
|
-
field: "uri",
|
|
40
|
-
metaMessages: [
|
|
41
|
-
"- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.",
|
|
42
|
-
"- See https://www.rfc-editor.org/rfc/rfc3986",
|
|
43
|
-
"",
|
|
44
|
-
`Provided value: ${c}`
|
|
45
|
-
]
|
|
46
|
-
});
|
|
47
|
-
if (f !== "1")
|
|
48
|
-
throw new e({
|
|
49
|
-
field: "version",
|
|
50
|
-
metaMessages: [
|
|
51
|
-
"- Version must be '1'.",
|
|
52
|
-
"",
|
|
53
|
-
`Provided value: ${f}`
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
if (o && !P.test(o))
|
|
57
|
-
throw new e({
|
|
58
|
-
field: "scheme",
|
|
59
|
-
metaMessages: [
|
|
60
|
-
"- Scheme must be an RFC 3986 URI scheme.",
|
|
61
|
-
"- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1",
|
|
62
|
-
"",
|
|
63
|
-
`Provided value: ${o}`
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
const t = n.statement;
|
|
67
|
-
if (t != null && t.includes(`
|
|
68
|
-
`))
|
|
69
|
-
throw new e({
|
|
70
|
-
field: "statement",
|
|
71
|
-
metaMessages: [
|
|
72
|
-
"- Statement must not include '\\n'.",
|
|
73
|
-
"",
|
|
74
|
-
`Provided value: ${t}`
|
|
75
|
-
]
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const l = S(n.address), v = o ? `${o}://${s}` : s, I = n.statement ? `${n.statement}
|
|
79
|
-
` : "", R = `${v} wants you to sign in with your Ethereum account:
|
|
80
|
-
${l}
|
|
81
|
-
|
|
82
|
-
${I}`;
|
|
83
|
-
let r = `URI: ${c}
|
|
84
|
-
Version: ${f}
|
|
85
|
-
Chain ID: ${i}
|
|
86
|
-
Nonce: ${a}
|
|
87
|
-
Issued At: ${g.toISOString()}`;
|
|
88
|
-
if (u && (r += `
|
|
89
|
-
Expiration Time: ${u.toISOString()}`), m && (r += `
|
|
90
|
-
Not Before: ${m.toISOString()}`), h && (r += `
|
|
91
|
-
Request ID: ${h}`), w) {
|
|
92
|
-
let t = `
|
|
93
|
-
Resources:`;
|
|
94
|
-
for (const d of w) {
|
|
95
|
-
if (!$(d))
|
|
96
|
-
throw new e({
|
|
97
|
-
field: "resources",
|
|
98
|
-
metaMessages: [
|
|
99
|
-
"- Every resource must be a RFC 3986 URI.",
|
|
100
|
-
"- See https://www.rfc-editor.org/rfc/rfc3986",
|
|
101
|
-
"",
|
|
102
|
-
`Provided value: ${d}`
|
|
103
|
-
]
|
|
104
|
-
});
|
|
105
|
-
t += `
|
|
106
|
-
- ${d}`;
|
|
107
|
-
}
|
|
108
|
-
r += t;
|
|
109
|
-
}
|
|
110
|
-
return `${R}
|
|
111
|
-
${r}`;
|
|
112
|
-
}
|
|
113
|
-
const p = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/, M = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/, x = /^localhost(:[0-9]{1,5})?$/, A = /^[a-zA-Z0-9]{8,}$/, P = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
|
|
1
|
+
var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
|
|
114
2
|
export {
|
|
115
|
-
|
|
3
|
+
t as StoreKeys
|
|
116
4
|
};
|
package/dist/index15.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 r=require("./index17.cjs"),n=require("viem"),s=require("./index20.cjs"),l=require("./index22.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/index15.js
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
address: "0xce01f8eee7E479C928F8919abD53E553a36CeF67",
|
|
24
|
-
blockCreated: 19258213
|
|
25
|
-
},
|
|
26
|
-
multicall3: {
|
|
27
|
-
address: "0xca11bde05977b3631167028862be2a173976ca11",
|
|
28
|
-
blockCreated: 14353601
|
|
29
|
-
}
|
|
1
|
+
import { Err as o, Ok as n } from "./index17.js";
|
|
2
|
+
import { createPublicClient as s, http as m } from "viem";
|
|
3
|
+
import { mainnet as u } from "./index20.js";
|
|
4
|
+
import { sepolia as b } from "./index22.js";
|
|
5
|
+
const e = {
|
|
6
|
+
42161: u,
|
|
7
|
+
421614: b
|
|
8
|
+
}, N = async (r) => {
|
|
9
|
+
const { chain: t } = r;
|
|
10
|
+
if (!t) return o("No chain found");
|
|
11
|
+
const i = ((a) => a in e)(t.id) ? e[t.id] : t;
|
|
12
|
+
return await l(i);
|
|
13
|
+
}, l = async (r) => {
|
|
14
|
+
const t = s({
|
|
15
|
+
chain: r,
|
|
16
|
+
transport: m()
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
const c = await t.getBlockNumber();
|
|
20
|
+
return n(Number(c));
|
|
21
|
+
} catch (c) {
|
|
22
|
+
return o("Failed to fetch evm block number", c);
|
|
30
23
|
}
|
|
31
|
-
})
|
|
24
|
+
}, C = async (r) => {
|
|
25
|
+
try {
|
|
26
|
+
const t = await r.getLatestTip();
|
|
27
|
+
return n(t);
|
|
28
|
+
} catch (t) {
|
|
29
|
+
return o("Failed to fetch bitcoin block number", t);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
l as _fetchEVMBlockNumber,
|
|
34
|
+
C as fetchBitcoinBlockNumber,
|
|
35
|
+
N as fetchEVMBlockNumber
|
|
34
36
|
};
|