forked from webdigi/EOS-Offline-Private-key-check
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
executable file
·84 lines (65 loc) · 2.11 KB
/
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
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
let privateKeyPair = null
function generate() {
showPane('generate')
setTimeout(() => {
var privKey = byId('privKey').value;
privateKeyPair = webdigiKeyPair(privKey)
console.log(privateKeyPair);
hide("generate-progress")
byId("generate-pubkey").innerHTML = privateKeyPair.pubkey
byId("generate-pubkey-error").innerHTML = privateKeyPair.pubkeyError
byId("generate-privkey").innerHTML = privateKeyPair.privkey
byId("generate-privkey-error").innerHTML = privateKeyPair.privkeyError
show("generate-confirm")
show("generate-link")
}, 1000)
}
function webdigiKeyPair(privKeyInput) {
var {PrivateKey, PublicKey} = eos_ecc
var privkeyError = ''
var pubkeyError = ''
try{
var abc = PrivateKey.fromWif(privKeyInput);
var privkey = abc.toWif()
var pubkey = abc.toPublic().toString()
} catch(error){
privkeyError = 'Private key in invalid, please try again.'
}
if(privkey && pubkey){
try {
var pub2 = PrivateKey.fromWif(privkey).toPublic().toString()
if(pubkey !== pub2) {
throw {message: 'public key miss-match: ' + pubkey + ' !== ' + pub2}
}
} catch(error) {
//console.log('privkeyError', error, privkey)
privkeyError = error.message + ' => ' + privkey
}
try {
PublicKey.fromStringOrThrow(pubkey)
} catch(error) {
// console.log('pubkeyError', error, pubkey)
pubkeyError = error.message + ' => ' + pubkey
}
}
if(privkeyError || pubkeyError) {
privkey = 'DO NOT USE'
pubkey = 'DO NOT USE'
}
return {pubkey, privkey, pubkeyError, privkeyError}
}
function showPane(name) {
//hidePanes()
show(`${name}-pane`)
show(`${name}-progress`)
hide(`${name}-confirm`)
hide(`${name}-link`)
}
//function hidePanes() {
// for (var x of "generate transfer buy register".split(" ")) {
// try {
// show(`${x}-link`)
// hide(`${x}-pane`)
// } catch (error) {}
// }
//}