gun-eth 2.0.1 → 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.
Files changed (64) hide show
  1. package/README.md +320 -141
  2. package/dist/gun-eth.bundle.js +6806 -0
  3. package/dist/gun-eth.cjs +2465 -0
  4. package/dist/types/browser.d.ts +6 -0
  5. package/dist/types/config/local.d.ts +7 -0
  6. package/dist/types/constants/abis.d.ts +37 -0
  7. package/dist/types/constants/index.d.ts +1 -0
  8. package/dist/types/core/gun-eth.d.ts +419 -0
  9. package/dist/types/features/bubbles/client/bubble-client.d.ts +184 -0
  10. package/dist/types/features/bubbles/providers/base-bubble-provider.d.ts +303 -0
  11. package/dist/types/features/bubbles/providers/gun-bubble-provider.d.ts +173 -0
  12. package/dist/types/features/bubbles/providers/hybrid-bubble-provider.d.ts +124 -0
  13. package/dist/types/features/proof/ProofChain.d.ts +225 -0
  14. package/dist/types/features/stealth/StealthChain.d.ts +200 -0
  15. package/dist/types/index.d.ts +61 -0
  16. package/dist/types/utils/common.d.ts +11 -0
  17. package/dist/types/utils/encryption.d.ts +32 -0
  18. package/package.json +110 -26
  19. package/dist/gun-eth-protocol.cjs.js +0 -11528
  20. package/dist/gun-eth-protocol.esm.js +0 -11503
  21. package/dist/gun-eth-protocol.js +0 -18
  22. package/dist/gun-eth-protocol.react.js +0 -11503
  23. package/dist/gun-eth-protocol.umd.js +0 -18
  24. package/jsdoc.json +0 -7
  25. package/rollup.config.js +0 -80
  26. package/src/index.js +0 -181
  27. package/src/lib/authentication/index.js +0 -13
  28. package/src/lib/authentication/isAuthenticated.js +0 -20
  29. package/src/lib/authentication/login.js +0 -25
  30. package/src/lib/authentication/register.js +0 -58
  31. package/src/lib/blockchain/abis/SHINE.json +0 -262
  32. package/src/lib/blockchain/contracts/SHINE.sol +0 -52
  33. package/src/lib/blockchain/ethereum.js +0 -74
  34. package/src/lib/blockchain/shine.js +0 -204
  35. package/src/lib/certificates/friendsCertificates.js +0 -92
  36. package/src/lib/certificates/index.js +0 -44
  37. package/src/lib/certificates/messagingCertificates.js +0 -94
  38. package/src/lib/friends/acceptFriendRequest.js +0 -69
  39. package/src/lib/friends/addFriendRequest.js +0 -49
  40. package/src/lib/friends/friendRequests.js +0 -51
  41. package/src/lib/friends/friendsList.js +0 -57
  42. package/src/lib/friends/index.js +0 -36
  43. package/src/lib/friends/rejectFriendRequest.js +0 -31
  44. package/src/lib/messaging/chatsList.js +0 -42
  45. package/src/lib/messaging/createChat.js +0 -132
  46. package/src/lib/messaging/index.js +0 -36
  47. package/src/lib/messaging/messageList.js +0 -106
  48. package/src/lib/messaging/sendMessage.js +0 -132
  49. package/src/lib/messaging/sendVoiceMessage.js +0 -119
  50. package/src/lib/notes/createNote.js +0 -41
  51. package/src/lib/notes/deleteNote.js +0 -12
  52. package/src/lib/notes/getNote.js +0 -25
  53. package/src/lib/notes/getUserNote.js +0 -59
  54. package/src/lib/notes/index.js +0 -8
  55. package/src/lib/notes/updateNotes.js +0 -35
  56. package/src/lib/post/createPost.js +0 -17
  57. package/src/lib/post/decryptPost.js +0 -14
  58. package/src/lib/post/deletePost.js +0 -13
  59. package/src/lib/post/encryptPost,js +0 -16
  60. package/src/lib/post/getPost.js +0 -36
  61. package/src/lib/post/index.js +0 -9
  62. package/src/lib/post/updatePost.js +0 -16
  63. package/src/state/gun.js +0 -33
  64. package/types/types.d.ts +0 -244
package/README.md CHANGED
@@ -1,207 +1,386 @@
1
- # GUN-ETH
1
+ # Gun-ETH 🔫
2
2
 
3
- <img src="https://imgs.search.brave.com/RM76D4wyToxCzGffJLw33O_L3glhpIVS3KLvXehpMt8/rs:fit:500:0:0:0/g:ce/aHR0cHM6Ly93d3cu/dXNlcmxvZ29zLm9y/Zy9maWxlcy9sb2dv/cy9mZXJuYW5kb3Nh/bnR1Y2NpLzI5NDY5/X2d1bmRiLWxvZ28u/cG5n" alt="gun" width="200"/>
4
- <img src="https://imgs.search.brave.com/kQyriTMPqw42DEhIQj3eEKIcLZu_C4nNIVR8KtAn3lo/rs:fit:500:0:0:0/g:ce/aHR0cHM6Ly93d3cu/bG9nby53aW5lL2Ev/bG9nby9FdGhlcmV1/bS9FdGhlcmV1bS1E/aWFtb25kLUxvZ28u/d2luZS5zdmc" alt="eth" width="200"/>
3
+ <img src="landing/assets/hero-image.webp" alt="Gun-ETH Logo" width="300">
5
4
 
6
- ## Table of Contents
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.
7
6
 
8
- 1. [DESCRIPTION](#description)
9
- 2. [SMART CONTRACT](#smart-contract)
10
- 3. [KEY FEATURES](#key-features)
11
- 4. [HOW TO INSTALL](#how-to-install)
12
- 5. [HOW TO USE](#how-to-use)
13
- 6. [HOW IT WORKS](#how-it-works)
14
- 7. [CORE FUNCTIONS](#core-functions)
15
- 8. [SHINE](#shine)
16
- 9. [STANDALONE MODE](#standalone-mode)
17
- 10. [SECURITY CONSIDERATIONS](#security-considerations)
18
- 11. [CONTRIBUTING](#contributing)
19
- 12. [LICENSE](#license)
20
- 13. [CONTACT](#contact)
7
+ ## ✨ Why Gun-ETH?
21
8
 
22
- ## DESCRIPTION
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
23
13
 
24
- Gun-eth is a plugin for GunDB that integrates Ethereum and Web3 functionality. This plugin extends GunDB's capabilities by allowing interaction with the Ethereum blockchain and providing cryptographic and signature management features.
14
+ ## 🚀 Quick Start
25
15
 
26
- ## SMART CONTRACT
27
-
28
- SHINE Smart Contract deployed on Optimism Sepolia: [0x43D838b683F772F08f321E5FA265ad3e333BE9C2](https://sepolia-optimism.etherscan.io/address/0x43D838b683F772F08f321E5FA265ad3e333BE9C2)
29
-
30
- Currently, the contract is deployed only on Optimism Sepolia. In the future, it will be deployed on multiple chains.
31
-
32
- ## No time? Check the [TUTORIAL](./TUTORIAL.md)
33
-
34
- ## KEY FEATURES
35
-
36
- - **Ethereum Signature Verification**: Verify Ethereum signatures for messages.
37
- - **Password Generation**: Generate secure passwords from Ethereum signatures.
38
- - **Signature Creation**: Create Ethereum signatures for messages.
39
- - **Encrypted Key Pair Management**: Create, store, and retrieve encrypted key pairs.
40
- - **SHINE Implementation**: Implement the SHINE for data verification on the blockchain.
41
- - **Custom Token Management**: Set and retrieve custom tokens for Gun operations.
42
-
43
- ## HOW TO INSTALL
16
+ ### Installation
44
17
 
45
18
  ```bash
46
19
  npm install gun-eth
20
+ # or
21
+ yarn add gun-eth
47
22
  ```
48
23
 
24
+ ### Basic Configuration
25
+
49
26
  ```javascript
50
- import gun from "gun";
51
- import "gun-eth";
27
+ import Gun from 'gun';
28
+ import { GunEth } from 'gun-eth';
29
+ import { ethers } from 'ethers';
52
30
 
53
- const gun = Gun();
31
+ // Configure Gun with peers
32
+ const gun = Gun({
33
+ peers: ['http://localhost:8765/gun']
34
+ });
54
35
 
55
- await gun.generatePassword("YOUR_SIGNATURE");
36
+ // Initialize GunEth
37
+ const gunEth = await GunEth.init('localhost'); // or 'mainnet', 'sepolia', etc.
56
38
  ```
57
39
 
58
- ## HOW TO USE
59
-
60
- Learn more about Gun.js [here](https://gun.eco/docs/Getting-Started).
61
-
62
- Learn more about plugin implementation [here](https://github.com/amark/gun/wiki/Adding-Methods-to-the-Gun-Chain#abstraction-layers).
63
-
64
-
65
- ## HOW IT WORKS
40
+ ### Signer Configuration
66
41
 
67
- ### Create KeyPair
42
+ Gun-ETH provides two ways to configure the signer:
68
43
 
44
+ 1. **Manual Configuration (Recommended for Production)**
45
+ ```javascript
46
+ import { setSigner, getSigner } from 'gun-eth';
69
47
 
70
- [![](https://mermaid.ink/img/pako:eNpdUUtuwjAQvcrIGzZwgSwqJSRQhEorwqZNWLjxkFgkduSPEAJu1Fv0Yp0khaj1wh6P3s_jCyu0QBawQ61PRcWNg12cKxhWmK2T97dwtYVlskm24W71utnDbPYE0SWVpUIDJdLOHQIHSx3uvEE4SVdBJS2ceF2juz0Eo458Tb-_rjDPlnfqGs8tl2agpUm4f-DnvVmcJaow59aBq_6hR09vpSqh9OqvQtwrJGQ2sBU9F7TqgHEEEzpm6KoJEGjiLRrbl1wIg9aOMkkvs8hSp8kLhzgo4PgbRnaKn3E0MhY945miiz2bsgZNw6WgSV86SM4oTIM5C6gU3Bxz1rfVjbDcO52eVcECZzxOmdG-rFhw4LWlm28FDS2WvDS8eXRRSIr2Mnxm_6dT1nL1ofUdc_sBNpWchQ?type=png)](https://mermaid.live/edit#pako:eNpdUUtuwjAQvcrIGzZwgSwqJSRQhEorwqZNWLjxkFgkduSPEAJu1Fv0Yp0khaj1wh6P3s_jCyu0QBawQ61PRcWNg12cKxhWmK2T97dwtYVlskm24W71utnDbPYE0SWVpUIDJdLOHQIHSx3uvEE4SVdBJS2ceF2juz0Eo458Tb-_rjDPlnfqGs8tl2agpUm4f-DnvVmcJaow59aBq_6hR09vpSqh9OqvQtwrJGQ2sBU9F7TqgHEEEzpm6KoJEGjiLRrbl1wIg9aOMkkvs8hSp8kLhzgo4PgbRnaKn3E0MhY945miiz2bsgZNw6WgSV86SM4oTIM5C6gU3Bxz1rfVjbDcO52eVcECZzxOmdG-rFhw4LWlm28FDS2WvDS8eXRRSIr2Mnxm_6dT1nL1ofUdc_sBNpWchQ)
71
-
72
- ### Retrive KeyPair
73
- ----
74
-
75
- [![](https://mermaid.ink/img/pako:eNplUsluwjAQ_ZWRz_ADObQCEiggOLAc2iQHN56ABbGjsU2FAv_erBBBLs7Yb5lnT8ESLZB5LD3rv-TIycLOjxSU3yjc7kabnQcbtCTxgrDEa84lxTAcfsC42BskyElfpEADXAhCU65KgJEHxa0j_Lw3WuOKcvtGc4NJ-NBDldA1tyjg1ChDSjqDmVP-OG6Ik9rLL4J3qHZKdPr-Uz8IfayxD6QzUh26RnvNtRZBbTEtWprUCoxLkjJL6s6dwfRpMKsCOFIg8KWnuI9d6xt8dVAk0uTBXvHfM4LVHTfut18x5i-M9spBadskjvsXWjEWL4yVNHXe7j00vSWe1YmXYbD2nw7Uvkrn8NWAmmLeLxZNwQYsQ8q4FOX4FNVRxOwRM4yYV_4KTqeI1dvqXmK5s3p7VQnzLDkcMNLucGReys-mrFwuuEVf8gPx7LGLQlpNq2ZC60EdsJyrH607zP0f6c7pXw?type=png)](https://mermaid.live/edit#pako:eNplUsluwjAQ_ZWRz_ADObQCEiggOLAc2iQHN56ABbGjsU2FAv_erBBBLs7Yb5lnT8ESLZB5LD3rv-TIycLOjxSU3yjc7kabnQcbtCTxgrDEa84lxTAcfsC42BskyElfpEADXAhCU65KgJEHxa0j_Lw3WuOKcvtGc4NJ-NBDldA1tyjg1ChDSjqDmVP-OG6Ik9rLL4J3qHZKdPr-Uz8IfayxD6QzUh26RnvNtRZBbTEtWprUCoxLkjJL6s6dwfRpMKsCOFIg8KWnuI9d6xt8dVAk0uTBXvHfM4LVHTfut18x5i-M9spBadskjvsXWjEWL4yVNHXe7j00vSWe1YmXYbD2nw7Uvkrn8NWAmmLeLxZNwQYsQ8q4FOX4FNVRxOwRM4yYV_4KTqeI1dvqXmK5s3p7VQnzLDkcMNLucGReys-mrFwuuEVf8gPx7LGLQlpNq2ZC60EdsJyrH607zP0f6c7pXw)
76
-
77
- ## CORE FUNCTIONS
48
+ // Configure with explicit RPC URL and private key
49
+ await setSigner(
50
+ "https://your-rpc-url",
51
+ "your-private-key"
52
+ );
78
53
 
79
- - `verifySignature(message, signature)`: Verifies an Ethereum signature for a given message.
54
+ // Get the configured signer
55
+ const signer = await getSigner();
56
+ ```
80
57
 
81
- ```javascript
82
- const recoveredAddress = await gun.verifySignature(message, signature);
83
- ```
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
+ ```
84
70
 
85
- - `generatePassword(signature)`: Generates a password from an Ethereum signature.
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
86
75
 
87
- ```javascript
88
- const password = gun.generatePassword(signature);
89
- ```
76
+ ### Error Handling
90
77
 
91
- - `createSignature(message)`: Creates an Ethereum signature for a message.
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
+ ```
92
88
 
93
- ```javascript
94
- const signature = await gun.createSignature(message);
95
- ```
89
+ ## 📚 Documentation
96
90
 
97
- - `createAndStoreEncryptedPair(address, signature)`: Creates and stores an encrypted key pair.
91
+ ### 🔐 Gun-Ethereum Integration
98
92
 
99
- ```javascript
100
- await gun.createAndStoreEncryptedPair(address, signature);
101
- ```
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
+ ```
102
114
 
103
- - `getAndDecryptPair(address, signature)`: Retrieves and decrypts a stored key pair.
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
+ ```
104
125
 
105
- ```javascript
106
- const decryptedPair = await gun.getAndDecryptPair(address, signature);
107
- ```
126
+ ### 🔒 Stealth Chain
108
127
 
109
- - `shine(chain, nodeId, data, callback)`: Implements SHINE for data verification and storage on the blockchain.
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
+ ```
110
170
 
111
- ```javascript
112
- gun.shine("optimismSepolia", nodeId, data, callback);
113
- ```
114
-
115
- ## SHINE
171
+ ### ⛓️ Proof Chain
116
172
 
117
- SHINE (Secure Hash Integrity Network Ethereum) provides a mechanism for verifying data integrity using Ethereum and Gun.js.
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
+ ```
118
202
 
203
+ ### 🫧 Encrypted Bubbles
119
204
 
120
- [![](https://mermaid.ink/img/pako:eNplk1GTmjAQx79KJs_oICAiD9epQoX25Dq1006LPqRkPTMHiRODdx763S8Ez7N3PCXZ__73txvS4EJQwCFel-Kx2BCp0M9oyZH-PucL1e4XSZrF6BdItmYFUUzwFer1btCkSfm2ViHi2iGln05d2qQNHv_A7oim-Q9QksEeECWKoLUUFZrVPJqsOu3UGEVNZKKi5heX6M0lzuMnJUmhUCG4Aq4SstusrmWZOKIvecxpiIwTF6pzO6tiU2aWmx4OHYvgPd0u42fJzEiSjmRPSkYvilek5A0pzWegUEkU7BSSUAhJu-b-laJ4uPZNLoBf3wHuzUDhlTE1AN-uRO8E19Nt_W41AwepGRCHx_MlnLW3xmyeTyW08Y9zmxtBpm9YSECM_3crmQne5b8l08mCf-zqzii-d7CZrm5GumvN6ApbuAJZEUb1b9W0CUusNlDBEod6SYl8WGJzzE9aS2olFgde4FDJGiwsRX2_weGalDu9q7faGiJG7iWpLqdbwnHY4Ccc9pxxf-wEA9exPc92A384tPABh8NB33WDwdCxfcfxAy84WfhZCG0x6HuuZ49HI98PRjpojywMlGn2efcSzIMwNf6ahBbr9AJRuPoz?type=png)](https://mermaid.live/edit#pako:eNplk1GTmjAQx79KJs_oICAiD9epQoX25Dq1006LPqRkPTMHiRODdx763S8Ez7N3PCXZ__73txvS4EJQwCFel-Kx2BCp0M9oyZH-PucL1e4XSZrF6BdItmYFUUzwFer1btCkSfm2ViHi2iGln05d2qQNHv_A7oim-Q9QksEeECWKoLUUFZrVPJqsOu3UGEVNZKKi5heX6M0lzuMnJUmhUCG4Aq4SstusrmWZOKIvecxpiIwTF6pzO6tiU2aWmx4OHYvgPd0u42fJzEiSjmRPSkYvilek5A0pzWegUEkU7BSSUAhJu-b-laJ4uPZNLoBf3wHuzUDhlTE1AN-uRO8E19Nt_W41AwepGRCHx_MlnLW3xmyeTyW08Y9zmxtBpm9YSECM_3crmQne5b8l08mCf-zqzii-d7CZrm5GumvN6ApbuAJZEUb1b9W0CUusNlDBEod6SYl8WGJzzE9aS2olFgde4FDJGiwsRX2_weGalDu9q7faGiJG7iWpLqdbwnHY4Ccc9pxxf-wEA9exPc92A384tPABh8NB33WDwdCxfcfxAy84WfhZCG0x6HuuZ49HI98PRjpojywMlGn2efcSzIMwNf6ahBbr9AJRuPoz)
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
+ });
121
217
 
218
+ // Create and manage bubbles
219
+ const bubble = await bubbleClient.createBubble("My Bubble", {
220
+ isPrivate: true
221
+ });
122
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
+ ```
123
243
 
124
- #### SHINE Contract Configuration
244
+ ### 🔄 Bubble Providers
125
245
 
126
- Currently, SHINE supports only the Optimism Sepolia network. The contract address is managed internally:
246
+ Gun-ETH offers three types of providers for managing encrypted bubbles:
127
247
 
248
+ #### Base Provider
128
249
  ```javascript
129
- const SHINE_OPTIMISM_SEPOLIA = "0x43D838b683F772F08f321E5FA265ad3e333BE9C2";
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
+ }
130
258
  ```
131
259
 
132
- To support other chains in the future, the plugin will select the appropriate address based on the `chain` parameter provided to the `shine` function.
260
+ #### GUN Provider
261
+ ```javascript
262
+ import { GUNBubbleProvider } from 'gun-eth';
133
263
 
134
- #### SHINE Helper Functions
264
+ const gunProvider = new GUNBubbleProvider({
265
+ gun: gunInstance,
266
+ signer: signer,
267
+ keypair: keypair
268
+ });
135
269
 
136
- SHINE uses several internal helper functions to interact with the blockchain:
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';
137
280
 
138
- - `getSigner()`: Retrieves an Ethereum signer from the browser provider (e.g., MetaMask).
139
- - `verifyOnChain(nodeId, contentHash)`: Verifies data integrity on the blockchain.
140
- - `writeOnChain(nodeId, contentHash)`: Writes the content hash to the blockchain.
141
- - `getLatestRecord(nodeId)`: Retrieves the latest record associated with a nodeId from the blockchain.
281
+ const hybridProvider = new HybridBubbleProvider({
282
+ gun: gunInstance,
283
+ signer: signer,
284
+ keypair: keypair,
285
+ storage: customStorageAdapter
286
+ });
142
287
 
143
- These functions are used internally by the `shine` method and are not directly exposed to the user.
288
+ // Supports both GUN and external storage
289
+ await hybridProvider.handleCreateBubble({
290
+ name: "Hybrid Bubble",
291
+ isPrivate: true,
292
+ useExternal: true
293
+ });
294
+ ```
144
295
 
145
- ### Usage Examples
296
+ ### 📋 Templates
146
297
 
147
- #### Verifying Data by NodeId
298
+ Gun-ETH provides ready-to-use templates for common implementations:
148
299
 
300
+ #### Client Template
149
301
  ```javascript
150
- const nodeId = "your-node-id-here";
151
-
152
- gun.shine("optimismSepolia", nodeId, null, (ack) => {
153
- if (ack.ok) {
154
- console.log("Data verified on blockchain", ack);
155
- console.log("Timestamp:", ack.timestamp);
156
- console.log("Updater:", ack.updater);
157
- console.log("Latest Record:", ack.latestRecord);
158
- } else {
159
- console.log("Data not verified or not found", ack);
160
- }
161
- });
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");
162
318
  ```
163
319
 
164
- #### Storing New Data
165
-
320
+ #### Provider Template
166
321
  ```javascript
167
- const data = { message: "Hello, blockchain!" };
168
-
169
- gun.shine("optimismSepolia", null, data, (ack) => {
170
- if (ack.ok) {
171
- console.log("Data stored on Gun.js and blockchain", ack);
172
- console.log("New Node ID:", ack.nodeId);
173
- console.log("Transaction Hash:", ack.txHash);
174
- } else {
175
- console.log("Error storing data", ack);
176
- }
177
- });
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);
178
340
  ```
179
341
 
180
- ## STANDALONE MODE
342
+ ## 🏗️ Architecture
181
343
 
182
- For users who want to run the plugin without a browser wallet, you can use the standalone mode. This requires setting up an RPC URL and a private key:
344
+ Gun-ETH is structured in independent modules:
183
345
 
184
- ```javascript
185
- gun.setStandaloneConfig("https://your-rpc-url", "your-private-key");
186
- ```
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
187
353
 
188
- Make sure to keep your private key secure and never expose it in client-side code.
354
+ ### Secure Backup System
355
+ - End-to-end encryption
356
+ - Version control
357
+ - Decentralized storage
189
358
 
190
- ### Security Considerations
359
+ ### Advanced Privacy
360
+ - Stealth transactions
361
+ - Private communications
362
+ - On-chain announcements
191
363
 
192
- - Use a secure Ethereum provider (e.g., MetaMask) when interacting with functions that require signatures.
193
- - Generated passwords and key pairs are sensitive. Handle them carefully and avoid exposing them.
194
- - Keep Gun.js and Ethereum dependencies up to date for security.
195
- - Be aware of gas costs associated with blockchain interactions when using SHINE.
364
+ ### Data Integrity
365
+ - Cryptographic verification
366
+ - Blockchain anchoring
367
+ - Change monitoring
196
368
 
197
- ## Contributing
369
+ ### Web3 Integration
370
+ - Seamless Gun/Ethereum account conversion
371
+ - Signature and authentication support
372
+ - Complete key management
198
373
 
199
- We welcome contributions! Please open an issue or submit a pull request on GitHub.
374
+ ## 🤝 Contributing
200
375
 
201
- ## License
376
+ Contributions are welcome! Please:
202
377
 
203
- This project is released under the MIT license.
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
204
383
 
205
- ## Contact
384
+ ## 📄 License
206
385
 
207
- For questions or support, please open an issue on GitHub: https://github.com/scobru/gun-eth
386
+ MIT © 2024 Scobru