@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/admin-api/admin-client.d.ts +10 -5
- package/dist/admin-api/admin-client.js +10 -5
- package/dist/admin-api/admin-types.d.ts +8 -7
- package/dist/events/group.d.ts +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +16 -143
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.mjs +16 -143
- package/dist/index.mjs.map +4 -4
- package/dist/warrant/warrant.d.ts +5 -6
- package/dist/warrant/warrant.js +1 -54
- package/package.json +1 -1
- package/dist/account/index.d.ts +0 -43
- package/dist/account/index.js +0 -139
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
|
|
@@ -1299,14 +1296,16 @@ var AdminApiClient = class {
|
|
|
1299
1296
|
}
|
|
1300
1297
|
/**
|
|
1301
1298
|
* `identity` is the member's ACCOUNT (64 hex), as returned by
|
|
1302
|
-
* {@link listGroupMembers} — not the
|
|
1299
|
+
* {@link listGroupMembers} — not the signing key that added them. Both are
|
|
1300
|
+
* 64 hex, so nothing but the source tells them apart.
|
|
1303
1301
|
*/
|
|
1304
1302
|
async updateMemberRole(groupId, identity, request) {
|
|
1305
1303
|
await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/role`, request);
|
|
1306
1304
|
}
|
|
1307
1305
|
/**
|
|
1308
1306
|
* `identity` is the member's ACCOUNT (64 hex), as returned by
|
|
1309
|
-
* {@link listGroupMembers} — not the
|
|
1307
|
+
* {@link listGroupMembers} — not the signing key that added them. Both are
|
|
1308
|
+
* 64 hex, so nothing but the source tells them apart.
|
|
1310
1309
|
*/
|
|
1311
1310
|
async getMemberCapabilities(groupId, identity) {
|
|
1312
1311
|
return unwrap(
|
|
@@ -1317,7 +1316,8 @@ var AdminApiClient = class {
|
|
|
1317
1316
|
}
|
|
1318
1317
|
/**
|
|
1319
1318
|
* `identity` is the member's ACCOUNT (64 hex), as returned by
|
|
1320
|
-
* {@link listGroupMembers} — not the
|
|
1319
|
+
* {@link listGroupMembers} — not the signing key that added them. Both are
|
|
1320
|
+
* 64 hex, so nothing but the source tells them apart.
|
|
1321
1321
|
*/
|
|
1322
1322
|
async setMemberCapabilities(groupId, identity, request) {
|
|
1323
1323
|
await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/capabilities`, request);
|
|
@@ -1350,7 +1350,8 @@ var AdminApiClient = class {
|
|
|
1350
1350
|
}
|
|
1351
1351
|
/**
|
|
1352
1352
|
* `identity` is the member's ACCOUNT (64 hex), as returned by
|
|
1353
|
-
* {@link listGroupMembers} — not the
|
|
1353
|
+
* {@link listGroupMembers} — not the signing key that added them. Both are
|
|
1354
|
+
* 64 hex, so nothing but the source tells them apart.
|
|
1354
1355
|
*/
|
|
1355
1356
|
async getMemberMetadata(groupId, identity) {
|
|
1356
1357
|
const response = await this.httpClient.get(
|
|
@@ -1504,7 +1505,8 @@ var AdminApiClient = class {
|
|
|
1504
1505
|
* /admin-api/groups/:group_id/members/:identity/auto-follow).
|
|
1505
1506
|
*
|
|
1506
1507
|
* `identity` is the member's ACCOUNT (64 hex), as returned by
|
|
1507
|
-
* {@link listGroupMembers} — not the
|
|
1508
|
+
* {@link listGroupMembers} — not the signing key that added them. Both are
|
|
1509
|
+
* 64 hex, so nothing but the source tells them apart.
|
|
1508
1510
|
*/
|
|
1509
1511
|
async setMemberAutoFollow(groupId, identity, request) {
|
|
1510
1512
|
await this.httpClient.put(`/admin-api/groups/${groupId}/members/${identity}/auto-follow`, request);
|
|
@@ -2509,93 +2511,6 @@ function createMeroJs(config) {
|
|
|
2509
2511
|
return new MeroJs(config);
|
|
2510
2512
|
}
|
|
2511
2513
|
|
|
2512
|
-
// src/account/index.ts
|
|
2513
|
-
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2514
|
-
var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
|
|
2515
|
-
function encodeBase58(bytes) {
|
|
2516
|
-
if (bytes.length === 0) return "";
|
|
2517
|
-
const digits = [0];
|
|
2518
|
-
for (const byte of bytes) {
|
|
2519
|
-
let carry = byte;
|
|
2520
|
-
for (let i = 0; i < digits.length; i++) {
|
|
2521
|
-
carry += digits[i] << 8;
|
|
2522
|
-
digits[i] = carry % 58;
|
|
2523
|
-
carry = carry / 58 | 0;
|
|
2524
|
-
}
|
|
2525
|
-
while (carry > 0) {
|
|
2526
|
-
digits.push(carry % 58);
|
|
2527
|
-
carry = carry / 58 | 0;
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
let out = "";
|
|
2531
|
-
for (const byte of bytes) {
|
|
2532
|
-
if (byte !== 0) break;
|
|
2533
|
-
out += BASE58_ALPHABET[0];
|
|
2534
|
-
}
|
|
2535
|
-
for (let i = digits.length - 1; i >= 0; i--) {
|
|
2536
|
-
out += BASE58_ALPHABET[digits[i]];
|
|
2537
|
-
}
|
|
2538
|
-
return out;
|
|
2539
|
-
}
|
|
2540
|
-
function decodeBase58(value) {
|
|
2541
|
-
if (value.length === 0) return null;
|
|
2542
|
-
const bytes = [0];
|
|
2543
|
-
for (const char of value) {
|
|
2544
|
-
const index = BASE58_ALPHABET.indexOf(char);
|
|
2545
|
-
if (index < 0) return null;
|
|
2546
|
-
let carry = index;
|
|
2547
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
2548
|
-
carry += bytes[i] * 58;
|
|
2549
|
-
bytes[i] = carry & 255;
|
|
2550
|
-
carry >>= 8;
|
|
2551
|
-
}
|
|
2552
|
-
while (carry > 0) {
|
|
2553
|
-
bytes.push(carry & 255);
|
|
2554
|
-
carry >>= 8;
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
let leadingZeros = 0;
|
|
2558
|
-
for (const char of value) {
|
|
2559
|
-
if (char !== BASE58_ALPHABET[0]) break;
|
|
2560
|
-
leadingZeros++;
|
|
2561
|
-
}
|
|
2562
|
-
return Uint8Array.from([
|
|
2563
|
-
...new Array(leadingZeros).fill(0),
|
|
2564
|
-
...bytes.reverse()
|
|
2565
|
-
]);
|
|
2566
|
-
}
|
|
2567
|
-
function toHex(bytes) {
|
|
2568
|
-
let out = "";
|
|
2569
|
-
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
2570
|
-
return out;
|
|
2571
|
-
}
|
|
2572
|
-
function fromHex(hex2) {
|
|
2573
|
-
const bytes = new Uint8Array(hex2.length / 2);
|
|
2574
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
2575
|
-
bytes[i] = parseInt(hex2.slice(i * 2, i * 2 + 2), 16);
|
|
2576
|
-
}
|
|
2577
|
-
return bytes;
|
|
2578
|
-
}
|
|
2579
|
-
function toAccountHex(id) {
|
|
2580
|
-
const trimmed = (id ?? "").trim();
|
|
2581
|
-
if (!trimmed) return "";
|
|
2582
|
-
if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
|
|
2583
|
-
const decoded = decodeBase58(trimmed);
|
|
2584
|
-
if (!decoded || decoded.length !== 32) return trimmed;
|
|
2585
|
-
return toHex(decoded);
|
|
2586
|
-
}
|
|
2587
|
-
function toAccountBase58(id) {
|
|
2588
|
-
const trimmed = (id ?? "").trim();
|
|
2589
|
-
if (!trimmed) return "";
|
|
2590
|
-
if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
|
|
2591
|
-
return encodeBase58(fromHex(trimmed));
|
|
2592
|
-
}
|
|
2593
|
-
function sameAccount(a, b) {
|
|
2594
|
-
const left = toAccountHex(a);
|
|
2595
|
-
const right = toAccountHex(b);
|
|
2596
|
-
return HEX_ACCOUNT.test(left) && left === right;
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
2514
|
// src/token-store/index.ts
|
|
2600
2515
|
var MemoryTokenStore = class {
|
|
2601
2516
|
constructor() {
|
|
@@ -2698,11 +2613,10 @@ var PKCS8_ED25519_PREFIX = new Uint8Array([
|
|
|
2698
2613
|
4,
|
|
2699
2614
|
32
|
|
2700
2615
|
]);
|
|
2701
|
-
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2702
2616
|
function hex(bytes) {
|
|
2703
2617
|
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
2704
2618
|
}
|
|
2705
|
-
function
|
|
2619
|
+
function fromHex(value, label, expectedBytes) {
|
|
2706
2620
|
const clean = value.trim();
|
|
2707
2621
|
if (!/^[0-9a-fA-F]*$/.test(clean) || clean.length !== expectedBytes * 2) {
|
|
2708
2622
|
throw new Error(
|
|
@@ -2715,47 +2629,6 @@ function fromHex2(value, label, expectedBytes) {
|
|
|
2715
2629
|
}
|
|
2716
2630
|
return bytes;
|
|
2717
2631
|
}
|
|
2718
|
-
function fromBase58(value, label) {
|
|
2719
|
-
const clean = value.trim();
|
|
2720
|
-
let n = 0n;
|
|
2721
|
-
for (const char of clean) {
|
|
2722
|
-
const digit = B58.indexOf(char);
|
|
2723
|
-
if (digit < 0) {
|
|
2724
|
-
throw new Error(`${label} is not base58: unexpected character '${char}'`);
|
|
2725
|
-
}
|
|
2726
|
-
n = n * 58n + BigInt(digit);
|
|
2727
|
-
}
|
|
2728
|
-
const out = new Uint8Array(32);
|
|
2729
|
-
for (let i = 31; i >= 0; i -= 1) {
|
|
2730
|
-
out[i] = Number(n & 0xffn);
|
|
2731
|
-
n >>= 8n;
|
|
2732
|
-
}
|
|
2733
|
-
if (n !== 0n) {
|
|
2734
|
-
throw new Error(`${label} decodes to more than 32 bytes`);
|
|
2735
|
-
}
|
|
2736
|
-
if (toBase58(out) !== clean) {
|
|
2737
|
-
throw new Error(
|
|
2738
|
-
`${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`
|
|
2739
|
-
);
|
|
2740
|
-
}
|
|
2741
|
-
return out;
|
|
2742
|
-
}
|
|
2743
|
-
function toBase58(bytes) {
|
|
2744
|
-
let n = 0n;
|
|
2745
|
-
for (const byte of bytes) {
|
|
2746
|
-
n = n << 8n | BigInt(byte);
|
|
2747
|
-
}
|
|
2748
|
-
let out = "";
|
|
2749
|
-
while (n > 0n) {
|
|
2750
|
-
out = B58[Number(n % 58n)] + out;
|
|
2751
|
-
n /= 58n;
|
|
2752
|
-
}
|
|
2753
|
-
let leadingZeros = 0;
|
|
2754
|
-
while (leadingZeros < bytes.length && bytes[leadingZeros] === 0) {
|
|
2755
|
-
leadingZeros += 1;
|
|
2756
|
-
}
|
|
2757
|
-
return "1".repeat(leadingZeros) + out;
|
|
2758
|
-
}
|
|
2759
2632
|
function u64le(value) {
|
|
2760
2633
|
const out = new Uint8Array(8);
|
|
2761
2634
|
new DataView(out.buffer).setBigUint64(0, BigInt(value), true);
|
|
@@ -2784,7 +2657,7 @@ async function intentHash(method, argsJson) {
|
|
|
2784
2657
|
return domainHash(INTENT_DOMAIN, [new TextEncoder().encode(method), args]);
|
|
2785
2658
|
}
|
|
2786
2659
|
async function importSigningKey(secretHex) {
|
|
2787
|
-
const seed =
|
|
2660
|
+
const seed = fromHex(secretHex, "deviceSecret", 32);
|
|
2788
2661
|
const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
|
|
2789
2662
|
try {
|
|
2790
2663
|
return await crypto.subtle.importKey(
|
|
@@ -2802,9 +2675,9 @@ async function importSigningKey(secretHex) {
|
|
|
2802
2675
|
}
|
|
2803
2676
|
}
|
|
2804
2677
|
async function signWarrant(input) {
|
|
2805
|
-
const context =
|
|
2806
|
-
const authorAccount =
|
|
2807
|
-
const executor =
|
|
2678
|
+
const context = fromHex(input.context, "context", 32);
|
|
2679
|
+
const authorAccount = fromHex(input.authorAccount, "authorAccount", 32);
|
|
2680
|
+
const executor = fromHex(input.executor, "executor", 32);
|
|
2808
2681
|
const key = await importSigningKey(input.deviceSecret);
|
|
2809
2682
|
const publicKey = await derivePublicKey(input.deviceSecret);
|
|
2810
2683
|
const commitment = await intentHash(input.method, input.argsJson);
|
|
@@ -2836,7 +2709,7 @@ async function signWarrant(input) {
|
|
|
2836
2709
|
);
|
|
2837
2710
|
}
|
|
2838
2711
|
async function derivePublicKey(secretHex) {
|
|
2839
|
-
const seed =
|
|
2712
|
+
const seed = fromHex(secretHex, "deviceSecret", 32);
|
|
2840
2713
|
const pkcs8 = concat(PKCS8_ED25519_PREFIX, seed);
|
|
2841
2714
|
const key = await crypto.subtle.importKey(
|
|
2842
2715
|
"pkcs8",
|