forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpubkey.html
96 lines (81 loc) · 3.08 KB
/
xpubkey.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
<!DOCTYPE html>
<html>
<head>
<title>TREZOR Get XPUB Key Test</title>
<style>
input[type="text"]:disabled {
background: #dddddd;
}
</style>
<script>
function trezorGetXPubKey() {
var path = document.getElementById('account_path').value;
var coin = document.getElementById('coin').value;
if (path.lenght < 1 || document.getElementById('account_path').disabled) path = null;
// var path = [44 | 0x80000000,
// 0 | 0x80000000,
// 0 | 0x80000000 ]; // path in raw form
TrezorConnect.setCurrency(coin); // set backend
TrezorConnect.getXPubKey(path, function (response) {
if (response.success) {
console.log('XPUB:', response.xpubkey); // serialized XPUB
console.log('Raw path:', response.path);
console.log('Serialized path:', response.serializedPath);
} else {
console.error('Error:', response.error); // error message
}
document.getElementById("response").innerHTML = JSON.stringify(response, undefined, 2);
});
}
function handleCoinChange() {
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'",
}
var coin = document.getElementById('coin').value;
document.getElementById('account_path').value = defaultPaths[coin];
var checkbox = document.getElementById('discovery')
if (coin === 'Dogecoin' || coin === 'Namecoin') {
checkbox.checked = false;
checkbox.disabled = true;
document.getElementById('account_path').disabled = false;
} else {
checkbox.disabled = false;
}
}
function handleDiscoveryChange(element) {
document.getElementById('account_path').disabled = element.checked;
}
</script>
</head>
<body>
Coin:
<select id="coin" onchange="handleCoinChange()">
<option selected>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>
<input id="account_path" type="text" value="m/49'/0'/0'" />
<input type="checkbox" id="discovery" onchange="handleDiscoveryChange(this)" /> Discover account
<button onclick="trezorGetXPubKey()">Get XPUB key</button>
<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>