parse_str_secret_key js function added

master
moneroexamples 7 years ago
parent 589a5d9548
commit d2c0a4895d

@ -211,11 +211,17 @@
return; return;
} }
// when using subaddress, there can be more than one tx_prv_key
var multiple_tx_prv_keys = parse_str_secret_key(tx_prv_key);
console.log("multiple_tx_prv_keys: ", multiple_tx_prv_keys);
try { try {
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,
add_tx_pub_keys); multiple_tx_prv_keys);
} 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>' );
@ -224,6 +230,25 @@
}); });
// based on C++ by stoffu
function parse_str_secret_key(key_str) {
var multiple_tx_secret_keys = [];
var num_keys = Math.floor(key_str.length / 64);
if (num_keys * 64 != key_str.length)
throw "num_keys * 64 != key_str.length for " + num_keys + " and " + key_str;
for (var i = 0; i < num_keys; i++)
{
multiple_tx_secret_keys.push(key_str.slice(64*i, 64*i + 64));
}
return multiple_tx_secret_keys;
}
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) {
//console.log(tx_json); //console.log(tx_json);

@ -77,14 +77,18 @@ bool
parse_str_secret_key(const string& key_str, std::vector<T>& secret_keys) parse_str_secret_key(const string& key_str, std::vector<T>& secret_keys)
{ {
const size_t num_keys = key_str.size() / 64; const size_t num_keys = key_str.size() / 64;
if (num_keys * 64 != key_str.size()) if (num_keys * 64 != key_str.size())
return false; return false;
secret_keys.resize(num_keys); secret_keys.resize(num_keys);
for (size_t i = 0; i < num_keys; ++i) for (size_t i = 0; i < num_keys; ++i)
{ {
if (!parse_str_secret_key(key_str.substr(64*i, 64), secret_keys[i])) if (!parse_str_secret_key(key_str.substr(64*i, 64), secret_keys[i]))
return false; return false;
} }
return true; return true;
} }

Loading…
Cancel
Save