@powerhousedao/reactor-browser 6.2.2-dev.9 → 6.2.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/README.md +341 -0
- package/dist/attachment-service-KFFLBEuD.d.ts +1062 -0
- package/dist/attachment-service-KFFLBEuD.d.ts.map +1 -0
- package/dist/{client-u13cr-Vg.js → client-B8ezRmBB.js} +30 -3
- package/dist/client-B8ezRmBB.js.map +1 -0
- package/dist/client-BIHN_UyR.d.ts +14 -0
- package/dist/client-BIHN_UyR.d.ts.map +1 -0
- package/dist/{client-_Gh2Uf0E.js → client-D66jVnot.js} +79 -13
- package/dist/client-D66jVnot.js.map +1 -0
- package/dist/{document-by-id-dLYFX-xz.js → document-by-id-BSZqTN66.js} +81 -51
- package/dist/document-by-id-BSZqTN66.js.map +1 -0
- package/dist/document-model-modules-DfQBNGc-.js +419 -0
- package/dist/document-model-modules-DfQBNGc-.js.map +1 -0
- package/dist/document-operations-CBExT76y.js +2544 -0
- package/dist/document-operations-CBExT76y.js.map +1 -0
- package/dist/global-1rvI8VdA.d.ts +400 -0
- package/dist/global-1rvI8VdA.d.ts.map +1 -0
- package/dist/index-BE3wBHLP.d.ts +349 -0
- package/dist/index-BE3wBHLP.d.ts.map +1 -0
- package/dist/index-BIVDXw3K.d.ts +144 -0
- package/dist/index-BIVDXw3K.d.ts.map +1 -0
- package/dist/index.d.ts +385 -718
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +957 -1712
- package/dist/index.js.map +1 -1
- package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-6h5VKAwt.d.ts} +4 -2
- package/dist/inspector-proxy-6h5VKAwt.d.ts.map +1 -0
- package/dist/{make-ph-event-functions-BHoLPif5.js → make-ph-event-functions-DBq3iWYn.js} +1 -1
- package/dist/{make-ph-event-functions-BHoLPif5.js.map → make-ph-event-functions-DBq3iWYn.js.map} +1 -1
- package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-9NDG14dS.d.ts} +2 -142
- package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +1 -0
- package/dist/{relational-Dj06-YkI.js → relational-D4sxGPz7.js} +2 -2
- package/dist/{relational-Dj06-YkI.js.map → relational-D4sxGPz7.js.map} +1 -1
- package/dist/renown-BHxwP7xU.js +97 -0
- package/dist/renown-BHxwP7xU.js.map +1 -0
- package/dist/{renown-D-1c_Bvx.js → renown-BIEv6bSI.js} +523 -57
- package/dist/renown-BIEv6bSI.js.map +1 -0
- package/dist/src/ai/index.d.ts +371 -0
- package/dist/src/ai/index.d.ts.map +1 -0
- package/dist/src/ai/index.js +1067 -0
- package/dist/src/ai/index.js.map +1 -0
- package/dist/src/analytics/index.d.ts +1 -1
- package/dist/src/analytics/index.js +2 -1
- package/dist/src/analytics/index.js.map +1 -1
- package/dist/src/graphql/client.d.ts +3 -2
- package/dist/src/graphql/client.js +1 -1
- package/dist/src/graphql-client/entry.d.ts +4 -0
- package/dist/src/graphql-client/entry.js +4 -0
- package/dist/src/relational/index.d.ts +1 -1
- package/dist/src/relational/index.js +1 -1
- package/dist/src/renown/index.d.ts +2 -2
- package/dist/src/renown/index.js +3 -2
- package/dist/src/rpc/index.d.ts +6 -3
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +41 -10
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/store-BJYcr_FL.js +37 -0
- package/dist/store-BJYcr_FL.js.map +1 -0
- package/dist/switchboard-D4-_jwk-.js +271 -0
- package/dist/switchboard-D4-_jwk-.js.map +1 -0
- package/dist/{types-CPV0Cnsy.d.ts → types-6vDzbRRS.d.ts} +1 -1
- package/dist/{types-CPV0Cnsy.d.ts.map → types-6vDzbRRS.d.ts.map} +1 -1
- package/dist/{client-09xv0Dq6.d.ts → types-Dcv1ZLoW.d.ts} +87 -19
- package/dist/types-Dcv1ZLoW.d.ts.map +1 -0
- package/package.json +27 -10
- package/dist/client-09xv0Dq6.d.ts.map +0 -1
- package/dist/client-_Gh2Uf0E.js.map +0 -1
- package/dist/client-u13cr-Vg.js.map +0 -1
- package/dist/document-by-id-dLYFX-xz.js.map +0 -1
- package/dist/index-D3bV5rcl.d.ts +0 -216
- package/dist/index-D3bV5rcl.d.ts.map +0 -1
- package/dist/index-DS4W07Y8.d.ts.map +0 -1
- package/dist/inspector-proxy-CvQDDxmT.d.ts.map +0 -1
- package/dist/renown-D-1c_Bvx.js.map +0 -1
|
@@ -1,42 +1,105 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { a as useRenown, c as RENOWN_INITIAL_UNKNOWN, i as useLoginStatus, l as RenownInitialUserProvider, n as setRenown, o as useUser, s as RENOWN_INITIAL_ANONYMOUS, t as addRenownEventHandler, u as useRenownInitialAuth } from "./renown-BHxwP7xU.js";
|
|
2
2
|
import { logger } from "document-model";
|
|
3
|
-
import { Children, cloneElement, forwardRef, isValidElement, useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
-
import { BrowserKeyStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, DOMAIN_TYPE, ISSUER_TYPE, RenownBuilder, RenownCryptoBuilder, VERIFIABLE_CREDENTIAL_EIP712_TYPE } from "@renown/sdk";
|
|
3
|
+
import { Children, cloneElement, createContext, forwardRef, isValidElement, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
5
|
+
import { BrowserKeyStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, DOMAIN_TYPE, ISSUER_TYPE, MissingSwitchboardError, RenownBuilder, RenownCryptoBuilder, VERIFIABLE_CREDENTIAL_EIP712_TYPE, readPersistedUser } from "@renown/sdk";
|
|
6
|
+
import { LoginMethod, isWalletRedirectReturn, resolveAdapters } from "@renown/sdk/wallet";
|
|
7
|
+
//#region src/renown/wallet-registry.ts
|
|
8
|
+
let activeWalletController;
|
|
9
|
+
let controllerWaiters = [];
|
|
10
|
+
let walletActivator;
|
|
11
|
+
const activatorListeners = /* @__PURE__ */ new Set();
|
|
12
|
+
function setActiveWalletController(controller) {
|
|
13
|
+
activeWalletController = controller;
|
|
14
|
+
if (controller) {
|
|
15
|
+
const waiters = controllerWaiters;
|
|
16
|
+
controllerWaiters = [];
|
|
17
|
+
waiters.forEach(({ resolve }) => resolve(controller));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function failWalletActivation(error) {
|
|
21
|
+
const waiters = controllerWaiters;
|
|
22
|
+
controllerWaiters = [];
|
|
23
|
+
waiters.forEach(({ reject }) => reject(error));
|
|
24
|
+
}
|
|
25
|
+
function getActiveWalletController() {
|
|
26
|
+
return activeWalletController;
|
|
27
|
+
}
|
|
28
|
+
function setWalletActivator(activator) {
|
|
29
|
+
if (activator === walletActivator) return;
|
|
30
|
+
walletActivator = activator;
|
|
31
|
+
activatorListeners.forEach((listener) => listener());
|
|
32
|
+
}
|
|
33
|
+
function subscribeWalletActivator(listener) {
|
|
34
|
+
activatorListeners.add(listener);
|
|
35
|
+
return () => activatorListeners.delete(listener);
|
|
36
|
+
}
|
|
37
|
+
function getWalletActivator() {
|
|
38
|
+
return walletActivator;
|
|
39
|
+
}
|
|
40
|
+
function whenWalletControllerReady() {
|
|
41
|
+
if (activeWalletController) return Promise.resolve(activeWalletController);
|
|
42
|
+
return new Promise((resolve, reject) => controllerWaiters.push({
|
|
43
|
+
resolve,
|
|
44
|
+
reject
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
const NO_DESCRIPTORS = Object.freeze([]);
|
|
48
|
+
const DESCRIPTOR_STORE = Symbol.for("@powerhousedao/reactor-browser:renown-wallet-descriptors");
|
|
49
|
+
function descriptorStore() {
|
|
50
|
+
const host = globalThis;
|
|
51
|
+
return host[DESCRIPTOR_STORE] ??= {
|
|
52
|
+
descriptors: NO_DESCRIPTORS,
|
|
53
|
+
listeners: /* @__PURE__ */ new Set()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function setWalletDescriptors(descriptors) {
|
|
57
|
+
const store = descriptorStore();
|
|
58
|
+
const next = descriptors ?? NO_DESCRIPTORS;
|
|
59
|
+
if (next === store.descriptors) return;
|
|
60
|
+
if (next.length === 0 && store.descriptors.length === 0) return;
|
|
61
|
+
store.descriptors = next;
|
|
62
|
+
store.listeners.forEach((listener) => listener());
|
|
63
|
+
}
|
|
64
|
+
function getWalletDescriptors() {
|
|
65
|
+
return descriptorStore().descriptors;
|
|
66
|
+
}
|
|
67
|
+
function getServerWalletDescriptors() {
|
|
68
|
+
return NO_DESCRIPTORS;
|
|
69
|
+
}
|
|
70
|
+
function subscribeWalletDescriptors(listener) {
|
|
71
|
+
const { listeners } = descriptorStore();
|
|
72
|
+
listeners.add(listener);
|
|
73
|
+
return () => listeners.delete(listener);
|
|
74
|
+
}
|
|
75
|
+
const NO_CONTROLLERS = Object.freeze({});
|
|
76
|
+
const CONTROLLER_STORE = Symbol.for("@powerhousedao/reactor-browser:renown-wallet-adapter-controllers");
|
|
77
|
+
function controllerStore() {
|
|
78
|
+
const host = globalThis;
|
|
79
|
+
return host[CONTROLLER_STORE] ??= {
|
|
80
|
+
controllers: NO_CONTROLLERS,
|
|
81
|
+
listeners: /* @__PURE__ */ new Set()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function setWalletAdapterController(id, controller) {
|
|
85
|
+
const store = controllerStore();
|
|
86
|
+
if (store.controllers[id] === controller) return;
|
|
87
|
+
const next = { ...store.controllers };
|
|
88
|
+
if (controller) next[id] = controller;
|
|
89
|
+
else delete next[id];
|
|
90
|
+
store.controllers = Object.freeze(next);
|
|
91
|
+
store.listeners.forEach((listener) => listener());
|
|
92
|
+
}
|
|
93
|
+
function getWalletAdapterControllers() {
|
|
94
|
+
return controllerStore().controllers;
|
|
95
|
+
}
|
|
96
|
+
function getServerWalletAdapterControllers() {
|
|
97
|
+
return NO_CONTROLLERS;
|
|
98
|
+
}
|
|
99
|
+
function subscribeWalletAdapterControllers(listener) {
|
|
100
|
+
const { listeners } = controllerStore();
|
|
101
|
+
listeners.add(listener);
|
|
102
|
+
return () => listeners.delete(listener);
|
|
40
103
|
}
|
|
41
104
|
//#endregion
|
|
42
105
|
//#region src/renown/constants.ts
|
|
@@ -44,7 +107,7 @@ const RENOWN_URL = "https://www.renown.id";
|
|
|
44
107
|
const RENOWN_NETWORK_ID = "eip155";
|
|
45
108
|
const RENOWN_CHAIN_ID = "1";
|
|
46
109
|
//#endregion
|
|
47
|
-
//#region src/renown/
|
|
110
|
+
//#region src/renown/session.ts
|
|
48
111
|
function openRenown(documentId) {
|
|
49
112
|
const renown = window.ph?.renown;
|
|
50
113
|
let renownUrl = renown?.baseUrl;
|
|
@@ -65,10 +128,47 @@ function openRenown(documentId) {
|
|
|
65
128
|
url.searchParams.set("returnUrl", returnUrl.toJSON());
|
|
66
129
|
window.open(url, "_self")?.focus();
|
|
67
130
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
131
|
+
async function signIn(session) {
|
|
132
|
+
const renown = window.ph?.renown;
|
|
133
|
+
if (!renown) {
|
|
134
|
+
logger.warn("Renown instance not found, cannot sign in");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
return renown.signIn({
|
|
138
|
+
address: session.address,
|
|
139
|
+
chainId: session.chainId,
|
|
140
|
+
signTypedData: session.signTypedData
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
let inFlightSignIn;
|
|
144
|
+
let inFlightAddress;
|
|
145
|
+
let lastSignedAddress;
|
|
146
|
+
async function completeSignIn(session) {
|
|
147
|
+
const { address } = session;
|
|
148
|
+
if (address === lastSignedAddress) return;
|
|
149
|
+
if (inFlightSignIn && address === inFlightAddress) return inFlightSignIn;
|
|
150
|
+
inFlightAddress = address;
|
|
151
|
+
inFlightSignIn = (async () => {
|
|
152
|
+
try {
|
|
153
|
+
const user = await signIn(session);
|
|
154
|
+
if (user) lastSignedAddress = address;
|
|
155
|
+
return user;
|
|
156
|
+
} finally {
|
|
157
|
+
inFlightSignIn = void 0;
|
|
158
|
+
inFlightAddress = void 0;
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
return inFlightSignIn;
|
|
162
|
+
}
|
|
163
|
+
function resetSignInGuard() {
|
|
164
|
+
inFlightSignIn = void 0;
|
|
165
|
+
inFlightAddress = void 0;
|
|
166
|
+
lastSignedAddress = void 0;
|
|
167
|
+
}
|
|
168
|
+
function hasRedirectSignIn() {
|
|
169
|
+
if (typeof window === "undefined") return false;
|
|
170
|
+
return new URLSearchParams(window.location.search).has("user");
|
|
171
|
+
}
|
|
72
172
|
function consumeDidFromUrl() {
|
|
73
173
|
if (typeof window === "undefined") return;
|
|
74
174
|
const userParam = new URLSearchParams(window.location.search).get("user");
|
|
@@ -79,12 +179,6 @@ function consumeDidFromUrl() {
|
|
|
79
179
|
window.history.replaceState({}, "", cleanUrl.toString());
|
|
80
180
|
return userDid;
|
|
81
181
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Log in the user. Resolves the user DID from (in order):
|
|
84
|
-
* 1. Explicit `userDid` argument
|
|
85
|
-
* 2. `?user=` URL parameter (from Renown portal redirect)
|
|
86
|
-
* 3. Previously stored session in the Renown instance
|
|
87
|
-
*/
|
|
88
182
|
async function login(userDid, renown) {
|
|
89
183
|
if (!renown) return;
|
|
90
184
|
const did = userDid ?? consumeDidFromUrl();
|
|
@@ -98,7 +192,13 @@ async function login(userDid, renown) {
|
|
|
98
192
|
}
|
|
99
193
|
}
|
|
100
194
|
async function logout() {
|
|
195
|
+
try {
|
|
196
|
+
await (getActiveWalletController() ?? await getWalletActivator()?.())?.disconnect();
|
|
197
|
+
} catch (error) {
|
|
198
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
199
|
+
}
|
|
101
200
|
await (window.ph?.renown)?.logout();
|
|
201
|
+
resetSignInGuard();
|
|
102
202
|
const url = new URL(window.location.href);
|
|
103
203
|
if (url.searchParams.has("user")) {
|
|
104
204
|
url.searchParams.delete("user");
|
|
@@ -111,13 +211,20 @@ function truncateAddress$1(address) {
|
|
|
111
211
|
if (address.length <= 13) return address;
|
|
112
212
|
return `${address.slice(0, 7)}...${address.slice(-5)}`;
|
|
113
213
|
}
|
|
214
|
+
function isUserCancellation(error) {
|
|
215
|
+
const msg = error.message.toLowerCase();
|
|
216
|
+
return msg.includes("exited_auth_flow") || msg.includes("user rejected") || msg.includes("user denied") || msg.includes("userrejected") || msg.includes("cancel");
|
|
217
|
+
}
|
|
114
218
|
function toRenownAuthStatus(loginStatus, user) {
|
|
115
219
|
if (loginStatus === "authorized") return user ? "authorized" : "checking";
|
|
116
220
|
return loginStatus;
|
|
117
221
|
}
|
|
118
222
|
function useRenownAuth() {
|
|
119
223
|
const user = useUser();
|
|
120
|
-
const
|
|
224
|
+
const loginStatus = useLoginStatus();
|
|
225
|
+
const [pending, setPending] = useState(false);
|
|
226
|
+
const [error, setError] = useState(void 0);
|
|
227
|
+
const status = toRenownAuthStatus(loginStatus, user);
|
|
121
228
|
const address = user?.address;
|
|
122
229
|
const ensName = user?.ens?.name;
|
|
123
230
|
const avatarUrl = user?.profile?.userImage ?? user?.ens?.avatarUrl;
|
|
@@ -131,9 +238,39 @@ function useRenownAuth() {
|
|
|
131
238
|
profileId,
|
|
132
239
|
displayName: ensName ?? user?.profile?.username ?? void 0,
|
|
133
240
|
displayAddress: address ? truncateAddress$1(address) : void 0,
|
|
134
|
-
login: useCallback(() => {
|
|
135
|
-
|
|
241
|
+
login: useCallback((session, method) => {
|
|
242
|
+
const existing = getActiveWalletController();
|
|
243
|
+
const activator = getWalletActivator();
|
|
244
|
+
if (!session && !existing && !activator) {
|
|
245
|
+
openRenown();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
setPending(true);
|
|
249
|
+
setError(void 0);
|
|
250
|
+
(async () => {
|
|
251
|
+
try {
|
|
252
|
+
let resolved = session;
|
|
253
|
+
if (!resolved) {
|
|
254
|
+
const activated = existing ?? (activator ? await activator() : void 0);
|
|
255
|
+
resolved = await (getActiveWalletController() ?? activated)?.connect(method);
|
|
256
|
+
}
|
|
257
|
+
if (!resolved) {
|
|
258
|
+
openRenown();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
await completeSignIn(resolved);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
264
|
+
if (isUserCancellation(err)) return;
|
|
265
|
+
setError(err);
|
|
266
|
+
if (MissingSwitchboardError.is(err)) openRenown();
|
|
267
|
+
} finally {
|
|
268
|
+
setPending(false);
|
|
269
|
+
}
|
|
270
|
+
})();
|
|
136
271
|
}, []),
|
|
272
|
+
pending,
|
|
273
|
+
error,
|
|
137
274
|
logout: useCallback(async () => {
|
|
138
275
|
await logout();
|
|
139
276
|
}, []),
|
|
@@ -142,6 +279,24 @@ function useRenownAuth() {
|
|
|
142
279
|
}, [profileId])
|
|
143
280
|
};
|
|
144
281
|
}
|
|
282
|
+
const subscribeNothing$1 = () => () => {};
|
|
283
|
+
function useRenownAuthAsync() {
|
|
284
|
+
const auth = useRenownAuth();
|
|
285
|
+
const initial = useRenownInitialAuth();
|
|
286
|
+
const redirectSignIn = useSyncExternalStore(subscribeNothing$1, hasRedirectSignIn, () => false);
|
|
287
|
+
const { user, status, pending } = auth;
|
|
288
|
+
let state;
|
|
289
|
+
if (user) state = "authenticated";
|
|
290
|
+
else if (pending) state = "resolving";
|
|
291
|
+
else if (initial.state === "anonymous" && !redirectSignIn && status !== "checking") state = "unauthenticated";
|
|
292
|
+
else if (status === void 0 || status === "loading" || status === "checking") state = "resolving";
|
|
293
|
+
else state = "unauthenticated";
|
|
294
|
+
return {
|
|
295
|
+
...auth,
|
|
296
|
+
state,
|
|
297
|
+
isResolving: state === "resolving"
|
|
298
|
+
};
|
|
299
|
+
}
|
|
145
300
|
//#endregion
|
|
146
301
|
//#region src/renown/components/icons.tsx
|
|
147
302
|
function RenownLogo({ width = 71, height = 19, hovered = false, color = "currentColor", className }) {
|
|
@@ -849,13 +1004,88 @@ async function initRenownCrypto() {
|
|
|
849
1004
|
return await new RenownCryptoBuilder().withKeyPairStorage(keyStorage).build();
|
|
850
1005
|
}
|
|
851
1006
|
//#endregion
|
|
1007
|
+
//#region src/renown/use-renown-session.ts
|
|
1008
|
+
const DEFAULT_ENDPOINT = "/api/renown/session";
|
|
1009
|
+
const DEFAULT_EXPIRES_IN = 10080 * 60;
|
|
1010
|
+
function useRenownSessionCookie(options = {}) {
|
|
1011
|
+
const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
|
|
1012
|
+
const expiresIn = options.expiresIn ?? DEFAULT_EXPIRES_IN;
|
|
1013
|
+
const enabled = options.enabled ?? true;
|
|
1014
|
+
const { user, displayName, avatarUrl } = useRenownAuth();
|
|
1015
|
+
const renown = useRenown();
|
|
1016
|
+
const address = user?.address;
|
|
1017
|
+
const profile = user?.profile;
|
|
1018
|
+
const hadUser = useRef(false);
|
|
1019
|
+
const [synced, setSynced] = useState(false);
|
|
1020
|
+
useEffect(() => {
|
|
1021
|
+
if (!enabled) return;
|
|
1022
|
+
const ready = !!renown && typeof renown.getBearerToken === "function";
|
|
1023
|
+
if (address && ready) {
|
|
1024
|
+
hadUser.current = true;
|
|
1025
|
+
setSynced(false);
|
|
1026
|
+
let cancelled = false;
|
|
1027
|
+
(async () => {
|
|
1028
|
+
try {
|
|
1029
|
+
const token = await renown.getBearerToken({ expiresIn });
|
|
1030
|
+
await fetch(endpoint, {
|
|
1031
|
+
method: "POST",
|
|
1032
|
+
headers: { "content-type": "application/json" },
|
|
1033
|
+
body: JSON.stringify({
|
|
1034
|
+
token,
|
|
1035
|
+
profile: {
|
|
1036
|
+
name: displayName ?? null,
|
|
1037
|
+
avatar: avatarUrl ?? null,
|
|
1038
|
+
documentId: profile?.documentId ?? null,
|
|
1039
|
+
username: profile?.username ?? null,
|
|
1040
|
+
userImage: profile?.userImage ?? null
|
|
1041
|
+
}
|
|
1042
|
+
})
|
|
1043
|
+
});
|
|
1044
|
+
if (!cancelled) setSynced(true);
|
|
1045
|
+
} catch (error) {
|
|
1046
|
+
console.error("Failed to sync Renown session cookie", error);
|
|
1047
|
+
}
|
|
1048
|
+
})();
|
|
1049
|
+
return () => {
|
|
1050
|
+
cancelled = true;
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
if (!address) {
|
|
1054
|
+
setSynced(false);
|
|
1055
|
+
if (hadUser.current) {
|
|
1056
|
+
hadUser.current = false;
|
|
1057
|
+
fetch(endpoint, { method: "DELETE" }).catch(() => {});
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}, [
|
|
1061
|
+
address,
|
|
1062
|
+
displayName,
|
|
1063
|
+
avatarUrl,
|
|
1064
|
+
profile?.documentId,
|
|
1065
|
+
profile?.username,
|
|
1066
|
+
profile?.userImage,
|
|
1067
|
+
renown,
|
|
1068
|
+
endpoint,
|
|
1069
|
+
expiresIn,
|
|
1070
|
+
enabled
|
|
1071
|
+
]);
|
|
1072
|
+
return { synced };
|
|
1073
|
+
}
|
|
1074
|
+
const RenownSessionSyncedContext = createContext(false);
|
|
1075
|
+
function useRenownSessionSynced() {
|
|
1076
|
+
return useContext(RenownSessionSyncedContext);
|
|
1077
|
+
}
|
|
1078
|
+
//#endregion
|
|
852
1079
|
//#region src/renown/use-renown-init.ts
|
|
853
|
-
async function initRenown(appName, namespace, url) {
|
|
1080
|
+
async function initRenown(appName, namespace, url, switchboardUrl, revalidate, chainId) {
|
|
854
1081
|
addRenownEventHandler();
|
|
855
1082
|
setRenown(null);
|
|
856
1083
|
const renown = await new RenownBuilder(appName, {
|
|
857
1084
|
basename: namespace,
|
|
858
|
-
baseUrl: url
|
|
1085
|
+
baseUrl: url,
|
|
1086
|
+
switchboardUrl,
|
|
1087
|
+
revalidate,
|
|
1088
|
+
chainId
|
|
859
1089
|
}).build();
|
|
860
1090
|
setRenown(renown);
|
|
861
1091
|
await login(void 0, renown);
|
|
@@ -874,14 +1104,14 @@ async function initRenown(appName, namespace, url) {
|
|
|
874
1104
|
* }
|
|
875
1105
|
* ```
|
|
876
1106
|
*/
|
|
877
|
-
function useRenownInit({ appName, namespace, url }) {
|
|
1107
|
+
function useRenownInit({ appName, namespace, url, switchboardUrl, revalidate = "always", chainId }) {
|
|
878
1108
|
const promiseRef = useRef(null);
|
|
879
1109
|
promiseRef.current ??= Promise.withResolvers();
|
|
880
1110
|
const initRef = useRef(false);
|
|
881
1111
|
useEffect(() => {
|
|
882
1112
|
if (initRef.current) return;
|
|
883
1113
|
initRef.current = true;
|
|
884
|
-
initRenown(appName, namespace, url).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
|
|
1114
|
+
initRenown(appName, namespace, url, switchboardUrl, revalidate, chainId).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
|
|
885
1115
|
}, []);
|
|
886
1116
|
return promiseRef.current.promise;
|
|
887
1117
|
}
|
|
@@ -908,6 +1138,242 @@ function Renown({ onError, ...initOptions }) {
|
|
|
908
1138
|
return null;
|
|
909
1139
|
}
|
|
910
1140
|
//#endregion
|
|
911
|
-
|
|
1141
|
+
//#region src/renown/use-complete-redirect-sign-in.ts
|
|
1142
|
+
function useCompleteRedirectSignIn(metas) {
|
|
1143
|
+
const renown = useRenown();
|
|
1144
|
+
const user = useUser();
|
|
1145
|
+
const [pendingSilentSession, setPendingSilentSession] = useState(null);
|
|
1146
|
+
const oauthReturnRef = useRef(typeof window !== "undefined" && isWalletRedirectReturn(window.location.search, metas));
|
|
1147
|
+
const onSession = useCallback((_id, session) => {
|
|
1148
|
+
setPendingSilentSession(session?.canSignSilently ? session : null);
|
|
1149
|
+
}, []);
|
|
1150
|
+
useEffect(() => {
|
|
1151
|
+
if (!oauthReturnRef.current) return;
|
|
1152
|
+
if (user) {
|
|
1153
|
+
oauthReturnRef.current = false;
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (!pendingSilentSession || !renown) return;
|
|
1157
|
+
oauthReturnRef.current = false;
|
|
1158
|
+
Promise.resolve(completeSignIn(pendingSilentSession)).catch((error) => logger.error(error instanceof Error ? error.message : String(error)));
|
|
1159
|
+
}, [
|
|
1160
|
+
pendingSilentSession,
|
|
1161
|
+
renown,
|
|
1162
|
+
user
|
|
1163
|
+
]);
|
|
1164
|
+
return { onSession };
|
|
1165
|
+
}
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region src/renown/wallet-provider.tsx
|
|
1168
|
+
function mergeControllers(mounted) {
|
|
1169
|
+
if (mounted.length === 0) return void 0;
|
|
1170
|
+
return {
|
|
1171
|
+
connect(method) {
|
|
1172
|
+
if (method) {
|
|
1173
|
+
const target = mounted.find((m) => m.meta.supportedMethods.includes(method));
|
|
1174
|
+
if (!target) throw new Error(`No wallet adapter supports login method "${method}"`);
|
|
1175
|
+
return target.controller.connect(method);
|
|
1176
|
+
}
|
|
1177
|
+
const chosen = mounted.at(0);
|
|
1178
|
+
if (!chosen) throw new Error("No wallet adapter available");
|
|
1179
|
+
return chosen.controller.connect(method);
|
|
1180
|
+
},
|
|
1181
|
+
async disconnect() {
|
|
1182
|
+
await Promise.all(mounted.map((m) => m.controller.disconnect()));
|
|
1183
|
+
},
|
|
1184
|
+
getSession() {
|
|
1185
|
+
for (const { controller } of mounted) {
|
|
1186
|
+
const session = controller.getSession();
|
|
1187
|
+
if (session) return session;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function AdapterControllerBridge(props) {
|
|
1193
|
+
const { adapter, onController, onSession } = props;
|
|
1194
|
+
const { meta } = adapter;
|
|
1195
|
+
const controller = adapter.useController();
|
|
1196
|
+
useEffect(() => {
|
|
1197
|
+
onController(meta, controller);
|
|
1198
|
+
return () => onController(meta, void 0);
|
|
1199
|
+
}, [
|
|
1200
|
+
meta,
|
|
1201
|
+
controller,
|
|
1202
|
+
onController
|
|
1203
|
+
]);
|
|
1204
|
+
useEffect(() => {
|
|
1205
|
+
if (!controller.subscribe) return;
|
|
1206
|
+
return controller.subscribe((session) => onSession(meta.id, session));
|
|
1207
|
+
}, [
|
|
1208
|
+
meta.id,
|
|
1209
|
+
controller,
|
|
1210
|
+
onSession
|
|
1211
|
+
]);
|
|
1212
|
+
return null;
|
|
1213
|
+
}
|
|
1214
|
+
/** Drop-in provider for Renown in-page wallet sign-in: registers the login activator, lazy-mounts the configured adapters on first demand (login, logout, {@link useRenownWalletAdapter}, or an OAuth redirect return — not on a restored session), and merges their controllers for {@link useRenownAuth}. Full walkthrough + examples: the `@powerhousedao/reactor-browser` README ("Renown in-page sign-in") and the Academy Renown authentication guide. Pair with {@link useRenownLoginMethods} to build the login UI. */
|
|
1215
|
+
function RenownWalletProvider({ adapters: adaptersConfig, theme, children }) {
|
|
1216
|
+
const [descriptors] = useState(() => adaptersConfig);
|
|
1217
|
+
useEffect(() => {
|
|
1218
|
+
if (typeof process !== "undefined" && true) return;
|
|
1219
|
+
if (adaptersConfig === descriptors) return;
|
|
1220
|
+
console.error("RenownWalletProvider: the `adapters` array changed identity after mount, and the new value was ignored. Build it once at module scope (or memoize it) — see the @powerhousedao/reactor-browser README.");
|
|
1221
|
+
}, [adaptersConfig, descriptors]);
|
|
1222
|
+
useEffect(() => {
|
|
1223
|
+
setWalletDescriptors(descriptors);
|
|
1224
|
+
return () => setWalletDescriptors(void 0);
|
|
1225
|
+
}, [descriptors]);
|
|
1226
|
+
const metas = useMemo(() => descriptors?.map((descriptor) => descriptor.meta) ?? [], [descriptors]);
|
|
1227
|
+
const [active, setActive] = useState(() => typeof window !== "undefined" && isWalletRedirectReturn(window.location.search, metas));
|
|
1228
|
+
const [adapters, setAdapters] = useState(null);
|
|
1229
|
+
const mountedRef = useRef(/* @__PURE__ */ new Map());
|
|
1230
|
+
const { onSession } = useCompleteRedirectSignIn(metas);
|
|
1231
|
+
useEffect(() => {
|
|
1232
|
+
if (!descriptors) return;
|
|
1233
|
+
setWalletActivator(() => {
|
|
1234
|
+
setActive(true);
|
|
1235
|
+
return whenWalletControllerReady();
|
|
1236
|
+
});
|
|
1237
|
+
return () => setWalletActivator(void 0);
|
|
1238
|
+
}, [descriptors]);
|
|
1239
|
+
useEffect(() => {
|
|
1240
|
+
if (!active || !descriptors) return;
|
|
1241
|
+
let cancelled = false;
|
|
1242
|
+
resolveAdapters(descriptors).then((resolved) => {
|
|
1243
|
+
if (cancelled) return;
|
|
1244
|
+
if (resolved.length === 0) {
|
|
1245
|
+
failWalletActivation(/* @__PURE__ */ new Error("No wallet adapters were configured for in-page sign-in."));
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1248
|
+
setAdapters(resolved);
|
|
1249
|
+
}).catch((error) => {
|
|
1250
|
+
if (!cancelled) failWalletActivation(error instanceof Error ? error : new Error(String(error)));
|
|
1251
|
+
});
|
|
1252
|
+
return () => {
|
|
1253
|
+
cancelled = true;
|
|
1254
|
+
};
|
|
1255
|
+
}, [active, descriptors]);
|
|
1256
|
+
const onController = useCallback((meta, controller) => {
|
|
1257
|
+
if (controller) mountedRef.current.set(meta.id, {
|
|
1258
|
+
meta,
|
|
1259
|
+
controller
|
|
1260
|
+
});
|
|
1261
|
+
else mountedRef.current.delete(meta.id);
|
|
1262
|
+
setWalletAdapterController(meta.id, controller);
|
|
1263
|
+
setActiveWalletController(mergeControllers(Array.from(mountedRef.current.values())));
|
|
1264
|
+
}, []);
|
|
1265
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children, descriptors && active && adapters && adapters.length > 0 ? adapters.reduceRight((acc, adapter) => {
|
|
1266
|
+
const Provider = adapter.Provider;
|
|
1267
|
+
return /* @__PURE__ */ jsx(Provider, {
|
|
1268
|
+
theme,
|
|
1269
|
+
children: acc
|
|
1270
|
+
});
|
|
1271
|
+
}, /* @__PURE__ */ jsx(Fragment, { children: adapters.map((adapter) => /* @__PURE__ */ jsx(AdapterControllerBridge, {
|
|
1272
|
+
adapter,
|
|
1273
|
+
onController,
|
|
1274
|
+
onSession
|
|
1275
|
+
}, adapter.meta.id)) })) : null] });
|
|
1276
|
+
}
|
|
1277
|
+
//#endregion
|
|
1278
|
+
//#region src/renown/provider.tsx
|
|
1279
|
+
const subscribeNothing = () => () => {};
|
|
1280
|
+
function SessionSync({ enabled, endpoint, children }) {
|
|
1281
|
+
const { synced } = useRenownSessionCookie({
|
|
1282
|
+
endpoint,
|
|
1283
|
+
enabled
|
|
1284
|
+
});
|
|
1285
|
+
return /* @__PURE__ */ jsx(RenownSessionSyncedContext.Provider, {
|
|
1286
|
+
value: synced,
|
|
1287
|
+
children
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
function RenownProvider({ appName, namespace, url, switchboardUrl, adapters, theme, revalidate, chainId, session, sessionEndpoint, onError, children }) {
|
|
1291
|
+
const isServerSession = session !== void 0;
|
|
1292
|
+
const mounted = useSyncExternalStore(subscribeNothing, () => true, () => false);
|
|
1293
|
+
const seed = useMemo(() => {
|
|
1294
|
+
if (mounted) {
|
|
1295
|
+
const persisted = readPersistedUser(namespace);
|
|
1296
|
+
return persisted ? {
|
|
1297
|
+
state: "authenticated",
|
|
1298
|
+
user: persisted
|
|
1299
|
+
} : RENOWN_INITIAL_ANONYMOUS;
|
|
1300
|
+
}
|
|
1301
|
+
if (!isServerSession) return RENOWN_INITIAL_UNKNOWN;
|
|
1302
|
+
return session?.user ? {
|
|
1303
|
+
state: "authenticated",
|
|
1304
|
+
user: session.user
|
|
1305
|
+
} : RENOWN_INITIAL_ANONYMOUS;
|
|
1306
|
+
}, [
|
|
1307
|
+
mounted,
|
|
1308
|
+
isServerSession,
|
|
1309
|
+
session,
|
|
1310
|
+
namespace
|
|
1311
|
+
]);
|
|
1312
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renown, {
|
|
1313
|
+
appName,
|
|
1314
|
+
namespace,
|
|
1315
|
+
url,
|
|
1316
|
+
switchboardUrl,
|
|
1317
|
+
revalidate,
|
|
1318
|
+
chainId,
|
|
1319
|
+
onError
|
|
1320
|
+
}), /* @__PURE__ */ jsx(RenownInitialUserProvider, {
|
|
1321
|
+
initialAuth: seed,
|
|
1322
|
+
children: /* @__PURE__ */ jsx(RenownWalletProvider, {
|
|
1323
|
+
adapters,
|
|
1324
|
+
theme,
|
|
1325
|
+
children: /* @__PURE__ */ jsx(SessionSync, {
|
|
1326
|
+
enabled: isServerSession,
|
|
1327
|
+
endpoint: sessionEndpoint,
|
|
1328
|
+
children
|
|
1329
|
+
})
|
|
1330
|
+
})
|
|
1331
|
+
})] });
|
|
1332
|
+
}
|
|
1333
|
+
//#endregion
|
|
1334
|
+
//#region src/renown/login-methods.ts
|
|
1335
|
+
const DEFAULT_METHOD_LABELS = {
|
|
1336
|
+
[LoginMethod.WALLET]: "Connect a Wallet",
|
|
1337
|
+
[LoginMethod.GOOGLE]: "Continue with Google",
|
|
1338
|
+
[LoginMethod.EMAIL]: "Continue with Email",
|
|
1339
|
+
[LoginMethod.APPLE]: "Continue with Apple"
|
|
1340
|
+
};
|
|
1341
|
+
/** The login methods the mounted {@link RenownWalletProvider}'s adapters offer, for building a login UI. Reads each descriptor's eager metadata only — no wallet libraries load. Buttons follow the provider's descriptor array order, deduped; empty when no provider is mounted (redirect-only). Wire each to `useRenownAuth().login(undefined, id)`. Labels are overridable. See the reactor-browser README + Academy Renown auth guide. */
|
|
1342
|
+
function useRenownLoginMethods(labels) {
|
|
1343
|
+
const descriptors = useSyncExternalStore(subscribeWalletDescriptors, getWalletDescriptors, getServerWalletDescriptors);
|
|
1344
|
+
return useMemo(() => {
|
|
1345
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1346
|
+
const methods = [];
|
|
1347
|
+
for (const { meta } of descriptors) for (const id of meta.supportedMethods) {
|
|
1348
|
+
if (seen.has(id)) continue;
|
|
1349
|
+
seen.add(id);
|
|
1350
|
+
methods.push({
|
|
1351
|
+
id,
|
|
1352
|
+
label: labels?.[id] ?? DEFAULT_METHOD_LABELS[id] ?? id
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
return methods;
|
|
1356
|
+
}, [descriptors, labels]);
|
|
1357
|
+
}
|
|
1358
|
+
//#endregion
|
|
1359
|
+
//#region src/renown/use-renown-wallet-adapter.ts
|
|
1360
|
+
/** The controller of one adapter mounted by {@link RenownWalletProvider}, by its `meta.id`, typed as that adapter's own surface — e.g. `useRenownWalletAdapter<PrivyWalletController>("privy")` for headless email OTP. Rendering it activates the wallet tree (the adapter's library loads then), so call it from the sign-in screen, not the app shell. `undefined` until the adapter is mounted, or forever when no provider offers that id. */
|
|
1361
|
+
function useRenownWalletAdapter(id) {
|
|
1362
|
+
const controller = useSyncExternalStore(subscribeWalletAdapterControllers, getWalletAdapterControllers, getServerWalletAdapterControllers)[id];
|
|
1363
|
+
const hasActivator = useSyncExternalStore(subscribeWalletActivator, getWalletActivator, () => void 0) !== void 0;
|
|
1364
|
+
useEffect(() => {
|
|
1365
|
+
if (controller || !hasActivator) return;
|
|
1366
|
+
const current = getWalletActivator();
|
|
1367
|
+
if (!current) return;
|
|
1368
|
+
current().catch((error) => logger.error(error instanceof Error ? error.message : String(error)));
|
|
1369
|
+
}, [
|
|
1370
|
+
controller,
|
|
1371
|
+
hasActivator,
|
|
1372
|
+
id
|
|
1373
|
+
]);
|
|
1374
|
+
return controller;
|
|
1375
|
+
}
|
|
1376
|
+
//#endregion
|
|
1377
|
+
export { RENOWN_CHAIN_ID as A, logout as C, CREDENTIAL_TYPES as D, CREDENTIAL_SUBJECT_TYPE as E, RENOWN_URL as M, VERIFIABLE_CREDENTIAL_EIP712_TYPE as N, DOMAIN_TYPE as O, login as S, CREDENTIAL_SCHEMA_EIP712_TYPE as T, RenownLogo as _, Renown as a, useRenownAuth as b, useRenownSessionSynced as c, RenownAuthButton as d, RenownUserButton as f, DisconnectIcon as g, CopyIcon as h, RenownWalletProvider as i, RENOWN_NETWORK_ID as j, ISSUER_TYPE as k, initConnectCrypto as l, ChevronDownIcon as m, useRenownLoginMethods as n, useRenownInit as o, RenownLoginButton as p, RenownProvider as r, useRenownSessionCookie as s, useRenownWalletAdapter as t, initRenownCrypto as u, SpinnerIcon as v, openRenown as w, useRenownAuthAsync as x, UserIcon as y };
|
|
912
1378
|
|
|
913
|
-
//# sourceMappingURL=renown-
|
|
1379
|
+
//# sourceMappingURL=renown-BIEv6bSI.js.map
|