@gethashd/bytecave-browser 1.0.24 → 1.0.26

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.
@@ -5706,43 +5706,67 @@ var P2PProtocolClient = class {
5706
5706
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5707
5707
  const storePromise = (async () => {
5708
5708
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5709
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
5709
5710
  const existingConns = this.node.getConnections(peerIdObj);
5710
5711
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5711
5712
  existingConns.forEach((conn, idx) => {
5712
5713
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
5713
5714
  remoteAddr: conn.remoteAddr.toString(),
5715
+ remotePeer: conn.remotePeer.toString(),
5714
5716
  status: conn.status,
5715
5717
  direction: conn.direction,
5718
+ streams: conn.streams.length,
5716
5719
  timeline: conn.timeline
5717
5720
  });
5718
5721
  });
5722
+ const peerStore = this.node.peerStore;
5723
+ try {
5724
+ const peer = await peerStore.get(peerIdObj);
5725
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
5726
+ } catch (e) {
5727
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5728
+ }
5719
5729
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5720
5730
  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) {
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
+ }
5754
+ }
5755
+ if (!stream) {
5731
5756
  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)
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)
5737
5762
  });
5738
- throw dialError;
5763
+ throw lastError;
5739
5764
  }
5740
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5741
5765
  const dataCopy = new Uint8Array(ciphertext);
5742
5766
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5743
5767
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5744
5768
  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) + "...");
5769
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5746
5770
  const request = {
5747
5771
  cid,
5748
5772
  mimeType,
@@ -5753,18 +5777,18 @@ var P2PProtocolClient = class {
5753
5777
  timestamp: authorization?.timestamp || Date.now(),
5754
5778
  authorization
5755
5779
  };
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...");
5780
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5781
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5758
5782
  const writeStart = Date.now();
5759
5783
  await this.writeMessage(stream, request);
5760
5784
  const writeDuration = Date.now() - writeStart;
5761
5785
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5762
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
5786
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5763
5787
  const readStart = Date.now();
5764
5788
  const response = await this.readMessage(stream);
5765
5789
  const readDuration = Date.now() - readStart;
5766
5790
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5767
- console.log("[ByteCave P2P] Step 7: Closing stream...");
5791
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5768
5792
  await stream.close();
5769
5793
  console.log("[ByteCave P2P] Stream closed successfully");
5770
5794
  if (response?.success) {
package/dist/index.cjs CHANGED
@@ -5774,43 +5774,67 @@ var P2PProtocolClient = class {
5774
5774
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
5775
5775
  const storePromise = (async () => {
5776
5776
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
5777
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
5777
5778
  const existingConns = this.node.getConnections(peerIdObj);
5778
5779
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
5779
5780
  existingConns.forEach((conn, idx) => {
5780
5781
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
5781
5782
  remoteAddr: conn.remoteAddr.toString(),
5783
+ remotePeer: conn.remotePeer.toString(),
5782
5784
  status: conn.status,
5783
5785
  direction: conn.direction,
5786
+ streams: conn.streams.length,
5784
5787
  timeline: conn.timeline
5785
5788
  });
5786
5789
  });
5790
+ const peerStore = this.node.peerStore;
5791
+ try {
5792
+ const peer = await peerStore.get(peerIdObj);
5793
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
5794
+ } catch (e) {
5795
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
5796
+ }
5787
5797
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
5788
5798
  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) {
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
+ }
5822
+ }
5823
+ if (!stream) {
5799
5824
  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)
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)
5805
5830
  });
5806
- throw dialError;
5831
+ throw lastError;
5807
5832
  }
5808
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
5809
5833
  const dataCopy = new Uint8Array(ciphertext);
5810
5834
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
5811
5835
  const hashArray = Array.from(new Uint8Array(hashBuffer));
5812
5836
  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) + "...");
5837
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
5814
5838
  const request = {
5815
5839
  cid,
5816
5840
  mimeType,
@@ -5821,18 +5845,18 @@ var P2PProtocolClient = class {
5821
5845
  timestamp: authorization?.timestamp || Date.now(),
5822
5846
  authorization
5823
5847
  };
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...");
5848
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
5849
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
5826
5850
  const writeStart = Date.now();
5827
5851
  await this.writeMessage(stream, request);
5828
5852
  const writeDuration = Date.now() - writeStart;
5829
5853
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
5830
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
5854
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
5831
5855
  const readStart = Date.now();
5832
5856
  const response = await this.readMessage(stream);
5833
5857
  const readDuration = Date.now() - readStart;
5834
5858
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
5835
- console.log("[ByteCave P2P] Step 7: Closing stream...");
5859
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
5836
5860
  await stream.close();
5837
5861
  console.log("[ByteCave P2P] Stream closed successfully");
5838
5862
  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-XMU2N2NN.js";
17
17
  import {
18
18
  clearHashdCache,
19
19
  createHashdUrl,
@@ -6029,43 +6029,67 @@ var P2PProtocolClient = class {
6029
6029
  console.log(`[ByteCave P2P] Store timeout: ${Math.round(timeoutMs / 1e3)}s for ${fileSizeMB.toFixed(2)}MB`);
6030
6030
  const storePromise = (async () => {
6031
6031
  console.log("[ByteCave P2P] Step 1: Checking existing connections to peer", peerId.slice(0, 12));
6032
+ console.log("[ByteCave P2P] Full peer ID:", peerId);
6032
6033
  const existingConns = this.node.getConnections(peerIdObj);
6033
6034
  console.log("[ByteCave P2P] Existing connections:", existingConns.length);
6034
6035
  existingConns.forEach((conn, idx) => {
6035
6036
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
6036
6037
  remoteAddr: conn.remoteAddr.toString(),
6038
+ remotePeer: conn.remotePeer.toString(),
6037
6039
  status: conn.status,
6038
6040
  direction: conn.direction,
6041
+ streams: conn.streams.length,
6039
6042
  timeline: conn.timeline
6040
6043
  });
6041
6044
  });
6045
+ const peerStore = this.node.peerStore;
6046
+ try {
6047
+ const peer = await peerStore.get(peerIdObj);
6048
+ console.log("[ByteCave P2P] Peer protocols from peerStore:", peer.protocols);
6049
+ } catch (e) {
6050
+ console.warn("[ByteCave P2P] Could not get peer info from peerStore:", e);
6051
+ }
6042
6052
  console.log("[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...");
6043
6053
  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) {
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
+ }
6077
+ }
6078
+ if (!stream) {
6054
6079
  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)
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)
6060
6085
  });
6061
- throw dialError;
6086
+ throw lastError;
6062
6087
  }
6063
- const stream = await this.node.dialProtocol(peerIdObj, "/bytecave/store/1.0.0");
6064
6088
  const dataCopy = new Uint8Array(ciphertext);
6065
6089
  const hashBuffer = await crypto.subtle.digest("SHA-256", dataCopy);
6066
6090
  const hashArray = Array.from(new Uint8Array(hashBuffer));
6067
6091
  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) + "...");
6092
+ console.log("[ByteCave P2P] Step 5: CID generated:", cid.slice(0, 16) + "...");
6069
6093
  const request = {
6070
6094
  cid,
6071
6095
  mimeType,
@@ -6076,18 +6100,18 @@ var P2PProtocolClient = class {
6076
6100
  timestamp: authorization?.timestamp || Date.now(),
6077
6101
  authorization
6078
6102
  };
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...");
6103
+ console.log("[ByteCave P2P] Step 5: Request prepared, size:", JSON.stringify(request).length, "bytes");
6104
+ console.log("[ByteCave P2P] Step 6: Writing message to stream...");
6081
6105
  const writeStart = Date.now();
6082
6106
  await this.writeMessage(stream, request);
6083
6107
  const writeDuration = Date.now() - writeStart;
6084
6108
  console.log("[ByteCave P2P] Request written in", writeDuration, "ms");
6085
- console.log("[ByteCave P2P] Step 6: Waiting for response from node...");
6109
+ console.log("[ByteCave P2P] Step 7: Waiting for response from node...");
6086
6110
  const readStart = Date.now();
6087
6111
  const response = await this.readMessage(stream);
6088
6112
  const readDuration = Date.now() - readStart;
6089
6113
  console.log("[ByteCave P2P] Response received in", readDuration, "ms:", response);
6090
- console.log("[ByteCave P2P] Step 7: Closing stream...");
6114
+ console.log("[ByteCave P2P] Step 8: Closing stream...");
6091
6115
  await stream.close();
6092
6116
  console.log("[ByteCave P2P] Stream closed successfully");
6093
6117
  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-XMU2N2NN.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.26",
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",
@@ -125,46 +125,77 @@ export class P2PProtocolClient {
125
125
  // Wrap the entire operation in a timeout
126
126
  const storePromise = (async () => {
127
127
  console.log('[ByteCave P2P] Step 1: Checking existing connections to peer', peerId.slice(0, 12));
128
+ console.log('[ByteCave P2P] Full peer ID:', peerId);
128
129
  const existingConns = this.node!.getConnections(peerIdObj);
129
130
  console.log('[ByteCave P2P] Existing connections:', existingConns.length);
130
131
  existingConns.forEach((conn, idx) => {
131
132
  console.log(`[ByteCave P2P] Connection ${idx}:`, {
132
133
  remoteAddr: conn.remoteAddr.toString(),
134
+ remotePeer: conn.remotePeer.toString(),
133
135
  status: conn.status,
134
136
  direction: conn.direction,
137
+ streams: conn.streams.length,
135
138
  timeline: conn.timeline
136
139
  });
137
140
  });
138
141
 
142
+ // Check what protocols the peer supports
143
+ const peerStore = this.node!.peerStore;
144
+ try {
145
+ const peer = await peerStore.get(peerIdObj);
146
+ console.log('[ByteCave P2P] Peer protocols from peerStore:', peer.protocols);
147
+ } catch (e) {
148
+ console.warn('[ByteCave P2P] Could not get peer info from peerStore:', e);
149
+ }
150
+
151
+ // Step 2: Dial store protocol with retry (node may need time to register handlers after startup)
139
152
  console.log('[ByteCave P2P] Step 2: Dialing store protocol /bytecave/store/1.0.0...');
140
153
  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) {
154
+ let stream;
155
+ let lastError;
156
+
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
+ }
180
+ }
181
+
182
+ if (!stream) {
151
183
  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)
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)
157
189
  });
158
- throw dialError;
190
+ throw lastError;
159
191
  }
160
- const stream = await this.node!.dialProtocol(peerIdObj, '/bytecave/store/1.0.0');
161
192
 
162
193
  // Generate CID using SHA-256 (matches bytecave-core format: 64-char hex)
163
194
  const dataCopy = new Uint8Array(ciphertext);
164
195
  const hashBuffer = await crypto.subtle.digest('SHA-256', dataCopy);
165
196
  const hashArray = Array.from(new Uint8Array(hashBuffer));
166
197
  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) + '...');
198
+ console.log('[ByteCave P2P] Step 5: CID generated:', cid.slice(0, 16) + '...');
168
199
 
169
200
  const request: StoreRequest = {
170
201
  cid,
@@ -176,21 +207,21 @@ export class P2PProtocolClient {
176
207
  timestamp: authorization?.timestamp || Date.now(),
177
208
  authorization
178
209
  };
179
- console.log('[ByteCave P2P] Step 4: Request prepared, size:', JSON.stringify(request).length, 'bytes');
210
+ console.log('[ByteCave P2P] Step 5: Request prepared, size:', JSON.stringify(request).length, 'bytes');
180
211
 
181
- console.log('[ByteCave P2P] Step 5: Writing message to stream...');
212
+ console.log('[ByteCave P2P] Step 6: Writing message to stream...');
182
213
  const writeStart = Date.now();
183
214
  await this.writeMessage(stream, request);
184
215
  const writeDuration = Date.now() - writeStart;
185
216
  console.log('[ByteCave P2P] Request written in', writeDuration, 'ms');
186
217
 
187
- console.log('[ByteCave P2P] Step 6: Waiting for response from node...');
218
+ console.log('[ByteCave P2P] Step 7: Waiting for response from node...');
188
219
  const readStart = Date.now();
189
220
  const response = await this.readMessage<StoreResponse>(stream);
190
221
  const readDuration = Date.now() - readStart;
191
222
  console.log('[ByteCave P2P] Response received in', readDuration, 'ms:', response);
192
223
 
193
- console.log('[ByteCave P2P] Step 7: Closing stream...');
224
+ console.log('[ByteCave P2P] Step 8: Closing stream...');
194
225
  await stream.close();
195
226
  console.log('[ByteCave P2P] Stream closed successfully');
196
227