aboutsummaryrefslogtreecommitdiff
path: root/extension/background
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-12-07 23:39:25 +0100
committerFlorian Dold <florian.dold@gmail.com>2015-12-07 23:39:25 +0100
commit415570a720a7a74b2d25699a55d03403e6d6231a (patch)
tree1fb56e2adc5da40bfd7247a42b41e5cf6d9d69b0 /extension/background
parentaeac228df7121dada4827ac248e61ba8b1db7318 (diff)
Towards reserve creation.
Diffstat (limited to 'extension/background')
-rw-r--r--extension/background/emscriptif.js102
-rw-r--r--extension/background/wallet.js35
2 files changed, 55 insertions, 82 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;
}
});