@calimero-network/mero-js 19.14.1 → 19.16.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,36 @@
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, callerProof, createProofSigner, } from "./request/index.js";
28
+ export type { CallerProofInput, ProofRequest, ProofSignerOptions, } from "./request/index.js";
29
+ export type { RequestSigInput } from "./request/index.js";
30
+ export { signLoginStatement } from "./login/index.js";
31
+ export type { Audience, LoginStatementInput } from "./login/index.js";
32
+ export { login, generateSessionKey } from "./login/index.js";
33
+ export type { LoginConfig, DelegatedSession, SessionKeyPair, } from "./login/index.js";
34
+ export * from "./capabilities.js";
35
+ export { DEFAULT_LOCAL_NODE_PORTS, localNodeUrl, nodeEndpoint, probeNodeHealth, discoverLocalNodes, } from "./nodeDiscovery.js";
36
+ 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, callerProof, createProofSigner, } 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
@@ -85,6 +85,14 @@ function headersToRecord(headers) {
85
85
  });
86
86
  return record;
87
87
  }
88
+ function pathForProof(url) {
89
+ try {
90
+ return new URL(url).pathname;
91
+ } catch {
92
+ const query = url.indexOf("?");
93
+ return query === -1 ? url : url.slice(0, query);
94
+ }
95
+ }
88
96
  var WebHttpClient = class {
89
97
  constructor(transport) {
90
98
  this.transport = transport;
@@ -211,6 +219,16 @@ var WebHttpClient = class {
211
219
  if (init?.keepalive !== void 0) {
212
220
  requestInit.keepalive = init.keepalive;
213
221
  }
222
+ if (this.transport.getProof) {
223
+ const proof = await this.transport.getProof({
224
+ method: requestInit.method ?? "GET",
225
+ path: pathForProof(url),
226
+ body: requestInit.body
227
+ });
228
+ if (proof) {
229
+ headersObj["X-Calimero-Proof"] = proof;
230
+ }
231
+ }
214
232
  try {
215
233
  const response = await this.transport.fetch(url, requestInit);
216
234
  if (!response.ok) {
@@ -407,6 +425,7 @@ function createBrowserHttpClient(options) {
407
425
  fetch: (url, init) => globalThis.fetch(url, init),
408
426
  baseUrl: options.baseUrl,
409
427
  getAuthToken: options.getAuthToken,
428
+ getProof: options.getProof,
410
429
  onTokenRefresh: options.onTokenRefresh,
411
430
  refreshToken: options.refreshToken,
412
431
  onAuthRevoked: options.onAuthRevoked,
@@ -433,6 +452,7 @@ function createNodeHttpClient(options) {
433
452
  fetch: isDefaultFetch ? (url, init) => globalThis.fetch(url, init) : (url, init) => fetchImpl(url, init),
434
453
  baseUrl: options.baseUrl,
435
454
  getAuthToken: options.getAuthToken,
455
+ getProof: options.getProof,
436
456
  onTokenRefresh: options.onTokenRefresh,
437
457
  refreshToken: options.refreshToken,
438
458
  onAuthRevoked: options.onAuthRevoked,
@@ -2572,6 +2592,17 @@ function fromHex(value, label, expectedBytes) {
2572
2592
  }
2573
2593
  return bytes;
2574
2594
  }
2595
+ function fromHexUnsized(value, label) {
2596
+ const clean = value.trim();
2597
+ if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length % 2 !== 0) {
2598
+ throw new Error(`${label} must be an even number of hex characters`);
2599
+ }
2600
+ const bytes = new Uint8Array(clean.length / 2);
2601
+ for (let i = 0; i < bytes.length; i += 1) {
2602
+ bytes[i] = Number.parseInt(clean.slice(i * 2, i * 2 + 2), 16);
2603
+ }
2604
+ return bytes;
2605
+ }
2575
2606
  function u64le(value) {
2576
2607
  const out = new Uint8Array(8);
2577
2608
  new DataView(out.buffer).setBigUint64(0, BigInt(value), true);
@@ -6442,8 +6473,88 @@ async function signMemberJoinOp(input) {
6442
6473
  return hex(concat(signable, signature, unendorsed));
6443
6474
  }
6444
6475
 
6476
+ // src/request/request-sig.ts
6477
+ var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.request.v1");
6478
+ var BODY_DOMAIN = new TextEncoder().encode("calimero.auth.request.body.v1");
6479
+ function borshString2(value) {
6480
+ const bytes = new TextEncoder().encode(value);
6481
+ return concat(u32le(bytes.length), bytes);
6482
+ }
6483
+ async function requestBodyHash(body = new Uint8Array(0)) {
6484
+ const bytes = typeof body === "string" ? new TextEncoder().encode(body) : body;
6485
+ return domainHash(BODY_DOMAIN, [bytes]);
6486
+ }
6487
+ async function signRequest(input) {
6488
+ const key = await importSigningKey(input.signerSecret);
6489
+ const bodyHash = await requestBodyHash(input.body);
6490
+ const issuedAt = u64le(input.issuedAt);
6491
+ const expiresAt = u64le(input.expiresAt);
6492
+ const encoder = new TextEncoder();
6493
+ const preimage = await domainHash(SIGN_DOMAIN2, [
6494
+ encoder.encode(input.method),
6495
+ encoder.encode(input.path),
6496
+ bodyHash,
6497
+ issuedAt,
6498
+ expiresAt
6499
+ ]);
6500
+ const signature = new Uint8Array(
6501
+ await crypto.subtle.sign({ name: "Ed25519" }, key, preimage)
6502
+ );
6503
+ return hex(
6504
+ concat(
6505
+ borshString2(input.method),
6506
+ borshString2(input.path),
6507
+ bodyHash,
6508
+ issuedAt,
6509
+ expiresAt,
6510
+ signature
6511
+ )
6512
+ );
6513
+ }
6514
+
6515
+ // src/request/caller-proof.ts
6516
+ function callerProof(input) {
6517
+ const credential = fromHexUnsized(input.credential, "credential");
6518
+ const request = fromHexUnsized(input.request, "request signature");
6519
+ const session = input.session === void 0 ? new Uint8Array([0]) : concat(new Uint8Array([1]), fromHexUnsized(input.session, "session statement"));
6520
+ return hex(concat(credential, session, request));
6521
+ }
6522
+
6523
+ // src/request/proof-signer.ts
6524
+ function bodyBytes(body) {
6525
+ if (body === void 0 || body === null) return new Uint8Array(0);
6526
+ if (typeof body === "string") return body;
6527
+ if (body instanceof Uint8Array) return body;
6528
+ if (body instanceof ArrayBuffer) return new Uint8Array(body);
6529
+ if (ArrayBuffer.isView(body)) {
6530
+ return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
6531
+ }
6532
+ throw new Error(
6533
+ `a request-carried proof cannot commit to a ${body?.constructor?.name ?? typeof body} body: pass a string or bytes, or use a session for this call`
6534
+ );
6535
+ }
6536
+ function createProofSigner(options) {
6537
+ const ttl = options.ttlSeconds ?? 120;
6538
+ const clock = options.now ?? (() => Math.floor(Date.now() / 1e3));
6539
+ return async (request) => {
6540
+ const issuedAt = clock();
6541
+ return callerProof({
6542
+ credential: options.credential,
6543
+ session: options.session,
6544
+ request: await signRequest({
6545
+ method: request.method,
6546
+ path: request.path,
6547
+ body: bodyBytes(request.body),
6548
+ issuedAt,
6549
+ expiresAt: issuedAt + ttl,
6550
+ signerSecret: options.signerSecret
6551
+ })
6552
+ });
6553
+ };
6554
+ }
6555
+
6445
6556
  // src/login/login.ts
6446
- var SIGN_DOMAIN2 = new TextEncoder().encode("calimero.auth.login.v1");
6557
+ var SIGN_DOMAIN3 = new TextEncoder().encode("calimero.auth.login.v1");
6447
6558
  var AUDIENCE_TAG = {
6448
6559
  webOrigin: 0,
6449
6560
  codeSigningId: 1,
@@ -6482,7 +6593,7 @@ async function signLoginStatement(input) {
6482
6593
  const deviceKey = await derivePublicKey(input.deviceSecret);
6483
6594
  const issuedAt = u64le(input.issuedAt);
6484
6595
  const expiresAt = u64le(input.expiresAt);
6485
- const preimage = await domainHash(SIGN_DOMAIN2, [
6596
+ const preimage = await domainHash(SIGN_DOMAIN3, [
6486
6597
  node,
6487
6598
  audienceSigningBytes(input.audience),
6488
6599
  challenge,
@@ -6683,6 +6794,7 @@ export {
6683
6794
  accountRootFromPhrase,
6684
6795
  accountRootFromSecret,
6685
6796
  buildAuthLoginUrl,
6797
+ callerProof,
6686
6798
  combineSignals,
6687
6799
  compareSemver,
6688
6800
  connectCloud,
@@ -6700,6 +6812,7 @@ export {
6700
6812
  createNodeAdminApiClient,
6701
6813
  createNodeAuthApiClient,
6702
6814
  createNodeHttpClient,
6815
+ createProofSigner,
6703
6816
  createRetryableMethod,
6704
6817
  createTimeoutSignal,
6705
6818
  createUniversalHttpClient,
@@ -6718,12 +6831,14 @@ export {
6718
6831
  nodeEndpoint,
6719
6832
  parseAuthCallback,
6720
6833
  probeNodeHealth,
6834
+ requestBodyHash,
6721
6835
  routingProofHeaders,
6722
6836
  signAccountLink,
6723
6837
  signAccountLogin,
6724
6838
  signDeviceCert,
6725
6839
  signLoginStatement,
6726
6840
  signMemberJoinOp,
6841
+ signRequest,
6727
6842
  signRoutingChallenge,
6728
6843
  signWarrant,
6729
6844
  withCap,