@gethashd/bytecave-browser 1.0.26 → 1.0.27

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.
@@ -5726,41 +5726,36 @@ var P2PProtocolClient = class {
5726
5726
  } catch (e) {
5727
5727
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5728
5728
  }
5729
- console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5730
- const dialStart = Date.now();
5731
- let stream;
5732
- let lastError;
5733
- for (let attempt = 1; attempt <= 3; attempt++) {
5734
- try {
5735
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5736
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5737
- const dialDuration = Date.now() - dialStart;
5738
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5739
- console.log("[ByteCave P2P] Stream details:", {
5740
- protocol: stream.protocol,
5741
- direction: stream.direction,
5742
- timeline: stream.timeline
5743
- });
5744
- break;
5745
- } catch (dialError) {
5746
- lastError = dialError;
5747
- const dialDuration = Date.now() - dialStart;
5748
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5749
- if (attempt < 3) {
5750
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5751
- await new Promise((resolve) => setTimeout(resolve, 1e3));
5752
- }
5753
- }
5729
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5730
+ if (existingConns.length === 0) {
5731
+ throw new Error("No connection to peer - cannot open protocol stream");
5754
5732
  }
5755
- if (!stream) {
5756
- const dialDuration = Date.now() - dialStart;
5757
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5758
- error: lastError.message,
5759
- code: lastError.code,
5760
- name: lastError.name,
5761
- stack: lastError.stack?.split("\n").slice(0, 3)
5733
+ const connection = existingConns[0];
5734
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5735
+ const streamStart = Date.now();
5736
+ let stream;
5737
+ try {
5738
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5739
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5740
+ const streamDuration = Date.now() - streamStart;
5741
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5742
+ console.log("[ByteCave P2P] Stream details:", {
5743
+ protocol: stream.protocol,
5744
+ direction: stream.direction,
5745
+ id: stream.id,
5746
+ timeline: stream.timeline
5747
+ });
5748
+ } catch (streamError) {
5749
+ const streamDuration = Date.now() - streamStart;
5750
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5751
+ error: streamError.message,
5752
+ code: streamError.code,
5753
+ name: streamError.name,
5754
+ connectionStatus: connection.status,
5755
+ connectionStreams: connection.streams.length,
5756
+ stack: streamError.stack?.split("\n").slice(0, 3)
5762
5757
  });
5763
- throw lastError;
5758
+ throw streamError;
5764
5759
  }
5765
5760
  const dataCopy = new Uint8Array(ciphertext);
5766
5761
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
package/dist/index.cjs CHANGED
@@ -5794,41 +5794,36 @@ var P2PProtocolClient = class {
5794
5794
  } catch (e) {
5795
5795
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5796
5796
  }
5797
- console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5798
- const dialStart = Date.now();
5799
- let stream;
5800
- let lastError;
5801
- for (let attempt = 1; attempt <= 3; attempt++) {
5802
- try {
5803
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5804
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5805
- const dialDuration = Date.now() - dialStart;
5806
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5807
- console.log("[ByteCave P2P] Stream details:", {
5808
- protocol: stream.protocol,
5809
- direction: stream.direction,
5810
- timeline: stream.timeline
5811
- });
5812
- break;
5813
- } catch (dialError) {
5814
- lastError = dialError;
5815
- const dialDuration = Date.now() - dialStart;
5816
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5817
- if (attempt < 3) {
5818
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5819
- await new Promise((resolve) => setTimeout(resolve, 1e3));
5820
- }
5821
- }
5797
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
5798
+ if (existingConns.length === 0) {
5799
+ throw new Error("No connection to peer - cannot open protocol stream");
5822
5800
  }
5823
- if (!stream) {
5824
- const dialDuration = Date.now() - dialStart;
5825
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5826
- error: lastError.message,
5827
- code: lastError.code,
5828
- name: lastError.name,
5829
- stack: lastError.stack?.split("\n").slice(0, 3)
5801
+ const connection = existingConns[0];
5802
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
5803
+ const streamStart = Date.now();
5804
+ let stream;
5805
+ try {
5806
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
5807
+ stream = await connection.newStream("/bytecave/store/1.0.0");
5808
+ const streamDuration = Date.now() - streamStart;
5809
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
5810
+ console.log("[ByteCave P2P] Stream details:", {
5811
+ protocol: stream.protocol,
5812
+ direction: stream.direction,
5813
+ id: stream.id,
5814
+ timeline: stream.timeline
5815
+ });
5816
+ } catch (streamError) {
5817
+ const streamDuration = Date.now() - streamStart;
5818
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
5819
+ error: streamError.message,
5820
+ code: streamError.code,
5821
+ name: streamError.name,
5822
+ connectionStatus: connection.status,
5823
+ connectionStreams: connection.streams.length,
5824
+ stack: streamError.stack?.split("\n").slice(0, 3)
5830
5825
  });
5831
- throw lastError;
5826
+ throw streamError;
5832
5827
  }
5833
5828
  const dataCopy = new Uint8Array(ciphertext);
5834
5829
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-XMU2N2NN.js";
16
+ } from "./chunk-AETVOZYQ.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6049,41 +6049,36 @@ var P2PProtocolClient = class {
6049
6049
  } catch (e) {
6050
6050
  console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
6051
6051
  }
6052
- console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
6053
- const dialStart = Date.now();
6054
- let stream;
6055
- let lastError;
6056
- for (let attempt = 1; attempt <= 3; attempt++) {
6057
- try {
6058
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
6059
- stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6060
- const dialDuration = Date.now() - dialStart;
6061
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
6062
- console.log("[ByteCave P2P] Stream details:", {
6063
- protocol: stream.protocol,
6064
- direction: stream.direction,
6065
- timeline: stream.timeline
6066
- });
6067
- break;
6068
- } catch (dialError) {
6069
- lastError = dialError;
6070
- const dialDuration = Date.now() - dialStart;
6071
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
6072
- if (attempt < 3) {
6073
- console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
6074
- await new Promise((resolve) => setTimeout(resolve, 1e3));
6075
- }
6076
- }
6052
+ console.log("[ByteCave P2P] Step 2: Opening protocol stream on existing connection...");
6053
+ if (existingConns.length === 0) {
6054
+ throw new Error("No connection to peer - cannot open protocol stream");
6077
6055
  }
6078
- if (!stream) {
6079
- const dialDuration = Date.now() - dialStart;
6080
- console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
6081
- error: lastError.message,
6082
- code: lastError.code,
6083
- name: lastError.name,
6084
- stack: lastError.stack?.split("\n").slice(0, 3)
6056
+ const connection = existingConns[0];
6057
+ console.log("[ByteCave P2P] Using connection:", connection.remoteAddr.toString());
6058
+ const streamStart = Date.now();
6059
+ let stream;
6060
+ try {
6061
+ console.log("[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...");
6062
+ stream = await connection.newStream("/bytecave/store/1.0.0");
6063
+ const streamDuration = Date.now() - streamStart;
6064
+ console.log("[ByteCave P2P] Step 3: Protocol stream opened in", streamDuration, "ms");
6065
+ console.log("[ByteCave P2P] Stream details:", {
6066
+ protocol: stream.protocol,
6067
+ direction: stream.direction,
6068
+ id: stream.id,
6069
+ timeline: stream.timeline
6070
+ });
6071
+ } catch (streamError) {
6072
+ const streamDuration = Date.now() - streamStart;
6073
+ console.error("[ByteCave P2P] Failed to open protocol stream after", streamDuration, "ms:", {
6074
+ error: streamError.message,
6075
+ code: streamError.code,
6076
+ name: streamError.name,
6077
+ connectionStatus: connection.status,
6078
+ connectionStreams: connection.streams.length,
6079
+ stack: streamError.stack?.split("\n").slice(0, 3)
6085
6080
  });
6086
- throw lastError;
6081
+ throw streamError;
6087
6082
  }
6088
6083
  const dataCopy = new Uint8Array(ciphertext);
6089
6084
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-XMU2N2NN.js";
11
+ } from "../chunk-AETVOZYQ.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.26",
3
+ "version": "1.0.27",
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",
@@ -148,46 +148,41 @@ export class P2PProtocolClient {
148
148
  console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
149
149
  }
150
150
 
151
- // Step 2: Dial store protocol with retry (node may need time to register handlers after startup)
152
- console.log('[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...');
153
- const dialStart = Date.now();
154
- let stream;
155
- let lastError;
151
+ // Step 2: Open protocol stream on existing connection (relay circuits require explicit stream creation)
152
+ console.log('[ByteCave P2P] Step 2: Opening protocol stream on existing connection...');
156
153
 
157
- // Retry up to 3 times with 1s delay - gives node time to register protocol handlers
158
- for (let attempt = 1; attempt <= 3; attempt++) {
159
- try {
160
- console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
161
- stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
162
- const dialDuration = Date.now() - dialStart;
163
- console.log('[ByteCave P2P] Step 3: Stream established in', dialDuration, 'ms');
164
- console.log('[ByteCave P2P] Stream details:', {
165
- protocol: stream.protocol,
166
- direction: stream.direction,
167
- timeline: stream.timeline
168
- });
169
- break; // Success!
170
- } catch (dialError: any) {
171
- lastError = dialError;
172
- const dialDuration = Date.now() - dialStart;
173
- console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
174
-
175
- if (attempt < 3) {
176
- console.log('[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...');
177
- await new Promise(resolve => setTimeout(resolve, 1000));
178
- }
179
- }
154
+ if (existingConns.length === 0) {
155
+ throw new Error('No connection to peer - cannot open protocol stream');
180
156
  }
181
157
 
182
- if (!stream) {
183
- const dialDuration = Date.now() - dialStart;
184
- console.error('[ByteCave P2P] All dial attempts FAILED after', dialDuration, 'ms:', {
185
- error: lastError.message,
186
- code: lastError.code,
187
- name: lastError.name,
188
- stack: lastError.stack?.split('\n').slice(0, 3)
158
+ const connection = existingConns[0]; // Use first available connection
159
+ console.log('[ByteCave P2P] Using connection:', connection.remoteAddr.toString());
160
+
161
+ const streamStart = Date.now();
162
+ let stream;
163
+ try {
164
+ // Open a new stream on the existing connection with the protocol
165
+ console.log('[ByteCave P2P] Calling connection.newStream with protocol /bytecave/store/1.0.0...');
166
+ stream = await connection.newStream('/bytecave/store/1.0.0');
167
+ const streamDuration = Date.now() - streamStart;
168
+ console.log('[ByteCave P2P] Step 3: Protocol stream opened in', streamDuration, 'ms');
169
+ console.log('[ByteCave P2P] Stream details:', {
170
+ protocol: stream.protocol,
171
+ direction: stream.direction,
172
+ id: stream.id,
173
+ timeline: stream.timeline
174
+ });
175
+ } catch (streamError: any) {
176
+ const streamDuration = Date.now() - streamStart;
177
+ console.error('[ByteCave P2P] Failed to open protocol stream after', streamDuration, 'ms:', {
178
+ error: streamError.message,
179
+ code: streamError.code,
180
+ name: streamError.name,
181
+ connectionStatus: connection.status,
182
+ connectionStreams: connection.streams.length,
183
+ stack: streamError.stack?.split('\n').slice(0, 3)
189
184
  });
190
- throw lastError;
185
+ throw streamError;
191
186
  }
192
187
 
193
188
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)