gun-eth 1.2.8 → 1.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +30 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -1,7 +1,12 @@
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("../abis/SHINE.json");
4
+ const SHINE = require("../abis/SHINE.json"); */
5
+
6
+ import { ethers } from "ethers";
7
+ import SHINE from "../abis/SHINE.json";
8
+ import SEA from "gun/sea";
9
+ import Gun from "gun";
5
10
 
6
11
  const SHINE_ABI = SHINE.abi;
7
12
  const SHINE_OPTIMISM_SEPOLIA = SHINE.address;
@@ -12,6 +17,28 @@ let customToken = "";
12
17
  let rpcUrl = "";
13
18
  let privateKey = "";
14
19
 
20
+ /**
21
+ * Funzione per ottenere il signer
22
+ * @returns {Promise<ethers.Signer>} Il signer.
23
+ */
24
+ const getSigner = async () => {
25
+ if (rpcUrl && privateKey) {
26
+ // Modalità standalone
27
+ const provider = new ethers.JsonRpcProvider(rpcUrl);
28
+ return new ethers.Wallet(privateKey, provider);
29
+ } else if (
30
+ typeof window !== "undefined" &&
31
+ typeof window.ethereum !== "undefined"
32
+ ) {
33
+ // Modalità browser
34
+ await window.ethereum.request({ method: "eth_requestAccounts" });
35
+ const provider = new ethers.BrowserProvider(window.ethereum);
36
+ return provider.getSigner();
37
+ } else {
38
+ throw new Error("No valid Ethereum provider found");
39
+ }
40
+ };
41
+
15
42
  /**
16
43
  * Sets standalone configuration for Gun.
17
44
  * @param {string} newRpcUrl - The new RPC URL.
@@ -175,30 +202,10 @@ Gun.chain.shine = function (chain, nodeId, data, callback) {
175
202
  } else {
176
203
  throw new Error("Chain not supported");
177
204
  }
178
-
179
- // Funzione per ottenere il signer
180
- const getSigner = async () => {
181
- if (rpcUrl && privateKey) {
182
- // Modalità standalone
183
- const provider = new ethers.JsonRpcProvider(rpcUrl);
184
- return new ethers.Wallet(privateKey, provider);
185
- } else if (
186
- typeof window !== "undefined" &&
187
- typeof window.ethereum !== "undefined"
188
- ) {
189
- // Modalità browser
190
- await window.ethereum.request({ method: "eth_requestAccounts" });
191
- const provider = new ethers.BrowserProvider(window.ethereum);
192
- return provider.getSigner();
193
- } else {
194
- throw new Error("No valid Ethereum provider found");
195
- }
196
- };
197
-
198
205
  // Funzione per verificare on-chain
199
206
  const verifyOnChain = async (nodeId, contentHash) => {
200
207
  console.log("Verifying on chain:", { nodeId, contentHash });
201
- const signer = await getSigner();
208
+ const signer = await this.getSigner();
202
209
  const contract = new ethers.Contract(
203
210
  SHINE_CONTRACT_ADDRESS,
204
211
  SHINE_ABI,