@gethashd/bytecave-browser 1.0.49 → 1.0.51

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.
@@ -6250,7 +6250,21 @@ var StorageWebTransportClient = class {
6250
6250
  };
6251
6251
  }
6252
6252
  console.log("[WebTransport] Connecting to node:", url);
6253
- const transport = new WebTransport(url);
6253
+ const certHash = this.extractCertHash(this.nodeMultiaddr);
6254
+ if (!certHash) {
6255
+ return {
6256
+ success: false,
6257
+ error: "No certificate hash in WebTransport multiaddr"
6258
+ };
6259
+ }
6260
+ const sha256Hash = await this.certHashToSHA256(certHash);
6261
+ console.log("[WebTransport] Using certificate hash:", sha256Hash);
6262
+ const transport = new WebTransport(url, {
6263
+ serverCertificateHashes: [{
6264
+ algorithm: "sha-256",
6265
+ value: sha256Hash
6266
+ }]
6267
+ });
6254
6268
  await transport.ready;
6255
6269
  console.log("[WebTransport] Connected, opening bidirectional stream");
6256
6270
  const stream = await transport.createBidirectionalStream();
@@ -6319,6 +6333,40 @@ var StorageWebTransportClient = class {
6319
6333
  return null;
6320
6334
  }
6321
6335
  }
6336
+ /**
6337
+ * Extract certificate hash from multiaddr
6338
+ * Format: /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEi...
6339
+ */
6340
+ extractCertHash(multiaddr2) {
6341
+ try {
6342
+ const parts = multiaddr2.split("/").filter((p) => p);
6343
+ const certhashIndex = parts.indexOf("certhash");
6344
+ if (certhashIndex !== -1 && certhashIndex + 1 < parts.length) {
6345
+ return parts[certhashIndex + 1];
6346
+ }
6347
+ return null;
6348
+ } catch (error) {
6349
+ console.error("[WebTransport] Failed to extract cert hash:", error);
6350
+ return null;
6351
+ }
6352
+ }
6353
+ /**
6354
+ * Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
6355
+ * The certhash in multiaddr format is: uEi<hex-hash>
6356
+ * where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
6357
+ */
6358
+ async certHashToSHA256(multihash) {
6359
+ try {
6360
+ let hexHash = multihash.startsWith("uEi") ? multihash.slice(3) : multihash;
6361
+ const bytes = new Uint8Array(hexHash.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
6362
+ console.log("[WebTransport] Decoded certificate hash:", hexHash);
6363
+ console.log("[WebTransport] Hash bytes length:", bytes.length);
6364
+ return bytes.buffer;
6365
+ } catch (error) {
6366
+ console.error("[WebTransport] Failed to convert cert hash:", error);
6367
+ throw new Error("Failed to decode certificate hash");
6368
+ }
6369
+ }
6322
6370
  };
6323
6371
 
6324
6372
  // src/contracts/ContentRegistry.ts
package/dist/index.cjs CHANGED
@@ -6303,7 +6303,21 @@ var StorageWebTransportClient = class {
6303
6303
  };
6304
6304
  }
6305
6305
  console.log("[WebTransport] Connecting to node:", url);
6306
- const transport = new WebTransport(url);
6306
+ const certHash = this.extractCertHash(this.nodeMultiaddr);
6307
+ if (!certHash) {
6308
+ return {
6309
+ success: false,
6310
+ error: "No certificate hash in WebTransport multiaddr"
6311
+ };
6312
+ }
6313
+ const sha256Hash = await this.certHashToSHA256(certHash);
6314
+ console.log("[WebTransport] Using certificate hash:", sha256Hash);
6315
+ const transport = new WebTransport(url, {
6316
+ serverCertificateHashes: [{
6317
+ algorithm: "sha-256",
6318
+ value: sha256Hash
6319
+ }]
6320
+ });
6307
6321
  await transport.ready;
6308
6322
  console.log("[WebTransport] Connected, opening bidirectional stream");
6309
6323
  const stream = await transport.createBidirectionalStream();
@@ -6372,6 +6386,40 @@ var StorageWebTransportClient = class {
6372
6386
  return null;
6373
6387
  }
6374
6388
  }
6389
+ /**
6390
+ * Extract certificate hash from multiaddr
6391
+ * Format: /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEi...
6392
+ */
6393
+ extractCertHash(multiaddr2) {
6394
+ try {
6395
+ const parts = multiaddr2.split("/").filter((p) => p);
6396
+ const certhashIndex = parts.indexOf("certhash");
6397
+ if (certhashIndex !== -1 && certhashIndex + 1 < parts.length) {
6398
+ return parts[certhashIndex + 1];
6399
+ }
6400
+ return null;
6401
+ } catch (error) {
6402
+ console.error("[WebTransport] Failed to extract cert hash:", error);
6403
+ return null;
6404
+ }
6405
+ }
6406
+ /**
6407
+ * Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
6408
+ * The certhash in multiaddr format is: uEi<hex-hash>
6409
+ * where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
6410
+ */
6411
+ async certHashToSHA256(multihash) {
6412
+ try {
6413
+ let hexHash = multihash.startsWith("uEi") ? multihash.slice(3) : multihash;
6414
+ const bytes = new Uint8Array(hexHash.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
6415
+ console.log("[WebTransport] Decoded certificate hash:", hexHash);
6416
+ console.log("[WebTransport] Hash bytes length:", bytes.length);
6417
+ return bytes.buffer;
6418
+ } catch (error) {
6419
+ console.error("[WebTransport] Failed to convert cert hash:", error);
6420
+ throw new Error("Failed to decode certificate hash");
6421
+ }
6422
+ }
6375
6423
  };
6376
6424
 
6377
6425
  // src/contracts/ContentRegistry.ts
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-CVBYHRQD.js";
16
+ } from "./chunk-KU6ZO2QD.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-CVBYHRQD.js";
11
+ } from "../chunk-KU6ZO2QD.js";
12
12
  import "../chunk-EEZWRIUI.js";
13
13
  export {
14
14
  HashdAudio,
@@ -33,4 +33,15 @@ export declare class StorageWebTransportClient {
33
33
  * Convert libp2p multiaddr to WebTransport URL
34
34
  */
35
35
  private multiaddrToWebTransportUrl;
36
+ /**
37
+ * Extract certificate hash from multiaddr
38
+ * Format: /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEi...
39
+ */
40
+ private extractCertHash;
41
+ /**
42
+ * Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
43
+ * The certhash in multiaddr format is: uEi<hex-hash>
44
+ * where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
45
+ */
46
+ private certHashToSHA256;
36
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gethashd/bytecave-browser",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "ByteCave browser client for WebRTC P2P connections to storage nodes",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -59,8 +59,27 @@ export class StorageWebTransportClient {
59
59
 
60
60
  console.log('[WebTransport] Connecting to node:', url);
61
61
 
62
- // Create WebTransport connection
63
- const transport = new WebTransport(url);
62
+ // Extract certificate hash from multiaddr for self-signed cert verification
63
+ const certHash = this.extractCertHash(this.nodeMultiaddr);
64
+ if (!certHash) {
65
+ return {
66
+ success: false,
67
+ error: 'No certificate hash in WebTransport multiaddr'
68
+ };
69
+ }
70
+
71
+ // Convert base58 multihash to SHA-256 hash for serverCertificateHashes
72
+ const sha256Hash = await this.certHashToSHA256(certHash);
73
+
74
+ console.log('[WebTransport] Using certificate hash:', sha256Hash);
75
+
76
+ // Create WebTransport connection with self-signed certificate support
77
+ const transport = new WebTransport(url, {
78
+ serverCertificateHashes: [{
79
+ algorithm: 'sha-256',
80
+ value: sha256Hash
81
+ }]
82
+ });
64
83
  await transport.ready;
65
84
 
66
85
  console.log('[WebTransport] Connected, opening bidirectional stream');
@@ -145,7 +164,6 @@ export class StorageWebTransportClient {
145
164
  }
146
165
 
147
166
  // WebTransport URL format: https://ip:port
148
- // Note: In production, this needs proper certificate handling
149
167
  return `https://${ip}:${port}`;
150
168
 
151
169
  } catch (error) {
@@ -153,4 +171,46 @@ export class StorageWebTransportClient {
153
171
  return null;
154
172
  }
155
173
  }
174
+
175
+ /**
176
+ * Extract certificate hash from multiaddr
177
+ * Format: /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEi...
178
+ */
179
+ private extractCertHash(multiaddr: string): string | null {
180
+ try {
181
+ const parts = multiaddr.split('/').filter(p => p);
182
+ const certhashIndex = parts.indexOf('certhash');
183
+ if (certhashIndex !== -1 && certhashIndex + 1 < parts.length) {
184
+ return parts[certhashIndex + 1];
185
+ }
186
+ return null;
187
+ } catch (error) {
188
+ console.error('[WebTransport] Failed to extract cert hash:', error);
189
+ return null;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
195
+ * The certhash in multiaddr format is: uEi<hex-hash>
196
+ * where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
197
+ */
198
+ private async certHashToSHA256(multihash: string): Promise<ArrayBuffer> {
199
+ try {
200
+ // Remove 'uEi' prefix to get the raw hex hash
201
+ // Format: uEi733dc9ebf43a04ad3bc692f104cf6ccc228a062fcd7aa43fc370f9c3c67e3bfc
202
+ let hexHash = multihash.startsWith('uEi') ? multihash.slice(3) : multihash;
203
+
204
+ // The hash after uEi is already in hex format, just convert to bytes
205
+ const bytes = new Uint8Array(hexHash.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
206
+
207
+ console.log('[WebTransport] Decoded certificate hash:', hexHash);
208
+ console.log('[WebTransport] Hash bytes length:', bytes.length);
209
+
210
+ return bytes.buffer;
211
+ } catch (error) {
212
+ console.error('[WebTransport] Failed to convert cert hash:', error);
213
+ throw new Error('Failed to decode certificate hash');
214
+ }
215
+ }
156
216
  }