-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
53 lines (29 loc) · 1022 Bytes
/
functions.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
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require("fs")
const Web3 = require("web3")
const web3 = new Web3 ("http://127.0.0.1:8545")
const createWallet = () => {
const wallet = web3.eth.accounts.create()
const privateKey = wallet.privateKey
return privateKey
}
const generateKeyStore = (key, password) => {
const keystore = web3.eth.accounts.encrypt(key, password)
const keystoreToString = JSON.stringify(keystore)
const wallet = web3.eth.accounts.privateKeyToAccount(key, false)
fs.writeFile("./keys/" + wallet.address + ".keystore", keystoreToString, (err)=>{
if(err) {
console.log(err)
}
console.log("keystore file created")
})
}
const getKeyStore = (file, password) => {
fs.readFile(file, "utf-8", (err, keyStore)=>{
if (err) {
console.log(err)
}
const wallet = web3.eth.accounts.decrypt(keyStore, password)
console.log(wallet)
})
}
module.exports = { createWallet, generateKeyStore, getKeyStore }