multiple output tx with sub-address

master
moneroexamples 7 years ago
parent d2c0a4895d
commit 5473bf25ee

@ -190,11 +190,13 @@
return; return;
} }
multiple_tx_secret_keys = [];
try { try {
var address_decoded = decode_address(address); var address_decoded = decode_address(address);
decodeOutputs(tx_json, tx_public_key, viewkey, decodeOutputs(tx_json, tx_public_key, viewkey,
address_decoded.spend, payment_id, address_decoded.spend, payment_id,
add_tx_pub_keys); add_tx_pub_keys, multiple_tx_secret_keys, false);
} catch(err){ } catch(err){
console.log(err); console.log(err);
$("#decode-prove-results").html('<h4>Error:' + err.message + '</h4>' ); $("#decode-prove-results").html('<h4>Error:' + err.message + '</h4>' );
@ -221,7 +223,7 @@
var address_decoded = decode_address(address); var address_decoded = decode_address(address);
decodeOutputs(tx_json, address_decoded.view, tx_prv_key, decodeOutputs(tx_json, address_decoded.view, tx_prv_key,
address_decoded.spend, payment_id, address_decoded.spend, payment_id,
multiple_tx_prv_keys); add_tx_pub_keys, multiple_tx_prv_keys, true);
} catch(err){ } catch(err){
console.log(err); console.log(err);
$("#decode-prove-results").html('<h4>Error:' + err.message + '</h4>' ); $("#decode-prove-results").html('<h4>Error:' + err.message + '</h4>' );
@ -250,24 +252,34 @@
function decodeOutputs(tx_json, pub_key, sec_key, function decodeOutputs(tx_json, pub_key, sec_key,
address_pub_key, payment_id, add_tx_pub_keys) { address_pub_key, payment_id,
add_tx_pub_keys, multiple_tx_prv_keys, tx_prove) {
//console.log(tx_json); //console.log(tx_json);
var is_rct = (tx_json.version === 2); var is_rct = (tx_json.version === 2);
var rct_type = (is_rct ? tx_json.rct_signatures.type : -1); var rct_type = (is_rct ? tx_json.rct_signatures.type : -1);
var key_derivation = generate_key_derivation(pub_key, sec_key); var key_derivation = "";
if (tx_prove)
key_derivation = generate_key_derivation(pub_key, multiple_tx_prv_keys[0]);
else
key_derivation = generate_key_derivation(pub_key, sec_key);
var add_key_derivation = []; var add_key_derivation = [];
if (add_tx_pub_keys) { if (add_tx_pub_keys) {
for (var i = 0; i < add_tx_pub_keys.length; i++) for (var i = 0; i < add_tx_pub_keys.length; i++)
{ {
if (!tx_prove)
add_key_derivation.push(generate_key_derivation(add_tx_pub_keys[i], sec_key)); add_key_derivation.push(generate_key_derivation(add_tx_pub_keys[i], sec_key));
else
add_key_derivation.push(generate_key_derivation(pub_key, multiple_tx_prv_keys[i+1]));
} }
} }
console.log("add_key_derivation: ", add_key_derivation); //console.log("add_key_derivation: ", add_key_derivation);
// go over each tx output, and check if it is ours or not // go over each tx output, and check if it is ours or not
@ -291,17 +303,32 @@
var output_pub_key = output.target.key; var output_pub_key = output.target.key;
var amount = output.amount; var amount = output.amount;
var pubkey_generated = (add_tx_pub_keys // var pubkey_generated = (add_tx_pub_keys
? derive_public_key(add_key_derivation[output_idx], // ? derive_public_key(add_key_derivation[output_idx],
output_idx, address_pub_key) // output_idx, address_pub_key)
: derive_public_key(key_derivation, output_idx, address_pub_key)); // : derive_public_key(key_derivation, output_idx, address_pub_key));
console.log(pubkey_generated); var pubkey_generated = derive_public_key(key_derivation, output_idx, address_pub_key);
//console.log(pubkey_generated);
var mine_output = (output_pub_key == pubkey_generated); var mine_output = (output_pub_key == pubkey_generated);
var with_additional = false;
var mine_output_str = "false"; var mine_output_str = "false";
if (!mine_output && add_tx_pub_keys.length == tx_json.vout.length) {
pubkey_generated = derive_public_key(add_key_derivation[output_idx],
output_idx, address_pub_key);
mine_output = (output_pub_key == pubkey_generated);
with_additional = true;
}
if (mine_output) { if (mine_output) {
mine_output_str = '<span style="color: #008009;font-weight: bold">true</span>'; mine_output_str = '<span style="color: #008009;font-weight: bold">true</span>';
@ -309,12 +336,11 @@
if (is_rct) { if (is_rct) {
try { try {
//var ecdh = decodeRct(tx_json.rct_signatures, output_idx, key_derivation); //var ecdh = decodeRct(tx_json.rct_signatures, output_idx, key_derivation);
var ecdh = decodeRct(tx_json.rct_signatures, output_idx,
(with_additional ? add_key_derivation[output_idx] : key_derivation));
var ecdh = (add_tx_pub_keys
? decodeRct(tx_json.rct_signatures, output_idx, add_key_derivation[output_idx])
: decodeRct(tx_json.rct_signatures, output_idx, key_derivation));
amount = ecdh.amount; amount = parseInt(ecdh.amount);
} catch (err) { } catch (err) {
decoding_results_str += "<span class='validNo'>RingCT amount for output " + i + " with pubkey: " + output_pub_key + "</span>" + "<br>"; //rct commitment != computed decoding_results_str += "<span class='validNo'>RingCT amount for output " + i + " with pubkey: " + output_pub_key + "</span>" + "<br>"; //rct commitment != computed
throw "invalid rct amount"; throw "invalid rct amount";
@ -327,8 +353,8 @@
decoding_results_str += "<tr>" decoding_results_str += "<tr>"
+"<td>" + output_idx + "</td>" +"<td>" + output_idx + "</td>"
+"<td>" + output_pub_key + "</td>" +"<td>" + output_pub_key + "</td>"
+"<td>" + mine_output_str + "</td>"
+"<td>" + (amount / 1e12) + "</td>" +"<td>" + (amount / 1e12) + "</td>"
+"<td>" + mine_output_str + "</td>"
+"</tr>"; +"</tr>";
//console.log(output[1], pubkey_generated); //console.log(output[1], pubkey_generated);

Loading…
Cancel
Save