@calimero-network/mero-js 19.14.0 → 19.15.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.d.ts CHANGED
@@ -1,33 +1,35 @@
1
- export { MeroJs, createMeroJs } from './mero-js.js';
2
- export type { MeroJsConfig, TokenData } from './mero-js.js';
3
- export * from './http-client/index.js';
4
- export * from './auth-api/index.js';
5
- export * from './admin-api/index.js';
6
- export { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
7
- export type { AuthCallbackResult, AuthLoginOptions } from './auth/index.js';
8
- export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
9
- export type { TokenStore } from './token-store/index.js';
10
- export { RpcClient, RpcError } from './rpc/index.js';
11
- export type { MigrateMyEntriesSummary } from './rpc/index.js';
12
- export type { ExecuteParams } from './rpc/index.js';
13
- export { SseClient, WsClient } from './events/index.js';
14
- export type { SseEventData, WsEventData, AppVersionChangedEvent, GroupMembershipEventData, GroupMigrationEventData, MigrationStartedData, MigrationProgressData, CascadeProgressData, MigrationCompletedData, } from './events/index.js';
15
- export { EphemeralClient, jsonCodec } from './ephemeral/index.js';
16
- export type { Codec, EphemeralEntry } from './ephemeral/index.js';
17
- export * from './cloud/index.js';
18
- export * from './relay/index.js';
19
- export { signWarrant, intentHash } from './warrant/index.js';
20
- export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from './account/index.js';
21
- export type { AccountRoot, RecoverableAccountRoot, AccountLinkInput, AccountLoginInput, } from './account/index.js';
22
- export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, } from './device-cert/index.js';
23
- export type { DeviceCertInput } from './device-cert/index.js';
24
- export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from './namespace-op/index.js';
25
- export type { SignMemberJoinInput } from './namespace-op/index.js';
26
- export type { WarrantInput } from './warrant/index.js';
27
- export { signLoginStatement } from './login/index.js';
28
- export type { Audience, LoginStatementInput } from './login/index.js';
29
- export { login, generateSessionKey } from './login/index.js';
30
- export type { LoginConfig, DelegatedSession, SessionKeyPair, } from './login/index.js';
31
- export * from './capabilities.js';
32
- export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from './nodeDiscovery.js';
33
- export type { DiscoverLocalNodesOptions } from './nodeDiscovery.js';
1
+ export { MeroJs, createMeroJs } from "./mero-js.js";
2
+ export type { MeroJsConfig, TokenData } from "./mero-js.js";
3
+ export * from "./http-client/index.js";
4
+ export * from "./auth-api/index.js";
5
+ export * from "./admin-api/index.js";
6
+ export { parseAuthCallback, buildAuthLoginUrl } from "./auth/index.js";
7
+ export type { AuthCallbackResult, AuthLoginOptions } from "./auth/index.js";
8
+ export { MemoryTokenStore, LocalStorageTokenStore, } from "./token-store/index.js";
9
+ export type { TokenStore } from "./token-store/index.js";
10
+ export { RpcClient, RpcError } from "./rpc/index.js";
11
+ export type { MigrateMyEntriesSummary } from "./rpc/index.js";
12
+ export type { ExecuteParams } from "./rpc/index.js";
13
+ export { SseClient, WsClient } from "./events/index.js";
14
+ export type { SseEventData, WsEventData, AppVersionChangedEvent, GroupMembershipEventData, GroupMigrationEventData, MigrationStartedData, MigrationProgressData, CascadeProgressData, MigrationCompletedData, } from "./events/index.js";
15
+ export { EphemeralClient, jsonCodec } from "./ephemeral/index.js";
16
+ export type { Codec, EphemeralEntry } from "./ephemeral/index.js";
17
+ export * from "./cloud/index.js";
18
+ export * from "./relay/index.js";
19
+ export { signWarrant, intentHash } from "./warrant/index.js";
20
+ export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from "./account/index.js";
21
+ export type { AccountRoot, RecoverableAccountRoot, AccountLinkInput, AccountLoginInput, } from "./account/index.js";
22
+ export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, } from "./device-cert/index.js";
23
+ export type { DeviceCertInput } from "./device-cert/index.js";
24
+ export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from "./namespace-op/index.js";
25
+ export type { SignMemberJoinInput } from "./namespace-op/index.js";
26
+ export type { WarrantInput } from "./warrant/index.js";
27
+ export { requestBodyHash, signRequest } from "./request/index.js";
28
+ export type { RequestSigInput } from "./request/index.js";
29
+ export { signLoginStatement } from "./login/index.js";
30
+ export type { Audience, LoginStatementInput } from "./login/index.js";
31
+ export { login, generateSessionKey } from "./login/index.js";
32
+ export type { LoginConfig, DelegatedSession, SessionKeyPair, } from "./login/index.js";
33
+ export * from "./capabilities.js";
34
+ export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from "./nodeDiscovery.js";
35
+ export type { DiscoverLocalNodesOptions } from "./nodeDiscovery.js";
package/dist/index.js CHANGED
@@ -1,37 +1,38 @@
1
1
  // Mero.js - Pure JavaScript SDK for Calimero
2
2
  // This will contain the pure JavaScript SDK without React dependencies
3
3
  // Main SDK class
4
- export { MeroJs, createMeroJs } from './mero-js.js';
4
+ export { MeroJs, createMeroJs } from "./mero-js.js";
5
5
  // HTTP client module (Web Standards based)
6
- export * from './http-client/index.js';
6
+ export * from "./http-client/index.js";
7
7
  // Auth API client
8
- export * from './auth-api/index.js';
8
+ export * from "./auth-api/index.js";
9
9
  // Admin API client
10
- export * from './admin-api/index.js';
10
+ export * from "./admin-api/index.js";
11
11
  // Auth utilities
12
- export { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
12
+ export { parseAuthCallback, buildAuthLoginUrl } from "./auth/index.js";
13
13
  // Token store
14
- export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
14
+ export { MemoryTokenStore, LocalStorageTokenStore, } from "./token-store/index.js";
15
15
  // RPC client
16
- export { RpcClient, RpcError } from './rpc/index.js';
16
+ export { RpcClient, RpcError } from "./rpc/index.js";
17
17
  // Events (SSE / WebSocket)
18
- export { SseClient, WsClient } from './events/index.js';
18
+ export { SseClient, WsClient } from "./events/index.js";
19
19
  // Ephemeral presence (cursors / typing / online)
20
- export { EphemeralClient, jsonCodec } from './ephemeral/index.js';
20
+ export { EphemeralClient, jsonCodec } from "./ephemeral/index.js";
21
21
  // Cloud client — namespaces, relays, HA, and the cloud sign-in path
22
- export * from './cloud/index.js';
22
+ export * from "./cloud/index.js";
23
23
  // Relay client — write through delegated execution, holding only a signing key
24
- export * from './relay/index.js';
24
+ export * from "./relay/index.js";
25
25
  // Warrant signing — mint the author's consent for a relay to run one intent
26
- export { signWarrant, intentHash } from './warrant/index.js';
26
+ export { signWarrant, intentHash } from "./warrant/index.js";
27
27
  // Account roots — mint one with a recovery phrase, or prove you hold one
28
- export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from './account/index.js';
29
- export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, } from './device-cert/index.js';
30
- export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from './namespace-op/index.js';
28
+ export { generateAccountRoot, accountRootFromPhrase, accountRootFromSecret, signAccountLink, signAccountLogin, } from "./account/index.js";
29
+ export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, } from "./device-cert/index.js";
30
+ export { signMemberJoinOp, encodeSignedInvitation, SIGNED_NAMESPACE_OP_SCHEMA_VERSION, } from "./namespace-op/index.js";
31
31
  // Login-statement signing — the device's half of a password-free session
32
- export { signLoginStatement } from './login/index.js';
33
- export { login, generateSessionKey } from './login/index.js';
32
+ export { requestBodyHash, signRequest } from "./request/index.js";
33
+ export { signLoginStatement } from "./login/index.js";
34
+ export { login, generateSessionKey } from "./login/index.js";
34
35
  // Member capability bitmask constants & helpers
35
- export * from './capabilities.js';
36
+ export * from "./capabilities.js";
36
37
  // Utilities
37
- export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from './nodeDiscovery.js';
38
+ export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from "./nodeDiscovery.js";
package/dist/index.mjs CHANGED
@@ -1959,6 +1959,13 @@ function isGroupMigrationEvent(event) {
1959
1959
 
1960
1960
  // src/events/sse.ts
1961
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
+ }
1962
1969
  var SseClient = class {
1963
1970
  constructor(opts) {
1964
1971
  this.sessionId = null;
@@ -2045,11 +2052,11 @@ var SseClient = class {
2045
2052
  signal: this.abortController.signal
2046
2053
  });
2047
2054
  if (!response.ok) {
2048
- const authError = response.headers.get("x-auth-error");
2055
+ const terminal = isTerminalAuthFailure(response);
2049
2056
  const bodyText = await response.text().catch(() => void 0);
2050
- if (response.status === 401 && authError && TERMINAL_AUTH_ERRORS2.has(authError)) {
2057
+ if (terminal) {
2051
2058
  throw new AuthRevokedError(
2052
- authError,
2059
+ terminal,
2053
2060
  response.status,
2054
2061
  response.statusText,
2055
2062
  url,
@@ -2078,6 +2085,7 @@ var SseClient = class {
2078
2085
  if (this.closed) return;
2079
2086
  const error = err instanceof Error ? err : new Error(String(err));
2080
2087
  this.emit("error", error);
2088
+ if (error instanceof AuthRevokedError) return;
2081
2089
  this.scheduleReconnect();
2082
2090
  }
2083
2091
  }
@@ -2208,7 +2216,25 @@ var SseClient = class {
2208
2216
  })
2209
2217
  });
2210
2218
  if (!response.ok) {
2211
- 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
+ );
2212
2238
  }
2213
2239
  } catch (err) {
2214
2240
  this.emit("error", err instanceof Error ? err : new Error(`SSE ${method} failed`));
@@ -6416,8 +6442,47 @@ async function signMemberJoinOp(input) {
6416
6442
  return hex(concat(signable, signature, unendorsed));
6417
6443
  }
6418
6444
 
6445
+ // src/request/request-sig.ts
6446
+ var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.request.v1");
6447
+ var BODY_DOMAIN = new TextEncoder().encode("calimero.auth.request.body.v1");
6448
+ function borshString2(value) {
6449
+ const bytes = new TextEncoder().encode(value);
6450
+ return concat(u32le(bytes.length), bytes);
6451
+ }
6452
+ async function requestBodyHash(body = new Uint8Array(0)) {
6453
+ const bytes = typeof body === "string" ? new TextEncoder().encode(body) : body;
6454
+ return domainHash(BODY_DOMAIN, [bytes]);
6455
+ }
6456
+ async function signRequest(input) {
6457
+ const key = await importSigningKey(input.signerSecret);
6458
+ const bodyHash = await requestBodyHash(input.body);
6459
+ const issuedAt = u64le(input.issuedAt);
6460
+ const expiresAt = u64le(input.expiresAt);
6461
+ const encoder = new TextEncoder();
6462
+ const preimage = await domainHash(SIGN_DOMAIN2, [
6463
+ encoder.encode(input.method),
6464
+ encoder.encode(input.path),
6465
+ bodyHash,
6466
+ issuedAt,
6467
+ expiresAt
6468
+ ]);
6469
+ const signature = new Uint8Array(
6470
+ await crypto.subtle.sign({ name: "Ed25519" }, key, preimage)
6471
+ );
6472
+ return hex(
6473
+ concat(
6474
+ borshString2(input.method),
6475
+ borshString2(input.path),
6476
+ bodyHash,
6477
+ issuedAt,
6478
+ expiresAt,
6479
+ signature
6480
+ )
6481
+ );
6482
+ }
6483
+
6419
6484
  // src/login/login.ts
6420
- var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.login.v1");
6485
+ var SIGN_DOMAIN3 = new TextEncoder().encode("calimero.auth.login.v1");
6421
6486
  var AUDIENCE_TAG = {
6422
6487
  webOrigin: 0,
6423
6488
  codeSigningId: 1,
@@ -6456,7 +6521,7 @@ async function signLoginStatement(input) {
6456
6521
  const deviceKey = await derivePublicKey(input.deviceSecret);
6457
6522
  const issuedAt = u64le(input.issuedAt);
6458
6523
  const expiresAt = u64le(input.expiresAt);
6459
- const preimage = await domainHash(SIGN_DOMAIN2, [
6524
+ const preimage = await domainHash(SIGN_DOMAIN3, [
6460
6525
  node,
6461
6526
  audienceSigningBytes(input.audience),
6462
6527
  challenge,
@@ -6692,12 +6757,14 @@ export {
6692
6757
  nodeEndpoint,
6693
6758
  parseAuthCallback,
6694
6759
  probeNodeHealth,
6760
+ requestBodyHash,
6695
6761
  routingProofHeaders,
6696
6762
  signAccountLink,
6697
6763
  signAccountLogin,
6698
6764
  signDeviceCert,
6699
6765
  signLoginStatement,
6700
6766
  signMemberJoinOp,
6767
+ signRequest,
6701
6768
  signRoutingChallenge,
6702
6769
  signWarrant,
6703
6770
  withCap,