From b8ccc7c990a1542cf80578b41972f9a5b0870af9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 30 Nov 2017 04:07:36 +0100 Subject: partial implementation of tipping --- src/crypto/cryptoApi.ts | 5 +++++ src/crypto/cryptoWorker.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src/crypto') diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts index 00013f0d3..5300c1370 100644 --- a/src/crypto/cryptoApi.ts +++ b/src/crypto/cryptoApi.ts @@ -34,6 +34,7 @@ import { PreCoinRecord, RefreshSessionRecord, ReserveRecord, + TipPlanchet, WireFee, } from "../types"; @@ -253,6 +254,10 @@ export class CryptoApi { return this.doRpc("createPreCoin", 1, denom, reserve); } + createTipPlanchet(denom: DenominationRecord): Promise { + return this.doRpc("createTipPlanchet", 1, denom); + } + hashString(str: string): Promise { return this.doRpc("hashString", 1, str); } diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts index 0a93fcb07..5ec7c18e5 100644 --- a/src/crypto/cryptoWorker.ts +++ b/src/crypto/cryptoWorker.ts @@ -40,6 +40,7 @@ import { RefreshPreCoinRecord, RefreshSessionRecord, ReserveRecord, + TipPlanchet, WireFee, } from "../types"; @@ -103,6 +104,7 @@ namespace RpcFunctions { coinValue: denom.value, denomPub: denomPub.encode().toCrock(), exchangeBaseUrl: reserve.exchange_base_url, + isFromTip: false, reservePub: reservePub.toCrock(), withdrawSig: sig.toCrock(), }; @@ -110,6 +112,35 @@ namespace RpcFunctions { } + export function createTipPlanchet(denom: DenominationRecord): TipPlanchet { + const denomPub = native.RsaPublicKey.fromCrock(denom.denomPub); + const coinPriv = native.EddsaPrivateKey.create(); + const coinPub = coinPriv.getPublicKey(); + const blindingFactor = native.RsaBlindingKeySecret.create(); + const pubHash: native.HashCode = coinPub.hash(); + const ev = native.rsaBlind(pubHash, blindingFactor, denomPub); + + if (!ev) { + throw Error("couldn't blind (malicious exchange key?)"); + } + + if (!denom.feeWithdraw) { + throw Error("Field fee_withdraw missing"); + } + + const tipPlanchet: TipPlanchet = { + blindingKey: blindingFactor.toCrock(), + coinEv: ev.toCrock(), + coinPriv: coinPriv.toCrock(), + coinPub: coinPub.toCrock(), + coinValue: denom.value, + denomPubHash: denomPub.encode().hash().toCrock(), + denomPub: denomPub.encode().toCrock(), + }; + return tipPlanchet; + } + + /** * Create and sign a message to request payback for a coin. */ -- cgit v1.2.3