@calimero-network/mero-js 19.12.0 → 19.13.1

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.mjs CHANGED
@@ -5086,6 +5086,61 @@ var CloudClient = class {
5086
5086
  const challenge = await this.getRoutingChallenge(namespaceId);
5087
5087
  return routingProofHeaders(challenge, this.routingCredential);
5088
5088
  }
5089
+ /**
5090
+ * Ask the cloud for a challenge bound to one ACCOUNT.
5091
+ *
5092
+ * Public and unauthenticated like {@link getRoutingChallenge}: an account id
5093
+ * is `H(genesis(root_pk))` and travels in the clear in every device-link op,
5094
+ * so naming one here reveals nothing and authorises nothing. MDMA re-derives
5095
+ * the account from the certificate and refuses a mismatch.
5096
+ */
5097
+ async getAccountRelaysChallenge(accountId) {
5098
+ const body = await this.request("GET", `/api/cloud/accounts/${encodeURIComponent(accountId)}/challenge`, {
5099
+ anonymous: true
5100
+ });
5101
+ return {
5102
+ accountId: String(body.account_id ?? accountId),
5103
+ nonce: String(body.nonce ?? ""),
5104
+ expiresAtMs: Number(body.expires_at_ms ?? 0)
5105
+ };
5106
+ }
5107
+ /**
5108
+ * Which relays serve this account — the bootstrap, and nothing more.
5109
+ *
5110
+ * A device holding a certificate can resolve a namespace it can *name*
5111
+ * ({@link getNamespaceRouting}) and can ask a node it can *reach* what its
5112
+ * account belongs to. It starts with neither. This closes that one gap.
5113
+ *
5114
+ * **It does not return namespaces, deliberately.** The node answers that from
5115
+ * the governance DAG, scoped to the calling account: log in at one of these
5116
+ * relays with an account proof and read its namespace listing. A cloud-side
5117
+ * copy would be a second source of truth built from rows that linger for an
5118
+ * account which left a namespace.
5119
+ *
5120
+ * So the sequence is: this → log in at a relay → ask it what you are in.
5121
+ *
5122
+ * Proven with the **device certificate**, not a cloud session, so it needs a
5123
+ * `routingCredential` and throws without one rather than returning an empty
5124
+ * list — "you configured no credential" and "you have no relays" are
5125
+ * different answers and must not look alike.
5126
+ */
5127
+ async getAccountRelays(accountId) {
5128
+ if (!this.routingCredential) {
5129
+ throw new Error(
5130
+ "getAccountRelays needs a routingCredential: construct the client with the device certificate and its signing secret, since this read is proven by the device, not by a session."
5131
+ );
5132
+ }
5133
+ const challenge = await this.getAccountRelaysChallenge(accountId);
5134
+ const body = await this.request("GET", `/api/cloud/accounts/${encodeURIComponent(accountId)}/relays`, {
5135
+ anonymous: true,
5136
+ headers: await routingProofHeaders(challenge, this.routingCredential)
5137
+ });
5138
+ return (body.relays ?? []).map((row) => ({
5139
+ peerId: String(row.peer_id ?? ""),
5140
+ relayUrl: row.relay_url ?? null,
5141
+ fresh: row.fresh === true
5142
+ }));
5143
+ }
5089
5144
  /**
5090
5145
  * The node to send a signed join to, chosen from those an invitation names.
5091
5146
  *