@calimero-network/mero-js 13.1.0 → 13.2.1
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/account/index.d.ts +43 -0
- package/dist/account/index.js +139 -0
- package/dist/admin-api/admin-client.js +11 -1
- package/dist/admin-api/admin-types.d.ts +19 -1
- package/dist/events/sse.js +23 -2
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +117 -3
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +117 -3
- package/dist/index.mjs.map +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,9 @@ __export(index_exports, {
|
|
|
60
60
|
nodeEndpoint: () => nodeEndpoint,
|
|
61
61
|
parseAuthCallback: () => parseAuthCallback,
|
|
62
62
|
probeNodeHealth: () => probeNodeHealth,
|
|
63
|
+
sameAccount: () => sameAccount,
|
|
64
|
+
toAccountBase58: () => toAccountBase58,
|
|
65
|
+
toAccountHex: () => toAccountHex,
|
|
63
66
|
withCap: () => withCap,
|
|
64
67
|
withRetry: () => withRetry,
|
|
65
68
|
withoutCap: () => withoutCap
|
|
@@ -1193,13 +1196,17 @@ var AdminApiClient = class {
|
|
|
1193
1196
|
);
|
|
1194
1197
|
}
|
|
1195
1198
|
async joinNamespace(namespaceId, request) {
|
|
1196
|
-
|
|
1199
|
+
const data = unwrap(
|
|
1197
1200
|
await this.httpClient.post(
|
|
1198
1201
|
`/admin-api/namespaces/${namespaceId}/join`,
|
|
1199
1202
|
request,
|
|
1200
1203
|
{ timeoutMs: 65e3 }
|
|
1201
1204
|
)
|
|
1202
1205
|
);
|
|
1206
|
+
if (data && data.namespaceId === void 0 && data.groupId !== void 0) {
|
|
1207
|
+
return { ...data, namespaceId: data.groupId };
|
|
1208
|
+
}
|
|
1209
|
+
return data;
|
|
1203
1210
|
}
|
|
1204
1211
|
async createGroupInNamespace(namespaceId, request) {
|
|
1205
1212
|
return unwrap(
|
|
@@ -1595,6 +1602,7 @@ function isGroupMigrationEvent(event) {
|
|
|
1595
1602
|
}
|
|
1596
1603
|
|
|
1597
1604
|
// src/events/sse.ts
|
|
1605
|
+
var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
|
|
1598
1606
|
var SseClient = class {
|
|
1599
1607
|
constructor(opts) {
|
|
1600
1608
|
this.sessionId = null;
|
|
@@ -1672,7 +1680,8 @@ var SseClient = class {
|
|
|
1672
1680
|
this.abortController = new AbortController();
|
|
1673
1681
|
try {
|
|
1674
1682
|
const token = await this.getAuthToken();
|
|
1675
|
-
const
|
|
1683
|
+
const url = `${this.baseUrl}/sse`;
|
|
1684
|
+
const response = await fetch(url, {
|
|
1676
1685
|
headers: {
|
|
1677
1686
|
"Authorization": `Bearer ${token}`,
|
|
1678
1687
|
"Accept": "text/event-stream"
|
|
@@ -1680,7 +1689,25 @@ var SseClient = class {
|
|
|
1680
1689
|
signal: this.abortController.signal
|
|
1681
1690
|
});
|
|
1682
1691
|
if (!response.ok) {
|
|
1683
|
-
|
|
1692
|
+
const authError = response.headers.get("x-auth-error");
|
|
1693
|
+
const bodyText = await response.text().catch(() => void 0);
|
|
1694
|
+
if (response.status === 401 && authError && TERMINAL_AUTH_ERRORS2.has(authError)) {
|
|
1695
|
+
throw new AuthRevokedError(
|
|
1696
|
+
authError,
|
|
1697
|
+
response.status,
|
|
1698
|
+
response.statusText,
|
|
1699
|
+
url,
|
|
1700
|
+
response.headers,
|
|
1701
|
+
bodyText
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
throw new HTTPError(
|
|
1705
|
+
response.status,
|
|
1706
|
+
response.statusText,
|
|
1707
|
+
url,
|
|
1708
|
+
response.headers,
|
|
1709
|
+
bodyText
|
|
1710
|
+
);
|
|
1684
1711
|
}
|
|
1685
1712
|
if (!response.body) {
|
|
1686
1713
|
throw new Error("SSE response has no body");
|
|
@@ -2446,6 +2473,93 @@ function createMeroJs(config) {
|
|
|
2446
2473
|
return new MeroJs(config);
|
|
2447
2474
|
}
|
|
2448
2475
|
|
|
2476
|
+
// src/account/index.ts
|
|
2477
|
+
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2478
|
+
var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
|
|
2479
|
+
function encodeBase58(bytes) {
|
|
2480
|
+
if (bytes.length === 0) return "";
|
|
2481
|
+
const digits = [0];
|
|
2482
|
+
for (const byte of bytes) {
|
|
2483
|
+
let carry = byte;
|
|
2484
|
+
for (let i = 0; i < digits.length; i++) {
|
|
2485
|
+
carry += digits[i] << 8;
|
|
2486
|
+
digits[i] = carry % 58;
|
|
2487
|
+
carry = carry / 58 | 0;
|
|
2488
|
+
}
|
|
2489
|
+
while (carry > 0) {
|
|
2490
|
+
digits.push(carry % 58);
|
|
2491
|
+
carry = carry / 58 | 0;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
let out = "";
|
|
2495
|
+
for (const byte of bytes) {
|
|
2496
|
+
if (byte !== 0) break;
|
|
2497
|
+
out += BASE58_ALPHABET[0];
|
|
2498
|
+
}
|
|
2499
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
2500
|
+
out += BASE58_ALPHABET[digits[i]];
|
|
2501
|
+
}
|
|
2502
|
+
return out;
|
|
2503
|
+
}
|
|
2504
|
+
function decodeBase58(value) {
|
|
2505
|
+
if (value.length === 0) return null;
|
|
2506
|
+
const bytes = [0];
|
|
2507
|
+
for (const char of value) {
|
|
2508
|
+
const index = BASE58_ALPHABET.indexOf(char);
|
|
2509
|
+
if (index < 0) return null;
|
|
2510
|
+
let carry = index;
|
|
2511
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2512
|
+
carry += bytes[i] * 58;
|
|
2513
|
+
bytes[i] = carry & 255;
|
|
2514
|
+
carry >>= 8;
|
|
2515
|
+
}
|
|
2516
|
+
while (carry > 0) {
|
|
2517
|
+
bytes.push(carry & 255);
|
|
2518
|
+
carry >>= 8;
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
let leadingZeros = 0;
|
|
2522
|
+
for (const char of value) {
|
|
2523
|
+
if (char !== BASE58_ALPHABET[0]) break;
|
|
2524
|
+
leadingZeros++;
|
|
2525
|
+
}
|
|
2526
|
+
return Uint8Array.from([
|
|
2527
|
+
...new Array(leadingZeros).fill(0),
|
|
2528
|
+
...bytes.reverse()
|
|
2529
|
+
]);
|
|
2530
|
+
}
|
|
2531
|
+
function toHex(bytes) {
|
|
2532
|
+
let out = "";
|
|
2533
|
+
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
2534
|
+
return out;
|
|
2535
|
+
}
|
|
2536
|
+
function fromHex(hex) {
|
|
2537
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2538
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2539
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
2540
|
+
}
|
|
2541
|
+
return bytes;
|
|
2542
|
+
}
|
|
2543
|
+
function toAccountHex(id) {
|
|
2544
|
+
const trimmed = (id ?? "").trim();
|
|
2545
|
+
if (!trimmed) return "";
|
|
2546
|
+
if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
|
|
2547
|
+
const decoded = decodeBase58(trimmed);
|
|
2548
|
+
if (!decoded || decoded.length !== 32) return trimmed;
|
|
2549
|
+
return toHex(decoded);
|
|
2550
|
+
}
|
|
2551
|
+
function toAccountBase58(id) {
|
|
2552
|
+
const trimmed = (id ?? "").trim();
|
|
2553
|
+
if (!trimmed) return "";
|
|
2554
|
+
if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
|
|
2555
|
+
return encodeBase58(fromHex(trimmed));
|
|
2556
|
+
}
|
|
2557
|
+
function sameAccount(a, b) {
|
|
2558
|
+
const left = toAccountHex(a);
|
|
2559
|
+
const right = toAccountHex(b);
|
|
2560
|
+
return HEX_ACCOUNT.test(left) && left === right;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2449
2563
|
// src/token-store/index.ts
|
|
2450
2564
|
var MemoryTokenStore = class {
|
|
2451
2565
|
constructor() {
|