gun-eth 1.4.29 → 1.4.31
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/gun-eth.cjs.js +25 -24145
- package/dist/gun-eth.cjs.js.map +1 -1
- package/dist/gun-eth.esm.js +1368 -9
- package/dist/gun-eth.esm.js.map +1 -1
- package/dist/gun-eth.min.js +1 -9
- package/dist/gun-eth.min.js.map +1 -1
- package/dist/gun-eth.mjs +37 -24157
- package/dist/gun-eth.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.js +31 -32
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "gun-eth",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.31",
|
4
4
|
"description": "A GunDB plugin for Ethereum, and Web3",
|
5
5
|
"main": "dist/gun-eth.cjs.js",
|
6
6
|
"module": "dist/gun-eth.mjs",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"import": "./dist/gun-eth.esm.js",
|
17
17
|
"require": "./dist/gun-eth.min.js"
|
18
18
|
},
|
19
|
-
"default": "./dist/gun-eth.
|
19
|
+
"default": "./dist/gun-eth.cjs.js"
|
20
20
|
}
|
21
21
|
},
|
22
22
|
"type": "module",
|
@@ -58,7 +58,7 @@
|
|
58
58
|
"@types/mocha": "^10.0.1",
|
59
59
|
"chai": "^4.2.0",
|
60
60
|
"cross-env": "^7.0.3",
|
61
|
-
"ethers": "^6.
|
61
|
+
"ethers": "^6.13.4",
|
62
62
|
"gun": "^0.2020.1239",
|
63
63
|
"hardhat": "^2.17.0",
|
64
64
|
"hardhat-gas-reporter": "^1.0.8",
|
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,19 @@ 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';
|
18
|
+
import {
|
19
|
+
JsonRpcProvider,
|
20
|
+
BrowserProvider,
|
21
|
+
Wallet,
|
22
|
+
Contract,
|
23
|
+
concat,
|
24
|
+
keccak256,
|
25
|
+
verifyMessage,
|
26
|
+
getBytes
|
27
|
+
} from 'ethers';
|
28
28
|
|
29
29
|
let PROOF_CONTRACT_ADDRESS;
|
30
30
|
let rpcUrl = "";
|
@@ -39,20 +39,19 @@ let contractAddresses = {
|
|
39
39
|
|
40
40
|
// Solo per Node.js
|
41
41
|
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
42
|
try {
|
51
|
-
const
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
43
|
+
const __filename = fileURLToPath(import.meta.url);
|
44
|
+
const __dirname = dirname(__filename);
|
45
|
+
|
46
|
+
try {
|
47
|
+
const rawdata = readFileSync(path.join(__dirname, 'contract-address.json'), 'utf8');
|
48
|
+
contractAddresses = JSON.parse(rawdata);
|
49
|
+
console.log('Loaded contract addresses:', contractAddresses);
|
50
|
+
} catch (err) {
|
51
|
+
console.warn('Warning: contract-address.json not found or invalid');
|
52
|
+
}
|
53
|
+
} catch (error) {
|
54
|
+
console.error('Error loading Node.js modules:', error);
|
56
55
|
}
|
57
56
|
}
|
58
57
|
|
@@ -64,8 +63,8 @@ if (typeof window === 'undefined') {
|
|
64
63
|
* @returns {string} A random hexadecimal string
|
65
64
|
*/
|
66
65
|
export function generateRandomId() {
|
67
|
-
const
|
68
|
-
return hexlify(
|
66
|
+
const randomBytes = ethers.randomBytes(32);
|
67
|
+
return ethers.hexlify(randomBytes).slice(2);
|
69
68
|
}
|
70
69
|
|
71
70
|
/**
|
@@ -75,8 +74,8 @@ export function generateRandomId() {
|
|
75
74
|
*/
|
76
75
|
export function generatePassword(signature) {
|
77
76
|
try {
|
78
|
-
const signatureBytes = getBytes(signature);
|
79
|
-
const hash = keccak256(signatureBytes);
|
77
|
+
const signatureBytes = ethers.getBytes(signature);
|
78
|
+
const hash = ethers.keccak256(signatureBytes);
|
80
79
|
console.log("Generated password:", hash);
|
81
80
|
return hash;
|
82
81
|
} catch (error) {
|
@@ -124,7 +123,7 @@ export function gunToEthAccount(gunPrivateKey) {
|
|
124
123
|
*/
|
125
124
|
export const getSigner = async () => {
|
126
125
|
if (rpcUrl && privateKey) {
|
127
|
-
const provider = new JsonRpcProvider(rpcUrl, {
|
126
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl, {
|
128
127
|
chainId: LOCAL_CONFIG.CHAIN_ID,
|
129
128
|
name: "localhost"
|
130
129
|
});
|