@calimero-network/mero-js 19.11.0 → 19.13.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
@@ -1470,6 +1470,20 @@ var AdminApiClient = class {
1470
1470
  )
1471
1471
  );
1472
1472
  }
1473
+ /**
1474
+ * Name a device of this account, for a listing to render.
1475
+ *
1476
+ * Run on the node holding the account root to name any device; a paired
1477
+ * node is accepted only for that device's own id.
1478
+ */
1479
+ async labelAccountDevice(deviceId, request) {
1480
+ return unwrap(
1481
+ await this.httpClient.put(
1482
+ `/admin-api/account/devices/${encodeURIComponent(deviceId)}/label`,
1483
+ request
1484
+ )
1485
+ );
1486
+ }
1473
1487
  /**
1474
1488
  * Every device of this account, as this node sees them - its own included.
1475
1489
  *
@@ -5164,6 +5178,61 @@ var CloudClient = class {
5164
5178
  const challenge = await this.getRoutingChallenge(namespaceId);
5165
5179
  return routingProofHeaders(challenge, this.routingCredential);
5166
5180
  }
5181
+ /**
5182
+ * Ask the cloud for a challenge bound to one ACCOUNT.
5183
+ *
5184
+ * Public and unauthenticated like {@link getRoutingChallenge}: an account id
5185
+ * is `H(genesis(root_pk))` and travels in the clear in every device-link op,
5186
+ * so naming one here reveals nothing and authorises nothing. MDMA re-derives
5187
+ * the account from the certificate and refuses a mismatch.
5188
+ */
5189
+ async getAccountRelaysChallenge(accountId) {
5190
+ const body = await this.request("GET", `/api/cloud/accounts/${encodeURIComponent(accountId)}/challenge`, {
5191
+ anonymous: true
5192
+ });
5193
+ return {
5194
+ accountId: String(body.account_id ?? accountId),
5195
+ nonce: String(body.nonce ?? ""),
5196
+ expiresAtMs: Number(body.expires_at_ms ?? 0)
5197
+ };
5198
+ }
5199
+ /**
5200
+ * Which relays serve this account — the bootstrap, and nothing more.
5201
+ *
5202
+ * A device holding a certificate can resolve a namespace it can *name*
5203
+ * ({@link getNamespaceRouting}) and can ask a node it can *reach* what its
5204
+ * account belongs to. It starts with neither. This closes that one gap.
5205
+ *
5206
+ * **It does not return namespaces, deliberately.** The node answers that from
5207
+ * the governance DAG, scoped to the calling account: log in at one of these
5208
+ * relays with an account proof and read its namespace listing. A cloud-side
5209
+ * copy would be a second source of truth built from rows that linger for an
5210
+ * account which left a namespace.
5211
+ *
5212
+ * So the sequence is: this → log in at a relay → ask it what you are in.
5213
+ *
5214
+ * Proven with the **device certificate**, not a cloud session, so it needs a
5215
+ * `routingCredential` and throws without one rather than returning an empty
5216
+ * list — "you configured no credential" and "you have no relays" are
5217
+ * different answers and must not look alike.
5218
+ */
5219
+ async getAccountRelays(accountId) {
5220
+ if (!this.routingCredential) {
5221
+ throw new Error(
5222
+ "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."
5223
+ );
5224
+ }
5225
+ const challenge = await this.getAccountRelaysChallenge(accountId);
5226
+ const body = await this.request("GET", `/api/cloud/accounts/${encodeURIComponent(accountId)}/relays`, {
5227
+ anonymous: true,
5228
+ headers: await routingProofHeaders(challenge, this.routingCredential)
5229
+ });
5230
+ return (body.relays ?? []).map((row) => ({
5231
+ peerId: String(row.peer_id ?? ""),
5232
+ relayUrl: row.relay_url ?? null,
5233
+ fresh: row.fresh === true
5234
+ }));
5235
+ }
5167
5236
  /**
5168
5237
  * The node to send a signed join to, chosen from those an invitation names.
5169
5238
  *