@gethashd/bytecave-browser 1.0.38 → 1.0.40

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.
@@ -6534,84 +6534,43 @@ Nonce: ${nonce}`;
6534
6534
  console.warn("[ByteCave] Failed to create authorization:", err.message);
6535
6535
  }
6536
6536
  }
6537
- if (this.config.relayWsUrl) {
6538
- console.log("[ByteCave] Attempting WebSocket storage via relay");
6539
- try {
6540
- if (!this.storageWsClient) {
6541
- this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
6542
- }
6543
- const wsAuth = authorization ? {
6544
- signature: authorization.signature,
6545
- address: authorization.sender,
6546
- timestamp: authorization.timestamp,
6547
- nonce: authorization.nonce,
6548
- appId: authorization.appId,
6549
- contentHash: authorization.contentHash
6550
- } : void 0;
6551
- const result = await this.storageWsClient.store({
6552
- data: dataArray,
6553
- contentType: mimeType || "application/octet-stream",
6554
- hashIdToken,
6555
- authorization: wsAuth,
6556
- timeout: 3e4
6557
- });
6558
- if (result.success && result.cid) {
6559
- console.log("[ByteCave] \u2713 WebSocket storage successful:", result.cid);
6560
- return {
6561
- success: true,
6562
- cid: result.cid,
6563
- peerId: "relay-ws"
6564
- };
6565
- }
6566
- console.warn("[ByteCave] WebSocket storage failed:", result.error);
6567
- } catch (err) {
6568
- console.warn("[ByteCave] WebSocket storage exception:", err.message);
6569
- }
6537
+ if (!this.config.relayWsUrl) {
6538
+ return { success: false, error: "WebSocket relay URL not configured" };
6570
6539
  }
6571
- if (!this.node) {
6572
- return { success: false, error: "WebSocket storage failed and P2P node not initialized" };
6573
- }
6574
- console.log("[ByteCave] Falling back to P2P storage");
6575
- const allPeers = this.node.getPeers();
6576
- const connectedPeerIds = allPeers.map((p) => p.toString());
6577
- console.log("[ByteCave] Store - connected storage peers:", connectedPeerIds.length);
6578
- if (connectedPeerIds.length === 0) {
6579
- return { success: false, error: "WebSocket storage failed and no P2P peers available" };
6580
- }
6581
- const registeredPeerIds = Array.from(this.knownPeers.values()).filter((p) => p.isRegistered && connectedPeerIds.includes(p.peerId)).map((p) => p.peerId);
6582
- const storagePeerIds = registeredPeerIds.length > 0 ? [...registeredPeerIds, ...connectedPeerIds.filter((id) => !registeredPeerIds.includes(id))] : connectedPeerIds;
6583
- const errors = [];
6584
- for (const peerId of storagePeerIds) {
6585
- console.log("[ByteCave] Attempting P2P store to peer:", peerId.slice(0, 12) + "...");
6586
- try {
6587
- const result = await p2pProtocolClient.storeToPeer(
6588
- peerId,
6589
- dataArray,
6590
- mimeType || "application/octet-stream",
6591
- authorization,
6592
- false,
6593
- // shouldVerifyOnChain - false for browser test storage
6594
- hashIdToken
6595
- );
6596
- if (result.success && result.cid) {
6597
- console.log("[ByteCave] \u2713 P2P store successful:", result.cid);
6598
- return {
6599
- success: true,
6600
- cid: result.cid,
6601
- peerId
6602
- };
6603
- }
6604
- const errorMsg = `${peerId.slice(0, 12)}: ${result.error}`;
6605
- console.warn("[ByteCave] \u2717 P2P store failed:", errorMsg);
6606
- errors.push(errorMsg);
6607
- } catch (err) {
6608
- const errorMsg = `${peerId.slice(0, 12)}: ${err.message}`;
6609
- console.error("[ByteCave] \u2717 P2P store exception:", errorMsg);
6610
- errors.push(errorMsg);
6540
+ console.log("[ByteCave] Storing via WebSocket relay");
6541
+ try {
6542
+ if (!this.storageWsClient) {
6543
+ this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
6611
6544
  }
6545
+ const wsAuth = authorization ? {
6546
+ signature: authorization.signature,
6547
+ address: authorization.sender,
6548
+ timestamp: authorization.timestamp,
6549
+ nonce: authorization.nonce,
6550
+ appId: authorization.appId,
6551
+ contentHash: authorization.contentHash
6552
+ } : void 0;
6553
+ const result = await this.storageWsClient.store({
6554
+ data: dataArray,
6555
+ contentType: mimeType || "application/octet-stream",
6556
+ hashIdToken,
6557
+ authorization: wsAuth,
6558
+ timeout: 3e4
6559
+ });
6560
+ if (result.success && result.cid) {
6561
+ console.log("[ByteCave] \u2713 WebSocket storage successful:", result.cid);
6562
+ return {
6563
+ success: true,
6564
+ cid: result.cid,
6565
+ peerId: "relay-ws"
6566
+ };
6567
+ }
6568
+ console.warn("[ByteCave] WebSocket storage failed:", result.error);
6569
+ return { success: false, error: result.error || "WebSocket storage failed" };
6570
+ } catch (err) {
6571
+ console.error("[ByteCave] WebSocket storage exception:", err.message);
6572
+ return { success: false, error: err.message };
6612
6573
  }
6613
- console.error("[ByteCave] All storage methods failed. Errors:", errors);
6614
- return { success: false, error: `All storage methods failed: ${errors.join("; ")}` };
6615
6574
  }
6616
6575
  /**
6617
6576
  * Retrieve ciphertext from a node via P2P only (no HTTP fallback)
package/dist/index.cjs CHANGED
@@ -6587,84 +6587,43 @@ Nonce: ${nonce}`;
6587
6587
  console.warn("[ByteCave] Failed to create authorization:", err.message);
6588
6588
  }
6589
6589
  }
6590
- if (this.config.relayWsUrl) {
6591
- console.log("[ByteCave] Attempting WebSocket storage via relay");
6592
- try {
6593
- if (!this.storageWsClient) {
6594
- this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
6595
- }
6596
- const wsAuth = authorization ? {
6597
- signature: authorization.signature,
6598
- address: authorization.sender,
6599
- timestamp: authorization.timestamp,
6600
- nonce: authorization.nonce,
6601
- appId: authorization.appId,
6602
- contentHash: authorization.contentHash
6603
- } : void 0;
6604
- const result = await this.storageWsClient.store({
6605
- data: dataArray,
6606
- contentType: mimeType || "application/octet-stream",
6607
- hashIdToken,
6608
- authorization: wsAuth,
6609
- timeout: 3e4
6610
- });
6611
- if (result.success && result.cid) {
6612
- console.log("[ByteCave] \u2713 WebSocket storage successful:", result.cid);
6613
- return {
6614
- success: true,
6615
- cid: result.cid,
6616
- peerId: "relay-ws"
6617
- };
6618
- }
6619
- console.warn("[ByteCave] WebSocket storage failed:", result.error);
6620
- } catch (err) {
6621
- console.warn("[ByteCave] WebSocket storage exception:", err.message);
6622
- }
6590
+ if (!this.config.relayWsUrl) {
6591
+ return { success: false, error: "WebSocket relay URL not configured" };
6623
6592
  }
6624
- if (!this.node) {
6625
- return { success: false, error: "WebSocket storage failed and P2P node not initialized" };
6626
- }
6627
- console.log("[ByteCave] Falling back to P2P storage");
6628
- const allPeers = this.node.getPeers();
6629
- const connectedPeerIds = allPeers.map((p) => p.toString());
6630
- console.log("[ByteCave] Store - connected storage peers:", connectedPeerIds.length);
6631
- if (connectedPeerIds.length === 0) {
6632
- return { success: false, error: "WebSocket storage failed and no P2P peers available" };
6633
- }
6634
- const registeredPeerIds = Array.from(this.knownPeers.values()).filter((p) => p.isRegistered && connectedPeerIds.includes(p.peerId)).map((p) => p.peerId);
6635
- const storagePeerIds = registeredPeerIds.length > 0 ? [...registeredPeerIds, ...connectedPeerIds.filter((id) => !registeredPeerIds.includes(id))] : connectedPeerIds;
6636
- const errors = [];
6637
- for (const peerId of storagePeerIds) {
6638
- console.log("[ByteCave] Attempting P2P store to peer:", peerId.slice(0, 12) + "...");
6639
- try {
6640
- const result = await p2pProtocolClient.storeToPeer(
6641
- peerId,
6642
- dataArray,
6643
- mimeType || "application/octet-stream",
6644
- authorization,
6645
- false,
6646
- // shouldVerifyOnChain - false for browser test storage
6647
- hashIdToken
6648
- );
6649
- if (result.success && result.cid) {
6650
- console.log("[ByteCave] \u2713 P2P store successful:", result.cid);
6651
- return {
6652
- success: true,
6653
- cid: result.cid,
6654
- peerId
6655
- };
6656
- }
6657
- const errorMsg = `${peerId.slice(0, 12)}: ${result.error}`;
6658
- console.warn("[ByteCave] \u2717 P2P store failed:", errorMsg);
6659
- errors.push(errorMsg);
6660
- } catch (err) {
6661
- const errorMsg = `${peerId.slice(0, 12)}: ${err.message}`;
6662
- console.error("[ByteCave] \u2717 P2P store exception:", errorMsg);
6663
- errors.push(errorMsg);
6593
+ console.log("[ByteCave] Storing via WebSocket relay");
6594
+ try {
6595
+ if (!this.storageWsClient) {
6596
+ this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
6664
6597
  }
6598
+ const wsAuth = authorization ? {
6599
+ signature: authorization.signature,
6600
+ address: authorization.sender,
6601
+ timestamp: authorization.timestamp,
6602
+ nonce: authorization.nonce,
6603
+ appId: authorization.appId,
6604
+ contentHash: authorization.contentHash
6605
+ } : void 0;
6606
+ const result = await this.storageWsClient.store({
6607
+ data: dataArray,
6608
+ contentType: mimeType || "application/octet-stream",
6609
+ hashIdToken,
6610
+ authorization: wsAuth,
6611
+ timeout: 3e4
6612
+ });
6613
+ if (result.success && result.cid) {
6614
+ console.log("[ByteCave] \u2713 WebSocket storage successful:", result.cid);
6615
+ return {
6616
+ success: true,
6617
+ cid: result.cid,
6618
+ peerId: "relay-ws"
6619
+ };
6620
+ }
6621
+ console.warn("[ByteCave] WebSocket storage failed:", result.error);
6622
+ return { success: false, error: result.error || "WebSocket storage failed" };
6623
+ } catch (err) {
6624
+ console.error("[ByteCave] WebSocket storage exception:", err.message);
6625
+ return { success: false, error: err.message };
6665
6626
  }
6666
- console.error("[ByteCave] All storage methods failed. Errors:", errors);
6667
- return { success: false, error: `All storage methods failed: ${errors.join("; ")}` };
6668
6627
  }
6669
6628
  /**
6670
6629
  * Retrieve ciphertext from a node via P2P only (no HTTP fallback)
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-CIBPIU23.js";
16
+ } from "./chunk-IXGM3WHR.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-CIBPIU23.js";
11
+ } from "../chunk-IXGM3WHR.js";
12
12
  import "../chunk-EEZWRIUI.js";
13
13
  export {
14
14
  HashdAudio,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gethashd/bytecave-browser",
3
- "version": "1.0.38",
3
+ "version": "1.0.40",
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",
package/src/client.ts CHANGED
@@ -476,108 +476,50 @@ Nonce: ${nonce}`;
476
476
  }
477
477
  }
478
478
 
479
- // Try WebSocket storage first if relay WS URL is configured
480
- if (this.config.relayWsUrl) {
481
- console.log('[ByteCave] Attempting WebSocket storage via relay');
482
-
483
- try {
484
- if (!this.storageWsClient) {
485
- this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
486
- }
487
-
488
- const wsAuth = authorization ? {
489
- signature: authorization.signature,
490
- address: authorization.sender,
491
- timestamp: authorization.timestamp,
492
- nonce: authorization.nonce,
493
- appId: authorization.appId,
494
- contentHash: authorization.contentHash
495
- } : undefined;
496
-
497
- const result = await this.storageWsClient.store({
498
- data: dataArray,
499
- contentType: mimeType || 'application/octet-stream',
500
- hashIdToken,
501
- authorization: wsAuth,
502
- timeout: 30000
503
- });
504
-
505
- if (result.success && result.cid) {
506
- console.log('[ByteCave] ✓ WebSocket storage successful:', result.cid);
507
- return {
508
- success: true,
509
- cid: result.cid,
510
- peerId: 'relay-ws'
511
- };
512
- }
513
-
514
- console.warn('[ByteCave] WebSocket storage failed:', result.error);
515
- } catch (err: any) {
516
- console.warn('[ByteCave] WebSocket storage exception:', err.message);
517
- }
479
+ // Use WebSocket relay for storage (browsers cannot use P2P storage protocol)
480
+ if (!this.config.relayWsUrl) {
481
+ return { success: false, error: 'WebSocket relay URL not configured' };
518
482
  }
519
483
 
520
- // Fallback to P2P storage
521
- if (!this.node) {
522
- return { success: false, error: 'WebSocket storage failed and P2P node not initialized' };
523
- }
524
-
525
- console.log('[ByteCave] Falling back to P2P storage');
526
-
527
- // Get all connected peers
528
- const allPeers = this.node.getPeers();
529
- const connectedPeerIds = allPeers.map(p => p.toString());
530
-
531
- console.log('[ByteCave] Store - connected storage peers:', connectedPeerIds.length);
532
-
533
- if (connectedPeerIds.length === 0) {
534
- return { success: false, error: 'WebSocket storage failed and no P2P peers available' };
535
- }
484
+ console.log('[ByteCave] Storing via WebSocket relay');
536
485
 
537
- // Prioritize registered peers from knownPeers
538
- const registeredPeerIds = Array.from(this.knownPeers.values())
539
- .filter(p => p.isRegistered && connectedPeerIds.includes(p.peerId))
540
- .map(p => p.peerId);
541
-
542
- const storagePeerIds = registeredPeerIds.length > 0
543
- ? [...registeredPeerIds, ...connectedPeerIds.filter(id => !registeredPeerIds.includes(id))]
544
- : connectedPeerIds;
545
-
546
- const errors: string[] = [];
547
- for (const peerId of storagePeerIds) {
548
- console.log('[ByteCave] Attempting P2P store to peer:', peerId.slice(0, 12) + '...');
549
-
550
- try {
551
- const result = await p2pProtocolClient.storeToPeer(
552
- peerId,
553
- dataArray,
554
- mimeType || 'application/octet-stream',
555
- authorization,
556
- false, // shouldVerifyOnChain - false for browser test storage
557
- hashIdToken
558
- );
486
+ try {
487
+ if (!this.storageWsClient) {
488
+ this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
489
+ }
559
490
 
560
- if (result.success && result.cid) {
561
- console.log('[ByteCave] ✓ P2P store successful:', result.cid);
562
- return {
563
- success: true,
564
- cid: result.cid,
565
- peerId
566
- };
567
- }
568
-
569
- const errorMsg = `${peerId.slice(0, 12)}: ${result.error}`;
570
- console.warn('[ByteCave] ✗ P2P store failed:', errorMsg);
571
- errors.push(errorMsg);
572
- } catch (err: any) {
573
- const errorMsg = `${peerId.slice(0, 12)}: ${err.message}`;
574
- console.error('[ByteCave] ✗ P2P store exception:', errorMsg);
575
- errors.push(errorMsg);
491
+ const wsAuth = authorization ? {
492
+ signature: authorization.signature,
493
+ address: authorization.sender,
494
+ timestamp: authorization.timestamp,
495
+ nonce: authorization.nonce,
496
+ appId: authorization.appId,
497
+ contentHash: authorization.contentHash
498
+ } : undefined;
499
+
500
+ const result = await this.storageWsClient.store({
501
+ data: dataArray,
502
+ contentType: mimeType || 'application/octet-stream',
503
+ hashIdToken,
504
+ authorization: wsAuth,
505
+ timeout: 30000
506
+ });
507
+
508
+ if (result.success && result.cid) {
509
+ console.log('[ByteCave] ✓ WebSocket storage successful:', result.cid);
510
+ return {
511
+ success: true,
512
+ cid: result.cid,
513
+ peerId: 'relay-ws'
514
+ };
576
515
  }
516
+
517
+ console.warn('[ByteCave] WebSocket storage failed:', result.error);
518
+ return { success: false, error: result.error || 'WebSocket storage failed' };
519
+ } catch (err: any) {
520
+ console.error('[ByteCave] WebSocket storage exception:', err.message);
521
+ return { success: false, error: err.message };
577
522
  }
578
-
579
- console.error('[ByteCave] All storage methods failed. Errors:', errors);
580
- return { success: false, error: `All storage methods failed: ${errors.join('; ')}` };
581
523
  }
582
524
 
583
525
  /**