@calimero-network/mero-js 26.4.1 → 26.5.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.d.ts CHANGED
@@ -28,8 +28,8 @@ export { signerFromSecret, signerFromCryptoKey } from "./signer/index.js";
28
28
  export type { Signer } from "./signer/index.js";
29
29
  export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, createAccountRootSigner, accountRootSignerFromPhrase, signAccountLink, signAccountLogin, resolveRoot, resolveRootPair, } from "./account/index.js";
30
30
  export type { AccountRoot, RecoverableAccountRoot, AccountRootSigner, NewAccountRootSigner, AccountLinkInput, AccountLoginInput, RootSource, ResolvedRoot, } from "./account/index.js";
31
- export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
32
- export type { DelegatedCredential, DelegatedAccountSession, RelayMap, RelayNodeKeyAttempt, RelayResolutionStep, RelayResolutionFailure, ResolvedInvitationRelay, ResolveRelayResult, ResolveRelayFromInvitationInput, JoinWithNodeInput, JoinWithNodeResult, JoinWithNodeSuccess, JoinWithNodeFailure, JoinWithNodeStep, BootstrapStep, BootstrapResult, BootstrapSuccess, BootstrapFailure, BootstrapFromInvitationInput, CreateDelegatedContextRequest, FoundedDelegatedNamespace, RegistryBundle, ResolvedApplication, AccountAdminDeps, NodeAdminDeps, } from "./account/index.js";
31
+ export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
32
+ export type { DelegatedCredential, DelegatedAccountSession, RelayMap, RelayNodeKeyAttempt, RelayListingFailure, RelayResolutionStep, RelayResolutionFailure, ResolvedInvitationRelay, ResolveRelayResult, ResolveRelayFromInvitationInput, JoinWithNodeInput, JoinWithNodeResult, JoinWithNodeSuccess, JoinWithNodeFailure, JoinWithNodeStep, BootstrapStep, BootstrapResult, BootstrapSuccess, BootstrapFailure, BootstrapFromInvitationInput, CreateDelegatedContextRequest, FoundedDelegatedNamespace, RegistryBundle, ResolvedApplication, AccountAdminDeps, NodeAdminDeps, } from "./account/index.js";
33
33
  export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, parseDeviceCredential, verifyDeviceCredential, } from "./device-cert/index.js";
34
34
  export type { DeviceCertInput, DeviceCredential } from "./device-cert/index.js";
35
35
  export { signDeviceScope, deviceScopePayload } from "./device-cert/index.js";
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ resolveRoot, resolveRootPair, } from "./account/index.js";
52
52
  // Framework-free; mero-react re-exports every one of these under the same name
53
53
  // (its `DelegatedSession` is `DelegatedAccountSession` here: the login module
54
54
  // already owns the bare name for the session `login()` mints).
55
- export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
55
+ export { readDelegatedSession, saveDelegatedSession, clearDelegatedSession, readDelegatedCredential, saveDelegatedCredential, clearDelegatedCredential, persistedNonces, markContextNonceSpent, pinRelayNodeKey, readPinnedRelayNodeKey, attemptRelayNodeKey, resolveRelayNodeKey, learnRelayNodeKey, RELAY_NODE_KEY_RETRY_MS, forgetMethodKinds, forgetRelaySealing, relayTransportFetch, buildDelegatedClient, readRelayMap, rememberRelay, relayForContext, carryExecutorAccount, knownRelays, listDelegatedContexts, listDelegatedNamespaces, RelaysUnavailableError, resolveRelayFromInvitation, normaliseAccount, joinWithNode, bootstrapFromInvitation, joinAsAccount, createDelegatedContext, createDelegatedPrivateContext, foundDelegatedNamespace, delegatedGovernance, latestPublishedVersion, HA_ACCOUNT_NOT_LINKED_MESSAGE, HA_REFUSAL_MESSAGES, governGroup, governRoot, namespaceOfGroup, rememberGroupNamespace, applicationIdForBundle, fetchRegistryBundles, resolveApplicationIdFromRegistry, selectLatestBundle, createAccountAdmin, InvitationNotClaimableError, NoRelayError, NotForAccountError, createNodeAdmin, } from "./account/index.js";
56
56
  export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, parseDeviceCredential, verifyDeviceCredential, } from "./device-cert/index.js";
57
57
  // A device's scope — signed by the root beside its certificate, and what a relay
58
58
  // needs with it to bind the device of an account that has no node.
package/dist/index.mjs CHANGED
@@ -9570,24 +9570,53 @@ function knownRelays(s) {
9570
9570
  const all = [s.relayUrl, ...Object.values(map.namespaces), ...Object.values(map.contexts)].filter((u) => typeof u === "string" && u.length > 0).map(relayOrigin);
9571
9571
  return [...new Set(all)];
9572
9572
  }
9573
+ var RelaysUnavailableError = class extends Error {
9574
+ constructor(failures) {
9575
+ super(`none of this account's relays answered: ${failures.map((f) => `${f.relayUrl} (${f.kind})`).join(", ")}`);
9576
+ this.failures = failures;
9577
+ this.name = "RelaysUnavailableError";
9578
+ this.relays = failures.map((f) => f.relayUrl);
9579
+ }
9580
+ /** Every relay refused its attestation: retrying will not help. */
9581
+ get refused() {
9582
+ return this.failures.every((f) => f.kind === "refused");
9583
+ }
9584
+ };
9585
+ async function listingClient(s, relayUrl) {
9586
+ const key = await attemptRelayNodeKey(relayUrl);
9587
+ if (key.kind !== "learned") {
9588
+ console.warn("[mero-js] could not learn the relay node key from its attestation", key.error);
9589
+ return { failure: { relayUrl, kind: key.kind, error: key.error } };
9590
+ }
9591
+ const client2 = buildDelegatedClient({ ...s, relayUrl }, null);
9592
+ if (!client2) return { failure: { relayUrl, kind: "unavailable", error: new Error(`no client for ${relayUrl}`) } };
9593
+ return { client: client2 };
9594
+ }
9573
9595
  async function listDelegatedContexts(s) {
9574
9596
  const out = [];
9575
9597
  const map = readRelayMap(s.account);
9576
- for (const relayUrl of knownRelays(s)) {
9598
+ const relays = knownRelays(s);
9599
+ const failures = [];
9600
+ for (const relayUrl of relays) {
9601
+ const got = await listingClient(s, relayUrl);
9602
+ if ("failure" in got) {
9603
+ failures.push(got.failure);
9604
+ continue;
9605
+ }
9606
+ const { client: client2 } = got;
9577
9607
  try {
9578
- if (!await resolveRelayNodeKey(relayUrl)) continue;
9579
- const client2 = buildDelegatedClient({ ...s, relayUrl }, null);
9580
- if (!client2) continue;
9581
9608
  const { contexts } = await client2.admin.getContexts();
9582
9609
  for (const c of contexts ?? []) {
9583
9610
  out.push({ ...c, relayUrl });
9584
9611
  map.contexts[c.id] = relayUrl;
9585
9612
  }
9586
9613
  } catch (e) {
9614
+ failures.push({ relayUrl, kind: "unavailable", error: e });
9587
9615
  console.warn(`[mero-js] could not list contexts on ${relayUrl}`, e);
9588
9616
  }
9589
9617
  }
9590
9618
  writeRelayMap(s.account, map);
9619
+ if (relays.length > 0 && failures.length === relays.length) throw new RelaysUnavailableError(failures);
9591
9620
  return out;
9592
9621
  }
9593
9622
  async function listDelegatedNamespaces(s) {
@@ -9595,11 +9624,16 @@ async function listDelegatedNamespaces(s) {
9595
9624
  const out = [];
9596
9625
  const seen = /* @__PURE__ */ new Set();
9597
9626
  const map = readRelayMap(s.account);
9598
- for (const relayUrl of knownRelays(s)) {
9627
+ const relays = knownRelays(s);
9628
+ const failures = [];
9629
+ for (const relayUrl of relays) {
9630
+ const got = await listingClient(s, relayUrl);
9631
+ if ("failure" in got) {
9632
+ failures.push(got.failure);
9633
+ continue;
9634
+ }
9635
+ const { client: client2 } = got;
9599
9636
  try {
9600
- if (!await resolveRelayNodeKey(relayUrl)) continue;
9601
- const client2 = buildDelegatedClient({ ...s, relayUrl }, null);
9602
- if (!client2) continue;
9603
9637
  for (const ns of await client2.admin.listNamespaces()) {
9604
9638
  if (seen.has(ns.namespaceId)) continue;
9605
9639
  seen.add(ns.namespaceId);
@@ -9607,10 +9641,12 @@ async function listDelegatedNamespaces(s) {
9607
9641
  (_a = map.namespaces)[_b = ns.namespaceId] ?? (_a[_b] = relayUrl);
9608
9642
  }
9609
9643
  } catch (e) {
9644
+ failures.push({ relayUrl, kind: "unavailable", error: e });
9610
9645
  console.warn(`[mero-js] could not list namespaces on ${relayUrl}`, e);
9611
9646
  }
9612
9647
  }
9613
9648
  writeRelayMap(s.account, map);
9649
+ if (relays.length > 0 && failures.length === relays.length) throw new RelaysUnavailableError(failures);
9614
9650
  return out;
9615
9651
  }
9616
9652
 
@@ -13133,6 +13169,7 @@ export {
13133
13169
  RelayObserver,
13134
13170
  RelayPresenceClient,
13135
13171
  RelayTransport,
13172
+ RelaysUnavailableError,
13136
13173
  RpcClient,
13137
13174
  RpcError,
13138
13175
  SEALED_CONTENT_TYPE,