@calimero-network/mero-js 24.0.0 → 24.1.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/cloud/cloud-client.d.ts +48 -0
- package/dist/cloud/cloud-client.js +24 -0
- package/dist/cloud/index.d.ts +1 -1
- package/dist/device-cert/device-cert.d.ts +4 -3
- package/dist/device-cert/device-cert.js +6 -4
- package/dist/events/sse.d.ts +4 -0
- package/dist/events/sse.js +35 -11
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +63 -27
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +63 -27
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2739,6 +2739,7 @@ function isGroupMigrationEvent(event) {
|
|
|
2739
2739
|
// src/events/sse.ts
|
|
2740
2740
|
var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
|
|
2741
2741
|
var TERMINAL_AUTH_STATUSES = /* @__PURE__ */ new Set([401, 403]);
|
|
2742
|
+
var SUBSCRIPTION_TIMEOUT_MS = 1e4;
|
|
2742
2743
|
function isTerminalAuthFailure(response) {
|
|
2743
2744
|
const authError = response.headers.get("x-auth-error");
|
|
2744
2745
|
if (!authError) return null;
|
|
@@ -2923,15 +2924,21 @@ var SseClient = class {
|
|
|
2923
2924
|
try {
|
|
2924
2925
|
const msg = JSON.parse(jsonStr);
|
|
2925
2926
|
if (msg.type === "connect" && msg.session_id) {
|
|
2926
|
-
|
|
2927
|
-
this.
|
|
2927
|
+
const sessionId = msg.session_id;
|
|
2928
|
+
this.sessionId = sessionId;
|
|
2928
2929
|
this.presence.clear();
|
|
2929
|
-
if (this.subscribedContextIds.size
|
|
2930
|
-
this.
|
|
2931
|
-
|
|
2932
|
-
groupIds: [...this.subscribedGroupIds]
|
|
2933
|
-
});
|
|
2930
|
+
if (this.subscribedContextIds.size === 0 && this.subscribedGroupIds.size === 0) {
|
|
2931
|
+
this.emit("connect", sessionId);
|
|
2932
|
+
return;
|
|
2934
2933
|
}
|
|
2934
|
+
void this.postSubscription("subscribe", {
|
|
2935
|
+
contextIds: [...this.subscribedContextIds],
|
|
2936
|
+
groupIds: [...this.subscribedGroupIds]
|
|
2937
|
+
}).then((failure) => {
|
|
2938
|
+
if (this.closed || this.sessionId !== sessionId) return;
|
|
2939
|
+
this.emit("connect", sessionId);
|
|
2940
|
+
if (failure) this.emit("error", failure);
|
|
2941
|
+
});
|
|
2935
2942
|
return;
|
|
2936
2943
|
}
|
|
2937
2944
|
if (!msg.result) return;
|
|
@@ -3020,6 +3027,16 @@ var SseClient = class {
|
|
|
3020
3027
|
}
|
|
3021
3028
|
}
|
|
3022
3029
|
async sendSubscription(method, ids) {
|
|
3030
|
+
const failure = await this.postSubscription(method, ids);
|
|
3031
|
+
if (failure) this.emit("error", failure);
|
|
3032
|
+
}
|
|
3033
|
+
/** Sends one subscription change and returns why it failed, or `null`. */
|
|
3034
|
+
async postSubscription(method, ids) {
|
|
3035
|
+
const timeout = new AbortController();
|
|
3036
|
+
const timer = setTimeout(
|
|
3037
|
+
() => timeout.abort(new DOMException(`SSE ${method} timed out`, "TimeoutError")),
|
|
3038
|
+
SUBSCRIPTION_TIMEOUT_MS
|
|
3039
|
+
);
|
|
3023
3040
|
try {
|
|
3024
3041
|
const params = {};
|
|
3025
3042
|
if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
|
|
@@ -3032,31 +3049,32 @@ var SseClient = class {
|
|
|
3032
3049
|
...await this.authorize({ method: "POST", path: new URL(url).pathname, body }),
|
|
3033
3050
|
"Content-Type": "application/json"
|
|
3034
3051
|
},
|
|
3035
|
-
body
|
|
3052
|
+
body,
|
|
3053
|
+
signal: timeout.signal
|
|
3036
3054
|
});
|
|
3037
3055
|
if (!response.ok) {
|
|
3038
3056
|
const terminal = isTerminalAuthFailure(response);
|
|
3039
3057
|
const bodyText = await response.text().catch(() => void 0);
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
response.headers,
|
|
3054
|
-
bodyText
|
|
3055
|
-
)
|
|
3058
|
+
return terminal ? new AuthRevokedError(
|
|
3059
|
+
terminal,
|
|
3060
|
+
response.status,
|
|
3061
|
+
response.statusText,
|
|
3062
|
+
`${this.baseUrl}/sse/subscription`,
|
|
3063
|
+
response.headers,
|
|
3064
|
+
bodyText
|
|
3065
|
+
) : new HTTPError(
|
|
3066
|
+
response.status,
|
|
3067
|
+
response.statusText,
|
|
3068
|
+
`${this.baseUrl}/sse/subscription`,
|
|
3069
|
+
response.headers,
|
|
3070
|
+
bodyText
|
|
3056
3071
|
);
|
|
3057
3072
|
}
|
|
3073
|
+
return null;
|
|
3058
3074
|
} catch (err) {
|
|
3059
|
-
|
|
3075
|
+
return err instanceof Error ? err : new Error(`SSE ${method} failed`);
|
|
3076
|
+
} finally {
|
|
3077
|
+
clearTimeout(timer);
|
|
3060
3078
|
}
|
|
3061
3079
|
}
|
|
3062
3080
|
forceReconnect() {
|
|
@@ -3535,7 +3553,8 @@ async function mintDeviceId(account, nonce2) {
|
|
|
3535
3553
|
throw new Error(`nonce must be 16 bytes, got ${nonce2.length}`);
|
|
3536
3554
|
}
|
|
3537
3555
|
const accountBytes = fromHex(account, "account", 32);
|
|
3538
|
-
|
|
3556
|
+
const binding = await domainHash(DEVICE_ID_DOMAIN, [accountBytes, nonce2]);
|
|
3557
|
+
return hex(concat(nonce2, binding.subarray(0, 16)));
|
|
3539
3558
|
}
|
|
3540
3559
|
async function deviceCertPayload(input) {
|
|
3541
3560
|
return domainHash(CERT_DOMAIN, [
|
|
@@ -10930,6 +10949,20 @@ function teeRoleOf(row) {
|
|
|
10930
10949
|
function pickExecutingRelay(relays) {
|
|
10931
10950
|
return relays.find((r) => r.canExecute && r.relayUrl !== null && r.executorAccount !== null) ?? null;
|
|
10932
10951
|
}
|
|
10952
|
+
function joinOf(row) {
|
|
10953
|
+
const raw = row.join;
|
|
10954
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
10955
|
+
const join = raw;
|
|
10956
|
+
if (typeof join.state !== "string") return null;
|
|
10957
|
+
const refusals = Array.isArray(join.refusals) ? join.refusals.filter((r) => !!r && typeof r === "object").map((r) => ({ peer: String(r.peer ?? ""), reason: String(r.reason ?? "") })) : [];
|
|
10958
|
+
return {
|
|
10959
|
+
state: join.state,
|
|
10960
|
+
attempts: typeof join.attempts === "number" ? join.attempts : 0,
|
|
10961
|
+
refusals,
|
|
10962
|
+
error: typeof join.error === "string" ? join.error : null,
|
|
10963
|
+
reportedAt: typeof join.reported_at === "string" ? join.reported_at : null
|
|
10964
|
+
};
|
|
10965
|
+
}
|
|
10933
10966
|
var ACCOUNT_HEX = /^[0-9a-f]{64}$/;
|
|
10934
10967
|
function accountHexOrNull(value) {
|
|
10935
10968
|
return typeof value === "string" && ACCOUNT_HEX.test(value) ? value : null;
|
|
@@ -11169,7 +11202,10 @@ var CloudClient = class {
|
|
|
11169
11202
|
authorshipReady && relayUrl !== null && executorAccount !== null
|
|
11170
11203
|
),
|
|
11171
11204
|
lastSeenAt: row.last_seen_at ?? null,
|
|
11172
|
-
confirmedAt: row.confirmed_at ?? null
|
|
11205
|
+
confirmedAt: row.confirmed_at ?? null,
|
|
11206
|
+
admission: typeof row.admission === "string" ? row.admission : null,
|
|
11207
|
+
admissionHint: typeof row.admission_hint === "string" ? row.admission_hint : null,
|
|
11208
|
+
join: joinOf(row)
|
|
11173
11209
|
};
|
|
11174
11210
|
});
|
|
11175
11211
|
}
|