Advanced: ReserveProof: Add support for reserve proof

This change adds the ability to prove and check a reserve proof
to this existing "Prove/check" advanced menu. If the amount line has
a valid amount less than that of the current account index this input
will drive the logic for generating a reserve proof. Checking a reserve
proof is accomplished by validating the address and verifying that
signature.indexOf("ReserveProofV") === 0. The result displays the total
and spent amount of the proof.
This commit is contained in:
reemuru
2022-01-18 16:10:56 -05:00
parent a959919b8a
commit 0f67580e8f
6 changed files with 103 additions and 29 deletions

View File

@@ -985,24 +985,28 @@ ApplicationWindow {
}
// called on "getProof"
function handleGetProof(txid, address, message) {
console.log("Getting payment proof: ")
console.log("\ttxid: ", txid,
", address: ", address,
", message: ", message);
function spendProofFallback(txid, result){
if (!result || result.indexOf("error|") === 0) {
currentWallet.getSpendProofAsync(txid, message, txProofComputed);
} else {
txProofComputed(txid, result);
function handleGetProof(txid, address, message, amount) {
if (amount.length > 0) {
var result = currentWallet.getReserveProof(false, currentWallet.currentSubaddressAccount, walletManager.amountFromString(amount), message)
txProofComputed(null, result)
} else {
console.log("Getting payment proof: ")
console.log("\ttxid: ", txid,
", address: ", address,
", message: ", message);
function spendProofFallback(txid, result){
if (!result || result.indexOf("error|") === 0) {
currentWallet.getSpendProofAsync(txid, message, txProofComputed);
} else {
txProofComputed(txid, result);
}
}
if (address.length > 0)
currentWallet.getTxProofAsync(txid, address, message, spendProofFallback);
else
spendProofFallback(txid, null);
}
if (address.length > 0)
currentWallet.getTxProofAsync(txid, address, message, spendProofFallback);
else
spendProofFallback(txid, null);
informationPopup.open()
}
function txProofComputed(txid, result){
@@ -1025,12 +1029,18 @@ ApplicationWindow {
", signature: ", signature);
var result;
if (address.length > 0)
var isReserveProof = signature.indexOf("ReserveProofV") === 0;
if (address.length > 0 && !isReserveProof) {
result = currentWallet.checkTxProof(txid, address, message, signature);
else
}
else if (isReserveProof) {
result = currentWallet.checkReserveProof(address, message, signature);
}
else {
result = currentWallet.checkSpendProof(txid, message, signature);
}
var results = result.split("|");
if (address.length > 0 && results.length == 5 && results[0] === "true") {
if (address.length > 0 && results.length == 5 && results[0] === "true" && !isReserveProof) {
var good = results[1] === "true";
var received = results[2];
var in_pool = results[3] === "true";
@@ -1058,6 +1068,12 @@ ApplicationWindow {
informationPopup.title = qsTr("Payment proof check") + translationManager.emptyString;
informationPopup.icon = good ? StandardIcon.Information : StandardIcon.Critical;
informationPopup.text = good ? qsTr("Good signature") : qsTr("Bad signature");
}
else if (isReserveProof && results[0] === "true") {
var good = results[1] === "true";
informationPopup.title = qsTr("Reserve proof check") + translationManager.emptyString;
informationPopup.icon = good ? StandardIcon.Information : StandardIcon.Critical;
informationPopup.text = good ? qsTr("Good signature on ") + results[2] + qsTr(" total and ") + results[3] + qsTr(" spent.") : qsTr("Bad signature");
}
else {
informationPopup.title = qsTr("Error") + translationManager.emptyString;