aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 04:16:12 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 04:16:12 +0200
commitd5bba630a35fff72b11273fb5e62c2208f9e1f5b (patch)
tree3397a580d663161be1ba7c46df368ac10d566cdc /src/crypto
parent419a05e801da688a1d0917a6bf16d468e6362a3d (diff)
implement returning coins to user's account
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cryptoApi.ts6
-rw-r--r--src/crypto/cryptoWorker.ts22
2 files changed, 16 insertions, 12 deletions
diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts
index 139f8ae88..227c3d346 100644
--- a/src/crypto/cryptoApi.ts
+++ b/src/crypto/cryptoApi.ts
@@ -26,8 +26,8 @@
import {
AmountJson,
CoinRecord,
+ ContractTerms,
DenominationRecord,
- ProposalRecord,
PayCoinInfo,
PaybackRequest,
PreCoinRecord,
@@ -277,9 +277,9 @@ export class CryptoApi {
return this.doRpc<PayCoinInfo>("isValidPaymentSignature", 1, sig, contractHash, merchantPub);
}
- signDeposit(proposal: ProposalRecord,
+ signDeposit(contractTerms: ContractTerms,
cds: CoinWithDenom[]): Promise<PayCoinInfo> {
- return this.doRpc<PayCoinInfo>("signDeposit", 3, proposal, cds);
+ return this.doRpc<PayCoinInfo>("signDeposit", 3, contractTerms, cds);
}
createEddsaKeypair(): Promise<{priv: string, pub: string}> {
diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts
index 507a080ac..b05d7d184 100644
--- a/src/crypto/cryptoWorker.ts
+++ b/src/crypto/cryptoWorker.ts
@@ -28,8 +28,8 @@ import {
CoinPaySig,
CoinRecord,
CoinStatus,
+ ContractTerms,
DenominationRecord,
- ProposalRecord,
PayCoinInfo,
PaybackRequest,
PreCoinRecord,
@@ -39,6 +39,9 @@ import {
WireFee,
} from "../types";
import {
+ canonicalJson,
+} from "../helpers";
+import {
CoinWithDenom,
} from "../wallet";
@@ -227,16 +230,17 @@ namespace RpcFunctions {
* Generate updated coins (to store in the database)
* and deposit permissions for each given coin.
*/
- export function signDeposit(proposal: ProposalRecord,
+ export function signDeposit(contractTerms: ContractTerms,
cds: CoinWithDenom[]): PayCoinInfo {
const ret: PayCoinInfo = [];
+ const contractTermsHash = hashString(canonicalJson(contractTerms));
const feeList: AmountJson[] = cds.map((x) => x.denom.feeDeposit);
let fees = Amounts.add(Amounts.getZero(feeList[0].currency), ...feeList).amount;
// okay if saturates
- fees = Amounts.sub(fees, proposal.contractTerms.max_fee).amount;
- const total = Amounts.add(fees, proposal.contractTerms.amount).amount;
+ fees = Amounts.sub(fees, contractTerms.max_fee).amount;
+ const total = Amounts.add(fees, contractTerms.amount).amount;
const amountSpent = native.Amount.getZero(cds[0].coin.currentAmount.currency);
const amountRemaining = new native.Amount(total);
@@ -273,11 +277,11 @@ namespace RpcFunctions {
amount_with_fee: coinSpend.toNbo(),
coin_pub: native.EddsaPublicKey.fromCrock(cd.coin.coinPub),
deposit_fee: new native.Amount(cd.denom.feeDeposit).toNbo(),
- h_contract: native.HashCode.fromCrock(proposal.contractTermsHash),
- h_wire: native.HashCode.fromCrock(proposal.contractTerms.H_wire),
- merchant: native.EddsaPublicKey.fromCrock(proposal.contractTerms.merchant_pub),
- refund_deadline: native.AbsoluteTimeNbo.fromTalerString(proposal.contractTerms.refund_deadline),
- timestamp: native.AbsoluteTimeNbo.fromTalerString(proposal.contractTerms.timestamp),
+ h_contract: native.HashCode.fromCrock(contractTermsHash),
+ h_wire: native.HashCode.fromCrock(contractTerms.H_wire),
+ merchant: native.EddsaPublicKey.fromCrock(contractTerms.merchant_pub),
+ refund_deadline: native.AbsoluteTimeNbo.fromTalerString(contractTerms.refund_deadline),
+ timestamp: native.AbsoluteTimeNbo.fromTalerString(contractTerms.timestamp),
});
const coinSig = native.eddsaSign(d.toPurpose(),