payment
This commit is contained in:
parent
d583dfb073
commit
4bba46b53e
@ -268,6 +268,19 @@ class PackedArenaObject extends ArenaObject {
|
|||||||
emsc.hash(this.nativePtr, this.size(), x.nativePtr);
|
emsc.hash(this.nativePtr, this.size(), x.nativePtr);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
hexdump() {
|
||||||
|
let bytes = [];
|
||||||
|
for (let i = 0; i < this.size(); i++) {
|
||||||
|
let b = Module.getValue(this.getNative() + i, "i8");
|
||||||
|
b = (b + 256) % 256;
|
||||||
|
bytes.push("0".concat(b.toString(16)).slice(-2));
|
||||||
|
}
|
||||||
|
let lines = [];
|
||||||
|
for (let i = 0; i < bytes.length; i += 8) {
|
||||||
|
lines.push(bytes.slice(i, i + 8).join(","));
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class AmountNbo extends PackedArenaObject {
|
class AmountNbo extends PackedArenaObject {
|
||||||
size() {
|
size() {
|
||||||
@ -496,7 +509,7 @@ class AbsoluteTimeNbo extends PackedArenaObject {
|
|||||||
if (m.length != 2) {
|
if (m.length != 2) {
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
let n = parseInt(m[1]);
|
let n = parseInt(m[1]) * 1000000;
|
||||||
// XXX: This only works up to 54 bit numbers.
|
// XXX: This only works up to 54 bit numbers.
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
@ -508,14 +521,15 @@ class AbsoluteTimeNbo extends PackedArenaObject {
|
|||||||
// XXX: This only works up to 54 bit numbers.
|
// XXX: This only works up to 54 bit numbers.
|
||||||
function set64(p, n) {
|
function set64(p, n) {
|
||||||
for (let i = 0; i < 8; ++i) {
|
for (let i = 0; i < 8; ++i) {
|
||||||
Module.setValue(p + (8 - i), n & 0xFF, "i8");
|
Module.setValue(p + (7 - i), n & 0xFF, "i8");
|
||||||
n >>>= 8;
|
n = Math.floor(n / 256);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class UInt64 extends PackedArenaObject {
|
class UInt64 extends PackedArenaObject {
|
||||||
static fromNumber(n) {
|
static fromNumber(n) {
|
||||||
let x = new UInt64();
|
let x = new UInt64();
|
||||||
x.alloc();
|
x.alloc();
|
||||||
|
console.log("Creating UINT64 with", n);
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -419,6 +419,21 @@ abstract class PackedArenaObject extends ArenaObject {
|
|||||||
emsc.hash(this.nativePtr, this.size(), x.nativePtr);
|
emsc.hash(this.nativePtr, this.size(), x.nativePtr);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hexdump() {
|
||||||
|
let bytes: string[] = [];
|
||||||
|
for (let i = 0; i < this.size(); i++) {
|
||||||
|
let b = Module.getValue(this.getNative() + i, "i8");
|
||||||
|
b = (b + 256) % 256;
|
||||||
|
bytes.push("0".concat(b.toString(16)).slice(-2));
|
||||||
|
}
|
||||||
|
let lines = [];
|
||||||
|
for (let i = 0; i < bytes.length; i+=8) {
|
||||||
|
lines.push(bytes.slice(i, i+8).join(","));
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -715,7 +730,7 @@ class AbsoluteTimeNbo extends PackedArenaObject {
|
|||||||
if (m.length != 2) {
|
if (m.length != 2) {
|
||||||
throw Error();
|
throw Error();
|
||||||
}
|
}
|
||||||
let n = parseInt(m[1]);
|
let n = parseInt(m[1]) * 1000000;
|
||||||
// XXX: This only works up to 54 bit numbers.
|
// XXX: This only works up to 54 bit numbers.
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
@ -730,8 +745,8 @@ class AbsoluteTimeNbo extends PackedArenaObject {
|
|||||||
// XXX: This only works up to 54 bit numbers.
|
// XXX: This only works up to 54 bit numbers.
|
||||||
function set64(p: number, n: number) {
|
function set64(p: number, n: number) {
|
||||||
for (let i = 0; i < 8; ++i) {
|
for (let i = 0; i < 8; ++i) {
|
||||||
Module.setValue(p + (8 - i), n & 0xFF, "i8");
|
Module.setValue(p + (7 - i), n & 0xFF, "i8");
|
||||||
n >>>= 8;
|
n = Math.floor(n / 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -741,6 +756,7 @@ class UInt64 extends PackedArenaObject {
|
|||||||
static fromNumber(n: number): UInt64 {
|
static fromNumber(n: number): UInt64 {
|
||||||
let x = new UInt64();
|
let x = new UInt64();
|
||||||
x.alloc();
|
x.alloc();
|
||||||
|
console.log("Creating UINT64 with", n);
|
||||||
set64(x.getNative(), n);
|
set64(x.getNative(), n);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ function signDeposit(db, offer, cds) {
|
|||||||
let newAmount = new Amount(cd.coin.currentAmount);
|
let newAmount = new Amount(cd.coin.currentAmount);
|
||||||
newAmount.sub(coinSpend);
|
newAmount.sub(coinSpend);
|
||||||
cd.coin.currentAmount = newAmount.toJson();
|
cd.coin.currentAmount = newAmount.toJson();
|
||||||
|
console.log("DepositRequestPS: ", d.toPurpose().hexdump());
|
||||||
let coinSig = eddsaSign(d.toPurpose(), EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
|
let coinSig = eddsaSign(d.toPurpose(), EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
|
||||||
.toCrock();
|
.toCrock();
|
||||||
let s = {
|
let s = {
|
||||||
@ -145,31 +146,26 @@ function getPossibleMintCoins(db, paymentAmount, depositFeeLimit, allowedMints)
|
|||||||
}
|
}
|
||||||
function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
|
function executePay(db, offer, payCoinInfo, merchantBaseUrl, chosenMint) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let reqData = {};
|
let payReq = {};
|
||||||
reqData["H_wire"] = offer.contract.H_wire;
|
payReq["H_wire"] = offer.contract.H_wire;
|
||||||
reqData["H_contract"] = offer.H_contract;
|
payReq["H_contract"] = offer.H_contract;
|
||||||
reqData["transaction_id"] = offer.contract.transaction_id;
|
payReq["transaction_id"] = offer.contract.transaction_id;
|
||||||
reqData["refund_deadline"] = offer.contract.refund_deadline;
|
payReq["refund_deadline"] = offer.contract.refund_deadline;
|
||||||
reqData["mint"] = URI(chosenMint).hostname();
|
payReq["mint"] = URI(chosenMint).href();
|
||||||
reqData["coins"] = payCoinInfo.map((x) => x.sig);
|
payReq["coins"] = payCoinInfo.map((x) => x.sig);
|
||||||
reqData["timestamp"] = offer.contract.timestamp;
|
payReq["timestamp"] = offer.contract.timestamp;
|
||||||
let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl);
|
let payUrl = URI(offer.pay_url).absoluteTo(merchantBaseUrl);
|
||||||
console.log("Merchant URL", payUrl.href());
|
let t = {
|
||||||
let req = new XMLHttpRequest();
|
contractHash: offer.H_contract,
|
||||||
req.open('post', payUrl.href());
|
contract: offer.contract,
|
||||||
req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
payUrl: payUrl.href(),
|
||||||
req.send(JSON.stringify(reqData));
|
payReq: payReq
|
||||||
req.addEventListener('readystatechange', (e) => {
|
};
|
||||||
if (req.readyState == XMLHttpRequest.DONE) {
|
let tx = db.transaction(['transactions'], 'readwrite');
|
||||||
if (req.status == 200) {
|
tx.objectStore('transactions').put(t);
|
||||||
console.log("Merchant response:", req.responseText);
|
tx.oncomplete = (e) => {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
};
|
||||||
else {
|
|
||||||
throw Error("bad status " + req.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function confirmPay(db, detail, sendResponse) {
|
function confirmPay(db, detail, sendResponse) {
|
||||||
@ -192,8 +188,23 @@ function confirmPay(db, detail, sendResponse) {
|
|||||||
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl);
|
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
sendResponse({ success: true });
|
sendResponse({
|
||||||
|
success: true,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
function doPayment(db, detail, sendResponse) {
|
||||||
|
let H_contract = detail.H_contract;
|
||||||
|
let req = db.transaction(['transactions']).objectStore("transactions").get(H_contract);
|
||||||
|
console.log("executing contract", H_contract);
|
||||||
|
req.onsuccess = (e) => {
|
||||||
|
if (!req.result) {
|
||||||
|
sendResponse({ success: false, error: "contract not found" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendResponse({ success: true, payUrl: req.result.payUrl, payReq: req.result.payReq });
|
||||||
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function confirmReserve(db, detail, sendResponse) {
|
function confirmReserve(db, detail, sendResponse) {
|
||||||
@ -592,12 +603,14 @@ function balances(db, detail, sendResponse) {
|
|||||||
chrome.browserAction.setBadgeText({ text: "" });
|
chrome.browserAction.setBadgeText({ text: "" });
|
||||||
openTalerDb().then((db) => {
|
openTalerDb().then((db) => {
|
||||||
console.log("db loaded");
|
console.log("db loaded");
|
||||||
|
updateBadge(db);
|
||||||
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {
|
chrome.runtime.onMessage.addListener(function (req, sender, onresponse) {
|
||||||
let dispatch = {
|
let dispatch = {
|
||||||
"confirm-reserve": confirmReserve,
|
"confirm-reserve": confirmReserve,
|
||||||
"confirm-pay": confirmPay,
|
"confirm-pay": confirmPay,
|
||||||
"dump-db": dumpDb,
|
"dump-db": dumpDb,
|
||||||
"balances": balances,
|
"balances": balances,
|
||||||
|
"execute-payment": doPayment,
|
||||||
"reset": reset
|
"reset": reset
|
||||||
};
|
};
|
||||||
if (req.type in dispatch) {
|
if (req.type in dispatch) {
|
||||||
|
@ -38,6 +38,8 @@ interface Offer {
|
|||||||
contract: Contract;
|
contract: Contract;
|
||||||
sig: string;
|
sig: string;
|
||||||
H_contract: string;
|
H_contract: string;
|
||||||
|
pay_url: string;
|
||||||
|
exec_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Contract {
|
interface Contract {
|
||||||
@ -50,7 +52,6 @@ interface Contract {
|
|||||||
merchant: any;
|
merchant: any;
|
||||||
merchant_pub: string;
|
merchant_pub: string;
|
||||||
mints: MintInfo[];
|
mints: MintInfo[];
|
||||||
pay_url: string;
|
|
||||||
products: string[];
|
products: string[];
|
||||||
refund_deadline: string;
|
refund_deadline: string;
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
@ -112,6 +113,8 @@ function signDeposit(db: IDBDatabase,
|
|||||||
newAmount.sub(coinSpend);
|
newAmount.sub(coinSpend);
|
||||||
cd.coin.currentAmount = newAmount.toJson();
|
cd.coin.currentAmount = newAmount.toJson();
|
||||||
|
|
||||||
|
console.log("DepositRequestPS: ", d.toPurpose().hexdump());
|
||||||
|
|
||||||
let coinSig = eddsaSign(d.toPurpose(),
|
let coinSig = eddsaSign(d.toPurpose(),
|
||||||
EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
|
EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
|
||||||
.toCrock();
|
.toCrock();
|
||||||
@ -224,37 +227,40 @@ function getPossibleMintCoins(db: IDBDatabase,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface Transaction {
|
||||||
|
contractHash: string;
|
||||||
|
contract: any;
|
||||||
|
payUrl: string;
|
||||||
|
payReq: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function executePay(db,
|
function executePay(db,
|
||||||
offer: Offer,
|
offer: Offer,
|
||||||
payCoinInfo: PayCoinInfo,
|
payCoinInfo: PayCoinInfo,
|
||||||
merchantBaseUrl: string,
|
merchantBaseUrl: string,
|
||||||
chosenMint: string) {
|
chosenMint: string) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let reqData = {};
|
let payReq = {};
|
||||||
reqData["H_wire"] = offer.contract.H_wire;
|
payReq["H_wire"] = offer.contract.H_wire;
|
||||||
reqData["H_contract"] = offer.H_contract;
|
payReq["H_contract"] = offer.H_contract;
|
||||||
reqData["transaction_id"] = offer.contract.transaction_id;
|
payReq["transaction_id"] = offer.contract.transaction_id;
|
||||||
reqData["refund_deadline"] = offer.contract.refund_deadline;
|
payReq["refund_deadline"] = offer.contract.refund_deadline;
|
||||||
reqData["mint"] = URI(chosenMint).hostname();
|
payReq["mint"] = URI(chosenMint).href();
|
||||||
reqData["coins"] = payCoinInfo.map((x) => x.sig);
|
payReq["coins"] = payCoinInfo.map((x) => x.sig);
|
||||||
reqData["timestamp"] = offer.contract.timestamp;
|
payReq["timestamp"] = offer.contract.timestamp;
|
||||||
let payUrl = URI(offer.contract.pay_url).absoluteTo(merchantBaseUrl);
|
let payUrl = URI(offer.pay_url).absoluteTo(merchantBaseUrl);
|
||||||
console.log("Merchant URL", payUrl.href());
|
let t: Transaction = {
|
||||||
let req = new XMLHttpRequest();
|
contractHash: offer.H_contract,
|
||||||
req.open('post', payUrl.href());
|
contract: offer.contract,
|
||||||
req.setRequestHeader("Content-Type",
|
payUrl: payUrl.href(),
|
||||||
"application/json;charset=UTF-8");
|
payReq: payReq
|
||||||
req.send(JSON.stringify(reqData));
|
};
|
||||||
req.addEventListener('readystatechange', (e) => {
|
let tx = db.transaction(['transactions'], 'readwrite');
|
||||||
if (req.readyState == XMLHttpRequest.DONE) {
|
tx.objectStore('transactions').put(t);
|
||||||
if (req.status == 200) {
|
tx.oncomplete = (e) => {
|
||||||
console.log("Merchant response:", req.responseText);
|
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
};
|
||||||
throw Error("bad status " + req.status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,8 +289,26 @@ function confirmPay(db, detail: ConfirmPayRequest, sendResponse) {
|
|||||||
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl);
|
return executePay(db, offer, ds, detail.merchantPageUrl, mintUrl);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
sendResponse({success: true});
|
sendResponse({
|
||||||
|
success: true,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function doPayment(db, detail, sendResponse) {
|
||||||
|
let H_contract = detail.H_contract;
|
||||||
|
let req = db.transaction(['transactions']).objectStore("transactions").get(H_contract);
|
||||||
|
console.log("executing contract", H_contract);
|
||||||
|
req.onsuccess = (e) => {
|
||||||
|
if (!req.result) {
|
||||||
|
sendResponse({success: false, error: "contract not found"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendResponse({success: true, payUrl: req.result.payUrl, payReq: req.result.payReq});
|
||||||
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,6 +756,7 @@ chrome.browserAction.setBadgeText({text: ""});
|
|||||||
|
|
||||||
openTalerDb().then((db) => {
|
openTalerDb().then((db) => {
|
||||||
console.log("db loaded");
|
console.log("db loaded");
|
||||||
|
updateBadge(db);
|
||||||
chrome.runtime.onMessage.addListener(
|
chrome.runtime.onMessage.addListener(
|
||||||
function(req, sender, onresponse) {
|
function(req, sender, onresponse) {
|
||||||
let dispatch = {
|
let dispatch = {
|
||||||
@ -739,6 +764,7 @@ openTalerDb().then((db) => {
|
|||||||
"confirm-pay": confirmPay,
|
"confirm-pay": confirmPay,
|
||||||
"dump-db": dumpDb,
|
"dump-db": dumpDb,
|
||||||
"balances": balances,
|
"balances": balances,
|
||||||
|
"execute-payment": doPayment,
|
||||||
"reset": reset
|
"reset": reset
|
||||||
};
|
};
|
||||||
if (req.type in dispatch) {
|
if (req.type in dispatch) {
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
// Script that is injected into pages in order to allow merchants pages to
|
// Script that is injected into pages in order to allow merchants pages to
|
||||||
// query the availability of Taler.
|
// query the availability of Taler.
|
||||||
'use strict';
|
"use strict";
|
||||||
document.addEventListener('taler-checkout-probe', function (e) {
|
document.addEventListener("taler-checkout-probe", function (e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("merchant handshake done");
|
console.log("merchant handshake done");
|
||||||
});
|
});
|
||||||
document.addEventListener('taler-wire-probe', function (e) {
|
document.addEventListener("taler-wire-probe", function (e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("bank handshake done");
|
console.log("bank handshake done");
|
||||||
});
|
});
|
||||||
document.addEventListener('taler-checkout-probe', function (e) {
|
document.addEventListener("taler-checkout-probe", function (e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("merchant handshake done");
|
console.log("merchant handshake done");
|
||||||
});
|
});
|
||||||
document.addEventListener('taler-create-reserve', function (e) {
|
document.addEventListener("taler-create-reserve", function (e) {
|
||||||
let $ = (x) => document.getElementById(x);
|
let $ = (x) => document.getElementById(x);
|
||||||
console.log("taler-create-reserve with " + JSON.stringify(e.detail));
|
console.log("taler-create-reserve with " + JSON.stringify(e.detail));
|
||||||
let form_uri = $(e.detail.form_id).action;
|
let form_uri = $(e.detail.form_id).action;
|
||||||
@ -46,3 +46,30 @@ document.addEventListener('taler-contract', function (e) {
|
|||||||
};
|
};
|
||||||
document.location.href = uri.query(params).href();
|
document.location.href = uri.query(params).href();
|
||||||
});
|
});
|
||||||
|
document.addEventListener('taler-execute-payment', function (e) {
|
||||||
|
console.log("got taler-execute-payment in content page");
|
||||||
|
let msg = {
|
||||||
|
type: "execute-payment",
|
||||||
|
detail: {
|
||||||
|
H_contract: e.detail.H_contract
|
||||||
|
},
|
||||||
|
};
|
||||||
|
chrome.runtime.sendMessage(msg, (resp) => {
|
||||||
|
//console.log("got response from bg page", JSON.stringify(resp));
|
||||||
|
if (!resp.success) {
|
||||||
|
console.log("failure!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let r = new XMLHttpRequest();
|
||||||
|
r.open('post', resp.payUrl);
|
||||||
|
r.send(JSON.stringify(resp.payReq));
|
||||||
|
r.onload = (e) => {
|
||||||
|
if (r.status != 200) {
|
||||||
|
console.log("non-200 error");
|
||||||
|
console.log(r.responseText);
|
||||||
|
}
|
||||||
|
let evt = new Event("taler-payment-result", resp);
|
||||||
|
document.dispatchEvent(evt);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
// Script that is injected into pages in order to allow merchants pages to
|
// Script that is injected into pages in order to allow merchants pages to
|
||||||
// query the availability of Taler.
|
// query the availability of Taler.
|
||||||
|
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
document.addEventListener('taler-checkout-probe', function(e) {
|
document.addEventListener("taler-checkout-probe", function(e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("merchant handshake done");
|
console.log("merchant handshake done");
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('taler-wire-probe', function(e) {
|
document.addEventListener("taler-wire-probe", function(e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("bank handshake done");
|
console.log("bank handshake done");
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('taler-checkout-probe', function(e) {
|
document.addEventListener("taler-checkout-probe", function(e) {
|
||||||
let evt = new Event('taler-wallet-present');
|
let evt = new Event("taler-wallet-present");
|
||||||
document.dispatchEvent(evt);
|
document.dispatchEvent(evt);
|
||||||
console.log("merchant handshake done");
|
console.log("merchant handshake done");
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('taler-create-reserve', function(e: CustomEvent) {
|
document.addEventListener("taler-create-reserve", function(e: CustomEvent) {
|
||||||
let $ = (x) => document.getElementById(x);
|
let $ = (x) => document.getElementById(x);
|
||||||
console.log("taler-create-reserve with " + JSON.stringify(e.detail));
|
console.log("taler-create-reserve with " + JSON.stringify(e.detail));
|
||||||
let form_uri = (<HTMLFormElement>$(e.detail.form_id)).action;
|
let form_uri = (<HTMLFormElement>$(e.detail.form_id)).action;
|
||||||
@ -52,3 +52,32 @@ document.addEventListener('taler-contract', function(e: CustomEvent) {
|
|||||||
};
|
};
|
||||||
document.location.href = uri.query(params).href();
|
document.location.href = uri.query(params).href();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('taler-execute-payment', function(e: CustomEvent) {
|
||||||
|
console.log("got taler-execute-payment in content page");
|
||||||
|
let msg = {
|
||||||
|
type: "execute-payment",
|
||||||
|
detail: {
|
||||||
|
H_contract: e.detail.H_contract
|
||||||
|
},
|
||||||
|
};
|
||||||
|
chrome.runtime.sendMessage(msg, (resp) => {
|
||||||
|
//console.log("got response from bg page", JSON.stringify(resp));
|
||||||
|
if (!resp.success) {
|
||||||
|
console.log("failure!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let r = new XMLHttpRequest();
|
||||||
|
r.open('post', resp.payUrl);
|
||||||
|
r.send(JSON.stringify(resp.payReq));
|
||||||
|
r.onload = (e) => {
|
||||||
|
if (r.status != 200) {
|
||||||
|
console.log("non-200 error");
|
||||||
|
console.log(r.responseText);
|
||||||
|
}
|
||||||
|
let evt = new Event("taler-payment-result", resp);
|
||||||
|
document.dispatchEvent(evt);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"description": "Privacy preserving and transparent payments",
|
"description": "Privacy preserving and transparent payments",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Taler Wallet",
|
"name": "GNU Taler Wallet",
|
||||||
"version": "0.1",
|
"version": "0.2",
|
||||||
|
|
||||||
"applications": {
|
"applications": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
|
@ -20,8 +20,7 @@ document.addEventListener("DOMContentLoaded", (e) => {
|
|||||||
console.dir(offer);
|
console.dir(offer);
|
||||||
let source = $_("contract-template").innerHTML;
|
let source = $_("contract-template").innerHTML;
|
||||||
let template = Handlebars.compile(source);
|
let template = Handlebars.compile(source);
|
||||||
let html = template(offer.contract);
|
$_("render-contract").innerHTML = template(offer.contract);
|
||||||
$_("render-contract").innerHTML = html;
|
|
||||||
document.getElementById("confirm-pay").addEventListener("click", (e) => {
|
document.getElementById("confirm-pay").addEventListener("click", (e) => {
|
||||||
console.log("Query:", JSON.stringify(query));
|
console.log("Query:", JSON.stringify(query));
|
||||||
let d = {
|
let d = {
|
||||||
@ -29,13 +28,16 @@ document.addEventListener("DOMContentLoaded", (e) => {
|
|||||||
merchantPageUrl: query.merchantPageUrl
|
merchantPageUrl: query.merchantPageUrl
|
||||||
};
|
};
|
||||||
chrome.runtime.sendMessage({ type: 'confirm-pay', detail: d }, (resp) => {
|
chrome.runtime.sendMessage({ type: 'confirm-pay', detail: d }, (resp) => {
|
||||||
console.log("got response", resp);
|
if (!resp.success) {
|
||||||
if ("error" in resp) {
|
|
||||||
let source = $_("error-template").innerHTML;
|
let source = $_("error-template").innerHTML;
|
||||||
let template = Handlebars.compile(source);
|
let template = Handlebars.compile(source);
|
||||||
$_("status").innerHTML = template(resp);
|
$_("status").innerHTML = template(resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
document.location.href = URI(d.offer.exec_url)
|
||||||
|
.absoluteTo(query.merchantPageUrl)
|
||||||
|
.addQuery({ H_contract: d.offer.H_contract })
|
||||||
|
.href();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -29,9 +29,7 @@ document.addEventListener("DOMContentLoaded", (e) => {
|
|||||||
|
|
||||||
let source = $_("contract-template").innerHTML;
|
let source = $_("contract-template").innerHTML;
|
||||||
let template = Handlebars.compile(source);
|
let template = Handlebars.compile(source);
|
||||||
let html = template(offer.contract);
|
$_("render-contract").innerHTML = template(offer.contract);
|
||||||
|
|
||||||
$_("render-contract").innerHTML = html;
|
|
||||||
|
|
||||||
document.getElementById("confirm-pay").addEventListener("click", (e) => {
|
document.getElementById("confirm-pay").addEventListener("click", (e) => {
|
||||||
console.log("Query:", JSON.stringify(query));
|
console.log("Query:", JSON.stringify(query));
|
||||||
@ -40,13 +38,16 @@ document.addEventListener("DOMContentLoaded", (e) => {
|
|||||||
merchantPageUrl: query.merchantPageUrl
|
merchantPageUrl: query.merchantPageUrl
|
||||||
};
|
};
|
||||||
chrome.runtime.sendMessage({type:'confirm-pay', detail: d}, (resp) => {
|
chrome.runtime.sendMessage({type:'confirm-pay', detail: d}, (resp) => {
|
||||||
console.log("got response", resp);
|
if (!resp.success) {
|
||||||
if ("error" in resp) {
|
|
||||||
let source = $_("error-template").innerHTML;
|
let source = $_("error-template").innerHTML;
|
||||||
let template = Handlebars.compile(source);
|
let template = Handlebars.compile(source);
|
||||||
$_("status").innerHTML = template(resp);
|
$_("status").innerHTML = template(resp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
document.location.href = URI(d.offer.exec_url)
|
||||||
|
.absoluteTo(query.merchantPageUrl)
|
||||||
|
.addQuery({H_contract: d.offer.H_contract})
|
||||||
|
.href();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Taler Wallet: Confirm Reserve Creation</title>
|
<title>Taler Wallet: Confirm Reserve Creation</title>
|
||||||
<script src="../lib/URI.js"></script>
|
<script src="../lib/URI.js"></script>
|
||||||
|
<script src="../lib/polyfill-react.js"></script>
|
||||||
<script src="confirm-create-reserve.js"></script>
|
<script src="confirm-create-reserve.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="../style/wallet.css">
|
<link rel="stylesheet" type="text/css" href="../style/wallet.css">
|
||||||
</head>
|
</head>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var ConfirmCreateReserve;
|
||||||
|
(function (ConfirmCreateReserve) {
|
||||||
let url = URI(document.location.href);
|
let url = URI(document.location.href);
|
||||||
let query = URI.parseQuery(url.query());
|
let query = URI.parseQuery(url.query());
|
||||||
|
|
||||||
function updateAmount() {
|
function updateAmount() {
|
||||||
let showAmount = document.getElementById("show-amount");
|
let showAmount = document.getElementById("show-amount");
|
||||||
console.log("Query is " + JSON.stringify(query));
|
console.log("Query is " + JSON.stringify(query));
|
||||||
@ -13,31 +13,24 @@ function updateAmount() {
|
|||||||
}
|
}
|
||||||
showAmount.textContent = s;
|
showAmount.textContent = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clone(obj) {
|
function clone(obj) {
|
||||||
// This is faster than it looks ...
|
// This is faster than it looks ...
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", (e) => {
|
document.addEventListener("DOMContentLoaded", (e) => {
|
||||||
updateAmount();
|
updateAmount();
|
||||||
|
|
||||||
document.getElementById("confirm").addEventListener("click", (e) => {
|
document.getElementById("confirm").addEventListener("click", (e) => {
|
||||||
let d = clone(query);
|
let d = clone(query);
|
||||||
d.mint = document.getElementById('mint-url').value;
|
d.mint = document.getElementById('mint-url').value;
|
||||||
chrome.runtime.sendMessage({ type: 'confirm-reserve', detail: d }, (resp) => {
|
chrome.runtime.sendMessage({ type: 'confirm-reserve', detail: d }, (resp) => {
|
||||||
if (resp.success === true) {
|
if (resp.success === true) {
|
||||||
document.location.href = resp.backlink;
|
document.location.href = resp.backlink;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
document.body.innerHTML =
|
document.body.innerHTML =
|
||||||
`Oops, something went wrong.
|
React.createElement("div", null, "Oops, something went wrong." + ' ' + "The bank responded with HTTP status code $", resp.status, "." + ' ' + "Here is some more info:", React.createElement("pre", null, resp.text), "`");
|
||||||
The bank responded with HTTP status code ${resp.status}.
|
|
||||||
Here is some more info:
|
|
||||||
<pre>${resp.text}</pre>`;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
})(ConfirmCreateReserve || (ConfirmCreateReserve = {}));
|
||||||
|
|
||||||
|
@ -1,19 +1,4 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
let React = {
|
|
||||||
createElement: function (tag, props, ...children) {
|
|
||||||
let e = document.createElement(tag);
|
|
||||||
for (let k in props) {
|
|
||||||
e.setAttribute(k, props[k]);
|
|
||||||
}
|
|
||||||
for (let child of children) {
|
|
||||||
if ("string" === typeof child || "number" == typeof child) {
|
|
||||||
child = document.createTextNode(child);
|
|
||||||
}
|
|
||||||
e.appendChild(child);
|
|
||||||
}
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener('DOMContentLoaded', (e) => {
|
document.addEventListener('DOMContentLoaded', (e) => {
|
||||||
console.log("content loaded");
|
console.log("content loaded");
|
||||||
chrome.runtime.sendMessage({ type: "balances" }, function (wallet) {
|
chrome.runtime.sendMessage({ type: "balances" }, function (wallet) {
|
||||||
|
@ -1,22 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
let React = {
|
|
||||||
createElement: function(tag, props, ...children) {
|
|
||||||
let e = document.createElement(tag);
|
|
||||||
for (let k in props) {
|
|
||||||
e.setAttribute(k, props[k]);
|
|
||||||
}
|
|
||||||
for (let child of children) {
|
|
||||||
if ("string" === typeof child || "number" == typeof child) {
|
|
||||||
child = document.createTextNode(child);
|
|
||||||
}
|
|
||||||
e.appendChild(child);
|
|
||||||
}
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', (e) => {
|
document.addEventListener('DOMContentLoaded', (e) => {
|
||||||
console.log("content loaded");
|
console.log("content loaded");
|
||||||
chrome.runtime.sendMessage({type: "balances"}, function(wallet) {
|
chrome.runtime.sendMessage({type: "balances"}, function(wallet) {
|
||||||
|
@ -8,8 +8,10 @@
|
|||||||
"background/emscriptif.ts",
|
"background/emscriptif.ts",
|
||||||
"background/db.ts",
|
"background/db.ts",
|
||||||
"lib/util.ts",
|
"lib/util.ts",
|
||||||
|
"lib/polyfill-react.ts",
|
||||||
"content_scripts/notify.ts",
|
"content_scripts/notify.ts",
|
||||||
"popup/balance-overview.tsx",
|
"popup/balance-overview.tsx",
|
||||||
"pages/confirm-contract.tsx"
|
"pages/confirm-contract.tsx",
|
||||||
|
"pages/confirm-create-reserve.tsx"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user