@le-space/aleph-bootstrap 0.9.2 → 0.9.3

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.
Files changed (3) hide show
  1. package/index.d.ts +24 -1
  2. package/index.js +28 -9
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -85,6 +85,13 @@ interface DiscoverAlephBootstrapOptions {
85
85
  maxAgeMs?: number;
86
86
  compactMultiaddrLimit?: number;
87
87
  browserDialableOnly?: boolean;
88
+ /**
89
+ * Keep plaintext `/ws` relays in a browser-dialable result. Defaults to
90
+ * false so an https page never receives an address the browser will block as
91
+ * mixed content. Set it for consumers that dial from node or a plain-http
92
+ * origin.
93
+ */
94
+ allowInsecureWebSockets?: boolean;
88
95
  requireDualKeyAttestation?: boolean;
89
96
  verifyDualKeyAttestation?: boolean;
90
97
  /**
@@ -101,6 +108,15 @@ interface DiscoverAlephBootstrapOptions {
101
108
  interface FilterPublicMultiaddrsOptions {
102
109
  browserDialableOnly?: boolean;
103
110
  requirePeerId?: boolean;
111
+ /**
112
+ * Keep plaintext `/ws` addresses in the browser-dialable set. Defaults to
113
+ * false: a page served over https cannot open a `ws://` socket, the browser
114
+ * blocks it as mixed content, so a plaintext relay is dead weight in a
115
+ * browser bootstrap list. Publishers pass true — a relay should still
116
+ * announce the plaintext port it really serves, for node peers that can use
117
+ * it.
118
+ */
119
+ allowInsecureWebSockets?: boolean;
104
120
  }
105
121
  interface CreateRelayBootstrapPostOptions {
106
122
  sender: string;
@@ -122,7 +138,14 @@ interface CreateRelayBootstrapPostOptions {
122
138
  }
123
139
  type RelayBootstrapTrustMode = "wallet-signed" | "dual-key-attested";
124
140
  declare function relayBootstrapMultiaddrsHash(addrs: readonly string[]): string;
141
+ /**
142
+ * Publish-side helper: pick the addresses a relay announces to the registry.
143
+ * Plaintext `/ws` is kept here on purpose — announcing the port the relay
144
+ * really serves is honest, and node peers can dial it. Browsers filter it out
145
+ * again on the read side, where the https origin makes it undialable.
146
+ */
125
147
  declare function selectCompactRelayBootstrapMultiaddrs(addrs: readonly string[], limit?: number): string[];
148
+ declare function isBrowserDialableMultiaddr(addr: string, options?: Pick<FilterPublicMultiaddrsOptions, "allowInsecureWebSockets">): boolean;
126
149
  declare function dedupeMultiaddrs(addrs: readonly string[]): string[];
127
150
  declare function isPublicMultiaddr(addr: string): boolean;
128
151
  declare function filterPublicMultiaddrs(addrs: readonly string[], options?: FilterPublicMultiaddrsOptions): string[];
@@ -202,4 +225,4 @@ declare function createLibp2pAlephBootstrap(options?: DiscoverAlephBootstrapOpti
202
225
  tagName?: string;
203
226
  }): Promise<ReturnType<typeof bootstrap>>;
204
227
 
205
- export { type CreateRelayBootstrapPostOptions, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_BOOTSTRAP_CHANNEL, DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE, DEFAULT_ALEPH_BOOTSTRAP_REF, DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT, DEFAULT_BOOTSTRAP_MAX_AGE_MS, DEFAULT_BOOTSTRAP_MAX_PAGES, DEFAULT_BOOTSTRAP_PAGINATION, type DiscoverAlephBootstrapOptions, type FilterPublicMultiaddrsOptions, RELAY_BOOTSTRAP_SIGNATURE_SCHEME, type RelayBootstrapAuthorizationPayload, type RelayBootstrapAuthorizationRecord, type RelayBootstrapContent, type RelayBootstrapPostContent, type RelayBootstrapPostRecord, type RelayBootstrapProofPayload, type RelayBootstrapProofRecord, type RelayBootstrapProofSigner, type RelayBootstrapTrustMode, type RelayBootstrapVerificationResult, buildRelayBootstrapPostContent, createLibp2pAlephBootstrap, createRelayBootstrapPost, dedupeMultiaddrs, discoverAlephBootstrapMultiaddrs, fetchAlephBootstrapPosts, filterPublicMultiaddrs, filterRelayBootstrapPostsByProfile, isPublicMultiaddr, relayBootstrapMultiaddrsHash, relayBootstrapTrustMode, selectCompactRelayBootstrapMultiaddrs, selectCurrentRelayBootstrapPosts, signRelayBootstrapAuthorization, signRelayBootstrapProof, verifyRelayBootstrapAuthorization, verifyRelayBootstrapDualKeyContent, verifyRelayBootstrapProof };
228
+ export { type CreateRelayBootstrapPostOptions, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_BOOTSTRAP_CHANNEL, DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE, DEFAULT_ALEPH_BOOTSTRAP_REF, DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT, DEFAULT_BOOTSTRAP_MAX_AGE_MS, DEFAULT_BOOTSTRAP_MAX_PAGES, DEFAULT_BOOTSTRAP_PAGINATION, type DiscoverAlephBootstrapOptions, type FilterPublicMultiaddrsOptions, RELAY_BOOTSTRAP_SIGNATURE_SCHEME, type RelayBootstrapAuthorizationPayload, type RelayBootstrapAuthorizationRecord, type RelayBootstrapContent, type RelayBootstrapPostContent, type RelayBootstrapPostRecord, type RelayBootstrapProofPayload, type RelayBootstrapProofRecord, type RelayBootstrapProofSigner, type RelayBootstrapTrustMode, type RelayBootstrapVerificationResult, buildRelayBootstrapPostContent, createLibp2pAlephBootstrap, createRelayBootstrapPost, dedupeMultiaddrs, discoverAlephBootstrapMultiaddrs, fetchAlephBootstrapPosts, filterPublicMultiaddrs, filterRelayBootstrapPostsByProfile, isBrowserDialableMultiaddr, isPublicMultiaddr, relayBootstrapMultiaddrsHash, relayBootstrapTrustMode, selectCompactRelayBootstrapMultiaddrs, selectCurrentRelayBootstrapPosts, signRelayBootstrapAuthorization, signRelayBootstrapProof, verifyRelayBootstrapAuthorization, verifyRelayBootstrapDualKeyContent, verifyRelayBootstrapProof };
package/index.js CHANGED
@@ -58,7 +58,8 @@ function browserMultiaddrTransport(addr) {
58
58
  }
59
59
  function selectCompactRelayBootstrapMultiaddrs(addrs, limit = DEFAULT_BOOTSTRAP_COMPACT_MULTIADDR_LIMIT) {
60
60
  const entries = filterPublicMultiaddrs(addrs, {
61
- browserDialableOnly: true
61
+ browserDialableOnly: true,
62
+ allowInsecureWebSockets: true
62
63
  }).map((addr, index) => ({
63
64
  addr,
64
65
  index,
@@ -134,12 +135,23 @@ function isLocalHostname(host) {
134
135
  function hasPeerId(addr) {
135
136
  return splitMultiaddr(addr).includes("p2p");
136
137
  }
137
- function isBrowserDialableMultiaddr(addr) {
138
+ function isSecureWebSocketMultiaddr(addr) {
139
+ const parts = splitMultiaddr(addr.toLowerCase());
140
+ if (parts.includes("wss")) return true;
141
+ const wsIndex = parts.indexOf("ws");
142
+ return wsIndex > 0 && parts.lastIndexOf("tls", wsIndex) >= 0;
143
+ }
144
+ function isWebSocketMultiaddr(addr) {
145
+ const parts = splitMultiaddr(addr.toLowerCase());
146
+ return parts.includes("ws") || parts.includes("wss");
147
+ }
148
+ function isBrowserDialableMultiaddr(addr, options = {}) {
138
149
  const normalized = addr.toLowerCase();
139
150
  if (normalized.includes("/webtransport") || normalized.includes("/webrtc-direct")) {
140
151
  return normalized.includes("/certhash/");
141
152
  }
142
- return normalized.includes("/ws") || normalized.includes("/wss");
153
+ if (!isWebSocketMultiaddr(addr)) return false;
154
+ return (options.allowInsecureWebSockets ?? false) || isSecureWebSocketMultiaddr(addr);
143
155
  }
144
156
  function dedupeMultiaddrs(addrs) {
145
157
  const seen = /* @__PURE__ */ new Set();
@@ -173,7 +185,9 @@ function filterPublicMultiaddrs(addrs, options = {}) {
173
185
  return dedupeMultiaddrs(addrs).filter((addr) => {
174
186
  if (!isPublicMultiaddr(addr)) return false;
175
187
  if (options.requirePeerId !== false && !hasPeerId(addr)) return false;
176
- if (options.browserDialableOnly && !isBrowserDialableMultiaddr(addr)) {
188
+ if (options.browserDialableOnly && !isBrowserDialableMultiaddr(addr, {
189
+ allowInsecureWebSockets: options.allowInsecureWebSockets
190
+ })) {
177
191
  return false;
178
192
  }
179
193
  return true;
@@ -288,7 +302,8 @@ function buildRelayBootstrapPostContent(args) {
288
302
  const updatedAt = args.now ?? Date.now();
289
303
  const fullMultiaddrs = filterPublicMultiaddrs(args.multiaddrs);
290
304
  const fullBrowserMultiaddrs = args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
291
- browserDialableOnly: true
305
+ browserDialableOnly: true,
306
+ allowInsecureWebSockets: true
292
307
  }) : void 0;
293
308
  const compactMultiaddrs = selectCompactRelayBootstrapMultiaddrs(
294
309
  fullBrowserMultiaddrs && fullBrowserMultiaddrs.length > 0 ? fullBrowserMultiaddrs : fullMultiaddrs,
@@ -376,7 +391,8 @@ async function signRelayBootstrapAuthorization(args) {
376
391
  async function signRelayBootstrapProof(args) {
377
392
  const fullMultiaddrs = filterPublicMultiaddrs(args.multiaddrs);
378
393
  const fullBrowserMultiaddrs = args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
379
- browserDialableOnly: true
394
+ browserDialableOnly: true,
395
+ allowInsecureWebSockets: true
380
396
  }) : void 0;
381
397
  const compactMultiaddrs = selectCompactRelayBootstrapMultiaddrs(
382
398
  fullBrowserMultiaddrs && fullBrowserMultiaddrs.length > 0 ? fullBrowserMultiaddrs : fullMultiaddrs,
@@ -688,7 +704,8 @@ async function discoverAlephBootstrapMultiaddrs(options = {}) {
688
704
  });
689
705
  const addrs = relayBootstrapPostsToMultiaddrs(
690
706
  trustedPosts,
691
- browserDialableOnly
707
+ browserDialableOnly,
708
+ options.allowInsecureWebSockets ?? false
692
709
  );
693
710
  if (addrs.length > 0) {
694
711
  return addrs;
@@ -699,7 +716,7 @@ async function discoverAlephBootstrapMultiaddrs(options = {}) {
699
716
  }
700
717
  return [];
701
718
  }
702
- function relayBootstrapPostsToMultiaddrs(posts, browserDialableOnly) {
719
+ function relayBootstrapPostsToMultiaddrs(posts, browserDialableOnly, allowInsecureWebSockets) {
703
720
  const addrs = [];
704
721
  for (const post of posts) {
705
722
  const content = post.content;
@@ -707,7 +724,8 @@ function relayBootstrapPostsToMultiaddrs(posts, browserDialableOnly) {
707
724
  const candidates = browserDialableOnly && Array.isArray(content.browserMultiaddrs) && content.browserMultiaddrs.length > 0 ? content.browserMultiaddrs : content.multiaddrs;
708
725
  addrs.push(
709
726
  ...filterPublicMultiaddrs(candidates, {
710
- browserDialableOnly
727
+ browserDialableOnly,
728
+ allowInsecureWebSockets
711
729
  })
712
730
  );
713
731
  }
@@ -739,6 +757,7 @@ export {
739
757
  fetchAlephBootstrapPosts,
740
758
  filterPublicMultiaddrs,
741
759
  filterRelayBootstrapPostsByProfile,
760
+ isBrowserDialableMultiaddr,
742
761
  isPublicMultiaddr,
743
762
  relayBootstrapMultiaddrsHash,
744
763
  relayBootstrapTrustMode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/aleph-bootstrap",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Aleph-backed libp2p bootstrap discovery and relay registration helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",