@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 ADDED
@@ -0,0 +1,176 @@
1
+ # ByteCave Browser - Agent Guide
2
+
3
+ ## Overview
4
+ ByteCave Browser is a browser-compatible P2P client library that enables web applications to connect directly to ByteCave storage nodes via WebRTC. It provides React hooks and a client API for decentralized storage.
5
+
6
+ ## Critical Dependencies
7
+
8
+ ### Internal Dependencies
9
+ - **bytecave-core** - Core types and utilities (NOT the full node implementation)
10
+ - Changes to bytecave-core may require rebuilding this package
11
+
12
+ ### External Dependencies
13
+ - **@libp2p/webrtc** - WebRTC transport for browser P2P
14
+ - **ethers v6** - Ethereum wallet integration for signing
15
+ - **React** - React hooks and context providers (peer dependency)
16
+
17
+ ## Build Process
18
+
19
+ ### Standard Build
20
+ ```bash
21
+ cd bytecave-browser
22
+ yarn build
23
+ ```
24
+ - Uses `tsup` for bundling
25
+ - Outputs ESM and CJS formats to `dist/`
26
+ - Generates TypeScript declarations
27
+
28
+ ### Build Output
29
+ - `dist/index.js` - ESM bundle
30
+ - `dist/index.cjs` - CommonJS bundle
31
+ - `dist/react/index.js` - React-specific exports
32
+ - `dist/*.d.ts` - TypeScript type definitions
33
+
34
+ ## **CRITICAL: Git Workflow**
35
+
36
+ ### After Making Changes
37
+ **YOU MUST FOLLOW THIS WORKFLOW:**
38
+
39
+ 1. **Build the package**
40
+ ```bash
41
+ yarn build
42
+ ```
43
+
44
+ 2. **Commit changes to git**
45
+ ```bash
46
+ git add .
47
+ git commit -m "Description of changes"
48
+ ```
49
+
50
+ 3. **Push to git**
51
+ ```bash
52
+ git push
53
+ ```
54
+
55
+ 4. **Update dependent packages**
56
+ In `web/` or `dashboard/`:
57
+ ```bash
58
+ yarn upgrade @hashd/bytecave-browser
59
+ ```
60
+
61
+ ### Why This Is Critical
62
+ - `web` and `dashboard` install bytecave-browser from **git**, not from local files
63
+ - If you don't push to git, dependent packages will use stale code
64
+ - Even after rebuilding, changes won't appear until pushed and upgraded
65
+
66
+ ### Common Mistake
67
+ ❌ **WRONG**: Build bytecave-browser → Rebuild web/dashboard → Test
68
+ - This will use OLD code because web/dashboard pull from git
69
+
70
+ ✅ **CORRECT**: Build bytecave-browser → Git commit & push → Upgrade in web/dashboard → Test
71
+ - This ensures latest code is used
72
+
73
+ ## Key Architecture Concepts
74
+
75
+ ### ByteCaveClient
76
+ Main client class for P2P storage operations:
77
+ - `store(data, contentType, signer)` - Store blob with optional authorization
78
+ - `retrieve(cid)` - Retrieve blob by CID
79
+ - Handles peer discovery via contract and floodsub announcements
80
+
81
+ ### React Integration
82
+ - `<ByteCaveProvider>` - Context provider for React apps
83
+ - `useByteCave()` - Hook to access client instance
84
+ - `appId` prop is required and should be passed from app config
85
+
86
+ ### Storage Authorization
87
+ - Uses ethers signer to create signed authorization
88
+ - Signature message format matches bytecave-core
89
+ - Includes `appId`, `contentHash`, `timestamp`, `nonce`
90
+
91
+ ### shouldVerifyOnChain Flag
92
+ - **New parameter** in `storeToPeer()` function
93
+ - Defaults to `false` for browser/test storage
94
+ - Set to `true` for content that should be verified on-chain (messages, posts)
95
+ - Passed to node in `StoreRequest`
96
+
97
+ ## Dependent Packages
98
+
99
+ ### Web App (`/web`)
100
+ - Uses bytecave-browser for vault storage
101
+ - Installs from git: `@hashd/bytecave-browser`
102
+ - After bytecave-browser changes: `yarn upgrade @hashd/bytecave-browser`
103
+
104
+ ### Dashboard (`/dashboard`)
105
+ - Uses bytecave-browser for test storage
106
+ - Installs from git: `@hashd/bytecave-browser`
107
+ - After bytecave-browser changes: `yarn upgrade @hashd/bytecave-browser`
108
+
109
+ ## Testing Workflow
110
+
111
+ ### After Code Changes
112
+ 1. Build: `yarn build`
113
+ 2. Commit and push to git
114
+ 3. In web/dashboard: `yarn upgrade @hashd/bytecave-browser`
115
+ 4. Rebuild web/dashboard: `yarn build`
116
+ 5. Hard refresh browser (Cmd+Shift+R) to clear cache
117
+ 6. Test storage functionality
118
+
119
+ ### Common Issues
120
+
121
+ #### Stale Code in Web/Dashboard
122
+ **Symptom**: Changes to bytecave-browser don't appear in web/dashboard
123
+ **Solution**:
124
+ 1. Verify bytecave-browser was pushed to git
125
+ 2. Run `yarn upgrade @hashd/bytecave-browser` in web/dashboard
126
+ 3. Check `node_modules/@hashd/bytecave-browser/package.json` version/commit
127
+ 4. Hard refresh browser
128
+
129
+ #### Type Errors After Changes
130
+ **Symptom**: TypeScript errors in web/dashboard after bytecave-browser changes
131
+ **Solution**:
132
+ 1. Ensure bytecave-browser built successfully
133
+ 2. Check type definitions in `dist/*.d.ts`
134
+ 3. Upgrade in dependent packages
135
+ 4. Restart TypeScript server in IDE
136
+
137
+ ## Important Files
138
+
139
+ ### Core Client
140
+ - `src/client.ts` - Main ByteCaveClient class
141
+ - `src/p2p-protocols.ts` - P2P protocol client (storeToPeer, etc.)
142
+ - `src/discovery.ts` - Contract-based node discovery
143
+
144
+ ### React Integration
145
+ - `src/react/provider.tsx` - ByteCaveProvider component
146
+ - `src/react/hooks.ts` - useByteCave hook
147
+
148
+ ### Type Definitions
149
+ - `src/types.ts` - Core type definitions
150
+ - `src/p2p-protocols.ts` - Protocol interfaces (StoreRequest, StoreResponse)
151
+
152
+ ## Configuration
153
+
154
+ ### ByteCaveConfig
155
+ Required configuration for client:
156
+ - `contractAddress` - ByteCave registry contract
157
+ - `rpcUrl` - Ethereum RPC endpoint
158
+ - `appId` - Application identifier (e.g., "hashd")
159
+ - `directNodeAddrs` - Optional direct node addresses
160
+ - `relayPeers` - Optional relay peer addresses
161
+
162
+ ## Package Manager
163
+ - **Yarn** - Always use `yarn` not `npm`
164
+ - Lock file: `yarn.lock`
165
+
166
+ ## Build Tools
167
+ - **tsup** - Fast TypeScript bundler
168
+ - **TypeScript** - Type checking and declaration generation
169
+ - Config: `tsup.config.ts`, `tsconfig.json`
170
+
171
+ ## User Preferences
172
+ - User prefers separate components
173
+ - Avoid temporary fixes
174
+ - Fix lint errors at each step
175
+ - Use Yarn as package manager
176
+ - Always push to git after changes to this package