gun-eth 1.4.16 → 1.4.18

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,21 +1,32 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.4.16",
3
+ "version": "1.4.18",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
5
  "main": "dist/gun-eth.cjs.js",
6
6
  "module": "dist/gun-eth.esm.js",
7
7
  "browser": "dist/gun-eth.min.js",
8
+ "unpkg": "dist/gun-eth.min.js",
9
+ "types": "dist/types/index.d.ts",
8
10
  "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/gun-eth.esm.js",
14
+ "require": "./dist/gun-eth.cjs.js",
15
+ "browser": "./dist/gun-eth.min.js"
16
+ }
17
+ },
9
18
  "scripts": {
19
+ "clean": "rimraf dist",
20
+ "build": "npm run clean && rollup -c",
21
+ "build:watch": "rollup -c -w",
10
22
  "test": "echo \"Error: no test specified\" && exit 1",
11
23
  "start-gun": "node startGun.js",
12
24
  "compile": "hardhat compile",
13
25
  "start-node": "hardhat node",
14
26
  "deploy-local": "hardhat run scripts/start-local-node.cjs --network localhost",
15
- "test-stealth": "cross-env NODE_ENV=development node --experimental-json-modules src/examples/stealth-example.js",
16
- "test-proof": "cross-env NODE_ENV=development node --experimental-json-modules src/examples/proof-example.js",
17
- "build": "rollup -c",
18
- "build:watch": "rollup -c -w"
27
+ "test-stealth": "cross-env NODE_ENV=development node --experimental-json-modules examples/stealth-example.js",
28
+ "test-proof": "cross-env NODE_ENV=development node --experimental-json-modules examples/proof-example.js",
29
+ "prepare": "npm run build"
19
30
  },
20
31
  "dependencies": {
21
32
  "ethers": "^6.0.0",
@@ -28,6 +39,10 @@
28
39
  "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
29
40
  "@nomicfoundation/hardhat-toolbox": "^3.0.0",
30
41
  "@nomicfoundation/hardhat-verify": "^1.0.0",
42
+ "@rollup/plugin-commonjs": "^25.0.0",
43
+ "@rollup/plugin-json": "^6.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.0",
45
+ "@rollup/plugin-terser": "^0.4.0",
31
46
  "@typechain/ethers-v6": "^0.4.0",
32
47
  "@typechain/hardhat": "^8.0.0",
33
48
  "@types/chai": "^4.2.0",
@@ -36,15 +51,12 @@
36
51
  "cross-env": "^7.0.3",
37
52
  "hardhat": "^2.17.0",
38
53
  "hardhat-gas-reporter": "^1.0.8",
54
+ "rimraf": "^5.0.0",
55
+ "rollup": "^3.0.0",
39
56
  "solidity-coverage": "^0.8.1",
40
57
  "ts-node": "^10.9.1",
41
58
  "typechain": "^8.2.0",
42
- "typescript": "^5.0.0",
43
- "@rollup/plugin-commonjs": "^25.0.0",
44
- "@rollup/plugin-node-resolve": "^15.0.0",
45
- "@rollup/plugin-json": "^6.0.0",
46
- "@rollup/plugin-terser": "^0.4.0",
47
- "rollup": "^3.0.0"
59
+ "typescript": "^5.0.0"
48
60
  },
49
61
  "author": "scobru",
50
62
  "repository": {
@@ -67,6 +79,7 @@
67
79
  },
68
80
  "homepage": "https://github.com/scobru/gun-eth#readme",
69
81
  "files": [
70
- "dist"
82
+ "dist",
83
+ "src"
71
84
  ]
72
85
  }
@@ -0,0 +1,391 @@
1
+ import { LOCAL_CONFIG } from '../config/local.js';
2
+
3
+ // Indirizzi di produzione per diverse chain
4
+ export const CHAIN_CONFIG = {
5
+ optimismSepolia: {
6
+ STEALTH_ANNOUNCER_ADDRESS: "",
7
+ PROOF_OF_INTEGRITY_ADDRESS: "",
8
+ RPC_URL: "https://sepolia.optimism.io",
9
+ CHAIN_ID: 11155420
10
+ },
11
+ arbitrumSepolia: {
12
+ STEALTH_ANNOUNCER_ADDRESS: "",
13
+ PROOF_OF_INTEGRITY_ADDRESS: "",
14
+ RPC_URL: "https://sepolia-rollup.arbitrum.io/rpc",
15
+ CHAIN_ID: 421614
16
+ },
17
+ localhost: {
18
+ RPC_URL: "http://127.0.0.1:8545",
19
+ CHAIN_ID: 1337
20
+ }
21
+ };
22
+
23
+ // Funzione per ottenere gli indirizzi corretti
24
+ export function getAddressesForChain(chainName) {
25
+ let config;
26
+
27
+ // Se è localhost, prova a caricare gli indirizzi locali
28
+ if (chainName === 'localhost') {
29
+ try {
30
+ // Carica gli indirizzi dal file generato dal deploy locale
31
+ const localAddresses = require('../config/contract-address.json');
32
+ config = {
33
+ ...CHAIN_CONFIG.localhost,
34
+ ...localAddresses
35
+ };
36
+ console.log("Using local addresses:", config);
37
+ return config;
38
+ } catch (err) {
39
+ console.warn('No local addresses found');
40
+ throw new Error('No local addresses found. Did you run local deployment?');
41
+ }
42
+ }
43
+
44
+ // Altrimenti usa gli indirizzi di produzione
45
+ config = CHAIN_CONFIG[chainName];
46
+ if (!config) {
47
+ throw new Error(`Chain ${chainName} not supported. Supported chains: ${Object.keys(CHAIN_CONFIG).join(', ')}`);
48
+ }
49
+
50
+ return config;
51
+ }
52
+
53
+ // Funzione helper per verificare se siamo in ambiente locale
54
+ export function isLocalEnvironment() {
55
+ return process.env.NODE_ENV === 'development' &&
56
+ typeof window !== 'undefined' &&
57
+ window.location.hostname === 'localhost';
58
+ }
59
+
60
+ export const STEALTH_ANNOUNCER_ABI = [
61
+ {
62
+ "inputs": [
63
+ {
64
+ "internalType": "address",
65
+ "name": "_devAddress",
66
+ "type": "address"
67
+ }
68
+ ],
69
+ "stateMutability": "nonpayable",
70
+ "type": "constructor"
71
+ },
72
+ {
73
+ "anonymous": false,
74
+ "inputs": [
75
+ {
76
+ "internalType": "string",
77
+ "name": "senderPublicKey",
78
+ "type": "string"
79
+ },
80
+ {
81
+ "internalType": "string",
82
+ "name": "spendingPublicKey",
83
+ "type": "string"
84
+ },
85
+ {
86
+ "internalType": "address",
87
+ "name": "stealthAddress",
88
+ "type": "address"
89
+ },
90
+ {
91
+ "internalType": "uint256",
92
+ "name": "timestamp",
93
+ "type": "uint256"
94
+ }
95
+ ],
96
+ "name": "StealthPaymentAnnounced",
97
+ "type": "event"
98
+ },
99
+ {
100
+ "anonymous": false,
101
+ "inputs": [
102
+ {
103
+ "internalType": "address",
104
+ "name": "newAddress",
105
+ "type": "address"
106
+ }
107
+ ],
108
+ "name": "DevAddressUpdated",
109
+ "type": "event"
110
+ },
111
+ {
112
+ "anonymous": false,
113
+ "inputs": [
114
+ {
115
+ "internalType": "uint256",
116
+ "name": "newFee",
117
+ "type": "uint256"
118
+ }
119
+ ],
120
+ "name": "DevFeeUpdated",
121
+ "type": "event"
122
+ },
123
+ {
124
+ "inputs": [
125
+ {
126
+ "internalType": "string",
127
+ "name": "senderPublicKey",
128
+ "type": "string"
129
+ },
130
+ {
131
+ "internalType": "string",
132
+ "name": "spendingPublicKey",
133
+ "type": "string"
134
+ },
135
+ {
136
+ "internalType": "address",
137
+ "name": "stealthAddress",
138
+ "type": "address"
139
+ }
140
+ ],
141
+ "name": "announcePayment",
142
+ "outputs": [],
143
+ "stateMutability": "payable",
144
+ "type": "function"
145
+ },
146
+ {
147
+ "inputs": [],
148
+ "name": "devAddress",
149
+ "outputs": [
150
+ {
151
+ "internalType": "address",
152
+ "name": "",
153
+ "type": "address"
154
+ }
155
+ ],
156
+ "stateMutability": "view",
157
+ "type": "function"
158
+ },
159
+ {
160
+ "inputs": [],
161
+ "name": "devFee",
162
+ "outputs": [
163
+ {
164
+ "internalType": "uint256",
165
+ "name": "",
166
+ "type": "uint256"
167
+ }
168
+ ],
169
+ "stateMutability": "view",
170
+ "type": "function"
171
+ },
172
+ {
173
+ "inputs": [],
174
+ "name": "getAnnouncementsCount",
175
+ "outputs": [
176
+ {
177
+ "internalType": "uint256",
178
+ "name": "",
179
+ "type": "uint256"
180
+ }
181
+ ],
182
+ "stateMutability": "view",
183
+ "type": "function"
184
+ },
185
+ {
186
+ "inputs": [
187
+ {
188
+ "internalType": "uint256",
189
+ "name": "fromIndex",
190
+ "type": "uint256"
191
+ },
192
+ {
193
+ "internalType": "uint256",
194
+ "name": "toIndex",
195
+ "type": "uint256"
196
+ }
197
+ ],
198
+ "name": "getAnnouncementsInRange",
199
+ "outputs": [
200
+ {
201
+ "components": [
202
+ {
203
+ "internalType": "string",
204
+ "name": "senderPublicKey",
205
+ "type": "string"
206
+ },
207
+ {
208
+ "internalType": "string",
209
+ "name": "spendingPublicKey",
210
+ "type": "string"
211
+ },
212
+ {
213
+ "internalType": "address",
214
+ "name": "stealthAddress",
215
+ "type": "address"
216
+ },
217
+ {
218
+ "internalType": "uint256",
219
+ "name": "timestamp",
220
+ "type": "uint256"
221
+ }
222
+ ],
223
+ "internalType": "struct StealthAnnouncer.StealthAnnouncement[]",
224
+ "name": "",
225
+ "type": "tuple[]"
226
+ }
227
+ ],
228
+ "stateMutability": "view",
229
+ "type": "function"
230
+ },
231
+ {
232
+ "inputs": [
233
+ {
234
+ "internalType": "uint256",
235
+ "name": "_newFee",
236
+ "type": "uint256"
237
+ }
238
+ ],
239
+ "name": "updateDevFee",
240
+ "outputs": [],
241
+ "stateMutability": "nonpayable",
242
+ "type": "function"
243
+ },
244
+ {
245
+ "inputs": [
246
+ {
247
+ "internalType": "address",
248
+ "name": "_newAddress",
249
+ "type": "address"
250
+ }
251
+ ],
252
+ "name": "updateDevAddress",
253
+ "outputs": [],
254
+ "stateMutability": "nonpayable",
255
+ "type": "function"
256
+ },
257
+ {
258
+ "inputs": [],
259
+ "name": "withdrawStuckETH",
260
+ "outputs": [],
261
+ "stateMutability": "nonpayable",
262
+ "type": "function"
263
+ }
264
+ ];
265
+
266
+ export const PROOF_OF_INTEGRITY_ABI = [
267
+ {
268
+ "inputs": [
269
+ {
270
+ "internalType": "bytes[]",
271
+ "name": "nodeIds",
272
+ "type": "bytes[]"
273
+ },
274
+ {
275
+ "internalType": "bytes32[]",
276
+ "name": "contentHashes",
277
+ "type": "bytes32[]"
278
+ }
279
+ ],
280
+ "name": "batchUpdateData",
281
+ "outputs": [],
282
+ "stateMutability": "nonpayable",
283
+ "type": "function"
284
+ },
285
+ {
286
+ "anonymous": false,
287
+ "inputs": [
288
+ {
289
+ "indexed": true,
290
+ "internalType": "bytes",
291
+ "name": "nodeId",
292
+ "type": "bytes"
293
+ },
294
+ {
295
+ "indexed": false,
296
+ "internalType": "bytes32",
297
+ "name": "contentHash",
298
+ "type": "bytes32"
299
+ },
300
+ {
301
+ "indexed": false,
302
+ "internalType": "address",
303
+ "name": "updater",
304
+ "type": "address"
305
+ }
306
+ ],
307
+ "name": "DataUpdated",
308
+ "type": "event"
309
+ },
310
+ {
311
+ "inputs": [
312
+ {
313
+ "internalType": "bytes",
314
+ "name": "nodeId",
315
+ "type": "bytes"
316
+ }
317
+ ],
318
+ "name": "getLatestRecord",
319
+ "outputs": [
320
+ {
321
+ "internalType": "bytes32",
322
+ "name": "",
323
+ "type": "bytes32"
324
+ },
325
+ {
326
+ "internalType": "uint256",
327
+ "name": "",
328
+ "type": "uint256"
329
+ },
330
+ {
331
+ "internalType": "address",
332
+ "name": "",
333
+ "type": "address"
334
+ }
335
+ ],
336
+ "stateMutability": "view",
337
+ "type": "function"
338
+ },
339
+ {
340
+ "inputs": [
341
+ {
342
+ "internalType": "bytes",
343
+ "name": "nodeId",
344
+ "type": "bytes"
345
+ },
346
+ {
347
+ "internalType": "bytes32",
348
+ "name": "contentHash",
349
+ "type": "bytes32"
350
+ }
351
+ ],
352
+ "name": "updateData",
353
+ "outputs": [],
354
+ "stateMutability": "nonpayable",
355
+ "type": "function"
356
+ },
357
+ {
358
+ "inputs": [
359
+ {
360
+ "internalType": "bytes",
361
+ "name": "nodeId",
362
+ "type": "bytes"
363
+ },
364
+ {
365
+ "internalType": "bytes32",
366
+ "name": "contentHash",
367
+ "type": "bytes32"
368
+ }
369
+ ],
370
+ "name": "verifyData",
371
+ "outputs": [
372
+ {
373
+ "internalType": "bool",
374
+ "name": "",
375
+ "type": "bool"
376
+ },
377
+ {
378
+ "internalType": "uint256",
379
+ "name": "",
380
+ "type": "uint256"
381
+ },
382
+ {
383
+ "internalType": "address",
384
+ "name": "",
385
+ "type": "address"
386
+ }
387
+ ],
388
+ "stateMutability": "view",
389
+ "type": "function"
390
+ }
391
+ ];
@@ -0,0 +1,4 @@
1
+ {
2
+ "STEALTH_ANNOUNCER_ADDRESS": "",
3
+ "PROOF_OF_INTEGRITY_ADDRESS": ""
4
+ }
@@ -0,0 +1,29 @@
1
+ let contractAddresses = {
2
+ PROOF_OF_INTEGRITY_ADDRESS: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
3
+ STEALTH_ANNOUNCER_ADDRESS: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
4
+ };
5
+
6
+ if (typeof window === 'undefined') {
7
+ const { fileURLToPath } = require('url');
8
+ const { dirname } = require('path');
9
+ const { readFileSync } = require('fs');
10
+ const { join } = require('path');
11
+
12
+ try {
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = dirname(__filename);
15
+ const rawdata = readFileSync(join(__dirname, 'contract-address.json'), 'utf8');
16
+ contractAddresses = JSON.parse(rawdata);
17
+ console.log("Loaded contract addresses:", contractAddresses);
18
+ } catch (error) {
19
+ console.warn("Warning: contract-address.json not found or invalid");
20
+ }
21
+ }
22
+
23
+ export const LOCAL_CONFIG = {
24
+ CHAIN_ID: 1337,
25
+ PROOF_OF_INTEGRITY_ADDRESS: contractAddresses.PROOF_OF_INTEGRITY_ADDRESS,
26
+ STEALTH_ANNOUNCER_ADDRESS: contractAddresses.STEALTH_ANNOUNCER_ADDRESS,
27
+ RPC_URL: "http://127.0.0.1:8545",
28
+ GUN_PEER: "http://localhost:8765/gun"
29
+ };