@use-glyph/sdk-react 2.1.12 → 2.2.0
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/README.md +58 -1
- package/dist/EIP1193Strategy.js +375 -123
- package/dist/EIP1193Strategy.js.map +1 -1
- package/dist/PrivyStrategy.js +112 -103
- package/dist/PrivyStrategy.js.map +1 -1
- package/dist/glyph-widget.es.js +3 -3
- package/dist/glyph-widget.umd.js +31 -111
- package/dist/glyph-widget.umd.js.map +1 -1
- package/dist/index.js +8205 -7448
- package/dist/index.js.map +1 -1
- package/dist/types/components/ui/drawer.d.ts +9 -11
- package/dist/types/context/glyphDataQuery.d.ts +11 -0
- package/dist/types/context/strategies/privyWallet.d.ts +11 -0
- package/dist/types/hooks/useBalancesForChain.d.ts +1 -1
- package/dist/types/hooks/useGlyph.d.ts +5 -1
- package/dist/types/hooks/useRelayQuote.d.ts +15 -15
- package/dist/types/hooks/useRelayTokenList.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib/walletAuth.d.ts +15 -0
- package/dist/types/lib/walletAuthSession.d.ts +36 -0
- package/dist/types/types/GlyphWidgetTypes.d.ts +10 -1
- package/package.json +21 -10
package/README.md
CHANGED
|
@@ -6,9 +6,66 @@ Dashboard ⚙️: [https://useglyph.io/](https://useglyph.io/)
|
|
|
6
6
|
|
|
7
7
|
Documentation 📝: [https://docs.useglyph.io/](https://docs.useglyph.io/)
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Wallet compatibility (2.2.0)
|
|
10
|
+
|
|
11
|
+
Tested with wagmi `2.19.5`, viem `2.57.5`, RainbowKit `2.2.11`,
|
|
12
|
+
Privy React `3.48.1`, Privy wagmi `4.0.19`, and Relay SDK `3.2.0`.
|
|
13
|
+
Keep the app's Relay version aligned when passing `RelayChain` values to Glyph.
|
|
14
|
+
Privy uses nested viem `2.56.5`; do not force a global viem override.
|
|
15
|
+
|
|
16
|
+
React 18 and 19 are supported. ConnectKit `1.9.2` requires React 18.
|
|
17
|
+
Dynamic's Glyph connector `4.5.0` requires cross-app-connect `0.2.3`;
|
|
18
|
+
other tested adapters use cross-app-connect `0.7.3`.
|
|
19
|
+
Do not force those separate adapter generations onto one version.
|
|
20
|
+
|
|
21
|
+
See the integration-specific installation commands in the documentation.
|
|
22
|
+
The examples cover native, Privy, RainbowKit, ConnectKit, cross-app, and Dynamic integrations.
|
|
23
|
+
User login and wallet confirmation remain required; installing this SDK does not
|
|
24
|
+
grant an agent permission to sign or send transactions.
|
|
25
|
+
|
|
26
|
+
## Dependency security
|
|
27
|
+
|
|
28
|
+
Wallet peers remain external to the SDK bundle. Compatibility is not a clean-audit
|
|
29
|
+
guarantee. Audit the consuming application's resolved dependency graph, including
|
|
30
|
+
its wallet adapters. Overrides in the SDK source workspace do not propagate to
|
|
31
|
+
consuming applications. See the [security policy and guidance](https://github.com/yuga-labs/glyph-sdk-react/blob/main/SECURITY.md).
|
|
32
|
+
Legacy Dynamic/Solana dependencies still include an unpatched `bigint-buffer`
|
|
33
|
+
advisory; track its upstream replacement before enabling affected server-side code.
|
|
34
|
+
|
|
35
|
+
## SDK diagnostics
|
|
10
36
|
|
|
11
37
|
SDK debug and informational logs are disabled by default. Warnings and errors remain visible.
|
|
12
38
|
Import `setGlyphDebugLogging` from `@use-glyph/sdk-react` and call it with `true` for temporary diagnostics.
|
|
13
39
|
Call it with `false` to disable diagnostics again. Third-party wallet logging is separate.
|
|
14
40
|
Authentication logs never contain signatures, tokens, nonces, or raw provider errors.
|
|
41
|
+
|
|
42
|
+
## Wallet sign-in and recovery
|
|
43
|
+
|
|
44
|
+
For the EIP1193 strategy, `useGlyph()` exposes `signIn(): Promise<boolean>`,
|
|
45
|
+
`needsSignature`, and `authError`. Existing `login()` uses the same sign-in path.
|
|
46
|
+
Call `signIn()` directly from a fresh click; do not await a fetch first. It returns
|
|
47
|
+
`false` if message preparation is pending, a popup needs activation, or sign-in
|
|
48
|
+
fails. Wait for `ready`, then offer another click. `askForSignature={false}` prepares
|
|
49
|
+
only; it never automatically signs. A rejected or blocked attempt never starts an
|
|
50
|
+
automatic signing retry loop.
|
|
51
|
+
|
|
52
|
+
`onAuthError` receives only a static reason (`popup_blocked`, `rejected`,
|
|
53
|
+
`verify_failed`, or `network`), message and optional `retryAt`. No alert or raw
|
|
54
|
+
provider error is exposed. A 429 blocks authentication requests and signing until
|
|
55
|
+
`Retry-After`; missing headers use bounded backoff. A current credential's 401
|
|
56
|
+
clears that session and prepares a message for manual retry. A 403 does not log out,
|
|
57
|
+
and late old responses cannot revoke replacement credentials.
|
|
58
|
+
|
|
59
|
+
Persistence binds the wallet, API origin and connector family (`id`, `type`).
|
|
60
|
+
Recreating wagmi configuration on reload can restore that scoped credential without
|
|
61
|
+
another signature. Live callbacks also bind the connector instance (`uid`): a
|
|
62
|
+
committed live scope change revokes old callbacks, forgets the old record and
|
|
63
|
+
requires sign-in. Normal unmount and StrictMode replay retain persistence; explicit
|
|
64
|
+
logout and external disconnect clear it. Restored credentials still face server
|
|
65
|
+
session checks. Legacy unbound token/nonce records are cleared, so an existing user
|
|
66
|
+
may need one new sign-in; the SDK does not guess their wallet or origin binding.
|
|
67
|
+
|
|
68
|
+
Privy retains its existing login and wallet-selection behavior. Its `signIn()`
|
|
69
|
+
returns `true` when the login call completes, which does not guarantee an EVM wallet
|
|
70
|
+
or Glyph authentication. Check `authenticated` for wallet/API readiness. Privy
|
|
71
|
+
reports `needsSignature: false` and `authError: null`.
|
package/dist/EIP1193Strategy.js
CHANGED
|
@@ -1,153 +1,405 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import { useAccount as
|
|
4
|
-
import { c as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsx as U } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as O, useMemo as q, useSyncExternalStore as z, useEffect as W, useCallback as D } from "react";
|
|
3
|
+
import { useAccount as $, useDisconnect as B, useSignMessage as K, useSignTypedData as X, useSendTransaction as H, useAccountEffect as Q } from "wagmi";
|
|
4
|
+
import { c as V, g as Y, G as Z, W as ee, b as te } from "./index.js";
|
|
5
|
+
class v extends Error {
|
|
6
|
+
constructor(n, a, s) {
|
|
7
|
+
super(a), this.reason = n, this.retryAfterMs = s;
|
|
8
|
+
}
|
|
9
|
+
reason;
|
|
10
|
+
retryAfterMs;
|
|
11
|
+
}
|
|
12
|
+
function re(t) {
|
|
13
|
+
try {
|
|
14
|
+
const n = new URL(t);
|
|
15
|
+
return ["http:", "https:"].includes(n.protocol) && !n.username && !n.password ? n.origin : null;
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function j() {
|
|
21
|
+
return typeof navigator > "u" ? !1 : navigator.userActivation?.isActive ?? !0;
|
|
22
|
+
}
|
|
23
|
+
function ne(t) {
|
|
24
|
+
try {
|
|
25
|
+
let n = t;
|
|
26
|
+
for (let a = 0; n && a < 5; a++) {
|
|
27
|
+
const s = n, c = [s.message, s.details].filter((f) => typeof f == "string").map((f) => f.slice(0, 4096)).join(" ");
|
|
28
|
+
if (s.code === 4001 || /user (rejected|denied|cancel)/i.test(c))
|
|
29
|
+
return new v("rejected", "The signature request was rejected.");
|
|
30
|
+
if (/failed to initialize request|popup.*block|pop-up.*block/i.test(c))
|
|
31
|
+
return new v("popup_blocked", "Open sign-in from a click to allow the wallet popup.");
|
|
32
|
+
n = s.cause;
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
return new v("network", "The signature request failed.");
|
|
37
|
+
}
|
|
38
|
+
async function ae(t, n, a) {
|
|
39
|
+
if (t.status === 429) {
|
|
40
|
+
const u = t.headers.get("Retry-After");
|
|
41
|
+
t.body?.cancel().catch(() => {
|
|
42
|
+
});
|
|
43
|
+
const S = u?.trim() ? Number(u) : NaN, E = u ? Date.parse(u) : NaN, k = Number.isFinite(S) && S >= 0 ? S * 1e3 : Number.isFinite(E) ? Math.max(0, E - Date.now()) : 0;
|
|
44
|
+
throw new v(
|
|
45
|
+
"network",
|
|
46
|
+
"Sign-in is rate limited. Try again later.",
|
|
47
|
+
Number.isSafeInteger(k) && k > 0 ? k : 0
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (!t.ok)
|
|
51
|
+
throw t.body?.cancel().catch(() => {
|
|
52
|
+
}), new v(n, "The authentication request was rejected.");
|
|
53
|
+
const s = t.body?.getReader();
|
|
54
|
+
if (!s) throw new v(n, "The authentication response was invalid.");
|
|
55
|
+
const c = () => {
|
|
56
|
+
s.cancel().catch(() => {
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
a.addEventListener("abort", c, { once: !0 }), a.aborted && c();
|
|
60
|
+
const f = [];
|
|
61
|
+
let r = 0;
|
|
62
|
+
try {
|
|
63
|
+
for (; ; ) {
|
|
64
|
+
if (a.aborted) throw new v("network", "The authentication request timed out.");
|
|
65
|
+
const u = await s.read();
|
|
66
|
+
if (a.aborted) throw new v("network", "The authentication request timed out.");
|
|
67
|
+
if (u.done) break;
|
|
68
|
+
if (r += u.value.byteLength, r > 65536) throw new v(n, "The authentication response was invalid.");
|
|
69
|
+
f.push(u.value);
|
|
70
|
+
}
|
|
71
|
+
} finally {
|
|
72
|
+
a.removeEventListener("abort", c), c(), s.releaseLock();
|
|
73
|
+
}
|
|
74
|
+
const h = new Uint8Array(r);
|
|
75
|
+
let y = 0;
|
|
76
|
+
for (const u of f)
|
|
77
|
+
h.set(u, y), y += u.byteLength;
|
|
78
|
+
let d;
|
|
79
|
+
try {
|
|
80
|
+
d = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(h));
|
|
81
|
+
} catch {
|
|
82
|
+
throw new v(n, "The authentication response was invalid.");
|
|
83
|
+
}
|
|
84
|
+
if (!d || typeof d != "object" || Array.isArray(d))
|
|
85
|
+
throw new v("network", "The authentication response was invalid.");
|
|
86
|
+
return d;
|
|
87
|
+
}
|
|
88
|
+
const R = (t, n) => typeof t == "string" && t.trim().length > 0 && t.length <= n;
|
|
89
|
+
async function J(t, n, a, s) {
|
|
90
|
+
const c = new AbortController(), f = c.signal, r = () => c.abort();
|
|
91
|
+
a.aborted ? r() : a.addEventListener("abort", r, { once: !0 });
|
|
92
|
+
const h = performance.now(), y = setTimeout(() => c.abort(), 1e4);
|
|
93
|
+
try {
|
|
94
|
+
const d = await fetch(t, { ...n, signal: f, redirect: "error", credentials: "omit" }), u = await ae(d, s, f);
|
|
95
|
+
if (f.aborted || performance.now() - h >= 1e4)
|
|
96
|
+
throw new v("network", "The authentication request timed out.");
|
|
97
|
+
return u;
|
|
98
|
+
} finally {
|
|
99
|
+
a.removeEventListener("abort", r), clearTimeout(y), c.abort();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function se(t, n, a) {
|
|
103
|
+
const s = await J(new URL(`/api/widget/auth/message/${n}`, t), {}, a, "network");
|
|
104
|
+
if (!R(s.message, 16384) || !R(s.nonce, 1024))
|
|
105
|
+
throw new v("network", "The sign-in message was invalid.");
|
|
106
|
+
return { message: s.message, nonce: s.nonce };
|
|
107
|
+
}
|
|
108
|
+
async function oe(t, n, a, s, c) {
|
|
109
|
+
const f = await J(
|
|
110
|
+
new URL(`/api/widget/auth/verify/${n}`, t),
|
|
111
|
+
{
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json" },
|
|
114
|
+
body: JSON.stringify({ signature: a, nonce: s })
|
|
115
|
+
},
|
|
116
|
+
c,
|
|
117
|
+
"verify_failed"
|
|
118
|
+
);
|
|
119
|
+
if (!R(f.token, 16384))
|
|
120
|
+
throw new v("verify_failed", "Signature verification returned no token.");
|
|
121
|
+
return f.token;
|
|
122
|
+
}
|
|
123
|
+
function ie(t) {
|
|
124
|
+
return t instanceof v ? { reason: t.reason, message: t.message } : { reason: "network", message: "Authentication failed." };
|
|
125
|
+
}
|
|
126
|
+
function ce(t) {
|
|
127
|
+
let n = !1, a = 0, s = !1, c = !1, f = !1, r, h, y = 0, d = 0, u = new AbortController(), S, E;
|
|
128
|
+
const k = /* @__PURE__ */ new Set(), I = `__glyph-wallet-session-v2__:${JSON.stringify([t.origin, t.address.toLowerCase(), t.connector])}`;
|
|
129
|
+
let _ = Object.freeze({
|
|
130
|
+
generation: a,
|
|
131
|
+
ready: !1,
|
|
132
|
+
authenticated: !1,
|
|
133
|
+
needsSignature: !1,
|
|
134
|
+
authError: null,
|
|
135
|
+
apiFetch: null
|
|
136
|
+
});
|
|
137
|
+
const i = (e = a) => n && a === e && t.isCurrent(), w = (e) => {
|
|
138
|
+
_ = Object.freeze({ ..._, ...e, generation: a });
|
|
139
|
+
for (const o of k) o();
|
|
140
|
+
}, N = (e) => {
|
|
15
141
|
try {
|
|
16
|
-
|
|
142
|
+
t.storage && e(t.storage);
|
|
17
143
|
} catch {
|
|
18
|
-
return a.warn("Error reading session token"), null;
|
|
19
144
|
}
|
|
20
|
-
}
|
|
21
|
-
if (typeof window > "u")
|
|
22
|
-
return null;
|
|
145
|
+
}, x = (e) => {
|
|
23
146
|
try {
|
|
24
|
-
|
|
147
|
+
e();
|
|
25
148
|
} catch {
|
|
26
|
-
return a.warn("Error reading session nonce"), null;
|
|
27
149
|
}
|
|
28
|
-
})
|
|
29
|
-
|
|
150
|
+
}, l = (e, o) => async (b, A) => {
|
|
151
|
+
const T = () => {
|
|
152
|
+
if (!i(o) || r !== e) throw new Error("Glyph wallet session changed");
|
|
153
|
+
};
|
|
154
|
+
T();
|
|
155
|
+
let g;
|
|
30
156
|
try {
|
|
31
|
-
|
|
157
|
+
if (g = new URL(b, t.origin), g.origin !== t.origin || g.username || g.password) throw new Error();
|
|
32
158
|
} catch {
|
|
33
|
-
|
|
159
|
+
throw new Error("Unsupported Glyph request URL");
|
|
34
160
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
161
|
+
const p = A?.signal ? AbortSignal.any([A.signal, u.signal]) : u.signal, F = await V(t.origin, void 0, {
|
|
162
|
+
Authorization: `Bearer ${e.token}`,
|
|
163
|
+
"x-evm-address": t.address,
|
|
164
|
+
"x-glyph-nonce": e.nonce
|
|
165
|
+
})(g.href, { ...A, signal: p, redirect: "error" });
|
|
166
|
+
return T(), F.status === 401 && (M(!0), P(new v("verify_failed", "The wallet session expired. Sign in again."), a), L()), F;
|
|
167
|
+
}, P = (e, o) => {
|
|
168
|
+
if (!i(o)) return;
|
|
169
|
+
let b = ie(e);
|
|
170
|
+
if (e instanceof v && e.retryAfterMs !== void 0) {
|
|
171
|
+
d++;
|
|
172
|
+
const A = e.retryAfterMs || Math.min(3e4 * 2 ** Math.min(d - 1, 5), 6e5);
|
|
173
|
+
y = Math.min(Number.MAX_SAFE_INTEGER, Date.now() + A), b = { ...b, retryAt: y };
|
|
174
|
+
}
|
|
175
|
+
w({ authError: b, needsSignature: !0 }), i(o) && x(() => t.onAuthError(b));
|
|
176
|
+
}, m = (e) => {
|
|
177
|
+
clearTimeout(E), !(!i(e) || !y) && (E = setTimeout(
|
|
178
|
+
() => {
|
|
179
|
+
i(e) && (Date.now() < y ? m(e) : (y = 0, L()));
|
|
180
|
+
},
|
|
181
|
+
Math.max(1, Math.min(2147483647, y - Date.now()))
|
|
182
|
+
));
|
|
183
|
+
}, L = () => {
|
|
184
|
+
if (!i() || r || h || S) return S ?? Promise.resolve();
|
|
185
|
+
const e = a;
|
|
186
|
+
if (Date.now() < y)
|
|
187
|
+
return m(e), Promise.resolve();
|
|
188
|
+
if (f = !0, w({ ready: !1 }), !i(e)) return Promise.resolve();
|
|
189
|
+
const o = se(t.origin, t.address, u.signal).then((b) => {
|
|
190
|
+
i(e) && (h = b);
|
|
191
|
+
}).catch((b) => {
|
|
192
|
+
P(b, e);
|
|
193
|
+
}).finally(() => {
|
|
194
|
+
!i(e) || S !== o || (S = void 0, f = !1, w({ ready: !c, needsSignature: !r }), y && m(e));
|
|
195
|
+
});
|
|
196
|
+
return S = o, o;
|
|
197
|
+
}, M = (e) => {
|
|
198
|
+
a++, u.abort(), u = new AbortController(), clearTimeout(E), r = void 0, h = void 0, S = void 0, c = !1, f = !1, s = !0, e && N((o) => o.removeItem(I)), w({ ready: n, authenticated: !1, apiFetch: null, authError: null, needsSignature: !1 });
|
|
199
|
+
}, C = (e) => {
|
|
200
|
+
if (!i(e) || c) return Promise.resolve(!1);
|
|
201
|
+
if (s = !0, r) return Promise.resolve(!0);
|
|
202
|
+
if (Date.now() < y)
|
|
203
|
+
return w({
|
|
204
|
+
authError: { reason: "network", message: "Sign-in is rate limited. Try again later.", retryAt: y },
|
|
205
|
+
needsSignature: !0
|
|
206
|
+
}), Promise.resolve(!1);
|
|
207
|
+
if (!h)
|
|
208
|
+
return L(), w({ needsSignature: !0 }), Promise.resolve(!1);
|
|
209
|
+
if (t.popup && !(t.activation ?? j)())
|
|
210
|
+
return w({ needsSignature: !0 }), Promise.resolve(!1);
|
|
211
|
+
const o = h;
|
|
212
|
+
if (c = !0, w({ ready: !1, needsSignature: !1, authError: null }), !i(e)) return Promise.resolve(!1);
|
|
213
|
+
let b;
|
|
214
|
+
try {
|
|
215
|
+
b = t.sign(o.message);
|
|
216
|
+
} catch (A) {
|
|
217
|
+
b = Promise.reject(A);
|
|
218
|
+
}
|
|
219
|
+
return (async () => {
|
|
38
220
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
221
|
+
let A;
|
|
222
|
+
try {
|
|
223
|
+
A = await b;
|
|
224
|
+
} catch (g) {
|
|
225
|
+
throw ne(g);
|
|
226
|
+
}
|
|
227
|
+
if (!i(e)) return !1;
|
|
228
|
+
const T = await oe(
|
|
229
|
+
t.origin,
|
|
230
|
+
t.address,
|
|
231
|
+
A,
|
|
232
|
+
o.nonce,
|
|
233
|
+
u.signal
|
|
234
|
+
);
|
|
235
|
+
return i(e) ? (r = { token: T, nonce: o.nonce }, d = 0, y = 0, N((g) => g.setItem(I, JSON.stringify(r))), w({ authenticated: !0, apiFetch: l(r, e), authError: null }), i(e) && x(t.onLogin), i(e) && !!r) : !1;
|
|
236
|
+
} catch (A) {
|
|
237
|
+
return i(e) && (h = void 0, r = void 0, N((T) => T.removeItem(I)), w({ authenticated: !1, apiFetch: null }), P(A, e)), !1;
|
|
238
|
+
} finally {
|
|
239
|
+
i(e) && (c = !1, w({ ready: !f, needsSignature: !r }), r || L());
|
|
44
240
|
}
|
|
241
|
+
})();
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
subscribe(e) {
|
|
245
|
+
return k.add(e), () => {
|
|
246
|
+
k.delete(e);
|
|
247
|
+
};
|
|
45
248
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
249
|
+
getSnapshot: () => _,
|
|
250
|
+
current: i,
|
|
251
|
+
signIn: C,
|
|
252
|
+
automatic() {
|
|
253
|
+
if (!(!i() || s || !h || r || c)) {
|
|
254
|
+
if (t.popup && !(t.activation ?? j)()) {
|
|
255
|
+
s = !0, w({ needsSignature: !0 });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
C(a);
|
|
56
259
|
}
|
|
57
260
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
261
|
+
start() {
|
|
262
|
+
n = !0, N((e) => {
|
|
263
|
+
e.removeItem("__glyph-widget-token__"), e.removeItem("__glyph-widget-nonce__");
|
|
264
|
+
try {
|
|
265
|
+
const o = JSON.parse(e.getItem(I) ?? "null");
|
|
266
|
+
o && typeof o.token == "string" && o.token.trim() && o.token.length <= 16384 && typeof o.nonce == "string" && o.nonce.trim() && o.nonce.length <= 1024 && (r = o);
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}), w({ ready: !0, authenticated: !!r, apiFetch: r ? l(r, a) : null }), r || L();
|
|
270
|
+
},
|
|
271
|
+
stop(e = !1) {
|
|
272
|
+
const o = s;
|
|
273
|
+
n = !1, M(e), s = o;
|
|
274
|
+
},
|
|
275
|
+
logout() {
|
|
276
|
+
i() && M(!0);
|
|
277
|
+
},
|
|
278
|
+
// A replaced instance shares its family's persistence key, but no longer
|
|
279
|
+
// owns it. Committed scope cleanup already forgets the departing record.
|
|
280
|
+
forget() {
|
|
281
|
+
i() && M(!0);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const G = te("EIP1193Strategy"), ge = ({
|
|
286
|
+
children: t,
|
|
287
|
+
glyphUrl: n,
|
|
288
|
+
onLogin: a,
|
|
289
|
+
onLogout: s,
|
|
290
|
+
onAuthError: c,
|
|
291
|
+
askForSignature: f = !0
|
|
292
|
+
}) => {
|
|
293
|
+
const { address: r, isConnected: h, chainId: y, connector: d } = $(), { disconnectAsync: u } = B(), { signMessageAsync: S } = K(), { signTypedDataAsync: E } = X(), { sendTransactionAsync: k } = H(), I = re(n || ee), _ = O(null), i = O({ onLogin: a, onLogout: s, onAuthError: c, signMessageAsync: S });
|
|
294
|
+
i.current = { onLogin: a, onLogout: s, onAuthError: c, signMessageAsync: S };
|
|
295
|
+
const w = O(!1), N = O(null), x = q(
|
|
296
|
+
() => ({ family: JSON.stringify([d?.id, d?.type]), uid: d?.uid }),
|
|
297
|
+
[d?.id, d?.type, d?.uid]
|
|
298
|
+
), l = q(() => {
|
|
299
|
+
const g = ce({
|
|
300
|
+
address: r ?? "",
|
|
301
|
+
origin: I ?? "",
|
|
302
|
+
connector: x.family,
|
|
303
|
+
popup: d?.type === "privy" || d?.id === Y.id,
|
|
304
|
+
isCurrent: () => _.current === g && !!r && h && !!I,
|
|
305
|
+
sign: (p) => i.current.signMessageAsync({ account: r, message: p }),
|
|
306
|
+
onLogin: () => {
|
|
307
|
+
w.current = !1, i.current.onLogin?.();
|
|
308
|
+
},
|
|
309
|
+
onAuthError: (p) => i.current.onAuthError?.(p),
|
|
310
|
+
storage: typeof window > "u" ? void 0 : {
|
|
311
|
+
getItem: (p) => window.localStorage.getItem(p),
|
|
312
|
+
setItem: (p, F) => window.localStorage.setItem(p, F),
|
|
313
|
+
removeItem: (p) => window.localStorage.removeItem(p)
|
|
314
|
+
}
|
|
71
315
|
});
|
|
72
|
-
|
|
73
|
-
}, [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
316
|
+
return g;
|
|
317
|
+
}, [r, h, I, x, d?.type, d?.id]);
|
|
318
|
+
_.current = l;
|
|
319
|
+
const P = h ? l : N.current;
|
|
320
|
+
h && (N.current = l);
|
|
321
|
+
const m = z(l.subscribe, l.getSnapshot, l.getSnapshot);
|
|
322
|
+
W(() => (l.start(), () => l.stop(_.current !== l)), [l]), W(() => {
|
|
323
|
+
f && l.automatic();
|
|
324
|
+
}, [l, m, f]);
|
|
325
|
+
const L = D(() => l.signIn(m.generation), [l, m.generation]), M = D(() => {
|
|
326
|
+
if (!w.current) {
|
|
327
|
+
w.current = !0;
|
|
328
|
+
try {
|
|
329
|
+
i.current.onLogout?.();
|
|
330
|
+
} catch {
|
|
331
|
+
G.error("Logout callback failed");
|
|
332
|
+
}
|
|
80
333
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
334
|
+
}, []), C = D(async () => {
|
|
335
|
+
if (l.current(m.generation)) {
|
|
336
|
+
l.logout(), M();
|
|
337
|
+
try {
|
|
338
|
+
await u();
|
|
339
|
+
} catch {
|
|
340
|
+
G.error("Wallet disconnect failed");
|
|
85
341
|
}
|
|
86
|
-
i(!0);
|
|
87
|
-
const e = await y({ account: t, message: g }), r = (await D(t, e, o))?.token;
|
|
88
|
-
p(r);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
a.error("Authentication failed"), e?.message?.toLowerCase?.().includes?.("user rejected") || await alert(
|
|
91
|
-
"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in."
|
|
92
|
-
), f(null), p(null), w(null);
|
|
93
|
-
} finally {
|
|
94
|
-
i(!1), M?.();
|
|
95
342
|
}
|
|
96
|
-
}, [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const r = e.types, d = e.primaryType, S = e.message;
|
|
110
|
-
return k({ types: r, primaryType: d, message: S });
|
|
343
|
+
}, [l, m.generation, M, u]);
|
|
344
|
+
Q({
|
|
345
|
+
onDisconnect: () => {
|
|
346
|
+
P?.forget(), (_.current === P || !h) && M();
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
const e = D(() => {
|
|
350
|
+
if (!l.current(m.generation)) throw new Error("Glyph wallet session changed");
|
|
351
|
+
}, [l, m.generation]), o = D(
|
|
352
|
+
async ({ message: g }) => {
|
|
353
|
+
e();
|
|
354
|
+
const p = await S({ account: r, message: g });
|
|
355
|
+
return e(), p;
|
|
111
356
|
},
|
|
112
|
-
[
|
|
113
|
-
),
|
|
114
|
-
async ({
|
|
115
|
-
|
|
116
|
-
|
|
357
|
+
[e, r, S]
|
|
358
|
+
), b = D(
|
|
359
|
+
async ({ data: g }) => {
|
|
360
|
+
e();
|
|
361
|
+
const p = await E({
|
|
362
|
+
types: g.types,
|
|
363
|
+
primaryType: g.primaryType,
|
|
364
|
+
message: g.message
|
|
365
|
+
});
|
|
366
|
+
return e(), p;
|
|
117
367
|
},
|
|
118
|
-
[
|
|
119
|
-
),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
368
|
+
[e, E]
|
|
369
|
+
), A = D(
|
|
370
|
+
async ({ transaction: g }) => {
|
|
371
|
+
e();
|
|
372
|
+
const p = await k({
|
|
373
|
+
...g,
|
|
374
|
+
chainId: g.chainId || y
|
|
375
|
+
});
|
|
376
|
+
return e(), p;
|
|
123
377
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
m && n && t && N && o && g && (E(), W(!1));
|
|
129
|
-
}, [n, t, E, N, o, g, m]), /* @__PURE__ */ J(
|
|
130
|
-
U.Provider,
|
|
378
|
+
[e, k, y]
|
|
379
|
+
), T = l.current(m.generation);
|
|
380
|
+
return /* @__PURE__ */ U(
|
|
381
|
+
Z.Provider,
|
|
131
382
|
{
|
|
132
383
|
value: {
|
|
133
|
-
ready:
|
|
134
|
-
authenticated:
|
|
135
|
-
glyphUrl:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
384
|
+
ready: m.ready,
|
|
385
|
+
authenticated: T && m.authenticated,
|
|
386
|
+
glyphUrl: n,
|
|
387
|
+
hideWidget: !h || !r,
|
|
388
|
+
login: L,
|
|
389
|
+
signIn: L,
|
|
390
|
+
needsSignature: T && m.needsSignature,
|
|
391
|
+
authError: T ? m.authError : null,
|
|
392
|
+
logout: C,
|
|
393
|
+
signMessage: o,
|
|
394
|
+
signTypedData: b,
|
|
395
|
+
sendTransaction: A,
|
|
396
|
+
apiFetch: T ? m.apiFetch : null
|
|
145
397
|
},
|
|
146
|
-
children:
|
|
398
|
+
children: t
|
|
147
399
|
}
|
|
148
400
|
);
|
|
149
401
|
};
|
|
150
402
|
export {
|
|
151
|
-
|
|
403
|
+
ge as default
|
|
152
404
|
};
|
|
153
405
|
//# sourceMappingURL=EIP1193Strategy.js.map
|