diff options
-rw-r--r-- | extension/background/emscriptif.js | 102 | ||||
-rw-r--r-- | extension/background/wallet.js | 35 | ||||
-rw-r--r-- | extension/content_scripts/notify.js | 19 | ||||
-rw-r--r-- | extension/manifest.json | 8 | ||||
-rw-r--r-- | extension/pages/confirm-create-reserve.html | 23 | ||||
-rw-r--r-- | extension/pages/confirm-create-reserve.js | 43 | ||||
-rw-r--r-- | extension/pages/reserve-success.html | 12 | ||||
-rw-r--r-- | extension/style/wallet.css | 19 |
8 files changed, 178 insertions, 83 deletions
diff --git a/extension/background/emscriptif.js b/extension/background/emscriptif.js index 62b233eda..ceed32c97 100644 --- a/extension/background/emscriptif.js +++ b/extension/background/emscriptif.js @@ -13,87 +13,10 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - - */ +"use strict"; -var EXPORTED_SYMBOLS = [ - 'TWRhelloWorld', - 'TWRgetValue', - 'TWRgetFraction', - 'TWRgetCurrency', - 'TamountCmp', - 'TWRverifyConfirmation', - 'TWRverifySignKey', - 'TWRverifyDenom', - 'TWRverifyDenoms', - 'TWRALLrsaPublicKeyHash', - 'TWRALLgetEncodingFromRsaSignature', - 'DWRtestStringCmp', - 'TWRmultiplyAmount', - 'TWRmultiplyAmounts', - 'DWRdumpAmount', - 'TWRALLgetAmount', - 'DWRtestString', - 'DWRgetPurpose', - 'TWReddsaVerify', - 'TamountAdd', - 'TamountSubtract', - 'TWRALLmakeEddsaSignature', - 'TWRALLamountAdd', - 'TWRALLeddsaPublicKeyFromPrivate', - 'TWRALLeddsaPublicKeyFromPrivString', - 'TWRALLeddsaPrivateKeyFromString', - 'TWRALLeccEcdh', - 'TWRALLhash', - 'TWRALLecdhePublicKeyFromPrivateKey', - 'TWRALLrsaPublicKeyDecodeFromString', - 'GCeddsaSign', - 'TWRALLmakeWithdrawBundle', - 'GCALLrsaSignatureDecode', - 'GCrsaSignatureEncode', - 'TWRALLsignDepositPermission', - 'GCALLrsaPublicKeyDecode', - 'GCALLrsaPublicKeyEncode', - 'WRALLeddsaPublicKey', - 'GCALLeddsaKeyCreate', - 'WRALLecdhePublicKey ', - 'GSALLdataToStringAlloc', - 'TWRgnunetFree', - 'GSstringToData', - 'TWRALLgetCurrentTime', - 'TWRgetFancyTime', - 'GChash', - 'getHashedArray', - 'TWRALLsignTest', - 'GCALLecdheKeyCreate', - 'GCecdheKeyGetPublic', - 'WRALLecdhePublicKey', - 'WRverifyTest', - 'GCeccEcdh', - 'TWRALLgenSymmetricKey', - 'TWRALLgenInitVector', - 'GCsymmetricDecrypt', - 'GCsymmetricEncrypt', - 'TWRALLgenKeyFromBlob', - 'GCALLrsaPrivateKeyGetPublic', - 'GCALLrsaPrivateKeyCreate', - 'GCALLrsaBlindingKeyCreate', - 'GCrsaBlindingKeyFree', - 'GCrsaPublicKeyFree', - 'GCrsaPrivateKeyFree', - 'GCALLrsaBlind', - 'GCALLrsaUnblind', - 'GCALLrsaSign', - 'GCrsaVerify', - 'GCrsaSignatureFree', - 'GCeddsaKeyGetPublic', - 'WRALLmakePurpose', - 'GChkdf', - 'emscMalloc', - 'emscFree' -]; /* The following definition is needed to make emscripted library to remain 'alive' after its loading. Otherwise, the normal behaviour would be: @@ -143,19 +66,15 @@ getLastWindow().Module = { // shortcut to emscr's 'malloc' function emscMalloc(size) { - var ptr = Module._malloc(size); return ptr; - } /* shortcut to emscr's 'free'. This function is problematic: it randomly stops working giving 'emscFree is not a function' error */ function emscFree(ptr) { - Module._free(ptr); - } var getEmsc = Module.cwrap; @@ -585,3 +504,22 @@ var TWRALLsignTest = getEmsc('TALER_WRALL_sign_test', var WRverifyTest = getEmsc('WR_verify_test', 'number', ['number']); + + +let d2s = getEmsc('GNUNET_STRINGS_data_to_string_alloc', + 'string', + ['number', 'number']); + + +let sizeof_EddsaPrivateKey = 32; +let sizeof_EddsaPublicKey = 32; + + +function createEddsaKeyPair() { + let privPtr = GCALLeddsaKeyCreate(); + let pubPtr = emscMalloc(sizeof_EddsaPublicKey); + GCeddsaKeyGetPublic(privPtr, pubPtr); + let privStr = d2s(privPtr, sizeof_EddsaPrivateKey); + let pubStr = d2s(pubPtr, sizeof_EddsaPublicKey); + return {priv: privStr, pub: pubStr}; +} diff --git a/extension/background/wallet.js b/extension/background/wallet.js index 1e8dd6a7c..2d3687f98 100644 --- a/extension/background/wallet.js +++ b/extension/background/wallet.js @@ -17,6 +17,8 @@ DB.open(function () { console.log ("DB: ready"); }); +let DONE = 4; + chrome.runtime.onMessage.addListener( function (req, sender, onresponse) { console.log("Message: " + req.type + @@ -36,5 +38,38 @@ chrome.runtime.onMessage.addListener( case "db-list-reserves": DB.reserve_list (onresponse); break; + case "confirm-reserve": + console.log('detail: ' + JSON.stringify(req.detail)); + let keypair = createEddsaKeyPair(); + let form = new FormData(); + form.append(req.detail.field_amount, req.detail.amount_str); + form.append(req.detail.field_reserve_pub, keypair.pub); + form.append(req.detail.field_mint, req.detail.mint); + // XXX: set bank-specified fields. + let myRequest = new XMLHttpRequest(); + console.log("making request to " + req.detail.post_url); + myRequest.open('post', req.detail.post_url); + myRequest.send(form); + myRequest.addEventListener('readystatechange', (e) => { + if (myRequest.readyState == DONE) { + let resp = {}; + resp.status = myRequest.status; + resp.text = myRequest.responseText; + switch (myRequest.status) { + case 200: + resp.success = true; + // We can't show the page directly, so + // we show some generic page from the wallet. + resp.backlink = chrome.extension.getURL("pages/reserve-success.html"); + break; + default: + resp.success = false; + } + onresponse(resp); + } + }); + // Allow async response + return true; + break; } }); diff --git a/extension/content_scripts/notify.js b/extension/content_scripts/notify.js index 94356cf52..0fab0e6dc 100644 --- a/extension/content_scripts/notify.js +++ b/extension/content_scripts/notify.js @@ -18,6 +18,25 @@ document.addEventListener("DOMContentLoaded", function(e) { document.body.dispatchEvent(evt); console.log("bank handshake done"); }); + document.body.addEventListener('taler-create-reserve', function(e) { + let $ = (x) => document.getElementById(x); + console.log("taler-create-reserve with " + JSON.stringify(e.detail)); + let form_uri = $(e.detail.form_id).action; + // TODO: validate event fields + // TODO: also send extra bank-defined form fields + let params = { + post_url: URI(form_uri).absoluteTo(document.location.href).href(), + // TODO: This should change in the future, we should not deal with the + // amount as a bank-specific string here. + amount_str: $(e.detail.input_amount).value, + // TODO: This double indirection is way too much ... + field_amount: $(e.detail.input_amount).name, + field_reserve_pub: $(e.detail.input_pub).name, + field_mint: $(e.detail.mint_rcv).name, + }; + let uri = URI(chrome.extension.getURL("pages/confirm-create-reserve.html")); + document.location.href = uri.query(params).href(); + }); }); console.log("Taler wallet: content page loaded"); diff --git a/extension/manifest.json b/extension/manifest.json index 9a1b1f3bf..0dad29ca6 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -26,12 +26,18 @@ "matches": ["*://*/*"], "js": [ "content_scripts/notify.js", - "lib/URI.js" + "lib/URI.js", + "lib/util.js" ], "run_at": "document_start" } ], + "web_accessible_resources": [ + "pages/*", + "lib/*" + ], + "background": { "scripts": [ "lib/util.js", diff --git a/extension/pages/confirm-create-reserve.html b/extension/pages/confirm-create-reserve.html new file mode 100644 index 000000000..4a01e47d1 --- /dev/null +++ b/extension/pages/confirm-create-reserve.html @@ -0,0 +1,23 @@ +<!doctype html> + +<html> + <head> + <title>Taler Wallet: Confirm Reserve Creation</title> + <script src="../lib/URI.js"></script> + <script src="confirm-create-reserve.js"></script> + <link rel="stylesheet" type="text/css" href="../style/wallet.css"> + </head> + <body> + <h1>Confirm Reserve Creation</h1> + Hello, this is the wallet. A bank wants to create a reserve for <span id=show-amount>(loading...)</span>. + Please specify the base URL of the mint you want to use. + <p /> + <div class='formish'> + <div class='form-row'> + <label for='mint-url'>Mint URL</label> + <input class='url' id='mint-url' type="text"></input> + </div> + <button id='confirm'>Confirm Reserve</button> + </div> + </body> +</html> diff --git a/extension/pages/confirm-create-reserve.js b/extension/pages/confirm-create-reserve.js new file mode 100644 index 000000000..5c35121e3 --- /dev/null +++ b/extension/pages/confirm-create-reserve.js @@ -0,0 +1,43 @@ +"use strict"; + +let url = URI(document.location.href); +let query = URI.parseQuery(url.query()); + +function updateAmount() { + let showAmount = document.getElementById("show-amount"); + console.log("Query is " + JSON.stringify(query)); + let s = query.amount_str; + if (!s) { + document.body.innerHTML = "Oops, something went wrong."; + return; + } + showAmount.textContent = s; +} + +function clone(obj) { + // This is faster than it looks ... + return JSON.parse(JSON.stringify(obj)); +} + +document.addEventListener("DOMContentLoaded", (e) => { + updateAmount(); + + document.getElementById("confirm").addEventListener("click", (e) => { + let d = clone(query); + d.mint = document.getElementById('mint-url').value; + chrome.runtime.sendMessage({type:'confirm-reserve', detail: d}, (resp) => { + if (resp.success === true) { + document.location.href = resp.backlink; + } else { + document.body.innerHTML = + `Oops, something went wrong. + The bank responded with HTTP status code ${resp.status}. + Here is some more info: + <pre>${resp.text}</pre>`; + } + }); + + }); +}); + + diff --git a/extension/pages/reserve-success.html b/extension/pages/reserve-success.html new file mode 100644 index 000000000..81de9cb41 --- /dev/null +++ b/extension/pages/reserve-success.html @@ -0,0 +1,12 @@ +<!doctype html> + +<html> + <head> + <title>Taler Wallet: Reserve Created</title> + <link rel="stylesheet" type="text/css" href="../style/wallet.css"> + </head> + <body> + <h1>Success!</h1> + The reserve was created successfully. + </body> +</html> diff --git a/extension/style/wallet.css b/extension/style/wallet.css new file mode 100644 index 000000000..ba698296a --- /dev/null +++ b/extension/style/wallet.css @@ -0,0 +1,19 @@ +.form-row { + padding-top: 5px; + padding-bottom: 5px; +} + +label { + padding-right: 1em; +} + +label::after { + content: ":"; +} + +input.url { + width: 25em; +} + +.formish { +} |