@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/index.mjs CHANGED
@@ -1378,6 +1378,43 @@ var AdminApiClient = class {
1378
1378
  )
1379
1379
  );
1380
1380
  }
1381
+ /**
1382
+ * Sign a payload an outside verifier specified, with this account's root.
1383
+ *
1384
+ * The counterpart to a verifier that issued a challenge and will check the
1385
+ * signature against the account id it derives — the cloud's account link and
1386
+ * login exchanges being the ones this exists for. The root never leaves the
1387
+ * node, so this is the only way a client can produce that signature.
1388
+ *
1389
+ * `domain` is a NAME from a closed set the node knows, never the domain bytes.
1390
+ * That is the security property rather than an encoding preference: signing
1391
+ * caller-supplied bytes under a caller-supplied prefix would be an oracle over
1392
+ * the one key that can certify a device. A node refuses a name it does not
1393
+ * know, and refuses one whose bytes could be extended into a credential of its
1394
+ * own.
1395
+ *
1396
+ * What comes back proves possession of the root and nothing else. Whether the
1397
+ * payload is a challenge anyone issued, whether it is fresh, and whether the
1398
+ * holder may link this account are the verifier's to decide — it issued the
1399
+ * challenge and knows who to.
1400
+ *
1401
+ * ```ts
1402
+ * const { nonce } = await cloud.getAccountLoginChallenge();
1403
+ * const { rootPublicKey, signature } = await admin.signWithAccountRoot({
1404
+ * domain: 'mdma.account-login',
1405
+ * payload: hexEncodeUtf8(nonce),
1406
+ * });
1407
+ * await cloud.submitAccountLogin({ rootPublicKey, nonce, signature });
1408
+ * ```
1409
+ */
1410
+ async signWithAccountRoot(request) {
1411
+ return unwrap(
1412
+ await this.httpClient.post(
1413
+ "/admin-api/account/sign-with-root",
1414
+ request
1415
+ )
1416
+ );
1417
+ }
1381
1418
  /**
1382
1419
  * Name a device of this account, for a listing to render.
1383
1420
  *
@@ -1793,6 +1830,14 @@ var AdminApiClient = class {
1793
1830
  }
1794
1831
  };
1795
1832
 
1833
+ // src/admin-api/admin-types.ts
1834
+ function hexEncodeUtf8(text) {
1835
+ return Array.from(
1836
+ new TextEncoder().encode(text),
1837
+ (b) => b.toString(16).padStart(2, "0")
1838
+ ).join("");
1839
+ }
1840
+
1796
1841
  // src/admin-api/admin-factory.ts
1797
1842
  function createBrowserAdminApiClient(config) {
1798
1843
  return new AdminApiClient(createBrowserHttpClient(config));
@@ -1914,6 +1959,13 @@ function isGroupMigrationEvent(event) {
1914
1959
 
1915
1960
  // src/events/sse.ts
1916
1961
  var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
1962
+ var TERMINAL_AUTH_STATUSES = /* @__PURE__ */ new Set([401, 403]);
1963
+ function isTerminalAuthFailure(response) {
1964
+ const authError = response.headers.get("x-auth-error");
1965
+ if (!authError) return null;
1966
+ if (!TERMINAL_AUTH_STATUSES.has(response.status)) return null;
1967
+ return TERMINAL_AUTH_ERRORS2.has(authError) ? authError : null;
1968
+ }
1917
1969
  var SseClient = class {
1918
1970
  constructor(opts) {
1919
1971
  this.sessionId = null;
@@ -2000,11 +2052,11 @@ var SseClient = class {
2000
2052
  signal: this.abortController.signal
2001
2053
  });
2002
2054
  if (!response.ok) {
2003
- const authError = response.headers.get("x-auth-error");
2055
+ const terminal = isTerminalAuthFailure(response);
2004
2056
  const bodyText = await response.text().catch(() => void 0);
2005
- if (response.status === 401 && authError && TERMINAL_AUTH_ERRORS2.has(authError)) {
2057
+ if (terminal) {
2006
2058
  throw new AuthRevokedError(
2007
- authError,
2059
+ terminal,
2008
2060
  response.status,
2009
2061
  response.statusText,
2010
2062
  url,
@@ -2033,6 +2085,7 @@ var SseClient = class {
2033
2085
  if (this.closed) return;
2034
2086
  const error = err instanceof Error ? err : new Error(String(err));
2035
2087
  this.emit("error", error);
2088
+ if (error instanceof AuthRevokedError) return;
2036
2089
  this.scheduleReconnect();
2037
2090
  }
2038
2091
  }
@@ -2163,7 +2216,25 @@ var SseClient = class {
2163
2216
  })
2164
2217
  });
2165
2218
  if (!response.ok) {
2166
- this.emit("error", new Error(`SSE ${method} failed: ${response.status}`));
2219
+ const terminal = isTerminalAuthFailure(response);
2220
+ const bodyText = await response.text().catch(() => void 0);
2221
+ this.emit(
2222
+ "error",
2223
+ terminal ? new AuthRevokedError(
2224
+ terminal,
2225
+ response.status,
2226
+ response.statusText,
2227
+ `${this.baseUrl}/sse/subscription`,
2228
+ response.headers,
2229
+ bodyText
2230
+ ) : new HTTPError(
2231
+ response.status,
2232
+ response.statusText,
2233
+ `${this.baseUrl}/sse/subscription`,
2234
+ response.headers,
2235
+ bodyText
2236
+ )
2237
+ );
2167
2238
  }
2168
2239
  } catch (err) {
2169
2240
  this.emit("error", err instanceof Error ? err : new Error(`SSE ${method} failed`));
@@ -6638,6 +6709,7 @@ export {
6638
6709
  generateAccountRoot,
6639
6710
  generateSessionKey,
6640
6711
  hasCap,
6712
+ hexEncodeUtf8,
6641
6713
  intentHash,
6642
6714
  jsonCodec,
6643
6715
  localNodeUrl,