@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.
@@ -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
+ }