aboutsummaryrefslogtreecommitdiff
path: root/lib/wallet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/wallet')
-rw-r--r--lib/wallet/cryptoApi.ts8
-rw-r--r--lib/wallet/cryptoLib.ts4
-rw-r--r--lib/wallet/db.ts18
-rw-r--r--lib/wallet/helpers.ts6
-rw-r--r--lib/wallet/http.ts2
-rw-r--r--lib/wallet/types.ts81
-rw-r--r--lib/wallet/wallet.ts214
-rw-r--r--lib/wallet/wxApi.ts3
-rw-r--r--lib/wallet/wxMessaging.ts29
9 files changed, 204 insertions, 161 deletions
diff --git a/lib/wallet/cryptoApi.ts b/lib/wallet/cryptoApi.ts
index 300b928db..3cbed89c3 100644
--- a/lib/wallet/cryptoApi.ts
+++ b/lib/wallet/cryptoApi.ts
@@ -15,6 +15,12 @@
*/
+/**
+ * API to access the Taler crypto worker thread.
+ * @author Florian Dold
+ */
+
+
import {PreCoin} from "./types";
import {Reserve} from "./types";
import {Denomination} from "./types";
@@ -90,4 +96,4 @@ export class CryptoApi {
rsaUnblind(sig: string, bk: string, pk: string): Promise<string> {
return this.doRpc("rsaUnblind", sig, bk, pk);
}
-} \ No newline at end of file
+}
diff --git a/lib/wallet/cryptoLib.ts b/lib/wallet/cryptoLib.ts
index 869ddbaff..769cb3356 100644
--- a/lib/wallet/cryptoLib.ts
+++ b/lib/wallet/cryptoLib.ts
@@ -14,7 +14,6 @@
TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
*/
-import {Denomination} from "./types";
/**
* Web worker for crypto operations.
* @author Florian Dold
@@ -28,6 +27,7 @@ import create = chrome.alarms.create;
import {Offer} from "./wallet";
import {CoinWithDenom} from "./wallet";
import {CoinPaySig} from "./types";
+import {Denomination} from "./types";
export function main(worker: Worker) {
@@ -101,7 +101,7 @@ namespace RpcFunctions {
coinPub: coinPub.toCrock(),
coinPriv: coinPriv.toCrock(),
denomPub: denomPub.encode().toCrock(),
- mintBaseUrl: reserve.mint_base_url,
+ exchangeBaseUrl: reserve.exchange_base_url,
withdrawSig: sig.toCrock(),
coinEv: ev.toCrock(),
coinValue: denom.value
diff --git a/lib/wallet/db.ts b/lib/wallet/db.ts
index c7621c5ff..9374aa447 100644
--- a/lib/wallet/db.ts
+++ b/lib/wallet/db.ts
@@ -25,7 +25,7 @@
*/
const DB_NAME = "taler";
-const DB_VERSION = 1;
+const DB_VERSION = 5;
/**
* Return a promise that resolves
@@ -45,12 +45,13 @@ export function openTalerDb(): Promise<IDBDatabase> {
console.log("DB: upgrade needed: oldVersion = " + e.oldVersion);
switch (e.oldVersion) {
case 0: // DB does not exist yet
- const mints = db.createObjectStore("mints", {keyPath: "baseUrl"});
- mints.createIndex("pubKey", "masterPublicKey");
+ const exchanges = db.createObjectStore("exchanges",
+ {keyPath: "baseUrl"});
+ exchanges.createIndex("pubKey", "masterPublicKey");
db.createObjectStore("reserves", {keyPath: "reserve_pub"});
db.createObjectStore("denoms", {keyPath: "denomPub"});
const coins = db.createObjectStore("coins", {keyPath: "coinPub"});
- coins.createIndex("mintBaseUrl", "mintBaseUrl");
+ coins.createIndex("exchangeBaseUrl", "exchangeBaseUrl");
const transactions = db.createObjectStore("transactions",
{keyPath: "contractHash"});
transactions.createIndex("repurchase",
@@ -68,6 +69,15 @@ export function openTalerDb(): Promise<IDBDatabase> {
});
history.createIndex("timestamp", "timestamp");
break;
+ default:
+ if (e.oldVersion != DB_VERSION) {
+ window.alert("Incompatible wallet dababase version, please reset" +
+ " db.");
+ chrome.browserAction.setBadgeText({text: "R!"});
+ chrome.browserAction.setBadgeBackgroundColor({color: "#F00"});
+ throw Error("incompatible DB");
+ }
+ break;
}
};
});
diff --git a/lib/wallet/helpers.ts b/lib/wallet/helpers.ts
index 99913e558..477fce33f 100644
--- a/lib/wallet/helpers.ts
+++ b/lib/wallet/helpers.ts
@@ -18,6 +18,8 @@
/**
* Smaller helper functions that do not depend
* on the emscripten machinery.
+ *
+ * @author Florian Dold
*/
import {AmountJson} from "./types";
@@ -36,7 +38,7 @@ export function amountToPretty(amount: AmountJson): string {
/**
- * Canonicalize a base url, typically for the mint.
+ * Canonicalize a base url, typically for the exchange.
*
* See http://api.taler.net/wallet.html#general
*/
@@ -62,4 +64,4 @@ export function parsePrettyAmount(pretty: string): AmountJson {
fraction: res[2] ? (parseFloat(`0.${res[2]}`) * 1e-6) : 0,
currency: res[3]
}
-} \ No newline at end of file
+}
diff --git a/lib/wallet/http.ts b/lib/wallet/http.ts
index 3f7244e40..3bc80f40a 100644
--- a/lib/wallet/http.ts
+++ b/lib/wallet/http.ts
@@ -81,4 +81,4 @@ export class RequestException {
constructor(detail) {
}
-} \ No newline at end of file
+}
diff --git a/lib/wallet/types.ts b/lib/wallet/types.ts
index 9c7b21b7c..feab1bcb1 100644
--- a/lib/wallet/types.ts
+++ b/lib/wallet/types.ts
@@ -21,6 +21,8 @@
* are defined in types.ts are intended to be used by components
* that do not depend on the whole wallet implementation (which depends on
* emscripten).
+ *
+ * @author Florian Dold
*/
import {Checkable} from "./checkable";
@@ -43,11 +45,11 @@ export class AmountJson {
@Checkable.Class
export class CreateReserveResponse {
/**
- * Mint URL where the bank should create the reserve.
+ * Exchange URL where the bank should create the reserve.
* The URL is canonicalized in the response.
*/
@Checkable.String
- mint: string;
+ exchange: string;
@Checkable.String
reservePub: string;
@@ -95,14 +97,14 @@ export class Denomination {
}
-export interface IMintInfo {
+export interface IExchangeInfo {
baseUrl: string;
masterPublicKey: string;
denoms: Denomination[];
}
export interface ReserveCreationInfo {
- mintInfo: IMintInfo;
+ exchangeInfo: IExchangeInfo;
selectedDenoms: Denomination[];
withdrawFee: AmountJson;
overhead: AmountJson;
@@ -117,13 +119,13 @@ export interface PreCoin {
blindingKey: string;
withdrawSig: string;
coinEv: string;
- mintBaseUrl: string;
+ exchangeBaseUrl: string;
coinValue: AmountJson;
}
export interface Reserve {
- mint_base_url: string
+ exchange_base_url: string
reserve_priv: string;
reserve_pub: string;
}
@@ -144,7 +146,70 @@ export interface Coin {
denomPub: string;
denomSig: string;
currentAmount: AmountJson;
- mintBaseUrl: string;
+ exchangeBaseUrl: string;
+}
+
+
+@Checkable.Class
+export class ExchangeHandle {
+ @Checkable.String
+ master_pub: string;
+
+ @Checkable.String
+ url: string;
+
+ static checked: (obj: any) => ExchangeHandle;
+}
+
+
+@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(ExchangeHandle))
+ exchanges: ExchangeHandle[];
+
+ @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;
+
+ @Checkable.Optional(Checkable.String)
+ repurchase_correlation_id: string;
+
+ static checked: (obj: any) => Contract;
}
@@ -266,4 +331,4 @@ export interface CheckRepurchaseResult {
export interface Notifier {
notify();
-} \ No newline at end of file
+}
diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts
index 92fb92a4a..8291f653a 100644
--- a/lib/wallet/wallet.ts
+++ b/lib/wallet/wallet.ts
@@ -21,7 +21,7 @@
* @author Florian Dold
*/
-import {AmountJson, CreateReserveResponse, IMintInfo, Denomination, Notifier} from "./types";
+import {AmountJson, CreateReserveResponse, IExchangeInfo, Denomination, Notifier} from "./types";
import {HttpResponse, RequestException} from "./http";
import {Query} from "./query";
import {Checkable} from "./checkable";
@@ -33,6 +33,8 @@ import {CryptoApi} from "./cryptoApi";
import {Coin} from "./types";
import {PayCoinInfo} from "./types";
import {CheckRepurchaseResult} from "./types";
+import {Contract} from "./types";
+import {ExchangeHandle} from "./types";
"use strict";
@@ -70,7 +72,7 @@ export class KeysJson {
}
-class MintInfo implements IMintInfo {
+class ExchangeInfo implements IExchangeInfo {
baseUrl: string;
masterPublicKey: string;
denoms: Denomination[];
@@ -89,15 +91,15 @@ class MintInfo implements IMintInfo {
}
}
- static fresh(baseUrl: string): MintInfo {
- return new MintInfo({baseUrl});
+ static fresh(baseUrl: string): ExchangeInfo {
+ return new ExchangeInfo({baseUrl});
}
/**
- * Merge new key information into the mint info.
+ * Merge new key information into the exchange info.
* If the new key information is invalid (missing fields,
* invalid signatures), an exception is thrown, but the
- * mint info is updated with the new information up until
+ * exchange info is updated with the new information up until
* the first error.
*/
mergeKeys(newKeys: KeysJson, cryptoApi: CryptoApi): Promise<void> {
@@ -160,10 +162,10 @@ export class CreateReserveRequest {
amount: AmountJson;
/**
- * Mint URL where the bank should create the reserve.
+ * Exchange URL where the bank should create the reserve.
*/
@Checkable.String
- mint: string;
+ exchange: string;
static checked: (obj: any) => CreateReserveRequest;
}
@@ -182,68 +184,6 @@ export class ConfirmReserveRequest {
}
-@Checkable.Class
-export class MintHandle {
- @Checkable.String
- master_pub: string;
-
- @Checkable.String
- url: string;
-
- static checked: (obj: any) => MintHandle;
-}
-
-
-@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(MintHandle))
- mints: MintHandle[];
-
- @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;
-
- @Checkable.Optional(Checkable.String)
- repurchase_correlation_id: string;
-
- static checked: (obj: any) => Contract;
-}
-
@Checkable.Class
export class Offer {
@@ -264,8 +204,8 @@ interface ConfirmPayRequest {
offer: Offer;
}
-interface MintCoins {
- [mintUrl: string]: CoinWithDenom[];
+interface ExchangeCoins {
+ [exchangeUrl: string]: CoinWithDenom[];
}
@@ -402,22 +342,22 @@ export class Wallet {
/**
- * Get mints and associated coins that are still spendable,
+ * Get exchanges and associated coins that are still spendable,
* but only if the sum the coins' remaining value exceeds the payment amount.
*/
- private getPossibleMintCoins(paymentAmount: AmountJson,
+ private getPossibleExchangeCoins(paymentAmount: AmountJson,
depositFeeLimit: AmountJson,
- allowedMints: MintHandle[]): Promise<MintCoins> {
- // Mapping from mint base URL to list of coins together with their
+ allowedExchanges: ExchangeHandle[]): Promise<ExchangeCoins> {
+ // Mapping from exchange base URL to list of coins together with their
// denomination
- let m: MintCoins = {};
+ let m: ExchangeCoins = {};
- function storeMintCoin(mc) {
- let mint: IMintInfo = mc[0];
+ function storeExchangeCoin(mc) {
+ let exchange: IExchangeInfo = mc[0];
let coin: Coin = mc[1];
let cd = {
coin: coin,
- denom: mint.denoms.find((e) => e.denom_pub === coin.denomPub)
+ denom: exchange.denoms.find((e) => e.denom_pub === coin.denomPub)
};
if (!cd.denom) {
throw Error("denom not found (database inconsistent)");
@@ -426,36 +366,36 @@ export class Wallet {
console.warn("same pubkey for different currencies");
return;
}
- let x = m[mint.baseUrl];
+ let x = m[exchange.baseUrl];
if (!x) {
- m[mint.baseUrl] = [cd];
+ m[exchange.baseUrl] = [cd];
} else {
x.push(cd);
}
}
- let ps = allowedMints.map((info) => {
- console.log("Checking for merchant's mint", JSON.stringify(info));
+ let ps = allowedExchanges.map((info) => {
+ console.log("Checking for merchant's exchange", JSON.stringify(info));
return Query(this.db)
- .iter("mints", {indexName: "pubKey", only: info.master_pub})
- .indexJoin("coins", "mintBaseUrl", (mint) => mint.baseUrl)
- .reduce(storeMintCoin);
+ .iter("exchanges", {indexName: "pubKey", only: info.master_pub})
+ .indexJoin("coins", "exchangeBaseUrl", (exchange) => exchange.baseUrl)
+ .reduce(storeExchangeCoin);
});
return Promise.all(ps).then(() => {
- let ret: MintCoins = {};
+ let ret: ExchangeCoins = {};
if (Object.keys(m).length == 0) {
- console.log("not suitable mints found");
+ console.log("not suitable exchanges found");
}
console.dir(m);
- // We try to find the first mint where we have
+ // We try to find the first exchange where we have
// enough coins to cover the paymentAmount with fees
// under depositFeeLimit
- nextMint:
+ nextExchange:
for (let key in m) {
let coins = m[key];
// Sort by ascending deposit fee
@@ -479,12 +419,12 @@ export class Wallet {
// FIXME: if the fees are too high, we have
// to cover them ourselves ....
console.log("too much fees");
- continue nextMint;
+ continue nextExchange;
}
usableCoins.push(coins[i]);
if (Amounts.cmp(accAmount, minAmount) >= 0) {
ret[key] = usableCoins;
- continue nextMint;
+ continue nextExchange;
}
}
}
@@ -499,14 +439,14 @@ export class Wallet {
*/
private recordConfirmPay(offer: Offer,
payCoinInfo: PayCoinInfo,
- chosenMint: string): Promise<void> {
+ chosenExchange: string): Promise<void> {
let payReq = {};
payReq["amount"] = offer.contract.amount;
payReq["coins"] = payCoinInfo.map((x) => x.sig);
payReq["H_contract"] = offer.H_contract;
payReq["max_fee"] = offer.contract.max_fee;
payReq["merchant_sig"] = offer.merchant_sig;
- payReq["mint"] = URI(chosenMint).href();
+ payReq["exchange"] = URI(chosenExchange).href();
payReq["refund_deadline"] = offer.contract.refund_deadline;
payReq["timestamp"] = offer.contract.timestamp;
payReq["transaction_id"] = offer.contract.transaction_id;
@@ -549,9 +489,9 @@ export class Wallet {
confirmPay(offer: Offer): Promise<any> {
console.log("executing confirmPay");
return Promise.resolve().then(() => {
- return this.getPossibleMintCoins(offer.contract.amount,
+ return this.getPossibleExchangeCoins(offer.contract.amount,
offer.contract.max_fee,
- offer.contract.mints)
+ offer.contract.exchanges)
}).then((mcs) => {
if (Object.keys(mcs).length == 0) {
console.log("not confirming payment, insufficient coins");
@@ -559,10 +499,10 @@ export class Wallet {
error: "coins-insufficient",
};
}
- let mintUrl = Object.keys(mcs)[0];
+ let exchangeUrl = Object.keys(mcs)[0];
- return this.cryptoApi.signDeposit(offer, mcs[mintUrl])
- .then((ds) => this.recordConfirmPay(offer, ds, mintUrl))
+ return this.cryptoApi.signDeposit(offer, mcs[exchangeUrl])
+ .then((ds) => this.recordConfirmPay(offer, ds, exchangeUrl))
.then(() => ({}));
});
}
@@ -599,11 +539,11 @@ export class Wallet {
* then deplete the reserve, withdrawing coins until it is empty.
*/
private initReserve(reserveRecord) {
- this.updateMintFromUrl(reserveRecord.mint_base_url)
- .then((mint) =>
- this.updateReserve(reserveRecord.reserve_pub, mint)
+ this.updateExchangeFromUrl(reserveRecord.exchange_base_url)
+ .then((exchange) =>
+ this.updateReserve(reserveRecord.reserve_pub, exchange)
.then((reserve) => this.depleteReserve(reserve,
- mint)))
+ exchange)))
.then(() => {
let depleted = {
type: "depleted-reserve",
@@ -627,12 +567,12 @@ export class Wallet {
createReserve(req: CreateReserveRequest): Promise<CreateReserveResponse> {
return this.cryptoApi.createEddsaKeypair().then((keypair) => {
const now = (new Date).getTime();
- const canonMint = canonicalizeBaseUrl(req.mint);
+ const canonExchange = canonicalizeBaseUrl(req.exchange);
const reserveRecord = {
reserve_pub: keypair.pub,
reserve_priv: keypair.priv,
- mint_base_url: canonMint,
+ exchange_base_url: canonExchange,
created: now,
last_query: null,
current_amount: null,
@@ -656,7 +596,7 @@ export class Wallet {
.finish()
.then(() => {
let r: CreateReserveResponse = {
- mint: canonMint,
+ exchange: canonExchange,
reservePub: keypair.pub,
};
return r;
@@ -668,7 +608,7 @@ export class Wallet {
/**
* Mark an existing reserve as confirmed. The wallet will start trying
* to withdraw from that reserve. This may not immediately succeed,
- * since the mint might not know about the reserve yet, even though the
+ * since the exchange might not know about the reserve yet, even though the
* bank confirmed its creation.
*
* A confirmed reserve should be shown to the user in the UI, while
@@ -708,7 +648,7 @@ export class Wallet {
wd.reserve_pub = pc.reservePub;
wd.reserve_sig = pc.withdrawSig;
wd.coin_ev = pc.coinEv;
- let reqUrl = URI("reserve/withdraw").absoluteTo(r.mint_base_url);
+ let reqUrl = URI("reserve/withdraw").absoluteTo(r.exchange_base_url);
return this.http.postJson(reqUrl, wd);
})
.then(resp => {
@@ -727,7 +667,7 @@ export class Wallet {
denomPub: pc.denomPub,
denomSig: denomSig,
currentAmount: pc.coinValue,
- mintBaseUrl: pc.mintBaseUrl,
+ exchangeBaseUrl: pc.exchangeBaseUrl,
};
return coin;
@@ -775,8 +715,8 @@ export class Wallet {
/**
* Withdraw coins from a reserve until it is empty.
*/
- private depleteReserve(reserve, mint: MintInfo): Promise<void> {
- let denomsAvailable: Denomination[] = copy(mint.denoms);
+ private depleteReserve(reserve, exchange: ExchangeInfo): Promise<void> {
+ let denomsAvailable: Denomination[] = copy(exchange.denoms);
let denomsForWithdraw = getWithdrawDenomList(reserve.current_amount,
denomsAvailable);
@@ -793,13 +733,13 @@ export class Wallet {
/**
* Update the information about a reserve that is stored in the wallet
- * by quering the reserve's mint.
+ * by quering the reserve's exchange.
*/
- private updateReserve(reservePub: string, mint: MintInfo): Promise<Reserve> {
+ private updateReserve(reservePub: string, exchange: ExchangeInfo): Promise<Reserve> {
return Query(this.db)
.get("reserves", reservePub)
.then((reserve) => {
- let reqUrl = URI("reserve/status").absoluteTo(mint.baseUrl);
+ let reqUrl = URI("reserve/status").absoluteTo(exchange.baseUrl);
reqUrl.query({'reserve_pub': reservePub});
return this.http.get(reqUrl).then(resp => {
if (resp.status != 200) {
@@ -832,10 +772,10 @@ export class Wallet {
getReserveCreationInfo(baseUrl: string,
amount: AmountJson): Promise<ReserveCreationInfo> {
- return this.updateMintFromUrl(baseUrl)
- .then((mintInfo: IMintInfo) => {
+ return this.updateExchangeFromUrl(baseUrl)
+ .then((exchangeInfo: IExchangeInfo) => {
let selectedDenoms = getWithdrawDenomList(amount,
- mintInfo.denoms);
+ exchangeInfo.denoms);
let acc = Amounts.getZero(amount.currency);
for (let d of selectedDenoms) {
@@ -846,7 +786,7 @@ export class Wallet {
d.fee_withdraw).amount)
.reduce((a, b) => Amounts.add(a, b).amount);
let ret: ReserveCreationInfo = {
- mintInfo,
+ exchangeInfo,
selectedDenoms,
withdrawFee: acc,
overhead: Amounts.sub(amount, actualCoinCost).amount,
@@ -857,37 +797,37 @@ export class Wallet {
/**
- * Update or add mint DB entry by fetching the /keys information.
+ * Update or add exchange DB entry by fetching the /keys information.
* Optionally link the reserve entry to the new or existing
- * mint entry in then DB.
+ * exchange entry in then DB.
*/
- updateMintFromUrl(baseUrl): Promise<MintInfo> {
+ updateExchangeFromUrl(baseUrl): Promise<ExchangeInfo> {
baseUrl = canonicalizeBaseUrl(baseUrl);
let reqUrl = URI("keys").absoluteTo(baseUrl);
return this.http.get(reqUrl).then((resp) => {
if (resp.status != 200) {
throw Error("/keys request failed");
}
- let mintKeysJson = KeysJson.checked(JSON.parse(resp.responseText));
+ let exchangeKeysJson = KeysJson.checked(JSON.parse(resp.responseText));
- return Query(this.db).get("mints", baseUrl).then((r) => {
- let mintInfo;
+ return Query(this.db).get("exchanges", baseUrl).then((r) => {
+ let exchangeInfo;
console.dir(r);
if (!r) {
- mintInfo = MintInfo.fresh(baseUrl);
- console.log("making fresh mint");
+ exchangeInfo = ExchangeInfo.fresh(baseUrl);
+ console.log("making fresh exchange");
} else {
- mintInfo = new MintInfo(r);
- console.log("using old mint");
+ exchangeInfo = new ExchangeInfo(r);
+ console.log("using old exchange");
}
- return mintInfo.mergeKeys(mintKeysJson, this.cryptoApi)
+ return exchangeInfo.mergeKeys(exchangeKeysJson, this.cryptoApi)
.then(() => {
return Query(this.db)
- .put("mints", mintInfo)
+ .put("exchanges", exchangeInfo)
.finish()
- .then(() => mintInfo);
+ .then(() => exchangeInfo);
});
});
@@ -912,14 +852,17 @@ export class Wallet {
return Query(this.db)
.iter("coins")
- .reduce(collectBalances, {});
+ .reduce(collectBalances, {})
+ .then(byCurrency => {
+ return {balances: byCurrency};
+ });
}
/**
* Retrive the full event history for this wallet.
*/
- getHistory(): Promise<any[]> {
+ getHistory(): Promise<any> {
function collect(x, acc) {
acc.push(x);
return acc;
@@ -928,6 +871,7 @@ export class Wallet {
return Query(this.db)
.iter("history", {indexName: "timestamp"})
.reduce(collect, [])
+ .then(acc => ({history: acc}));
}
checkRepurchase(contract: Contract): Promise<CheckRepurchaseResult> {
@@ -954,4 +898,4 @@ export class Wallet {
}
});
}
-} \ No newline at end of file
+}
diff --git a/lib/wallet/wxApi.ts b/lib/wallet/wxApi.ts
index 9871b6e7f..2b69ff82e 100644
--- a/lib/wallet/wxApi.ts
+++ b/lib/wallet/wxApi.ts
@@ -19,6 +19,7 @@ import {ReserveCreationInfo} from "./types";
/**
* Interface to the wallet through WebExtension messaging.
+ * @author Florian Dold
*/
@@ -37,4 +38,4 @@ export function getReserveCreationInfo(baseUrl: string,
resolve(resp);
});
});
-} \ No newline at end of file
+}
diff --git a/lib/wallet/wxMessaging.ts b/lib/wallet/wxMessaging.ts
index 740873d88..daa9ec197 100644
--- a/lib/wallet/wxMessaging.ts
+++ b/lib/wallet/wxMessaging.ts
@@ -22,7 +22,7 @@ import {Checkable} from "./checkable";
import {AmountJson} from "./types";
import Port = chrome.runtime.Port;
import {Notifier} from "./types";
-import {Contract} from "./wallet";
+import {Contract} from "./types";
"use strict";
@@ -47,9 +47,11 @@ function makeHandlers(db: IDBDatabase,
return exportDb(db);
},
["reset"]: function(detail) {
- let tx = db.transaction(db.objectStoreNames, 'readwrite');
- for (let i = 0; i < db.objectStoreNames.length; i++) {
- tx.objectStore(db.objectStoreNames[i]).clear();
+ if (db) {
+ let tx = db.transaction(db.objectStoreNames, 'readwrite');
+ for (let i = 0; i < db.objectStoreNames.length; i++) {
+ tx.objectStore(db.objectStoreNames[i]).clear();
+ }
}
deleteDb();
@@ -60,7 +62,7 @@ function makeHandlers(db: IDBDatabase,
},
["create-reserve"]: function(detail) {
const d = {
- mint: detail.mint,
+ exchange: detail.exchange,
amount: detail.amount,
};
const req = CreateReserveRequest.checked(d);
@@ -96,11 +98,11 @@ function makeHandlers(db: IDBDatabase,
["execute-payment"]: function(detail) {
return wallet.executePayment(detail.H_contract);
},
- ["mint-info"]: function(detail) {
+ ["exchange-info"]: function(detail) {
if (!detail.baseUrl) {
return Promise.resolve({error: "bad url"});
}
- return wallet.updateMintFromUrl(detail.baseUrl);
+ return wallet.updateExchangeFromUrl(detail.baseUrl);
},
["reserve-creation-info"]: function(detail) {
if (!detail.baseUrl || typeof detail.baseUrl !== "string") {
@@ -193,6 +195,19 @@ class ChromeNotifier implements Notifier {
export function wxMain() {
chrome.browserAction.setBadgeText({text: ""});
+ chrome.tabs.query({}, function(tabs) {
+ for (let tab of tabs) {
+ if (!tab.url) {
+ return;
+ }
+ let uri = URI(tab.url);
+ if (uri.protocol() == "http" || uri.protocol() == "https") {
+ console.log("injecting into existing tab", tab.id);
+ chrome.tabs.executeScript(tab.id, {file: "content_scripts/notify.js"});
+ }
+ }
+ });
+
Promise.resolve()
.then(() => {
return openTalerDb();