@le-space/core 0.9.2 → 0.9.5
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 +36 -17
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -2628,7 +2628,8 @@ function browserMultiaddrTransport(addr) {
|
|
|
2628
2628
|
}
|
|
2629
2629
|
function selectCompactRelayBootstrapMultiaddrs(addrs, limit = DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT) {
|
|
2630
2630
|
const entries = filterPublicMultiaddrs(addrs, {
|
|
2631
|
-
browserDialableOnly: true
|
|
2631
|
+
browserDialableOnly: true,
|
|
2632
|
+
allowInsecureWebSockets: true
|
|
2632
2633
|
}).map((addr, index) => ({
|
|
2633
2634
|
addr,
|
|
2634
2635
|
index,
|
|
@@ -2698,12 +2699,23 @@ function isLocalHostname(host) {
|
|
|
2698
2699
|
function hasPeerId(addr) {
|
|
2699
2700
|
return splitMultiaddr(addr).includes("p2p");
|
|
2700
2701
|
}
|
|
2701
|
-
function
|
|
2702
|
+
function isSecureWebSocketMultiaddr(addr) {
|
|
2703
|
+
const parts = splitMultiaddr(addr.toLowerCase());
|
|
2704
|
+
if (parts.includes("wss")) return true;
|
|
2705
|
+
const wsIndex = parts.indexOf("ws");
|
|
2706
|
+
return wsIndex > 0 && parts.lastIndexOf("tls", wsIndex) >= 0;
|
|
2707
|
+
}
|
|
2708
|
+
function isWebSocketMultiaddr(addr) {
|
|
2709
|
+
const parts = splitMultiaddr(addr.toLowerCase());
|
|
2710
|
+
return parts.includes("ws") || parts.includes("wss");
|
|
2711
|
+
}
|
|
2712
|
+
function isBrowserDialableMultiaddr(addr, options = {}) {
|
|
2702
2713
|
const normalized = addr.toLowerCase();
|
|
2703
2714
|
if (normalized.includes("/webtransport") || normalized.includes("/webrtc-direct")) {
|
|
2704
2715
|
return normalized.includes("/certhash/");
|
|
2705
2716
|
}
|
|
2706
|
-
|
|
2717
|
+
if (!isWebSocketMultiaddr(addr)) return false;
|
|
2718
|
+
return (options.allowInsecureWebSockets ?? false) || isSecureWebSocketMultiaddr(addr);
|
|
2707
2719
|
}
|
|
2708
2720
|
function dedupeMultiaddrs(addrs) {
|
|
2709
2721
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -2737,7 +2749,9 @@ function filterPublicMultiaddrs(addrs, options = {}) {
|
|
|
2737
2749
|
return dedupeMultiaddrs(addrs).filter((addr) => {
|
|
2738
2750
|
if (!isPublicMultiaddr(addr)) return false;
|
|
2739
2751
|
if (options.requirePeerId !== false && !hasPeerId(addr)) return false;
|
|
2740
|
-
if (options.browserDialableOnly && !isBrowserDialableMultiaddr(addr
|
|
2752
|
+
if (options.browserDialableOnly && !isBrowserDialableMultiaddr(addr, {
|
|
2753
|
+
allowInsecureWebSockets: options.allowInsecureWebSockets
|
|
2754
|
+
})) {
|
|
2741
2755
|
return false;
|
|
2742
2756
|
}
|
|
2743
2757
|
return true;
|
|
@@ -2852,7 +2866,8 @@ function buildRelayBootstrapPostContent(args) {
|
|
|
2852
2866
|
const updatedAt = args.now ?? Date.now();
|
|
2853
2867
|
const fullMultiaddrs = filterPublicMultiaddrs(args.multiaddrs);
|
|
2854
2868
|
const fullBrowserMultiaddrs = args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
|
|
2855
|
-
browserDialableOnly: true
|
|
2869
|
+
browserDialableOnly: true,
|
|
2870
|
+
allowInsecureWebSockets: true
|
|
2856
2871
|
}) : void 0;
|
|
2857
2872
|
const compactMultiaddrs = selectCompactRelayBootstrapMultiaddrs(
|
|
2858
2873
|
fullBrowserMultiaddrs && fullBrowserMultiaddrs.length > 0 ? fullBrowserMultiaddrs : fullMultiaddrs,
|
|
@@ -2934,7 +2949,8 @@ async function signRelayBootstrapAuthorization(args) {
|
|
|
2934
2949
|
async function signRelayBootstrapProof(args) {
|
|
2935
2950
|
const fullMultiaddrs = filterPublicMultiaddrs(args.multiaddrs);
|
|
2936
2951
|
const fullBrowserMultiaddrs = args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
|
|
2937
|
-
browserDialableOnly: true
|
|
2952
|
+
browserDialableOnly: true,
|
|
2953
|
+
allowInsecureWebSockets: true
|
|
2938
2954
|
}) : void 0;
|
|
2939
2955
|
const compactMultiaddrs = selectCompactRelayBootstrapMultiaddrs(
|
|
2940
2956
|
fullBrowserMultiaddrs && fullBrowserMultiaddrs.length > 0 ? fullBrowserMultiaddrs : fullMultiaddrs,
|
|
@@ -2989,20 +3005,24 @@ async function fetchAlephBootstrapPosts(options = {}) {
|
|
|
2989
3005
|
}
|
|
2990
3006
|
const payload = await response.json();
|
|
2991
3007
|
const posts = (payload.posts ?? []).map((entry) => normalizeRelayBootstrapPostRecord(entry)).filter((entry) => entry != null).sort((left, right) => compareRelayBootstrapPostRecency(right, left));
|
|
2992
|
-
posts.
|
|
2993
|
-
return posts;
|
|
3008
|
+
return usableRelayBootstrapPosts(posts, options.onUnsupportedPost);
|
|
2994
3009
|
}
|
|
2995
|
-
function
|
|
3010
|
+
function unsupportedRelayBootstrapReason(post) {
|
|
2996
3011
|
if (post.type === "relay-bootstrap") {
|
|
2997
|
-
|
|
2998
|
-
"Legacy relay-bootstrap record encountered. Only relay-bootstrap-v2 is supported."
|
|
2999
|
-
);
|
|
3012
|
+
return "legacy relay-bootstrap record; only relay-bootstrap-v2 is supported";
|
|
3000
3013
|
}
|
|
3001
3014
|
if (post.type && post.type !== DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE) {
|
|
3002
|
-
|
|
3003
|
-
`Unsupported relay bootstrap post type: ${post.type}. Expected ${DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE}.`
|
|
3004
|
-
);
|
|
3015
|
+
return `unsupported post type ${post.type}; expected ${DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE}`;
|
|
3005
3016
|
}
|
|
3017
|
+
return null;
|
|
3018
|
+
}
|
|
3019
|
+
function usableRelayBootstrapPosts(posts, onUnsupportedPost) {
|
|
3020
|
+
return posts.filter((post) => {
|
|
3021
|
+
const reason = unsupportedRelayBootstrapReason(post);
|
|
3022
|
+
if (!reason) return true;
|
|
3023
|
+
onUnsupportedPost?.({ hash: post.itemHash ?? post.hash, reason });
|
|
3024
|
+
return false;
|
|
3025
|
+
});
|
|
3006
3026
|
}
|
|
3007
3027
|
function compareRelayBootstrapPostRecency(left, right) {
|
|
3008
3028
|
const leftUpdatedAt = left.content?.updatedAt ?? 0;
|
|
@@ -3023,8 +3043,7 @@ function selectCurrentRelayBootstrapPosts(posts, options = {}) {
|
|
|
3023
3043
|
const maxAgeMs = options.maxAgeMs ?? DEFAULT_BOOTSTRAP_MAX_AGE_MS;
|
|
3024
3044
|
const now = options.now ?? Date.now();
|
|
3025
3045
|
const selected = /* @__PURE__ */ new Map();
|
|
3026
|
-
for (const post of posts) {
|
|
3027
|
-
assertSupportedRelayBootstrapPost(post);
|
|
3046
|
+
for (const post of usableRelayBootstrapPosts(posts, options.onUnsupportedPost)) {
|
|
3028
3047
|
const content = post.content;
|
|
3029
3048
|
if (!content) continue;
|
|
3030
3049
|
if (now - content.updatedAt > maxAgeMs) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/NiKrause/relay-button/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@le-space/aleph-bootstrap": "0.9.
|
|
28
|
-
"@le-space/shared-types": "0.9.
|
|
27
|
+
"@le-space/aleph-bootstrap": "0.9.5",
|
|
28
|
+
"@le-space/shared-types": "0.9.5"
|
|
29
29
|
}
|
|
30
30
|
}
|