-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
58 lines (46 loc) · 1.9 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test</title>
<script type="application/javascript" src="./qos-keys.js" ></script>
</head>
<body>
</body>
<script type="application/javascript">
let mnemonic = "fury flavor subway start spare hospital tag chief word start pencil borrow town mandate detect pencil cook bridge right scout remain this differ leader";
let hexPrivateKey,bech32PubKey, bech32Address, err,hexPrivateKey2,bech32PubKey2, bech32Address2, privateKeyBz, publicKeyBz;
//从助记词中恢复QOS公私钥
[hexPrivateKey, bech32PubKey, bech32Address, privateKeyBz, publicKeyBz, err] = qosKeys.DeriveQOSKey(mnemonic);
if (err == null) {
console.log(hexPrivateKey);
console.log(bech32PubKey);
console.log(bech32Address);
console.log(privateKeyBz);
console.log(publicKeyBz);
}else{
console.log(err);
}
//从私钥中恢复公私钥及地址
[hexPrivateKey2, bech32PubKey2, bech32Address2, privateKeyBz, publicKeyBz,err] = qosKeys.RecoverFromPrivateKey(hexPrivateKey);
if (err == null) {
console.log(hexPrivateKey2);
console.log(bech32PubKey2);
console.log(bech32Address2);
}else{
console.log(err);
}
//对字符串及对base64编码的字符串签名
let message = "你好,QOS钱包";
let base64Message = qosKeys.EncodeBase64(message);
let signData1 = qosKeys.Sign(hexPrivateKey, message);
let signData2 = qosKeys.SignBase64Message(hexPrivateKey, base64Message);
console.log(signData1);
console.log(signData2);
console.log(qosKeys.EncodeBase64(signData1) === qosKeys.EncodeBase64(signData2));
//校验bech32格式字符串是否合法
console.log(qosKeys.VerifyBech32String(bech32PubKey));
console.log(qosKeys.VerifyBech32String(bech32Address));
</script>
</html>