@calimero-network/mero-js 14.0.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.cjs CHANGED
@@ -61,10 +61,7 @@ __export(index_exports, {
61
61
  nodeEndpoint: () => nodeEndpoint,
62
62
  parseAuthCallback: () => parseAuthCallback,
63
63
  probeNodeHealth: () => probeNodeHealth,
64
- sameAccount: () => sameAccount,
65
64
  signWarrant: () => signWarrant,
66
- toAccountBase58: () => toAccountBase58,
67
- toAccountHex: () => toAccountHex,
68
65
  withCap: () => withCap,
69
66
  withRetry: () => withRetry,
70
67
  withoutCap: () => withoutCap
@@ -2514,93 +2511,6 @@ function createMeroJs(config) {
2514
2511
  return new MeroJs(config);
2515
2512
  }
2516
2513
 
2517
- // src/account/index.ts
2518
- var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2519
- var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
2520
- function encodeBase58(bytes) {
2521
- if (bytes.length === 0) return "";
2522
- const digits = [0];
2523
- for (const byte of bytes) {
2524
- let carry = byte;
2525
- for (let i = 0; i < digits.length; i++) {
2526
- carry += digits[i] << 8;
2527
- digits[i] = carry % 58;
2528
- carry = carry / 58 | 0;
2529
- }
2530
- while (carry > 0) {
2531
- digits.push(carry % 58);
2532
- carry = carry / 58 | 0;
2533
- }
2534
- }
2535
- let out = "";
2536
- for (const byte of bytes) {
2537
- if (byte !== 0) break;
2538
- out += BASE58_ALPHABET[0];
2539
- }
2540
- for (let i = digits.length - 1; i >= 0; i--) {
2541
- out += BASE58_ALPHABET[digits[i]];
2542
- }
2543
- return out;
2544
- }
2545
- function decodeBase58(value) {
2546
- if (value.length === 0) return null;
2547
- const bytes = [0];
2548
- for (const char of value) {
2549
- const index = BASE58_ALPHABET.indexOf(char);
2550
- if (index < 0) return null;
2551
- let carry = index;
2552
- for (let i = 0; i < bytes.length; i++) {
2553
- carry += bytes[i] * 58;
2554
- bytes[i] = carry & 255;
2555
- carry >>= 8;
2556
- }
2557
- while (carry > 0) {
2558
- bytes.push(carry & 255);
2559
- carry >>= 8;
2560
- }
2561
- }
2562
- let leadingZeros = 0;
2563
- for (const char of value) {
2564
- if (char !== BASE58_ALPHABET[0]) break;
2565
- leadingZeros++;
2566
- }
2567
- return Uint8Array.from([
2568
- ...new Array(leadingZeros).fill(0),
2569
- ...bytes.reverse()
2570
- ]);
2571
- }
2572
- function toHex(bytes) {
2573
- let out = "";
2574
- for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
2575
- return out;
2576
- }
2577
- function fromHex(hex2) {
2578
- const bytes = new Uint8Array(hex2.length / 2);
2579
- for (let i = 0; i < bytes.length; i++) {
2580
- bytes[i] = parseInt(hex2.slice(i * 2, i * 2 + 2), 16);
2581
- }
2582
- return bytes;
2583
- }
2584
- function toAccountHex(id) {
2585
- const trimmed = (id ?? "").trim();
2586
- if (!trimmed) return "";
2587
- if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
2588
- const decoded = decodeBase58(trimmed);
2589
- if (!decoded || decoded.length !== 32) return trimmed;
2590
- return toHex(decoded);
2591
- }
2592
- function toAccountBase58(id) {
2593
- const trimmed = (id ?? "").trim();
2594
- if (!trimmed) return "";
2595
- if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
2596
- return encodeBase58(fromHex(trimmed));
2597
- }
2598
- function sameAccount(a, b) {
2599
- const left = toAccountHex(a);
2600
- const right = toAccountHex(b);
2601
- return HEX_ACCOUNT.test(left) && left === right;
2602
- }
2603
-
2604
2514
  // src/token-store/index.ts
2605
2515
  var MemoryTokenStore = class {
2606
2516
  constructor() {
@@ -2706,7 +2616,7 @@ var PKCS8_ED25519_PREFIX = new Uint8Array([
2706
2616
  function hex(bytes) {
2707
2617
  return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
2708
2618
  }
2709
- function fromHex2(value, label, expectedBytes) {
2619
+ function fromHex(value, label, expectedBytes) {
2710
2620
  const clean = value.trim();
2711
2621
  if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length !== expectedBytes * 2) {
2712
2622
  throw new Error(
@@ -2747,7 +2657,7 @@ async function intentHash(method, argsJson) {
2747
2657
  return domainHash(INTENT_DOMAIN, [new TextEncoder().encode(method), args]);
2748
2658
  }
2749
2659
  async function importSigningKey(secretHex) {
2750
- const seed = fromHex2(secretHex, "deviceSecret", 32);
2660
+ const seed = fromHex(secretHex, "deviceSecret", 32);
2751
2661
  const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
2752
2662
  try {
2753
2663
  return await crypto.subtle.importKey(
@@ -2765,9 +2675,9 @@ async function importSigningKey(secretHex) {
2765
2675
  }
2766
2676
  }
2767
2677
  async function signWarrant(input) {
2768
- const context = fromHex2(input.context, "context", 32);
2769
- const authorAccount = fromHex2(input.authorAccount, "authorAccount", 32);
2770
- const executor = fromHex2(input.executor, "executor", 32);
2678
+ const context = fromHex(input.context, "context", 32);
2679
+ const authorAccount = fromHex(input.authorAccount, "authorAccount", 32);
2680
+ const executor = fromHex(input.executor, "executor", 32);
2771
2681
  const key = await importSigningKey(input.deviceSecret);
2772
2682
  const publicKey = await derivePublicKey(input.deviceSecret);
2773
2683
  const commitment = await intentHash(input.method, input.argsJson);
@@ -2799,7 +2709,7 @@ async function signWarrant(input) {
2799
2709
  );
2800
2710
  }
2801
2711
  async function derivePublicKey(secretHex) {
2802
- const seed = fromHex2(secretHex, "deviceSecret", 32);
2712
+ const seed = fromHex(secretHex, "deviceSecret", 32);
2803
2713
  const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
2804
2714
  const key = await crypto.subtle.importKey(
2805
2715
  "pkcs8",