wallet-core: include age restriction in p2p signature, mark coins as spent
This commit is contained in:
parent
b1f77f4662
commit
300242637f
@ -442,6 +442,7 @@ export interface SignPurseDepositsRequest {
|
|||||||
contribution: AmountString;
|
contribution: AmountString;
|
||||||
denomPubHash: string;
|
denomPubHash: string;
|
||||||
denomSig: UnblindedSignature;
|
denomSig: UnblindedSignature;
|
||||||
|
ageCommitmentProof: AgeCommitmentProof | undefined;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1361,11 +1362,18 @@ export const nativeCryptoR: TalerCryptoInterfaceR = {
|
|||||||
const hExchangeBaseUrl = hash(stringToBytes(req.exchangeBaseUrl + "\0"));
|
const hExchangeBaseUrl = hash(stringToBytes(req.exchangeBaseUrl + "\0"));
|
||||||
const deposits: PurseDeposit[] = [];
|
const deposits: PurseDeposit[] = [];
|
||||||
for (const c of req.coins) {
|
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)
|
const sigBlob = buildSigPS(TalerSignaturePurpose.WALLET_PURSE_DEPOSIT)
|
||||||
.put(amountToBuffer(Amounts.parseOrThrow(c.contribution)))
|
.put(amountToBuffer(Amounts.parseOrThrow(c.contribution)))
|
||||||
.put(decodeCrock(c.denomPubHash))
|
.put(decodeCrock(c.denomPubHash))
|
||||||
// FIXME: use h_age_commitment here
|
.put(maybeAch)
|
||||||
.put(new Uint8Array(32))
|
|
||||||
.put(decodeCrock(req.pursePub))
|
.put(decodeCrock(req.pursePub))
|
||||||
.put(hExchangeBaseUrl)
|
.put(hExchangeBaseUrl)
|
||||||
.build();
|
.build();
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
AbsoluteTime,
|
AbsoluteTime,
|
||||||
AcceptPeerPullPaymentRequest,
|
AcceptPeerPullPaymentRequest,
|
||||||
AcceptPeerPushPaymentRequest,
|
AcceptPeerPushPaymentRequest,
|
||||||
|
AgeCommitmentProof,
|
||||||
AmountJson,
|
AmountJson,
|
||||||
AmountLike,
|
AmountLike,
|
||||||
Amounts,
|
Amounts,
|
||||||
@ -89,6 +90,7 @@ export interface PeerCoinSelection {
|
|||||||
contribution: AmountString;
|
contribution: AmountString;
|
||||||
denomPubHash: string;
|
denomPubHash: string;
|
||||||
denomSig: UnblindedSignature;
|
denomSig: UnblindedSignature;
|
||||||
|
ageCommitmentProof: AgeCommitmentProof | undefined;
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,6 +117,8 @@ interface CoinInfo {
|
|||||||
denomPubHash: string;
|
denomPubHash: string;
|
||||||
|
|
||||||
denomSig: UnblindedSignature;
|
denomSig: UnblindedSignature;
|
||||||
|
|
||||||
|
ageCommitmentProof: AgeCommitmentProof | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function selectPeerCoins(
|
export async function selectPeerCoins(
|
||||||
@ -152,6 +156,7 @@ export async function selectPeerCoins(
|
|||||||
denomPubHash: denom.denomPubHash,
|
denomPubHash: denom.denomPubHash,
|
||||||
coinPriv: coin.coinPriv,
|
coinPriv: coin.coinPriv,
|
||||||
denomSig: coin.denomSig,
|
denomSig: coin.denomSig,
|
||||||
|
ageCommitmentProof: coin.ageCommitmentProof,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (coinInfos.length === 0) {
|
if (coinInfos.length === 0) {
|
||||||
@ -170,6 +175,7 @@ export async function selectPeerCoins(
|
|||||||
contribution: AmountString;
|
contribution: AmountString;
|
||||||
denomPubHash: string;
|
denomPubHash: string;
|
||||||
denomSig: UnblindedSignature;
|
denomSig: UnblindedSignature;
|
||||||
|
ageCommitmentProof: AgeCommitmentProof | undefined;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
for (const coin of coinInfos) {
|
for (const coin of coinInfos) {
|
||||||
if (Amounts.cmp(amountAcc, instructedAmount) >= 0) {
|
if (Amounts.cmp(amountAcc, instructedAmount) >= 0) {
|
||||||
@ -196,6 +202,7 @@ export async function selectPeerCoins(
|
|||||||
contribution: Amounts.stringify(contrib),
|
contribution: Amounts.stringify(contrib),
|
||||||
denomPubHash: coin.denomPubHash,
|
denomPubHash: coin.denomPubHash,
|
||||||
denomSig: coin.denomSig,
|
denomSig: coin.denomSig,
|
||||||
|
ageCommitmentProof: coin.ageCommitmentProof,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -257,6 +264,7 @@ export async function initiatePeerToPeerPush(
|
|||||||
coin.currentAmount,
|
coin.currentAmount,
|
||||||
Amounts.parseOrThrow(c.contribution),
|
Amounts.parseOrThrow(c.contribution),
|
||||||
).amount;
|
).amount;
|
||||||
|
coin.status = CoinStatus.Dormant;
|
||||||
await tx.coins.put(coin);
|
await tx.coins.put(coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +287,7 @@ export async function initiatePeerToPeerPush(
|
|||||||
|
|
||||||
return sel;
|
return sel;
|
||||||
});
|
});
|
||||||
logger.info(`selected p2p coins: ${j2s(coinSelRes)}`);
|
logger.info(`selected p2p coins (push): ${j2s(coinSelRes)}`);
|
||||||
|
|
||||||
if (!coinSelRes) {
|
if (!coinSelRes) {
|
||||||
throw Error("insufficient balance");
|
throw Error("insufficient balance");
|
||||||
@ -592,6 +600,7 @@ export async function acceptPeerPullPayment(
|
|||||||
coin.currentAmount,
|
coin.currentAmount,
|
||||||
Amounts.parseOrThrow(c.contribution),
|
Amounts.parseOrThrow(c.contribution),
|
||||||
).amount;
|
).amount;
|
||||||
|
coin.status = CoinStatus.Dormant;
|
||||||
await tx.coins.put(coin);
|
await tx.coins.put(coin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,7 +617,7 @@ export async function acceptPeerPullPayment(
|
|||||||
|
|
||||||
return sel;
|
return sel;
|
||||||
});
|
});
|
||||||
logger.info(`selected p2p coins: ${j2s(coinSelRes)}`);
|
logger.info(`selected p2p coins (pull): ${j2s(coinSelRes)}`);
|
||||||
|
|
||||||
if (!coinSelRes) {
|
if (!coinSelRes) {
|
||||||
throw Error("insufficient balance");
|
throw Error("insufficient balance");
|
||||||
|
Loading…
Reference in New Issue
Block a user