gun-eth 1.4.28 → 1.4.30

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,18 +1,32 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.4.28",
3
+ "version": "1.4.30",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "dist/gun-eth.cjs.js",
6
- "module": "dist/gun-eth.esm.js",
6
+ "module": "dist/gun-eth.mjs",
7
7
  "browser": "dist/gun-eth.min.js",
8
8
  "exports": {
9
9
  ".": {
10
- "require": "./dist/gun-eth.cjs.js",
11
- "import": "./dist/gun-eth.esm.js",
12
- "browser": "./dist/gun-eth.min.js"
10
+ "types": "./dist/types/index.d.ts",
11
+ "node": {
12
+ "import": "./dist/gun-eth.mjs",
13
+ "require": "./dist/gun-eth.cjs.js"
14
+ },
15
+ "browser": {
16
+ "import": "./dist/gun-eth.esm.js",
17
+ "require": "./dist/gun-eth.min.js"
18
+ },
19
+ "default": "./dist/gun-eth.cjs.js"
13
20
  }
14
21
  },
15
22
  "type": "module",
23
+ "typesVersions": {
24
+ "*": {
25
+ "*": [
26
+ "dist/types/*"
27
+ ]
28
+ }
29
+ },
16
30
  "scripts": {
17
31
  "test": "echo \"Error: no test specified\" && exit 1",
18
32
  "start-gun": "node startGun.js",
package/src/index.js CHANGED
@@ -3,20 +3,7 @@
3
3
  // =============================================
4
4
  import Gun from "gun";
5
5
  import SEA from "gun/sea.js";
6
- import {
7
- ethers,
8
- JsonRpcProvider,
9
- BrowserProvider,
10
- Contract,
11
- Wallet,
12
- getBytes,
13
- concat,
14
- toUtf8Bytes,
15
- keccak256,
16
- verifyMessage,
17
- randomBytes,
18
- hexlify
19
- } from "ethers/lib/ethers.js";
6
+ import { ethers } from "ethers";
20
7
  import {
21
8
  PROOF_OF_INTEGRITY_ABI,
22
9
  STEALTH_ANNOUNCER_ABI,
@@ -25,6 +12,9 @@ import {
25
12
  CHAIN_CONFIG
26
13
  } from "./abis/abis.js";
27
14
  import { LOCAL_CONFIG } from "./config/local.js";
15
+ import { fileURLToPath } from 'url';
16
+ import { dirname } from 'path';
17
+ import { readFileSync } from 'fs';
28
18
 
29
19
  let PROOF_CONTRACT_ADDRESS;
30
20
  let rpcUrl = "";
@@ -39,20 +29,19 @@ let contractAddresses = {
39
29
 
40
30
  // Solo per Node.js
41
31
  if (typeof window === 'undefined') {
42
- const { fileURLToPath } = require('url');
43
- const { dirname } = require('path');
44
- const { readFileSync } = require('fs');
45
- const path = require('path');
46
-
47
- const __filename = fileURLToPath(import.meta.url);
48
- const __dirname = dirname(__filename);
49
-
50
32
  try {
51
- const rawdata = readFileSync(path.join(__dirname, 'contract-address.json'), 'utf8');
52
- contractAddresses = JSON.parse(rawdata);
53
- console.log('Loaded contract addresses:', contractAddresses);
54
- } catch (err) {
55
- console.warn('Warning: contract-address.json not found or invalid');
33
+ const __filename = fileURLToPath(import.meta.url);
34
+ const __dirname = dirname(__filename);
35
+
36
+ try {
37
+ const rawdata = readFileSync(path.join(__dirname, 'contract-address.json'), 'utf8');
38
+ contractAddresses = JSON.parse(rawdata);
39
+ console.log('Loaded contract addresses:', contractAddresses);
40
+ } catch (err) {
41
+ console.warn('Warning: contract-address.json not found or invalid');
42
+ }
43
+ } catch (error) {
44
+ console.error('Error loading Node.js modules:', error);
56
45
  }
57
46
  }
58
47
 
@@ -64,8 +53,8 @@ if (typeof window === 'undefined') {
64
53
  * @returns {string} A random hexadecimal string
65
54
  */
66
55
  export function generateRandomId() {
67
- const bytes = randomBytes(32);
68
- return hexlify(bytes).slice(2);
56
+ const randomBytes = ethers.randomBytes(32);
57
+ return ethers.hexlify(randomBytes).slice(2);
69
58
  }
70
59
 
71
60
  /**
@@ -75,8 +64,8 @@ export function generateRandomId() {
75
64
  */
76
65
  export function generatePassword(signature) {
77
66
  try {
78
- const signatureBytes = getBytes(signature);
79
- const hash = keccak256(signatureBytes);
67
+ const signatureBytes = ethers.getBytes(signature);
68
+ const hash = ethers.keccak256(signatureBytes);
80
69
  console.log("Generated password:", hash);
81
70
  return hash;
82
71
  } catch (error) {
@@ -124,17 +113,17 @@ export function gunToEthAccount(gunPrivateKey) {
124
113
  */
125
114
  export const getSigner = async () => {
126
115
  if (rpcUrl && privateKey) {
127
- const provider = new JsonRpcProvider(rpcUrl, {
116
+ const provider = new ethers.JsonRpcProvider(rpcUrl, {
128
117
  chainId: LOCAL_CONFIG.CHAIN_ID,
129
118
  name: "localhost"
130
119
  });
131
- return new Wallet(privateKey, provider);
120
+ return new ethers.Wallet(privateKey, provider);
132
121
  } else if (
133
122
  typeof window !== "undefined" &&
134
123
  typeof window.ethereum !== "undefined"
135
124
  ) {
136
125
  await window.ethereum.request({ method: "eth_requestAccounts" });
137
- const provider = new BrowserProvider(window.ethereum);
126
+ const provider = new ethers.BrowserProvider(window.ethereum);
138
127
  return provider.getSigner();
139
128
  } else {
140
129
  throw new Error("No valid Ethereum provider found");
@@ -149,17 +138,17 @@ export const getSigner = async () => {
149
138
  */
150
139
  export function deriveStealthAddress(sharedSecret, spendingPublicKey) {
151
140
  try {
152
- const sharedSecretBytes = getBytes(sharedSecret);
153
- const spendingPublicKeyBytes = getBytes(spendingPublicKey);
141
+ const sharedSecretBytes = ethers.getBytes(sharedSecret);
142
+ const spendingPublicKeyBytes = ethers.getBytes(spendingPublicKey);
154
143
 
155
- const stealthPrivateKey = keccak256(
156
- concat([
144
+ const stealthPrivateKey = ethers.keccak256(
145
+ ethers.concat([
157
146
  sharedSecretBytes,
158
147
  spendingPublicKeyBytes
159
148
  ])
160
149
  );
161
150
 
162
- const stealthWallet = new Wallet(stealthPrivateKey);
151
+ const stealthWallet = new ethers.Wallet(stealthPrivateKey);
163
152
 
164
153
  console.log("Debug deriveStealthAddress:", {
165
154
  sharedSecretHex: stealthPrivateKey,
@@ -209,7 +198,7 @@ Gun.chain.getSigner = getSigner();
209
198
  */
210
199
  Gun.chain.verifySignature = async function (message, signature) {
211
200
  try {
212
- const recoveredAddress = verifyMessage(message, signature);
201
+ const recoveredAddress = ethers.verifyMessage(message, signature);
213
202
  return recoveredAddress;
214
203
  } catch (error) {
215
204
  console.error("Error verifying signature:", error);