From 84d5b5e5ef34f7289256c6fd301206cda19be694 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 17 Dec 2020 12:21:03 +0100 Subject: export complete backup, derive planchets in withdrawal --- .../taler-wallet-core/src/operations/backup.ts | 44 +++++++++++++++------- .../taler-wallet-core/src/operations/reserves.ts | 1 + packages/taler-wallet-core/src/operations/tip.ts | 8 ++-- .../taler-wallet-core/src/operations/withdraw.ts | 2 + 4 files changed, 39 insertions(+), 16 deletions(-) (limited to 'packages/taler-wallet-core/src/operations') diff --git a/packages/taler-wallet-core/src/operations/backup.ts b/packages/taler-wallet-core/src/operations/backup.ts index 1e5aa542d..f071b6d08 100644 --- a/packages/taler-wallet-core/src/operations/backup.ts +++ b/packages/taler-wallet-core/src/operations/backup.ts @@ -198,17 +198,17 @@ export async function exportBackup( const withdrawalGroups = (withdrawalGroupsByReserve[ wg.reservePub ] ??= []); - // FIXME: finish! - // withdrawalGroups.push({ - // raw_withdrawal_amount: Amounts.stringify(wg.rawWithdrawalAmount), - // selected_denoms: wg.denomsSel.selectedDenoms.map((x) => ({ - // count: x.count, - // denom_pub_hash: x.denomPubHash, - // })), - // timestamp_start: wg.timestampStart, - // timestamp_finish: wg.timestampFinish, - // withdrawal_group_id: wg.withdrawalGroupId, - // }); + withdrawalGroups.push({ + raw_withdrawal_amount: Amounts.stringify(wg.rawWithdrawalAmount), + selected_denoms: wg.denomsSel.selectedDenoms.map((x) => ({ + count: x.count, + denom_pub_hash: x.denomPubHash, + })), + timestamp_start: wg.timestampStart, + timestamp_finish: wg.timestampFinish, + withdrawal_group_id: wg.withdrawalGroupId, + secret_seed: wg.secretSeed + }); }); await tx.iter(Stores.reserves).forEach((reserve) => { @@ -572,11 +572,29 @@ export async function encryptBackup( throw Error("not implemented"); } -export function importBackup( +export async function importBackup( ws: InternalWalletState, backupRequest: BackupRequest, ): Promise { - throw Error("not implemented"); + await provideBackupState(ws); + return ws.db.runWithWriteTransaction( + [ + Stores.config, + Stores.exchanges, + Stores.coins, + Stores.denominations, + Stores.purchases, + Stores.proposals, + Stores.refreshGroups, + Stores.backupProviders, + Stores.tips, + Stores.recoupGroups, + Stores.reserves, + Stores.withdrawalGroups, + ], + async (tx) => { + + }); } function deriveAccountKeyPair( diff --git a/packages/taler-wallet-core/src/operations/reserves.ts b/packages/taler-wallet-core/src/operations/reserves.ts index 95c38120c..4e4db1fc9 100644 --- a/packages/taler-wallet-core/src/operations/reserves.ts +++ b/packages/taler-wallet-core/src/operations/reserves.ts @@ -623,6 +623,7 @@ async function updateReserve( retryInfo: initRetryInfo(), lastError: undefined, denomsSel: denomSelectionInfoToState(denomSelInfo), + secretSeed: encodeCrock(getRandomBytes(64)), }; newReserve.lastError = undefined; diff --git a/packages/taler-wallet-core/src/operations/tip.ts b/packages/taler-wallet-core/src/operations/tip.ts index f47f76623..f683999bc 100644 --- a/packages/taler-wallet-core/src/operations/tip.ts +++ b/packages/taler-wallet-core/src/operations/tip.ts @@ -48,7 +48,7 @@ import { } from "../util/http"; import { URL } from "../util/url"; import { Logger } from "../util/logging"; -import { checkDbInvariant } from "../util/invariants"; +import { checkDbInvariant, checkLogicInvariant } from "../util/invariants"; import { TalerErrorCode } from "../TalerErrorCode"; import { initRetryInfo, updateRetryInfoTimeout } from "../util/retries"; import { j2s } from "../util/helpers"; @@ -221,13 +221,13 @@ async function processTipImpl( dh.denomPubHash, ]); checkDbInvariant(!!denom, "denomination should be in database"); - denomForPlanchet[planchets.length] = denom; for (let i = 0; i < dh.count; i++) { const p = await ws.cryptoApi.createTipPlanchet({ - denomPub: dh.denomPubHash, + denomPub: denom.denomPub, planchetIndex: planchets.length, secretSeed: tipRecord.secretSeed, }); + denomForPlanchet[planchets.length] = denom; planchets.push(p); planchetsDetail.push({ coin_ev: p.coinEv, @@ -275,7 +275,9 @@ async function processTipImpl( const blindedSig = response.blind_sigs[i].blind_sig; const denom = denomForPlanchet[i]; + checkLogicInvariant(!!denom); const planchet = planchets[i]; + checkLogicInvariant(!!planchet); const denomSig = await ws.cryptoApi.rsaUnblind( blindedSig, diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 758b80787..c2dfcd1c4 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -284,6 +284,8 @@ async function processPlanchetGenerate( reservePriv: reserve.reservePriv, reservePub: reserve.reservePub, value: denom.value, + coinIndex: coinIdx, + secretSeed: withdrawalGroup.secretSeed, }); const newPlanchet: PlanchetRecord = { blindingKey: r.blindingKey, -- cgit v1.2.3