gun-eth 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +292 -77
- package/dist/gun-eth.cjs.js +2808 -0
- package/dist/gun-eth.esm.js +2806 -0
- package/dist/gun-eth.min.js +1 -0
- package/package.json +43 -4
- package/TUTORIAL.md +0 -103
- package/src/abis/SHINE.json +0 -262
- package/src/contracts/SHINE.sol +0 -52
- package/src/examples/eth2gun.html +0 -163
- package/src/examples/gun2eth.html +0 -164
- package/src/examples/shine.html +0 -256
- package/src/index.js +0 -533
@@ -1,163 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8">
|
5
|
-
<title>💎 Ethereum to 🔫 Gun Key Pair Demo</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, div {
|
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: 100px;
|
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
|
-
</style>
|
62
|
-
</head>
|
63
|
-
<body>
|
64
|
-
<div class="container">
|
65
|
-
<h1>💎 Ethereum to 🔫 Gun Key Pair Demo</h1>
|
66
|
-
|
67
|
-
<form id="configForm">
|
68
|
-
<h2>🔧 Configuration</h2>
|
69
|
-
<label for="rpcUrl">🌐 RPC URL:</label>
|
70
|
-
<br>
|
71
|
-
<input type="text" id="rpcUrl" name="rpcUrl" required>
|
72
|
-
<br>
|
73
|
-
<label for="privateKey">🔑 Private Key:</label>
|
74
|
-
<br>
|
75
|
-
<input type="password" id="privateKey" name="privateKey" required>
|
76
|
-
<br>
|
77
|
-
<button type="submit">⚙️ Configure</button>
|
78
|
-
</form>
|
79
|
-
|
80
|
-
<div id="createPairSection">
|
81
|
-
<h2>🔒 Create and Store Encrypted Pair</h2>
|
82
|
-
<button id="createPairBtn">🔐 Create Pair</button>
|
83
|
-
</div>
|
84
|
-
|
85
|
-
<div id="retrievePairSection">
|
86
|
-
<h2>🔓 Retrieve and Decrypt Pair</h2>
|
87
|
-
<button id="retrievePairBtn">🔎 Retrieve Pair</button>
|
88
|
-
</div>
|
89
|
-
|
90
|
-
<div id="resultSection">
|
91
|
-
<h2>📊 Result</h2>
|
92
|
-
<p id="resultText"></p>
|
93
|
-
</div>
|
94
|
-
</div>
|
95
|
-
|
96
|
-
<script>
|
97
|
-
let gun;
|
98
|
-
const MESSAGE_TO_SIGN = "GunDB access with Ethereum";
|
99
|
-
|
100
|
-
document.getElementById('configForm').addEventListener('submit', function(event) {
|
101
|
-
event.preventDefault();
|
102
|
-
const rpcUrl = document.getElementById('rpcUrl').value;
|
103
|
-
const privateKey = document.getElementById('privateKey').value;
|
104
|
-
|
105
|
-
gun = Gun();
|
106
|
-
gun.setStandaloneConfig(rpcUrl, privateKey);
|
107
|
-
|
108
|
-
console.log('Standalone configuration set');
|
109
|
-
document.getElementById('resultText').innerText = '✅ Configuration set successfully';
|
110
|
-
});
|
111
|
-
|
112
|
-
document.getElementById('createPairBtn').addEventListener('click', async function() {
|
113
|
-
if (!gun) {
|
114
|
-
alert('⚠️ Please configure Gun first');
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
|
118
|
-
try {
|
119
|
-
const signature = await gun.createSignature(MESSAGE_TO_SIGN);
|
120
|
-
if (!signature) {
|
121
|
-
throw new Error('Failed to create signature');
|
122
|
-
}
|
123
|
-
|
124
|
-
const signer = new ethers.Wallet(document.getElementById('privateKey').value);
|
125
|
-
const address = await signer.getAddress();
|
126
|
-
|
127
|
-
await gun.createAndStoreEncryptedPair(address, signature);
|
128
|
-
|
129
|
-
document.getElementById('resultText').innerText = '✅ Encrypted pair created and stored successfully';
|
130
|
-
} catch (error) {
|
131
|
-
document.getElementById('resultText').innerText = '❌ Error: ' + error.message;
|
132
|
-
}
|
133
|
-
});
|
134
|
-
|
135
|
-
document.getElementById('retrievePairBtn').addEventListener('click', async function() {
|
136
|
-
if (!gun) {
|
137
|
-
alert('⚠️ Please configure Gun first');
|
138
|
-
return;
|
139
|
-
}
|
140
|
-
|
141
|
-
try {
|
142
|
-
const signature = await gun.createSignature(MESSAGE_TO_SIGN);
|
143
|
-
if (!signature) {
|
144
|
-
throw new Error('Failed to create signature');
|
145
|
-
}
|
146
|
-
|
147
|
-
const signer = new ethers.Wallet(document.getElementById('privateKey').value);
|
148
|
-
const address = await signer.getAddress();
|
149
|
-
|
150
|
-
const pair = await gun.getAndDecryptPair(address, signature);
|
151
|
-
|
152
|
-
document.getElementById('resultText').innerHTML = `
|
153
|
-
<strong>🔑 Retrieved pair:</strong>
|
154
|
-
<br>
|
155
|
-
${JSON.stringify(pair, null, 2)}
|
156
|
-
`;
|
157
|
-
} catch (error) {
|
158
|
-
document.getElementById('resultText').innerText = '❌ Error: ' + error.message;
|
159
|
-
}
|
160
|
-
});
|
161
|
-
</script>
|
162
|
-
</body>
|
163
|
-
</html>
|
@@ -1,164 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang="en">
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8">
|
5
|
-
<title>Gun to Ethereum Address Demo</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: 100px;
|
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
|
-
<h1>🔫 Gun to 💎 Ethereum Address Demo</h1>
|
73
|
-
|
74
|
-
<form id="gunUserForm">
|
75
|
-
<h2>👤 User Login/Registration</h2>
|
76
|
-
<label for="gunAlias">👤 Alias:</label>
|
77
|
-
<br>
|
78
|
-
<input type="text" id="gunAlias" name="gunAlias" required>
|
79
|
-
<br>
|
80
|
-
<label for="gunPassword">🔑 Password:</label>
|
81
|
-
<br>
|
82
|
-
<input type="password" id="gunPassword" name="gunPassword" required>
|
83
|
-
<br>
|
84
|
-
<button type="submit">🚀 Create/Login</button>
|
85
|
-
</form>
|
86
|
-
|
87
|
-
<div id="conversionSection" style="display:none;">
|
88
|
-
<h2>🔄 Convert Gun User to Ethereum Address</h2>
|
89
|
-
<button id="convertBtn">🔄 Convert
|
90
|
-
</div>
|
91
|
-
|
92
|
-
<div id="resultSection">
|
93
|
-
<h2>Result</h2>
|
94
|
-
<p id="resultText"></p>
|
95
|
-
</div>
|
96
|
-
</div>
|
97
|
-
|
98
|
-
<script>
|
99
|
-
let gun = Gun();
|
100
|
-
let currentUser = null;
|
101
|
-
|
102
|
-
document.getElementById('gunUserForm').addEventListener('submit', function(event) {
|
103
|
-
event.preventDefault();
|
104
|
-
const alias = document.getElementById('gunAlias').value;
|
105
|
-
const password = document.getElementById('gunPassword').value;
|
106
|
-
|
107
|
-
console.log('Attempting to create or login user:', alias);
|
108
|
-
|
109
|
-
gun.user().create(alias, password, function(ack) {
|
110
|
-
if (ack.err) {
|
111
|
-
console.log('User creation failed, trying to login:', ack.err);
|
112
|
-
gun.user().auth(alias, password, function(authAck) {
|
113
|
-
if (authAck.err) {
|
114
|
-
document.getElementById('resultText').innerText = 'Error logging in: ' + authAck.err;
|
115
|
-
} else {
|
116
|
-
currentUser = gun.user();
|
117
|
-
document.getElementById('resultText').innerText = 'User logged in successfully.';
|
118
|
-
document.getElementById('conversionSection').style.display = 'block';
|
119
|
-
}
|
120
|
-
});
|
121
|
-
} else {
|
122
|
-
console.log('User created successfully:', ack);
|
123
|
-
currentUser = gun.user();
|
124
|
-
document.getElementById('resultText').innerText = 'User created and logged in successfully.';
|
125
|
-
document.getElementById('conversionSection').style.display = 'block';
|
126
|
-
}
|
127
|
-
});
|
128
|
-
});
|
129
|
-
|
130
|
-
document.getElementById('convertBtn').addEventListener('click', function() {
|
131
|
-
if (!currentUser) {
|
132
|
-
alert('Please login first');
|
133
|
-
return;
|
134
|
-
}
|
135
|
-
|
136
|
-
console.log('Current user:', currentUser);
|
137
|
-
console.log('User pair:', currentUser._.sea);
|
138
|
-
|
139
|
-
try {
|
140
|
-
const pair = currentUser._.sea;
|
141
|
-
if (!pair || !pair.priv) {
|
142
|
-
throw new Error('Unable to retrieve Gun user private key');
|
143
|
-
}
|
144
|
-
|
145
|
-
const ethAccount = gun.gunToEthAccount(pair.priv);
|
146
|
-
|
147
|
-
document.getElementById('resultText').innerHTML = `
|
148
|
-
<strong>Gun User</strong>
|
149
|
-
<br>
|
150
|
-
${currentUser.is.alias}
|
151
|
-
<br>
|
152
|
-
<br>
|
153
|
-
<strong>Ethereum Address:</strong>
|
154
|
-
<br>
|
155
|
-
${ethAccount.publicKey}
|
156
|
-
`;
|
157
|
-
} catch (error) {
|
158
|
-
document.getElementById('resultText').innerText = 'Error: ' + error.message;
|
159
|
-
console.error('Conversion error:', error);
|
160
|
-
}
|
161
|
-
});
|
162
|
-
</script>
|
163
|
-
</body>
|
164
|
-
</html>
|
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>
|