aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/cryptoWorker.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-11-30 04:07:36 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-12-01 03:00:09 +0100
commitb8ccc7c990a1542cf80578b41972f9a5b0870af9 (patch)
tree6f16319f9ce3133c4c4617129a516e692cfc3ac1 /src/crypto/cryptoWorker.ts
parentbc2c4aff8e657c7d5709433f137299491b98d257 (diff)
downloadwallet-core-b8ccc7c990a1542cf80578b41972f9a5b0870af9.tar.xz
partial implementation of tipping
Diffstat (limited to 'src/crypto/cryptoWorker.ts')
-rw-r--r--src/crypto/cryptoWorker.ts31
1 files changed, 31 insertions, 0 deletions
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.
*/