summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-11-08 13:00:34 -0300
committerSebastian <sebasjm@gmail.com>2022-11-08 13:00:34 -0300
commit5c742afbdf9aaa767c3e4617c48a98439e400fa2 (patch)
tree336aa5fc9bc02879e989aef4fe2a82a7b167ef8d /packages/taler-wallet-core/src
parent43c7cff75055f72c7d59a7180ae8da2554456d8d (diff)
downloadwallet-core-5c742afbdf9aaa767c3e4617c48a98439e400fa2.tar.gz
wallet-core-5c742afbdf9aaa767c3e4617c48a98439e400fa2.tar.bz2
wallet-core-5c742afbdf9aaa767c3e4617c48a98439e400fa2.zip
feature: 7440 add expiration to p2p
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r--packages/taler-wallet-core/src/crypto/workers/synchronousWorkerFactory.ts1
-rw-r--r--packages/taler-wallet-core/src/operations/backup/import.ts4
-rw-r--r--packages/taler-wallet-core/src/operations/pay-merchant.ts6
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer.ts69
-rw-r--r--packages/taler-wallet-core/src/wallet-api-types.ts26
-rw-r--r--packages/taler-wallet-core/src/wallet.ts22
6 files changed, 88 insertions, 40 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/synchronousWorkerFactory.ts b/packages/taler-wallet-core/src/crypto/workers/synchronousWorkerFactory.ts
index 6ce21572e..e9d67eec6 100644
--- a/packages/taler-wallet-core/src/crypto/workers/synchronousWorkerFactory.ts
+++ b/packages/taler-wallet-core/src/crypto/workers/synchronousWorkerFactory.ts
@@ -27,7 +27,6 @@ import { SynchronousCryptoWorker } from "./synchronousWorkerNode.js";
*/
export class SynchronousCryptoWorkerFactory implements CryptoWorkerFactory {
startWorker(): CryptoWorker {
-
return new SynchronousCryptoWorker();
}
diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts
index 3159c60af..5fd220113 100644
--- a/packages/taler-wallet-core/src/operations/backup/import.ts
+++ b/packages/taler-wallet-core/src/operations/backup/import.ts
@@ -26,7 +26,7 @@ import {
BackupRefreshReason,
BackupRefundState,
BackupWgType,
- codecForContractTerms,
+ codecForMerchantContractTerms,
CoinStatus,
DenomKeyType,
DenomSelectionState,
@@ -638,7 +638,7 @@ export async function importBackup(
break;
}
}
- const parsedContractTerms = codecForContractTerms().decode(
+ const parsedContractTerms = codecForMerchantContractTerms().decode(
backupPurchase.contract_terms_raw,
);
const amount = Amounts.parseOrThrow(parsedContractTerms.amount);
diff --git a/packages/taler-wallet-core/src/operations/pay-merchant.ts b/packages/taler-wallet-core/src/operations/pay-merchant.ts
index 4483a57c0..bb391d468 100644
--- a/packages/taler-wallet-core/src/operations/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/operations/pay-merchant.ts
@@ -34,7 +34,7 @@ import {
Amounts,
ApplyRefundResponse,
codecForAbortResponse,
- codecForContractTerms,
+ codecForMerchantContractTerms,
codecForMerchantOrderRefundPickupResponse,
codecForMerchantOrderStatusPaid,
codecForMerchantPayResponse,
@@ -456,7 +456,7 @@ export async function processDownloadProposal(
let parsedContractTerms: MerchantContractTerms;
try {
- parsedContractTerms = codecForContractTerms().decode(
+ parsedContractTerms = codecForMerchantContractTerms().decode(
proposalResp.contract_terms,
);
} catch (e) {
@@ -1584,7 +1584,7 @@ export async function runPayForConfirmPay(
const numRetry = opRetry?.retryInfo.retryCounter ?? 0;
if (
res.errorDetail.code ===
- TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR &&
+ TalerErrorCode.WALLET_PAY_MERCHANT_SERVER_ERROR &&
numRetry < maxRetry
) {
// Pretend the operation is pending instead of reporting
diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts
index b6acef2dc..f31a7f37c 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer.ts
@@ -57,6 +57,10 @@ import {
parsePayPullUri,
parsePayPushUri,
PeerContractTerms,
+ PreparePeerPullPaymentRequest,
+ PreparePeerPullPaymentResponse,
+ PreparePeerPushPaymentRequest,
+ PreparePeerPushPaymentResponse,
RefreshReason,
strcmp,
TalerProtocolTimestamp,
@@ -218,28 +222,30 @@ export async function selectPeerCoins(
return undefined;
}
+export async function preparePeerPushPayment(
+ ws: InternalWalletState,
+ req: PreparePeerPushPaymentRequest,
+): Promise<PreparePeerPushPaymentResponse> {
+ // FIXME: look up for the exchange and calculate fee
+ return {
+ amountEffective: req.amount,
+ amountRaw: req.amount,
+ };
+}
+
export async function initiatePeerToPeerPush(
ws: InternalWalletState,
req: InitiatePeerPushPaymentRequest,
): Promise<InitiatePeerPushPaymentResponse> {
- const instructedAmount = Amounts.parseOrThrow(req.amount);
+ const instructedAmount = Amounts.parseOrThrow(
+ req.partialContractTerms.amount,
+ );
+ const purseExpiration = req.partialContractTerms.purse_expiration;
+ const contractTerms = req.partialContractTerms;
const pursePair = await ws.cryptoApi.createEddsaKeypair({});
const mergePair = await ws.cryptoApi.createEddsaKeypair({});
- const purseExpiration: TalerProtocolTimestamp = AbsoluteTime.toTimestamp(
- AbsoluteTime.addDuration(
- AbsoluteTime.now(),
- Duration.fromSpec({ days: 2 }),
- ),
- );
-
- const contractTerms = {
- ...req.partialContractTerms,
- purse_expiration: purseExpiration,
- amount: req.amount,
- };
-
const hContractTerms = ContractTermsUtil.hashContractTerms(contractTerms);
const econtractResp = await ws.cryptoApi.encryptContractForMerge({
@@ -751,6 +757,16 @@ export async function checkPeerPullPayment(
};
}
+export async function preparePeerPullPayment(
+ ws: InternalWalletState,
+ req: PreparePeerPullPaymentRequest,
+): Promise<PreparePeerPullPaymentResponse> {
+ //FIXME: look up for exchange details and use purse fee
+ return {
+ amountEffective: req.amount,
+ amountRaw: req.amount,
+ };
+}
/**
* Initiate a peer pull payment.
*/
@@ -769,24 +785,17 @@ export async function initiatePeerPullPayment(
const pursePair = await ws.cryptoApi.createEddsaKeypair({});
const mergePair = await ws.cryptoApi.createEddsaKeypair({});
- const purseExpiration: TalerProtocolTimestamp = AbsoluteTime.toTimestamp(
- AbsoluteTime.addDuration(
- AbsoluteTime.now(),
- Duration.fromSpec({ days: 2 }),
- ),
+ const instructedAmount = Amounts.parseOrThrow(
+ req.partialContractTerms.amount,
);
+ const purseExpiration = req.partialContractTerms.purse_expiration;
+ const contractTerms = req.partialContractTerms;
const reservePayto = talerPaytoFromExchangeReserve(
req.exchangeBaseUrl,
mergeReserveInfo.reservePub,
);
- const contractTerms = {
- ...req.partialContractTerms,
- amount: req.amount,
- purse_expiration: purseExpiration,
- };
-
const econtractResp = await ws.cryptoApi.encryptContractForDeposit({
contractTerms,
pursePriv: pursePair.priv,
@@ -796,7 +805,7 @@ export async function initiatePeerPullPayment(
const hContractTerms = ContractTermsUtil.hashContractTerms(contractTerms);
const purseFee = Amounts.stringify(
- Amounts.zeroOfCurrency(Amounts.parseOrThrow(req.amount).currency),
+ Amounts.zeroOfCurrency(instructedAmount.currency),
);
const sigRes = await ws.cryptoApi.signReservePurseCreate({
@@ -804,7 +813,7 @@ export async function initiatePeerPullPayment(
flags: WalletAccountMergeFlags.CreateWithPurseFee,
mergePriv: mergePair.priv,
mergeTimestamp: mergeTimestamp,
- purseAmount: req.amount,
+ purseAmount: req.partialContractTerms.amount,
purseExpiration: purseExpiration,
purseFee: purseFee,
pursePriv: pursePair.priv,
@@ -817,7 +826,7 @@ export async function initiatePeerPullPayment(
.mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms])
.runReadWrite(async (tx) => {
await tx.peerPullPaymentInitiations.put({
- amount: req.amount,
+ amount: req.partialContractTerms.amount,
contractTermsHash: hContractTerms,
exchangeBaseUrl: req.exchangeBaseUrl,
pursePriv: pursePair.priv,
@@ -840,7 +849,7 @@ export async function initiatePeerPullPayment(
purse_fee: purseFee,
purse_pub: pursePair.pub,
purse_sig: sigRes.purseSig,
- purse_value: req.amount,
+ purse_value: req.partialContractTerms.amount,
reserve_sig: sigRes.accountSig,
econtract: econtractResp.econtract,
};
@@ -862,7 +871,7 @@ export async function initiatePeerPullPayment(
logger.info(`reserve merge response: ${j2s(resp)}`);
const wg = await internalCreateWithdrawalGroup(ws, {
- amount: Amounts.parseOrThrow(req.amount),
+ amount: instructedAmount,
wgInfo: {
withdrawalType: WithdrawalRecordType.PeerPullCredit,
contractTerms,
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
index e36e630f4..b7d0ada3d 100644
--- a/packages/taler-wallet-core/src/wallet-api-types.ts
+++ b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -75,6 +75,10 @@ import {
PrepareDepositResponse,
PreparePayRequest,
PreparePayResult,
+ PreparePeerPullPaymentRequest,
+ PreparePeerPullPaymentResponse,
+ PreparePeerPushPaymentRequest,
+ PreparePeerPushPaymentResponse,
PrepareRefundRequest,
PrepareRefundResult,
PrepareTipRequest,
@@ -164,9 +168,11 @@ export enum WalletApiOperation {
WithdrawFakebank = "withdrawFakebank",
ImportDb = "importDb",
ExportDb = "exportDb",
+ PreparePeerPushPayment = "preparePeerPushPayment",
InitiatePeerPushPayment = "initiatePeerPushPayment",
CheckPeerPushPayment = "checkPeerPushPayment",
AcceptPeerPushPayment = "acceptPeerPushPayment",
+ PreparePeerPullPayment = "preparePeerPullPayment",
InitiatePeerPullPayment = "initiatePeerPullPayment",
CheckPeerPullPayment = "checkPeerPullPayment",
AcceptPeerPullPayment = "acceptPeerPullPayment",
@@ -556,6 +562,15 @@ export type ExportBackupPlainOp = {
/**
* Initiate an outgoing peer push payment.
*/
+export type PreparePeerPushPaymentOp = {
+ op: WalletApiOperation.PreparePeerPushPayment;
+ request: PreparePeerPushPaymentRequest;
+ response: PreparePeerPushPaymentResponse;
+};
+
+/**
+ * Initiate an outgoing peer push payment.
+ */
export type InitiatePeerPushPaymentOp = {
op: WalletApiOperation.InitiatePeerPushPayment;
request: InitiatePeerPushPaymentRequest;
@@ -583,6 +598,15 @@ export type AcceptPeerPushPaymentOp = {
/**
* Initiate an outgoing peer pull payment.
*/
+export type PreparePeerPullPaymentOp = {
+ op: WalletApiOperation.PreparePeerPullPayment;
+ request: PreparePeerPullPaymentRequest;
+ response: PreparePeerPullPaymentResponse;
+};
+
+/**
+ * Initiate an outgoing peer pull payment.
+ */
export type InitiatePeerPullPaymentOp = {
op: WalletApiOperation.InitiatePeerPullPayment;
request: InitiatePeerPullPaymentRequest;
@@ -815,9 +839,11 @@ export type WalletOperations = {
[WalletApiOperation.TestPay]: TestPayOp;
[WalletApiOperation.ExportDb]: ExportDbOp;
[WalletApiOperation.ImportDb]: ImportDbOp;
+ [WalletApiOperation.PreparePeerPushPayment]: PreparePeerPushPaymentOp;
[WalletApiOperation.InitiatePeerPushPayment]: InitiatePeerPushPaymentOp;
[WalletApiOperation.CheckPeerPushPayment]: CheckPeerPushPaymentOp;
[WalletApiOperation.AcceptPeerPushPayment]: AcceptPeerPushPaymentOp;
+ [WalletApiOperation.PreparePeerPullPayment]: PreparePeerPullPaymentOp;
[WalletApiOperation.InitiatePeerPullPayment]: InitiatePeerPullPaymentOp;
[WalletApiOperation.CheckPeerPullPayment]: CheckPeerPullPaymentOp;
[WalletApiOperation.AcceptPeerPullPayment]: AcceptPeerPullPaymentOp;
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 9339b2f8e..caaf6d410 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -57,6 +57,8 @@ import {
codecForListKnownBankAccounts,
codecForPrepareDepositRequest,
codecForPreparePayRequest,
+ codecForPreparePeerPullPaymentRequest,
+ codecForPreparePeerPushPaymentRequest,
codecForPrepareRefundRequest,
codecForPrepareTipRequest,
codecForRetryTransactionRequest,
@@ -186,6 +188,8 @@ import {
checkPeerPushPayment,
initiatePeerPullPayment,
initiatePeerToPeerPush,
+ preparePeerPullPayment,
+ preparePeerPushPayment,
} from "./operations/pay-peer.js";
import { getPendingOperations } from "./operations/pending.js";
import {
@@ -659,7 +663,9 @@ async function getExchanges(
const opRetryRecord = await tx.operationRetries.get(
RetryTags.forExchangeUpdate(r),
);
- exchanges.push(makeExchangeListItem(r, exchangeDetails, opRetryRecord?.lastError));
+ exchanges.push(
+ makeExchangeListItem(r, exchangeDetails, opRetryRecord?.lastError),
+ );
}
});
return { exchanges };
@@ -927,9 +933,9 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> {
ageCommitmentProof: c.ageCommitmentProof,
spend_allocation: c.spendAllocation
? {
- amount: c.spendAllocation.amount,
- id: c.spendAllocation.id,
- }
+ amount: c.spendAllocation.amount,
+ id: c.spendAllocation.id,
+ }
: undefined,
});
}
@@ -1340,6 +1346,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
await importDb(ws.db.idbHandle(), req.dump);
return [];
}
+ case WalletApiOperation.PreparePeerPushPayment: {
+ const req = codecForPreparePeerPushPaymentRequest().decode(payload);
+ return await preparePeerPushPayment(ws, req);
+ }
case WalletApiOperation.InitiatePeerPushPayment: {
const req = codecForInitiatePeerPushPaymentRequest().decode(payload);
return await initiatePeerToPeerPush(ws, req);
@@ -1352,6 +1362,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
const req = codecForAcceptPeerPushPaymentRequest().decode(payload);
return await acceptPeerPushPayment(ws, req);
}
+ case WalletApiOperation.PreparePeerPullPayment: {
+ const req = codecForPreparePeerPullPaymentRequest().decode(payload);
+ return await preparePeerPullPayment(ws, req);
+ }
case WalletApiOperation.InitiatePeerPullPayment: {
const req = codecForInitiatePeerPullPaymentRequest().decode(payload);
return await initiatePeerPullPayment(ws, req);