-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwallet_details.js
More file actions
96 lines (75 loc) · 3.04 KB
/
Copy pathwallet_details.js
File metadata and controls
96 lines (75 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { mnemonicToSeedSync } from "bip39";
import { computeCreateAddress } from "./utils/precompute-core-address.js";
import { hdkey } from "@ethereumjs/wallet";
import { writeFileSync } from "fs";
const contract_addresses = [
"ACL_CONTRACT_ADDRESS",
"FHEVM_COPROCESSOR_ADDRESS",
"KMS_VERIFIER_CONTRACT_ADDRESS",
]
async function deriveWalletsAndDetails(mnemonic) {
const seed = mnemonicToSeedSync(mnemonic);
const hdWallet = hdkey.EthereumHDKey.fromMasterSeed(seed);
const wallets = [
hdWallet.derivePath(`m/44'/60'/0'/0/0`).getWallet(),
hdWallet.derivePath(`m/44'/60'/0'/0/1`).getWallet(),
hdWallet.derivePath(`m/44'/60'/0'/0/2`).getWallet(),
];
const [coreWallet, gatewayWallet, relayerWallet] = wallets;
const deployerAddressCore = coreWallet.getAddressString();
const deployerAddressGateway = gatewayWallet.getAddressString();
const relayerAddress = relayerWallet.getAddressString();
return {
deployerAddressCore,
deployerAddressGateway,
relayerAddress
};
}
async function walletDetails() {
const mnemonicFlagIndex = process.argv.indexOf("--mnemonic");
let mnemonic;
if (mnemonicFlagIndex > -1 && mnemonicFlagIndex + 1 < process.argv.length) {
mnemonic = process.argv[mnemonicFlagIndex + 1];
} else {
console.error(formatDate(), "- Error: Please provide the mnemonic using the --mnemonic flag.");
process.exit(1);
}
const outputFlagIndex = process.argv.indexOf("--output"); // ✅ Corrected
let output;
if (outputFlagIndex > -1 && outputFlagIndex + 1 < process.argv.length) {
output = process.argv[outputFlagIndex + 1];
} else {
console.error(formatDate(), "- Error: Please provide the output using the --output flag.");
process.exit(1);
}
const deploymentData = {
"aclContractAddress": "",
"tfheExecutorAddress": "",
"kmsVerifierAddress": "",
"gatewayContractAddress": "",
"relayerGAddress": ""
}
const {
deployerAddressCore,
deployerAddressGateway,
relayerAddress
} = await deriveWalletsAndDetails(mnemonic);
for (let index = 0; index < contract_addresses.length; index++) {
const contractAddress = computeCreateAddress(deployerAddressCore, index);
if (index === 0) {
deploymentData.aclContractAddress = contractAddress;
} else if (index === 1) {
deploymentData.tfheExecutorAddress = contractAddress;
} else if (index === 2) {
deploymentData.kmsVerifierAddress = contractAddress;
}
}
const contractAddress = computeCreateAddress(deployerAddressGateway, 0);
deploymentData.gatewayContractAddress = contractAddress;
deploymentData.relayerGAddress = relayerAddress;
writeFileSync(`${output}/init_rollup_fhe_keys.json`, JSON.stringify(deploymentData, null, 2));
console.log("Wallets and contract addresses have been computed and saved to init_rollup_fhe_keys.json");
}
(async () => {
await walletDetails();
})();