@powerhousedao/reactor-browser 6.2.2-dev.2 → 6.2.2-dev.20
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 +178 -0
- package/dist/client-DAJGpNZH.d.ts +14 -0
- package/dist/client-DAJGpNZH.d.ts.map +1 -0
- package/dist/{client-u13cr-Vg.js → client-DKuvLO3_.js} +30 -3
- package/dist/client-DKuvLO3_.js.map +1 -0
- package/dist/index-B3keszpu.d.ts +144 -0
- package/dist/index-B3keszpu.d.ts.map +1 -0
- package/dist/index-Cj_YGHcz.d.ts +692 -0
- package/dist/index-Cj_YGHcz.d.ts.map +1 -0
- package/dist/index.d.ts +100 -382
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -7
- package/dist/index.js.map +1 -1
- package/dist/{inspector-proxy-CvQDDxmT.d.ts → inspector-proxy-Doocf0nD.d.ts} +1 -1
- package/dist/{inspector-proxy-CvQDDxmT.d.ts.map → inspector-proxy-Doocf0nD.d.ts.map} +1 -1
- package/dist/{index-DS4W07Y8.d.ts → pglite-CntadC_p-BgIvrYtV.d.ts} +2 -142
- package/dist/pglite-CntadC_p-BgIvrYtV.d.ts.map +1 -0
- package/dist/{renown-D-1c_Bvx.js → renown-DBvu1oq7.js} +424 -27
- package/dist/renown-DBvu1oq7.js.map +1 -0
- package/dist/src/graphql/client.d.ts +2 -1
- package/dist/src/relational/index.d.ts +1 -1
- package/dist/src/renown/index.d.ts +2 -2
- package/dist/src/renown/index.js +2 -2
- package/dist/src/rpc/index.d.ts +2 -2
- package/dist/src/rpc/index.js +1 -1
- package/dist/{client-09xv0Dq6.d.ts → types-CVZRGBXo.d.ts} +2 -11
- package/dist/types-CVZRGBXo.d.ts.map +1 -0
- package/package.json +9 -9
- package/dist/client-09xv0Dq6.d.ts.map +0 -1
- package/dist/client-u13cr-Vg.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/renown-D-1c_Bvx.js.map +0 -1
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { t as makePHEventFunctions } from "./make-ph-event-functions-BHoLPif5.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";
|
|
5
|
+
import { BrowserKeyStorage, CREDENTIAL_SCHEMA_EIP712_TYPE, CREDENTIAL_SUBJECT_TYPE, CREDENTIAL_TYPES, DOMAIN_TYPE, ISSUER_TYPE, RenownBuilder, RenownCryptoBuilder, VERIFIABLE_CREDENTIAL_EIP712_TYPE, readPersistedUser } from "@renown/sdk";
|
|
6
|
+
import { DEFAULT_MOCK_METHODS, DEFAULT_PRIVY_METHODS, LoginMethod, isWalletRedirectReturn, resolveAdapters } from "@renown/sdk/wallet";
|
|
7
|
+
//#region src/renown/initial-user.tsx
|
|
8
|
+
const RenownInitialUserContext = createContext(void 0);
|
|
9
|
+
function RenownInitialUserProvider({ initialUser, children }) {
|
|
10
|
+
return /* @__PURE__ */ jsx(RenownInitialUserContext.Provider, {
|
|
11
|
+
value: initialUser,
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function useRenownInitialUser() {
|
|
16
|
+
return useContext(RenownInitialUserContext);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
6
19
|
//#region src/hooks/loading.ts
|
|
7
20
|
const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
|
|
8
21
|
const loading = null;
|
|
@@ -22,12 +35,15 @@ function useDid() {
|
|
|
22
35
|
/** Returns the current user from the renown instance, subscribing to user events */
|
|
23
36
|
function useUser() {
|
|
24
37
|
const renown = useRenown();
|
|
25
|
-
const
|
|
38
|
+
const initialUser = useRenownInitialUser();
|
|
39
|
+
const instance = renown ? renown : void 0;
|
|
40
|
+
const [user, setUser] = useState(instance ? instance.user : initialUser);
|
|
26
41
|
useEffect(() => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
if (instance) {
|
|
43
|
+
setUser(instance.user);
|
|
44
|
+
return instance.on("user", setUser);
|
|
45
|
+
}
|
|
46
|
+
}, [instance]);
|
|
31
47
|
return user;
|
|
32
48
|
}
|
|
33
49
|
/** Returns the login status, subscribing to renown status events */
|
|
@@ -39,12 +55,46 @@ function useLoginStatus() {
|
|
|
39
55
|
}, () => renown === null ? "loading" : renown?.status, () => void 0);
|
|
40
56
|
}
|
|
41
57
|
//#endregion
|
|
58
|
+
//#region src/renown/wallet-registry.ts
|
|
59
|
+
let activeWalletController;
|
|
60
|
+
let controllerWaiters = [];
|
|
61
|
+
let walletActivator;
|
|
62
|
+
function setActiveWalletController(controller) {
|
|
63
|
+
activeWalletController = controller;
|
|
64
|
+
if (controller) {
|
|
65
|
+
const waiters = controllerWaiters;
|
|
66
|
+
controllerWaiters = [];
|
|
67
|
+
waiters.forEach(({ resolve }) => resolve(controller));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function failWalletActivation(error) {
|
|
71
|
+
const waiters = controllerWaiters;
|
|
72
|
+
controllerWaiters = [];
|
|
73
|
+
waiters.forEach(({ reject }) => reject(error));
|
|
74
|
+
}
|
|
75
|
+
function getActiveWalletController() {
|
|
76
|
+
return activeWalletController;
|
|
77
|
+
}
|
|
78
|
+
function setWalletActivator(activator) {
|
|
79
|
+
walletActivator = activator;
|
|
80
|
+
}
|
|
81
|
+
function getWalletActivator() {
|
|
82
|
+
return walletActivator;
|
|
83
|
+
}
|
|
84
|
+
function whenWalletControllerReady() {
|
|
85
|
+
if (activeWalletController) return Promise.resolve(activeWalletController);
|
|
86
|
+
return new Promise((resolve, reject) => controllerWaiters.push({
|
|
87
|
+
resolve,
|
|
88
|
+
reject
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
42
92
|
//#region src/renown/constants.ts
|
|
43
93
|
const RENOWN_URL = "https://www.renown.id";
|
|
44
94
|
const RENOWN_NETWORK_ID = "eip155";
|
|
45
95
|
const RENOWN_CHAIN_ID = "1";
|
|
46
96
|
//#endregion
|
|
47
|
-
//#region src/renown/
|
|
97
|
+
//#region src/renown/session.ts
|
|
48
98
|
function openRenown(documentId) {
|
|
49
99
|
const renown = window.ph?.renown;
|
|
50
100
|
let renownUrl = renown?.baseUrl;
|
|
@@ -65,10 +115,43 @@ function openRenown(documentId) {
|
|
|
65
115
|
url.searchParams.set("returnUrl", returnUrl.toJSON());
|
|
66
116
|
window.open(url, "_self")?.focus();
|
|
67
117
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
118
|
+
async function signIn(session) {
|
|
119
|
+
const renown = window.ph?.renown;
|
|
120
|
+
if (!renown) {
|
|
121
|
+
logger.warn("Renown instance not found, cannot sign in");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
return renown.signIn({
|
|
125
|
+
address: session.address,
|
|
126
|
+
chainId: session.chainId,
|
|
127
|
+
signTypedData: session.signTypedData
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
let inFlightSignIn;
|
|
131
|
+
let inFlightAddress;
|
|
132
|
+
let lastSignedAddress;
|
|
133
|
+
async function completeSignIn(session) {
|
|
134
|
+
const { address } = session;
|
|
135
|
+
if (address === lastSignedAddress) return;
|
|
136
|
+
if (inFlightSignIn && address === inFlightAddress) return inFlightSignIn;
|
|
137
|
+
inFlightAddress = address;
|
|
138
|
+
inFlightSignIn = (async () => {
|
|
139
|
+
try {
|
|
140
|
+
const user = await signIn(session);
|
|
141
|
+
if (user) lastSignedAddress = address;
|
|
142
|
+
return user;
|
|
143
|
+
} finally {
|
|
144
|
+
inFlightSignIn = void 0;
|
|
145
|
+
inFlightAddress = void 0;
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
return inFlightSignIn;
|
|
149
|
+
}
|
|
150
|
+
function resetSignInGuard() {
|
|
151
|
+
inFlightSignIn = void 0;
|
|
152
|
+
inFlightAddress = void 0;
|
|
153
|
+
lastSignedAddress = void 0;
|
|
154
|
+
}
|
|
72
155
|
function consumeDidFromUrl() {
|
|
73
156
|
if (typeof window === "undefined") return;
|
|
74
157
|
const userParam = new URLSearchParams(window.location.search).get("user");
|
|
@@ -79,12 +162,6 @@ function consumeDidFromUrl() {
|
|
|
79
162
|
window.history.replaceState({}, "", cleanUrl.toString());
|
|
80
163
|
return userDid;
|
|
81
164
|
}
|
|
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
165
|
async function login(userDid, renown) {
|
|
89
166
|
if (!renown) return;
|
|
90
167
|
const did = userDid ?? consumeDidFromUrl();
|
|
@@ -98,7 +175,13 @@ async function login(userDid, renown) {
|
|
|
98
175
|
}
|
|
99
176
|
}
|
|
100
177
|
async function logout() {
|
|
178
|
+
try {
|
|
179
|
+
await getActiveWalletController()?.disconnect();
|
|
180
|
+
} catch (error) {
|
|
181
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
182
|
+
}
|
|
101
183
|
await (window.ph?.renown)?.logout();
|
|
184
|
+
resetSignInGuard();
|
|
102
185
|
const url = new URL(window.location.href);
|
|
103
186
|
if (url.searchParams.has("user")) {
|
|
104
187
|
url.searchParams.delete("user");
|
|
@@ -111,13 +194,20 @@ function truncateAddress$1(address) {
|
|
|
111
194
|
if (address.length <= 13) return address;
|
|
112
195
|
return `${address.slice(0, 7)}...${address.slice(-5)}`;
|
|
113
196
|
}
|
|
197
|
+
function isUserCancellation(error) {
|
|
198
|
+
const msg = error.message.toLowerCase();
|
|
199
|
+
return msg.includes("exited_auth_flow") || msg.includes("user rejected") || msg.includes("user denied") || msg.includes("userrejected") || msg.includes("cancel");
|
|
200
|
+
}
|
|
114
201
|
function toRenownAuthStatus(loginStatus, user) {
|
|
115
202
|
if (loginStatus === "authorized") return user ? "authorized" : "checking";
|
|
116
203
|
return loginStatus;
|
|
117
204
|
}
|
|
118
205
|
function useRenownAuth() {
|
|
119
206
|
const user = useUser();
|
|
120
|
-
const
|
|
207
|
+
const loginStatus = useLoginStatus();
|
|
208
|
+
const [pending, setPending] = useState(false);
|
|
209
|
+
const [error, setError] = useState(void 0);
|
|
210
|
+
const status = toRenownAuthStatus(loginStatus, user);
|
|
121
211
|
const address = user?.address;
|
|
122
212
|
const ensName = user?.ens?.name;
|
|
123
213
|
const avatarUrl = user?.profile?.userImage ?? user?.ens?.avatarUrl;
|
|
@@ -131,9 +221,39 @@ function useRenownAuth() {
|
|
|
131
221
|
profileId,
|
|
132
222
|
displayName: ensName ?? user?.profile?.username ?? void 0,
|
|
133
223
|
displayAddress: address ? truncateAddress$1(address) : void 0,
|
|
134
|
-
login: useCallback(() => {
|
|
135
|
-
|
|
224
|
+
login: useCallback((session, method) => {
|
|
225
|
+
const existing = getActiveWalletController();
|
|
226
|
+
const activator = getWalletActivator();
|
|
227
|
+
if (!session && !existing && !activator) {
|
|
228
|
+
openRenown();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setPending(true);
|
|
232
|
+
setError(void 0);
|
|
233
|
+
(async () => {
|
|
234
|
+
try {
|
|
235
|
+
let resolved = session;
|
|
236
|
+
if (!resolved) {
|
|
237
|
+
const activated = existing ?? (activator ? await activator() : void 0);
|
|
238
|
+
resolved = await (getActiveWalletController() ?? activated)?.connect(method);
|
|
239
|
+
}
|
|
240
|
+
if (!resolved) {
|
|
241
|
+
openRenown();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
await completeSignIn(resolved);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
247
|
+
if (isUserCancellation(err)) return;
|
|
248
|
+
setError(err);
|
|
249
|
+
if (/switchboard/i.test(err.message)) openRenown();
|
|
250
|
+
} finally {
|
|
251
|
+
setPending(false);
|
|
252
|
+
}
|
|
253
|
+
})();
|
|
136
254
|
}, []),
|
|
255
|
+
pending,
|
|
256
|
+
error,
|
|
137
257
|
logout: useCallback(async () => {
|
|
138
258
|
await logout();
|
|
139
259
|
}, []),
|
|
@@ -142,6 +262,19 @@ function useRenownAuth() {
|
|
|
142
262
|
}, [profileId])
|
|
143
263
|
};
|
|
144
264
|
}
|
|
265
|
+
function useRenownAuthAsync() {
|
|
266
|
+
const auth = useRenownAuth();
|
|
267
|
+
const { user, status, pending } = auth;
|
|
268
|
+
let state;
|
|
269
|
+
if (user) state = "authenticated";
|
|
270
|
+
else if (pending || status === void 0 || status === "loading" || status === "checking") state = "resolving";
|
|
271
|
+
else state = "unauthenticated";
|
|
272
|
+
return {
|
|
273
|
+
...auth,
|
|
274
|
+
state,
|
|
275
|
+
isResolving: state === "resolving"
|
|
276
|
+
};
|
|
277
|
+
}
|
|
145
278
|
//#endregion
|
|
146
279
|
//#region src/renown/components/icons.tsx
|
|
147
280
|
function RenownLogo({ width = 71, height = 19, hovered = false, color = "currentColor", className }) {
|
|
@@ -849,13 +982,80 @@ async function initRenownCrypto() {
|
|
|
849
982
|
return await new RenownCryptoBuilder().withKeyPairStorage(keyStorage).build();
|
|
850
983
|
}
|
|
851
984
|
//#endregion
|
|
985
|
+
//#region src/renown/use-renown-session-cookie.ts
|
|
986
|
+
const DEFAULT_ENDPOINT = "/api/renown/session";
|
|
987
|
+
const DEFAULT_EXPIRES_IN = 10080 * 60;
|
|
988
|
+
function useRenownSessionCookie(options = {}) {
|
|
989
|
+
const endpoint = options.endpoint ?? DEFAULT_ENDPOINT;
|
|
990
|
+
const expiresIn = options.expiresIn ?? DEFAULT_EXPIRES_IN;
|
|
991
|
+
const enabled = options.enabled ?? true;
|
|
992
|
+
const { user, displayName, avatarUrl } = useRenownAuth();
|
|
993
|
+
const renown = useRenown();
|
|
994
|
+
const address = user?.address;
|
|
995
|
+
const hadUser = useRef(false);
|
|
996
|
+
const [synced, setSynced] = useState(false);
|
|
997
|
+
useEffect(() => {
|
|
998
|
+
if (!enabled) return;
|
|
999
|
+
const ready = !!renown && typeof renown.getBearerToken === "function";
|
|
1000
|
+
if (address && ready) {
|
|
1001
|
+
hadUser.current = true;
|
|
1002
|
+
setSynced(false);
|
|
1003
|
+
let cancelled = false;
|
|
1004
|
+
(async () => {
|
|
1005
|
+
try {
|
|
1006
|
+
const token = await renown.getBearerToken({ expiresIn });
|
|
1007
|
+
await fetch(endpoint, {
|
|
1008
|
+
method: "POST",
|
|
1009
|
+
headers: { "content-type": "application/json" },
|
|
1010
|
+
body: JSON.stringify({
|
|
1011
|
+
token,
|
|
1012
|
+
profile: {
|
|
1013
|
+
name: displayName ?? null,
|
|
1014
|
+
avatar: avatarUrl ?? null
|
|
1015
|
+
}
|
|
1016
|
+
})
|
|
1017
|
+
});
|
|
1018
|
+
if (!cancelled) setSynced(true);
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
console.error("Failed to sync Renown session cookie", error);
|
|
1021
|
+
}
|
|
1022
|
+
})();
|
|
1023
|
+
return () => {
|
|
1024
|
+
cancelled = true;
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
if (!address) {
|
|
1028
|
+
setSynced(false);
|
|
1029
|
+
if (hadUser.current) {
|
|
1030
|
+
hadUser.current = false;
|
|
1031
|
+
fetch(endpoint, { method: "DELETE" }).catch(() => {});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}, [
|
|
1035
|
+
address,
|
|
1036
|
+
displayName,
|
|
1037
|
+
avatarUrl,
|
|
1038
|
+
renown,
|
|
1039
|
+
endpoint,
|
|
1040
|
+
expiresIn,
|
|
1041
|
+
enabled
|
|
1042
|
+
]);
|
|
1043
|
+
return { synced };
|
|
1044
|
+
}
|
|
1045
|
+
const RenownSessionSyncedContext = createContext(false);
|
|
1046
|
+
function useRenownSessionSynced() {
|
|
1047
|
+
return useContext(RenownSessionSyncedContext);
|
|
1048
|
+
}
|
|
1049
|
+
//#endregion
|
|
852
1050
|
//#region src/renown/use-renown-init.ts
|
|
853
|
-
async function initRenown(appName, namespace, url) {
|
|
1051
|
+
async function initRenown(appName, namespace, url, switchboardUrl, revalidate) {
|
|
854
1052
|
addRenownEventHandler();
|
|
855
1053
|
setRenown(null);
|
|
856
1054
|
const renown = await new RenownBuilder(appName, {
|
|
857
1055
|
basename: namespace,
|
|
858
|
-
baseUrl: url
|
|
1056
|
+
baseUrl: url,
|
|
1057
|
+
switchboardUrl,
|
|
1058
|
+
revalidate
|
|
859
1059
|
}).build();
|
|
860
1060
|
setRenown(renown);
|
|
861
1061
|
await login(void 0, renown);
|
|
@@ -874,14 +1074,14 @@ async function initRenown(appName, namespace, url) {
|
|
|
874
1074
|
* }
|
|
875
1075
|
* ```
|
|
876
1076
|
*/
|
|
877
|
-
function useRenownInit({ appName, namespace, url }) {
|
|
1077
|
+
function useRenownInit({ appName, namespace, url, switchboardUrl, revalidate = "always" }) {
|
|
878
1078
|
const promiseRef = useRef(null);
|
|
879
1079
|
promiseRef.current ??= Promise.withResolvers();
|
|
880
1080
|
const initRef = useRef(false);
|
|
881
1081
|
useEffect(() => {
|
|
882
1082
|
if (initRef.current) return;
|
|
883
1083
|
initRef.current = true;
|
|
884
|
-
initRenown(appName, namespace, url).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
|
|
1084
|
+
initRenown(appName, namespace, url, switchboardUrl, revalidate).then(promiseRef.current.resolve).catch(promiseRef.current.reject);
|
|
885
1085
|
}, []);
|
|
886
1086
|
return promiseRef.current.promise;
|
|
887
1087
|
}
|
|
@@ -908,6 +1108,203 @@ function Renown({ onError, ...initOptions }) {
|
|
|
908
1108
|
return null;
|
|
909
1109
|
}
|
|
910
1110
|
//#endregion
|
|
911
|
-
|
|
1111
|
+
//#region src/renown/use-complete-redirect-sign-in.ts
|
|
1112
|
+
function useCompleteRedirectSignIn() {
|
|
1113
|
+
const renown = useRenown();
|
|
1114
|
+
const user = useUser();
|
|
1115
|
+
const [pendingSilentSession, setPendingSilentSession] = useState(null);
|
|
1116
|
+
const oauthReturnRef = useRef(typeof window !== "undefined" && isWalletRedirectReturn(window.location.search));
|
|
1117
|
+
const onSession = useCallback((_id, session) => {
|
|
1118
|
+
setPendingSilentSession(session?.canSignSilently ? session : null);
|
|
1119
|
+
}, []);
|
|
1120
|
+
useEffect(() => {
|
|
1121
|
+
if (!oauthReturnRef.current) return;
|
|
1122
|
+
if (user) {
|
|
1123
|
+
oauthReturnRef.current = false;
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (!pendingSilentSession || !renown) return;
|
|
1127
|
+
oauthReturnRef.current = false;
|
|
1128
|
+
Promise.resolve(completeSignIn(pendingSilentSession)).catch((error) => logger.error(error instanceof Error ? error.message : String(error)));
|
|
1129
|
+
}, [
|
|
1130
|
+
pendingSilentSession,
|
|
1131
|
+
renown,
|
|
1132
|
+
user
|
|
1133
|
+
]);
|
|
1134
|
+
return { onSession };
|
|
1135
|
+
}
|
|
1136
|
+
//#endregion
|
|
1137
|
+
//#region src/renown/wallet-provider.tsx
|
|
1138
|
+
function mergeControllers(controllers) {
|
|
1139
|
+
if (controllers.length === 0) return void 0;
|
|
1140
|
+
return {
|
|
1141
|
+
supportedMethods: Array.from(new Set(controllers.flatMap((c) => c.supportedMethods))),
|
|
1142
|
+
connect(method) {
|
|
1143
|
+
if (method) {
|
|
1144
|
+
const target = controllers.find((c) => c.supportedMethods.includes(method));
|
|
1145
|
+
if (!target) throw new Error(`No wallet adapter supports login method "${method}"`);
|
|
1146
|
+
return target.connect(method);
|
|
1147
|
+
}
|
|
1148
|
+
const chosen = controllers.at(0);
|
|
1149
|
+
if (!chosen) throw new Error("No wallet adapter available");
|
|
1150
|
+
return chosen.connect(method);
|
|
1151
|
+
},
|
|
1152
|
+
async disconnect() {
|
|
1153
|
+
await Promise.all(controllers.map((c) => c.disconnect()));
|
|
1154
|
+
},
|
|
1155
|
+
getSession() {
|
|
1156
|
+
for (const c of controllers) {
|
|
1157
|
+
const session = c.getSession();
|
|
1158
|
+
if (session) return session;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
function AdapterControllerBridge(props) {
|
|
1164
|
+
const { adapter, onController, onSession } = props;
|
|
1165
|
+
const controller = adapter.useController();
|
|
1166
|
+
useEffect(() => {
|
|
1167
|
+
onController(adapter.id, controller);
|
|
1168
|
+
return () => onController(adapter.id, void 0);
|
|
1169
|
+
}, [
|
|
1170
|
+
adapter.id,
|
|
1171
|
+
controller,
|
|
1172
|
+
onController
|
|
1173
|
+
]);
|
|
1174
|
+
useEffect(() => {
|
|
1175
|
+
if (!controller.subscribe) return;
|
|
1176
|
+
return controller.subscribe((session) => onSession(adapter.id, session));
|
|
1177
|
+
}, [
|
|
1178
|
+
adapter.id,
|
|
1179
|
+
controller,
|
|
1180
|
+
onSession
|
|
1181
|
+
]);
|
|
1182
|
+
return null;
|
|
1183
|
+
}
|
|
1184
|
+
/** Drop-in provider for Renown in-page wallet sign-in: registers the login activator, lazy-mounts the configured adapters on first click, 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. */
|
|
1185
|
+
function RenownWalletProvider({ adapters: adaptersConfig, theme, children }) {
|
|
1186
|
+
const [config] = useState(() => adaptersConfig);
|
|
1187
|
+
const user = useUser();
|
|
1188
|
+
const [activated, setActivated] = useState(() => typeof window !== "undefined" && isWalletRedirectReturn(window.location.search));
|
|
1189
|
+
if (user && !activated) setActivated(true);
|
|
1190
|
+
const active = activated;
|
|
1191
|
+
const [adapters, setAdapters] = useState(null);
|
|
1192
|
+
const controllersRef = useRef(/* @__PURE__ */ new Map());
|
|
1193
|
+
const { onSession } = useCompleteRedirectSignIn();
|
|
1194
|
+
useEffect(() => {
|
|
1195
|
+
if (!config) return;
|
|
1196
|
+
setWalletActivator(() => {
|
|
1197
|
+
setActivated(true);
|
|
1198
|
+
return whenWalletControllerReady();
|
|
1199
|
+
});
|
|
1200
|
+
return () => setWalletActivator(void 0);
|
|
1201
|
+
}, [config]);
|
|
1202
|
+
useEffect(() => {
|
|
1203
|
+
if (!active || !config) return;
|
|
1204
|
+
let cancelled = false;
|
|
1205
|
+
resolveAdapters(config).then((resolved) => {
|
|
1206
|
+
if (cancelled) return;
|
|
1207
|
+
if (resolved.length === 0) {
|
|
1208
|
+
failWalletActivation(/* @__PURE__ */ new Error("No wallet adapters could be loaded. Check that the configured adapters' peer dependencies are installed."));
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
setAdapters(resolved);
|
|
1212
|
+
}).catch((error) => {
|
|
1213
|
+
if (!cancelled) failWalletActivation(error instanceof Error ? error : new Error(String(error)));
|
|
1214
|
+
});
|
|
1215
|
+
return () => {
|
|
1216
|
+
cancelled = true;
|
|
1217
|
+
};
|
|
1218
|
+
}, [active, config]);
|
|
1219
|
+
const onController = useCallback((id, controller) => {
|
|
1220
|
+
if (controller) controllersRef.current.set(id, controller);
|
|
1221
|
+
else controllersRef.current.delete(id);
|
|
1222
|
+
setActiveWalletController(mergeControllers(Array.from(controllersRef.current.values())));
|
|
1223
|
+
}, []);
|
|
1224
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children, config && active && adapters && adapters.length > 0 ? adapters.reduceRight((acc, adapter) => {
|
|
1225
|
+
const Provider = adapter.Provider;
|
|
1226
|
+
return /* @__PURE__ */ jsx(Provider, {
|
|
1227
|
+
theme,
|
|
1228
|
+
children: acc
|
|
1229
|
+
});
|
|
1230
|
+
}, /* @__PURE__ */ jsx(Fragment, { children: adapters.map((adapter) => /* @__PURE__ */ jsx(AdapterControllerBridge, {
|
|
1231
|
+
adapter,
|
|
1232
|
+
onController,
|
|
1233
|
+
onSession
|
|
1234
|
+
}, adapter.id)) })) : null] });
|
|
1235
|
+
}
|
|
1236
|
+
//#endregion
|
|
1237
|
+
//#region src/renown/provider.tsx
|
|
1238
|
+
function SessionSync({ enabled, endpoint, children }) {
|
|
1239
|
+
const { synced } = useRenownSessionCookie({
|
|
1240
|
+
endpoint,
|
|
1241
|
+
enabled
|
|
1242
|
+
});
|
|
1243
|
+
return /* @__PURE__ */ jsx(RenownSessionSyncedContext.Provider, {
|
|
1244
|
+
value: synced,
|
|
1245
|
+
children
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
function RenownProvider({ appName, namespace, url, switchboardUrl, adapters, theme, revalidate, session, sessionEndpoint, onError, children }) {
|
|
1249
|
+
const isServerSession = session !== void 0;
|
|
1250
|
+
const seed = useMemo(() => {
|
|
1251
|
+
if (isServerSession) return session?.user ?? void 0;
|
|
1252
|
+
return readPersistedUser(namespace);
|
|
1253
|
+
}, [
|
|
1254
|
+
isServerSession,
|
|
1255
|
+
session,
|
|
1256
|
+
namespace
|
|
1257
|
+
]);
|
|
1258
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Renown, {
|
|
1259
|
+
appName,
|
|
1260
|
+
namespace,
|
|
1261
|
+
url,
|
|
1262
|
+
switchboardUrl,
|
|
1263
|
+
revalidate,
|
|
1264
|
+
onError
|
|
1265
|
+
}), /* @__PURE__ */ jsx(RenownInitialUserProvider, {
|
|
1266
|
+
initialUser: seed,
|
|
1267
|
+
children: /* @__PURE__ */ jsx(RenownWalletProvider, {
|
|
1268
|
+
adapters,
|
|
1269
|
+
theme,
|
|
1270
|
+
children: /* @__PURE__ */ jsx(SessionSync, {
|
|
1271
|
+
enabled: isServerSession,
|
|
1272
|
+
endpoint: sessionEndpoint,
|
|
1273
|
+
children
|
|
1274
|
+
})
|
|
1275
|
+
})
|
|
1276
|
+
})] });
|
|
1277
|
+
}
|
|
1278
|
+
//#endregion
|
|
1279
|
+
//#region src/renown/login-methods.ts
|
|
1280
|
+
const DEFAULT_METHOD_LABELS = {
|
|
1281
|
+
[LoginMethod.WALLET]: "Connect a Wallet",
|
|
1282
|
+
[LoginMethod.GOOGLE]: "Continue with Google",
|
|
1283
|
+
[LoginMethod.EMAIL]: "Continue with Email",
|
|
1284
|
+
[LoginMethod.APPLE]: "Continue with Apple"
|
|
1285
|
+
};
|
|
1286
|
+
/** Derive the offered login methods (wallet + Privy's methods) from an adapters config, for building a login UI. Reads config only — no wallet libraries load. Wire each to `useRenownAuth().login(undefined, id)`. Labels are overridable. See the reactor-browser README + Academy Renown auth guide. */
|
|
1287
|
+
function useRenownLoginMethods(adapters, labels) {
|
|
1288
|
+
return useMemo(() => {
|
|
1289
|
+
if (!adapters) return [];
|
|
1290
|
+
const label = (id) => labels?.[id] ?? DEFAULT_METHOD_LABELS[id] ?? id;
|
|
1291
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1292
|
+
const methods = [];
|
|
1293
|
+
const add = (id) => {
|
|
1294
|
+
if (seen.has(id)) return;
|
|
1295
|
+
seen.add(id);
|
|
1296
|
+
methods.push({
|
|
1297
|
+
id,
|
|
1298
|
+
label: label(id)
|
|
1299
|
+
});
|
|
1300
|
+
};
|
|
1301
|
+
if (adapters.rainbow) add(LoginMethod.WALLET);
|
|
1302
|
+
if (adapters.privy) (adapters.privy.methods?.length ? adapters.privy.methods : DEFAULT_PRIVY_METHODS).forEach(add);
|
|
1303
|
+
if (adapters.mock) (adapters.mock.methods?.length ? adapters.mock.methods : DEFAULT_MOCK_METHODS).forEach(add);
|
|
1304
|
+
return methods;
|
|
1305
|
+
}, [adapters, labels]);
|
|
1306
|
+
}
|
|
1307
|
+
//#endregion
|
|
1308
|
+
export { RENOWN_NETWORK_ID as A, loading as B, openRenown as C, DOMAIN_TYPE as D, CREDENTIAL_TYPES as E, useDid as F, useLoading as H, useLoginStatus as I, useRenown as L, VERIFIABLE_CREDENTIAL_EIP712_TYPE as M, addRenownEventHandler as N, ISSUER_TYPE as O, setRenown as P, useUser as R, logout as S, CREDENTIAL_SUBJECT_TYPE as T, RenownInitialUserProvider as U, setLoading as V, useRenownInitialUser as W, SpinnerIcon as _, useRenownInit as a, useRenownAuthAsync as b, initConnectCrypto as c, RenownUserButton as d, RenownLoginButton as f, RenownLogo as g, DisconnectIcon as h, Renown as i, RENOWN_URL as j, RENOWN_CHAIN_ID as k, initRenownCrypto as l, CopyIcon as m, RenownProvider as n, useRenownSessionCookie as o, ChevronDownIcon as p, RenownWalletProvider as r, useRenownSessionSynced as s, useRenownLoginMethods as t, RenownAuthButton as u, UserIcon as v, CREDENTIAL_SCHEMA_EIP712_TYPE as w, login as x, useRenownAuth as y, addLoadingEventHandler as z };
|
|
912
1309
|
|
|
913
|
-
//# sourceMappingURL=renown-
|
|
1310
|
+
//# sourceMappingURL=renown-DBvu1oq7.js.map
|