@gethashd/bytecave-browser 1.0.24 → 1.0.25

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.
@@ -5718,31 +5718,45 @@ var P2PProtocolClient = class {
5718
5718
  });
5719
5719
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5720
5720
  const dialStart = Date.now();
5721
- try {
5722
- const stream2 = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5723
- const dialDuration = Date.now() - dialStart;
5724
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5725
- console.log("[ByteCave P2P] Stream details:", {
5726
- protocol: stream2.protocol,
5727
- direction: stream2.direction,
5728
- timeline: stream2.timeline
5729
- });
5730
- } catch (dialError) {
5721
+ let stream;
5722
+ let lastError;
5723
+ for (let attempt = 1; attempt <= 3; attempt++) {
5724
+ try {
5725
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5726
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5727
+ const dialDuration = Date.now() - dialStart;
5728
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5729
+ console.log("[ByteCave P2P] Stream details:", {
5730
+ protocol: stream.protocol,
5731
+ direction: stream.direction,
5732
+ timeline: stream.timeline
5733
+ });
5734
+ break;
5735
+ } catch (dialError) {
5736
+ lastError = dialError;
5737
+ const dialDuration = Date.now() - dialStart;
5738
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5739
+ if (attempt < 3) {
5740
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5741
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
5742
+ }
5743
+ }
5744
+ }
5745
+ if (!stream) {
5731
5746
  const dialDuration = Date.now() - dialStart;
5732
- console.error("[ByteCave P2P] dialProtocol FAILED after", dialDuration, "ms:", {
5733
- error: dialError.message,
5734
- code: dialError.code,
5735
- name: dialError.name,
5736
- stack: dialError.stack?.split("\n").slice(0, 3)
5747
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5748
+ error: lastError.message,
5749
+ code: lastError.code,
5750
+ name: lastError.name,
5751
+ stack: lastError.stack?.split("\n").slice(0, 3)
5737
5752
  });
5738
- throw dialError;
5753
+ throw lastError;
5739
5754
  }
5740
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5741
5755
  const dataCopy = new Uint8Array(ciphertext);
5742
5756
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5743
5757
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5744
5758
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
5745
- console.log("[ByteCave P2P] Step 4: CID generated:", cid.slice(0, 16) + "...");
5759
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5746
5760
  const request = {
5747
5761
  cid,
5748
5762
  mimeType,
@@ -5753,18 +5767,18 @@ var P2PProtocolClient = class {
5753
5767
  timestamp: authorization?.timestamp || Date.now(),
5754
5768
  authorization
5755
5769
  };
5756
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
5757
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
5770
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5771
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5758
5772
  const writeStart = Date.now();
5759
5773
  await this.writeMessage(stream, request);
5760
5774
  const writeDuration = Date.now() - writeStart;
5761
5775
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5762
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
5776
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5763
5777
  const readStart = Date.now();
5764
5778
  const response = await this.readMessage(stream);
5765
5779
  const readDuration = Date.now() - readStart;
5766
5780
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5767
- console.log("[ByteCave P2P] Step 7: Closing stream...");
5781
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5768
5782
  await stream.close();
5769
5783
  console.log("[ByteCave P2P] Stream closed successfully");
5770
5784
  if (response?.success) {
package/dist/index.cjs CHANGED
@@ -5786,31 +5786,45 @@ var P2PProtocolClient = class {
5786
5786
  });
5787
5787
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5788
5788
  const dialStart = Date.now();
5789
- try {
5790
- const stream2 = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5791
- const dialDuration = Date.now() - dialStart;
5792
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5793
- console.log("[ByteCave P2P] Stream details:", {
5794
- protocol: stream2.protocol,
5795
- direction: stream2.direction,
5796
- timeline: stream2.timeline
5797
- });
5798
- } catch (dialError) {
5789
+ let stream;
5790
+ let lastError;
5791
+ for (let attempt = 1; attempt <= 3; attempt++) {
5792
+ try {
5793
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
5794
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5795
+ const dialDuration = Date.now() - dialStart;
5796
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
5797
+ console.log("[ByteCave P2P] Stream details:", {
5798
+ protocol: stream.protocol,
5799
+ direction: stream.direction,
5800
+ timeline: stream.timeline
5801
+ });
5802
+ break;
5803
+ } catch (dialError) {
5804
+ lastError = dialError;
5805
+ const dialDuration = Date.now() - dialStart;
5806
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
5807
+ if (attempt < 3) {
5808
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
5809
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
5810
+ }
5811
+ }
5812
+ }
5813
+ if (!stream) {
5799
5814
  const dialDuration = Date.now() - dialStart;
5800
- console.error("[ByteCave P2P] dialProtocol FAILED after", dialDuration, "ms:", {
5801
- error: dialError.message,
5802
- code: dialError.code,
5803
- name: dialError.name,
5804
- stack: dialError.stack?.split("\n").slice(0, 3)
5815
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
5816
+ error: lastError.message,
5817
+ code: lastError.code,
5818
+ name: lastError.name,
5819
+ stack: lastError.stack?.split("\n").slice(0, 3)
5805
5820
  });
5806
- throw dialError;
5821
+ throw lastError;
5807
5822
  }
5808
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5809
5823
  const dataCopy = new Uint8Array(ciphertext);
5810
5824
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5811
5825
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5812
5826
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
5813
- console.log("[ByteCave P2P] Step 4: CID generated:", cid.slice(0, 16) + "...");
5827
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5814
5828
  const request = {
5815
5829
  cid,
5816
5830
  mimeType,
@@ -5821,18 +5835,18 @@ var P2PProtocolClient = class {
5821
5835
  timestamp: authorization?.timestamp || Date.now(),
5822
5836
  authorization
5823
5837
  };
5824
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
5825
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
5838
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5839
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5826
5840
  const writeStart = Date.now();
5827
5841
  await this.writeMessage(stream, request);
5828
5842
  const writeDuration = Date.now() - writeStart;
5829
5843
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5830
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
5844
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5831
5845
  const readStart = Date.now();
5832
5846
  const response = await this.readMessage(stream);
5833
5847
  const readDuration = Date.now() - readStart;
5834
5848
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5835
- console.log("[ByteCave P2P] Step 7: Closing stream...");
5849
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5836
5850
  await stream.close();
5837
5851
  console.log("[ByteCave P2P] Stream closed successfully");
5838
5852
  if (response?.success) {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  useHashdImage,
14
14
  useHashdMedia,
15
15
  useHashdUrl
16
- } from "./chunk-TT75S7TA.js";
16
+ } from "./chunk-MVXA47HN.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6041,31 +6041,45 @@ var P2PProtocolClient = class {
6041
6041
  });
6042
6042
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
6043
6043
  const dialStart = Date.now();
6044
- try {
6045
- const stream2 = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6046
- const dialDuration = Date.now() - dialStart;
6047
- console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
6048
- console.log("[ByteCave P2P] Stream details:", {
6049
- protocol: stream2.protocol,
6050
- direction: stream2.direction,
6051
- timeline: stream2.timeline
6052
- });
6053
- } catch (dialError) {
6044
+ let stream;
6045
+ let lastError;
6046
+ for (let attempt = 1; attempt <= 3; attempt++) {
6047
+ try {
6048
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
6049
+ stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6050
+ const dialDuration = Date.now() - dialStart;
6051
+ console.log("[ByteCave P2P] Step 3: Stream established in", dialDuration, "ms");
6052
+ console.log("[ByteCave P2P] Stream details:", {
6053
+ protocol: stream.protocol,
6054
+ direction: stream.direction,
6055
+ timeline: stream.timeline
6056
+ });
6057
+ break;
6058
+ } catch (dialError) {
6059
+ lastError = dialError;
6060
+ const dialDuration = Date.now() - dialStart;
6061
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
6062
+ if (attempt < 3) {
6063
+ console.log("[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...");
6064
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
6065
+ }
6066
+ }
6067
+ }
6068
+ if (!stream) {
6054
6069
  const dialDuration = Date.now() - dialStart;
6055
- console.error("[ByteCave P2P] dialProtocol FAILED after", dialDuration, "ms:", {
6056
- error: dialError.message,
6057
- code: dialError.code,
6058
- name: dialError.name,
6059
- stack: dialError.stack?.split("\n").slice(0, 3)
6070
+ console.error("[ByteCave P2P] All dial attempts FAILED after", dialDuration, "ms:", {
6071
+ error: lastError.message,
6072
+ code: lastError.code,
6073
+ name: lastError.name,
6074
+ stack: lastError.stack?.split("\n").slice(0, 3)
6060
6075
  });
6061
- throw dialError;
6076
+ throw lastError;
6062
6077
  }
6063
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6064
6078
  const dataCopy = new Uint8Array(ciphertext);
6065
6079
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
6066
6080
  const hashArray = Array.from(new Uint8Array(hashBuffer));
6067
6081
  const cid = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
6068
- console.log("[ByteCave P2P] Step 4: CID generated:", cid.slice(0, 16) + "...");
6082
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
6069
6083
  const request = {
6070
6084
  cid,
6071
6085
  mimeType,
@@ -6076,18 +6090,18 @@ var P2PProtocolClient = class {
6076
6090
  timestamp: authorization?.timestamp || Date.now(),
6077
6091
  authorization
6078
6092
  };
6079
- console.log("[ByteCave P2P] Step 4: Request prepared, size:", JSON.stringify(request).length, "bytes");
6080
- console.log("[ByteCave P2P] Step 5: Writing message to stream...");
6093
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
6094
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
6081
6095
  const writeStart = Date.now();
6082
6096
  await this.writeMessage(stream, request);
6083
6097
  const writeDuration = Date.now() - writeStart;
6084
6098
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
6085
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
6099
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
6086
6100
  const readStart = Date.now();
6087
6101
  const response = await this.readMessage(stream);
6088
6102
  const readDuration = Date.now() - readStart;
6089
6103
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
6090
- console.log("[ByteCave P2P] Step 7: Closing stream...");
6104
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
6091
6105
  await stream.close();
6092
6106
  console.log("[ByteCave P2P] Stream closed successfully");
6093
6107
  if (response?.success) {
@@ -8,7 +8,7 @@ import {
8
8
  useHashdImage,
9
9
  useHashdMedia,
10
10
  useHashdUrl
11
- } from "../chunk-TT75S7TA.js";
11
+ } from "../chunk-MVXA47HN.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.24",
3
+ "version": "1.0.25",
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",
@@ -136,35 +136,54 @@ export class P2PProtocolClient {
136
136
  });
137
137
  });
138
138
 
139
+ // Step 2: Dial store protocol with retry (node may need time to register handlers after startup)
139
140
  console.log('[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...');
140
141
  const dialStart = Date.now();
141
- try {
142
- const stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
143
- const dialDuration = Date.now() - dialStart;
144
- console.log('[ByteCave P2P] Step 3: Stream established in', dialDuration, 'ms');
145
- console.log('[ByteCave P2P] Stream details:', {
146
- protocol: stream.protocol,
147
- direction: stream.direction,
148
- timeline: stream.timeline
149
- });
150
- } catch (dialError: any) {
142
+ let stream;
143
+ let lastError;
144
+
145
+ // Retry up to 3 times with 1s delay - gives node time to register protocol handlers
146
+ for (let attempt = 1; attempt <= 3; attempt++) {
147
+ try {
148
+ console.log(`[ByteCave P2P] Dial attempt ${attempt}/3...`);
149
+ stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
150
+ const dialDuration = Date.now() - dialStart;
151
+ console.log('[ByteCave P2P] Step 3: Stream established in', dialDuration, 'ms');
152
+ console.log('[ByteCave P2P] Stream details:', {
153
+ protocol: stream.protocol,
154
+ direction: stream.direction,
155
+ timeline: stream.timeline
156
+ });
157
+ break; // Success!
158
+ } catch (dialError: any) {
159
+ lastError = dialError;
160
+ const dialDuration = Date.now() - dialStart;
161
+ console.warn(`[ByteCave P2P] Dial attempt ${attempt} failed after ${dialDuration}ms:`, dialError.message);
162
+
163
+ if (attempt < 3) {
164
+ console.log('[ByteCave P2P] Waiting 1s before retry (node may still be registering handlers)...');
165
+ await new Promise(resolve => setTimeout(resolve, 1000));
166
+ }
167
+ }
168
+ }
169
+
170
+ if (!stream) {
151
171
  const dialDuration = Date.now() - dialStart;
152
- console.error('[ByteCave P2P] dialProtocol FAILED after', dialDuration, 'ms:', {
153
- error: dialError.message,
154
- code: dialError.code,
155
- name: dialError.name,
156
- stack: dialError.stack?.split('\n').slice(0, 3)
172
+ console.error('[ByteCave P2P] All dial attempts FAILED after', dialDuration, 'ms:', {
173
+ error: lastError.message,
174
+ code: lastError.code,
175
+ name: lastError.name,
176
+ stack: lastError.stack?.split('\n').slice(0, 3)
157
177
  });
158
- throw dialError;
178
+ throw lastError;
159
179
  }
160
- const stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
161
180
 
162
181
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)
163
182
  const dataCopy = new Uint8Array(ciphertext);
164
183
  const hashBuffer = await crypto.subtle.digest('SHA-256', dataCopy);
165
184
  const hashArray = Array.from(new Uint8Array(hashBuffer));
166
185
  const cid = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
167
- console.log('[ByteCave P2P] Step 4: CID generated:', cid.slice(0, 16) + '...');
186
+ console.log('[ByteCave P2P] Step 5: CID generated:', cid.slice(0, 16) + '...');
168
187
 
169
188
  const request: StoreRequest = {
170
189
  cid,
@@ -176,21 +195,21 @@ export class P2PProtocolClient {
176
195
  timestamp: authorization?.timestamp || Date.now(),
177
196
  authorization
178
197
  };
179
- console.log('[ByteCave P2P] Step 4: Request prepared, size:', JSON.stringify(request).length, 'bytes');
198
+ console.log('[ByteCave P2P] Step 5: Request prepared, size:', JSON.stringify(request).length, 'bytes');
180
199
 
181
- console.log('[ByteCave P2P] Step 5: Writing message to stream...');
200
+ console.log('[ByteCave P2P] Step 6: Writing message to stream...');
182
201
  const writeStart = Date.now();
183
202
  await this.writeMessage(stream, request);
184
203
  const writeDuration = Date.now() - writeStart;
185
204
  console.log('[ByteCave P2P] Request written in', writeDuration, 'ms');
186
205
 
187
- console.log('[ByteCave P2P] Step 6: Waiting for response from node...');
206
+ console.log('[ByteCave P2P] Step 7: Waiting for response from node...');
188
207
  const readStart = Date.now();
189
208
  const response = await this.readMessage<StoreResponse>(stream);
190
209
  const readDuration = Date.now() - readStart;
191
210
  console.log('[ByteCave P2P] Response received in', readDuration, 'ms:', response);
192
211
 
193
- console.log('[ByteCave P2P] Step 7: Closing stream...');
212
+ console.log('[ByteCave P2P] Step 8: Closing stream...');
194
213
  await stream.close();
195
214
  console.log('[ByteCave P2P] Stream closed successfully');
196
215