gun-eth 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -111,19 +111,7 @@ Learn more about plugin implementation [here](https://github.com/amark/gun/wiki/
111
111
  ```javascript
112
112
  gun.shine("optimismSepolia", nodeId, data, callback);
113
113
  ```
114
-
115
- - `setToken(token)`: Sets a custom token for Gun operations.
116
-
117
- ```javascript
118
- gun.setToken("yourCustomToken");
119
- ```
120
-
121
- - `getToken()`: Retrieves the current custom token.
122
-
123
- ```javascript
124
- const currentToken = gun.getToken();
125
- ```
126
-
114
+
127
115
  ## SHINE
128
116
 
129
117
  SHINE (Secure Hash Integrity Network Ethereum) provides a mechanism for verifying data integrity using Ethereum and Gun.js.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  <!-- Include Ethers.js -->
11
11
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.7.0/ethers.umd.min.js"></script>
12
12
  <!-- Include the Gun-Eth plugin -->
13
- <script src="../gun-eth.js"></script>
13
+ <script src="https://cdn.jsdelivr.net/npm/gun-eth/src/gun-eth.js""></script>
14
14
  <style>
15
15
  body {
16
16
  font-family: Arial, sans-serif;
@@ -10,7 +10,7 @@
10
10
  <!-- Include Ethers.js -->
11
11
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.7.0/ethers.umd.min.js"></script>
12
12
  <!-- Include the Gun-Eth plugin -->
13
- <script src="../gun-eth.js"></script>
13
+ <script src="https://cdn.jsdelivr.net/npm/gun-eth/src/gun-eth.js""></script>
14
14
  <style>
15
15
  body {
16
16
  font-family: Arial, sans-serif;
package/src/gun-eth.js CHANGED
@@ -9,6 +9,7 @@
9
9
  })(typeof self !== "undefined" ? self : this, function (Gun, SEA, ethers) {
10
10
  console.log('Factory del plugin Gun-Eth chiamata');
11
11
 
12
+ const MESSAGE_TO_SIGN = "Accesso a GunDB con Ethereum";
12
13
 
13
14
 
14
15
  // Funzione per verificare se ethers è disponibile
@@ -180,7 +181,6 @@
180
181
 
181
182
  let SHINE_OPTIMISM_SEPOLIA = "0x43D838b683F772F08f321E5FA265ad3e333BE9C2";
182
183
  let SHINE_CONTRACT_ADDRESS;
183
- let customToken = "";
184
184
  let rpcUrl = "";
185
185
  let privateKey = "";
186
186
 
@@ -219,38 +219,6 @@
219
219
  return this;
220
220
  };
221
221
 
222
- /**
223
- * Sets a custom token for Gun operations.
224
- * @param {string} token - The token to be set.
225
- * @returns {Gun} The Gun instance for chaining.
226
- */
227
- Gun.chain.setToken = function (token) {
228
- if (typeof token === "string" && token.length > 0) {
229
- customToken = token;
230
- console.log("Token set successfully:", token);
231
- } else {
232
- console.error("Invalid token. Must be a non-empty string.");
233
- }
234
- return this;
235
- };
236
-
237
- /**
238
- * Retrieves the current custom token.
239
- * @returns {string} The current custom token.
240
- */
241
- Gun.chain.getToken = function () {
242
- return customToken;
243
- };
244
-
245
- // Add custom token to all 'put' operations
246
- Gun.on("put", function (msg) {
247
- const to = this.to;
248
- msg.headers = {
249
- token: customToken,
250
- };
251
- to.next(msg);
252
- });
253
-
254
222
  /**
255
223
  * Verifies an Ethereum signature.
256
224
  * @param {string} message - The original message that was signed.
@@ -291,6 +259,10 @@
291
259
  */
292
260
  Gun.chain.createSignature = async function (message) {
293
261
  try {
262
+ // Verifica se il messaggio è uguale a MESSAGE_TO_SIGN
263
+ if (message !== MESSAGE_TO_SIGN) {
264
+ throw new Error("Invalid message, valid message is: " + MESSAGE_TO_SIGN);
265
+ }
294
266
  const signer = await getSigner();
295
267
  const signature = await signer.signMessage(message);
296
268
  console.log("Signature created:", signature);
package/src/index.js CHANGED
@@ -7,11 +7,12 @@ const SHINE_ABI = SHINE.abi;
7
7
  const SHINE_OPTIMISM_SEPOLIA = SHINE.address;
8
8
 
9
9
  let SHINE_CONTRACT_ADDRESS;
10
- let customToken = "";
11
10
 
12
11
  let rpcUrl = "";
13
12
  let privateKey = "";
14
13
 
14
+ const MESSAGE_TO_SIGN = "Accesso a GunDB con Ethereum";
15
+
15
16
  /**
16
17
  * Funzione per ottenere il signer
17
18
  * @returns {Promise<ethers.Signer>} Il signer.
@@ -47,38 +48,6 @@ Gun.chain.setStandaloneConfig = function (newRpcUrl, newPrivateKey) {
47
48
  return this;
48
49
  };
49
50
 
50
- /**
51
- * Sets a custom token for Gun operations.
52
- * @param {string} token - The token to be set.
53
- * @returns {Gun} The Gun instance for chaining.
54
- */
55
- Gun.chain.setToken = function (token) {
56
- if (typeof token === "string" && token.length > 0) {
57
- customToken = token;
58
- console.log("Token set successfully:", token);
59
- } else {
60
- console.error("Invalid token. Must be a non-empty string.");
61
- }
62
- return this;
63
- };
64
-
65
- /**
66
- * Retrieves the current custom token.
67
- * @returns {string} The current custom token.
68
- */
69
- Gun.chain.getToken = function () {
70
- return customToken;
71
- };
72
-
73
- // Add custom token to all 'put' operations
74
- Gun.on("put", function (msg) {
75
- const to = this.to;
76
- msg.headers = {
77
- token: customToken,
78
- };
79
- to.next(msg);
80
- });
81
-
82
51
  /**
83
52
  * Verifies an Ethereum signature.
84
53
  * @param {string} message - The original message that was signed.
@@ -119,6 +88,10 @@ Gun.chain.generatePassword = function (signature) {
119
88
  */
120
89
  Gun.chain.createSignature = async function (message) {
121
90
  try {
91
+ // Verifica se il messaggio è uguale a MESSAGE_TO_SIGN
92
+ if (message !== MESSAGE_TO_SIGN) {
93
+ throw new Error("Invalid message, valid message is: " + MESSAGE_TO_SIGN);
94
+ }
122
95
  const signer = await getSigner();
123
96
  const signature = await signer.signMessage(message);
124
97
  console.log("Signature created:", signature);