refactoring / cosmetic changes

This commit is contained in:
Florian Dold 2016-02-10 02:03:31 +01:00
parent 14f636d670
commit a04a9d0424
17 changed files with 344 additions and 360 deletions

View File

@ -20,16 +20,22 @@
"use strict"; "use strict";
// TypeScript does not allow ".js" extensions in the
// module name, so SystemJS must add it.
System.config({ System.config({
defaultJSExtensions: true, defaultJSExtensions: true,
}); });
var Module: any; // We expect that in the manifest, the emscripten js is loaded
// becore the background page.
// Currently it is not possible to use SystemJS to load the emscripten js.
declare var Module: any;
if ("object" !== typeof Module) { if ("object" !== typeof Module) {
throw Error("emscripten not loaded, no 'Module' defined"); throw Error("emscripten not loaded, no 'Module' defined");
} }
// Manually register the emscripten js as a SystemJS, so that
// we can use it from TypeScript by importing it.
let mod = System.newModule({Module: Module}); let mod = System.newModule({Module: Module});
let modName = System.normalizeSync("../lib/emscripten/emsc"); let modName = System.normalizeSync("../lib/emscripten/emsc");
console.log("registering", modName); console.log("registering", modName);

View File

@ -14,11 +14,11 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
/// <reference path="../lib/decl/chrome/chrome.d.ts" /> /// <reference path="../lib/decl/chrome/chrome.d.ts" />
"use strict";
/** /**
* Script that is injected into (all!) pages to allow them * Script that is injected into (all!) pages to allow them
* to interact with the GNU Taler wallet via DOM Events. * to interact with the GNU Taler wallet via DOM Events.
*/ */
"use strict";
// Make sure we don't pollute the namespace too much. // Make sure we don't pollute the namespace too much.
var TalerNotify; var TalerNotify;
(function (TalerNotify) { (function (TalerNotify) {

View File

@ -16,14 +16,14 @@
/// <reference path="../lib/decl/chrome/chrome.d.ts" /> /// <reference path="../lib/decl/chrome/chrome.d.ts" />
"use strict";
/** /**
* Script that is injected into (all!) pages to allow them * Script that is injected into (all!) pages to allow them
* to interact with the GNU Taler wallet via DOM Events. * to interact with the GNU Taler wallet via DOM Events.
*/ */
"use strict";
// Make sure we don't pollute the namespace too much. // Make sure we don't pollute the namespace too much.
namespace TalerNotify { namespace TalerNotify {
const PROTOCOL_VERSION = 1; const PROTOCOL_VERSION = 1;

View File

@ -71,6 +71,8 @@ const tsBaseArgs = {
module: "system", module: "system",
sourceMap: true, sourceMap: true,
noLib: true, noLib: true,
noImplicitReturns: true,
noFallthroughCasesInSwitch: true,
}; };

View File

@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
import {AmountJson} from "./types"; import {AmountJson} from "./wallet";
import * as EmscWrapper from "../emscripten/emsc"; import * as EmscWrapper from "../emscripten/emsc";
/** /**

View File

@ -1,200 +0,0 @@
/*
This file is part of TALER
(C) 2016 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
import {EddsaPublicKey} from "./emscriptif";
import {Checkable} from "./checkable";
"use strict";
// TODO: factor into multiple files
export interface Mint {
baseUrl: string;
keys: Keys
}
export interface CoinWithDenom {
coin: Coin;
denom: Denomination;
}
export interface Keys {
denoms: Denomination[];
}
export interface Denomination {
value: AmountJson;
denom_pub: string;
fee_withdraw: AmountJson;
fee_deposit: AmountJson;
}
export interface PreCoin {
coinPub: string;
coinPriv: string;
reservePub: string;
denomPub: string;
blindingKey: string;
withdrawSig: string;
coinEv: string;
mintBaseUrl: string;
coinValue: AmountJson;
}
export interface Coin {
coinPub: string;
coinPriv: string;
denomPub: string;
denomSig: string;
currentAmount: AmountJson;
mintBaseUrl: string;
}
@Checkable.Class
export class AmountJson {
@Checkable.Number
value: number;
@Checkable.Number
fraction: number;
@Checkable.String
currency: string;
static checked: (obj: any) => AmountJson;
}
@Checkable.Class
export class CreateReserveRequest {
/**
* The initial amount for the reserve.
*/
@Checkable.Value(AmountJson)
amount: AmountJson;
/**
* Mint URL where the bank should create the reserve.
*/
@Checkable.String
mint: string;
static checked: (obj: any) => CreateReserveRequest;
}
@Checkable.Class
export class CreateReserveResponse {
/**
* Mint URL where the bank should create the reserve.
* The URL is canonicalized in the response.
*/
@Checkable.String
mint: string;
@Checkable.String
reservePub: string;
static checked: (obj: any) => CreateReserveResponse;
}
@Checkable.Class
export class ConfirmReserveRequest {
/**
* Public key of then reserve that should be marked
* as confirmed.
*/
@Checkable.String
reservePub: string;
static checked: (obj: any) => ConfirmReserveRequest;
}
@Checkable.Class
export class MintInfo {
@Checkable.String
master_pub: string;
@Checkable.String
url: string;
static checked: (obj: any) => MintInfo;
}
@Checkable.Class
export class Contract {
@Checkable.String
H_wire: string;
@Checkable.Value(AmountJson)
amount: AmountJson;
@Checkable.List(Checkable.AnyObject)
auditors: any[];
@Checkable.String
expiry: string;
@Checkable.Any
locations: any;
@Checkable.Value(AmountJson)
max_fee: AmountJson;
@Checkable.Any
merchant: any;
@Checkable.String
merchant_pub: string;
@Checkable.List(Checkable.Value(MintInfo))
mints: MintInfo[];
@Checkable.List(Checkable.AnyObject)
products: any[];
@Checkable.String
refund_deadline: string;
@Checkable.String
timestamp: string;
@Checkable.Number
transaction_id: number;
@Checkable.String
fulfillment_url: string;
static checked: (obj: any) => Contract;
}
@Checkable.Class
export class Offer {
@Checkable.Value(Contract)
contract: Contract;
@Checkable.String
merchant_sig: string;
@Checkable.String
H_contract: string;
static checked: (obj: any) => Offer;
}

View File

@ -21,41 +21,195 @@
* @author Florian Dold * @author Florian Dold
*/ */
import {Amount} from "./emscriptif" import * as native from "./emscriptif";
import {CoinWithDenom} from "./types"; import {HttpResponse, RequestException} from "./http";
import {DepositRequestPS_Args} from "./emscriptif";
import {HashCode} from "./emscriptif";
import {EddsaPublicKey} from "./emscriptif";
import {Coin} from "./types";
import {AbsoluteTimeNbo} from "./emscriptif";
import {UInt64} from "./emscriptif";
import {DepositRequestPS} from "./emscriptif";
import {eddsaSign} from "./emscriptif";
import {EddsaPrivateKey} from "./emscriptif";
import {CreateReserveRequest} from "./types";
import {RsaPublicKey} from "./emscriptif";
import {Denomination} from "./types";
import {RsaBlindingKey} from "./emscriptif";
import {ByteArray} from "./emscriptif";
import {rsaBlind} from "./emscriptif";
import {WithdrawRequestPS} from "./emscriptif";
import {PreCoin} from "./types";
import {rsaUnblind} from "./emscriptif";
import {RsaSignature} from "./emscriptif";
import {Mint} from "./types";
import {HttpResponse} from "./http";
import {RequestException} from "./http";
import {Query} from "./query"; import {Query} from "./query";
import {AmountJson} from "./types"; import {Checkable} from "./checkable";
import {ConfirmReserveRequest} from "./types";
import {Offer} from "./types";
import {Contract} from "./types";
import {MintInfo} from "./types";
import {CreateReserveResponse} from "./types";
"use strict"; "use strict";
export interface Mint {
baseUrl: string;
keys: Keys
}
export interface CoinWithDenom {
coin: Coin;
denom: Denomination;
}
export interface Keys {
denoms: Denomination[];
}
export interface Denomination {
value: AmountJson;
denom_pub: string;
fee_withdraw: AmountJson;
fee_deposit: AmountJson;
stamp_expire_withdraw: string;
}
export interface PreCoin {
coinPub: string;
coinPriv: string;
reservePub: string;
denomPub: string;
blindingKey: string;
withdrawSig: string;
coinEv: string;
mintBaseUrl: string;
coinValue: AmountJson;
}
export interface Coin {
coinPub: string;
coinPriv: string;
denomPub: string;
denomSig: string;
currentAmount: AmountJson;
mintBaseUrl: string;
}
@Checkable.Class
export class AmountJson {
@Checkable.Number
value: number;
@Checkable.Number
fraction: number;
@Checkable.String
currency: string;
static checked: (obj: any) => AmountJson;
}
@Checkable.Class
export class CreateReserveRequest {
/**
* The initial amount for the reserve.
*/
@Checkable.Value(AmountJson)
amount: AmountJson;
/**
* Mint URL where the bank should create the reserve.
*/
@Checkable.String
mint: string;
static checked: (obj: any) => CreateReserveRequest;
}
@Checkable.Class
export class CreateReserveResponse {
/**
* Mint URL where the bank should create the reserve.
* The URL is canonicalized in the response.
*/
@Checkable.String
mint: string;
@Checkable.String
reservePub: string;
static checked: (obj: any) => CreateReserveResponse;
}
@Checkable.Class
export class ConfirmReserveRequest {
/**
* Public key of then reserve that should be marked
* as confirmed.
*/
@Checkable.String
reservePub: string;
static checked: (obj: any) => ConfirmReserveRequest;
}
@Checkable.Class
export class MintInfo {
@Checkable.String
master_pub: string;
@Checkable.String
url: string;
static checked: (obj: any) => MintInfo;
}
@Checkable.Class
export class Contract {
@Checkable.String
H_wire: string;
@Checkable.Value(AmountJson)
amount: AmountJson;
@Checkable.List(Checkable.AnyObject)
auditors: any[];
@Checkable.String
expiry: string;
@Checkable.Any
locations: any;
@Checkable.Value(AmountJson)
max_fee: AmountJson;
@Checkable.Any
merchant: any;
@Checkable.String
merchant_pub: string;
@Checkable.List(Checkable.Value(MintInfo))
mints: MintInfo[];
@Checkable.List(Checkable.AnyObject)
products: any[];
@Checkable.String
refund_deadline: string;
@Checkable.String
timestamp: string;
@Checkable.Number
transaction_id: number;
@Checkable.String
fulfillment_url: string;
static checked: (obj: any) => Contract;
}
@Checkable.Class
export class Offer {
@Checkable.Value(Contract)
contract: Contract;
@Checkable.String
merchant_sig: string;
@Checkable.String
H_contract: string;
static checked: (obj: any) => Offer;
}
interface ConfirmPayRequest { interface ConfirmPayRequest {
offer: Offer; offer: Offer;
} }
@ -93,10 +247,29 @@ export interface Badge {
setColor(c: string): void; setColor(c: string): void;
} }
type PayCoinInfo = Array<{ updatedCoin: Coin, sig: CoinPaySig }>; type PayCoinInfo = Array<{ updatedCoin: Coin, sig: CoinPaySig }>;
function getTalerStampSec(stamp: string) {
const m = stamp.match(/\/?Date\(([0-9]*)\)\/?/);
if (!m) {
return null;
}
return parseInt(m[1]);
}
function isWithdrawableDenom(d: Denomination) {
const now_sec = (new Date).getTime() / 1000;
const stamp_withdraw_sec = getTalerStampSec(d.stamp_expire_withdraw);
// Withdraw if still possible to withdraw within a minute
if (stamp_withdraw_sec + 60 > now_sec) {
return true;
}
return false;
}
/** /**
* See http://api.taler.net/wallet.html#general * See http://api.taler.net/wallet.html#general
*/ */
@ -111,6 +284,7 @@ function canonicalizeBaseUrl(url) {
return x.href() return x.href()
} }
function parsePrettyAmount(pretty: string): AmountJson { function parsePrettyAmount(pretty: string): AmountJson {
const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty); const res = /([0-9]+)(.[0-9]+)?\s*(\w+)/.exec(pretty);
if (!res) { if (!res) {
@ -144,8 +318,8 @@ function copy(o) {
function rankDenom(denom1: any, denom2: any) { function rankDenom(denom1: any, denom2: any) {
// Slow ... we should find a better way than to convert it evert time. // Slow ... we should find a better way than to convert it evert time.
let v1 = new Amount(denom1.value); let v1 = new native.Amount(denom1.value);
let v2 = new Amount(denom2.value); let v2 = new native.Amount(denom2.value);
return (-1) * v1.cmp(v2); return (-1) * v1.cmp(v2);
} }
@ -161,11 +335,11 @@ export class Wallet {
this.badge = badge; this.badge = badge;
} }
static signDeposit(offer: Offer, private static signDeposit(offer: Offer,
cds: CoinWithDenom[]): PayCoinInfo { cds: CoinWithDenom[]): PayCoinInfo {
let ret = []; let ret = [];
let amountSpent = Amount.getZero(cds[0].coin.currentAmount.currency); let amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
let amountRemaining = new Amount(offer.contract.amount); let amountRemaining = new native.Amount(offer.contract.amount);
cds = copy(cds); cds = copy(cds);
for (let cd of cds) { for (let cd of cds) {
let coinSpend; let coinSpend;
@ -174,36 +348,36 @@ export class Wallet {
break; break;
} }
if (amountRemaining.cmp(new Amount(cd.coin.currentAmount)) < 0) { if (amountRemaining.cmp(new native.Amount(cd.coin.currentAmount)) < 0) {
coinSpend = new Amount(amountRemaining.toJson()); coinSpend = new native.Amount(amountRemaining.toJson());
} else { } else {
coinSpend = new Amount(cd.coin.currentAmount); coinSpend = new native.Amount(cd.coin.currentAmount);
} }
amountSpent.add(coinSpend); amountSpent.add(coinSpend);
amountRemaining.sub(coinSpend); amountRemaining.sub(coinSpend);
let newAmount = new Amount(cd.coin.currentAmount); let newAmount = new native.Amount(cd.coin.currentAmount);
newAmount.sub(coinSpend); newAmount.sub(coinSpend);
cd.coin.currentAmount = newAmount.toJson(); cd.coin.currentAmount = newAmount.toJson();
let args: DepositRequestPS_Args = { let args: native.DepositRequestPS_Args = {
h_contract: HashCode.fromCrock(offer.H_contract), h_contract: native.HashCode.fromCrock(offer.H_contract),
h_wire: HashCode.fromCrock(offer.contract.H_wire), h_wire: native.HashCode.fromCrock(offer.contract.H_wire),
amount_with_fee: coinSpend.toNbo(), amount_with_fee: coinSpend.toNbo(),
coin_pub: EddsaPublicKey.fromCrock(cd.coin.coinPub), coin_pub: native.EddsaPublicKey.fromCrock(cd.coin.coinPub),
deposit_fee: new Amount(cd.denom.fee_deposit).toNbo(), deposit_fee: new native.Amount(cd.denom.fee_deposit).toNbo(),
merchant: EddsaPublicKey.fromCrock(offer.contract.merchant_pub), merchant: native.EddsaPublicKey.fromCrock(offer.contract.merchant_pub),
refund_deadline: AbsoluteTimeNbo.fromTalerString(offer.contract.refund_deadline), refund_deadline: native.AbsoluteTimeNbo.fromTalerString(offer.contract.refund_deadline),
timestamp: AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp), timestamp: native.AbsoluteTimeNbo.fromTalerString(offer.contract.timestamp),
transaction_id: UInt64.fromNumber(offer.contract.transaction_id), transaction_id: native.UInt64.fromNumber(offer.contract.transaction_id),
}; };
let d = new DepositRequestPS(args); let d = new native.DepositRequestPS(args);
let coinSig = eddsaSign(d.toPurpose(), let coinSig = native.eddsaSign(d.toPurpose(),
EddsaPrivateKey.fromCrock(cd.coin.coinPriv)) native.EddsaPrivateKey.fromCrock(cd.coin.coinPriv))
.toCrock(); .toCrock();
let s: CoinPaySig = { let s: CoinPaySig = {
coin_sig: coinSig, coin_sig: coinSig,
@ -225,9 +399,9 @@ export class Wallet {
* @param depositFeeLimit * @param depositFeeLimit
* @param allowedMints * @param allowedMints
*/ */
getPossibleMintCoins(paymentAmount: AmountJson, private getPossibleMintCoins(paymentAmount: AmountJson,
depositFeeLimit: AmountJson, depositFeeLimit: AmountJson,
allowedMints: MintInfo[]): Promise<MintCoins> { allowedMints: MintInfo[]): Promise<MintCoins> {
let m: MintCoins = {}; let m: MintCoins = {};
@ -263,19 +437,19 @@ export class Wallet {
nextMint: nextMint:
for (let key in m) { for (let key in m) {
let coins = m[key].map((x) => ({ let coins = m[key].map((x) => ({
a: new Amount(x.denom.fee_deposit), a: new native.Amount(x.denom.fee_deposit),
c: x c: x
})); }));
// Sort by ascending deposit fee // Sort by ascending deposit fee
coins.sort((o1, o2) => o1.a.cmp(o2.a)); coins.sort((o1, o2) => o1.a.cmp(o2.a));
let maxFee = new Amount(depositFeeLimit); let maxFee = new native.Amount(depositFeeLimit);
let minAmount = new Amount(paymentAmount); let minAmount = new native.Amount(paymentAmount);
let accFee = new Amount(coins[0].c.denom.fee_deposit); let accFee = new native.Amount(coins[0].c.denom.fee_deposit);
let accAmount = Amount.getZero(coins[0].c.coin.currentAmount.currency); let accAmount = native.Amount.getZero(coins[0].c.coin.currentAmount.currency);
let usableCoins: CoinWithDenom[] = []; let usableCoins: CoinWithDenom[] = [];
nextCoin: nextCoin:
for (let i = 0; i < coins.length; i++) { for (let i = 0; i < coins.length; i++) {
let coinAmount = new Amount(coins[i].c.coin.currentAmount); let coinAmount = new native.Amount(coins[i].c.coin.currentAmount);
let coinFee = coins[i].a; let coinFee = coins[i].a;
if (coinAmount.cmp(coinFee) <= 0) { if (coinAmount.cmp(coinFee) <= 0) {
continue nextCoin; continue nextCoin;
@ -298,9 +472,13 @@ export class Wallet {
} }
executePay(offer: Offer, /**
payCoinInfo: PayCoinInfo, * Record all information that is necessary to
chosenMint: string): Promise<any> { * pay for a contract in the wallet's database.
*/
private recordConfirmPay(offer: Offer,
payCoinInfo: PayCoinInfo,
chosenMint: string): Promise<void> {
let payReq = {}; let payReq = {};
payReq["amount"] = offer.contract.amount; payReq["amount"] = offer.contract.amount;
payReq["coins"] = payCoinInfo.map((x) => x.sig); payReq["coins"] = payCoinInfo.map((x) => x.sig);
@ -332,14 +510,14 @@ export class Wallet {
.put("transactions", t) .put("transactions", t)
.put("history", historyEntry) .put("history", historyEntry)
.putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin)) .putAll("coins", payCoinInfo.map((pci) => pci.updatedCoin))
.finish() .finish();
.then(() => {
return {
success: true
};
});
} }
/**
* Add a contract to the wallet and sign coins,
* but do not send them yet.
*/
confirmPay(offer: Offer): Promise<any> { confirmPay(offer: Offer): Promise<any> {
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
return this.getPossibleMintCoins(offer.contract.amount, return this.getPossibleMintCoins(offer.contract.amount,
@ -348,18 +526,22 @@ export class Wallet {
}).then((mcs) => { }).then((mcs) => {
if (Object.keys(mcs).length == 0) { if (Object.keys(mcs).length == 0) {
return { return {
success: false, error: "coins-insufficient",
message: "Not enough coins",
}; };
} }
let mintUrl = Object.keys(mcs)[0]; let mintUrl = Object.keys(mcs)[0];
let ds = Wallet.signDeposit(offer, mcs[mintUrl]); let ds = Wallet.signDeposit(offer, mcs[mintUrl]);
return this return this.recordConfirmPay(offer, ds, mintUrl)
.executePay(offer, ds, mintUrl); .then((() => ({})));
}); });
} }
doPayment(H_contract): Promise<any> {
/**
* Retrieve all necessary information for looking up the contract
* with the given hash.
*/
executePayment(H_contract): Promise<any> {
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
return Query(this.db) return Query(this.db)
.get("transactions", H_contract) .get("transactions", H_contract)
@ -385,7 +567,7 @@ export class Wallet {
* First fetch information requred to withdraw from the reserve, * First fetch information requred to withdraw from the reserve,
* then deplete the reserve, withdrawing coins until it is empty. * then deplete the reserve, withdrawing coins until it is empty.
*/ */
initReserve(reserveRecord) { private initReserve(reserveRecord) {
this.updateMintFromUrl(reserveRecord.mint_base_url) this.updateMintFromUrl(reserveRecord.mint_base_url)
.then((mint) => .then((mint) =>
this.updateReserve(reserveRecord.reserve_pub, mint) this.updateReserve(reserveRecord.reserve_pub, mint)
@ -411,7 +593,7 @@ export class Wallet {
* Create a reserve, but do not flag it as confirmed yet. * Create a reserve, but do not flag it as confirmed yet.
*/ */
createReserve(req: CreateReserveRequest): Promise<CreateReserveResponse> { createReserve(req: CreateReserveRequest): Promise<CreateReserveResponse> {
const reservePriv = EddsaPrivateKey.create(); const reservePriv = native.EddsaPrivateKey.create();
const reservePub = reservePriv.getPublicKey(); const reservePub = reservePriv.getPublicKey();
const now = (new Date).getTime(); const now = (new Date).getTime();
@ -486,29 +668,31 @@ export class Wallet {
} }
withdrawPrepare(denom: Denomination, private withdrawPrepare(denom: Denomination,
reserve: Reserve): Promise<PreCoin> { reserve: Reserve): Promise<PreCoin> {
let reservePriv = new EddsaPrivateKey(); let reservePriv = new native.EddsaPrivateKey();
reservePriv.loadCrock(reserve.reserve_priv); reservePriv.loadCrock(reserve.reserve_priv);
let reservePub = new EddsaPublicKey(); let reservePub = new native.EddsaPublicKey();
reservePub.loadCrock(reserve.reserve_pub); reservePub.loadCrock(reserve.reserve_pub);
let denomPub = RsaPublicKey.fromCrock(denom.denom_pub); let denomPub = native.RsaPublicKey.fromCrock(denom.denom_pub);
let coinPriv = EddsaPrivateKey.create(); let coinPriv = native.EddsaPrivateKey.create();
let coinPub = coinPriv.getPublicKey(); let coinPub = coinPriv.getPublicKey();
let blindingFactor = RsaBlindingKey.create(1024); let blindingFactor = native.RsaBlindingKey.create(1024);
let pubHash: HashCode = coinPub.hash(); let pubHash: native.HashCode = coinPub.hash();
let ev: ByteArray = rsaBlind(pubHash, blindingFactor, denomPub); let ev: native.ByteArray = native.rsaBlind(pubHash,
blindingFactor,
denomPub);
if (!denom.fee_withdraw) { if (!denom.fee_withdraw) {
throw Error("Field fee_withdraw missing"); throw Error("Field fee_withdraw missing");
} }
let amountWithFee = new Amount(denom.value); let amountWithFee = new native.Amount(denom.value);
amountWithFee.add(new Amount(denom.fee_withdraw)); amountWithFee.add(new native.Amount(denom.fee_withdraw));
let withdrawFee = new Amount(denom.fee_withdraw); let withdrawFee = new native.Amount(denom.fee_withdraw);
// Signature // Signature
let withdrawRequest = new WithdrawRequestPS({ let withdrawRequest = new native.WithdrawRequestPS({
reserve_pub: reservePub, reserve_pub: reservePub,
amount_with_fee: amountWithFee.toNbo(), amount_with_fee: amountWithFee.toNbo(),
withdraw_fee: withdrawFee.toNbo(), withdraw_fee: withdrawFee.toNbo(),
@ -516,7 +700,7 @@ export class Wallet {
h_coin_envelope: ev.hash() h_coin_envelope: ev.hash()
}); });
var sig = eddsaSign(withdrawRequest.toPurpose(), reservePriv); var sig = native.eddsaSign(withdrawRequest.toPurpose(), reservePriv);
let preCoin: PreCoin = { let preCoin: PreCoin = {
reservePub: reservePub.toCrock(), reservePub: reservePub.toCrock(),
@ -534,7 +718,7 @@ export class Wallet {
} }
withdrawExecute(pc: PreCoin): Promise<Coin> { private withdrawExecute(pc: PreCoin): Promise<Coin> {
return Query(this.db) return Query(this.db)
.get("reserves", pc.reservePub) .get("reserves", pc.reservePub)
.then((r) => { .then((r) => {
@ -554,9 +738,9 @@ export class Wallet {
}); });
} }
let r = JSON.parse(resp.responseText); let r = JSON.parse(resp.responseText);
let denomSig = rsaUnblind(RsaSignature.fromCrock(r.ev_sig), let denomSig = native.rsaUnblind(native.RsaSignature.fromCrock(r.ev_sig),
RsaBlindingKey.fromCrock(pc.blindingKey), native.RsaBlindingKey.fromCrock(pc.blindingKey),
RsaPublicKey.fromCrock(pc.denomPub)); native.RsaPublicKey.fromCrock(pc.denomPub));
let coin: Coin = { let coin: Coin = {
coinPub: pc.coinPub, coinPub: pc.coinPub,
coinPriv: pc.coinPriv, coinPriv: pc.coinPriv,
@ -609,7 +793,7 @@ export class Wallet {
} }
withdraw(denom, reserve): Promise<void> { private withdraw(denom, reserve): Promise<void> {
return this.withdrawPrepare(denom, reserve) return this.withdrawPrepare(denom, reserve)
.then((pc) => this.withdrawExecute(pc)) .then((pc) => this.withdrawExecute(pc))
.then((c) => this.storeCoin(c)); .then((c) => this.storeCoin(c));
@ -619,16 +803,19 @@ export class Wallet {
/** /**
* Withdraw coins from a reserve until it is empty. * Withdraw coins from a reserve until it is empty.
*/ */
depleteReserve(reserve, mint): Promise<void> { private depleteReserve(reserve, mint: Mint): Promise<void> {
let denoms = copy(mint.keys.denoms); let denoms: Denomination[] = copy(mint.keys.denoms);
let remaining = new Amount(reserve.current_amount); let remaining = new native.Amount(reserve.current_amount);
denoms = denoms.filter(isWithdrawableDenom);
denoms.sort(rankDenom); denoms.sort(rankDenom);
let workList = []; let workList = [];
for (let i = 0; i < 1000; i++) { for (let i = 0; i < 1000; i++) {
let found = false; let found = false;
for (let d of denoms) { for (let d of denoms) {
let cost = new Amount(d.value); let cost = new native.Amount(d.value);
cost.add(new Amount(d.fee_withdraw)); cost.add(new native.Amount(d.fee_withdraw));
if (remaining.cmp(cost) < 0) { if (remaining.cmp(cost) < 0) {
continue; continue;
} }
@ -665,8 +852,7 @@ export class Wallet {
} }
updateReserve(reservePub: string, private updateReserve(reservePub: string, mint): Promise<Reserve> {
mint): Promise<Reserve> {
return Query(this.db) return Query(this.db)
.get("reserves", reservePub) .get("reserves", reservePub)
.then((reserve) => { .then((reserve) => {
@ -706,7 +892,7 @@ export class Wallet {
* Optionally link the reserve entry to the new or existing * Optionally link the reserve entry to the new or existing
* mint entry in then DB. * mint entry in then DB.
*/ */
updateMintFromUrl(baseUrl) { private updateMintFromUrl(baseUrl): Promise<Mint> {
let reqUrl = URI("keys").absoluteTo(baseUrl); let reqUrl = URI("keys").absoluteTo(baseUrl);
return this.http.get(reqUrl).then((resp) => { return this.http.get(reqUrl).then((resp) => {
if (resp.status != 200) { if (resp.status != 200) {
@ -729,10 +915,10 @@ export class Wallet {
function collectBalances(c: Coin, byCurrency) { function collectBalances(c: Coin, byCurrency) {
let acc: AmountJson = byCurrency[c.currentAmount.currency]; let acc: AmountJson = byCurrency[c.currentAmount.currency];
if (!acc) { if (!acc) {
acc = Amount.getZero(c.currentAmount.currency).toJson(); acc = native.Amount.getZero(c.currentAmount.currency).toJson();
} }
let am = new Amount(c.currentAmount); let am = new native.Amount(c.currentAmount);
am.add(new Amount(acc)); am.add(new native.Amount(acc));
byCurrency[c.currentAmount.currency] = am.toJson(); byCurrency[c.currentAmount.currency] = am.toJson();
return byCurrency; return byCurrency;
} }

View File

@ -13,9 +13,10 @@
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) { System.register(["./wallet", "./db", "./http"], function(exports_1, context_1) {
"use strict"; "use strict";
var types_1, wallet_1, db_1, db_2, db_3, http_1, types_2, types_3; var __moduleName = context_1 && context_1.id;
var wallet_1, db_1, http_1;
var ChromeBadge; var ChromeBadge;
/** /**
* Messaging for the WebExtensions wallet. Should contain * Messaging for the WebExtensions wallet. Should contain
@ -44,7 +45,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
for (var i = 0; i < db.objectStoreNames.length; i++) { for (var i = 0; i < db.objectStoreNames.length; i++) {
tx.objectStore(db.objectStoreNames[i]).clear(); tx.objectStore(db.objectStoreNames[i]).clear();
} }
db_2.deleteDb(); db_1.deleteDb();
chrome.browserAction.setBadgeText({ text: "" }); chrome.browserAction.setBadgeText({ text: "" });
console.log("reset done"); console.log("reset done");
// Response is synchronous // Response is synchronous
@ -55,7 +56,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
mint: detail.mint, mint: detail.mint,
amount: detail.amount, amount: detail.amount,
}; };
var req = types_2.CreateReserveRequest.checked(d); var req = wallet_1.CreateReserveRequest.checked(d);
wallet.createReserve(req) wallet.createReserve(req)
.then(function (resp) { .then(function (resp) {
sendResponse(resp); sendResponse(resp);
@ -72,7 +73,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
var d = { var d = {
reservePub: detail.reservePub reservePub: detail.reservePub
}; };
var req = types_1.ConfirmReserveRequest.checked(d); var req = wallet_1.ConfirmReserveRequest.checked(d);
wallet.confirmReserve(req) wallet.confirmReserve(req)
.then(function (resp) { .then(function (resp) {
sendResponse(resp); sendResponse(resp);
@ -85,10 +86,10 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
return true; return true;
}, },
_a["confirm-pay"] = function (db, detail, sendResponse) { _a["confirm-pay"] = function (db, detail, sendResponse) {
var offer = types_3.Offer.checked(detail.offer); var offer = wallet_1.Offer.checked(detail.offer);
wallet.confirmPay(offer) wallet.confirmPay(offer)
.then(function (r) { .then(function () {
sendResponse(r); sendResponse({});
}) })
.catch(function (e) { .catch(function (e) {
console.error("exception during 'confirm-pay'"); console.error("exception during 'confirm-pay'");
@ -98,7 +99,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
return true; return true;
}, },
_a["execute-payment"] = function (db, detail, sendResponse) { _a["execute-payment"] = function (db, detail, sendResponse) {
wallet.doPayment(detail.H_contract) wallet.executePayment(detail.H_contract)
.then(function (r) { .then(function (r) {
sendResponse(r); sendResponse(r);
}) })
@ -131,7 +132,7 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
} }
function wxMain() { function wxMain() {
chrome.browserAction.setBadgeText({ text: "" }); chrome.browserAction.setBadgeText({ text: "" });
db_3.openTalerDb() db_1.openTalerDb()
.then(function (db) { .then(function (db) {
var http = new http_1.BrowserHttpLib(); var http = new http_1.BrowserHttpLib();
var badge = new ChromeBadge(); var badge = new ChromeBadge();
@ -154,18 +155,11 @@ System.register(["./types", "./wallet", "./db", "./http"], function(exports_1) {
exports_1("wxMain", wxMain); exports_1("wxMain", wxMain);
return { return {
setters:[ setters:[
function (types_1_1) {
types_1 = types_1_1;
types_2 = types_1_1;
types_3 = types_1_1;
},
function (wallet_1_1) { function (wallet_1_1) {
wallet_1 = wallet_1_1; wallet_1 = wallet_1_1;
}, },
function (db_1_1) { function (db_1_1) {
db_1 = db_1_1; db_1 = db_1_1;
db_2 = db_1_1;
db_3 = db_1_1;
}, },
function (http_1_1) { function (http_1_1) {
http_1 = http_1_1; http_1 = http_1_1;

View File

@ -15,15 +15,9 @@
*/ */
import {ConfirmReserveRequest} from "./types"; import {Wallet, Offer, Badge, ConfirmReserveRequest, CreateReserveRequest} from "./wallet";
import {Wallet} from "./wallet"; import {deleteDb, exportDb, openTalerDb} from "./db";
import {exportDb} from "./db";
import {deleteDb} from "./db";
import {openTalerDb} from "./db";
import {BrowserHttpLib} from "./http"; import {BrowserHttpLib} from "./http";
import {Badge} from "./wallet";
import {CreateReserveRequest} from "./types";
import {Offer} from "./types";
"use strict"; "use strict";
@ -99,8 +93,8 @@ function makeHandlers(wallet: Wallet) {
["confirm-pay"]: function(db, detail, sendResponse) { ["confirm-pay"]: function(db, detail, sendResponse) {
const offer = Offer.checked(detail.offer); const offer = Offer.checked(detail.offer);
wallet.confirmPay(offer) wallet.confirmPay(offer)
.then((r) => { .then(() => {
sendResponse(r) sendResponse({})
}) })
.catch((e) => { .catch((e) => {
console.error("exception during 'confirm-pay'"); console.error("exception during 'confirm-pay'");
@ -110,7 +104,7 @@ function makeHandlers(wallet: Wallet) {
return true; return true;
}, },
["execute-payment"]: function(db, detail, sendResponse) { ["execute-payment"]: function(db, detail, sendResponse) {
wallet.doPayment(detail.H_contract) wallet.executePayment(detail.H_contract)
.then((r) => { .then((r) => {
sendResponse(r); sendResponse(r);
}) })

View File

@ -14,7 +14,8 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
import {AmountJson} from "./wallet/types"; import {AmountJson} from "./wallet/wallet";
export function substituteFulfillmentUrl(url: string, vars) { export function substituteFulfillmentUrl(url: string, vars) {
url = url.replace("${H_contract}", vars.H_contract); url = url.replace("${H_contract}", vars.H_contract);
url = url.replace("${$}", "$"); url = url.replace("${$}", "$");

View File

@ -2,7 +2,7 @@
"description": "Privacy preserving and transparent payments", "description": "Privacy preserving and transparent payments",
"manifest_version": 2, "manifest_version": 2,
"name": "GNU Taler Wallet (git)", "name": "GNU Taler Wallet (git)",
"version": "0.5.5", "version": "0.5.6",
"applications": { "applications": {
"gecko": { "gecko": {

View File

@ -13,9 +13,10 @@
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
System.register(["../lib/web-common"], function(exports_1) { System.register(["../lib/web-common"], function(exports_1, context_1) {
/// <reference path="../lib/decl/handlebars/handlebars.d.ts" /> /// <reference path="../lib/decl/handlebars/handlebars.d.ts" />
"use strict"; "use strict";
var __moduleName = context_1 && context_1.id;
var web_common_1; var web_common_1;
function prettyAmount(amount) { function prettyAmount(amount) {
var v = amount.value + amount.fraction / 1e6; var v = amount.value + amount.fraction / 1e6;

View File

@ -13,14 +13,15 @@
You should have received a copy of the GNU General Public License along with You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1) { System.register(["../lib/web-common", "../lib/wallet/wallet"], function(exports_1, context_1) {
"use strict"; "use strict";
var types_1, web_common_1, types_2; var __moduleName = context_1 && context_1.id;
var web_common_1, wallet_1;
function main() { function main() {
function updateAmount() { function updateAmount() {
var showAmount = document.getElementById("show-amount"); var showAmount = document.getElementById("show-amount");
console.log("Query is " + JSON.stringify(query)); console.log("Query is " + JSON.stringify(query));
var amount = types_1.AmountJson.checked(JSON.parse(query.amount)); var amount = wallet_1.AmountJson.checked(JSON.parse(query.amount));
showAmount.textContent = web_common_1.amountToPretty(amount); showAmount.textContent = web_common_1.amountToPretty(amount);
} }
var url = URI(document.location.href); var url = URI(document.location.href);
@ -44,7 +45,7 @@ System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1
throw Error("empty response"); throw Error("empty response");
} }
if (!rawResp.error) { if (!rawResp.error) {
var resp = types_2.CreateReserveResponse.checked(rawResp); var resp = wallet_1.CreateReserveResponse.checked(rawResp);
var q = { var q = {
mint: resp.mint, mint: resp.mint,
reserve_pub: resp.reservePub, reserve_pub: resp.reservePub,
@ -67,12 +68,11 @@ System.register(["../lib/wallet/types", "../lib/web-common"], function(exports_1
exports_1("main", main); exports_1("main", main);
return { return {
setters:[ setters:[
function (types_1_1) {
types_1 = types_1_1;
types_2 = types_1_1;
},
function (web_common_1_1) { function (web_common_1_1) {
web_common_1 = web_common_1_1; web_common_1 = web_common_1_1;
},
function (wallet_1_1) {
wallet_1 = wallet_1_1;
}], }],
execute: function() { execute: function() {
"use strict"; "use strict";

View File

@ -14,9 +14,8 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/> TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/ */
import {AmountJson} from "../lib/wallet/types";
import {amountToPretty} from "../lib/web-common"; import {amountToPretty} from "../lib/web-common";
import {CreateReserveResponse} from "../lib/wallet/types"; import {AmountJson, CreateReserveResponse} from "../lib/wallet/wallet";
"use strict"; "use strict";

View File

@ -15,7 +15,7 @@
*/ */
/// <reference path="../lib/mithril.d.ts" /> /// <reference path="../lib/decl/mithril.d.ts" />
/// <reference path="../lib/decl/lodash.d.ts" /> /// <reference path="../lib/decl/lodash.d.ts" />
"use strict"; "use strict";

View File

@ -5,7 +5,9 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"module": "system", "module": "system",
"sourceMap": true, "sourceMap": true,
"noLib": true "noLib": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}, },
"files": [ "files": [
"lib/i18n.ts", "lib/i18n.ts",
@ -16,7 +18,6 @@
"lib/wallet/emscriptif.ts", "lib/wallet/emscriptif.ts",
"lib/wallet/http.ts", "lib/wallet/http.ts",
"lib/wallet/query.ts", "lib/wallet/query.ts",
"lib/wallet/types.ts",
"lib/wallet/wallet.ts", "lib/wallet/wallet.ts",
"lib/wallet/wxmessaging.ts", "lib/wallet/wxmessaging.ts",
"background/main.ts", "background/main.ts",