From 415570a720a7a74b2d25699a55d03403e6d6231a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 7 Dec 2015 23:39:25 +0100 Subject: Towards reserve creation. --- extension/background/emscriptif.js | 102 ++++++++----------------------------- extension/background/wallet.js | 35 +++++++++++++ 2 files changed, 55 insertions(+), 82 deletions(-) (limited to 'extension/background') 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 - - */ +"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; } }); -- cgit v1.2.3