forked from NxtChg/tsbw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
194 lines (147 loc) · 6.89 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE HTML>
<html>
<head><title>TSBW: The Simplest Bitcoin Wallet</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="TSBW: The Simplest Bitcoin Wallet">
<meta name="keywords" content="tsbw,simple,simplest,online,bitcoin,wallet,btc,js,browser">
<link rel="shortcut icon" href="favicon.ico"/>
<style>
html, body{ width:100%; height:100%; margin:0; line-height:20px; background:#eee; }
a{ color:#16E; text-decoration:none; cursor:pointer; }
a.visited{ color:#16E; }
a:hover{ color:red; }
input { height:18px; padding:3px 4px; font-size:14px; margin:2px 0; }
button{ padding:4px 12px; font-size:14px; }
#page{ width:496px; height:244px; position:absolute; top:0; right:0; left:0; bottom:0; margin:auto; background:#F5F5F5; text-align:center; font-family:arial; font-size:14px; overflow:hidden; }
#pass_form, #send_form{ padding:30px; color:#888; text-align:left; display:none; }
#pass_form{ text-align:center; display:none; }
#passphrase{ width:310px; }
#to { width:268px; }
#amount { width: 66px; }
#status { color:#777; }
#adr { font-size:16px; color:#666; }
#wif { font-size:14px; }
#balance{ color:#C74; font-size:20px; }
#close, #made{ position:absolute; color:#BBB; font-family:verdana,arial; }
#close:hover { color:#555; }
#close { top: 5px; right:10px; cursor:pointer; }
#made { bottom:6px; right:12px; font-size:13px; text-align:right; }
</style>
<script language='JavaScript' type='text/javascript' src='common.js'></script>
<script language='JavaScript' type='text/javascript' src='hashes.js'></script>
<script language='JavaScript' type='text/javascript' src='jsbn.js'></script>
<script language='JavaScript' type='text/javascript' src='elliptic.js'></script>
<script language='JavaScript' type='text/javascript' src='btc.js'></script>
<script language='JavaScript' type='text/javascript' src='backend_bci.js'></script>
</head>
<body>
<div id=page>
<form id=pass_form action="javascript:open_wallet();">
<br><input id=passphrase type=password placeholder="Passphrase or private key" title="Can also use compressed WIF key."> <button type=submit>Open</button><br>
<br><br>Nothing is sent to our server, everything is done in the browser.<br>It gets utxo and sends signed txs via <span id=backend></span> API.
<br><br>You can download it from <a href='https://github.com/NxtChg/tsbw' target=_blank>github</a> and use it locally.
<div style="position:absolute; right:12px; bottom:8px;"><a href="bcc/">Bitcoin Cash version</a> | <a href="test/">TestNet</a></div>
</form>
<form id=send_form action="javascript:send_tx();">
<span id=adr></span><br><br>
<span id=balance>Balance: </span><br><br>
<input id=to type=text placeholder="Address"> <input id=amount type=text placeholder="Amount"> <button type=submit>Send</button>
<br><br><div id=status></div>
<div id=close onclick="location.reload()" title="sign out">X</div>
</form>
</div>
<div id=made>Created by NxtChg<br><span style="font-size:10px">19BryCNdGs5F48J6yvw41pVSd5RDiA4j1x</span></div>
<script>
var tx, keys, fee = 0.00002;
function balance_cb(amount)
{
if(isNaN(amount)) amount = '?'; else amount = js.format_money(amount, 8);
$('balance').innerHTML = "<span title='click to refresh' onclick='refresh(true);' style='cursor:pointer'>Balance: <b id=amt>" + amount + "</b> BTC</span> (<a href='" + backend.adr_page + keys.adr + "' target=_blank rel=\"noopener noreferrer\">transactions</a>)";
}//____________________________________________________________________________
function refresh(set_amount)
{
if(set_amount) $('amt').innerHTML = '?';
backend.get_balance(keys.adr, balance_cb);
}//____________________________________________________________________________
function open_wallet()
{
var pass = js.trim($('passphrase').value); if(pass.length < 1) return;
if(!btc.check_entropy(pass))
{
if(!confirm('This passphrase is weak, are you sure?')){ $('passphrase').value = ''; return; }
}
keys = btc.get_keys(pass); if(keys === false){ alert('Bad private key!'); return; }
$('pass_form').hide();
$('send_form').show();
$('to').focus();
$('adr').innerHTML = "<b style='font-size:16px'>" + keys.adr + "</b>–[<a href='javascript:show_wif()'>wif</a>]–<br><span id=wif></span>";
$('status').innerHTML = 'Fee: ' + fee;
refresh(); setInterval(refresh, 60000);
}//____________________________________________________________________________
function show_wif(){ $('wif').innerHTML = ($('wif').innerHTML == '' ? keys.wif : ''); }
//_____________________________________________________________________________
function broadcast_cb(res)
{
if(res == '')
{
$('to' ).value = '';
$('amount').value = '';
$('status').innerHTML = '<a href="'+ backend.tx_page + tx.txid() + '" target=_blank rel="noopener noreferrer">Transaction</a> sent.';
}
else $('status').innerHTML = 'Error: ' + res;
tx = null; js.enable_form('send_form', true); setTimeout(refresh, 1000);
}//____________________________________________________________________________
function broadcast()
{
$('status').innerHTML = 'Signing tx...';
var signed = tx.sign(keys);
$('status').innerHTML = 'Broadcasting...';
console.log('TX: ', signed);
backend.send(signed, broadcast_cb);
}//____________________________________________________________________________
function unspent_cb(utxo)
{
if(utxo !== false)
{
var total = tx.add_unspent(utxo), err = '';
var tx_total = tx.amount + fee;
if(total >= tx_total)
{
var change = total - tx_total;
if(change > 0.000001) tx.add_output(keys.adr, change);
setTimeout(broadcast, 300);
return;
}
else err = 'Not enough money! Need ' + js.format_money(tx_total - total, 8) + ' BTC more.';
}
else err = 'Failed to get unspent outputs!';
tx = null; js.enable_form('send_form', true); $('status').innerHTML = err;
}//____________________________________________________________________________
function send_tx()
{
var dst = js.trim($('to').value), amount = parseFloat(js.trim($('amount').value));
if(dst == '' || btc.decode_adr(dst) === false || isNaN(amount) || amount < 0.0001) return;
if(confirm('Send ' + amount + ' BTC to ' + dst + '?'))
{
tx = btc.new_tx();
tx.add_output(dst, amount);
js.enable_form('send_form', false);
$('status').innerHTML = 'Getting unspent outputs...';
backend.get_utxo(keys.adr, unspent_cb);
}
}//____________________________________________________________________________
if(!JSON || !JSON.parse) alert("Your browser doesn't support native JSON decoding. This page will not work, sorry.");
else
{
var x = new XMLHttpRequest();
if('withCredentials' in x)
{
$('backend').innerHTML = '<a href="'+backend.home_page+'" target=_blank rel="noopener noreferrer">'+backend.host+'</a>';
$('pass_form' ).show();
$('passphrase').focus();
}
else alert("Your browser dosen't support Cross-Origin Resource Sharing. This page will not work, sorry.");
}
</script>
</body>
</head>