gun-eth 1.2.8 → 1.2.9

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/package.json +1 -1
  2. package/src/index.js +23 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -12,6 +12,28 @@ let customToken = "";
12
12
  let rpcUrl = "";
13
13
  let privateKey = "";
14
14
 
15
+ /**
16
+ * Funzione per ottenere il signer
17
+ * @returns {Promise<ethers.Signer>} Il signer.
18
+ */
19
+ const getSigner = async () => {
20
+ if (rpcUrl && privateKey) {
21
+ // Modalità standalone
22
+ const provider = new ethers.JsonRpcProvider(rpcUrl);
23
+ return new ethers.Wallet(privateKey, provider);
24
+ } else if (
25
+ typeof window !== "undefined" &&
26
+ typeof window.ethereum !== "undefined"
27
+ ) {
28
+ // Modalità browser
29
+ await window.ethereum.request({ method: "eth_requestAccounts" });
30
+ const provider = new ethers.BrowserProvider(window.ethereum);
31
+ return provider.getSigner();
32
+ } else {
33
+ throw new Error("No valid Ethereum provider found");
34
+ }
35
+ };
36
+
15
37
  /**
16
38
  * Sets standalone configuration for Gun.
17
39
  * @param {string} newRpcUrl - The new RPC URL.
@@ -175,30 +197,10 @@ Gun.chain.shine = function (chain, nodeId, data, callback) {
175
197
  } else {
176
198
  throw new Error("Chain not supported");
177
199
  }
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
200
  // Funzione per verificare on-chain
199
201
  const verifyOnChain = async (nodeId, contentHash) => {
200
202
  console.log("Verifying on chain:", { nodeId, contentHash });
201
- const signer = await getSigner();
203
+ const signer = await this.getSigner();
202
204
  const contract = new ethers.Contract(
203
205
  SHINE_CONTRACT_ADDRESS,
204
206
  SHINE_ABI,