@calimero-network/mero-react 9.9.1 → 9.10.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 +24 -1
- package/dist/index.cjs +216 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -9
- package/dist/index.d.ts +43 -9
- package/dist/index.js +217 -197
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useMemo, useState, useRef, useCallback, useEffect, useContext } from 'react';
|
|
2
|
-
import { signGroupInvitation, signMemberJoinOp, CloudClient, LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl,
|
|
2
|
+
import { signGroupInvitation, signMemberJoinOp, CloudClient, LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, readEnrolmentCallback, completeDeviceEnrolment, deviceEnrolmentUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, memberJoinedOpenOp, signerFromSecret, groupDeletedOp, memberAddedOp, memberRemovedOp, subgroupCreation, memberRoleSetOp, defaultCapabilitiesSetOp, subgroupVisibilitySetOp, groupMetadataSetOp, memberMetadataSetOp, contextMetadataSetOp, groupReparentedOp, contextDetachedOp, compareSemver, AuthRevokedError, HTTPError, memberLeftOp, memberCapabilitySetOp, createMeroClient, RelayClient, createLocalStorageNonceSource, classifyError, attestRelayNodeKey, login, defaultAudience, AccountNotLinkedError, AccountHaRefusedError, createSignedReleaseVerifier, fetchNodeRelease, cloudNodeReleaseUrl, DEFAULT_RELEASE_MIRROR, fetchNodeReleaseVersion } from '@calimero-network/mero-js';
|
|
3
3
|
export * from '@calimero-network/mero-js';
|
|
4
4
|
export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
|
|
5
5
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -1933,6 +1933,196 @@ function AccountSignInPanel({
|
|
|
1933
1933
|
] })
|
|
1934
1934
|
] });
|
|
1935
1935
|
}
|
|
1936
|
+
var DEVICE_KEY = "calimero.device";
|
|
1937
|
+
var STATE_KEY = "calimero.enrol.state";
|
|
1938
|
+
var HOSTED_WALLET = "https://wallet.cloud.calimero.network/account-enroll";
|
|
1939
|
+
var hex = (b) => [...new Uint8Array(b)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
1940
|
+
function executorOf(relay) {
|
|
1941
|
+
const value = relay.executorAccount;
|
|
1942
|
+
return typeof value === "string" && /^[0-9a-f]{64}$/.test(value) ? value : null;
|
|
1943
|
+
}
|
|
1944
|
+
function chooseRelay(relays) {
|
|
1945
|
+
const reachable = relays.filter(
|
|
1946
|
+
(r) => typeof r.relayUrl === "string" && r.relayUrl.length > 0
|
|
1947
|
+
);
|
|
1948
|
+
const fresh = reachable.find((r) => r.fresh);
|
|
1949
|
+
if (fresh) return { relayUrl: fresh.relayUrl, executorAccount: executorOf(fresh), note: null };
|
|
1950
|
+
if (reachable.length > 0) {
|
|
1951
|
+
return {
|
|
1952
|
+
relayUrl: reachable[0].relayUrl,
|
|
1953
|
+
executorAccount: executorOf(reachable[0]),
|
|
1954
|
+
note: "Connected through a relay whose last heartbeat has lapsed \u2014 it may not answer. It was the only one with an address."
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
if (relays.length > 0) {
|
|
1958
|
+
return {
|
|
1959
|
+
relayUrl: null,
|
|
1960
|
+
executorAccount: null,
|
|
1961
|
+
note: `Signed in. Your account has ${relays.length} relay${relays.length === 1 ? "" : "s"} assigned, but the cloud knows no address for any of them yet, so there is nowhere to write through for the moment. Reads and writes resume as soon as one reports in.`
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
return {
|
|
1965
|
+
relayUrl: null,
|
|
1966
|
+
executorAccount: null,
|
|
1967
|
+
note: "Signed in, with nowhere to write yet: a new account is a member of nothing, so no node serves it. Redeeming an invitation admits this account to a namespace and gives it a relay \u2014 that is the normal first step, not an error."
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
async function deviceKeys() {
|
|
1971
|
+
const had = localStorage.getItem(DEVICE_KEY);
|
|
1972
|
+
if (had) {
|
|
1973
|
+
const parsed = JSON.parse(had);
|
|
1974
|
+
if (parsed.kemSk && parsed.signSk && parsed.signPk && parsed.kemPk) {
|
|
1975
|
+
return parsed;
|
|
1976
|
+
}
|
|
1977
|
+
localStorage.removeItem(DEVICE_KEY);
|
|
1978
|
+
}
|
|
1979
|
+
const sign = await crypto.subtle.generateKey({ name: "Ed25519" }, true, [
|
|
1980
|
+
"sign",
|
|
1981
|
+
"verify"
|
|
1982
|
+
]);
|
|
1983
|
+
let agree;
|
|
1984
|
+
try {
|
|
1985
|
+
agree = await crypto.subtle.generateKey({ name: "X25519" }, true, [
|
|
1986
|
+
"deriveBits"
|
|
1987
|
+
]);
|
|
1988
|
+
} catch {
|
|
1989
|
+
throw new Error(
|
|
1990
|
+
"this browser cannot generate an X25519 key, so it cannot receive wrapped scope keys. Chrome 133+ and Safari 17+ support it; enrolling without one would certify a delivery key nothing holds the secret for."
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
const keys = {
|
|
1994
|
+
signPk: hex(await crypto.subtle.exportKey("raw", sign.publicKey)),
|
|
1995
|
+
signSk: hex((await crypto.subtle.exportKey("pkcs8", sign.privateKey)).slice(16)),
|
|
1996
|
+
kemPk: hex(await crypto.subtle.exportKey("raw", agree.publicKey)),
|
|
1997
|
+
kemSk: hex((await crypto.subtle.exportKey("pkcs8", agree.privateKey)).slice(16))
|
|
1998
|
+
};
|
|
1999
|
+
localStorage.setItem(DEVICE_KEY, JSON.stringify(keys));
|
|
2000
|
+
return keys;
|
|
2001
|
+
}
|
|
2002
|
+
function isReturningFromWallet(location = typeof window === "undefined" ? void 0 : window.location) {
|
|
2003
|
+
if (!location) return false;
|
|
2004
|
+
const params = new URLSearchParams(location.hash.replace(/^#/, ""));
|
|
2005
|
+
if (params.get("error")) return true;
|
|
2006
|
+
return Boolean(params.get("credential") && params.get("account") && params.get("device"));
|
|
2007
|
+
}
|
|
2008
|
+
function useAccountEnrolment({
|
|
2009
|
+
walletUrl: walletOverride,
|
|
2010
|
+
enabled = true
|
|
2011
|
+
} = {}) {
|
|
2012
|
+
const { connectWithAccount, cloudBaseUrl } = useMero();
|
|
2013
|
+
const [note, setNote] = useState(null);
|
|
2014
|
+
const walletUrl = walletOverride ?? HOSTED_WALLET;
|
|
2015
|
+
const callbackRef = useRef(void 0);
|
|
2016
|
+
const callbackErrorRef = useRef(null);
|
|
2017
|
+
if (enabled && callbackRef.current === void 0 && typeof window !== "undefined") {
|
|
2018
|
+
try {
|
|
2019
|
+
callbackRef.current = readEnrolmentCallback();
|
|
2020
|
+
} catch (e) {
|
|
2021
|
+
callbackRef.current = null;
|
|
2022
|
+
callbackErrorRef.current = e instanceof Error ? e.message : String(e);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
const returningRef = useRef(null);
|
|
2026
|
+
if (returningRef.current === null && callbackRef.current !== void 0) {
|
|
2027
|
+
returningRef.current = callbackRef.current !== null || callbackErrorRef.current !== null;
|
|
2028
|
+
}
|
|
2029
|
+
const completingRef = useRef(false);
|
|
2030
|
+
useEffect(() => {
|
|
2031
|
+
if (callbackErrorRef.current) {
|
|
2032
|
+
setNote(callbackErrorRef.current);
|
|
2033
|
+
callbackErrorRef.current = null;
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
const back = callbackRef.current;
|
|
2037
|
+
if (!back || completingRef.current) return;
|
|
2038
|
+
completingRef.current = true;
|
|
2039
|
+
let cancelled = false;
|
|
2040
|
+
(async () => {
|
|
2041
|
+
try {
|
|
2042
|
+
const keys = await deviceKeys();
|
|
2043
|
+
const sent = (() => {
|
|
2044
|
+
try {
|
|
2045
|
+
return sessionStorage.getItem(STATE_KEY);
|
|
2046
|
+
} catch {
|
|
2047
|
+
return null;
|
|
2048
|
+
}
|
|
2049
|
+
})();
|
|
2050
|
+
try {
|
|
2051
|
+
sessionStorage.removeItem(STATE_KEY);
|
|
2052
|
+
} catch {
|
|
2053
|
+
}
|
|
2054
|
+
if (!sent) {
|
|
2055
|
+
setNote(
|
|
2056
|
+
'This enrolment could not be verified as one this tab started, so it was not accepted. Start again from "Enrol with your account".'
|
|
2057
|
+
);
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
const enrolled = await completeDeviceEnrolment({
|
|
2061
|
+
...back,
|
|
2062
|
+
devicePublicKey: keys.signPk,
|
|
2063
|
+
kemPublicKey: keys.kemPk,
|
|
2064
|
+
expectState: sent
|
|
2065
|
+
});
|
|
2066
|
+
saveDelegatedCredential({
|
|
2067
|
+
account: enrolled.account,
|
|
2068
|
+
credential: enrolled.credential,
|
|
2069
|
+
deviceSecret: keys.signSk
|
|
2070
|
+
});
|
|
2071
|
+
const cloud = new CloudClient({
|
|
2072
|
+
cloudBaseUrl,
|
|
2073
|
+
routingCredential: {
|
|
2074
|
+
credential: enrolled.credential,
|
|
2075
|
+
deviceSecret: keys.signSk
|
|
2076
|
+
}
|
|
2077
|
+
});
|
|
2078
|
+
const chosen = chooseRelay(await cloud.getAccountRelays(enrolled.account));
|
|
2079
|
+
if (chosen.note) setNote(chosen.note);
|
|
2080
|
+
connectWithAccount({
|
|
2081
|
+
relayUrl: chosen.relayUrl,
|
|
2082
|
+
account: enrolled.account,
|
|
2083
|
+
credential: enrolled.credential,
|
|
2084
|
+
deviceSecret: keys.signSk,
|
|
2085
|
+
...chosen.executorAccount ? { executorAccount: chosen.executorAccount } : {}
|
|
2086
|
+
});
|
|
2087
|
+
} catch (e) {
|
|
2088
|
+
if (!cancelled) setNote(e instanceof Error ? e.message : String(e));
|
|
2089
|
+
}
|
|
2090
|
+
})();
|
|
2091
|
+
return () => {
|
|
2092
|
+
cancelled = true;
|
|
2093
|
+
};
|
|
2094
|
+
}, [connectWithAccount, cloudBaseUrl]);
|
|
2095
|
+
const goToWallet = useCallback(async () => {
|
|
2096
|
+
let keys;
|
|
2097
|
+
try {
|
|
2098
|
+
keys = await deviceKeys();
|
|
2099
|
+
} catch (e) {
|
|
2100
|
+
setNote(e instanceof Error ? e.message : String(e));
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
2103
|
+
const state = hex(crypto.getRandomValues(new Uint8Array(16)));
|
|
2104
|
+
try {
|
|
2105
|
+
sessionStorage.setItem(STATE_KEY, state);
|
|
2106
|
+
} catch {
|
|
2107
|
+
}
|
|
2108
|
+
window.location.assign(
|
|
2109
|
+
deviceEnrolmentUrl({
|
|
2110
|
+
walletUrl,
|
|
2111
|
+
devicePublicKey: keys.signPk,
|
|
2112
|
+
kemPublicKey: keys.kemPk,
|
|
2113
|
+
returnTo: window.location.origin + window.location.pathname,
|
|
2114
|
+
state
|
|
2115
|
+
})
|
|
2116
|
+
);
|
|
2117
|
+
}, [walletUrl]);
|
|
2118
|
+
return {
|
|
2119
|
+
goToWallet,
|
|
2120
|
+
note,
|
|
2121
|
+
returning: returningRef.current === true,
|
|
2122
|
+
walletUrl,
|
|
2123
|
+
customWallet: walletOverride !== void 0
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
1936
2126
|
var CUSTOM_SELECTION = "__custom__";
|
|
1937
2127
|
var TABS = [
|
|
1938
2128
|
{ id: "node", label: "Node" },
|
|
@@ -2216,8 +2406,21 @@ function LoginModal({
|
|
|
2216
2406
|
theme,
|
|
2217
2407
|
localNodePorts = DEFAULT_LOCAL_NODE_PORTS,
|
|
2218
2408
|
cloud,
|
|
2219
|
-
initialTab
|
|
2409
|
+
initialTab: initialTabProp
|
|
2220
2410
|
}) {
|
|
2411
|
+
const own = useAccountEnrolment({ enabled: cloud === void 0 });
|
|
2412
|
+
const cloudTab = useMemo(
|
|
2413
|
+
() => cloud === void 0 ? {
|
|
2414
|
+
onEnrol: () => {
|
|
2415
|
+
void own.goToWallet();
|
|
2416
|
+
},
|
|
2417
|
+
note: own.note,
|
|
2418
|
+
walletUrl: own.walletUrl,
|
|
2419
|
+
customWallet: own.customWallet
|
|
2420
|
+
} : cloud || null,
|
|
2421
|
+
[cloud, own.goToWallet, own.note, own.walletUrl, own.customWallet]
|
|
2422
|
+
);
|
|
2423
|
+
const initialTab = initialTabProp ?? (cloud === void 0 && own.returning ? "cloud" : "node");
|
|
2221
2424
|
const [tab, setTab] = useState(initialTab);
|
|
2222
2425
|
useEffect(() => {
|
|
2223
2426
|
if (isOpen) setTab(initialTab);
|
|
@@ -2226,7 +2429,7 @@ function LoginModal({
|
|
|
2226
2429
|
node: null,
|
|
2227
2430
|
cloud: null
|
|
2228
2431
|
});
|
|
2229
|
-
const activeTab =
|
|
2432
|
+
const activeTab = cloudTab ? tab : "node";
|
|
2230
2433
|
const [selected, setSelected] = useState(CUSTOM_SELECTION);
|
|
2231
2434
|
const [discovered, setDiscovered] = useState([]);
|
|
2232
2435
|
const [discovering, setDiscovering] = useState(false);
|
|
@@ -2426,7 +2629,7 @@ function LoginModal({
|
|
|
2426
2629
|
}
|
|
2427
2630
|
) })
|
|
2428
2631
|
] });
|
|
2429
|
-
if (!
|
|
2632
|
+
if (!cloudTab) return body;
|
|
2430
2633
|
return /* @__PURE__ */ jsx(
|
|
2431
2634
|
"div",
|
|
2432
2635
|
{
|
|
@@ -2487,8 +2690,8 @@ function LoginModal({
|
|
|
2487
2690
|
/* @__PURE__ */ jsx(CalimeroLogo, { size: 44, color: cssVar(resolved, "primary") }),
|
|
2488
2691
|
/* @__PURE__ */ jsx("h1", { style: styles.title, children: "Connect to Calimero" })
|
|
2489
2692
|
] }),
|
|
2490
|
-
|
|
2491
|
-
activeTab === "cloud" &&
|
|
2693
|
+
cloudTab && renderTabs(),
|
|
2694
|
+
activeTab === "cloud" && cloudTab ? /* @__PURE__ */ jsx(
|
|
2492
2695
|
"div",
|
|
2493
2696
|
{
|
|
2494
2697
|
role: "tabpanel",
|
|
@@ -2498,10 +2701,10 @@ function LoginModal({
|
|
|
2498
2701
|
children: /* @__PURE__ */ jsx(
|
|
2499
2702
|
AccountSignInPanel,
|
|
2500
2703
|
{
|
|
2501
|
-
onEnrol:
|
|
2502
|
-
note:
|
|
2503
|
-
walletUrl:
|
|
2504
|
-
customWallet:
|
|
2704
|
+
onEnrol: cloudTab.onEnrol,
|
|
2705
|
+
note: cloudTab.note,
|
|
2706
|
+
walletUrl: cloudTab.walletUrl,
|
|
2707
|
+
customWallet: cloudTab.customWallet,
|
|
2505
2708
|
theme
|
|
2506
2709
|
}
|
|
2507
2710
|
)
|
|
@@ -2511,190 +2714,6 @@ function LoginModal({
|
|
|
2511
2714
|
] });
|
|
2512
2715
|
return createPortal(modalContent, document.body);
|
|
2513
2716
|
}
|
|
2514
|
-
var DEVICE_KEY = "calimero.device";
|
|
2515
|
-
var STATE_KEY = "calimero.enrol.state";
|
|
2516
|
-
var HOSTED_WALLET = "https://wallet.cloud.calimero.network/account-enroll";
|
|
2517
|
-
var hex = (b) => [...new Uint8Array(b)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
2518
|
-
function executorOf(relay) {
|
|
2519
|
-
const value = relay.executorAccount;
|
|
2520
|
-
return typeof value === "string" && /^[0-9a-f]{64}$/.test(value) ? value : null;
|
|
2521
|
-
}
|
|
2522
|
-
function chooseRelay(relays) {
|
|
2523
|
-
const reachable = relays.filter(
|
|
2524
|
-
(r) => typeof r.relayUrl === "string" && r.relayUrl.length > 0
|
|
2525
|
-
);
|
|
2526
|
-
const fresh = reachable.find((r) => r.fresh);
|
|
2527
|
-
if (fresh) return { relayUrl: fresh.relayUrl, executorAccount: executorOf(fresh), note: null };
|
|
2528
|
-
if (reachable.length > 0) {
|
|
2529
|
-
return {
|
|
2530
|
-
relayUrl: reachable[0].relayUrl,
|
|
2531
|
-
executorAccount: executorOf(reachable[0]),
|
|
2532
|
-
note: "Connected through a relay whose last heartbeat has lapsed \u2014 it may not answer. It was the only one with an address."
|
|
2533
|
-
};
|
|
2534
|
-
}
|
|
2535
|
-
if (relays.length > 0) {
|
|
2536
|
-
return {
|
|
2537
|
-
relayUrl: null,
|
|
2538
|
-
executorAccount: null,
|
|
2539
|
-
note: `Signed in. Your account has ${relays.length} relay${relays.length === 1 ? "" : "s"} assigned, but the cloud knows no address for any of them yet, so there is nowhere to write through for the moment. Reads and writes resume as soon as one reports in.`
|
|
2540
|
-
};
|
|
2541
|
-
}
|
|
2542
|
-
return {
|
|
2543
|
-
relayUrl: null,
|
|
2544
|
-
executorAccount: null,
|
|
2545
|
-
note: "Signed in, with nowhere to write yet: a new account is a member of nothing, so no node serves it. Redeeming an invitation admits this account to a namespace and gives it a relay \u2014 that is the normal first step, not an error."
|
|
2546
|
-
};
|
|
2547
|
-
}
|
|
2548
|
-
async function deviceKeys() {
|
|
2549
|
-
const had = localStorage.getItem(DEVICE_KEY);
|
|
2550
|
-
if (had) {
|
|
2551
|
-
const parsed = JSON.parse(had);
|
|
2552
|
-
if (parsed.kemSk && parsed.signSk && parsed.signPk && parsed.kemPk) {
|
|
2553
|
-
return parsed;
|
|
2554
|
-
}
|
|
2555
|
-
localStorage.removeItem(DEVICE_KEY);
|
|
2556
|
-
}
|
|
2557
|
-
const sign = await crypto.subtle.generateKey({ name: "Ed25519" }, true, [
|
|
2558
|
-
"sign",
|
|
2559
|
-
"verify"
|
|
2560
|
-
]);
|
|
2561
|
-
let agree;
|
|
2562
|
-
try {
|
|
2563
|
-
agree = await crypto.subtle.generateKey({ name: "X25519" }, true, [
|
|
2564
|
-
"deriveBits"
|
|
2565
|
-
]);
|
|
2566
|
-
} catch {
|
|
2567
|
-
throw new Error(
|
|
2568
|
-
"this browser cannot generate an X25519 key, so it cannot receive wrapped scope keys. Chrome 133+ and Safari 17+ support it; enrolling without one would certify a delivery key nothing holds the secret for."
|
|
2569
|
-
);
|
|
2570
|
-
}
|
|
2571
|
-
const keys = {
|
|
2572
|
-
signPk: hex(await crypto.subtle.exportKey("raw", sign.publicKey)),
|
|
2573
|
-
signSk: hex((await crypto.subtle.exportKey("pkcs8", sign.privateKey)).slice(16)),
|
|
2574
|
-
kemPk: hex(await crypto.subtle.exportKey("raw", agree.publicKey)),
|
|
2575
|
-
kemSk: hex((await crypto.subtle.exportKey("pkcs8", agree.privateKey)).slice(16))
|
|
2576
|
-
};
|
|
2577
|
-
localStorage.setItem(DEVICE_KEY, JSON.stringify(keys));
|
|
2578
|
-
return keys;
|
|
2579
|
-
}
|
|
2580
|
-
function useAccountEnrolment({
|
|
2581
|
-
walletUrl: walletOverride,
|
|
2582
|
-
enabled = true
|
|
2583
|
-
} = {}) {
|
|
2584
|
-
const { connectWithAccount, cloudBaseUrl } = useMero();
|
|
2585
|
-
const [note, setNote] = useState(null);
|
|
2586
|
-
const walletUrl = walletOverride ?? HOSTED_WALLET;
|
|
2587
|
-
const callbackRef = useRef(void 0);
|
|
2588
|
-
const callbackErrorRef = useRef(null);
|
|
2589
|
-
if (enabled && callbackRef.current === void 0 && typeof window !== "undefined") {
|
|
2590
|
-
try {
|
|
2591
|
-
callbackRef.current = readEnrolmentCallback();
|
|
2592
|
-
} catch (e) {
|
|
2593
|
-
callbackRef.current = null;
|
|
2594
|
-
callbackErrorRef.current = e instanceof Error ? e.message : String(e);
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
const returningRef = useRef(null);
|
|
2598
|
-
if (returningRef.current === null && callbackRef.current !== void 0) {
|
|
2599
|
-
returningRef.current = callbackRef.current !== null || callbackErrorRef.current !== null;
|
|
2600
|
-
}
|
|
2601
|
-
const completingRef = useRef(false);
|
|
2602
|
-
useEffect(() => {
|
|
2603
|
-
if (callbackErrorRef.current) {
|
|
2604
|
-
setNote(callbackErrorRef.current);
|
|
2605
|
-
callbackErrorRef.current = null;
|
|
2606
|
-
return;
|
|
2607
|
-
}
|
|
2608
|
-
const back = callbackRef.current;
|
|
2609
|
-
if (!back || completingRef.current) return;
|
|
2610
|
-
completingRef.current = true;
|
|
2611
|
-
let cancelled = false;
|
|
2612
|
-
(async () => {
|
|
2613
|
-
try {
|
|
2614
|
-
const keys = await deviceKeys();
|
|
2615
|
-
const sent = (() => {
|
|
2616
|
-
try {
|
|
2617
|
-
return sessionStorage.getItem(STATE_KEY);
|
|
2618
|
-
} catch {
|
|
2619
|
-
return null;
|
|
2620
|
-
}
|
|
2621
|
-
})();
|
|
2622
|
-
try {
|
|
2623
|
-
sessionStorage.removeItem(STATE_KEY);
|
|
2624
|
-
} catch {
|
|
2625
|
-
}
|
|
2626
|
-
if (!sent) {
|
|
2627
|
-
setNote(
|
|
2628
|
-
'This enrolment could not be verified as one this tab started, so it was not accepted. Start again from "Enrol with your account".'
|
|
2629
|
-
);
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2632
|
-
const enrolled = await completeDeviceEnrolment({
|
|
2633
|
-
...back,
|
|
2634
|
-
devicePublicKey: keys.signPk,
|
|
2635
|
-
kemPublicKey: keys.kemPk,
|
|
2636
|
-
expectState: sent
|
|
2637
|
-
});
|
|
2638
|
-
saveDelegatedCredential({
|
|
2639
|
-
account: enrolled.account,
|
|
2640
|
-
credential: enrolled.credential,
|
|
2641
|
-
deviceSecret: keys.signSk
|
|
2642
|
-
});
|
|
2643
|
-
const cloud = new CloudClient({
|
|
2644
|
-
cloudBaseUrl,
|
|
2645
|
-
routingCredential: {
|
|
2646
|
-
credential: enrolled.credential,
|
|
2647
|
-
deviceSecret: keys.signSk
|
|
2648
|
-
}
|
|
2649
|
-
});
|
|
2650
|
-
const chosen = chooseRelay(await cloud.getAccountRelays(enrolled.account));
|
|
2651
|
-
if (chosen.note) setNote(chosen.note);
|
|
2652
|
-
connectWithAccount({
|
|
2653
|
-
relayUrl: chosen.relayUrl,
|
|
2654
|
-
account: enrolled.account,
|
|
2655
|
-
credential: enrolled.credential,
|
|
2656
|
-
deviceSecret: keys.signSk,
|
|
2657
|
-
...chosen.executorAccount ? { executorAccount: chosen.executorAccount } : {}
|
|
2658
|
-
});
|
|
2659
|
-
} catch (e) {
|
|
2660
|
-
if (!cancelled) setNote(e instanceof Error ? e.message : String(e));
|
|
2661
|
-
}
|
|
2662
|
-
})();
|
|
2663
|
-
return () => {
|
|
2664
|
-
cancelled = true;
|
|
2665
|
-
};
|
|
2666
|
-
}, [connectWithAccount, cloudBaseUrl]);
|
|
2667
|
-
const goToWallet = useCallback(async () => {
|
|
2668
|
-
let keys;
|
|
2669
|
-
try {
|
|
2670
|
-
keys = await deviceKeys();
|
|
2671
|
-
} catch (e) {
|
|
2672
|
-
setNote(e instanceof Error ? e.message : String(e));
|
|
2673
|
-
return;
|
|
2674
|
-
}
|
|
2675
|
-
const state = hex(crypto.getRandomValues(new Uint8Array(16)));
|
|
2676
|
-
try {
|
|
2677
|
-
sessionStorage.setItem(STATE_KEY, state);
|
|
2678
|
-
} catch {
|
|
2679
|
-
}
|
|
2680
|
-
window.location.assign(
|
|
2681
|
-
deviceEnrolmentUrl({
|
|
2682
|
-
walletUrl,
|
|
2683
|
-
devicePublicKey: keys.signPk,
|
|
2684
|
-
kemPublicKey: keys.kemPk,
|
|
2685
|
-
returnTo: window.location.origin + window.location.pathname,
|
|
2686
|
-
state
|
|
2687
|
-
})
|
|
2688
|
-
);
|
|
2689
|
-
}, [walletUrl]);
|
|
2690
|
-
return {
|
|
2691
|
-
goToWallet,
|
|
2692
|
-
note,
|
|
2693
|
-
returning: returningRef.current === true,
|
|
2694
|
-
walletUrl,
|
|
2695
|
-
customWallet: walletOverride !== void 0
|
|
2696
|
-
};
|
|
2697
|
-
}
|
|
2698
2717
|
function shortAccount(account) {
|
|
2699
2718
|
return account.length > 14 ? `${account.slice(0, 6)}\u2026${account.slice(-6)}` : account;
|
|
2700
2719
|
}
|
|
@@ -2873,7 +2892,7 @@ function ConnectButton({
|
|
|
2873
2892
|
note: enrolment.note,
|
|
2874
2893
|
walletUrl: enrolment.walletUrl,
|
|
2875
2894
|
customWallet: enrolment.customWallet
|
|
2876
|
-
} :
|
|
2895
|
+
} : false,
|
|
2877
2896
|
initialTab: cloud && enrolment.returning ? "cloud" : "node"
|
|
2878
2897
|
}
|
|
2879
2898
|
)
|
|
@@ -3033,7 +3052,8 @@ function ConnectButtonAccount({
|
|
|
3033
3052
|
connectToNode(url);
|
|
3034
3053
|
},
|
|
3035
3054
|
onClose: () => setIsNodeModalOpen(false),
|
|
3036
|
-
theme: resolvedTheme ?? theme
|
|
3055
|
+
theme: resolvedTheme ?? theme,
|
|
3056
|
+
cloud: false
|
|
3037
3057
|
}
|
|
3038
3058
|
)
|
|
3039
3059
|
] });
|
|
@@ -5045,6 +5065,6 @@ function useJoinInvitation() {
|
|
|
5045
5065
|
return { joinInvitation, joining, memberships, invitationRedeemer };
|
|
5046
5066
|
}
|
|
5047
5067
|
|
|
5048
|
-
export { AccountSignInPanel, AppMode, CalimeroLogo, ConnectButton, ConnectButtonAccount, ConnectionType, DEFAULT_MIGRATION_POLL_INTERVAL_MS, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, InvitationNotClaimableError, LoginModal, MERO_CSS_VARS, MeroContext, MeroProvider, MigrationAdminPanel, MigrationPendingBanner, NoRelayError, NotForAccountError, bootstrapFromInvitation, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearDelegatedCredential, clearNodeUrl, clearTokenNodeUrl, createAccountAdmin, createDelegatedContext, createNodeAdmin, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, isFinalInvitationError, joinWithNode, listDelegatedContexts, localStorageTokenStorage, normaliseAccount, pinRelayNodeKey, readDelegatedCredential, readPinnedRelayNodeKey, readRelayMap, relayForContext, rememberRelay, resolveMeroTheme, resolveRelayFromInvitation, saveDelegatedCredential, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAccountEnrolment, useAddGroupMembers, useAppVersion, useApplicationContexts, useBlobInfo, useBlobUrl, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useCreatePrivateContext, useDefaultCapabilities, useDelegatedBootstrap, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useEphemeral, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinInvitation, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationEvents, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useNodeIdentity, useRedeemInvitation, useRemoveGroupMembers, useReparentGroup, useResyncContext, useRetryGroupUpgrade, useSetContextMetadata, useSetDefaultCapabilities, useSetGroupMetadata, useSetMemberMetadata, useSetSubgroupVisibility, useSetTeeAdmissionPolicy, useSubgroupVisibility, useSubgroups, useSubscription, useSyncGroup, useUpdateMemberRole, useUpgradeGroup, useUploadBlob };
|
|
5068
|
+
export { AccountSignInPanel, AppMode, CalimeroLogo, ConnectButton, ConnectButtonAccount, ConnectionType, DEFAULT_MIGRATION_POLL_INTERVAL_MS, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, InvitationNotClaimableError, LoginModal, MERO_CSS_VARS, MeroContext, MeroProvider, MigrationAdminPanel, MigrationPendingBanner, NoRelayError, NotForAccountError, bootstrapFromInvitation, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearDelegatedCredential, clearNodeUrl, clearTokenNodeUrl, createAccountAdmin, createDelegatedContext, createNodeAdmin, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, isFinalInvitationError, isReturningFromWallet, joinWithNode, listDelegatedContexts, localStorageTokenStorage, normaliseAccount, pinRelayNodeKey, readDelegatedCredential, readPinnedRelayNodeKey, readRelayMap, relayForContext, rememberRelay, resolveMeroTheme, resolveRelayFromInvitation, saveDelegatedCredential, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAccountEnrolment, useAddGroupMembers, useAppVersion, useApplicationContexts, useBlobInfo, useBlobUrl, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useCreatePrivateContext, useDefaultCapabilities, useDelegatedBootstrap, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useEphemeral, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinInvitation, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationEvents, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useNodeIdentity, useRedeemInvitation, useRemoveGroupMembers, useReparentGroup, useResyncContext, useRetryGroupUpgrade, useSetContextMetadata, useSetDefaultCapabilities, useSetGroupMetadata, useSetMemberMetadata, useSetSubgroupVisibility, useSetTeeAdmissionPolicy, useSubgroupVisibility, useSubgroups, useSubscription, useSyncGroup, useUpdateMemberRole, useUpgradeGroup, useUploadBlob };
|
|
5049
5069
|
//# sourceMappingURL=index.js.map
|
|
5050
5070
|
//# sourceMappingURL=index.js.map
|