-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeytoPk.js
41 lines (26 loc) · 1.03 KB
/
keytoPk.js
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
import { config } from 'dotenv';
import Keythereum from 'keythereum';
config();
const { PASSWORD, ADDRESS, KEYSTORE_DIR } = process.env;
export async function decrypt() {
try {
// The address of which you want to decrypt keystore.
const address = ADDRESS;
// The directory where the keystore folder saved. - Should Be Save in "keystore" folder
const dir = KEYSTORE_DIR;
// phrase to unlock the address which you insert
const passphrase = PASSWORD;
const keyObject = Keythereum.importFromFile(address, dir);
console.log("key object ok");
const privateKey = await Keythereum.recover(passphrase, keyObject);
console.log("privateKey ok")
// Print out the decryptized Keystore -> privateKey
const result = privateKey.toString('hex');
console.log("Derived Private Key: %o", result);
return result;
} catch (error) {
console.log("Error: %o", { error });
throw new Error(`Error: ${error}`);
}
}
await decrypt();