aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-09-05 12:55:46 +0200
committerFlorian Dold <florian@dold.me>2022-09-05 12:55:46 +0200
commit300242637f20401fa9074e36eea5fa8788cc7202 (patch)
tree58c962aeee17f2dc1e8de53fb6c5403a1960f789 /packages
parentb1f77f4662e8198d0e02e74d43fd6d1f82ce2fb0 (diff)
downloadwallet-core-300242637f20401fa9074e36eea5fa8788cc7202.tar.gz
wallet-core-300242637f20401fa9074e36eea5fa8788cc7202.tar.bz2
wallet-core-300242637f20401fa9074e36eea5fa8788cc7202.zip
wallet-core: include age restriction in p2p signature, mark coins as spent
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/crypto/cryptoImplementation.ts12
-rw-r--r--packages/taler-wallet-core/src/operations/peer-to-peer.ts13
2 files changed, 21 insertions, 4 deletions
diff --git a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
index 193712e52..6336539fa 100644
--- a/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
+++ b/packages/taler-wallet-core/src/crypto/cryptoImplementation.ts
@@ -442,6 +442,7 @@ export interface SignPurseDepositsRequest {
contribution: AmountString;
denomPubHash: string;
denomSig: UnblindedSignature;
+ ageCommitmentProof: AgeCommitmentProof | undefined;
}[];
}
@@ -1361,11 +1362,18 @@ export const nativeCryptoR: TalerCryptoInterfaceR = {
const hExchangeBaseUrl = hash(stringToBytes(req.exchangeBaseUrl + "\0"));
const deposits: PurseDeposit[] = [];
for (const c of req.coins) {
+ let maybeAch: Uint8Array;
+ if (c.ageCommitmentProof) {
+ maybeAch = decodeCrock(
+ AgeRestriction.hashCommitment(c.ageCommitmentProof.commitment),
+ );
+ } else {
+ maybeAch = new Uint8Array(32);
+ }
const sigBlob = buildSigPS(TalerSignaturePurpose.WALLET_PURSE_DEPOSIT)
.put(amountToBuffer(Amounts.parseOrThrow(c.contribution)))
.put(decodeCrock(c.denomPubHash))
- // FIXME: use h_age_commitment here
- .put(new Uint8Array(32))
+ .put(maybeAch)
.put(decodeCrock(req.pursePub))
.put(hExchangeBaseUrl)
.build();
diff --git a/packages/taler-wallet-core/src/operations/peer-to-peer.ts b/packages/taler-wallet-core/src/operations/peer-to-peer.ts
index 275258081..965dfd8ed 100644
--- a/packages/taler-wallet-core/src/operations/peer-to-peer.ts
+++ b/packages/taler-wallet-core/src/operations/peer-to-peer.ts
@@ -21,6 +21,7 @@ import {
AbsoluteTime,
AcceptPeerPullPaymentRequest,
AcceptPeerPushPaymentRequest,
+ AgeCommitmentProof,
AmountJson,
AmountLike,
Amounts,
@@ -89,6 +90,7 @@ export interface PeerCoinSelection {
contribution: AmountString;
denomPubHash: string;
denomSig: UnblindedSignature;
+ ageCommitmentProof: AgeCommitmentProof | undefined;
}[];
/**
@@ -115,6 +117,8 @@ interface CoinInfo {
denomPubHash: string;
denomSig: UnblindedSignature;
+
+ ageCommitmentProof: AgeCommitmentProof | undefined;
}
export async function selectPeerCoins(
@@ -152,6 +156,7 @@ export async function selectPeerCoins(
denomPubHash: denom.denomPubHash,
coinPriv: coin.coinPriv,
denomSig: coin.denomSig,
+ ageCommitmentProof: coin.ageCommitmentProof,
});
}
if (coinInfos.length === 0) {
@@ -170,6 +175,7 @@ export async function selectPeerCoins(
contribution: AmountString;
denomPubHash: string;
denomSig: UnblindedSignature;
+ ageCommitmentProof: AgeCommitmentProof | undefined;
}[] = [];
for (const coin of coinInfos) {
if (Amounts.cmp(amountAcc, instructedAmount) >= 0) {
@@ -196,6 +202,7 @@ export async function selectPeerCoins(
contribution: Amounts.stringify(contrib),
denomPubHash: coin.denomPubHash,
denomSig: coin.denomSig,
+ ageCommitmentProof: coin.ageCommitmentProof,
});
}
continue;
@@ -257,6 +264,7 @@ export async function initiatePeerToPeerPush(
coin.currentAmount,
Amounts.parseOrThrow(c.contribution),
).amount;
+ coin.status = CoinStatus.Dormant;
await tx.coins.put(coin);
}
@@ -279,7 +287,7 @@ export async function initiatePeerToPeerPush(
return sel;
});
- logger.info(`selected p2p coins: ${j2s(coinSelRes)}`);
+ logger.info(`selected p2p coins (push): ${j2s(coinSelRes)}`);
if (!coinSelRes) {
throw Error("insufficient balance");
@@ -592,6 +600,7 @@ export async function acceptPeerPullPayment(
coin.currentAmount,
Amounts.parseOrThrow(c.contribution),
).amount;
+ coin.status = CoinStatus.Dormant;
await tx.coins.put(coin);
}
@@ -608,7 +617,7 @@ export async function acceptPeerPullPayment(
return sel;
});
- logger.info(`selected p2p coins: ${j2s(coinSelRes)}`);
+ logger.info(`selected p2p coins (pull): ${j2s(coinSelRes)}`);
if (!coinSelRes) {
throw Error("insufficient balance");