@gethashd/bytecave-browser 1.0.50 → 1.0.52
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-2FNF5T75.js → chunk-XPZKBTJA.js} +48 -30
- package/dist/index.cjs +48 -30
- package/dist/index.js +1 -1
- package/dist/react/index.js +1 -1
- package/dist/storage-webtransport.d.ts +2 -5
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/client.ts +50 -10
- package/src/storage-webtransport.ts +10 -40
- package/src/types.ts +4 -0
|
@@ -6352,37 +6352,21 @@ var StorageWebTransportClient = class {
|
|
|
6352
6352
|
}
|
|
6353
6353
|
/**
|
|
6354
6354
|
* Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
|
|
6355
|
-
* The certhash in multiaddr is
|
|
6355
|
+
* The certhash in multiaddr format is: uEi<hex-hash>
|
|
6356
|
+
* where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
|
|
6356
6357
|
*/
|
|
6357
6358
|
async certHashToSHA256(multihash) {
|
|
6358
6359
|
try {
|
|
6359
|
-
|
|
6360
|
-
const hexHash = this.base58ToHex(base58Data);
|
|
6360
|
+
let hexHash = multihash.startsWith("uEi") ? multihash.slice(3) : multihash;
|
|
6361
6361
|
const bytes = new Uint8Array(hexHash.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
6362
|
+
console.log("[WebTransport] Decoded certificate hash:", hexHash);
|
|
6363
|
+
console.log("[WebTransport] Hash bytes length:", bytes.length);
|
|
6362
6364
|
return bytes.buffer;
|
|
6363
6365
|
} catch (error) {
|
|
6364
6366
|
console.error("[WebTransport] Failed to convert cert hash:", error);
|
|
6365
|
-
|
|
6367
|
+
throw new Error("Failed to decode certificate hash");
|
|
6366
6368
|
}
|
|
6367
6369
|
}
|
|
6368
|
-
/**
|
|
6369
|
-
* Simple base58 to hex converter (simplified version)
|
|
6370
|
-
*/
|
|
6371
|
-
base58ToHex(base58) {
|
|
6372
|
-
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
6373
|
-
let num = BigInt(0);
|
|
6374
|
-
for (let i = 0; i < base58.length; i++) {
|
|
6375
|
-
const char = base58[i];
|
|
6376
|
-
const value = alphabet.indexOf(char);
|
|
6377
|
-
if (value === -1) {
|
|
6378
|
-
throw new Error(`Invalid base58 character: ${char}`);
|
|
6379
|
-
}
|
|
6380
|
-
num = num * BigInt(58) + BigInt(value);
|
|
6381
|
-
}
|
|
6382
|
-
let hex = num.toString(16);
|
|
6383
|
-
if (hex.length % 2) hex = "0" + hex;
|
|
6384
|
-
return hex;
|
|
6385
|
-
}
|
|
6386
6370
|
};
|
|
6387
6371
|
|
|
6388
6372
|
// src/contracts/ContentRegistry.ts
|
|
@@ -7014,14 +6998,48 @@ Nonce: ${nonce}`;
|
|
|
7014
6998
|
try {
|
|
7015
6999
|
const peerInfo = this.knownPeers.get(peerId);
|
|
7016
7000
|
const relayAddrs = peerInfo?.relayAddrs;
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7001
|
+
const multiaddrs = peerInfo?.multiaddrs;
|
|
7002
|
+
if (this.node) {
|
|
7003
|
+
const connections = this.node.getConnections().filter((c) => c.remotePeer.toString() === peerId);
|
|
7004
|
+
if (connections.length === 0) {
|
|
7005
|
+
console.log("[ByteCave] No existing connection to peer, attempting to dial");
|
|
7006
|
+
if (relayAddrs && relayAddrs.length > 0) {
|
|
7007
|
+
console.log("[ByteCave] Trying relay address:", relayAddrs[0].slice(0, 60));
|
|
7008
|
+
try {
|
|
7009
|
+
const ma = multiaddr(relayAddrs[0]);
|
|
7010
|
+
await this.node.dial(ma);
|
|
7011
|
+
console.log("[ByteCave] \u2713 Connected via relay");
|
|
7012
|
+
} catch (dialError) {
|
|
7013
|
+
console.warn("[ByteCave] Relay dial failed:", dialError.message);
|
|
7014
|
+
if (multiaddrs && multiaddrs.length > 0) {
|
|
7015
|
+
const wtAddr = multiaddrs.find((addr) => addr.includes("/webtransport"));
|
|
7016
|
+
if (wtAddr) {
|
|
7017
|
+
console.log("[ByteCave] Trying WebTransport address:", wtAddr.slice(0, 60));
|
|
7018
|
+
try {
|
|
7019
|
+
const ma = multiaddr(wtAddr);
|
|
7020
|
+
await this.node.dial(ma);
|
|
7021
|
+
console.log("[ByteCave] \u2713 Connected via WebTransport");
|
|
7022
|
+
} catch (wtError) {
|
|
7023
|
+
console.warn("[ByteCave] WebTransport dial failed:", wtError.message);
|
|
7024
|
+
}
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
} else if (multiaddrs && multiaddrs.length > 0) {
|
|
7029
|
+
const wtAddr = multiaddrs.find((addr) => addr.includes("/webtransport"));
|
|
7030
|
+
if (wtAddr) {
|
|
7031
|
+
console.log("[ByteCave] Trying WebTransport address (no relay):", wtAddr.slice(0, 60));
|
|
7032
|
+
try {
|
|
7033
|
+
const ma = multiaddr(wtAddr);
|
|
7034
|
+
await this.node.dial(ma);
|
|
7035
|
+
console.log("[ByteCave] \u2713 Connected via WebTransport");
|
|
7036
|
+
} catch (wtError) {
|
|
7037
|
+
console.warn("[ByteCave] WebTransport dial failed:", wtError.message);
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
}
|
|
7041
|
+
} else {
|
|
7042
|
+
console.log("[ByteCave] Already connected to peer via", connections[0].remoteAddr.toString().slice(0, 60));
|
|
7025
7043
|
}
|
|
7026
7044
|
}
|
|
7027
7045
|
const health = await p2pProtocolClient.getHealthFromPeer(peerId);
|
package/dist/index.cjs
CHANGED
|
@@ -6405,37 +6405,21 @@ var StorageWebTransportClient = class {
|
|
|
6405
6405
|
}
|
|
6406
6406
|
/**
|
|
6407
6407
|
* Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
|
|
6408
|
-
* The certhash in multiaddr is
|
|
6408
|
+
* The certhash in multiaddr format is: uEi<hex-hash>
|
|
6409
|
+
* where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
|
|
6409
6410
|
*/
|
|
6410
6411
|
async certHashToSHA256(multihash) {
|
|
6411
6412
|
try {
|
|
6412
|
-
|
|
6413
|
-
const hexHash = this.base58ToHex(base58Data);
|
|
6413
|
+
let hexHash = multihash.startsWith("uEi") ? multihash.slice(3) : multihash;
|
|
6414
6414
|
const bytes = new Uint8Array(hexHash.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
6415
|
+
console.log("[WebTransport] Decoded certificate hash:", hexHash);
|
|
6416
|
+
console.log("[WebTransport] Hash bytes length:", bytes.length);
|
|
6415
6417
|
return bytes.buffer;
|
|
6416
6418
|
} catch (error) {
|
|
6417
6419
|
console.error("[WebTransport] Failed to convert cert hash:", error);
|
|
6418
|
-
|
|
6420
|
+
throw new Error("Failed to decode certificate hash");
|
|
6419
6421
|
}
|
|
6420
6422
|
}
|
|
6421
|
-
/**
|
|
6422
|
-
* Simple base58 to hex converter (simplified version)
|
|
6423
|
-
*/
|
|
6424
|
-
base58ToHex(base58) {
|
|
6425
|
-
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
6426
|
-
let num = BigInt(0);
|
|
6427
|
-
for (let i = 0; i < base58.length; i++) {
|
|
6428
|
-
const char = base58[i];
|
|
6429
|
-
const value = alphabet.indexOf(char);
|
|
6430
|
-
if (value === -1) {
|
|
6431
|
-
throw new Error(`Invalid base58 character: ${char}`);
|
|
6432
|
-
}
|
|
6433
|
-
num = num * BigInt(58) + BigInt(value);
|
|
6434
|
-
}
|
|
6435
|
-
let hex = num.toString(16);
|
|
6436
|
-
if (hex.length % 2) hex = "0" + hex;
|
|
6437
|
-
return hex;
|
|
6438
|
-
}
|
|
6439
6423
|
};
|
|
6440
6424
|
|
|
6441
6425
|
// src/contracts/ContentRegistry.ts
|
|
@@ -7067,14 +7051,48 @@ Nonce: ${nonce}`;
|
|
|
7067
7051
|
try {
|
|
7068
7052
|
const peerInfo = this.knownPeers.get(peerId);
|
|
7069
7053
|
const relayAddrs = peerInfo?.relayAddrs;
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7054
|
+
const multiaddrs = peerInfo?.multiaddrs;
|
|
7055
|
+
if (this.node) {
|
|
7056
|
+
const connections = this.node.getConnections().filter((c) => c.remotePeer.toString() === peerId);
|
|
7057
|
+
if (connections.length === 0) {
|
|
7058
|
+
console.log("[ByteCave] No existing connection to peer, attempting to dial");
|
|
7059
|
+
if (relayAddrs && relayAddrs.length > 0) {
|
|
7060
|
+
console.log("[ByteCave] Trying relay address:", relayAddrs[0].slice(0, 60));
|
|
7061
|
+
try {
|
|
7062
|
+
const ma = (0, import_multiaddr.multiaddr)(relayAddrs[0]);
|
|
7063
|
+
await this.node.dial(ma);
|
|
7064
|
+
console.log("[ByteCave] \u2713 Connected via relay");
|
|
7065
|
+
} catch (dialError) {
|
|
7066
|
+
console.warn("[ByteCave] Relay dial failed:", dialError.message);
|
|
7067
|
+
if (multiaddrs && multiaddrs.length > 0) {
|
|
7068
|
+
const wtAddr = multiaddrs.find((addr) => addr.includes("/webtransport"));
|
|
7069
|
+
if (wtAddr) {
|
|
7070
|
+
console.log("[ByteCave] Trying WebTransport address:", wtAddr.slice(0, 60));
|
|
7071
|
+
try {
|
|
7072
|
+
const ma = (0, import_multiaddr.multiaddr)(wtAddr);
|
|
7073
|
+
await this.node.dial(ma);
|
|
7074
|
+
console.log("[ByteCave] \u2713 Connected via WebTransport");
|
|
7075
|
+
} catch (wtError) {
|
|
7076
|
+
console.warn("[ByteCave] WebTransport dial failed:", wtError.message);
|
|
7077
|
+
}
|
|
7078
|
+
}
|
|
7079
|
+
}
|
|
7080
|
+
}
|
|
7081
|
+
} else if (multiaddrs && multiaddrs.length > 0) {
|
|
7082
|
+
const wtAddr = multiaddrs.find((addr) => addr.includes("/webtransport"));
|
|
7083
|
+
if (wtAddr) {
|
|
7084
|
+
console.log("[ByteCave] Trying WebTransport address (no relay):", wtAddr.slice(0, 60));
|
|
7085
|
+
try {
|
|
7086
|
+
const ma = (0, import_multiaddr.multiaddr)(wtAddr);
|
|
7087
|
+
await this.node.dial(ma);
|
|
7088
|
+
console.log("[ByteCave] \u2713 Connected via WebTransport");
|
|
7089
|
+
} catch (wtError) {
|
|
7090
|
+
console.warn("[ByteCave] WebTransport dial failed:", wtError.message);
|
|
7091
|
+
}
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
} else {
|
|
7095
|
+
console.log("[ByteCave] Already connected to peer via", connections[0].remoteAddr.toString().slice(0, 60));
|
|
7078
7096
|
}
|
|
7079
7097
|
}
|
|
7080
7098
|
const health = await p2pProtocolClient.getHealthFromPeer(peerId);
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -40,11 +40,8 @@ export declare class StorageWebTransportClient {
|
|
|
40
40
|
private extractCertHash;
|
|
41
41
|
/**
|
|
42
42
|
* Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
|
|
43
|
-
* The certhash in multiaddr is
|
|
43
|
+
* The certhash in multiaddr format is: uEi<hex-hash>
|
|
44
|
+
* where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
|
|
44
45
|
*/
|
|
45
46
|
private certHashToSHA256;
|
|
46
|
-
/**
|
|
47
|
-
* Simple base58 to hex converter (simplified version)
|
|
48
|
-
*/
|
|
49
|
-
private base58ToHex;
|
|
50
47
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export interface PeerInfo {
|
|
|
23
23
|
nodeUrl?: string;
|
|
24
24
|
isRegistered?: boolean;
|
|
25
25
|
owner?: string;
|
|
26
|
+
multiaddrs?: string[];
|
|
27
|
+
httpEndpoint?: string;
|
|
28
|
+
relayAddrs?: string[];
|
|
29
|
+
onChainNodeId?: string;
|
|
26
30
|
}
|
|
27
31
|
export interface StoreResult {
|
|
28
32
|
success: boolean;
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -811,19 +811,59 @@ Nonce: ${nonce}`;
|
|
|
811
811
|
uptime: number;
|
|
812
812
|
} | null> {
|
|
813
813
|
try {
|
|
814
|
-
// Check if we have
|
|
814
|
+
// Check if we have addresses for this peer
|
|
815
815
|
const peerInfo = this.knownPeers.get(peerId);
|
|
816
816
|
const relayAddrs = (peerInfo as any)?.relayAddrs;
|
|
817
|
+
const multiaddrs = peerInfo?.multiaddrs;
|
|
817
818
|
|
|
818
|
-
//
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
819
|
+
// Try to dial the peer if not already connected
|
|
820
|
+
if (this.node) {
|
|
821
|
+
const connections = this.node.getConnections().filter(c => c.remotePeer.toString() === peerId);
|
|
822
|
+
|
|
823
|
+
if (connections.length === 0) {
|
|
824
|
+
console.log('[ByteCave] No existing connection to peer, attempting to dial');
|
|
825
|
+
|
|
826
|
+
// Try relay addresses first (if available)
|
|
827
|
+
if (relayAddrs && relayAddrs.length > 0) {
|
|
828
|
+
console.log('[ByteCave] Trying relay address:', relayAddrs[0].slice(0, 60));
|
|
829
|
+
try {
|
|
830
|
+
const ma = multiaddr(relayAddrs[0]);
|
|
831
|
+
await this.node.dial(ma as any);
|
|
832
|
+
console.log('[ByteCave] ✓ Connected via relay');
|
|
833
|
+
} catch (dialError: any) {
|
|
834
|
+
console.warn('[ByteCave] Relay dial failed:', dialError.message);
|
|
835
|
+
|
|
836
|
+
// Fallback to WebTransport if relay fails
|
|
837
|
+
if (multiaddrs && multiaddrs.length > 0) {
|
|
838
|
+
const wtAddr = multiaddrs.find((addr: string) => addr.includes('/webtransport'));
|
|
839
|
+
if (wtAddr) {
|
|
840
|
+
console.log('[ByteCave] Trying WebTransport address:', wtAddr.slice(0, 60));
|
|
841
|
+
try {
|
|
842
|
+
const ma = multiaddr(wtAddr);
|
|
843
|
+
await this.node.dial(ma as any);
|
|
844
|
+
console.log('[ByteCave] ✓ Connected via WebTransport');
|
|
845
|
+
} catch (wtError: any) {
|
|
846
|
+
console.warn('[ByteCave] WebTransport dial failed:', wtError.message);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
} else if (multiaddrs && multiaddrs.length > 0) {
|
|
852
|
+
// No relay addresses, try WebTransport directly
|
|
853
|
+
const wtAddr = multiaddrs.find((addr: string) => addr.includes('/webtransport'));
|
|
854
|
+
if (wtAddr) {
|
|
855
|
+
console.log('[ByteCave] Trying WebTransport address (no relay):', wtAddr.slice(0, 60));
|
|
856
|
+
try {
|
|
857
|
+
const ma = multiaddr(wtAddr);
|
|
858
|
+
await this.node.dial(ma as any);
|
|
859
|
+
console.log('[ByteCave] ✓ Connected via WebTransport');
|
|
860
|
+
} catch (wtError: any) {
|
|
861
|
+
console.warn('[ByteCave] WebTransport dial failed:', wtError.message);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
} else {
|
|
866
|
+
console.log('[ByteCave] Already connected to peer via', connections[0].remoteAddr.toString().slice(0, 60));
|
|
827
867
|
}
|
|
828
868
|
}
|
|
829
869
|
|
|
@@ -192,55 +192,25 @@ export class StorageWebTransportClient {
|
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
194
|
* Convert libp2p multihash cert hash to SHA-256 ArrayBuffer for WebTransport
|
|
195
|
-
* The certhash in multiaddr is
|
|
195
|
+
* The certhash in multiaddr format is: uEi<hex-hash>
|
|
196
|
+
* where 'u' = base32 multibase, 'Ei' = multihash prefix for SHA-256
|
|
196
197
|
*/
|
|
197
198
|
private async certHashToSHA256(multihash: string): Promise<ArrayBuffer> {
|
|
198
199
|
try {
|
|
199
|
-
//
|
|
200
|
-
//
|
|
200
|
+
// Remove 'uEi' prefix to get the raw hex hash
|
|
201
|
+
// Format: uEi733dc9ebf43a04ad3bc692f104cf6ccc228a062fcd7aa43fc370f9c3c67e3bfc
|
|
202
|
+
let hexHash = multihash.startsWith('uEi') ? multihash.slice(3) : multihash;
|
|
201
203
|
|
|
202
|
-
//
|
|
203
|
-
const base58Data = multihash.startsWith('uEi') ? multihash.slice(3) : multihash;
|
|
204
|
-
|
|
205
|
-
// Decode base58 to get the raw hash
|
|
206
|
-
// For now, we'll convert the hex fingerprint to ArrayBuffer
|
|
207
|
-
// The fingerprint format is: "73:3d:c9:eb:f4:3a:04:ad:..."
|
|
208
|
-
// We need to convert this to raw bytes
|
|
209
|
-
|
|
210
|
-
// Since we don't have the original fingerprint here, we'll decode the base58
|
|
211
|
-
// This is a simplified approach - in production, use a proper base58 decoder
|
|
212
|
-
const hexHash = this.base58ToHex(base58Data);
|
|
204
|
+
// The hash after uEi is already in hex format, just convert to bytes
|
|
213
205
|
const bytes = new Uint8Array(hexHash.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
|
|
214
206
|
|
|
207
|
+
console.log('[WebTransport] Decoded certificate hash:', hexHash);
|
|
208
|
+
console.log('[WebTransport] Hash bytes length:', bytes.length);
|
|
209
|
+
|
|
215
210
|
return bytes.buffer;
|
|
216
211
|
} catch (error) {
|
|
217
212
|
console.error('[WebTransport] Failed to convert cert hash:', error);
|
|
218
|
-
|
|
219
|
-
return new Uint8Array(32).buffer;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Simple base58 to hex converter (simplified version)
|
|
225
|
-
*/
|
|
226
|
-
private base58ToHex(base58: string): string {
|
|
227
|
-
// This is a simplified implementation
|
|
228
|
-
// In production, use a proper base58 decoding library
|
|
229
|
-
const alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
230
|
-
let num = BigInt(0);
|
|
231
|
-
|
|
232
|
-
for (let i = 0; i < base58.length; i++) {
|
|
233
|
-
const char = base58[i];
|
|
234
|
-
const value = alphabet.indexOf(char);
|
|
235
|
-
if (value === -1) {
|
|
236
|
-
throw new Error(`Invalid base58 character: ${char}`);
|
|
237
|
-
}
|
|
238
|
-
num = num * BigInt(58) + BigInt(value);
|
|
213
|
+
throw new Error('Failed to decode certificate hash');
|
|
239
214
|
}
|
|
240
|
-
|
|
241
|
-
let hex = num.toString(16);
|
|
242
|
-
if (hex.length % 2) hex = '0' + hex;
|
|
243
|
-
|
|
244
|
-
return hex;
|
|
245
215
|
}
|
|
246
216
|
}
|
package/src/types.ts
CHANGED