@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.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +6 -96
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.mjs +6 -96
- package/dist/index.mjs.map +4 -4
- package/package.json +1 -1
- package/dist/account/index.d.ts +0 -43
- package/dist/account/index.js +0 -139
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 everywhere core spells one; an app may re-encode)
|
|
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
|
@@ -2441,93 +2441,6 @@ function createMeroJs(config) {
|
|
|
2441
2441
|
return new MeroJs(config);
|
|
2442
2442
|
}
|
|
2443
2443
|
|
|
2444
|
-
// src/account/index.ts
|
|
2445
|
-
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2446
|
-
var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
|
|
2447
|
-
function encodeBase58(bytes) {
|
|
2448
|
-
if (bytes.length === 0) return "";
|
|
2449
|
-
const digits = [0];
|
|
2450
|
-
for (const byte of bytes) {
|
|
2451
|
-
let carry = byte;
|
|
2452
|
-
for (let i = 0; i < digits.length; i++) {
|
|
2453
|
-
carry += digits[i] << 8;
|
|
2454
|
-
digits[i] = carry % 58;
|
|
2455
|
-
carry = carry / 58 | 0;
|
|
2456
|
-
}
|
|
2457
|
-
while (carry > 0) {
|
|
2458
|
-
digits.push(carry % 58);
|
|
2459
|
-
carry = carry / 58 | 0;
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
let out = "";
|
|
2463
|
-
for (const byte of bytes) {
|
|
2464
|
-
if (byte !== 0) break;
|
|
2465
|
-
out += BASE58_ALPHABET[0];
|
|
2466
|
-
}
|
|
2467
|
-
for (let i = digits.length - 1; i >= 0; i--) {
|
|
2468
|
-
out += BASE58_ALPHABET[digits[i]];
|
|
2469
|
-
}
|
|
2470
|
-
return out;
|
|
2471
|
-
}
|
|
2472
|
-
function decodeBase58(value) {
|
|
2473
|
-
if (value.length === 0) return null;
|
|
2474
|
-
const bytes = [0];
|
|
2475
|
-
for (const char of value) {
|
|
2476
|
-
const index = BASE58_ALPHABET.indexOf(char);
|
|
2477
|
-
if (index < 0) return null;
|
|
2478
|
-
let carry = index;
|
|
2479
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
2480
|
-
carry += bytes[i] * 58;
|
|
2481
|
-
bytes[i] = carry & 255;
|
|
2482
|
-
carry >>= 8;
|
|
2483
|
-
}
|
|
2484
|
-
while (carry > 0) {
|
|
2485
|
-
bytes.push(carry & 255);
|
|
2486
|
-
carry >>= 8;
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
let leadingZeros = 0;
|
|
2490
|
-
for (const char of value) {
|
|
2491
|
-
if (char !== BASE58_ALPHABET[0]) break;
|
|
2492
|
-
leadingZeros++;
|
|
2493
|
-
}
|
|
2494
|
-
return Uint8Array.from([
|
|
2495
|
-
...new Array(leadingZeros).fill(0),
|
|
2496
|
-
...bytes.reverse()
|
|
2497
|
-
]);
|
|
2498
|
-
}
|
|
2499
|
-
function toHex(bytes) {
|
|
2500
|
-
let out = "";
|
|
2501
|
-
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
2502
|
-
return out;
|
|
2503
|
-
}
|
|
2504
|
-
function fromHex(hex2) {
|
|
2505
|
-
const bytes = new Uint8Array(hex2.length / 2);
|
|
2506
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
2507
|
-
bytes[i] = parseInt(hex2.slice(i * 2, i * 2 + 2), 16);
|
|
2508
|
-
}
|
|
2509
|
-
return bytes;
|
|
2510
|
-
}
|
|
2511
|
-
function toAccountHex(id) {
|
|
2512
|
-
const trimmed = (id ?? "").trim();
|
|
2513
|
-
if (!trimmed) return "";
|
|
2514
|
-
if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
|
|
2515
|
-
const decoded = decodeBase58(trimmed);
|
|
2516
|
-
if (!decoded || decoded.length !== 32) return trimmed;
|
|
2517
|
-
return toHex(decoded);
|
|
2518
|
-
}
|
|
2519
|
-
function toAccountBase58(id) {
|
|
2520
|
-
const trimmed = (id ?? "").trim();
|
|
2521
|
-
if (!trimmed) return "";
|
|
2522
|
-
if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
|
|
2523
|
-
return encodeBase58(fromHex(trimmed));
|
|
2524
|
-
}
|
|
2525
|
-
function sameAccount(a, b) {
|
|
2526
|
-
const left = toAccountHex(a);
|
|
2527
|
-
const right = toAccountHex(b);
|
|
2528
|
-
return HEX_ACCOUNT.test(left) && left === right;
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
2444
|
// src/token-store/index.ts
|
|
2532
2445
|
var MemoryTokenStore = class {
|
|
2533
2446
|
constructor() {
|
|
@@ -2633,7 +2546,7 @@ var PKCS8_ED25519_PREFIX = new Uint8Array([
|
|
|
2633
2546
|
function hex(bytes) {
|
|
2634
2547
|
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
2635
2548
|
}
|
|
2636
|
-
function
|
|
2549
|
+
function fromHex(value, label, expectedBytes) {
|
|
2637
2550
|
const clean = value.trim();
|
|
2638
2551
|
if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length !== expectedBytes * 2) {
|
|
2639
2552
|
throw new Error(
|
|
@@ -2674,7 +2587,7 @@ async function intentHash(method, argsJson) {
|
|
|
2674
2587
|
return domainHash(INTENT_DOMAIN, [new TextEncoder().encode(method), args]);
|
|
2675
2588
|
}
|
|
2676
2589
|
async function importSigningKey(secretHex) {
|
|
2677
|
-
const seed =
|
|
2590
|
+
const seed = fromHex(secretHex, "deviceSecret", 32);
|
|
2678
2591
|
const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
|
|
2679
2592
|
try {
|
|
2680
2593
|
return await crypto.subtle.importKey(
|
|
@@ -2692,9 +2605,9 @@ async function importSigningKey(secretHex) {
|
|
|
2692
2605
|
}
|
|
2693
2606
|
}
|
|
2694
2607
|
async function signWarrant(input) {
|
|
2695
|
-
const context =
|
|
2696
|
-
const authorAccount =
|
|
2697
|
-
const executor =
|
|
2608
|
+
const context = fromHex(input.context, "context", 32);
|
|
2609
|
+
const authorAccount = fromHex(input.authorAccount, "authorAccount", 32);
|
|
2610
|
+
const executor = fromHex(input.executor, "executor", 32);
|
|
2698
2611
|
const key = await importSigningKey(input.deviceSecret);
|
|
2699
2612
|
const publicKey = await derivePublicKey(input.deviceSecret);
|
|
2700
2613
|
const commitment = await intentHash(input.method, input.argsJson);
|
|
@@ -2726,7 +2639,7 @@ async function signWarrant(input) {
|
|
|
2726
2639
|
);
|
|
2727
2640
|
}
|
|
2728
2641
|
async function derivePublicKey(secretHex) {
|
|
2729
|
-
const seed =
|
|
2642
|
+
const seed = fromHex(secretHex, "deviceSecret", 32);
|
|
2730
2643
|
const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
|
|
2731
2644
|
const key = await crypto.subtle.importKey(
|
|
2732
2645
|
"pkcs8",
|
|
@@ -2861,10 +2774,7 @@ export {
|
|
|
2861
2774
|
nodeEndpoint,
|
|
2862
2775
|
parseAuthCallback,
|
|
2863
2776
|
probeNodeHealth,
|
|
2864
|
-
sameAccount,
|
|
2865
2777
|
signWarrant,
|
|
2866
|
-
toAccountBase58,
|
|
2867
|
-
toAccountHex,
|
|
2868
2778
|
withCap,
|
|
2869
2779
|
withRetry,
|
|
2870
2780
|
withoutCap
|