gun-eth 1.2.3 → 1.2.5

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.
Files changed (2) hide show
  1. package/index.js +30 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,19 +1,44 @@
1
- /* const Gun = require("gun/gun");
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "index.js",
6
6
  "scripts": {