@calimero-network/mero-react 9.8.1 → 9.9.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/dist/index.cjs CHANGED
@@ -304,6 +304,11 @@ function rememberRelay(account, relayUrl, at) {
304
304
  function relayForContext(account, contextId) {
305
305
  return readRelayMap(account).contexts[contextId] ?? null;
306
306
  }
307
+ function carryExecutorAccount(prev, next) {
308
+ if (next.executorAccount || !prev?.executorAccount || !prev.relayUrl || !next.relayUrl) return next;
309
+ if (relayOrigin(prev.relayUrl) !== relayOrigin(next.relayUrl)) return next;
310
+ return { ...next, executorAccount: prev.executorAccount };
311
+ }
307
312
  function knownRelays(s) {
308
313
  const map = readRelayMap(s.account);
309
314
  const all = [s.relayUrl, ...Object.values(map.namespaces), ...Object.values(map.contexts)].filter((u) => typeof u === "string" && u.length > 0).map(relayOrigin);
@@ -1071,7 +1076,7 @@ async function joinAsAccount(session, namespaceId, invitation, opts) {
1071
1076
  });
1072
1077
  }
1073
1078
  if (outcome.session.relayUrl) rememberRelay(session.account, outcome.session.relayUrl, { namespaceId });
1074
- opts.onJoined(outcome.session);
1079
+ opts.onJoined(carryExecutorAccount(session, outcome.session));
1075
1080
  return { namespaceId };
1076
1081
  }
1077
1082
 
@@ -2429,26 +2434,33 @@ var DEVICE_KEY = "calimero.device";
2429
2434
  var STATE_KEY = "calimero.enrol.state";
2430
2435
  var HOSTED_WALLET = "https://wallet.cloud.calimero.network/account-enroll";
2431
2436
  var hex = (b) => [...new Uint8Array(b)].map((x) => x.toString(16).padStart(2, "0")).join("");
2437
+ function executorOf(relay) {
2438
+ const value = relay.executorAccount;
2439
+ return typeof value === "string" && /^[0-9a-f]{64}$/.test(value) ? value : null;
2440
+ }
2432
2441
  function chooseRelay(relays) {
2433
2442
  const reachable = relays.filter(
2434
2443
  (r) => typeof r.relayUrl === "string" && r.relayUrl.length > 0
2435
2444
  );
2436
2445
  const fresh = reachable.find((r) => r.fresh);
2437
- if (fresh) return { relayUrl: fresh.relayUrl, note: null };
2446
+ if (fresh) return { relayUrl: fresh.relayUrl, executorAccount: executorOf(fresh), note: null };
2438
2447
  if (reachable.length > 0) {
2439
2448
  return {
2440
2449
  relayUrl: reachable[0].relayUrl,
2450
+ executorAccount: executorOf(reachable[0]),
2441
2451
  note: "Connected through a relay whose last heartbeat has lapsed \u2014 it may not answer. It was the only one with an address."
2442
2452
  };
2443
2453
  }
2444
2454
  if (relays.length > 0) {
2445
2455
  return {
2446
2456
  relayUrl: null,
2457
+ executorAccount: null,
2447
2458
  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.`
2448
2459
  };
2449
2460
  }
2450
2461
  return {
2451
2462
  relayUrl: null,
2463
+ executorAccount: null,
2452
2464
  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."
2453
2465
  };
2454
2466
  }
@@ -2560,7 +2572,8 @@ function useAccountEnrolment({
2560
2572
  relayUrl: chosen.relayUrl,
2561
2573
  account: enrolled.account,
2562
2574
  credential: enrolled.credential,
2563
- deviceSecret: keys.signSk
2575
+ deviceSecret: keys.signSk,
2576
+ ...chosen.executorAccount ? { executorAccount: chosen.executorAccount } : {}
2564
2577
  });
2565
2578
  } catch (e) {
2566
2579
  if (!cancelled) setNote(e instanceof Error ? e.message : String(e));
@@ -4824,7 +4837,7 @@ function useDelegatedBootstrap(options = {}) {
4824
4837
  contextId: input.contextId
4825
4838
  });
4826
4839
  }
4827
- connectWithAccount(outcome.session);
4840
+ connectWithAccount(carryExecutorAccount(readDelegatedSession(), outcome.session));
4828
4841
  }
4829
4842
  return outcome;
4830
4843
  } finally {