From 715f467392d0e60b96aa75ced59a609502fb768b Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 19 Jan 2018 08:09:04 +0800 Subject: [PATCH] mvp js decoding/proving enabled --- src/templates/js/config.js | 2 +- src/templates/partials/tx_details.html | 29 ++++++++++---------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/templates/js/config.js b/src/templates/js/config.js index 123dc00..03f521f 100755 --- a/src/templates/js/config.js +++ b/src/templates/js/config.js @@ -1,5 +1,5 @@ var config = { - testnet: true, //@todo need to make it automated + testnet: false, //@todo need to make it automated coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero diff --git a/src/templates/partials/tx_details.html b/src/templates/partials/tx_details.html index ece4530..a0685d2 100644 --- a/src/templates/partials/tx_details.html +++ b/src/templates/partials/tx_details.html @@ -154,7 +154,6 @@ // to decode and prove txs. $(document).ready(function() { - // we need output pubplic keys, their indexes and amounts. // all this is already avaliable on the html, but we can use // musch framework to produce js array for this @@ -163,18 +162,6 @@ var tx_public_key = $("#tx_pub_key").text(); - // get the tx publick key outputs from the hidden field - var tx_outputs_tmp = $("#tx_outputs").val().split(';'); - - var tx_outputs = []; - - for (var i = 0; i < tx_outputs_tmp.length - 1; i++) { - tx_outputs.push(tx_outputs_tmp[i].split(',')); - } - - //console.log(is_rct, rct_type, tx_outputs); - - $("#decode_btn").click(function() { @@ -188,7 +175,6 @@ }); $("#prove_btn").click(function() { - $("#decode-prove-results").html("Prove button pressed"); var address = $("input[name=xmraddress]").val(); var tx_prv_key = $("input[name=txprvkey]").val(); @@ -219,6 +205,8 @@ var output_idx = 0; + var sum_outptus = 0; + tx_json.vout.forEach(function(output) { var output_pub_key = output.target.key; @@ -237,19 +225,21 @@ if (is_rct) { try { var ecdh = decodeRct(tx_json.rct_signatures, output_idx, key_derivation); - amount = ecdh.amount / 1e12; + amount = ecdh.amount; } catch (err) { decoding_results_str += "RingCT amount for output " + i + " with pubkey: " + output_pub_key + "" + "
"; //rct commitment != computed throw "invalid rct amount"; } } + + sum_outptus += amount; } decoding_results_str += "" +"" + output_idx + "" +"" + output_pub_key + "" +"" + mine_output_str + "" - +"" + amount + "" + +"" + (amount / 1e12) + "" +""; //console.log(output[1], pubkey_generated); @@ -259,6 +249,8 @@ decoding_results_str += "" + decoding_results_str += "

Sum XMR from matched outputs (i.e., incoming XMR): " + (sum_outptus / 1e12) + "

" + $("#decode-prove-results").html(decoding_results_str); } @@ -267,12 +259,13 @@ var H = "8b655970153799af2aeadc9ff1add0ea6c7251d54154cfa92c173a0dd39c1f94"; + // from https://xmr.llcoins.net/js/site.js function decodeRct(rv, i, der){ var key = derivation_to_scalar(der, i); var ecdh = decode_rct_ecdh(rv.ecdhInfo[i], key); - console.log(ecdh); + //console.log(ecdh); var Ctmp = commit(ecdh.amount, ecdh.mask); - console.log(Ctmp); + //console.log(Ctmp); if (Ctmp !== rv.outPk[i]){ throw "mismatched commitments!"; }