-
Notifications
You must be signed in to change notification settings - Fork 38
/
icebox.html
126 lines (105 loc) · 5.2 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
<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', '');
}
var numAddr = parseInt(document.getElementById('numAddr').value)
global_keystore.generateNewAddress(password, numAddr);
var addresses = global_keystore.getAddresses();
document.getElementById('sendFrom').innerHTML = ''
for (var i=0; i<addresses.length; ++i) {
document.getElementById('sendFrom').innerHTML += '<option value="' + addresses[i] + '">' + addresses[i] + '</option>'
}
showAddresses();
}
function showAddresses() {
var addresses = global_keystore.getAddresses();
document.getElementById('addr').innerHTML = 'Retrieving addresses...'
var addrString = ''
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>';
}
function setSeed() {
var password = prompt('Enter password to encrypt your seed for this session', '');
global_keystore = new lightwallet.keystore(
document.getElementById('seed').value,
password);
document.getElementById('seed').value = ''
newAddresses(password);
}
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, '');
global_keystore = new lightwallet.keystore(
randomSeed,
password);
newAddresses(password);
showAddresses();
}
function showSeed() {
var password = prompt('Enter your password to show your seed.', '');
var seed = global_keystore.getSeed(password);
alert('Your seed is: "' + seed + '". Please write it down.');
}
function sendEth() {
var password = prompt('Enter password to create and sign transaction', '');
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 = 30000
var rawUnsignedTx = lightwallet.txutils.valueTx({to: toAddr, value: value, gasPrice: gasPrice, gasLimit: gas, nonce: nonce})
var rawSignedTx = global_keystore.signTx(rawUnsignedTx, password, 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>';
}
</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</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=100000000000></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>
</body>
</html>