gun-eth 2.0.0 → 3.0.0
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/README.md +386 -18
- package/dist/gun-eth.bundle.js +6806 -0
- package/dist/gun-eth.cjs +2465 -0
- package/dist/types/browser.d.ts +6 -0
- package/dist/types/config/local.d.ts +7 -0
- package/dist/types/constants/abis.d.ts +37 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/core/gun-eth.d.ts +419 -0
- package/dist/types/features/bubbles/client/bubble-client.d.ts +184 -0
- package/dist/types/features/bubbles/providers/base-bubble-provider.d.ts +303 -0
- package/dist/types/features/bubbles/providers/gun-bubble-provider.d.ts +173 -0
- package/dist/types/features/bubbles/providers/hybrid-bubble-provider.d.ts +124 -0
- package/dist/types/features/proof/ProofChain.d.ts +225 -0
- package/dist/types/features/stealth/StealthChain.d.ts +200 -0
- package/dist/types/index.d.ts +61 -0
- package/dist/types/utils/common.d.ts +11 -0
- package/dist/types/utils/encryption.d.ts +32 -0
- package/package.json +110 -26
- package/dist/gun-eth-protocol.cjs.js +0 -11528
- package/dist/gun-eth-protocol.esm.js +0 -11503
- package/dist/gun-eth-protocol.js +0 -18
- package/dist/gun-eth-protocol.react.js +0 -11503
- package/dist/gun-eth-protocol.umd.js +0 -18
- package/jsdoc.json +0 -7
- package/rollup.config.js +0 -80
- package/src/index.js +0 -181
- package/src/lib/authentication/index.js +0 -13
- package/src/lib/authentication/isAuthenticated.js +0 -20
- package/src/lib/authentication/login.js +0 -25
- package/src/lib/authentication/register.js +0 -58
- package/src/lib/blockchain/abis/SHINE.json +0 -262
- package/src/lib/blockchain/contracts/SHINE.sol +0 -52
- package/src/lib/blockchain/ethereum.js +0 -74
- package/src/lib/blockchain/shine.js +0 -204
- package/src/lib/certificates/friendsCertificates.js +0 -92
- package/src/lib/certificates/index.js +0 -44
- package/src/lib/certificates/messagingCertificates.js +0 -94
- package/src/lib/friends/acceptFriendRequest.js +0 -69
- package/src/lib/friends/addFriendRequest.js +0 -49
- package/src/lib/friends/friendRequests.js +0 -51
- package/src/lib/friends/friendsList.js +0 -57
- package/src/lib/friends/index.js +0 -36
- package/src/lib/friends/rejectFriendRequest.js +0 -31
- package/src/lib/messaging/chatsList.js +0 -42
- package/src/lib/messaging/createChat.js +0 -132
- package/src/lib/messaging/index.js +0 -36
- package/src/lib/messaging/messageList.js +0 -106
- package/src/lib/messaging/sendMessage.js +0 -132
- package/src/lib/messaging/sendVoiceMessage.js +0 -119
- package/src/lib/notes/createNote.js +0 -41
- package/src/lib/notes/deleteNote.js +0 -12
- package/src/lib/notes/getNote.js +0 -25
- package/src/lib/notes/getUserNote.js +0 -59
- package/src/lib/notes/index.js +0 -8
- package/src/lib/notes/updateNotes.js +0 -35
- package/src/lib/post/createPost.js +0 -17
- package/src/lib/post/decryptPost.js +0 -14
- package/src/lib/post/deletePost.js +0 -13
- package/src/lib/post/encryptPost,js +0 -16
- package/src/lib/post/getPost.js +0 -36
- package/src/lib/post/index.js +0 -9
- package/src/lib/post/updatePost.js +0 -16
- package/src/state/gun.js +0 -33
- package/types/types.d.ts +0 -244
package/README.md
CHANGED
@@ -1,18 +1,386 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
# Gun-ETH 🔫
|
2
|
+
|
3
|
+
<img src="landing/assets/hero-image.webp" alt="Gun-ETH Logo" width="300">
|
4
|
+
|
5
|
+
A powerful Gun.js plugin that extends its capabilities by adding advanced blockchain and cryptographic features to create more secure and private decentralized applications.
|
6
|
+
|
7
|
+
## ✨ Why Gun-ETH?
|
8
|
+
|
9
|
+
- 🎯 **Powerful Extension**: Adds advanced blockchain and cryptographic features to Gun.js
|
10
|
+
- 🌐 **Seamless Integration**: Perfectly integrates with Gun.js while maintaining simplicity
|
11
|
+
- 🔒 **Advanced Privacy**: Implements stealth transactions, proof chain, and encrypted data
|
12
|
+
- 🚀 **Modern Architecture**: Intuitive APIs for easy Web3 functionality implementation
|
13
|
+
|
14
|
+
## 🚀 Quick Start
|
15
|
+
|
16
|
+
### Installation
|
17
|
+
|
18
|
+
```bash
|
19
|
+
npm install gun-eth
|
20
|
+
# or
|
21
|
+
yarn add gun-eth
|
22
|
+
```
|
23
|
+
|
24
|
+
### Basic Configuration
|
25
|
+
|
26
|
+
```javascript
|
27
|
+
import Gun from 'gun';
|
28
|
+
import { GunEth } from 'gun-eth';
|
29
|
+
import { ethers } from 'ethers';
|
30
|
+
|
31
|
+
// Configure Gun with peers
|
32
|
+
const gun = Gun({
|
33
|
+
peers: ['http://localhost:8765/gun']
|
34
|
+
});
|
35
|
+
|
36
|
+
// Initialize GunEth
|
37
|
+
const gunEth = await GunEth.init('localhost'); // or 'mainnet', 'sepolia', etc.
|
38
|
+
```
|
39
|
+
|
40
|
+
### Signer Configuration
|
41
|
+
|
42
|
+
Gun-ETH provides two ways to configure the signer:
|
43
|
+
|
44
|
+
1. **Manual Configuration (Recommended for Production)**
|
45
|
+
```javascript
|
46
|
+
import { setSigner, getSigner } from 'gun-eth';
|
47
|
+
|
48
|
+
// Configure with explicit RPC URL and private key
|
49
|
+
await setSigner(
|
50
|
+
"https://your-rpc-url",
|
51
|
+
"your-private-key"
|
52
|
+
);
|
53
|
+
|
54
|
+
// Get the configured signer
|
55
|
+
const signer = await getSigner();
|
56
|
+
```
|
57
|
+
|
58
|
+
2. **MetaMask Fallback (Development-Friendly)**
|
59
|
+
```javascript
|
60
|
+
import { getSigner } from 'gun-eth';
|
61
|
+
|
62
|
+
// Will automatically use MetaMask if available
|
63
|
+
try {
|
64
|
+
const signer = await getSigner();
|
65
|
+
console.log("Connected with address:", await signer.getAddress());
|
66
|
+
} catch (error) {
|
67
|
+
console.error("No valid provider found");
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
The signer selection follows these priorities:
|
72
|
+
1. Uses manually configured signer if set via `setSigner()`
|
73
|
+
2. Falls back to MetaMask if available and no manual configuration
|
74
|
+
3. Throws an error if no valid provider is found
|
75
|
+
|
76
|
+
### Error Handling
|
77
|
+
|
78
|
+
```javascript
|
79
|
+
try {
|
80
|
+
const gunEth = await GunEth.init({
|
81
|
+
gun,
|
82
|
+
chain: 'localhost'
|
83
|
+
});
|
84
|
+
} catch (error) {
|
85
|
+
console.error('Initialization error:', error);
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
## 📚 Documentation
|
90
|
+
|
91
|
+
### 🔐 Gun-Ethereum Integration
|
92
|
+
|
93
|
+
#### ETH -> GUN Conversion
|
94
|
+
```javascript
|
95
|
+
try {
|
96
|
+
// Create signature with Ethereum wallet
|
97
|
+
const signature = await GunEth.createSignature(GunEth.MESSAGE_TO_SIGN);
|
98
|
+
|
99
|
+
// Convert to Gun SEA compatible keypair
|
100
|
+
const gunKeyPair = await GunEth.ethToGunAccount(signature);
|
101
|
+
|
102
|
+
console.log('Generated Gun SEA keypair:', gunKeyPair);
|
103
|
+
// The keypair contains keys generated by Gun SEA:
|
104
|
+
// {
|
105
|
+
// pub: "SEA-public-key",
|
106
|
+
// priv: "SEA-private-key",
|
107
|
+
// epub: "SEA-encryption-public-key",
|
108
|
+
// epriv: "SEA-encryption-private-key"
|
109
|
+
// }
|
110
|
+
} catch (error) {
|
111
|
+
console.error('Conversion error:', error);
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
#### GUN -> ETH Conversion
|
116
|
+
```javascript
|
117
|
+
try {
|
118
|
+
// Requires the SEA private key generated by Gun
|
119
|
+
const ethAccount = await GunEth.gunToEthAccount(gunSEAPrivateKey);
|
120
|
+
console.log('Ethereum account:', ethAccount);
|
121
|
+
} catch (error) {
|
122
|
+
console.error('Conversion error:', error);
|
123
|
+
}
|
124
|
+
```
|
125
|
+
|
126
|
+
### 🔒 Stealth Chain
|
127
|
+
|
128
|
+
```javascript
|
129
|
+
// Initialize Gun
|
130
|
+
const gun = Gun();
|
131
|
+
await GunEth.init({ gun, chain: 'localhost' });
|
132
|
+
|
133
|
+
try {
|
134
|
+
// Publish stealth keys
|
135
|
+
const signature = await GunEth.createSignature(GunEth.MESSAGE_TO_SIGN);
|
136
|
+
await gun.publishStealthKeys(signature);
|
137
|
+
|
138
|
+
// Generate stealth address
|
139
|
+
const stealthInfo = await gun.generateStealthAddress(
|
140
|
+
recipientAddress,
|
141
|
+
signature,
|
142
|
+
{} // Additional options if needed
|
143
|
+
);
|
144
|
+
|
145
|
+
console.log('Generated stealth address:', stealthInfo);
|
146
|
+
// Returns:
|
147
|
+
// {
|
148
|
+
// stealthAddress: "0x...", // The generated stealth address
|
149
|
+
// senderPublicKey: "...", // The sender's public key
|
150
|
+
// spendingPublicKey: "..." // The recipient's spending public key
|
151
|
+
// }
|
152
|
+
|
153
|
+
// Announce the payment
|
154
|
+
await gun.announceStealthPayment(
|
155
|
+
stealthInfo.stealthAddress,
|
156
|
+
stealthInfo.senderPublicKey,
|
157
|
+
stealthInfo.spendingPublicKey,
|
158
|
+
signature,
|
159
|
+
{ onChain: true } // Optional: announce on-chain
|
160
|
+
);
|
161
|
+
} catch (error) {
|
162
|
+
console.error('Stealth operation error:', error);
|
163
|
+
}
|
164
|
+
|
165
|
+
// Monitor stealth events
|
166
|
+
gun.monitorStealthEvents((event) => {
|
167
|
+
console.log('New stealth event:', event);
|
168
|
+
});
|
169
|
+
```
|
170
|
+
|
171
|
+
### ⛓️ Proof Chain
|
172
|
+
|
173
|
+
```javascript
|
174
|
+
try {
|
175
|
+
// Write data with proof
|
176
|
+
await gun.proof('users', null, {
|
177
|
+
name: 'Alice',
|
178
|
+
age: 25
|
179
|
+
}, (ack) => {
|
180
|
+
if (ack.err) {
|
181
|
+
console.error('Write error:', ack.err);
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
console.log('Data written successfully:', {
|
185
|
+
nodeId: ack.nodeId,
|
186
|
+
txHash: ack.txHash
|
187
|
+
});
|
188
|
+
});
|
189
|
+
|
190
|
+
// Verify data integrity
|
191
|
+
await gun.proof('users', 'nodeId123', null, (ack) => {
|
192
|
+
if (ack.err) {
|
193
|
+
console.error('Verification error:', ack.err);
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
console.log('Verification completed:', ack.ok);
|
197
|
+
});
|
198
|
+
} catch (error) {
|
199
|
+
console.error('Proof operation error:', error);
|
200
|
+
}
|
201
|
+
```
|
202
|
+
|
203
|
+
### 🫧 Encrypted Bubbles
|
204
|
+
|
205
|
+
```javascript
|
206
|
+
// Initialize Bubble Client
|
207
|
+
import { BubbleClient } from 'gun-eth';
|
208
|
+
|
209
|
+
const bubbleClient = new BubbleClient({
|
210
|
+
providerUrl: "http://localhost:3000/api",
|
211
|
+
signer: signer, // Your Ethereum signer
|
212
|
+
keypair: { // Your encryption keypair
|
213
|
+
epub: "your-encryption-public-key",
|
214
|
+
epriv: "your-encryption-private-key"
|
215
|
+
}
|
216
|
+
});
|
217
|
+
|
218
|
+
// Create and manage bubbles
|
219
|
+
const bubble = await bubbleClient.createBubble("My Bubble", {
|
220
|
+
isPrivate: true
|
221
|
+
});
|
222
|
+
|
223
|
+
// Write encrypted content
|
224
|
+
await bubbleClient.writeBubble(
|
225
|
+
bubble.id,
|
226
|
+
"secret.txt",
|
227
|
+
"My secret content"
|
228
|
+
);
|
229
|
+
|
230
|
+
// Read and decrypt content
|
231
|
+
const result = await bubbleClient.readBubble(
|
232
|
+
bubble.id,
|
233
|
+
"secret.txt"
|
234
|
+
);
|
235
|
+
|
236
|
+
// Share with another user
|
237
|
+
await bubbleClient.shareBubble(
|
238
|
+
bubble.id,
|
239
|
+
recipientAddress,
|
240
|
+
{ granteeEpub: recipientPublicKey }
|
241
|
+
);
|
242
|
+
```
|
243
|
+
|
244
|
+
### 🔄 Bubble Providers
|
245
|
+
|
246
|
+
Gun-ETH offers three types of providers for managing encrypted bubbles:
|
247
|
+
|
248
|
+
#### Base Provider
|
249
|
+
```javascript
|
250
|
+
import { BaseBubbleProvider } from 'gun-eth';
|
251
|
+
|
252
|
+
class CustomProvider extends BaseBubbleProvider {
|
253
|
+
async handleCreateBubble(options) { }
|
254
|
+
async handleWriteBubble(bubbleId, fileName, content) { }
|
255
|
+
async handleReadBubble(bubbleId, fileName) { }
|
256
|
+
async handleGrantPermission(bubbleId, granteeAddress) { }
|
257
|
+
}
|
258
|
+
```
|
259
|
+
|
260
|
+
#### GUN Provider
|
261
|
+
```javascript
|
262
|
+
import { GUNBubbleProvider } from 'gun-eth';
|
263
|
+
|
264
|
+
const gunProvider = new GUNBubbleProvider({
|
265
|
+
gun: gunInstance,
|
266
|
+
signer: signer,
|
267
|
+
keypair: keypair
|
268
|
+
});
|
269
|
+
|
270
|
+
// Stores data directly in GUN's graph
|
271
|
+
await gunProvider.handleCreateBubble({
|
272
|
+
name: "GUN Bubble",
|
273
|
+
isPrivate: true
|
274
|
+
});
|
275
|
+
```
|
276
|
+
|
277
|
+
#### Hybrid Provider
|
278
|
+
```javascript
|
279
|
+
import { HybridBubbleProvider } from 'gun-eth';
|
280
|
+
|
281
|
+
const hybridProvider = new HybridBubbleProvider({
|
282
|
+
gun: gunInstance,
|
283
|
+
signer: signer,
|
284
|
+
keypair: keypair,
|
285
|
+
storage: customStorageAdapter
|
286
|
+
});
|
287
|
+
|
288
|
+
// Supports both GUN and external storage
|
289
|
+
await hybridProvider.handleCreateBubble({
|
290
|
+
name: "Hybrid Bubble",
|
291
|
+
isPrivate: true,
|
292
|
+
useExternal: true
|
293
|
+
});
|
294
|
+
```
|
295
|
+
|
296
|
+
### 📋 Templates
|
297
|
+
|
298
|
+
Gun-ETH provides ready-to-use templates for common implementations:
|
299
|
+
|
300
|
+
#### Client Template
|
301
|
+
```javascript
|
302
|
+
// template-bubble-client.js
|
303
|
+
const CONFIG = {
|
304
|
+
RPC_URL: process.env.RPC_URL,
|
305
|
+
PRIVATE_KEY: process.env.PRIVATE_KEY,
|
306
|
+
PROVIDER_URL: "http://localhost:3000/api",
|
307
|
+
GUN_PEERS: ['http://localhost:8765/gun'],
|
308
|
+
DECRYPTED_FILES_DIR: './decrypted-files'
|
309
|
+
};
|
310
|
+
|
311
|
+
// Initialize client with configuration
|
312
|
+
const client = await initializeClient();
|
313
|
+
|
314
|
+
// Example usage
|
315
|
+
const bubble = await client.createBubble("Test Bubble");
|
316
|
+
await client.writeBubble(bubble.id, "test.txt", "content");
|
317
|
+
const result = await client.readBubble(bubble.id, "test.txt");
|
318
|
+
```
|
319
|
+
|
320
|
+
#### Provider Template
|
321
|
+
```javascript
|
322
|
+
// template-bubble-provider.js
|
323
|
+
const CONFIG = {
|
324
|
+
RPC_URL: process.env.RPC_URL,
|
325
|
+
PRIVATE_KEY: process.env.PRIVATE_KEY,
|
326
|
+
GUN_PEERS: "http://localhost:8765/gun",
|
327
|
+
GUN_DIR: "radata",
|
328
|
+
BUBBLES_DIR: "bubbles"
|
329
|
+
};
|
330
|
+
|
331
|
+
// Initialize provider with configuration
|
332
|
+
const app = express();
|
333
|
+
const gun = Gun(gunOptions);
|
334
|
+
const provider = new HybridBubbleProvider(CONFIG);
|
335
|
+
|
336
|
+
// API endpoints
|
337
|
+
app.post('/bubble', handleCreateBubble);
|
338
|
+
app.post('/bubble/:id/write', handleWriteBubble);
|
339
|
+
app.get('/bubble/:id', handleReadBubble);
|
340
|
+
```
|
341
|
+
|
342
|
+
## 🏗️ Architecture
|
343
|
+
|
344
|
+
Gun-ETH is structured in independent modules:
|
345
|
+
|
346
|
+
- **Core**: Base functionality and Gun.js integration
|
347
|
+
- **Stealth**: Private transaction implementation
|
348
|
+
- **Proof**: Verification and anchoring system
|
349
|
+
- **Crypto**: Cryptographic utilities
|
350
|
+
- **Utils**: Common support functions
|
351
|
+
|
352
|
+
## 🌟 Features
|
353
|
+
|
354
|
+
### Secure Backup System
|
355
|
+
- End-to-end encryption
|
356
|
+
- Version control
|
357
|
+
- Decentralized storage
|
358
|
+
|
359
|
+
### Advanced Privacy
|
360
|
+
- Stealth transactions
|
361
|
+
- Private communications
|
362
|
+
- On-chain announcements
|
363
|
+
|
364
|
+
### Data Integrity
|
365
|
+
- Cryptographic verification
|
366
|
+
- Blockchain anchoring
|
367
|
+
- Change monitoring
|
368
|
+
|
369
|
+
### Web3 Integration
|
370
|
+
- Seamless Gun/Ethereum account conversion
|
371
|
+
- Signature and authentication support
|
372
|
+
- Complete key management
|
373
|
+
|
374
|
+
## 🤝 Contributing
|
375
|
+
|
376
|
+
Contributions are welcome! Please:
|
377
|
+
|
378
|
+
1. 🍴 Fork the repository
|
379
|
+
2. 🌿 Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
380
|
+
3. 💾 Commit your changes (`git commit -m 'Add: amazing feature'`)
|
381
|
+
4. 📤 Push to the branch (`git push origin feature/AmazingFeature`)
|
382
|
+
5. 🔄 Open a Pull Request
|
383
|
+
|
384
|
+
## 📄 License
|
385
|
+
|
386
|
+
MIT © 2024 Scobru
|