@calimero-network/mero-js 24.1.0 → 24.1.2
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/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 +45 -26
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +45 -26
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3021,6 +3021,7 @@ function isGroupMigrationEvent(event) {
|
|
|
3021
3021
|
// src/events/sse.ts
|
|
3022
3022
|
var TERMINAL_AUTH_ERRORS2 = /* @__PURE__ */ new Set(["token_reuse", "token_revoked"]);
|
|
3023
3023
|
var TERMINAL_AUTH_STATUSES = /* @__PURE__ */ new Set([401, 403]);
|
|
3024
|
+
var SUBSCRIPTION_TIMEOUT_MS = 1e4;
|
|
3024
3025
|
function isTerminalAuthFailure(response) {
|
|
3025
3026
|
const authError = response.headers.get("x-auth-error");
|
|
3026
3027
|
if (!authError) return null;
|
|
@@ -3205,15 +3206,21 @@ var SseClient = class {
|
|
|
3205
3206
|
try {
|
|
3206
3207
|
const msg = JSON.parse(jsonStr);
|
|
3207
3208
|
if (msg.type === "connect" && msg.session_id) {
|
|
3208
|
-
|
|
3209
|
-
this.
|
|
3209
|
+
const sessionId = msg.session_id;
|
|
3210
|
+
this.sessionId = sessionId;
|
|
3210
3211
|
this.presence.clear();
|
|
3211
|
-
if (this.subscribedContextIds.size
|
|
3212
|
-
this.
|
|
3213
|
-
|
|
3214
|
-
groupIds: [...this.subscribedGroupIds]
|
|
3215
|
-
});
|
|
3212
|
+
if (this.subscribedContextIds.size === 0 && this.subscribedGroupIds.size === 0) {
|
|
3213
|
+
this.emit("connect", sessionId);
|
|
3214
|
+
return;
|
|
3216
3215
|
}
|
|
3216
|
+
void this.postSubscription("subscribe", {
|
|
3217
|
+
contextIds: [...this.subscribedContextIds],
|
|
3218
|
+
groupIds: [...this.subscribedGroupIds]
|
|
3219
|
+
}).then((failure) => {
|
|
3220
|
+
if (this.closed || this.sessionId !== sessionId) return;
|
|
3221
|
+
this.emit("connect", sessionId);
|
|
3222
|
+
if (failure) this.emit("error", failure);
|
|
3223
|
+
});
|
|
3217
3224
|
return;
|
|
3218
3225
|
}
|
|
3219
3226
|
if (!msg.result) return;
|
|
@@ -3302,6 +3309,16 @@ var SseClient = class {
|
|
|
3302
3309
|
}
|
|
3303
3310
|
}
|
|
3304
3311
|
async sendSubscription(method, ids) {
|
|
3312
|
+
const failure = await this.postSubscription(method, ids);
|
|
3313
|
+
if (failure) this.emit("error", failure);
|
|
3314
|
+
}
|
|
3315
|
+
/** Sends one subscription change and returns why it failed, or `null`. */
|
|
3316
|
+
async postSubscription(method, ids) {
|
|
3317
|
+
const timeout = new AbortController();
|
|
3318
|
+
const timer = setTimeout(
|
|
3319
|
+
() => timeout.abort(new DOMException(`SSE ${method} timed out`, "TimeoutError")),
|
|
3320
|
+
SUBSCRIPTION_TIMEOUT_MS
|
|
3321
|
+
);
|
|
3305
3322
|
try {
|
|
3306
3323
|
const params = {};
|
|
3307
3324
|
if (ids.contextIds && ids.contextIds.length > 0) params.contextIds = ids.contextIds;
|
|
@@ -3314,31 +3331,32 @@ var SseClient = class {
|
|
|
3314
3331
|
...await this.authorize({ method: "POST", path: new URL(url).pathname, body }),
|
|
3315
3332
|
"Content-Type": "application/json"
|
|
3316
3333
|
},
|
|
3317
|
-
body
|
|
3334
|
+
body,
|
|
3335
|
+
signal: timeout.signal
|
|
3318
3336
|
});
|
|
3319
3337
|
if (!response.ok) {
|
|
3320
3338
|
const terminal = isTerminalAuthFailure(response);
|
|
3321
3339
|
const bodyText = await response.text().catch(() => void 0);
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
response.headers,
|
|
3336
|
-
bodyText
|
|
3337
|
-
)
|
|
3340
|
+
return terminal ? new AuthRevokedError(
|
|
3341
|
+
terminal,
|
|
3342
|
+
response.status,
|
|
3343
|
+
response.statusText,
|
|
3344
|
+
`${this.baseUrl}/sse/subscription`,
|
|
3345
|
+
response.headers,
|
|
3346
|
+
bodyText
|
|
3347
|
+
) : new HTTPError(
|
|
3348
|
+
response.status,
|
|
3349
|
+
response.statusText,
|
|
3350
|
+
`${this.baseUrl}/sse/subscription`,
|
|
3351
|
+
response.headers,
|
|
3352
|
+
bodyText
|
|
3338
3353
|
);
|
|
3339
3354
|
}
|
|
3355
|
+
return null;
|
|
3340
3356
|
} catch (err) {
|
|
3341
|
-
|
|
3357
|
+
return err instanceof Error ? err : new Error(`SSE ${method} failed`);
|
|
3358
|
+
} finally {
|
|
3359
|
+
clearTimeout(timer);
|
|
3342
3360
|
}
|
|
3343
3361
|
}
|
|
3344
3362
|
forceReconnect() {
|
|
@@ -3817,7 +3835,8 @@ async function mintDeviceId(account, nonce2) {
|
|
|
3817
3835
|
throw new Error(`nonce must be 16 bytes, got ${nonce2.length}`);
|
|
3818
3836
|
}
|
|
3819
3837
|
const accountBytes = fromHex(account, "account", 32);
|
|
3820
|
-
|
|
3838
|
+
const binding = await domainHash(DEVICE_ID_DOMAIN, [accountBytes, nonce2]);
|
|
3839
|
+
return hex(concat(nonce2, binding.subarray(0, 16)));
|
|
3821
3840
|
}
|
|
3822
3841
|
async function deviceCertPayload(input) {
|
|
3823
3842
|
return domainHash(CERT_DOMAIN, [
|