-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (68 loc) · 2.92 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>keccak256 & secp256k1</title>
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script src="./dist/noble.bundle.js"></script>
<style>
.text-box {
border: 1px solid black;
padding:10px;
margin-bottom:10px;
}
input {
width:500px;
}
</style>
</head>
<body>
<div class="text-box">
<h3>keccak256 test</h3>
<div>message: <input type="text" id="keccak256-input-message" value="hello"></div>
<div><button id="keccak256-test-btn">keccak256</button></div>
<pre id="keccak256-test-result"></pre>
</div>
<div class="text-box">
<h3>secp256k1 test</h3>
<div>message: <input type="text" id="secp256k1-input-message" value="hello"></div>
<div>private key: <input type="text" id="secp256k1-input-pk" value="1249aa350c169899ad570d3dc1fcfeb775a6446fee970fcec30d0c5d8929f869"></div>
<div><button id="secp256k1-test-btn">secp256k1</button></div>
<pre id="secp256k1-test-result"></pre>
</div>
<script>
$(document).ready(_ => {
// signature : 74d5f0535a6c5dc12a07543c60412bb25cd9892617b9687de13079fdff1c49eb2c13599b6d0016140c2c1fa0e2f55d813f1a4b4c534fe1324d55cded17e20f961b
// wallet : 0xaA1Cf45d14f02438D9644C1Fd54EC0b769459Dfe
$("#keccak256-test-btn").click(e=>{
let input = $("#keccak256-input-message").val();
let hashed = Noble.default.hash.keccak_256(input)
let str = Noble.default.utils.bytesToHex(hashed);
$("#keccak256-test-result").html(str);
});
$("#secp256k1-test-btn").click(async e=>{
let msg = $("#secp256k1-input-message").val();
let pkHexStr = $("#secp256k1-input-pk").val();
let hashed = Noble.default.utils.utf8ToBytes(msg);
let pk = Noble.default.utils.hexToBytes(pkHexStr);
let public_key = Noble.default.secp.getPublicKey(pk);
let compressed_public_key = Noble.default.secp.getPublicKey(pk, true);
let address = Noble.default.hash.keccak_256(public_key.slice(1)).slice(-20);
let signature = await Noble.default.secp.sign(hashed, pk);
let str = Noble.default.utils.bytesToHex(signature);
let sig = Noble.default.secp.Signature.fromHex(str);
$("#secp256k1-test-result").html([
`public_key(none compressed): ${Noble.default.utils.bytesToHex(public_key)}`,
`public_key(compressed): ${Noble.default.utils.bytesToHex(compressed_public_key)}`,
`address: 0x${Noble.default.utils.bytesToHex(address)}`,
`signature hex: ${sig.toHex()}`,
`signature.r: ${sig.r}`,
`signature.s: ${sig.s}`
].join("\n"));
});
})
</script>
</body>
</html>