@calimero-network/mero-react 9.11.3 → 9.11.4

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.d.cts CHANGED
@@ -677,7 +677,8 @@ declare function MigrationAdminPanel({ namespaceId, pollIntervalMs, className }:
677
677
  *
678
678
  * - `admitters-lookup` — the cloud read itself failed (offline, 5xx, a refused
679
679
  * routing proof). Nothing has been learned about the namespace.
680
- * - `no-nodes` — the read succeeded and the cloud lists nothing. The namespace
680
+ * - `no-nodes` — the read succeeded and the cloud lists nothing, and the
681
+ * invitation carries no http(s) address of an admitter either. The namespace
681
682
  * has no fleet assignment, so there is no cloud node to admit through; the
682
683
  * invitation's admitters are somebody's self-hosted or desktop node, which the
683
684
  * cloud neither knows nor routes to.
@@ -698,9 +699,13 @@ interface ResolvedInvitationRelay {
698
699
  readonly relayUrl: string;
699
700
  /** Where to POST the signed join — the cloud's own, never rebuilt when given. */
700
701
  readonly admitUrl: string;
701
- /** The admitter's account, as the cloud reported it. */
702
+ /**
703
+ * The admitter's account: as the cloud reported it, or — for a relay the
704
+ * invitation itself named — the one admitter it names, when it names one.
705
+ */
702
706
  readonly admitterAccount: string | null;
703
- readonly peerId: string;
707
+ /** The node's peer id as the cloud reported it; `null` for a relay the invitation named. */
708
+ readonly peerId: string | null;
704
709
  /**
705
710
  * Whether this node can also run delegated writes (`CAN_AUTHOR_ON_BEHALF`).
706
711
  *
@@ -711,6 +716,11 @@ interface ResolvedInvitationRelay {
711
716
  readonly writable: boolean;
712
717
  /** Whether the chosen node's heartbeat for this namespace has lapsed. */
713
718
  readonly stale: boolean;
719
+ /**
720
+ * Who named this relay: the cloud's routing, or the invitation's own
721
+ * `admitter_addrs` when the cloud routed the namespace to no node.
722
+ */
723
+ readonly via: 'cloud' | 'invitation';
714
724
  }
715
725
  interface RelayResolutionFailure {
716
726
  readonly ok: false;
@@ -731,6 +741,15 @@ interface ResolveRelayFromInvitationInput {
731
741
  * here that means "nobody may admit", because an invitation cannot say that.
732
742
  */
733
743
  readonly admitters?: readonly string[];
744
+ /**
745
+ * The invitation's `admitter_addrs`: where its admitters are reached. Core
746
+ * emits libp2p multiaddrs here; an account minting through mero-react adds
747
+ * its relay's http(s) origin. Only the http(s) entries are of use to a
748
+ * browser, and only when the cloud routes the namespace to no node — the
749
+ * case of a namespace whose founder never linked the account, which the
750
+ * cloud does not route yet whose own relay admits.
751
+ */
752
+ readonly admitterAddrs?: readonly string[];
734
753
  /** The delegated credential — an `AccountProof<DeviceCert>`, hex. */
735
754
  readonly credential: string;
736
755
  /** The certified device's ed25519 signing secret, hex. */
@@ -910,7 +929,10 @@ declare function joinWithNode(input: JoinWithNodeInput): Promise<JoinWithNodeRes
910
929
  * nothing to read off the invitation yet and this is the seam for when there
911
930
  * is;
912
931
  * 2. the cloud's `/api/cloud/namespaces/{ns}/admitters`, intersected with the
913
- * invitation's signed `admitters` — see `resolveRelayFromInvitation`.
932
+ * invitation's signed `admitters` — see `resolveRelayFromInvitation`;
933
+ * 3. an http(s) origin in the invitation's `admitter_addrs`, when the cloud
934
+ * routes the namespace to no node: the relay of a founder who never linked
935
+ * the account writes its own origin there when it mints.
914
936
  *
915
937
  * # Nothing here is minted, weakened or worked around
916
938
  *
@@ -1232,8 +1254,10 @@ declare class NoRelayError extends Error {
1232
1254
  * cloud's routing, intersected with the invitation's signed admitters, so an
1233
1255
  * invitation the cloud routes to none of them can only fail in their hands.
1234
1256
  *
1235
- * - `not-hosted` — the cloud serves the namespace on no node: HA was never
1236
- * enabled for it (not linked in the wallet, quota, or founding not attested).
1257
+ * - `not-hosted` — the cloud serves the namespace on no node AND no relay is a
1258
+ * member of it, so nothing admits a node-less claimant. A namespace with a
1259
+ * relay in it is minted for even when the cloud routes it nowhere: the relay
1260
+ * admits through its own `/admit`, and the invitation carries its address.
1237
1261
  * - `no-named-node` — the cloud's nodes are not among the admitters this
1238
1262
  * invitation would name.
1239
1263
  */
package/dist/index.d.ts CHANGED
@@ -677,7 +677,8 @@ declare function MigrationAdminPanel({ namespaceId, pollIntervalMs, className }:
677
677
  *
678
678
  * - `admitters-lookup` — the cloud read itself failed (offline, 5xx, a refused
679
679
  * routing proof). Nothing has been learned about the namespace.
680
- * - `no-nodes` — the read succeeded and the cloud lists nothing. The namespace
680
+ * - `no-nodes` — the read succeeded and the cloud lists nothing, and the
681
+ * invitation carries no http(s) address of an admitter either. The namespace
681
682
  * has no fleet assignment, so there is no cloud node to admit through; the
682
683
  * invitation's admitters are somebody's self-hosted or desktop node, which the
683
684
  * cloud neither knows nor routes to.
@@ -698,9 +699,13 @@ interface ResolvedInvitationRelay {
698
699
  readonly relayUrl: string;
699
700
  /** Where to POST the signed join — the cloud's own, never rebuilt when given. */
700
701
  readonly admitUrl: string;
701
- /** The admitter's account, as the cloud reported it. */
702
+ /**
703
+ * The admitter's account: as the cloud reported it, or — for a relay the
704
+ * invitation itself named — the one admitter it names, when it names one.
705
+ */
702
706
  readonly admitterAccount: string | null;
703
- readonly peerId: string;
707
+ /** The node's peer id as the cloud reported it; `null` for a relay the invitation named. */
708
+ readonly peerId: string | null;
704
709
  /**
705
710
  * Whether this node can also run delegated writes (`CAN_AUTHOR_ON_BEHALF`).
706
711
  *
@@ -711,6 +716,11 @@ interface ResolvedInvitationRelay {
711
716
  readonly writable: boolean;
712
717
  /** Whether the chosen node's heartbeat for this namespace has lapsed. */
713
718
  readonly stale: boolean;
719
+ /**
720
+ * Who named this relay: the cloud's routing, or the invitation's own
721
+ * `admitter_addrs` when the cloud routed the namespace to no node.
722
+ */
723
+ readonly via: 'cloud' | 'invitation';
714
724
  }
715
725
  interface RelayResolutionFailure {
716
726
  readonly ok: false;
@@ -731,6 +741,15 @@ interface ResolveRelayFromInvitationInput {
731
741
  * here that means "nobody may admit", because an invitation cannot say that.
732
742
  */
733
743
  readonly admitters?: readonly string[];
744
+ /**
745
+ * The invitation's `admitter_addrs`: where its admitters are reached. Core
746
+ * emits libp2p multiaddrs here; an account minting through mero-react adds
747
+ * its relay's http(s) origin. Only the http(s) entries are of use to a
748
+ * browser, and only when the cloud routes the namespace to no node — the
749
+ * case of a namespace whose founder never linked the account, which the
750
+ * cloud does not route yet whose own relay admits.
751
+ */
752
+ readonly admitterAddrs?: readonly string[];
734
753
  /** The delegated credential — an `AccountProof<DeviceCert>`, hex. */
735
754
  readonly credential: string;
736
755
  /** The certified device's ed25519 signing secret, hex. */
@@ -910,7 +929,10 @@ declare function joinWithNode(input: JoinWithNodeInput): Promise<JoinWithNodeRes
910
929
  * nothing to read off the invitation yet and this is the seam for when there
911
930
  * is;
912
931
  * 2. the cloud's `/api/cloud/namespaces/{ns}/admitters`, intersected with the
913
- * invitation's signed `admitters` — see `resolveRelayFromInvitation`.
932
+ * invitation's signed `admitters` — see `resolveRelayFromInvitation`;
933
+ * 3. an http(s) origin in the invitation's `admitter_addrs`, when the cloud
934
+ * routes the namespace to no node: the relay of a founder who never linked
935
+ * the account writes its own origin there when it mints.
914
936
  *
915
937
  * # Nothing here is minted, weakened or worked around
916
938
  *
@@ -1232,8 +1254,10 @@ declare class NoRelayError extends Error {
1232
1254
  * cloud's routing, intersected with the invitation's signed admitters, so an
1233
1255
  * invitation the cloud routes to none of them can only fail in their hands.
1234
1256
  *
1235
- * - `not-hosted` — the cloud serves the namespace on no node: HA was never
1236
- * enabled for it (not linked in the wallet, quota, or founding not attested).
1257
+ * - `not-hosted` — the cloud serves the namespace on no node AND no relay is a
1258
+ * member of it, so nothing admits a node-less claimant. A namespace with a
1259
+ * relay in it is minted for even when the cloud routes it nowhere: the relay
1260
+ * admits through its own `/admit`, and the invitation carries its address.
1237
1261
  * - `no-named-node` — the cloud's nodes are not among the admitters this
1238
1262
  * invitation would name.
1239
1263
  */
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, readEnrolmentCallback, completeDeviceEnrolment, deviceEnrolmentUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, memberJoinedOpenOp, signerFromSecret, compareSemver, AuthRevokedError, HTTPError, contextDetachedOp, memberRoleSetOp, memberLeftOp, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, subgroupVisibilitySetOp, defaultCapabilitiesSetOp, contextMetadataSetOp, memberMetadataSetOp, groupMetadataSetOp, memberRemovedOp, memberAddedOp, subgroupCreation, createMeroClient, RelayClient, createLocalStorageNonceSource, classifyError, attestRelayNodeKey, login, defaultAudience, AccountNotLinkedError, AccountHaRefusedError, createSignedReleaseVerifier, fetchNodeRelease, cloudNodeReleaseUrl, DEFAULT_RELEASE_MIRROR, fetchNodeReleaseVersion } from '@calimero-network/mero-js';
2
+ import { signGroupInvitation, signMemberJoinOp, CloudClient, LocalStorageTokenStore, parseAuthCallback, MeroJs, buildAuthLoginUrl, readEnrolmentCallback, completeDeviceEnrolment, deviceEnrolmentUrl, DEFAULT_LOCAL_NODE_PORTS, discoverLocalNodes, nodeEndpoint, memberJoinedOpenOp, signerFromSecret, compareSemver, AuthRevokedError, HTTPError, contextDetachedOp, memberRoleSetOp, memberLeftOp, groupReparentedOp, groupDeletedOp, memberCapabilitySetOp, subgroupVisibilitySetOp, defaultCapabilitiesSetOp, contextMetadataSetOp, memberMetadataSetOp, groupMetadataSetOp, memberRemovedOp, memberAddedOp, subgroupCreation, createMeroClient, RelayClient, createLocalStorageNonceSource, classifyError, attestRelayNodeKey, login, defaultAudience, AccountNotLinkedError, AccountHaRefusedError, SseClient, 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';
@@ -319,10 +319,79 @@ function relaySession(s, nodeKey) {
319
319
  return inflight;
320
320
  };
321
321
  }
322
+ var methodKinds = /* @__PURE__ */ new Map();
323
+ function isNotAView(e) {
324
+ return typeof e === "object" && e !== null && e.status === 409;
325
+ }
326
+ function readsThroughQuery(client2, relayUrl) {
327
+ const inner = client2.rpc;
328
+ const origin2 = relayOrigin(relayUrl);
329
+ const run = async (params) => {
330
+ const key = `${origin2}|${params.contextId}|${params.method}`;
331
+ if (methodKinds.get(key) !== "write") {
332
+ try {
333
+ const { returns } = await client2.admin.queryContext(params.contextId, {
334
+ method: params.method,
335
+ // The node defaults a warrant's missing `argsJson` to `{}`; the same here.
336
+ argsJson: params.argsJson ?? {}
337
+ });
338
+ methodKinds.set(key, "read");
339
+ return { returns, transport: "relay" };
340
+ } catch (e) {
341
+ if (isNotAView(e)) methodKinds.set(key, "write");
342
+ }
343
+ }
344
+ return inner.executeWithMetadata(params);
345
+ };
346
+ return {
347
+ get kind() {
348
+ return inner.kind;
349
+ },
350
+ get canSubscribe() {
351
+ return inner.canSubscribe;
352
+ },
353
+ execute: async (params) => (await run(params)).returns,
354
+ executeWithMetadata: run,
355
+ migrateMyEntries: (contextId) => inner.migrateMyEntries(contextId),
356
+ countMyPending: (contextId) => inner.countMyPending(contextId)
357
+ };
358
+ }
359
+ function dormantEvents(relayUrl) {
360
+ return new SseClient({
361
+ baseUrl: relayUrl,
362
+ authorize: async () => ({}),
363
+ fetch: (_url, init) => new Promise((_, reject) => {
364
+ const abort = () => reject(Object.assign(new Error("the stream was closed before the relay was attested"), { name: "AbortError" }));
365
+ if (init?.signal?.aborted) return abort();
366
+ init?.signal?.addEventListener("abort", abort, { once: true });
367
+ })
368
+ });
369
+ }
370
+ function delegatedClient(client2, opts) {
371
+ const rpc = opts.session ? readsThroughQuery(client2, opts.relayUrl) : null;
372
+ let dormant = null;
373
+ return new Proxy(client2, {
374
+ get(target, prop) {
375
+ if (prop === "rpc" && rpc) return rpc;
376
+ if (!opts.attested) {
377
+ if (prop === "canSubscribe") return false;
378
+ if (prop === "events") return dormant ?? (dormant = dormantEvents(opts.relayUrl));
379
+ if (prop === "close") {
380
+ return () => {
381
+ dormant?.close();
382
+ target.close();
383
+ };
384
+ }
385
+ }
386
+ const value = Reflect.get(target, prop, target);
387
+ return typeof value === "function" ? value.bind(target) : value;
388
+ }
389
+ });
390
+ }
322
391
  function buildDelegatedClient(s, _contextId) {
323
392
  if (!s.relayUrl) return null;
324
393
  const nodeKey = readPinnedRelayNodeKey(s.relayUrl);
325
- return createMeroClient({
394
+ const client2 = createMeroClient({
326
395
  transport: "relay",
327
396
  relay: {
328
397
  relayUrl: s.relayUrl,
@@ -356,6 +425,11 @@ function buildDelegatedClient(s, _contextId) {
356
425
  // through its own device-certificate login instead.
357
426
  observe: nodeKey ? { nodeKey } : void 0
358
427
  });
428
+ return delegatedClient(client2, {
429
+ relayUrl: s.relayUrl,
430
+ session: nodeKey !== null,
431
+ attested: nodeKey !== null || isLoopback(s.relayUrl)
432
+ });
359
433
  }
360
434
  var RELAY_MAP_PREFIX = "calimero.delegated.relays.";
361
435
  function readRelayMap(account) {
@@ -731,7 +805,7 @@ var NoRelayError = class extends Error {
731
805
  var InvitationNotClaimableError = class extends Error {
732
806
  constructor(namespaceId, reason) {
733
807
  super(
734
- reason === "not-hosted" ? `nobody could claim an invitation to ${namespaceId} yet: the namespace is not hosted in the cloud, so an invitee with no node has no relay to be admitted through. Link this account to your cloud user in the wallet and enable HA for the namespace, then invite.` : `nobody could claim an invitation to ${namespaceId}: the cloud routes to none of the relays or admins it would name as admitters`
808
+ reason === "not-hosted" ? `nobody could claim an invitation to ${namespaceId} yet: the namespace is not hosted in the cloud and has no relay in it, so an invitee with no node has no relay to be admitted through. Link this account to your cloud user in the wallet and enable HA for the namespace, then invite.` : `nobody could claim an invitation to ${namespaceId}: the cloud routes to none of the relays or admins it would name as admitters`
735
809
  );
736
810
  this.namespaceId = namespaceId;
737
811
  this.reason = reason;
@@ -914,11 +988,12 @@ function createAccountAdmin(input, deps = {}) {
914
988
  name: req.name,
915
989
  initializationParams: req.initializationParams
916
990
  });
917
- return { contextId, memberPublicKey: "", groupId: req.groupId };
991
+ return { contextId, memberPublicKey: s.account, groupId: req.groupId };
918
992
  },
919
993
  async createNamespaceInvitation(namespaceId) {
920
994
  const [{ members }, info] = await Promise.all([relay().listGroupMembers(namespaceId), relay().getGroupInfo(namespaceId)]);
921
995
  const relays = members.filter((m) => m.role === "RelayTee").map((m) => m.identity.toLowerCase());
996
+ let admitterAddrs;
922
997
  if (routing) {
923
998
  const named = new Set(
924
999
  relays.length > 0 ? relays : members.filter((m) => m.role === "Admin").map((m) => m.identity.toLowerCase())
@@ -929,8 +1004,10 @@ function createAccountAdmin(input, deps = {}) {
929
1004
  } catch {
930
1005
  }
931
1006
  if (nodes !== null) {
932
- if (nodes.length === 0) throw new InvitationNotClaimableError(namespaceId, "not-hosted");
933
- if (!nodes.some((n) => n.account !== null && named.has(n.account.toLowerCase()))) {
1007
+ if (nodes.length === 0) {
1008
+ if (relays.length === 0 || !s.relayUrl) throw new InvitationNotClaimableError(namespaceId, "not-hosted");
1009
+ admitterAddrs = [s.relayUrl];
1010
+ } else if (!nodes.some((n) => n.account !== null && named.has(n.account.toLowerCase()))) {
934
1011
  throw new InvitationNotClaimableError(namespaceId, "no-named-node");
935
1012
  }
936
1013
  }
@@ -940,6 +1017,7 @@ function createAccountAdmin(input, deps = {}) {
940
1017
  inviterAccount: s.account,
941
1018
  deviceSecret: s.deviceSecret,
942
1019
  ...relays.length > 0 ? { admitters: relays } : {},
1020
+ ...admitterAddrs ? { admitterAddrs } : {},
943
1021
  members,
944
1022
  applicationId: info.targetApplicationId,
945
1023
  appKey: info.appKey
@@ -1076,6 +1154,17 @@ function normaliseAccount(account) {
1076
1154
  const bare = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed;
1077
1155
  return bare.length > 0 ? bare : null;
1078
1156
  }
1157
+ function httpAdmitterOrigins(addrs) {
1158
+ const out = [];
1159
+ for (const addr of addrs ?? []) {
1160
+ try {
1161
+ const url = new URL(addr);
1162
+ if (url.protocol === "http:" || url.protocol === "https:") out.push(addr.replace(/\/+$/, ""));
1163
+ } catch {
1164
+ }
1165
+ }
1166
+ return out;
1167
+ }
1079
1168
  function isInvited(node, invited) {
1080
1169
  if (invited.size === 0) return true;
1081
1170
  const account = normaliseAccount(node.account);
@@ -1100,6 +1189,23 @@ async function resolveRelayFromInvitation(input) {
1100
1189
  };
1101
1190
  }
1102
1191
  if (nodes.length === 0) {
1192
+ const [relayUrl] = httpAdmitterOrigins(input.admitterAddrs);
1193
+ if (relayUrl) {
1194
+ const admitters = (input.admitters ?? []).map(normaliseAccount).filter((a) => a !== null);
1195
+ return {
1196
+ ok: true,
1197
+ relayUrl,
1198
+ admitUrl: `${relayUrl}/admin-api/namespaces/${input.namespaceId}/admit`,
1199
+ admitterAccount: admitters.length === 1 ? admitters[0] : null,
1200
+ peerId: null,
1201
+ // The relay a founder's session runs through executes that founder's
1202
+ // warrants, so it authors on behalf; the node's answer to the first
1203
+ // write is the authoritative one, as for a cloud-routed node.
1204
+ writable: true,
1205
+ stale: false,
1206
+ via: "invitation"
1207
+ };
1208
+ }
1103
1209
  return {
1104
1210
  ok: false,
1105
1211
  step: "no-nodes",
@@ -1143,7 +1249,8 @@ async function resolveRelayFromInvitation(input) {
1143
1249
  // Stale when the node's own heartbeat lapsed OR when the cloud's summary
1144
1250
  // disagrees with trying it at all. Both mean the same thing to a caller:
1145
1251
  // this was attempted on advisory data, so if the admit fails that is why.
1146
- stale: !chosen.fresh || advisory
1252
+ stale: !chosen.fresh || advisory,
1253
+ via: "cloud"
1147
1254
  };
1148
1255
  }
1149
1256
 
@@ -1161,6 +1268,7 @@ async function bootstrapFromInvitation(input) {
1161
1268
  // separately: two sources for one fact is how an intersection ends up
1162
1269
  // being performed against the wrong list.
1163
1270
  admitters: input.invitation.invitation.admitters,
1271
+ admitterAddrs: input.invitation.admitter_addrs,
1164
1272
  credential: input.credential.credential,
1165
1273
  deviceSecret: input.credential.deviceSecret,
1166
1274
  cloudBaseUrl: input.cloudBaseUrl