@le-space/aleph-bootstrap 0.6.25 → 0.6.27
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/index.js +52 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -52,7 +52,8 @@ function browserMultiaddrTransport(addr) {
|
|
|
52
52
|
const normalized = addr.toLowerCase();
|
|
53
53
|
if (normalized.includes("/webtransport/")) return "webtransport";
|
|
54
54
|
if (normalized.includes("/webrtc-direct/")) return "webrtc";
|
|
55
|
-
if (normalized.includes("/ws") || normalized.includes("/wss"))
|
|
55
|
+
if (normalized.includes("/ws") || normalized.includes("/wss"))
|
|
56
|
+
return "websocket";
|
|
56
57
|
return "other";
|
|
57
58
|
}
|
|
58
59
|
function selectCompactRelayBootstrapMultiaddrs(addrs, limit = DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT) {
|
|
@@ -135,7 +136,10 @@ function hasPeerId(addr) {
|
|
|
135
136
|
}
|
|
136
137
|
function isBrowserDialableMultiaddr(addr) {
|
|
137
138
|
const normalized = addr.toLowerCase();
|
|
138
|
-
|
|
139
|
+
if (normalized.includes("/webtransport") || normalized.includes("/webrtc-direct")) {
|
|
140
|
+
return normalized.includes("/certhash/");
|
|
141
|
+
}
|
|
142
|
+
return normalized.includes("/ws") || normalized.includes("/wss");
|
|
139
143
|
}
|
|
140
144
|
function dedupeMultiaddrs(addrs) {
|
|
141
145
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -181,8 +185,12 @@ function normalizeRelayBootstrapContent(value) {
|
|
|
181
185
|
const peerId = asTrimmedString(content.peerId);
|
|
182
186
|
const updatedAt = asNumber(content.updatedAt);
|
|
183
187
|
if (!peerId || updatedAt == null) return null;
|
|
184
|
-
const multiaddrs = Array.isArray(content.multiaddrs) ? content.multiaddrs.filter(
|
|
185
|
-
|
|
188
|
+
const multiaddrs = Array.isArray(content.multiaddrs) ? content.multiaddrs.filter(
|
|
189
|
+
(entry) => typeof entry === "string"
|
|
190
|
+
) : [];
|
|
191
|
+
const browserMultiaddrs = Array.isArray(content.browserMultiaddrs) ? content.browserMultiaddrs.filter(
|
|
192
|
+
(entry) => typeof entry === "string"
|
|
193
|
+
) : void 0;
|
|
186
194
|
return {
|
|
187
195
|
peerId,
|
|
188
196
|
multiaddrs: dedupeMultiaddrs(multiaddrs),
|
|
@@ -235,8 +243,12 @@ function normalizeRelayBootstrapProofPayload(value) {
|
|
|
235
243
|
const peerId = asTrimmedString(payload.peerId);
|
|
236
244
|
const updatedAt = asNumber(payload.updatedAt);
|
|
237
245
|
if (!peerId || updatedAt == null) return null;
|
|
238
|
-
const multiaddrs = Array.isArray(payload.multiaddrs) ? payload.multiaddrs.filter(
|
|
239
|
-
|
|
246
|
+
const multiaddrs = Array.isArray(payload.multiaddrs) ? payload.multiaddrs.filter(
|
|
247
|
+
(entry) => typeof entry === "string"
|
|
248
|
+
) : [];
|
|
249
|
+
const browserMultiaddrs = Array.isArray(payload.browserMultiaddrs) ? payload.browserMultiaddrs.filter(
|
|
250
|
+
(entry) => typeof entry === "string"
|
|
251
|
+
) : void 0;
|
|
240
252
|
return {
|
|
241
253
|
peerId,
|
|
242
254
|
multiaddrs: multiaddrs.length > 0 ? dedupeMultiaddrs(multiaddrs) : void 0,
|
|
@@ -395,7 +407,9 @@ async function verifyRelayBootstrapAuthorization(authorization, options = {}) {
|
|
|
395
407
|
return { ok: false, errors };
|
|
396
408
|
}
|
|
397
409
|
if (authorization.scheme !== RELAY_BOOTSTRAP_SIGNATURE_SCHEME) {
|
|
398
|
-
errors.push(
|
|
410
|
+
errors.push(
|
|
411
|
+
`Unsupported owner authorization scheme: ${authorization.scheme}`
|
|
412
|
+
);
|
|
399
413
|
return { ok: false, errors };
|
|
400
414
|
}
|
|
401
415
|
const payload = authorization.payload;
|
|
@@ -406,7 +420,9 @@ async function verifyRelayBootstrapAuthorization(authorization, options = {}) {
|
|
|
406
420
|
authorization.signature
|
|
407
421
|
);
|
|
408
422
|
if (normalizeAddress(recovered) !== normalizeAddress(payload.ownerAddress)) {
|
|
409
|
-
errors.push(
|
|
423
|
+
errors.push(
|
|
424
|
+
"Owner authorization signature does not recover the owner address."
|
|
425
|
+
);
|
|
410
426
|
}
|
|
411
427
|
} catch (error) {
|
|
412
428
|
errors.push(
|
|
@@ -432,9 +448,14 @@ async function verifyRelayBootstrapProof(proof, options = {}) {
|
|
|
432
448
|
const payload = proof.payload;
|
|
433
449
|
const serialized = serializeRelayProofPayload(payload);
|
|
434
450
|
try {
|
|
435
|
-
const recovered = await recoverAddressForSignature(
|
|
451
|
+
const recovered = await recoverAddressForSignature(
|
|
452
|
+
serialized,
|
|
453
|
+
proof.signature
|
|
454
|
+
);
|
|
436
455
|
if (options.expectedPublisherAddress && normalizeAddress(recovered) !== normalizeAddress(options.expectedPublisherAddress)) {
|
|
437
|
-
errors.push(
|
|
456
|
+
errors.push(
|
|
457
|
+
"Relay proof signature does not recover the expected publisher address."
|
|
458
|
+
);
|
|
438
459
|
}
|
|
439
460
|
} catch (error) {
|
|
440
461
|
errors.push(
|
|
@@ -465,7 +486,9 @@ async function verifyRelayBootstrapDualKeyContent(content, options = {}) {
|
|
|
465
486
|
errors.push(...proof.errors);
|
|
466
487
|
if (content.ownerAddress && content.authorization) {
|
|
467
488
|
if (normalizeAddress(content.ownerAddress) !== normalizeAddress(content.authorization.payload.ownerAddress)) {
|
|
468
|
-
errors.push(
|
|
489
|
+
errors.push(
|
|
490
|
+
"Content ownerAddress does not match the owner authorization payload."
|
|
491
|
+
);
|
|
469
492
|
}
|
|
470
493
|
}
|
|
471
494
|
if (expectedPublisherAddress && content.authorization) {
|
|
@@ -476,12 +499,16 @@ async function verifyRelayBootstrapDualKeyContent(content, options = {}) {
|
|
|
476
499
|
}
|
|
477
500
|
}
|
|
478
501
|
if (content.authorization && content.authorization.payload.peerId !== content.peerId) {
|
|
479
|
-
errors.push(
|
|
502
|
+
errors.push(
|
|
503
|
+
"Owner authorization peer ID does not match the bootstrap content peer ID."
|
|
504
|
+
);
|
|
480
505
|
}
|
|
481
506
|
const proofPayload = content.relayProof?.payload;
|
|
482
507
|
if (proofPayload) {
|
|
483
508
|
if (proofPayload.registrationId !== content.registrationId) {
|
|
484
|
-
errors.push(
|
|
509
|
+
errors.push(
|
|
510
|
+
"Relay proof registrationId does not match the bootstrap content."
|
|
511
|
+
);
|
|
485
512
|
}
|
|
486
513
|
if (proofPayload.profile !== content.profile) {
|
|
487
514
|
errors.push("Relay proof profile does not match the bootstrap content.");
|
|
@@ -490,11 +517,15 @@ async function verifyRelayBootstrapDualKeyContent(content, options = {}) {
|
|
|
490
517
|
errors.push("Relay proof version does not match the bootstrap content.");
|
|
491
518
|
}
|
|
492
519
|
if (proofPayload.updatedAt !== content.updatedAt) {
|
|
493
|
-
errors.push(
|
|
520
|
+
errors.push(
|
|
521
|
+
"Relay proof updatedAt does not match the bootstrap content."
|
|
522
|
+
);
|
|
494
523
|
}
|
|
495
524
|
if (proofPayload.multiaddrsHash) {
|
|
496
525
|
if (proofPayload.multiaddrsHash !== relayBootstrapMultiaddrsHash(content.multiaddrs)) {
|
|
497
|
-
errors.push(
|
|
526
|
+
errors.push(
|
|
527
|
+
"Relay proof multiaddrs hash does not match the bootstrap content."
|
|
528
|
+
);
|
|
498
529
|
}
|
|
499
530
|
} else if (JSON.stringify(dedupeMultiaddrs(proofPayload.multiaddrs ?? [])) !== JSON.stringify(dedupeMultiaddrs(content.multiaddrs))) {
|
|
500
531
|
errors.push("Relay proof multiaddrs do not match the bootstrap content.");
|
|
@@ -506,8 +537,12 @@ async function verifyRelayBootstrapDualKeyContent(content, options = {}) {
|
|
|
506
537
|
);
|
|
507
538
|
}
|
|
508
539
|
} else if (proofPayload.browserMultiaddrs || content.browserMultiaddrs) {
|
|
509
|
-
if (JSON.stringify(
|
|
510
|
-
|
|
540
|
+
if (JSON.stringify(
|
|
541
|
+
dedupeMultiaddrs(proofPayload.browserMultiaddrs ?? [])
|
|
542
|
+
) !== JSON.stringify(dedupeMultiaddrs(content.browserMultiaddrs ?? []))) {
|
|
543
|
+
errors.push(
|
|
544
|
+
"Relay proof browserMultiaddrs do not match the bootstrap content."
|
|
545
|
+
);
|
|
511
546
|
}
|
|
512
547
|
}
|
|
513
548
|
}
|