@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.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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';
|
|
8
9
|
export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
|
|
9
10
|
export type { TokenStore } from './token-store/index.js';
|
|
10
11
|
export { RpcClient, RpcError } from './rpc/index.js';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@ 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';
|
|
13
15
|
// Token store
|
|
14
16
|
export { MemoryTokenStore, LocalStorageTokenStore } from './token-store/index.js';
|
|
15
17
|
// RPC client
|
package/dist/index.mjs
CHANGED
|
@@ -1125,13 +1125,17 @@ var AdminApiClient = class {
|
|
|
1125
1125
|
);
|
|
1126
1126
|
}
|
|
1127
1127
|
async joinNamespace(namespaceId, request) {
|
|
1128
|
-
|
|
1128
|
+
const data = unwrap(
|
|
1129
1129
|
await this.httpClient.post(
|
|
1130
1130
|
`/admin-api/namespaces/${namespaceId}/join`,
|
|
1131
1131
|
request,
|
|
1132
1132
|
{ timeoutMs: 65e3 }
|
|
1133
1133
|
)
|
|
1134
1134
|
);
|
|
1135
|
+
if (data && data.namespaceId === void 0 && data.groupId !== void 0) {
|
|
1136
|
+
return { ...data, namespaceId: data.groupId };
|
|
1137
|
+
}
|
|
1138
|
+
return data;
|
|
1135
1139
|
}
|
|
1136
1140
|
async createGroupInNamespace(namespaceId, request) {
|
|
1137
1141
|
return unwrap(
|
|
@@ -1527,6 +1531,7 @@ function isGroupMigrationEvent(event) {
|
|
|
1527
1531
|
}
|
|
1528
1532
|
|
|
1529
1533
|
// src/events/sse.ts
|
|
1534
|
+
var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
|
|
1530
1535
|
var SseClient = class {
|
|
1531
1536
|
constructor(opts) {
|
|
1532
1537
|
this.sessionId = null;
|
|
@@ -1604,7 +1609,8 @@ var SseClient = class {
|
|
|
1604
1609
|
this.abortController = new AbortController();
|
|
1605
1610
|
try {
|
|
1606
1611
|
const token = await this.getAuthToken();
|
|
1607
|
-
const
|
|
1612
|
+
const url = `${this.baseUrl}/sse`;
|
|
1613
|
+
const response = await fetch(url, {
|
|
1608
1614
|
headers: {
|
|
1609
1615
|
"Authorization": `Bearer ${token}`,
|
|
1610
1616
|
"Accept": "text/event-stream"
|
|
@@ -1612,7 +1618,25 @@ var SseClient = class {
|
|
|
1612
1618
|
signal: this.abortController.signal
|
|
1613
1619
|
});
|
|
1614
1620
|
if (!response.ok) {
|
|
1615
|
-
|
|
1621
|
+
const authError = response.headers.get("x-auth-error");
|
|
1622
|
+
const bodyText = await response.text().catch(() => void 0);
|
|
1623
|
+
if (response.status === 401 && authError && TERMINAL_AUTH_ERRORS2.has(authError)) {
|
|
1624
|
+
throw new AuthRevokedError(
|
|
1625
|
+
authError,
|
|
1626
|
+
response.status,
|
|
1627
|
+
response.statusText,
|
|
1628
|
+
url,
|
|
1629
|
+
response.headers,
|
|
1630
|
+
bodyText
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
throw new HTTPError(
|
|
1634
|
+
response.status,
|
|
1635
|
+
response.statusText,
|
|
1636
|
+
url,
|
|
1637
|
+
response.headers,
|
|
1638
|
+
bodyText
|
|
1639
|
+
);
|
|
1616
1640
|
}
|
|
1617
1641
|
if (!response.body) {
|
|
1618
1642
|
throw new Error("SSE response has no body");
|
|
@@ -2378,6 +2402,93 @@ function createMeroJs(config) {
|
|
|
2378
2402
|
return new MeroJs(config);
|
|
2379
2403
|
}
|
|
2380
2404
|
|
|
2405
|
+
// src/account/index.ts
|
|
2406
|
+
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2407
|
+
var HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
|
|
2408
|
+
function encodeBase58(bytes) {
|
|
2409
|
+
if (bytes.length === 0) return "";
|
|
2410
|
+
const digits = [0];
|
|
2411
|
+
for (const byte of bytes) {
|
|
2412
|
+
let carry = byte;
|
|
2413
|
+
for (let i = 0; i < digits.length; i++) {
|
|
2414
|
+
carry += digits[i] << 8;
|
|
2415
|
+
digits[i] = carry % 58;
|
|
2416
|
+
carry = carry / 58 | 0;
|
|
2417
|
+
}
|
|
2418
|
+
while (carry > 0) {
|
|
2419
|
+
digits.push(carry % 58);
|
|
2420
|
+
carry = carry / 58 | 0;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
let out = "";
|
|
2424
|
+
for (const byte of bytes) {
|
|
2425
|
+
if (byte !== 0) break;
|
|
2426
|
+
out += BASE58_ALPHABET[0];
|
|
2427
|
+
}
|
|
2428
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
2429
|
+
out += BASE58_ALPHABET[digits[i]];
|
|
2430
|
+
}
|
|
2431
|
+
return out;
|
|
2432
|
+
}
|
|
2433
|
+
function decodeBase58(value) {
|
|
2434
|
+
if (value.length === 0) return null;
|
|
2435
|
+
const bytes = [0];
|
|
2436
|
+
for (const char of value) {
|
|
2437
|
+
const index = BASE58_ALPHABET.indexOf(char);
|
|
2438
|
+
if (index < 0) return null;
|
|
2439
|
+
let carry = index;
|
|
2440
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2441
|
+
carry += bytes[i] * 58;
|
|
2442
|
+
bytes[i] = carry & 255;
|
|
2443
|
+
carry >>= 8;
|
|
2444
|
+
}
|
|
2445
|
+
while (carry > 0) {
|
|
2446
|
+
bytes.push(carry & 255);
|
|
2447
|
+
carry >>= 8;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
let leadingZeros = 0;
|
|
2451
|
+
for (const char of value) {
|
|
2452
|
+
if (char !== BASE58_ALPHABET[0]) break;
|
|
2453
|
+
leadingZeros++;
|
|
2454
|
+
}
|
|
2455
|
+
return Uint8Array.from([
|
|
2456
|
+
...new Array(leadingZeros).fill(0),
|
|
2457
|
+
...bytes.reverse()
|
|
2458
|
+
]);
|
|
2459
|
+
}
|
|
2460
|
+
function toHex(bytes) {
|
|
2461
|
+
let out = "";
|
|
2462
|
+
for (const byte of bytes) out += byte.toString(16).padStart(2, "0");
|
|
2463
|
+
return out;
|
|
2464
|
+
}
|
|
2465
|
+
function fromHex(hex) {
|
|
2466
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
2467
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
2468
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
2469
|
+
}
|
|
2470
|
+
return bytes;
|
|
2471
|
+
}
|
|
2472
|
+
function toAccountHex(id) {
|
|
2473
|
+
const trimmed = (id ?? "").trim();
|
|
2474
|
+
if (!trimmed) return "";
|
|
2475
|
+
if (HEX_ACCOUNT.test(trimmed)) return trimmed.toLowerCase();
|
|
2476
|
+
const decoded = decodeBase58(trimmed);
|
|
2477
|
+
if (!decoded || decoded.length !== 32) return trimmed;
|
|
2478
|
+
return toHex(decoded);
|
|
2479
|
+
}
|
|
2480
|
+
function toAccountBase58(id) {
|
|
2481
|
+
const trimmed = (id ?? "").trim();
|
|
2482
|
+
if (!trimmed) return "";
|
|
2483
|
+
if (!HEX_ACCOUNT.test(trimmed)) return trimmed;
|
|
2484
|
+
return encodeBase58(fromHex(trimmed));
|
|
2485
|
+
}
|
|
2486
|
+
function sameAccount(a, b) {
|
|
2487
|
+
const left = toAccountHex(a);
|
|
2488
|
+
const right = toAccountHex(b);
|
|
2489
|
+
return HEX_ACCOUNT.test(left) && left === right;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2381
2492
|
// src/token-store/index.ts
|
|
2382
2493
|
var MemoryTokenStore = class {
|
|
2383
2494
|
constructor() {
|
|
@@ -2576,6 +2687,9 @@ export {
|
|
|
2576
2687
|
nodeEndpoint,
|
|
2577
2688
|
parseAuthCallback,
|
|
2578
2689
|
probeNodeHealth,
|
|
2690
|
+
sameAccount,
|
|
2691
|
+
toAccountBase58,
|
|
2692
|
+
toAccountHex,
|
|
2579
2693
|
withCap,
|
|
2580
2694
|
withRetry,
|
|
2581
2695
|
withoutCap
|