forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signmsg.html
169 lines (154 loc) · 4.56 KB
/
signmsg.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>TREZOR Sign Message Test</title>
<style>
table {
display: inline-block;
width: 49%;
vertical-align: top;
}
table tr:first-child {
font-weight: bold;
font-size: 18px;
text-indent: 100px;
}
table td {
vertical-align: top;
box-sizing: border-box;
clear: both;
}
table tr td:first-child {
width: 100px;
}
input {
width: 350px;
}
textarea {
width: 350px;
height: 100px;
}
</style>
<script>
function trezorSignMessage() {
var path = document.getElementById("path").value;
var message = document.getElementById("message").value;
var coin = document.getElementById("coin").value;
if (coin === "Bitcoin Cash") coin = "Bcash";
var address = document.getElementById("address");
var signature = document.getElementById("signature");
var messageV = document.getElementById("messageV");
TrezorConnect.signMessage(path, message, function (response) {
if (response.success) {
address.value = response.address;
messageV.value = message;
signature.value = response.signature;
} else {
address.value = "";
messageV.value = "";
signature.value = "";
}
document.getElementById("response").innerHTML = JSON.stringify(response, undefined, 2);
}, coin);
}
function trezorVerifyMessage() {
var messageV = document.getElementById("messageV").value;
var address = document.getElementById("address").value;
var signature = document.getElementById("signature").value;
var coin = document.getElementById("coin").value;
if (coin === "Bitcoin Cash") coin = "Bcash";
console.log(address, signature, messageV, coin)
TrezorConnect.verifyMessage(address, signature, messageV, function (response) {
if (response.success) {
console.log("Success! Verified.");
} else {
console.log(response.error);
}
document.getElementById("response").innerHTML = JSON.stringify(response, undefined, 2);
}, coin);
}
function handleCoinChange(element) {
var coin = element.value;
var defaultPaths = {
"Bitcoin": "m/49'/0'/0'",
"Bitcoin Cash": "m/44'/145'/0'",
"Litecoin": "m/49'/2'/0'",
"Dogecoin": "m/44'/3'/0'",
"Dash": "m/44'/5'/0'",
"Zcash": "m/44'/133'/0'",
"Testnet": "m/49'/1'/0'",
"Namecoin": "m/44'/7'/0'",
"Zcash testnet": "m/44'/133'/0'",
}
document.getElementById('path').value = defaultPaths[coin];
}
</script>
</head>
<body>
<table>
<tr>
<td colspan="2" style="font-weight:bold">Sign</td>
</tr>
<tr>
<td>Path:</td>
<td><input id="path" value="m/49'/0'/0'"></td>
</tr>
<tr>
<td>Message:</td>
<td><input id="message" value="Example message" size="64"></td>
</tr>
<tr>
<td>Coin:</td>
<td>
<select id="coin" onchange="handleCoinChange(this)">
<option>Bitcoin</option>
<option>Bitcoin Cash</option>
<option>Litecoin</option>
<option>Dogecoin</option>
<option>Dash</option>
<option>Zcash</option>
<option>Testnet</option>
<option>Namecoin</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><button onclick="trezorSignMessage()">Sign Message</button></td>
</tr>
</table>
<table>
<tr>
<td colspan="2" style="font-weight:bold">Verify</td>
</tr>
<tr>
<td>Address:</td>
<td><input id="address" value="" /></td>
</tr>
<tr>
<td>Message:</td>
<td><input id="messageV" value="Example message" /></td>
</tr>
<tr>
<td>Signature:</td>
<td><textarea id="signature"></textarea></td>
</tr>
<tr>
<td></td>
<td>
<button onclick="trezorVerifyMessage()">Verify Message</button>
</td>
</tr>
</table>
<hr>
<pre id="response"></pre>
<script>
if (window.location.hostname === 'localhost') {
window.TREZOR_POPUP_ORIGIN = window.location.origin;
window.TREZOR_POPUP_URL = window.TREZOR_POPUP_ORIGIN + '/popup/popup.html';
}
</script>
<script src="../connect.js"></script>
</body>
</html>