Commit c1dc1be2 authored by kenshin-samourai's avatar kenshin-samourai
Browse files

display public and private keys when possible

parent ad634016
......@@ -50,13 +50,13 @@ table.grid th {
}
table.grid tr.header th {
text-align: center;
text-align: left;
}
table.grid td {
text-align: center;
text-align: left;
vertical-align: top;
padding: 2px;
padding: 2px 2px 2px 5px;
}
textarea {
......
......@@ -69,6 +69,22 @@
<div id="bob_notif_addr" class="result"></div>
</td>
</tr>
<tr>
<th>BIP47 NOTIFICATION PUBLIC KEY</th>
<td>
<div id="alice_notif_pubkey" class="result"></div>
</td>
<td>
<div id="bob_notif_pubkey" class="result"></div>
</td>
</tr>
<tr>
<th>BIP47 NOTIFICATION PRIVATE KEY</th>
<td>
<div id="alice_notif_privkey" class="result"></div>
</td>
<td>-</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
......@@ -91,7 +107,9 @@
<th>YOUR COUNTERPARTY</th>
</tr>
<tr>
<th>BIP47 PAYMENT ADDRESSES</th>
<th>
<div id="payment_addresses" class="result"></div>
</th>
<td>
<div id="alice_payment_addresses" class="result"></div>
</td>
......
function derivePaymentAddresses(pcode, key, idx, network) {
function derivePaymentAddresses(pcode, key, idx, network, getPrivKey) {
const pmt_pubkey = pcode.derivePaymentPublicKey(key, idx)
const pmt_privkey = getPrivKey ? pcode.derivePaymentPrivateKey(key, idx).toString('hex') : ''
const p2pkh = bitcoinjs.payments.p2pkh({
pubkey: pmt_pubkey,
......@@ -19,7 +20,7 @@ function derivePaymentAddresses(pcode, key, idx, network) {
network: network,
}).address
return [p2pkh, p2wpkh, p2sh]
return [p2pkh, p2wpkh, p2sh, pmt_pubkey.toString('hex'), pmt_privkey]
}
function isValidMnemonic(a_mnemonic) {
......@@ -53,14 +54,19 @@ function refresh() {
const a_p2pkh_addr = []
const a_p2wpkh_addr = []
const a_p2sh_addr = []
const a_pubkeys = []
const a_privkeys = []
const b_p2pkh_addr = []
const b_p2wpkh_addr = []
const b_p2sh_addr = []
const b_pubkeys = []
let addr_list = ''
let a_addr_list = ''
let b_addr_list = ''
let a_pcode = ''
let b_pcode = ''
let a_notif_privkey = ''
let a_notif_pubkey = ''
let b_notif_pubkey = ''
let a_notif_addr = ''
let b_notif_addr = ''
......@@ -102,7 +108,9 @@ function refresh() {
if (hasValidMnemonic) {
const a_seed = bip39.mnemonicToSeedSync(a_mnemonic, a_passphrase)
a_pcode = bip47.fromWalletSeed(a_seed, 0, network)
a_notif_privkey = a_pcode.derive(0).privateKey
const a_notif = a_pcode.derive(0)
a_notif_privkey = a_notif.privateKey
a_notif_pubkey = a_notif.publicKey
a_notif_addr = a_pcode.getNotificationAddress()
}
......@@ -115,14 +123,17 @@ function refresh() {
if (hasValidMnemonic && hasValidPaymentCode) {
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)
const a_res = derivePaymentAddresses(a_pcode, b_notif_pubkey, idx, network, true)
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)
a_pubkeys.push(a_res[3])
a_privkeys.push(a_res[4])
const b_res = derivePaymentAddresses(b_pcode, a_notif_privkey, idx, network, false)
b_p2pkh_addr.push(b_res[0])
b_p2wpkh_addr.push(b_res[1])
b_p2sh_addr.push(b_res[2])
b_pubkeys.push(b_res[3])
}
}
......@@ -131,27 +142,42 @@ function refresh() {
//
for (let i=0; i<a_p2pkh_addr.length; i++) {
const idx = offset_deriv + i
a_addr_list += `<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]}`
a_addr_list += `<br/><br/>`
b_addr_list += `<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]}`
b_addr_list += `<br/><br/>`
addr_list += `<br/>`
addr_list += `P2PKH<br/>`
addr_list += `P2WPKH<br/>`
addr_list += `P2WPKH/P2SH<br/>`
addr_list += `Public Key<br/>`
addr_list += `Private Key<br/>`
addr_list += `<br/>`
a_addr_list += `<b>BIP47 PAYMENT ADDRESS #${idx}</b><br/>`
a_addr_list += `${a_p2pkh_addr[i]}<br/>`
a_addr_list += `${a_p2wpkh_addr[i]}<br/>`
a_addr_list += `${a_p2sh_addr[i]}<br/>`
a_addr_list += `${a_pubkeys[i]}<br/>`
a_addr_list += `${a_privkeys[i]}<br/>`
a_addr_list += `<br/>`
b_addr_list += `<b>BIP47 PAYMENT ADDRESS #${idx}</b><br/>`
b_addr_list += `${b_p2pkh_addr[i]}<br/>`
b_addr_list += `${b_p2wpkh_addr[i]}<br/>`
b_addr_list += `${b_p2sh_addr[i]}<br/>`
b_addr_list += `${b_pubkeys[i]}<br/>`
b_addr_list += `-<br/><br/>`
}
if (hasValidMnemonic) {
$('#alice_paymentcode').html(a_pcode.toBase58())
$('#alice_notif_addr').text(a_notif_addr)
$('#alice_notif_pubkey').text(a_notif_pubkey.toString('hex'))
$('#alice_notif_privkey').text(a_notif_privkey.toString('hex'))
}
if (hasValidPaymentCode) {
$('#bob_notif_addr').text(b_notif_addr)
$('#bob_notif_pubkey').text(b_notif_pubkey.toString('hex'))
}
if (hasValidMnemonic && hasValidPaymentCode) {
$('#payment_addresses').html(addr_list)
$('#alice_payment_addresses').html(a_addr_list)
$('#bob_payment_addresses').html(b_addr_list)
}
......
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