@calimero-network/mero-js 13.4.0 → 15.0.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
@@ -5,7 +5,6 @@ export * from './auth-api/index.js';
5
5
  export * from './admin-api/index.js';
6
6
  export { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
7
7
  export type { AuthCallbackResult, AuthLoginOptions } from './auth/index.js';
8
- export { toAccountHex, toAccountBase58, sameAccount, } from './account/index.js';
9
8
  export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
10
9
  export type { TokenStore } from './token-store/index.js';
11
10
  export { RpcClient, RpcError } from './rpc/index.js';
package/dist/index.js CHANGED
@@ -10,8 +10,6 @@ export * from './auth-api/index.js';
10
10
  export * from './admin-api/index.js';
11
11
  // Auth utilities
12
12
  export { parseAuthCallback, buildAuthLoginUrl } from './auth/index.js';
13
- // Account id encoding (hex on the admin API, base58 in contract data)
14
- export { toAccountHex, toAccountBase58, sameAccount, } from './account/index.js';
15
13
  // Token store
16
14
  export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
17
15
  // RPC client
package/dist/index.mjs CHANGED
@@ -1226,14 +1226,16 @@ var AdminApiClient = class {
1226
1226
  }
1227
1227
  /**
1228
1228
  * `identity` is the member's ACCOUNT (64 hex), as returned by
1229
- * {@link listGroupMembers} — not the bs58 signing key that added them.
1229
+ * {@link listGroupMembers} — not the signing key that added them. Both are
1230
+ * 64 hex, so nothing but the source tells them apart.
1230
1231
  */
1231
1232
  async updateMemberRole(groupId, identity, request) {
1232
1233
  await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/role`, request);
1233
1234
  }
1234
1235
  /**
1235
1236
  * `identity` is the member's ACCOUNT (64 hex), as returned by
1236
- * {@link listGroupMembers} — not the bs58 signing key that added them.
1237
+ * {@link listGroupMembers} — not the signing key that added them. Both are
1238
+ * 64 hex, so nothing but the source tells them apart.
1237
1239
  */
1238
1240
  async getMemberCapabilities(groupId, identity) {
1239
1241
  return unwrap(
@@ -1244,7 +1246,8 @@ var AdminApiClient = class {
1244
1246
  }
1245
1247
  /**
1246
1248
  * `identity` is the member's ACCOUNT (64 hex), as returned by
1247
- * {@link listGroupMembers} — not the bs58 signing key that added them.
1249
+ * {@link listGroupMembers} — not the signing key that added them. Both are
1250
+ * 64 hex, so nothing but the source tells them apart.
1248
1251
  */
1249
1252
  async setMemberCapabilities(groupId, identity, request) {
1250
1253
  await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/capabilities`, request);
@@ -1277,7 +1280,8 @@ var AdminApiClient = class {
1277
1280
  }
1278
1281
  /**
1279
1282
  * `identity` is the member's ACCOUNT (64 hex), as returned by
1280
- * {@link listGroupMembers} — not the bs58 signing key that added them.
1283
+ * {@link listGroupMembers} — not the signing key that added them. Both are
1284
+ * 64 hex, so nothing but the source tells them apart.
1281
1285
  */
1282
1286
  async getMemberMetadata(groupId, identity) {
1283
1287
  const response = await this.httpClient.get(
@@ -1431,7 +1435,8 @@ var AdminApiClient = class {
1431
1435
  * /admin-api/groups/:group_id/members/:identity/auto-follow).
1432
1436
  *
1433
1437
  * `identity` is the member's ACCOUNT (64 hex), as returned by
1434
- * {@link listGroupMembers} — not the bs58 signing key that added them.
1438
+ * {@link listGroupMembers} — not the signing key that added them. Both are
1439
+ * 64 hex, so nothing but the source tells them apart.
1435
1440
  */
1436
1441
  async setMemberAutoFollow(groupId, identity, request) {
1437
1442
  await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/auto-follow`, request);
@@ -2436,93 +2441,6 @@ function createMeroJs(config) {
2436
2441
  return new MeroJs(config);
2437
2442
  }
2438
2443
 
2439
- // src/account/index.ts
2440
- var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2441
- var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
2442
- function encodeBase58(bytes) {
2443
- if (bytes.length === 0) return "";
2444
- const digits = [0];
2445
- for (const byte of bytes) {
2446
- let carry = byte;
2447
- for (let i = 0; i < digits.length; i++) {
2448
- carry += digits[i] << 8;
2449
- digits[i] = carry % 58;
2450
- carry = carry / 58 | 0;
2451
- }
2452
- while (carry > 0) {
2453
- digits.push(carry % 58);
2454
- carry = carry / 58 | 0;
2455
- }
2456
- }
2457
- let out = "";
2458
- for (const byte of bytes) {
2459
- if (byte !== 0) break;
2460
- out += BASE58_ALPHABET[0];
2461
- }
2462
- for (let i = digits.length - 1; i >= 0; i--) {
2463
- out += BASE58_ALPHABET[digits[i]];
2464
- }
2465
- return out;
2466
- }
2467
- function decodeBase58(value) {
2468
- if (value.length === 0) return null;
2469
- const bytes = [0];
2470
- for (const char of value) {
2471
- const index = BASE58_ALPHABET.indexOf(char);
2472
- if (index < 0) return null;
2473
- let carry = index;
2474
- for (let i = 0; i < bytes.length; i++) {
2475
- carry += bytes[i] * 58;
2476
- bytes[i] = carry & 255;
2477
- carry >>= 8;
2478
- }
2479
- while (carry > 0) {
2480
- bytes.push(carry & 255);
2481
- carry >>= 8;
2482
- }
2483
- }
2484
- let leadingZeros = 0;
2485
- for (const char of value) {
2486
- if (char !== BASE58_ALPHABET[0]) break;
2487
- leadingZeros++;
2488
- }
2489
- return Uint8Array.from([
2490
- ...new Array(leadingZeros).fill(0),
2491
- ...bytes.reverse()
2492
- ]);
2493
- }
2494
- function toHex(bytes) {
2495
- let out = "";
2496
- for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
2497
- return out;
2498
- }
2499
- function fromHex(hex2) {
2500
- const bytes = new Uint8Array(hex2.length / 2);
2501
- for (let i = 0; i < bytes.length; i++) {
2502
- bytes[i] = parseInt(hex2.slice(i * 2, i * 2 + 2), 16);
2503
- }
2504
- return bytes;
2505
- }
2506
- function toAccountHex(id) {
2507
- const trimmed = (id ?? "").trim();
2508
- if (!trimmed) return "";
2509
- if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
2510
- const decoded = decodeBase58(trimmed);
2511
- if (!decoded || decoded.length !== 32) return trimmed;
2512
- return toHex(decoded);
2513
- }
2514
- function toAccountBase58(id) {
2515
- const trimmed = (id ?? "").trim();
2516
- if (!trimmed) return "";
2517
- if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
2518
- return encodeBase58(fromHex(trimmed));
2519
- }
2520
- function sameAccount(a, b) {
2521
- const left = toAccountHex(a);
2522
- const right = toAccountHex(b);
2523
- return HEX_ACCOUNT.test(left) && left === right;
2524
- }
2525
-
2526
2444
  // src/token-store/index.ts
2527
2445
  var MemoryTokenStore = class {
2528
2446
  constructor() {
@@ -2625,11 +2543,10 @@ var PKCS8_ED25519_PREFIX = new Uint8Array([
2625
2543
  4,
2626
2544
  32
2627
2545
  ]);
2628
- var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2629
2546
  function hex(bytes) {
2630
2547
  return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
2631
2548
  }
2632
- function fromHex2(value, label, expectedBytes) {
2549
+ function fromHex(value, label, expectedBytes) {
2633
2550
  const clean = value.trim();
2634
2551
  if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length !== expectedBytes * 2) {
2635
2552
  throw new Error(
@@ -2642,47 +2559,6 @@ function fromHex2(value, label, expectedBytes) {
2642
2559
  }
2643
2560
  return bytes;
2644
2561
  }
2645
- function fromBase58(value, label) {
2646
- const clean = value.trim();
2647
- let n = 0n;
2648
- for (const char of clean) {
2649
- const digit = B58.indexOf(char);
2650
- if (digit < 0) {
2651
- throw new Error(`${label} is not base58: unexpected character '${char}'`);
2652
- }
2653
- n = n * 58n + BigInt(digit);
2654
- }
2655
- const out = new Uint8Array(32);
2656
- for (let i = 31; i >= 0; i -= 1) {
2657
- out[i] = Number(n & 0xffn);
2658
- n >>= 8n;
2659
- }
2660
- if (n !== 0n) {
2661
- throw new Error(`${label} decodes to more than 32 bytes`);
2662
- }
2663
- if (toBase58(out) !== clean) {
2664
- throw new Error(
2665
- `${label} is not a canonical base58 32-byte id. If you have it in hex, note that ${label} is base58 here while accounts are hex`
2666
- );
2667
- }
2668
- return out;
2669
- }
2670
- function toBase58(bytes) {
2671
- let n = 0n;
2672
- for (const byte of bytes) {
2673
- n = n << 8n | BigInt(byte);
2674
- }
2675
- let out = "";
2676
- while (n > 0n) {
2677
- out = B58[Number(n % 58n)] + out;
2678
- n /= 58n;
2679
- }
2680
- let leadingZeros = 0;
2681
- while (leadingZeros < bytes.length && bytes[leadingZeros] === 0) {
2682
- leadingZeros += 1;
2683
- }
2684
- return "1".repeat(leadingZeros) + out;
2685
- }
2686
2562
  function u64le(value) {
2687
2563
  const out = new Uint8Array(8);
2688
2564
  new DataView(out.buffer).setBigUint64(0, BigInt(value), true);
@@ -2711,7 +2587,7 @@ async function intentHash(method, argsJson) {
2711
2587
  return domainHash(INTENT_DOMAIN, [new TextEncoder().encode(method), args]);
2712
2588
  }
2713
2589
  async function importSigningKey(secretHex) {
2714
- const seed = fromHex2(secretHex, "deviceSecret", 32);
2590
+ const seed = fromHex(secretHex, "deviceSecret", 32);
2715
2591
  const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
2716
2592
  try {
2717
2593
  return await crypto.subtle.importKey(
@@ -2729,9 +2605,9 @@ async function importSigningKey(secretHex) {
2729
2605
  }
2730
2606
  }
2731
2607
  async function signWarrant(input) {
2732
- const context = fromBase58(input.context, "context");
2733
- const authorAccount = fromHex2(input.authorAccount, "authorAccount", 32);
2734
- const executor = fromHex2(input.executor, "executor", 32);
2608
+ const context = fromHex(input.context, "context", 32);
2609
+ const authorAccount = fromHex(input.authorAccount, "authorAccount", 32);
2610
+ const executor = fromHex(input.executor, "executor", 32);
2735
2611
  const key = await importSigningKey(input.deviceSecret);
2736
2612
  const publicKey = await derivePublicKey(input.deviceSecret);
2737
2613
  const commitment = await intentHash(input.method, input.argsJson);
@@ -2763,7 +2639,7 @@ async function signWarrant(input) {
2763
2639
  );
2764
2640
  }
2765
2641
  async function derivePublicKey(secretHex) {
2766
- const seed = fromHex2(secretHex, "deviceSecret", 32);
2642
+ const seed = fromHex(secretHex, "deviceSecret", 32);
2767
2643
  const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
2768
2644
  const key = await crypto.subtle.importKey(
2769
2645
  "pkcs8",
@@ -2898,10 +2774,7 @@ export {
2898
2774
  nodeEndpoint,
2899
2775
  parseAuthCallback,
2900
2776
  probeNodeHealth,
2901
- sameAccount,
2902
2777
  signWarrant,
2903
- toAccountBase58,
2904
- toAccountHex,
2905
2778
  withCap,
2906
2779
  withRetry,
2907
2780
  withoutCap