forked from kobigurk/icebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicebox.html
182 lines (151 loc) · 7.11 KB
/
icebox.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
<html>
<head>
<title>icebox</title>
</head>
<body>
<script src="./lightwallet.min.js"></script>
<script>
var global_keystore;
function newAddresses(password) {
if (password == '') {
password = prompt('Enter password to retrieve addresses', '');
if(! password) { return false; }
}
global_keystore.keyFromPassword(password, function(err, pwDerivedKey) {
if(! global_keystore.isDerivedKeyCorrect(pwDerivedKey)) {
alert('Wrong password');
return newAddresses('');
}
var numAddr = parseInt(document.getElementById('numAddr').value)
global_keystore.generateNewAddress(pwDerivedKey, numAddr);
showAddresses();
});
}
function showAddresses() {
var addresses = global_keystore.getAddresses();
document.getElementById('addr').innerHTML = 'Retrieving addresses...'
var addrString = ''
document.getElementById('sendFrom').innerHTML = ''
document.getElementById('addr').innerHTML = ''
for (var i=0; i<addresses.length; ++i) {
document.getElementById('addr').innerHTML += '<div>' + addresses[i] + '</div>'
if (i !== (addresses.length-1)) {
addrString += addresses[i] + '_';
}
else {
addrString += addresses[i];
}
}
// Add link to Workflow app
var workflowURL = 'workflow://run-workflow?name=AddressQR&input=text&text='
document.getElementById('workflowAddr').innerHTML = '<a href="' + workflowURL + addrString + '">Address QR Codes (Workflow App)</a>';
// Add the 'sendFrom' modal
document.getElementById('sendFrom').innerHTML = ''
for (var i=0; i<addresses.length; ++i) {
document.getElementById('sendFrom').innerHTML += '<option value="' + addresses[i] + '">' + addresses[i] + '</option>'
}
}
function setSeed() {
var password = prompt('Enter password to encrypt your seed for this session', '');
if(! password) { return false; }
var randomSeed = document.getElementById('seed').value;
lightwallet.keystore.createVault({
password: password,
seedPhrase: randomSeed
}, function(err, ks) {
window.global_keystore = ks;
newAddresses(password);
document.getElementById('seed').value = '';
});
}
function newWallet() {
var extraEntropy = document.getElementById('userEntropy').value;
document.getElementById('userEntropy').value = '';
var randomSeed = lightwallet.keystore.generateRandomSeed(extraEntropy);
var infoString = 'Your new wallet seed is: "' + randomSeed +
'". Please write it down on paper, you will need it to access your wallet. Do not let anyone see this seed or they can take your Ether. Please chooses a password to encrypt your wallet for this session.'
var password = prompt(infoString, '');
if(! password) { return false; }
lightwallet.keystore.createVault({
password: password,
seedPhrase: randomSeed
}, function(err, ks) {
window.global_keystore = ks;
newAddresses(password);
});
}
function showSeed() {
var password = prompt('Enter your password to show your seed.', '');
if(! password) { return false; }
global_keystore.keyFromPassword(password, function(err, pwDerivedKey) {
if(! global_keystore.isDerivedKeyCorrect(pwDerivedKey)) {
alert('Wrong password');
return showSeed();
}
var seed = global_keystore.getSeed(pwDerivedKey);
alert('Your seed is: "' + seed + '". Please write it down.');
})
}
function sendEth() {
var password = prompt('Enter password to create and sign transaction', '');
if(! password) { return false; }
var fromAddr = document.getElementById('sendFrom').value
var toAddr = document.getElementById('sendTo').value
var valueEth = document.getElementById('sendValueAmount').value
var value = parseFloat(valueEth)*1.0e18
var nonce = parseInt(document.getElementById('nonce').value)
var gasPrice = parseInt(document.getElementById('gasPrice').value)
var gas = 21000
var rawUnsignedTx = lightwallet.txutils.valueTx({to: toAddr, value: value, gasPrice: gasPrice, gasLimit: gas, nonce: nonce})
global_keystore.keyFromPassword(password, function(err, pwDerivedKey) {
if(! global_keystore.isDerivedKeyCorrect(pwDerivedKey)) {
alert('Wrong password');
return sendEth();
}
var rawSignedTx = lightwallet.signing.signTx(global_keystore, pwDerivedKey, rawUnsignedTx, fromAddr)
document.getElementById('rawSignedTx').value = rawSignedTx
// Add link to Workflow app
var workflowURL = 'workflow://run-workflow?name=TransactionQR&input=text&text='
document.getElementById('workflowTx').innerHTML = '<a href="' + workflowURL + rawSignedTx + '">Transaction QR Code (Workflow App)</a>';
})
}
function saveWallet() {
var serialized = global_keystore.serialize();
document.getElementById('savedWallet').value = serialized;
}
function loadWallet() {
var serialized = document.getElementById('loadedWallet').value;
global_keystore = lightwallet.keystore.deserialize(serialized);
showAddresses();
alert('Wallet Loaded.');
}
</script>
<h1>icebox</h1>
<h2>New Wallet</h2>
<div><input type="text" id="userEntropy" placeholder="Type random text to generate entropy" size="80"></input><button onclick="newWallet()">Create New Wallet</button></div>
<h2>Restore Wallet From Seed</h2>
<div><input type="text" id="seed" value="" size="80"></input><button onclick="setSeed()">Restore wallet from Seed</button></div>
<h2>Show Addresses</h2>
<div>Show <input type="text" id="numAddr" size="5" value="3"></input> more address(es) <button onclick="newAddresses('')">Show</button></div>
<div id="addr"></div>
<div id="workflowAddr"></div>
<h2>Send Ether</h2>
<div>From: <select id="sendFrom"></select></div>
<div>To: <input type="text" size="40" id="sendTo"></input></div>
<div>Ether: <input type="text" id="sendValueAmount"></div>
<div>Nonce: <input type="text" id="nonce"></div>
<div>Gas Price<input type="text" id="gasPrice" value=20000000000></div>
<div><button onclick="sendEth()">Create Transaction</button></div>
<h3>Signed Transaction</h3>
<div><textarea id='rawSignedTx' rows=6 cols=40></textarea></div>
<div id='workflowTx'></div>
<h2>Show Seed</h2>
<button onclick="showSeed()">Show Seed</button>
<h2>Save Encrypted Wallet</h2>
<div><textarea id='savedWallet' rows=6 cols=40></textarea></div>
<button onclick="saveWallet()">Save Wallet</button>
<h2>Load Encrypted Wallet</h2>
<div><textarea id='loadedWallet' rows=6 cols=40></textarea></div>
<button onclick="loadWallet()">Load Wallet</button>
</body>
</html>