aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-01 04:33:47 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-01 04:33:47 +0200
commit10efd87a8ebcddb75d784f111af534b9d6ea494b (patch)
treeb1ace802de482e2ea5d253d097d5f37c5ceb9eae
parent41ed276f3aad355a8a2504759edf5b737922272e (diff)
store reservePub/blindingKey directly in coin
-rw-r--r--src/cryptoApi.ts4
-rw-r--r--src/cryptoWorker.ts9
-rw-r--r--src/pages/tree.tsx3
-rw-r--r--src/types.ts8
-rw-r--r--src/wallet.ts20
-rw-r--r--src/wxApi.ts4
-rw-r--r--src/wxBackend.ts6
7 files changed, 37 insertions, 17 deletions
diff --git a/src/cryptoApi.ts b/src/cryptoApi.ts
index 8dd14392a..402b33acd 100644
--- a/src/cryptoApi.ts
+++ b/src/cryptoApi.ts
@@ -267,8 +267,8 @@ export class CryptoApi {
return this.doRpc<string>("rsaUnblind", 4, sig, bk, pk);
}
- createPaybackRequest(coin: CoinRecord, preCoin: PreCoinRecord): Promise<PaybackRequest> {
- return this.doRpc<PaybackRequest>("createPaybackRequest", 1, coin, preCoin);
+ createPaybackRequest(coin: CoinRecord): Promise<PaybackRequest> {
+ return this.doRpc<PaybackRequest>("createPaybackRequest", 1, coin);
}
createRefreshSession(exchangeBaseUrl: string,
diff --git a/src/cryptoWorker.ts b/src/cryptoWorker.ts
index a11a0d021..aab7d3343 100644
--- a/src/cryptoWorker.ts
+++ b/src/cryptoWorker.ts
@@ -102,21 +102,18 @@ namespace RpcFunctions {
return preCoin;
}
- export function createPaybackRequest(coin: CoinRecord, preCoin: PreCoinRecord): PaybackRequest {
- if (coin.coinPub != preCoin.coinPub) {
- throw Error("coin doesn't match precoin");
- }
+ export function createPaybackRequest(coin: CoinRecord): PaybackRequest {
let p = new native.PaybackRequestPS({
coin_pub: native.EddsaPublicKey.fromCrock(coin.coinPub),
h_denom_pub: native.RsaPublicKey.fromCrock(coin.denomPub).encode().hash(),
- coin_blind: native.RsaBlindingKeySecret.fromCrock(preCoin.blindingKey),
+ coin_blind: native.RsaBlindingKeySecret.fromCrock(coin.blindingKey),
});
let coinPriv = native.EddsaPrivateKey.fromCrock(coin.coinPriv);
let coinSig = native.eddsaSign(p.toPurpose(), coinPriv);
let paybackRequest: PaybackRequest = {
denom_pub: coin.denomPub,
denom_sig: coin.denomSig,
- coin_blind_key_secret: preCoin.blindingKey,
+ coin_blind_key_secret: coin.blindingKey,
coin_pub: coin.coinPub,
coin_sig: coinSig.toCrock(),
};
diff --git a/src/pages/tree.tsx b/src/pages/tree.tsx
index a465cff59..201d411ac 100644
--- a/src/pages/tree.tsx
+++ b/src/pages/tree.tsx
@@ -33,7 +33,7 @@ import {
import { ImplicitStateComponent, StateHolder } from "../components";
import {
getReserves, getExchanges, getCoins, getPreCoins,
- refresh, getDenoms
+ refresh, getDenoms, payback,
} from "../wxApi";
import { prettyAmount } from "../renderHtml";
import { getTalerStampDate } from "../helpers";
@@ -135,6 +135,7 @@ class CoinView extends React.Component<CoinViewProps, void> {
<li>Suspended: {(c.suspended || false).toString()}</li>
<li>Status: {CoinStatus[c.status]}</li>
<li><RefreshDialog coin={c} /></li>
+ <li><button onClick={() => payback(c.coinPub)}>Payback</button></li>
</ul>
</div>
);
diff --git a/src/types.ts b/src/types.ts
index 4964d9f45..8fec79ef2 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -461,6 +461,14 @@ export interface CoinRecord {
*/
suspended?: boolean;
+ blindingKey: string;
+
+ /**
+ * Reserve public key for the reserve we got this coin from,
+ * or zero when we got the coin from refresh.
+ */
+ reservePub: string|undefined,
+
/**
* Status of the coin.
*/
diff --git a/src/wallet.ts b/src/wallet.ts
index 71dc1754b..b39cbd9e9 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -1144,10 +1144,12 @@ export class Wallet {
pc.blindingKey,
pc.denomPub);
let coin: CoinRecord = {
+ reservePub: pc.reservePub,
coinPub: pc.coinPub,
coinPriv: pc.coinPriv,
denomPub: pc.denomPub,
denomSig: denomSig,
+ blindingKey: pc.blindingKey,
currentAmount: pc.coinValue,
exchangeBaseUrl: pc.exchangeBaseUrl,
status: CoinStatus.Fresh,
@@ -1971,6 +1973,8 @@ export class Wallet {
pc.blindingKey,
denom.denomPub);
let coin: CoinRecord = {
+ reservePub: undefined,
+ blindingKey: pc.blindingKey,
coinPub: pc.publicKey,
coinPriv: pc.privateKey,
denomPub: denom.denomPub,
@@ -2128,11 +2132,11 @@ export class Wallet {
if (!coin) {
throw Error(`Coin ${coinPub} not found, can't request payback`);
}
- let preCoin = await this.q().get(Stores.precoins, coin.coinPub);
- if (!preCoin) {
- throw Error(`Precoin of coin ${coinPub} not found`);
+ let reservePub = coin.reservePub;
+ if (!reservePub) {
+ throw Error(`Can't request payback for a refreshed coin`);
}
- let reserve = await this.q().get(Stores.reserves, preCoin.reservePub);
+ let reserve = await this.q().get(Stores.reserves, reservePub);
if (!reserve) {
throw Error(`Reserve of coin ${coinPub} not found`);
}
@@ -2150,14 +2154,14 @@ export class Wallet {
reserve.hasPayback = true;
await this.q().put(Stores.coins, coin).put(Stores.reserves, reserve);
- let paybackRequest = await this.cryptoApi.createPaybackRequest(coin, preCoin);
- let reqUrl = new URI("payback").absoluteTo(preCoin.exchangeBaseUrl);
+ let paybackRequest = await this.cryptoApi.createPaybackRequest(coin);
+ let reqUrl = new URI("payback").absoluteTo(coin.exchangeBaseUrl);
let resp = await this.http.get(reqUrl.href());
if (resp.status != 200) {
throw Error();
}
let paybackConfirmation = PaybackConfirmation.checked(JSON.parse(resp.responseText));
- if (paybackConfirmation.reserve_pub != preCoin.reservePub) {
+ if (paybackConfirmation.reserve_pub != coin.reservePub) {
throw Error(`Coin's reserve doesn't match reserve on payback`);
}
coin = await this.q().get(Stores.coins, coinPub);
@@ -2166,7 +2170,7 @@ export class Wallet {
}
coin.status = CoinStatus.PaybackDone;
await this.q().put(Stores.coins, coin);
- await this.updateReserve(preCoin.reservePub);
+ await this.updateReserve(reservePub!);
}
diff --git a/src/wxApi.ts b/src/wxApi.ts
index 0f460085e..f06ab69a7 100644
--- a/src/wxApi.ts
+++ b/src/wxApi.ts
@@ -107,3 +107,7 @@ export async function getDenoms(exchangeBaseUrl: string): Promise<DenominationRe
export async function refresh(coinPub: string): Promise<void> {
return await callBackend("refresh-coin", { coinPub });
}
+
+export async function payback(coinPub: string): Promise<void> {
+ return await callBackend("payback-coin", { coinPub });
+}
diff --git a/src/wxBackend.ts b/src/wxBackend.ts
index 1588ec857..089526a43 100644
--- a/src/wxBackend.ts
+++ b/src/wxBackend.ts
@@ -259,6 +259,12 @@ function makeHandlers(db: IDBDatabase,
}
return wallet.refresh(detail.coinPub);
},
+ ["payback-coin"]: function (detail, sender) {
+ if (typeof detail.coinPub !== "string") {
+ return Promise.reject(Error("coinPub missing"));
+ }
+ return wallet.payback(detail.coinPub);
+ },
["payment-failed"]: function (detail, sender) {
// For now we just update exchanges (maybe the exchange did something
// wrong and the keys were messed up).