@le-space/aleph-bootstrap 0.6.5 → 0.6.6
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 +22 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -52,15 +52,35 @@ function browserMultiaddrPreference(addr) {
|
|
|
52
52
|
if (normalized.includes("/ws")) return 4;
|
|
53
53
|
return 5;
|
|
54
54
|
}
|
|
55
|
+
function browserMultiaddrTransport(addr) {
|
|
56
|
+
const normalized = addr.toLowerCase();
|
|
57
|
+
if (normalized.includes("/webtransport/")) return "webtransport";
|
|
58
|
+
if (normalized.includes("/webrtc-direct/")) return "webrtc";
|
|
59
|
+
if (normalized.includes("/ws") || normalized.includes("/wss")) return "websocket";
|
|
60
|
+
return "other";
|
|
61
|
+
}
|
|
55
62
|
function selectCompactRelayBootstrapMultiaddrs(addrs, limit = DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT) {
|
|
56
63
|
const entries = filterPublicMultiaddrs(addrs, {
|
|
57
64
|
browserDialableOnly: true
|
|
58
|
-
}).map((addr, index) => ({
|
|
65
|
+
}).map((addr, index) => ({
|
|
66
|
+
addr,
|
|
67
|
+
index,
|
|
68
|
+
transport: browserMultiaddrTransport(addr)
|
|
69
|
+
}));
|
|
59
70
|
entries.sort((left, right) => {
|
|
60
71
|
const preference = browserMultiaddrPreference(left.addr) - browserMultiaddrPreference(right.addr);
|
|
61
72
|
return preference !== 0 ? preference : left.index - right.index;
|
|
62
73
|
});
|
|
63
|
-
|
|
74
|
+
const perTransportLimit = Math.max(1, Math.floor(limit));
|
|
75
|
+
const selectedByTransport = /* @__PURE__ */ new Map();
|
|
76
|
+
const result = [];
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const selected = selectedByTransport.get(entry.transport) ?? 0;
|
|
79
|
+
if (selected >= perTransportLimit) continue;
|
|
80
|
+
selectedByTransport.set(entry.transport, selected + 1);
|
|
81
|
+
result.push(entry.addr);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
64
84
|
}
|
|
65
85
|
async function recoverAddressForSignature(payload, signature) {
|
|
66
86
|
return recoverMessageAddress({
|