@calimero-network/mero-js 19.12.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/cloud/cloud-client.d.ts +45 -1
- package/dist/cloud/cloud-client.js +54 -0
- package/dist/cloud/index.d.ts +2 -2
- package/dist/cloud/routing-proof.d.ts +22 -1
- package/dist/cloud/routing-proof.js +4 -0
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +55 -0
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5178,6 +5178,61 @@ var CloudClient = class {
|
|
|
5178
5178
|
const challenge = await this.getRoutingChallenge(namespaceId);
|
|
5179
5179
|
return routingProofHeaders(challenge, this.routingCredential);
|
|
5180
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
|
+
}
|
|
5181
5236
|
/**
|
|
5182
5237
|
* The node to send a signed join to, chosen from those an invitation names.
|
|
5183
5238
|
*
|