diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-09-28 23:41:34 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-09-28 23:41:34 +0200 |
commit | 274204c21e421ed13c66411ce56bb70dea03d410 (patch) | |
tree | 44f96996f5631526e96866fe583de2ca87ec2898 /content_scripts | |
parent | 29909a27f592ac1bca98bfe7058b576167445518 (diff) |
check contract hash, fix unicode bug
Diffstat (limited to 'content_scripts')
-rw-r--r-- | content_scripts/notify.ts | 80 |
1 files changed, 52 insertions, 28 deletions
diff --git a/content_scripts/notify.ts b/content_scripts/notify.ts index abc72616c..e50c93c4d 100644 --- a/content_scripts/notify.ts +++ b/content_scripts/notify.ts @@ -76,8 +76,8 @@ namespace TalerNotify { console.log("it's execute"); document.documentElement.style.visibility = "hidden"; taler.internalExecutePayment(resp.contractHash, - resp.payUrl, - resp.offerUrl); + resp.payUrl, + resp.offerUrl); } }); } @@ -163,38 +163,62 @@ namespace TalerNotify { return; } - const walletMsg = { - type: "check-repurchase", - detail: { - contract: offer.contract - }, + if (!offer.H_contract) { + console.error("H_contract field missing"); + return; + } + + let walletHashContractMsg = { + type: "hash-contract", + detail: {contract: offer.contract} }; - chrome.runtime.sendMessage(walletMsg, (resp: any) => { - if (resp.error) { - console.error("wallet backend error", resp); + chrome.runtime.sendMessage(walletHashContractMsg, (resp: any) => { + + if (!resp.hash) { + console.log("error", resp); + throw Error("hashing failed"); + } + + if (resp.hash != offer.H_contract) { + console.error("merchant-supplied contract hash is wrong"); return; } - if (resp.isRepurchase) { - console.log("doing repurchase"); - console.assert(resp.existingFulfillmentUrl); - console.assert(resp.existingContractHash); - window.location.href = subst(resp.existingFulfillmentUrl, - resp.existingContractHash); - - } else { - const uri = URI(chrome.extension.getURL("pages/confirm-contract.html")); - const params = { - offer: JSON.stringify(offer), - merchantPageUrl: document.location.href, - }; - const target = uri.query(params).href(); - if (msg.replace_navigation === true) { - document.location.replace(target); + + const walletMsg = { + type: "check-repurchase", + detail: { + contract: offer.contract + }, + }; + + chrome.runtime.sendMessage(walletMsg, (resp: any) => { + if (resp.error) { + console.error("wallet backend error", resp); + return; + } + if (resp.isRepurchase) { + console.log("doing repurchase"); + console.assert(resp.existingFulfillmentUrl); + console.assert(resp.existingContractHash); + window.location.href = subst(resp.existingFulfillmentUrl, + resp.existingContractHash); + } else { - document.location.href = target; + const uri = URI(chrome.extension.getURL( + "pages/confirm-contract.html")); + const params = { + offer: JSON.stringify(offer), + merchantPageUrl: document.location.href, + }; + const target = uri.query(params).href(); + if (msg.replace_navigation === true) { + document.location.replace(target); + } else { + document.location.href = target; + } } - } + }); }); }); |