Commit 7c7e1edc authored by kenshin-samourai's avatar kenshin-samourai
Browse files

initial commit

parent e91ce9c3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BIP47 DERIVATION TOOL</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/bitcoinjs-bundle.js"></script>
<script src="js/bip32-bundle.js"></script>
<script src="js/bip39-bundle.js"></script>
<script src="js/bip47-bundle.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>BIP47 DERIVATION TOOL</h1>
<table>
<tbody>
<tr>
<td width="20%"></td>
<td width="50%"></td>
<td width="30%"></td>
</tr>
<tr>
<th>BITCOIN NETWORK</th>
<td colspan="2">
<select id="network">
<option value="bitcoin">MAINNET</option>
<option value="testnet">TESTNET</option>
</select>
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<th></th>
<th>YOUR WALLET</th>
<th>YOUR COUNTERPARTY</th>
</tr>
<tr>
<th>BIP39 MNEMONIC</th>
<td>
<textarea id="alice_mnemonic"></textarea>
</td>
<td>-</td>
</tr>
<tr>
<th>BIP39 PASSPHRASE</th>
<td>
<textarea id="alice_passphrase"></textarea>
</td>
<td>-</td>
</tr>
<tr>
<th>BIP47 PAYMENT CODE</th>
<td>
<div id="alice_paymentcode"></div>
</td>
<td>
<textarea id="bob_paymentcode"></textarea>
</td>
</tr>
<tr>
<th>BIP47 NOTIFICATION ADDRESS</th>
<td>
<div id="alice_notif_addr"></div>
</td>
<td>
<div id="bob_notif_addr"></div>
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<th colspan="3">
<span>DERIVE</span>
<select id="derivation_nb_addresses">
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<span>ADDRESSES STARTING FROM INDEX</span>
<input id="derivation_start_index" value="0"/>
</th>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<th></th>
<th>YOUR WALLET</th>
<th>YOUR COUNTERPARTY</th>
</tr>
<tr>
<th>BIP47 PAYMENT ADDRESSES</th>
<td>
<div id="alice_payment_addresses"></div>
</td>
<td>
<div id="bob_payment_addresses"></div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
\ No newline at end of file
function derivePaymentAddresses(pcode, key, idx, network) {
const pmt_pubkey = pcode.derivePaymentPublicKey(key, idx)
const p2pkh = bitcoinjs.payments.p2pkh({
pubkey: pmt_pubkey,
network: network,
}).address
const p2wpkh = bitcoinjs.payments.p2wpkh({
pubkey: pmt_pubkey,
network: network,
}).address
const p2sh = bitcoinjs.payments.p2sh({
redeem: bitcoinjs.payments.p2wpkh({
pubkey: pmt_pubkey,
network: network,
}),
network: network,
}).address
return [p2pkh, p2wpkh, p2sh]
}
function refresh() {
const a_p2pkh_addr = []
const a_p2wpkh_addr = []
const a_p2sh_addr = []
const b_p2pkh_addr = []
const b_p2wpkh_addr = []
const b_p2sh_addr = []
// Retrieve data from form
const network = bitcoinjs.networks[$('#network').val()]
const nb_addr_deriv = parseInt($('#derivation_nb_addresses').val())
const offset_deriv = parseInt($('#derivation_start_index').val())
const a_mnemonic = $('#alice_mnemonic').val()
const a_passphrase = $('#alice_passphrase').val()
const b_pcode_b58 = $('#bob_paymentcode').val()
// Clear results
$('#alice_paymentcode').html('')
$('#alice_notif_addr').text('')
$('#bob_notif_addr').text('')
$('#alice_payment_addresses').html('')
$('#bob_payment_addresses').html('')
// Check data
if (!bip39.validateMnemonic(a_mnemonic)) {
alert('This is not a valid mnemonic')
return
}
// Compute bip47 derivations
const a_seed = bip39.mnemonicToSeedSync(a_mnemonic, a_passphrase)
const a_pcode = bip47.fromWalletSeed(a_seed, 0, network)
const a_notif_privkey = a_pcode.derive(0).privateKey
const a_notif_addr = a_pcode.getNotificationAddress()
const b_pcode = bip47.fromBase58(b_pcode_b58, network)
const b_notif_pubkey = b_pcode.derive(0).publicKey
const b_notif_addr = b_pcode.getNotificationAddress()
for (let i=0; i<nb_addr_deriv; i++) {
const idx = offset_deriv + i
const a_res = derivePaymentAddresses(a_pcode, b_notif_pubkey, idx, network)
a_p2pkh_addr.push(a_res[0])
a_p2wpkh_addr.push(a_res[1])
a_p2sh_addr.push(a_res[2])
const b_res = derivePaymentAddresses(b_pcode, a_notif_privkey, idx, network)
b_p2pkh_addr.push(b_res[0])
b_p2wpkh_addr.push(b_res[1])
b_p2sh_addr.push(b_res[2])
}
// Prepare ard display results
let a_addr_list = ''
let b_addr_list = ''
for (let i=0; i<nb_addr_deriv; i++) {
const idx = offset_deriv + i
a_addr_list += `<br/><br/><b>Address #${idx}</b>`
a_addr_list += `<br/> ${a_p2pkh_addr[i]}`
a_addr_list += `<br/> ${a_p2wpkh_addr[i]}`
a_addr_list += `<br/> ${a_p2sh_addr[i]}`
b_addr_list += `<br/><br/><b>Address #${idx}</b>`
b_addr_list += `<br/> ${b_p2pkh_addr[i]}`
b_addr_list += `<br/> ${b_p2wpkh_addr[i]}`
b_addr_list += `<br/> ${b_p2sh_addr[i]}`
}
$('#alice_paymentcode').html(a_pcode.toBase58())
$('#alice_notif_addr').text(a_notif_addr)
$('#bob_notif_addr').text(b_notif_addr)
$('#alice_payment_addresses').html(a_addr_list)
$('#bob_payment_addresses').html(b_addr_list)
}
$(document).ready(function() {
$('#network').change(evt => { refresh() })
$('#alice_mnemonic').change(evt => { refresh() })
$('#alice_passphrase').change(evt => { refresh() })
$('#bob_paymentcode').change(evt => { refresh() })
$('#derivation_nb_addresses').change(evt => { refresh() })
$('#derivation_start_index').change(evt => { refresh() })
})
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment