gun-eth 1.2.3 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +30 -5
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,19 +1,44 @@
|
|
1
|
-
|
1
|
+
const Gun = require("gun/gun");
|
2
2
|
const SEA = require("gun/sea");
|
3
3
|
const ethers = require("ethers");
|
4
|
-
const SHINE = require("./SHINE.json");
|
4
|
+
const SHINE = require("./SHINE.json");
|
5
5
|
|
6
|
-
import Gun from "gun";
|
6
|
+
/* import Gun from "gun";
|
7
7
|
import SEA from "gun/sea";
|
8
8
|
import { ethers } from "ethers";
|
9
|
-
|
10
|
-
import SHINE from "./SHINE.json";
|
9
|
+
import SHINE from "./SHINE.json"; */
|
11
10
|
|
12
11
|
const SHINE_ABI = SHINE.abi;
|
13
12
|
const SHINE_OPTIMISM_SEPOLIA = SHINE.address;
|
14
13
|
|
15
14
|
let SHINE_CONTRACT_ADDRESS;
|
16
15
|
|
16
|
+
let customToken = "";
|
17
|
+
|
18
|
+
Gun.chain.setToken = function (token) {
|
19
|
+
if (typeof token === "string" && token.length > 0) {
|
20
|
+
customToken = token;
|
21
|
+
console.log("Token impostato con successo:", token);
|
22
|
+
} else {
|
23
|
+
console.error("Token non valido. Deve essere una stringa non vuota.");
|
24
|
+
}
|
25
|
+
return this;
|
26
|
+
};
|
27
|
+
|
28
|
+
Gun.on("opt", function (ctx) {
|
29
|
+
if (ctx.once) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
ctx.on("out", function (msg) {
|
33
|
+
var to = this.to;
|
34
|
+
// Usa il token personalizzato
|
35
|
+
msg.headers = {
|
36
|
+
token: customToken,
|
37
|
+
};
|
38
|
+
to.next(msg); // passa al prossimo middleware
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
17
42
|
// Aggiungi il metodo alla catena di Gun
|
18
43
|
Gun.chain.verifySignature = async function (message, signature) {
|
19
44
|
try {
|