@gethashd/bytecave-browser 1.0.1
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/AGENTS.md +176 -0
- package/README.md +699 -0
- package/dist/__tests__/p2p-protocols.test.d.ts +10 -0
- package/dist/chunk-EEZWRIUI.js +160 -0
- package/dist/chunk-OJEETLZQ.js +7087 -0
- package/dist/client.d.ts +107 -0
- package/dist/contracts/ContentRegistry.d.ts +1 -0
- package/dist/discovery.d.ts +28 -0
- package/dist/index.cjs +7291 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +50 -0
- package/dist/p2p-protocols.d.ts +114 -0
- package/dist/protocol-handler.cjs +185 -0
- package/dist/protocol-handler.d.ts +57 -0
- package/dist/protocol-handler.js +18 -0
- package/dist/provider.d.ts +59 -0
- package/dist/react/components.d.ts +90 -0
- package/dist/react/hooks.d.ts +67 -0
- package/dist/react/index.cjs +6344 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +23 -0
- package/dist/react/useHashdUrl.d.ts +15 -0
- package/dist/types.d.ts +53 -0
- package/package.json +77 -0
- package/src/__tests__/p2p-protocols.test.ts +292 -0
- package/src/client.ts +876 -0
- package/src/contracts/ContentRegistry.ts +6 -0
- package/src/discovery.ts +79 -0
- package/src/index.ts +59 -0
- package/src/p2p-protocols.ts +451 -0
- package/src/protocol-handler.ts +271 -0
- package/src/provider.tsx +275 -0
- package/src/react/components.tsx +177 -0
- package/src/react/hooks.ts +253 -0
- package/src/react/index.ts +9 -0
- package/src/react/useHashdUrl.ts +68 -0
- package/src/types.ts +60 -0
- package/tsconfig.json +19 -0
- package/tsup.config.ts +17 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ByteCave Browser Client
|
|
3
|
+
*
|
|
4
|
+
* WebRTC P2P client for connecting browsers directly to ByteCave storage nodes.
|
|
5
|
+
*/
|
|
6
|
+
import { ethers } from 'ethers';
|
|
7
|
+
import type { ByteCaveConfig, PeerInfo, StoreResult, RetrieveResult, ConnectionState, SignalingMessage } from './types.js';
|
|
8
|
+
export declare class ByteCaveClient {
|
|
9
|
+
private node;
|
|
10
|
+
private discovery?;
|
|
11
|
+
private config;
|
|
12
|
+
private knownPeers;
|
|
13
|
+
private connectionState;
|
|
14
|
+
private eventListeners;
|
|
15
|
+
constructor(config: ByteCaveConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Initialize and start the P2P client
|
|
18
|
+
*/
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Stop the P2P client
|
|
22
|
+
*/
|
|
23
|
+
stop(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Refresh peer directory from relay
|
|
26
|
+
* This rediscovers nodes that may have reconnected or restarted
|
|
27
|
+
*/
|
|
28
|
+
refreshPeerDirectory(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Store data on the network
|
|
31
|
+
* Uses getPeers() directly for fast peer access
|
|
32
|
+
*
|
|
33
|
+
* @param data - Data to store
|
|
34
|
+
* @param mimeType - MIME type (optional, defaults to 'application/octet-stream')
|
|
35
|
+
* @param signer - Ethers signer for authorization (optional, but required for most nodes)
|
|
36
|
+
*/
|
|
37
|
+
store(data: Uint8Array | ArrayBuffer, mimeType?: string, signer?: any): Promise<StoreResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve ciphertext from a node via P2P only (no HTTP fallback)
|
|
40
|
+
*/
|
|
41
|
+
retrieve(cid: string): Promise<RetrieveResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Register content in ContentRegistry contract (on-chain)
|
|
44
|
+
* This must be called before storing content that requires on-chain verification
|
|
45
|
+
*/
|
|
46
|
+
registerContent(cid: string, appId: string, signer: ethers.Signer): Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
txHash?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Check if content is registered in ContentRegistry
|
|
53
|
+
*/
|
|
54
|
+
isContentRegistered(cid: string): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Get list of known peers (includes both announced peers and connected libp2p peers)
|
|
57
|
+
*/
|
|
58
|
+
getPeers(): Promise<PeerInfo[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Get count of connected peers
|
|
61
|
+
*/
|
|
62
|
+
getConnectedPeerCount(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Get node info from a peer via P2P stream (for registration)
|
|
65
|
+
*/
|
|
66
|
+
getNodeInfo(peerId: string): Promise<{
|
|
67
|
+
publicKey: string;
|
|
68
|
+
ownerAddress?: string;
|
|
69
|
+
peerId: string;
|
|
70
|
+
} | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Get health info from a peer via P2P stream
|
|
73
|
+
*/
|
|
74
|
+
getNodeHealth(peerId: string): Promise<{
|
|
75
|
+
status: string;
|
|
76
|
+
blobCount: number;
|
|
77
|
+
storageUsed: number;
|
|
78
|
+
uptime: number;
|
|
79
|
+
} | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Get current connection state
|
|
82
|
+
*/
|
|
83
|
+
getConnectionState(): ConnectionState;
|
|
84
|
+
/**
|
|
85
|
+
* Subscribe to events
|
|
86
|
+
*/
|
|
87
|
+
on(event: string, callback: Function): void;
|
|
88
|
+
/**
|
|
89
|
+
* Unsubscribe from events
|
|
90
|
+
*/
|
|
91
|
+
off(event: string, callback: Function): void;
|
|
92
|
+
private emit;
|
|
93
|
+
private setConnectionState;
|
|
94
|
+
private setupEventListeners;
|
|
95
|
+
private setupPubsub;
|
|
96
|
+
private handlePeerAnnouncement;
|
|
97
|
+
/**
|
|
98
|
+
* Check if a nodeId is registered in the on-chain registry
|
|
99
|
+
*/
|
|
100
|
+
private checkNodeRegistration;
|
|
101
|
+
private handleSignalingMessage;
|
|
102
|
+
/**
|
|
103
|
+
* Send signaling message to a peer for WebRTC negotiation
|
|
104
|
+
*/
|
|
105
|
+
sendSignalingMessage(targetPeerId: string, signal: Omit<SignalingMessage, 'from'>): Promise<void>;
|
|
106
|
+
private findPeerForContentType;
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONTENT_REGISTRY_ABI: readonly ["function registerContent(bytes32 cid, address owner, bytes32 appId) external", "function registerContent(string cid, string appId) external", "function isContentRegistered(bytes32 cid) external view returns (bool)", "function getContentRecord(bytes32 cid) external view returns (tuple(address owner, bytes32 appId, uint256 timestamp))"];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract-based peer discovery
|
|
3
|
+
*
|
|
4
|
+
* Reads registered nodes from the VaultNodeRegistry smart contract
|
|
5
|
+
* to bootstrap P2P connections without any central server.
|
|
6
|
+
*/
|
|
7
|
+
import type { NodeRegistryEntry } from './types.js';
|
|
8
|
+
export declare class ContractDiscovery {
|
|
9
|
+
private provider;
|
|
10
|
+
private contract;
|
|
11
|
+
constructor(vaultNodeRegistryAddress: string, rpcUrl: string);
|
|
12
|
+
/**
|
|
13
|
+
* Get all active nodes from the registry contract
|
|
14
|
+
*/
|
|
15
|
+
getActiveNodes(): Promise<NodeRegistryEntry[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Get node count from contract
|
|
18
|
+
*/
|
|
19
|
+
getNodeCount(): Promise<{
|
|
20
|
+
total: number;
|
|
21
|
+
active: number;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Derive peerId from publicKey (same algorithm as libp2p)
|
|
25
|
+
* Note: This is a simplified version - actual peerId derivation is more complex
|
|
26
|
+
*/
|
|
27
|
+
static publicKeyToPeerId(publicKey: string): string;
|
|
28
|
+
}
|