-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 876 Bytes
/
index.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
const fs = require('fs')
const Caver = require('caver-js')
async function loadPassword() {
var read = require('read')
return new Promise((resolve, reject)=> {
read({ prompt: 'Password: ', silent: true }, function(er, password) {
if(er) {
reject(er)
return
}
resolve(password)
})
})
}
async function loadKeystore(filepath) {
const keystore = fs.readFileSync(filepath, 'utf8')
const password = await loadPassword()
return new Caver().wallet.keyring.decrypt(keystore, password)
}
async function main() {
if(process.argv[2] === undefined) {
console.log(`Usage: node ${process.argv[1]} <filepath>`)
return;
}
const keystore = await loadKeystore(process.argv[2])
console.log(keystore)
console.log(JSON.stringify(keystore))
}
main()