@calimero-network/mero-js 19.13.1 → 19.14.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/admin-api/admin-client.d.ts +31 -1
- package/dist/admin-api/admin-client.js +32 -0
- package/dist/admin-api/admin-types.d.ts +55 -0
- package/dist/admin-api/admin-types.js +12 -1
- package/dist/events/sse.js +45 -6
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +76 -4
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +76 -4
- package/dist/index.mjs.map +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(index_exports, {
|
|
|
68
68
|
generateAccountRoot: () => generateAccountRoot,
|
|
69
69
|
generateSessionKey: () => generateSessionKey,
|
|
70
70
|
hasCap: () => hasCap,
|
|
71
|
+
hexEncodeUtf8: () => hexEncodeUtf8,
|
|
71
72
|
intentHash: () => intentHash,
|
|
72
73
|
jsonCodec: () => jsonCodec,
|
|
73
74
|
localNodeUrl: () => localNodeUrl,
|
|
@@ -1470,6 +1471,43 @@ var AdminApiClient = class {
|
|
|
1470
1471
|
)
|
|
1471
1472
|
);
|
|
1472
1473
|
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Sign a payload an outside verifier specified, with this account's root.
|
|
1476
|
+
*
|
|
1477
|
+
* The counterpart to a verifier that issued a challenge and will check the
|
|
1478
|
+
* signature against the account id it derives — the cloud's account link and
|
|
1479
|
+
* login exchanges being the ones this exists for. The root never leaves the
|
|
1480
|
+
* node, so this is the only way a client can produce that signature.
|
|
1481
|
+
*
|
|
1482
|
+
* `domain` is a NAME from a closed set the node knows, never the domain bytes.
|
|
1483
|
+
* That is the security property rather than an encoding preference: signing
|
|
1484
|
+
* caller-supplied bytes under a caller-supplied prefix would be an oracle over
|
|
1485
|
+
* the one key that can certify a device. A node refuses a name it does not
|
|
1486
|
+
* know, and refuses one whose bytes could be extended into a credential of its
|
|
1487
|
+
* own.
|
|
1488
|
+
*
|
|
1489
|
+
* What comes back proves possession of the root and nothing else. Whether the
|
|
1490
|
+
* payload is a challenge anyone issued, whether it is fresh, and whether the
|
|
1491
|
+
* holder may link this account are the verifier's to decide — it issued the
|
|
1492
|
+
* challenge and knows who to.
|
|
1493
|
+
*
|
|
1494
|
+
* ```ts
|
|
1495
|
+
* const { nonce } = await cloud.getAccountLoginChallenge();
|
|
1496
|
+
* const { rootPublicKey, signature } = await admin.signWithAccountRoot({
|
|
1497
|
+
* domain: 'mdma.account-login',
|
|
1498
|
+
* payload: hexEncodeUtf8(nonce),
|
|
1499
|
+
* });
|
|
1500
|
+
* await cloud.submitAccountLogin({ rootPublicKey, nonce, signature });
|
|
1501
|
+
* ```
|
|
1502
|
+
*/
|
|
1503
|
+
async signWithAccountRoot(request) {
|
|
1504
|
+
return unwrap(
|
|
1505
|
+
await this.httpClient.post(
|
|
1506
|
+
"/admin-api/account/sign-with-root",
|
|
1507
|
+
request
|
|
1508
|
+
)
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1473
1511
|
/**
|
|
1474
1512
|
* Name a device of this account, for a listing to render.
|
|
1475
1513
|
*
|
|
@@ -1885,6 +1923,14 @@ var AdminApiClient = class {
|
|
|
1885
1923
|
}
|
|
1886
1924
|
};
|
|
1887
1925
|
|
|
1926
|
+
// src/admin-api/admin-types.ts
|
|
1927
|
+
function hexEncodeUtf8(text) {
|
|
1928
|
+
return Array.from(
|
|
1929
|
+
new TextEncoder().encode(text),
|
|
1930
|
+
(b) => b.toString(16).padStart(2, "0")
|
|
1931
|
+
).join("");
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1888
1934
|
// src/admin-api/admin-factory.ts
|
|
1889
1935
|
function createBrowserAdminApiClient(config) {
|
|
1890
1936
|
return new AdminApiClient(createBrowserHttpClient(config));
|
|
@@ -2006,6 +2052,13 @@ function isGroupMigrationEvent(event) {
|
|
|
2006
2052
|
|
|
2007
2053
|
// src/events/sse.ts
|
|
2008
2054
|
var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
|
|
2055
|
+
var TERMINAL_AUTH_STATUSES = /* @__PURE__ */ new Set([401, 403]);
|
|
2056
|
+
function isTerminalAuthFailure(response) {
|
|
2057
|
+
const authError = response.headers.get("x-auth-error");
|
|
2058
|
+
if (!authError) return null;
|
|
2059
|
+
if (!TERMINAL_AUTH_STATUSES.has(response.status)) return null;
|
|
2060
|
+
return TERMINAL_AUTH_ERRORS2.has(authError) ? authError : null;
|
|
2061
|
+
}
|
|
2009
2062
|
var SseClient = class {
|
|
2010
2063
|
constructor(opts) {
|
|
2011
2064
|
this.sessionId = null;
|
|
@@ -2092,11 +2145,11 @@ var SseClient = class {
|
|
|
2092
2145
|
signal: this.abortController.signal
|
|
2093
2146
|
});
|
|
2094
2147
|
if (!response.ok) {
|
|
2095
|
-
const
|
|
2148
|
+
const terminal = isTerminalAuthFailure(response);
|
|
2096
2149
|
const bodyText = await response.text().catch(() => void 0);
|
|
2097
|
-
if (
|
|
2150
|
+
if (terminal) {
|
|
2098
2151
|
throw new AuthRevokedError(
|
|
2099
|
-
|
|
2152
|
+
terminal,
|
|
2100
2153
|
response.status,
|
|
2101
2154
|
response.statusText,
|
|
2102
2155
|
url,
|
|
@@ -2125,6 +2178,7 @@ var SseClient = class {
|
|
|
2125
2178
|
if (this.closed) return;
|
|
2126
2179
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
2127
2180
|
this.emit("error", error);
|
|
2181
|
+
if (error instanceof AuthRevokedError) return;
|
|
2128
2182
|
this.scheduleReconnect();
|
|
2129
2183
|
}
|
|
2130
2184
|
}
|
|
@@ -2255,7 +2309,25 @@ var SseClient = class {
|
|
|
2255
2309
|
})
|
|
2256
2310
|
});
|
|
2257
2311
|
if (!response.ok) {
|
|
2258
|
-
|
|
2312
|
+
const terminal = isTerminalAuthFailure(response);
|
|
2313
|
+
const bodyText = await response.text().catch(() => void 0);
|
|
2314
|
+
this.emit(
|
|
2315
|
+
"error",
|
|
2316
|
+
terminal ? new AuthRevokedError(
|
|
2317
|
+
terminal,
|
|
2318
|
+
response.status,
|
|
2319
|
+
response.statusText,
|
|
2320
|
+
`${this.baseUrl}/sse/subscription`,
|
|
2321
|
+
response.headers,
|
|
2322
|
+
bodyText
|
|
2323
|
+
) : new HTTPError(
|
|
2324
|
+
response.status,
|
|
2325
|
+
response.statusText,
|
|
2326
|
+
`${this.baseUrl}/sse/subscription`,
|
|
2327
|
+
response.headers,
|
|
2328
|
+
bodyText
|
|
2329
|
+
)
|
|
2330
|
+
);
|
|
2259
2331
|
}
|
|
2260
2332
|
} catch (err) {
|
|
2261
2333
|
this.emit("error", err instanceof Error ? err : new Error(`SSE ${method} failed`));
|