store reservePub/blindingKey directly in coin
This commit is contained in:
parent
41ed276f3a
commit
10efd87a8e
@ -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,
|
||||
|
@ -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(),
|
||||
};
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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!);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 });
|
||||
}
|
||||
|
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user