forked from greenaddress/WalletCrx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bip38_sandbox.html
35 lines (35 loc) · 1.65 KB
/
bip38_sandbox.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
<script>GAIT_IN_WORKER = true;</script>
<script type="text/javascript" src="/static/js/scrypt.js"></script>
<script type="text/javascript" src="/static/js/bitcoinjs.min.js"></script>
<script type="text/javascript" src="/static/js/bitcoinjs_util.js"></script>
<script type="text/javascript" src="/static/js/bip38.min.js"></script>
<script>
window.addEventListener('message', function(event) {
var input = event.data;
var bitcoinBip38 = new Bitcoin.bip38();
if (input.eckey) {
var ecpair = Bitcoin.bitcoin.ECPair.fromWIF(input.eckey, input.network);
// for compatibility with iOS, use mainnet bitcoin addr instead of testnet for salt:
ecpair.network = Bitcoin.bitcoin.networks.bitcoin;
event.source.postMessage(bitcoinBip38.encrypt(
input.eckey,
input.password,
ecpair.getAddress()
), event.origin);
} else if (input.mnemonic_decrypted) {
event.source.postMessage(bip38.encrypt({data: input.mnemonic_decrypted, key: input.password}, input.salt_a), event.origin);
} else if (input.mnemonic_encrypted) {
event.source.postMessage(bip38.decrypt({data: input.mnemonic_encrypted, key: input.password}), event.origin);
} else {
try {
event.source.postMessage(bitcoinBip38.decrypt(input.b58, input.password), event.origin);
} catch (e) {
if (e.message.indexOf("Hash could not be verified.") != -1) {
event.source.postMessage({error: 'invalid_passphrase'}, event.origin);
} else {
event.source.postMessage({error: 'invalid_privkey'}, event.origin);
}
}
};
});
</script>