Towards reserve creation.
This commit is contained in:
parent
aeac228df7
commit
415570a720
@ -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};
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
@ -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");
|
||||
|
@ -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",
|
||||
|
23
extension/pages/confirm-create-reserve.html
Normal file
23
extension/pages/confirm-create-reserve.html
Normal file
@ -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>
|
43
extension/pages/confirm-create-reserve.js
Normal file
43
extension/pages/confirm-create-reserve.js
Normal file
@ -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>`;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
12
extension/pages/reserve-success.html
Normal file
12
extension/pages/reserve-success.html
Normal file
@ -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>
|
19
extension/style/wallet.css
Normal file
19
extension/style/wallet.css
Normal file
@ -0,0 +1,19 @@
|
||||
.form-row {
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
label {
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
label::after {
|
||||
content: ":";
|
||||
}
|
||||
|
||||
input.url {
|
||||
width: 25em;
|
||||
}
|
||||
|
||||
.formish {
|
||||
}
|
Loading…
Reference in New Issue
Block a user