gun-eth 1.3.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +18 -207
- package/dist/gun-eth-protocol.cjs.js +11528 -0
- package/dist/gun-eth-protocol.esm.js +11503 -0
- package/dist/gun-eth-protocol.js +18 -0
- package/dist/gun-eth-protocol.react.js +11503 -0
- package/dist/gun-eth-protocol.umd.js +18 -0
- package/jsdoc.json +7 -0
- package/package.json +28 -25
- package/rollup.config.js +80 -0
- package/src/index.js +160 -512
- package/src/lib/authentication/index.js +13 -0
- package/src/lib/authentication/isAuthenticated.js +20 -0
- package/src/lib/authentication/login.js +25 -0
- package/src/lib/authentication/register.js +58 -0
- package/src/lib/blockchain/ethereum.js +74 -0
- package/src/lib/blockchain/shine.js +204 -0
- package/src/lib/certificates/friendsCertificates.js +92 -0
- package/src/lib/certificates/index.js +44 -0
- package/src/lib/certificates/messagingCertificates.js +94 -0
- package/src/lib/friends/acceptFriendRequest.js +69 -0
- package/src/lib/friends/addFriendRequest.js +49 -0
- package/src/lib/friends/friendRequests.js +51 -0
- package/src/lib/friends/friendsList.js +57 -0
- package/src/lib/friends/index.js +36 -0
- package/src/lib/friends/rejectFriendRequest.js +31 -0
- package/src/lib/messaging/chatsList.js +42 -0
- package/src/lib/messaging/createChat.js +132 -0
- package/src/lib/messaging/index.js +36 -0
- package/src/lib/messaging/messageList.js +106 -0
- package/src/lib/messaging/sendMessage.js +132 -0
- package/src/lib/messaging/sendVoiceMessage.js +119 -0
- package/src/lib/notes/createNote.js +41 -0
- package/src/lib/notes/deleteNote.js +12 -0
- package/src/lib/notes/getNote.js +25 -0
- package/src/lib/notes/getUserNote.js +59 -0
- package/src/lib/notes/index.js +8 -0
- package/src/lib/notes/updateNotes.js +35 -0
- package/src/lib/post/createPost.js +17 -0
- package/src/lib/post/decryptPost.js +14 -0
- package/src/lib/post/deletePost.js +13 -0
- package/src/lib/post/encryptPost,js +16 -0
- package/src/lib/post/getPost.js +36 -0
- package/src/lib/post/index.js +9 -0
- package/src/lib/post/updatePost.js +16 -0
- package/src/state/gun.js +33 -0
- package/types/types.d.ts +244 -0
- package/TUTORIAL.md +0 -103
- package/src/examples/eth2gun.html +0 -163
- package/src/examples/gun2eth.html +0 -164
- package/src/examples/shine.html +0 -256
- /package/src/{abis → lib/blockchain/abis}/SHINE.json +0 -0
- /package/src/{contracts → lib/blockchain/contracts}/SHINE.sol +0 -0
package/src/examples/shine.html
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8" />
|
5
|
-
<title>Demo Gun-Eth Plugin</title>
|
6
|
-
<!-- Include Gun -->
|
7
|
-
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
|
8
|
-
<!-- Include SEA (part of Gun) -->
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
|
10
|
-
<!-- Include Ethers.js -->
|
11
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.7.0/ethers.umd.min.js"></script>
|
12
|
-
<!-- Include the Gun-Eth plugin -->
|
13
|
-
<script src="https://cdn.jsdelivr.net/npm/gun-eth/src/gun-eth.js""></script>
|
14
|
-
<style>
|
15
|
-
body {
|
16
|
-
font-family: Arial, sans-serif;
|
17
|
-
margin: 0;
|
18
|
-
padding: 20px;
|
19
|
-
background-color: #f0f0f0;
|
20
|
-
}
|
21
|
-
.container {
|
22
|
-
max-width: 400px;
|
23
|
-
background-color: white;
|
24
|
-
border: 1px solid #000;
|
25
|
-
padding: 10px;
|
26
|
-
}
|
27
|
-
h1,
|
28
|
-
h2 {
|
29
|
-
margin: 0 0 10px 0;
|
30
|
-
font-size: 16px;
|
31
|
-
}
|
32
|
-
form {
|
33
|
-
margin-bottom: 15px;
|
34
|
-
}
|
35
|
-
input,
|
36
|
-
button {
|
37
|
-
display: inline-block;
|
38
|
-
margin: 2px 0;
|
39
|
-
padding: 2px;
|
40
|
-
font-size: 12px;
|
41
|
-
}
|
42
|
-
input {
|
43
|
-
width: 150px;
|
44
|
-
}
|
45
|
-
button {
|
46
|
-
width: 70px;
|
47
|
-
}
|
48
|
-
label {
|
49
|
-
display: inline-block;
|
50
|
-
width: 70px;
|
51
|
-
font-size: 12px;
|
52
|
-
}
|
53
|
-
#configStatus,
|
54
|
-
.result {
|
55
|
-
font-weight: bold;
|
56
|
-
margin-bottom: 10px;
|
57
|
-
}
|
58
|
-
.result {
|
59
|
-
color: blue;
|
60
|
-
}
|
61
|
-
.disclaimer {
|
62
|
-
background-color: #ffffd0;
|
63
|
-
border: 1px solid #e6e600;
|
64
|
-
padding: 10px;
|
65
|
-
margin-bottom: 15px;
|
66
|
-
font-size: 14px;
|
67
|
-
}
|
68
|
-
</style>
|
69
|
-
</head>
|
70
|
-
<body>
|
71
|
-
<div class="container">
|
72
|
-
<div class="disclaimer">
|
73
|
-
<strong>⚠️</strong> This example is available only on the
|
74
|
-
<strong>Optimism Sepolia</strong> chain.
|
75
|
-
</div>
|
76
|
-
<h1>💎 SHINE (Secure Hash Integriry Network Ethereum)</h1>
|
77
|
-
<hr />
|
78
|
-
<h2>🔧 Configuration</h2>
|
79
|
-
<form id="configForm">
|
80
|
-
<label for="rpcUrl">RPC URL:</label>
|
81
|
-
<input type="text" id="rpcUrl" name="rpcUrl" required />
|
82
|
-
<br />
|
83
|
-
<label for="privateKey">Private Key:</label>
|
84
|
-
<input type="password" id="privateKey" name="privateKey" required />
|
85
|
-
<br />
|
86
|
-
<button type="submit">Configure</button>
|
87
|
-
</form>
|
88
|
-
<div id="configStatus">Status: Not Configured</div>
|
89
|
-
<hr />
|
90
|
-
|
91
|
-
<h2>🔴 Write Data to Blockchain</h2>
|
92
|
-
<form id="writeForm">
|
93
|
-
<label for="data">Data</label>
|
94
|
-
<br />
|
95
|
-
<input type="text" id="data" name="data" required />
|
96
|
-
<br />
|
97
|
-
<button type="submit">Write</button>
|
98
|
-
</form>
|
99
|
-
<div id="writeResult" class="result"></div>
|
100
|
-
<hr />
|
101
|
-
|
102
|
-
<h2>🔍 Verify Data on Blockchain</h2>
|
103
|
-
<form id="verifyForm">
|
104
|
-
<label for="nodeId">Node ID</label>
|
105
|
-
<br />
|
106
|
-
<input type="text" id="nodeId" name="nodeId" required />
|
107
|
-
<br />
|
108
|
-
<button type="submit">Verify</button>
|
109
|
-
</form>
|
110
|
-
<div id="verifyResult" class="result"></div>
|
111
|
-
<hr />
|
112
|
-
|
113
|
-
<h2>🔄 Update Node Data in Gun</h2>
|
114
|
-
<form id="updateForm">
|
115
|
-
<label for="updateNodeId">Node ID</label>
|
116
|
-
<br />
|
117
|
-
<input type="text" id="updateNodeId" name="updateNodeId" required />
|
118
|
-
<br />
|
119
|
-
<label for="editMessage">New Data</label>
|
120
|
-
<br />
|
121
|
-
<input type="text" id="editMessage" name="editMessage" required />
|
122
|
-
<br />
|
123
|
-
<button type="submit">Update</button>
|
124
|
-
</form>
|
125
|
-
<div id="updateResult" class="result"></div>
|
126
|
-
</div>
|
127
|
-
|
128
|
-
<script>
|
129
|
-
let gun;
|
130
|
-
let isConfigured = false;
|
131
|
-
|
132
|
-
function updateConfigStatus() {
|
133
|
-
const statusElement = document.getElementById("configStatus");
|
134
|
-
statusElement.textContent = isConfigured
|
135
|
-
? "Status: Configured"
|
136
|
-
: "Status: Not Configured";
|
137
|
-
statusElement.style.color = isConfigured ? "green" : "red";
|
138
|
-
}
|
139
|
-
|
140
|
-
document
|
141
|
-
.getElementById("configForm")
|
142
|
-
.addEventListener("submit", function (event) {
|
143
|
-
event.preventDefault();
|
144
|
-
const rpcUrl = document.getElementById("rpcUrl").value;
|
145
|
-
const privateKey = document.getElementById("privateKey").value;
|
146
|
-
|
147
|
-
// Configure Gun with the provided details
|
148
|
-
gun = Gun();
|
149
|
-
gun.setStandaloneConfig(rpcUrl, privateKey);
|
150
|
-
|
151
|
-
console.log("Standalone configuration set");
|
152
|
-
isConfigured = true;
|
153
|
-
updateConfigStatus();
|
154
|
-
});
|
155
|
-
|
156
|
-
document
|
157
|
-
.getElementById("writeForm")
|
158
|
-
.addEventListener("submit", function (event) {
|
159
|
-
event.preventDefault();
|
160
|
-
if (!isConfigured) {
|
161
|
-
document.getElementById("writeResult").textContent =
|
162
|
-
"Please configure Gun first.";
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
const data = document.getElementById("data").value;
|
166
|
-
const resultElement = document.getElementById("writeResult");
|
167
|
-
resultElement.textContent = "Writing data...";
|
168
|
-
|
169
|
-
// Assicurati che `data` sia un oggetto JSON valido
|
170
|
-
|
171
|
-
gun.shine("optimismSepolia", null, data, function (result) {
|
172
|
-
console.log("Shine result:", result);
|
173
|
-
if (result.ok) {
|
174
|
-
resultElement.textContent =
|
175
|
-
"Data successfully written: " + result.nodeId;
|
176
|
-
} else {
|
177
|
-
resultElement.textContent = "Error writing data: " + result.err;
|
178
|
-
}
|
179
|
-
});
|
180
|
-
});
|
181
|
-
|
182
|
-
document
|
183
|
-
.getElementById("verifyForm")
|
184
|
-
.addEventListener("submit", function (event) {
|
185
|
-
event.preventDefault();
|
186
|
-
if (!isConfigured) {
|
187
|
-
document.getElementById("verifyResult").textContent =
|
188
|
-
"Please configure Gun first.";
|
189
|
-
return;
|
190
|
-
}
|
191
|
-
const nodeId = document.getElementById("nodeId").value;
|
192
|
-
const resultElement = document.getElementById("verifyResult");
|
193
|
-
resultElement.textContent = "Verifying data...";
|
194
|
-
|
195
|
-
gun.shine("optimismSepolia", nodeId, null, function (result) {
|
196
|
-
console.log("Verification result:", result);
|
197
|
-
if (result.ok) {
|
198
|
-
resultElement.textContent =
|
199
|
-
"Data successfully verified: " + result.message;
|
200
|
-
} else {
|
201
|
-
resultElement.textContent =
|
202
|
-
"Error verifying data: " + result.message;
|
203
|
-
}
|
204
|
-
});
|
205
|
-
});
|
206
|
-
|
207
|
-
document
|
208
|
-
.getElementById("updateForm")
|
209
|
-
.addEventListener("submit", function (event) {
|
210
|
-
event.preventDefault();
|
211
|
-
if (!isConfigured) {
|
212
|
-
document.getElementById("updateResult").textContent =
|
213
|
-
"Please configure Gun first.";
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
const nodeId = document.getElementById("updateNodeId").value;
|
217
|
-
const editMessage = document.getElementById("editMessage").value;
|
218
|
-
const resultElement = document.getElementById("updateResult");
|
219
|
-
resultElement.textContent = "Updating data...";
|
220
|
-
|
221
|
-
gun.get(nodeId).once(function (existingData) {
|
222
|
-
// Prepara i nuovi dati
|
223
|
-
const newData = {
|
224
|
-
message: editMessage,
|
225
|
-
_contentHash: existingData._contentHash, // Manteniamo il contentHash precedente per il calcolo
|
226
|
-
};
|
227
|
-
|
228
|
-
// Calcola il nuovo contentHash
|
229
|
-
const dataString = JSON.stringify(editMessage);
|
230
|
-
const newContentHash = ethers.keccak256(
|
231
|
-
ethers.toUtf8Bytes(dataString)
|
232
|
-
);
|
233
|
-
|
234
|
-
// Aggiorna i dati con il nuovo contentHash
|
235
|
-
newData._contentHash = newContentHash;
|
236
|
-
|
237
|
-
// Update data in Gun
|
238
|
-
gun.get(nodeId).put(newData, function (ack) {
|
239
|
-
if (ack.err) {
|
240
|
-
console.error("Error updating data in Gun:", ack.err);
|
241
|
-
resultElement.textContent =
|
242
|
-
"Error updating data in Gun: " + ack.err;
|
243
|
-
} else {
|
244
|
-
console.log("Data successfully updated in Gun:", nodeId);
|
245
|
-
resultElement.textContent =
|
246
|
-
"Data successfully updated in Gun: " + nodeId;
|
247
|
-
}
|
248
|
-
});
|
249
|
-
});
|
250
|
-
});
|
251
|
-
|
252
|
-
// Inizializza lo stato di configurazione
|
253
|
-
updateConfigStatus();
|
254
|
-
</script>
|
255
|
-
</body>
|
256
|
-
</html>
|
File without changes
|
File without changes
|