@gethashd/bytecave-browser 1.0.39 → 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.
- package/dist/{chunk-SIGWRCA5.js → chunk-IXGM3WHR.js} +35 -79
- package/dist/index.cjs +35 -79
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/src/client.ts +39 -98
|
@@ -6224,17 +6224,7 @@ var ByteCaveClient = class {
|
|
|
6224
6224
|
console.log("[ByteCave] Bootstrap peers:", bootstrapPeers);
|
|
6225
6225
|
this.node = await createLibp2p({
|
|
6226
6226
|
transports: [
|
|
6227
|
-
webRTC(
|
|
6228
|
-
rtcConfiguration: {
|
|
6229
|
-
iceServers: [
|
|
6230
|
-
// Google public STUN servers for NAT traversal
|
|
6231
|
-
{ urls: "stun:stun.l.google.com:19302" },
|
|
6232
|
-
{ urls: "stun:stun1.l.google.com:19302" },
|
|
6233
|
-
// Mozilla public STUN server
|
|
6234
|
-
{ urls: "stun:stun.services.mozilla.com" }
|
|
6235
|
-
]
|
|
6236
|
-
}
|
|
6237
|
-
}),
|
|
6227
|
+
webRTC(),
|
|
6238
6228
|
webSockets(),
|
|
6239
6229
|
circuitRelayTransport()
|
|
6240
6230
|
],
|
|
@@ -6544,77 +6534,43 @@ Nonce: ${nonce}`;
|
|
|
6544
6534
|
console.warn("[ByteCave] Failed to create authorization:", err.message);
|
|
6545
6535
|
}
|
|
6546
6536
|
}
|
|
6547
|
-
if (this.
|
|
6548
|
-
|
|
6549
|
-
const allPeers = this.node.getPeers();
|
|
6550
|
-
const connectedPeerIds = allPeers.map((p) => p.toString());
|
|
6551
|
-
console.log("[ByteCave] Store - connected storage peers:", connectedPeerIds.length);
|
|
6552
|
-
if (connectedPeerIds.length > 0) {
|
|
6553
|
-
const registeredPeerIds = Array.from(this.knownPeers.values()).filter((p) => p.isRegistered && connectedPeerIds.includes(p.peerId)).map((p) => p.peerId);
|
|
6554
|
-
const storagePeerIds = registeredPeerIds.length > 0 ? [...registeredPeerIds, ...connectedPeerIds.filter((id) => !registeredPeerIds.includes(id))] : connectedPeerIds;
|
|
6555
|
-
for (const peerId of storagePeerIds) {
|
|
6556
|
-
console.log("[ByteCave] Attempting P2P store to peer:", peerId.slice(0, 12) + "...");
|
|
6557
|
-
try {
|
|
6558
|
-
const result = await p2pProtocolClient.storeToPeer(
|
|
6559
|
-
peerId,
|
|
6560
|
-
dataArray,
|
|
6561
|
-
mimeType || "application/octet-stream",
|
|
6562
|
-
authorization,
|
|
6563
|
-
false,
|
|
6564
|
-
// shouldVerifyOnChain - false for browser test storage
|
|
6565
|
-
hashIdToken
|
|
6566
|
-
);
|
|
6567
|
-
if (result.success && result.cid) {
|
|
6568
|
-
console.log("[ByteCave] \u2713 P2P store successful:", result.cid);
|
|
6569
|
-
return {
|
|
6570
|
-
success: true,
|
|
6571
|
-
cid: result.cid,
|
|
6572
|
-
peerId
|
|
6573
|
-
};
|
|
6574
|
-
}
|
|
6575
|
-
console.warn("[ByteCave] \u2717 P2P store failed:", result.error);
|
|
6576
|
-
} catch (err) {
|
|
6577
|
-
console.error("[ByteCave] \u2717 P2P store exception:", err.message);
|
|
6578
|
-
}
|
|
6579
|
-
}
|
|
6580
|
-
}
|
|
6581
|
-
console.log("[ByteCave] P2P storage failed or no peers available, falling back to WebSocket relay");
|
|
6537
|
+
if (!this.config.relayWsUrl) {
|
|
6538
|
+
return { success: false, error: "WebSocket relay URL not configured" };
|
|
6582
6539
|
}
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
6588
|
-
}
|
|
6589
|
-
const wsAuth = authorization ? {
|
|
6590
|
-
signature: authorization.signature,
|
|
6591
|
-
address: authorization.sender,
|
|
6592
|
-
timestamp: authorization.timestamp,
|
|
6593
|
-
nonce: authorization.nonce,
|
|
6594
|
-
appId: authorization.appId,
|
|
6595
|
-
contentHash: authorization.contentHash
|
|
6596
|
-
} : void 0;
|
|
6597
|
-
const result = await this.storageWsClient.store({
|
|
6598
|
-
data: dataArray,
|
|
6599
|
-
contentType: mimeType || "application/octet-stream",
|
|
6600
|
-
hashIdToken,
|
|
6601
|
-
authorization: wsAuth,
|
|
6602
|
-
timeout: 3e4
|
|
6603
|
-
});
|
|
6604
|
-
if (result.success && result.cid) {
|
|
6605
|
-
console.log("[ByteCave] \u2713 WebSocket storage successful (fallback):", result.cid);
|
|
6606
|
-
return {
|
|
6607
|
-
success: true,
|
|
6608
|
-
cid: result.cid,
|
|
6609
|
-
peerId: "relay-ws"
|
|
6610
|
-
};
|
|
6611
|
-
}
|
|
6612
|
-
console.warn("[ByteCave] WebSocket storage failed:", result.error);
|
|
6613
|
-
} catch (err) {
|
|
6614
|
-
console.warn("[ByteCave] WebSocket storage exception:", err.message);
|
|
6540
|
+
console.log("[ByteCave] Storing via WebSocket relay");
|
|
6541
|
+
try {
|
|
6542
|
+
if (!this.storageWsClient) {
|
|
6543
|
+
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
6615
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 };
|
|
6616
6573
|
}
|
|
6617
|
-
return { success: false, error: "All storage methods failed (P2P and WebSocket relay)" };
|
|
6618
6574
|
}
|
|
6619
6575
|
/**
|
|
6620
6576
|
* Retrieve ciphertext from a node via P2P only (no HTTP fallback)
|
package/dist/index.cjs
CHANGED
|
@@ -6277,17 +6277,7 @@ var ByteCaveClient = class {
|
|
|
6277
6277
|
console.log("[ByteCave] Bootstrap peers:", bootstrapPeers);
|
|
6278
6278
|
this.node = await (0, import_libp2p.createLibp2p)({
|
|
6279
6279
|
transports: [
|
|
6280
|
-
(0, import_webrtc.webRTC)(
|
|
6281
|
-
rtcConfiguration: {
|
|
6282
|
-
iceServers: [
|
|
6283
|
-
// Google public STUN servers for NAT traversal
|
|
6284
|
-
{ urls: "stun:stun.l.google.com:19302" },
|
|
6285
|
-
{ urls: "stun:stun1.l.google.com:19302" },
|
|
6286
|
-
// Mozilla public STUN server
|
|
6287
|
-
{ urls: "stun:stun.services.mozilla.com" }
|
|
6288
|
-
]
|
|
6289
|
-
}
|
|
6290
|
-
}),
|
|
6280
|
+
(0, import_webrtc.webRTC)(),
|
|
6291
6281
|
(0, import_websockets.webSockets)(),
|
|
6292
6282
|
(0, import_circuit_relay_v2.circuitRelayTransport)()
|
|
6293
6283
|
],
|
|
@@ -6597,77 +6587,43 @@ Nonce: ${nonce}`;
|
|
|
6597
6587
|
console.warn("[ByteCave] Failed to create authorization:", err.message);
|
|
6598
6588
|
}
|
|
6599
6589
|
}
|
|
6600
|
-
if (this.
|
|
6601
|
-
|
|
6602
|
-
const allPeers = this.node.getPeers();
|
|
6603
|
-
const connectedPeerIds = allPeers.map((p) => p.toString());
|
|
6604
|
-
console.log("[ByteCave] Store - connected storage peers:", connectedPeerIds.length);
|
|
6605
|
-
if (connectedPeerIds.length > 0) {
|
|
6606
|
-
const registeredPeerIds = Array.from(this.knownPeers.values()).filter((p) => p.isRegistered && connectedPeerIds.includes(p.peerId)).map((p) => p.peerId);
|
|
6607
|
-
const storagePeerIds = registeredPeerIds.length > 0 ? [...registeredPeerIds, ...connectedPeerIds.filter((id) => !registeredPeerIds.includes(id))] : connectedPeerIds;
|
|
6608
|
-
for (const peerId of storagePeerIds) {
|
|
6609
|
-
console.log("[ByteCave] Attempting P2P store to peer:", peerId.slice(0, 12) + "...");
|
|
6610
|
-
try {
|
|
6611
|
-
const result = await p2pProtocolClient.storeToPeer(
|
|
6612
|
-
peerId,
|
|
6613
|
-
dataArray,
|
|
6614
|
-
mimeType || "application/octet-stream",
|
|
6615
|
-
authorization,
|
|
6616
|
-
false,
|
|
6617
|
-
// shouldVerifyOnChain - false for browser test storage
|
|
6618
|
-
hashIdToken
|
|
6619
|
-
);
|
|
6620
|
-
if (result.success && result.cid) {
|
|
6621
|
-
console.log("[ByteCave] \u2713 P2P store successful:", result.cid);
|
|
6622
|
-
return {
|
|
6623
|
-
success: true,
|
|
6624
|
-
cid: result.cid,
|
|
6625
|
-
peerId
|
|
6626
|
-
};
|
|
6627
|
-
}
|
|
6628
|
-
console.warn("[ByteCave] \u2717 P2P store failed:", result.error);
|
|
6629
|
-
} catch (err) {
|
|
6630
|
-
console.error("[ByteCave] \u2717 P2P store exception:", err.message);
|
|
6631
|
-
}
|
|
6632
|
-
}
|
|
6633
|
-
}
|
|
6634
|
-
console.log("[ByteCave] P2P storage failed or no peers available, falling back to WebSocket relay");
|
|
6590
|
+
if (!this.config.relayWsUrl) {
|
|
6591
|
+
return { success: false, error: "WebSocket relay URL not configured" };
|
|
6635
6592
|
}
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
6641
|
-
}
|
|
6642
|
-
const wsAuth = authorization ? {
|
|
6643
|
-
signature: authorization.signature,
|
|
6644
|
-
address: authorization.sender,
|
|
6645
|
-
timestamp: authorization.timestamp,
|
|
6646
|
-
nonce: authorization.nonce,
|
|
6647
|
-
appId: authorization.appId,
|
|
6648
|
-
contentHash: authorization.contentHash
|
|
6649
|
-
} : void 0;
|
|
6650
|
-
const result = await this.storageWsClient.store({
|
|
6651
|
-
data: dataArray,
|
|
6652
|
-
contentType: mimeType || "application/octet-stream",
|
|
6653
|
-
hashIdToken,
|
|
6654
|
-
authorization: wsAuth,
|
|
6655
|
-
timeout: 3e4
|
|
6656
|
-
});
|
|
6657
|
-
if (result.success && result.cid) {
|
|
6658
|
-
console.log("[ByteCave] \u2713 WebSocket storage successful (fallback):", result.cid);
|
|
6659
|
-
return {
|
|
6660
|
-
success: true,
|
|
6661
|
-
cid: result.cid,
|
|
6662
|
-
peerId: "relay-ws"
|
|
6663
|
-
};
|
|
6664
|
-
}
|
|
6665
|
-
console.warn("[ByteCave] WebSocket storage failed:", result.error);
|
|
6666
|
-
} catch (err) {
|
|
6667
|
-
console.warn("[ByteCave] WebSocket storage exception:", err.message);
|
|
6593
|
+
console.log("[ByteCave] Storing via WebSocket relay");
|
|
6594
|
+
try {
|
|
6595
|
+
if (!this.storageWsClient) {
|
|
6596
|
+
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
6668
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 };
|
|
6669
6626
|
}
|
|
6670
|
-
return { success: false, error: "All storage methods failed (P2P and WebSocket relay)" };
|
|
6671
6627
|
}
|
|
6672
6628
|
/**
|
|
6673
6629
|
* Retrieve ciphertext from a node via P2P only (no HTTP fallback)
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -99,17 +99,7 @@ export class ByteCaveClient {
|
|
|
99
99
|
// Create libp2p node with WebRTC transport
|
|
100
100
|
this.node = await createLibp2p({
|
|
101
101
|
transports: [
|
|
102
|
-
webRTC(
|
|
103
|
-
rtcConfiguration: {
|
|
104
|
-
iceServers: [
|
|
105
|
-
// Google public STUN servers for NAT traversal
|
|
106
|
-
{ urls: 'stun:stun.l.google.com:19302' },
|
|
107
|
-
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
108
|
-
// Mozilla public STUN server
|
|
109
|
-
{ urls: 'stun:stun.services.mozilla.com' }
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
}) as any,
|
|
102
|
+
webRTC() as any,
|
|
113
103
|
webSockets() as any,
|
|
114
104
|
circuitRelayTransport() as any
|
|
115
105
|
],
|
|
@@ -486,99 +476,50 @@ Nonce: ${nonce}`;
|
|
|
486
476
|
}
|
|
487
477
|
}
|
|
488
478
|
|
|
489
|
-
//
|
|
490
|
-
if (this.
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const allPeers = this.node.getPeers();
|
|
494
|
-
const connectedPeerIds = allPeers.map(p => p.toString());
|
|
495
|
-
|
|
496
|
-
console.log('[ByteCave] Store - connected storage peers:', connectedPeerIds.length);
|
|
497
|
-
|
|
498
|
-
if (connectedPeerIds.length > 0) {
|
|
499
|
-
// Prioritize registered peers from knownPeers
|
|
500
|
-
const registeredPeerIds = Array.from(this.knownPeers.values())
|
|
501
|
-
.filter(p => p.isRegistered && connectedPeerIds.includes(p.peerId))
|
|
502
|
-
.map(p => p.peerId);
|
|
503
|
-
|
|
504
|
-
const storagePeerIds = registeredPeerIds.length > 0
|
|
505
|
-
? [...registeredPeerIds, ...connectedPeerIds.filter(id => !registeredPeerIds.includes(id))]
|
|
506
|
-
: connectedPeerIds;
|
|
507
|
-
|
|
508
|
-
for (const peerId of storagePeerIds) {
|
|
509
|
-
console.log('[ByteCave] Attempting P2P store to peer:', peerId.slice(0, 12) + '...');
|
|
510
|
-
|
|
511
|
-
try {
|
|
512
|
-
const result = await p2pProtocolClient.storeToPeer(
|
|
513
|
-
peerId,
|
|
514
|
-
dataArray,
|
|
515
|
-
mimeType || 'application/octet-stream',
|
|
516
|
-
authorization,
|
|
517
|
-
false, // shouldVerifyOnChain - false for browser test storage
|
|
518
|
-
hashIdToken
|
|
519
|
-
);
|
|
520
|
-
|
|
521
|
-
if (result.success && result.cid) {
|
|
522
|
-
console.log('[ByteCave] ✓ P2P store successful:', result.cid);
|
|
523
|
-
return {
|
|
524
|
-
success: true,
|
|
525
|
-
cid: result.cid,
|
|
526
|
-
peerId
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
console.warn('[ByteCave] ✗ P2P store failed:', result.error);
|
|
531
|
-
} catch (err: any) {
|
|
532
|
-
console.error('[ByteCave] ✗ P2P store exception:', err.message);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
console.log('[ByteCave] P2P storage failed or no peers available, falling back to WebSocket relay');
|
|
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' };
|
|
538
482
|
}
|
|
539
483
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
547
|
-
}
|
|
484
|
+
console.log('[ByteCave] Storing via WebSocket relay');
|
|
485
|
+
|
|
486
|
+
try {
|
|
487
|
+
if (!this.storageWsClient) {
|
|
488
|
+
this.storageWsClient = new StorageWebSocketClient(this.config.relayWsUrl);
|
|
489
|
+
}
|
|
548
490
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (result.success && result.cid) {
|
|
567
|
-
console.log('[ByteCave] ✓ WebSocket storage successful (fallback):', result.cid);
|
|
568
|
-
return {
|
|
569
|
-
success: true,
|
|
570
|
-
cid: result.cid,
|
|
571
|
-
peerId: 'relay-ws'
|
|
572
|
-
};
|
|
573
|
-
}
|
|
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
|
+
});
|
|
574
507
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
+
};
|
|
578
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 };
|
|
579
522
|
}
|
|
580
|
-
|
|
581
|
-
return { success: false, error: 'All storage methods failed (P2P and WebSocket relay)' };
|
|
582
523
|
}
|
|
583
524
|
|
|
584
525
|
/**
|