gun-eth 2.0.0 → 2.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/README.md +207 -18
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,18 +1,207 @@
|
|
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="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"/>
|
5
|
+
|
6
|
+
## Table of Contents
|
7
|
+
|
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)
|
21
|
+
|
22
|
+
## DESCRIPTION
|
23
|
+
|
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.
|
25
|
+
|
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
|
44
|
+
|
45
|
+
```bash
|
46
|
+
npm install gun-eth
|
47
|
+
```
|
48
|
+
|
49
|
+
```javascript
|
50
|
+
import gun from "gun";
|
51
|
+
import "gun-eth";
|
52
|
+
|
53
|
+
const gun = Gun();
|
54
|
+
|
55
|
+
await gun.generatePassword("YOUR_SIGNATURE");
|
56
|
+
```
|
57
|
+
|
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
|
66
|
+
|
67
|
+
### Create KeyPair
|
68
|
+
|
69
|
+
|
70
|
+
[](https://mermaid.live/edit#pako:eNpdUUtuwjAQvcrIGzZwgSwqJSRQhEorwqZNWLjxkFgkduSPEAJu1Fv0Yp0khaj1wh6P3s_jCyu0QBawQ61PRcWNg12cKxhWmK2T97dwtYVlskm24W71utnDbPYE0SWVpUIDJdLOHQIHSx3uvEE4SVdBJS2ceF2juz0Eo458Tb-_rjDPlnfqGs8tl2agpUm4f-DnvVmcJaow59aBq_6hR09vpSqh9OqvQtwrJGQ2sBU9F7TqgHEEEzpm6KoJEGjiLRrbl1wIg9aOMkkvs8hSp8kLhzgo4PgbRnaKn3E0MhY945miiz2bsgZNw6WgSV86SM4oTIM5C6gU3Bxz1rfVjbDcO52eVcECZzxOmdG-rFhw4LWlm28FDS2WvDS8eXRRSIr2Mnxm_6dT1nL1ofUdc_sBNpWchQ)
|
71
|
+
|
72
|
+
### Retrive KeyPair
|
73
|
+
----
|
74
|
+
|
75
|
+
[](https://mermaid.live/edit#pako:eNplUsluwjAQ_ZWRz_ADObQCEiggOLAc2iQHN56ABbGjsU2FAv_erBBBLs7Yb5lnT8ESLZB5LD3rv-TIycLOjxSU3yjc7kabnQcbtCTxgrDEa84lxTAcfsC42BskyElfpEADXAhCU65KgJEHxa0j_Lw3WuOKcvtGc4NJ-NBDldA1tyjg1ChDSjqDmVP-OG6Ik9rLL4J3qHZKdPr-Uz8IfayxD6QzUh26RnvNtRZBbTEtWprUCoxLkjJL6s6dwfRpMKsCOFIg8KWnuI9d6xt8dVAk0uTBXvHfM4LVHTfut18x5i-M9spBadskjvsXWjEWL4yVNHXe7j00vSWe1YmXYbD2nw7Uvkrn8NWAmmLeLxZNwQYsQ8q4FOX4FNVRxOwRM4yYV_4KTqeI1dvqXmK5s3p7VQnzLDkcMNLucGReys-mrFwuuEVf8gPx7LGLQlpNq2ZC60EdsJyrH607zP0f6c7pXw)
|
76
|
+
|
77
|
+
## CORE FUNCTIONS
|
78
|
+
|
79
|
+
- `verifySignature(message, signature)`: Verifies an Ethereum signature for a given message.
|
80
|
+
|
81
|
+
```javascript
|
82
|
+
const recoveredAddress = await gun.verifySignature(message, signature);
|
83
|
+
```
|
84
|
+
|
85
|
+
- `generatePassword(signature)`: Generates a password from an Ethereum signature.
|
86
|
+
|
87
|
+
```javascript
|
88
|
+
const password = gun.generatePassword(signature);
|
89
|
+
```
|
90
|
+
|
91
|
+
- `createSignature(message)`: Creates an Ethereum signature for a message.
|
92
|
+
|
93
|
+
```javascript
|
94
|
+
const signature = await gun.createSignature(message);
|
95
|
+
```
|
96
|
+
|
97
|
+
- `createAndStoreEncryptedPair(address, signature)`: Creates and stores an encrypted key pair.
|
98
|
+
|
99
|
+
```javascript
|
100
|
+
await gun.createAndStoreEncryptedPair(address, signature);
|
101
|
+
```
|
102
|
+
|
103
|
+
- `getAndDecryptPair(address, signature)`: Retrieves and decrypts a stored key pair.
|
104
|
+
|
105
|
+
```javascript
|
106
|
+
const decryptedPair = await gun.getAndDecryptPair(address, signature);
|
107
|
+
```
|
108
|
+
|
109
|
+
- `shine(chain, nodeId, data, callback)`: Implements SHINE for data verification and storage on the blockchain.
|
110
|
+
|
111
|
+
```javascript
|
112
|
+
gun.shine("optimismSepolia", nodeId, data, callback);
|
113
|
+
```
|
114
|
+
|
115
|
+
## SHINE
|
116
|
+
|
117
|
+
SHINE (Secure Hash Integrity Network Ethereum) provides a mechanism for verifying data integrity using Ethereum and Gun.js.
|
118
|
+
|
119
|
+
|
120
|
+
[](https://mermaid.live/edit#pako:eNplk1GTmjAQx79KJs_oICAiD9epQoX25Dq1006LPqRkPTMHiRODdx763S8Ez7N3PCXZ__73txvS4EJQwCFel-Kx2BCp0M9oyZH-PucL1e4XSZrF6BdItmYFUUzwFer1btCkSfm2ViHi2iGln05d2qQNHv_A7oim-Q9QksEeECWKoLUUFZrVPJqsOu3UGEVNZKKi5heX6M0lzuMnJUmhUCG4Aq4SstusrmWZOKIvecxpiIwTF6pzO6tiU2aWmx4OHYvgPd0u42fJzEiSjmRPSkYvilek5A0pzWegUEkU7BSSUAhJu-b-laJ4uPZNLoBf3wHuzUDhlTE1AN-uRO8E19Nt_W41AwepGRCHx_MlnLW3xmyeTyW08Y9zmxtBpm9YSECM_3crmQne5b8l08mCf-zqzii-d7CZrm5GumvN6ApbuAJZEUb1b9W0CUusNlDBEod6SYl8WGJzzE9aS2olFgde4FDJGiwsRX2_weGalDu9q7faGiJG7iWpLqdbwnHY4Ccc9pxxf-wEA9exPc92A384tPABh8NB33WDwdCxfcfxAy84WfhZCG0x6HuuZ49HI98PRjpojywMlGn2efcSzIMwNf6ahBbr9AJRuPoz)
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
#### SHINE Contract Configuration
|
125
|
+
|
126
|
+
Currently, SHINE supports only the Optimism Sepolia network. The contract address is managed internally:
|
127
|
+
|
128
|
+
```javascript
|
129
|
+
const SHINE_OPTIMISM_SEPOLIA = "0x43D838b683F772F08f321E5FA265ad3e333BE9C2";
|
130
|
+
```
|
131
|
+
|
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.
|
133
|
+
|
134
|
+
#### SHINE Helper Functions
|
135
|
+
|
136
|
+
SHINE uses several internal helper functions to interact with the blockchain:
|
137
|
+
|
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.
|
142
|
+
|
143
|
+
These functions are used internally by the `shine` method and are not directly exposed to the user.
|
144
|
+
|
145
|
+
### Usage Examples
|
146
|
+
|
147
|
+
#### Verifying Data by NodeId
|
148
|
+
|
149
|
+
```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
|
+
});
|
162
|
+
```
|
163
|
+
|
164
|
+
#### Storing New Data
|
165
|
+
|
166
|
+
```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
|
+
});
|
178
|
+
```
|
179
|
+
|
180
|
+
## STANDALONE MODE
|
181
|
+
|
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:
|
183
|
+
|
184
|
+
```javascript
|
185
|
+
gun.setStandaloneConfig("https://your-rpc-url", "your-private-key");
|
186
|
+
```
|
187
|
+
|
188
|
+
Make sure to keep your private key secure and never expose it in client-side code.
|
189
|
+
|
190
|
+
### Security Considerations
|
191
|
+
|
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.
|
196
|
+
|
197
|
+
## Contributing
|
198
|
+
|
199
|
+
We welcome contributions! Please open an issue or submit a pull request on GitHub.
|
200
|
+
|
201
|
+
## License
|
202
|
+
|
203
|
+
This project is released under the MIT license.
|
204
|
+
|
205
|
+
## Contact
|
206
|
+
|
207
|
+
For questions or support, please open an issue on GitHub: https://github.com/scobru/gun-eth
|