wallet-core: make coin selection aware of age restriction
This commit is contained in:
parent
5e7be58658
commit
9996c27488
@ -315,6 +315,7 @@ export async function getCandidatePayCoins(
|
|||||||
denomPub: denom.denomPub,
|
denomPub: denom.denomPub,
|
||||||
feeDeposit: denom.feeDeposit,
|
feeDeposit: denom.feeDeposit,
|
||||||
exchangeBaseUrl: denom.exchangeBaseUrl,
|
exchangeBaseUrl: denom.exchangeBaseUrl,
|
||||||
|
ageCommitmentProof: coin.ageCommitmentProof,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1120,6 +1121,7 @@ async function handleInsufficientFunds(
|
|||||||
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
||||||
wireFeeLimit: contractData.maxWireFee,
|
wireFeeLimit: contractData.maxWireFee,
|
||||||
prevPayCoins,
|
prevPayCoins,
|
||||||
|
requiredMinimumAge: contractData.minimumAge,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@ -1236,6 +1238,7 @@ export async function checkPaymentByProposalId(
|
|||||||
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
||||||
wireFeeLimit: contractData.maxWireFee,
|
wireFeeLimit: contractData.maxWireFee,
|
||||||
prevPayCoins: [],
|
prevPayCoins: [],
|
||||||
|
requiredMinimumAge: contractData.minimumAge,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@ -1488,6 +1491,7 @@ export async function confirmPay(
|
|||||||
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
wireFeeAmortization: contractData.wireFeeAmortization ?? 1,
|
||||||
wireFeeLimit: contractData.maxWireFee,
|
wireFeeLimit: contractData.maxWireFee,
|
||||||
prevPayCoins: [],
|
prevPayCoins: [],
|
||||||
|
requiredMinimumAge: contractData.minimumAge,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.trace("coin selection result", res);
|
logger.trace("coin selection result", res);
|
||||||
|
@ -24,12 +24,12 @@
|
|||||||
* Imports.
|
* Imports.
|
||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
|
AgeCommitmentProof,
|
||||||
|
AgeRestriction,
|
||||||
AmountJson,
|
AmountJson,
|
||||||
Amounts,
|
Amounts,
|
||||||
DenominationPubKey,
|
DenominationPubKey,
|
||||||
DenomKeyType,
|
|
||||||
Logger,
|
Logger,
|
||||||
strcmp,
|
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
|
|
||||||
const logger = new Logger("coinSelection.ts");
|
const logger = new Logger("coinSelection.ts");
|
||||||
@ -94,6 +94,8 @@ export interface AvailableCoinInfo {
|
|||||||
feeDeposit: AmountJson;
|
feeDeposit: AmountJson;
|
||||||
|
|
||||||
exchangeBaseUrl: string;
|
exchangeBaseUrl: string;
|
||||||
|
|
||||||
|
ageCommitmentProof?: AgeCommitmentProof;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PreviousPayCoins = {
|
export type PreviousPayCoins = {
|
||||||
@ -115,6 +117,7 @@ export interface SelectPayCoinRequest {
|
|||||||
wireFeeLimit: AmountJson;
|
wireFeeLimit: AmountJson;
|
||||||
wireFeeAmortization: number;
|
wireFeeAmortization: number;
|
||||||
prevPayCoins?: PreviousPayCoins;
|
prevPayCoins?: PreviousPayCoins;
|
||||||
|
requiredMinimumAge?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CoinSelectionTally {
|
interface CoinSelectionTally {
|
||||||
@ -306,6 +309,21 @@ export function selectPayCoins(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.requiredMinimumAge != null) {
|
||||||
|
const index = AgeRestriction.getAgeGroupIndex(
|
||||||
|
aci.denomPub.age_mask,
|
||||||
|
req.requiredMinimumAge,
|
||||||
|
);
|
||||||
|
if (!aci.ageCommitmentProof) {
|
||||||
|
// No age restriction, can't use for this payment
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (aci.ageCommitmentProof.proof.privateKeys.length < index) {
|
||||||
|
// Available age proofs to low, can't use for this payment
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tally = tallyFees(
|
tally = tallyFees(
|
||||||
tally,
|
tally,
|
||||||
candidates.wireFeesPerExchange,
|
candidates.wireFeesPerExchange,
|
||||||
|
Loading…
Reference in New Issue
Block a user