2016-08-04 10:21:49 +03:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Ethereum Wallet</title>
|
2018-06-22 04:01:29 +03:00
|
|
|
<link rel="stylesheet" type="text/css" href="./style.css">
|
2016-08-04 10:21:49 +03:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="centerer" id="screen-select">
|
|
|
|
<div class="centered">
|
|
|
|
<h1>Ethereum Wallet Tool</h1>
|
|
|
|
<hr />
|
|
|
|
<h2>Load JSON Wallet</h2>
|
|
|
|
<p>
|
|
|
|
If you have a JSON wallet file from <i>geth</i> or from the initial <i>Ethereum</i>
|
|
|
|
crowd sale, you can decrypt it here. No information is shared with <b>any</b>
|
|
|
|
server.
|
|
|
|
</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>JSON Wallet:</th>
|
|
|
|
<td><div class="file" id="select-wallet-drop">Drop JSON wallet file here</div><input type="file" id="select-wallet-file" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Password:</th>
|
|
|
|
<td><input type="password" placeholder="(password)" id="select-wallet-password" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
|
|
|
<div id="select-submit-wallet" class="submit disable">Unlock JSON Wallet</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2017-04-06 00:14:09 +03:00
|
|
|
<hr />
|
|
|
|
<h2>Mnemonic Phrase Wallet</h2>
|
|
|
|
<p>
|
|
|
|
If you have a 12 word mnemonic phrase, you can generate your wallet here.
|
|
|
|
No information is shared with <b>any</b> server.
|
|
|
|
</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Mnemonic Phrase:</th>
|
|
|
|
<td><input type="text" placeholder="(mnemonic phrase)" id="select-mnemonic-phrase" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Path:</th>
|
|
|
|
<td><input type="text" placeholder="(path)" id="select-mnemonic-path" value="m/44'/60'/0'/0/0" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
|
|
|
<div id="select-submit-mnemonic" class="submit disable">Derive Wallet</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2016-08-08 07:18:01 +03:00
|
|
|
<hr />
|
|
|
|
<h2>Raw Private Key</h2>
|
|
|
|
<p>
|
|
|
|
</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
2016-08-09 00:12:27 +03:00
|
|
|
<th>Private Key:</th>
|
2016-08-08 07:18:01 +03:00
|
|
|
<td><input type="text" placeholder="(private key)" id="select-privatekey" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
2018-06-23 08:30:59 +03:00
|
|
|
<div id="select-submit-privatekey" class="submit disable">Load Raw Private Key</div>
|
2016-08-08 07:18:01 +03:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2016-08-04 10:21:49 +03:00
|
|
|
<hr />
|
|
|
|
<h3>Disclaimer:</h3>
|
|
|
|
<p>
|
|
|
|
This is beta software, with no warranty. <b>Use at your own risk.</b>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="centerer hidden" id="screen-loading">
|
|
|
|
<div class="centered">
|
|
|
|
<h1>Loading Wallet</h1>
|
|
|
|
<hr />
|
|
|
|
<h2 id="loading-header"></h2>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Progress:</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" readonly="readonly" class="readonly" id="loading-status" value="" /></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
|
|
|
<div id="loading-cancel" class="submit">Cancel</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
<h3>Disclaimer:</h3>
|
|
|
|
<p>
|
|
|
|
This is beta software, with no warranty. <b>Use at your own risk.</b>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="centerer hidden" id="screen-wallet">
|
|
|
|
<div class="centered">
|
|
|
|
<h1>Ethereum Wallet<span id="wallet-username" class="username right"></span></h1>
|
|
|
|
<hr />
|
|
|
|
<h3>Wallet Details:</h3>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Address:</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" readonly="readonly" class="readonly" id="wallet-address" value="" /></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Network:</th>
|
|
|
|
<td>
|
2018-06-22 03:58:13 +03:00
|
|
|
<div class="clearfix"></div>
|
|
|
|
<div class="network option" data-network="ropsten">Ropsten<br /><span>testnet</span></div>
|
|
|
|
<div class="network option" data-network="rinkeby">Rinkeby<br /><span>testnet</span></div>
|
|
|
|
<div class="network option" data-network="kovan">Kovan<br /><span>testnet</span></div>
|
|
|
|
<div class="network option last selected" data-network="homestead">Homestead<br /><span>mainnet</span></div>
|
|
|
|
<div class="clearfix"></div>
|
2016-08-04 10:21:49 +03:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Balance:</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" readonly="readonly" class="readonly" id="wallet-balance" value="0.0" /></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Nonce:</th>
|
|
|
|
<td>
|
|
|
|
<input type="text" readonly="readonly" class="readonly" id="wallet-transaction-count" value="0" /></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
|
|
|
<div id="wallet-submit-refresh" class="submit">Refresh</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<h3>Send Ether:</h3>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Target Address:</th>
|
|
|
|
<td><input type="text" placeholder="(target address)" id="wallet-send-target-address" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th>Amount:</th>
|
|
|
|
<td><input type="text" placeholder="(amount)" id="wallet-send-amount" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td> </td>
|
|
|
|
<td>
|
|
|
|
<div id="wallet-submit-send" class="submit disable">Send Ether</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<h3>Session Activity</h3>
|
|
|
|
<div id="wallet-activity" class="activity"></div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
<h3>Disclaimer:</h3>
|
|
|
|
<p>
|
|
|
|
This is beta software, with no warranty. <b>Use at your own risk.</b>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2017-04-06 00:14:09 +03:00
|
|
|
<script type="text/javascript" src="../../dist/ethers.js"></script>
|
2016-08-04 10:21:49 +03:00
|
|
|
<script type="text/javascript">
|
2018-06-22 03:58:13 +03:00
|
|
|
function query(el, selector) {
|
|
|
|
if (!selector) {
|
|
|
|
selector = el;
|
|
|
|
el = document;
|
|
|
|
}
|
|
|
|
return Array.prototype.slice.call(el.querySelectorAll(selector));
|
|
|
|
}
|
|
|
|
|
2016-08-04 10:21:49 +03:00
|
|
|
function setEnter(source, target) {
|
|
|
|
source.onkeyup = function(e) {
|
|
|
|
if (e.which === 13) { target.click(); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var cancelScrypt = false;
|
|
|
|
document.getElementById('loading-cancel').onclick = function() {
|
|
|
|
cancelScrypt = true;
|
|
|
|
};
|
|
|
|
|
2017-04-06 00:14:09 +03:00
|
|
|
var updateLoading = (function() {
|
|
|
|
var loadingStatus = document.getElementById('loading-status');
|
|
|
|
return (function(progress) {
|
|
|
|
loadingStatus.value = (parseInt(progress * 100)) + '%';
|
|
|
|
return cancelScrypt;
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2018-06-22 03:58:13 +03:00
|
|
|
// JSON Wallet
|
2016-08-04 10:21:49 +03:00
|
|
|
(function() {
|
|
|
|
var inputFile = document.getElementById('select-wallet-file');
|
|
|
|
var targetDrop = document.getElementById('select-wallet-drop');
|
|
|
|
var inputPassword = document.getElementById('select-wallet-password');
|
|
|
|
var submit = document.getElementById('select-submit-wallet');
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
if (inputFile.files && inputFile.files.length === 1) {
|
|
|
|
submit.classList.remove('disable');
|
|
|
|
targetDrop.textContent = inputFile.files[0].name;
|
|
|
|
} else {
|
|
|
|
submit.classList.add('disable');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputFile.onchange = check;
|
|
|
|
inputPassword.oninput = check;
|
|
|
|
|
|
|
|
setEnter(inputPassword, submit);
|
|
|
|
|
2016-08-05 03:12:50 +03:00
|
|
|
inputFile.addEventListener('dragover', function(event) {
|
2016-08-04 10:21:49 +03:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
targetDrop.classList.add('highlight');
|
|
|
|
}, true);
|
|
|
|
|
2016-08-05 03:12:50 +03:00
|
|
|
inputFile.addEventListener('drop', function(event) {
|
2016-08-04 10:21:49 +03:00
|
|
|
targetDrop.classList.remove('highlight');
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
submit.onclick = function() {
|
|
|
|
if (submit.classList.contains('disable')) { return; }
|
|
|
|
|
|
|
|
var fileReader = new FileReader();
|
|
|
|
fileReader.onload = function(e) {
|
|
|
|
var json = e.target.result;
|
|
|
|
|
2018-06-22 09:15:47 +03:00
|
|
|
if (ethers.Wallet.isEncryptedWallet(json)) {
|
2016-08-04 10:21:49 +03:00
|
|
|
showLoading('Decrypting Wallet...');
|
|
|
|
|
|
|
|
cancelScrypt = false;
|
|
|
|
|
2018-06-22 09:15:47 +03:00
|
|
|
ethers.Wallet.fromEncryptedJson(json, inputPassword.value, updateLoading).then(function(wallet) {
|
|
|
|
showWallet(wallet);
|
2016-08-04 10:21:49 +03:00
|
|
|
|
2018-06-22 09:15:47 +03:00
|
|
|
}, function(error) {
|
|
|
|
if (error.message === 'invalid password') {
|
|
|
|
alert('Wrong Password');
|
2016-08-04 10:21:49 +03:00
|
|
|
} else {
|
2018-06-22 09:15:47 +03:00
|
|
|
console.log(error);
|
|
|
|
alert('Error Decrypting Wallet');
|
2016-08-04 10:21:49 +03:00
|
|
|
}
|
2018-06-22 09:15:47 +03:00
|
|
|
showSelect();
|
2016-08-04 10:21:49 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
alert('Unknown JSON wallet format');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fileReader.readAsText(inputFile.files[0]);
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
2018-06-22 03:58:13 +03:00
|
|
|
// Raw Private Key
|
2016-08-08 07:18:01 +03:00
|
|
|
(function() {
|
|
|
|
var inputPrivatekey = document.getElementById('select-privatekey');
|
|
|
|
var submit = document.getElementById('select-submit-privatekey');
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
if (inputPrivatekey.value.match(/^(0x)?[0-9A-fa-f]{64}$/)) {
|
|
|
|
submit.classList.remove('disable');
|
|
|
|
} else {
|
|
|
|
submit.classList.add('disable');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputPrivatekey.oninput = check;
|
|
|
|
|
|
|
|
setEnter(inputPrivatekey, submit);
|
|
|
|
|
|
|
|
submit.onclick = function() {
|
|
|
|
if (submit.classList.contains('disable')) { return; }
|
|
|
|
var privateKey = inputPrivatekey.value;
|
|
|
|
if (privateKey.substring(0, 2) !== '0x') { privateKey = '0x' + privateKey; }
|
2017-04-06 00:14:09 +03:00
|
|
|
showWallet(new ethers.Wallet(privateKey));
|
2016-08-08 07:18:01 +03:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2018-06-22 03:58:13 +03:00
|
|
|
// Mnemonic Phrase
|
|
|
|
(function() {
|
|
|
|
var inputPhrase = document.getElementById('select-mnemonic-phrase');
|
|
|
|
var inputPath = document.getElementById('select-mnemonic-path');
|
|
|
|
var submit = document.getElementById('select-submit-mnemonic');
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
if (ethers.HDNode.isValidMnemonic(inputPhrase.value)) {
|
|
|
|
submit.classList.remove('disable');
|
|
|
|
} else {
|
|
|
|
submit.classList.add('disable');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputPhrase.oninput = check;
|
|
|
|
inputPath.oninput = check;
|
|
|
|
|
|
|
|
setEnter(inputPhrase, submit);
|
|
|
|
setEnter(inputPath, submit);
|
|
|
|
|
|
|
|
submit.onclick = function() {
|
|
|
|
if (submit.classList.contains('disable')) { return; }
|
|
|
|
showWallet(ethers.Wallet.fromMnemonic(inputPhrase.value, inputPath.value));
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2016-08-08 07:18:01 +03:00
|
|
|
|
2016-08-04 10:21:49 +03:00
|
|
|
var activeWallet = null;
|
|
|
|
|
|
|
|
function showError(error) {
|
|
|
|
alert('Error \u2014 ' + error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh balance and transaction count in the UI
|
|
|
|
var refresh = (function() {
|
|
|
|
var inputBalance = document.getElementById('wallet-balance');
|
|
|
|
var inputTransactionCount = document.getElementById('wallet-transaction-count');
|
|
|
|
var submit = document.getElementById('wallet-submit-refresh');
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
addActivity('> Refreshing details...');
|
|
|
|
activeWallet.getBalance('pending').then(function(balance) {
|
|
|
|
addActivity('< Balance: ' + balance.toString(10));
|
2018-06-22 03:58:13 +03:00
|
|
|
inputBalance.value = ethers.utils.formatEther(balance, { commify: true });
|
2016-08-04 10:21:49 +03:00
|
|
|
}, function(error) {
|
|
|
|
showError(error);
|
|
|
|
});
|
|
|
|
activeWallet.getTransactionCount('pending').then(function(transactionCount) {
|
|
|
|
addActivity('< TransactionCount: ' + transactionCount);
|
|
|
|
inputTransactionCount.value = transactionCount;
|
|
|
|
}, function(error) {
|
|
|
|
showError(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
submit.onclick = refresh;
|
|
|
|
|
|
|
|
return refresh;
|
|
|
|
})();
|
|
|
|
|
|
|
|
var addActivity = (function() {
|
|
|
|
var activity = document.getElementById('wallet-activity');
|
|
|
|
return function(message, url) {
|
|
|
|
var line = document.createElement('a');
|
|
|
|
line.textContent = message;
|
2018-06-22 03:58:13 +03:00
|
|
|
if (url) {
|
|
|
|
line.setAttribute('href', url);
|
|
|
|
line.setAttribute('target', '_blank');
|
|
|
|
}
|
2016-08-04 10:21:49 +03:00
|
|
|
activity.appendChild(line);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Set up the wallet page
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
var inputTargetAddress = document.getElementById('wallet-send-target-address');
|
|
|
|
var inputAmount = document.getElementById('wallet-send-amount');
|
|
|
|
var submit = document.getElementById('wallet-submit-send');
|
|
|
|
|
|
|
|
// Validate the address and value (to enable the send button)
|
|
|
|
function check() {
|
|
|
|
try {
|
2017-04-06 00:14:09 +03:00
|
|
|
ethers.utils.getAddress(inputTargetAddress.value);
|
|
|
|
ethers.utils.parseEther(inputAmount.value);
|
2016-08-04 10:21:49 +03:00
|
|
|
} catch (error) {
|
|
|
|
submit.classList.add('disable');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
submit.classList.remove('disable');
|
|
|
|
}
|
|
|
|
inputTargetAddress.oninput = check;
|
|
|
|
inputAmount.oninput = check;
|
|
|
|
|
2018-06-22 03:58:13 +03:00
|
|
|
query('.network.option').forEach(function(el) {
|
|
|
|
var network = el.getAttribute('data-network');
|
|
|
|
el.onclick = function() {
|
|
|
|
addActivity('! Switched network: ' + network);
|
|
|
|
activeWallet = activeWallet.connect(ethers.providers.getDefaultProvider(network));
|
|
|
|
query('.network.option.selected').forEach(function(el) {
|
|
|
|
el.classList.remove('selected');
|
|
|
|
});
|
|
|
|
el.classList.add('selected');
|
|
|
|
refresh();
|
|
|
|
};
|
|
|
|
});
|
2016-08-04 10:21:49 +03:00
|
|
|
|
|
|
|
// Send ether
|
|
|
|
submit.onclick = function() {
|
2016-08-04 10:43:59 +03:00
|
|
|
|
|
|
|
// Matt (from Etherscan) is working on a gasPrice API call, which
|
|
|
|
// should be done within a week or so.
|
2017-04-06 00:14:09 +03:00
|
|
|
// @TODO
|
2018-06-22 03:58:13 +03:00
|
|
|
//var gasPrice = (activeWallet.provider.testnet ? 0x4a817c800: 0xba43b7400);
|
|
|
|
//console.log('GasPrice: ' + gasPrice);
|
2016-08-04 10:21:49 +03:00
|
|
|
|
2017-04-06 00:14:09 +03:00
|
|
|
var targetAddress = ethers.utils.getAddress(inputTargetAddress.value);
|
|
|
|
var amountWei = ethers.utils.parseEther(inputAmount.value);
|
2016-08-04 10:21:49 +03:00
|
|
|
activeWallet.send(targetAddress, amountWei, {
|
2018-06-22 03:58:13 +03:00
|
|
|
gasPrice: activeWallet.provider.getGasPrice(),
|
2016-08-04 10:21:49 +03:00
|
|
|
gasLimit: 21000,
|
2018-06-22 03:58:13 +03:00
|
|
|
}).then(function(tx) {
|
|
|
|
console.log(tx);
|
|
|
|
|
|
|
|
// Since we only use standard networks, network will always be known
|
|
|
|
var tag = activeWallet.provider.network.name + '.';
|
|
|
|
if (tag === 'homestead.') { tag = ''; }
|
|
|
|
var url = 'https://' + tag + 'etherscan.io/tx/' + tx.hash;
|
|
|
|
addActivity('< Transaction sent: ' + tx.hash.substring(0, 20) + '...', url);
|
2016-08-04 10:21:49 +03:00
|
|
|
alert('Success!');
|
|
|
|
|
|
|
|
inputTargetAddress.value = '';
|
|
|
|
inputAmount.value = '';
|
|
|
|
submit.classList.add('disable');
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}, function(error) {
|
2018-06-22 03:58:13 +03:00
|
|
|
console.log(error);
|
2016-08-04 10:21:49 +03:00
|
|
|
showError(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
function showSelect() {
|
|
|
|
document.getElementById('screen-select').style.display = 'block';
|
|
|
|
document.getElementById('screen-loading').style.display = 'none';
|
|
|
|
document.getElementById('screen-wallet').style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
function showLoading(title) {
|
|
|
|
document.getElementById('screen-select').style.display = 'none';
|
|
|
|
document.getElementById('screen-loading').style.display = 'block';
|
|
|
|
document.getElementById('screen-wallet').style.display = 'none';
|
|
|
|
|
|
|
|
document.getElementById('loading-header').textContent = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showWallet(wallet) {
|
2018-06-22 03:58:13 +03:00
|
|
|
var network = document.querySelector('.network.option.selected').getAttribute('data-network');
|
|
|
|
activeWallet = wallet.connect(new ethers.providers.getDefaultProvider(network));
|
2016-08-04 10:21:49 +03:00
|
|
|
|
|
|
|
document.getElementById('screen-select').style.display = 'none';
|
|
|
|
document.getElementById('screen-loading').style.display = 'none';
|
|
|
|
document.getElementById('screen-wallet').style.display = 'block';
|
|
|
|
|
|
|
|
var inputWalletAddress = document.getElementById('wallet-address');
|
|
|
|
inputWalletAddress.value = wallet.address;
|
|
|
|
inputWalletAddress.onclick = function() {
|
|
|
|
this.select();
|
|
|
|
};
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
//var privateKey = '0x3141592653589793238462643383279502884197169399375105820974944592';
|
2018-06-22 03:58:13 +03:00
|
|
|
//showWallet(new ethers.Wallet(privateKey));
|
2016-08-04 10:21:49 +03:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|