-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
50 lines (49 loc) · 1.92 KB
/
Copy pathmain.js
File metadata and controls
50 lines (49 loc) · 1.92 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
import 'bootstrap/dist/css/bootstrap.css'
import ecc from 'eosjs-ecc'
// 前缀
const PUBKEY_PREFIX = 'TLOS'
// 生成按钮
let generateBtn = document.querySelector('#generate-key-btn')
generateBtn.addEventListener('click', () => {
let publicKeyLabel = document.querySelector('#public-key')
let privateKeyLabel = document.querySelector('#private-key')
ecc.randomKey().then((privateKey) => {
let publicKey = ecc.privateToPublic(privateKey, PUBKEY_PREFIX)
publicKeyLabel.textContent = `公钥: ${publicKey.toString()}`
privateKeyLabel.textContent = `私钥: ${privateKey.toString()}`
publicKeyLabel.className = 'd-block'
privateKeyLabel.className = 'd-block'
}).catch(err => {
alert(err.toString())
})
})
// 验证公钥
let validPublicKeyBtn = document.querySelector('#valid-public-key-btn')
validPublicKeyBtn.addEventListener('click', () => {
let label = document.querySelector('#valid-public-key')
let resultLabel = document.querySelector('#valid-public-key-result')
if (label.value) {
if (ecc.isValidPublic(label.value, PUBKEY_PREFIX)) {
resultLabel.className = 'text-success'
resultLabel.textContent = '公钥正确'
} else {
resultLabel.className = 'text-danger'
resultLabel.textContent = '公钥错误'
}
}
})
// 验证私钥
let validPrivateKeyBtn = document.querySelector('#valid-private-key-btn')
validPrivateKeyBtn.addEventListener('click', () => {
let label = document.querySelector('#valid-private-key')
let resultLabel = document.querySelector('#valid-private-key-result')
if (label.value) {
if (ecc.isValidPrivate(label.value)) {
resultLabel.className = 'text-success'
resultLabel.textContent = '私钥正确'
} else {
resultLabel.className = 'text-danger'
resultLabel.textContent = '私钥错误'
}
}
})