diff options
| author | Florian Dold <florian@dold.me> | 2021-08-24 15:43:06 +0200 | 
|---|---|---|
| committer | Florian Dold <florian@dold.me> | 2021-08-24 15:43:06 +0200 | 
| commit | 4c41e705658cbae6e4558bf29edeb39f474c244a (patch) | |
| tree | 6e598a6fd1ead8972c0b6cf551c3f3cb8293aec0 /packages/taler-wallet-core/src | |
| parent | a09359bd3930f2a4550de22bd018122a2c7846e6 (diff) | |
DB schema cleanup
Diffstat (limited to 'packages/taler-wallet-core/src')
8 files changed, 69 insertions, 77 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts b/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts index 61134ef6b..e1580a7d1 100644 --- a/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts +++ b/packages/taler-wallet-core/src/crypto/workers/cryptoImplementation.ts @@ -30,12 +30,11 @@  import {    CoinRecord,    DenominationRecord, -  RefreshPlanchet,    WireFee,    CoinSourceType,  } from "../../db.js"; -import { CoinDepositPermission, RecoupRequest } from "@gnu-taler/taler-util"; +import { CoinDepositPermission, RecoupRequest, RefreshPlanchetInfo } from "@gnu-taler/taler-util";  // FIXME: These types should be internal to the wallet!  import {    BenchmarkResult, @@ -442,7 +441,7 @@ export class CryptoImplementation {      const transferPubs: string[] = [];      const transferPrivs: string[] = []; -    const planchetsForGammas: RefreshPlanchet[][] = []; +    const planchetsForGammas: RefreshPlanchetInfo[][] = [];      for (let i = 0; i < kappa; i++) {        const transferKeyPair = setupRefreshTransferPub( @@ -464,7 +463,7 @@ export class CryptoImplementation {      sessionHc.update(decodeCrock(meltCoinPub));      sessionHc.update(amountToBuffer(valueWithFee));      for (let i = 0; i < kappa; i++) { -      const planchets: RefreshPlanchet[] = []; +      const planchets: RefreshPlanchetInfo[] = [];        for (let j = 0; j < newCoinDenoms.length; j++) {          const denomSel = newCoinDenoms[j];          for (let k = 0; k < denomSel.count; k++) { @@ -482,7 +481,7 @@ export class CryptoImplementation {            const pubHash = hash(coinPub);            const denomPub = decodeCrock(denomSel.denomPub);            const ev = rsaBlind(pubHash, blindingFactor, denomPub); -          const planchet: RefreshPlanchet = { +          const planchet: RefreshPlanchetInfo = {              blindingKey: encodeCrock(blindingFactor),              coinEv: encodeCrock(ev),              privateKey: encodeCrock(coinPriv), diff --git a/packages/taler-wallet-core/src/db-utils.ts b/packages/taler-wallet-core/src/db-utils.ts index 424d12b84..849dcfd15 100644 --- a/packages/taler-wallet-core/src/db-utils.ts +++ b/packages/taler-wallet-core/src/db-utils.ts @@ -134,8 +134,27 @@ export async function openTalerDatabase(      });    if (currentMainVersion !== TALER_DB_NAME) { -    // In the future, the migration logic will be implemented here. -    throw Error(`migration from database ${currentMainVersion} not supported`); +    switch (currentMainVersion) { +      case "taler-wallet-main-v2": { +        // We consider this a pre-release +        // development version, no migration is done. +        await metaDb +          .mktx((x) => ({ +            metaConfig: x.metaConfig, +          })) +          .runReadWrite(async (tx) => { +            await tx.metaConfig.put({ +              key: CURRENT_DB_CONFIG_KEY, +              value: TALER_DB_NAME, +            }); +          }); +        break; +      } +      default: +        throw Error( +          `migration from database ${currentMainVersion} not supported`, +        ); +    }    }    const mainDbHandle = await openDatabase( diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 66d79ebc0..7ea8b9ead 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -46,7 +46,7 @@ import { PayCoinSelection } from "./util/coinSelection.js";   * for all previous versions must be written, which should be   * avoided.   */ -export const TALER_DB_NAME = "taler-wallet-main-v2"; +export const TALER_DB_NAME = "taler-wallet-main-v3";  /**   * Name of the metadata database.  This database is used @@ -283,7 +283,7 @@ export interface ExchangeTrustRecord {  /**   * Status of a denomination.   */ -export enum DenominationStatus { +export enum DenominationVerificationStatus {    /**     * Verification was delayed.     */ @@ -366,10 +366,8 @@ export interface DenominationRecord {    /**     * Did we verify the signature on the denomination? -   * -   * FIXME:  Rename to "verificationStatus"?     */ -  status: DenominationStatus; +  verificationStatus: DenominationVerificationStatus;    /**     * Was this denomination still offered by the exchange the last time @@ -591,35 +589,6 @@ export interface PlanchetRecord {  }  /** - * Planchet for a coin during refresh. - * - * FIXME:  Not used in DB? - */ -export interface RefreshPlanchet { -  /** -   * Public key for the coin. -   */ -  publicKey: string; - -  /** -   * Private key for the coin. -   */ -  privateKey: string; - -  /** -   * Blinded public key. -   */ -  coinEv: string; - -  coinEvHash: string; - -  /** -   * Blinding key used. -   */ -  blindingKey: string; -} - -/**   * Status of a coin.   */  export enum CoinStatus { @@ -1320,21 +1289,6 @@ export interface WalletBackupConfState {  }  /** - * FIXME: Eliminate this in favor of DenomSelectionState. - */ -export interface DenominationSelectionInfo { -  totalCoinValue: AmountJson; -  totalWithdrawCost: AmountJson; -  selectedDenoms: { -    /** -     * How many times do we withdraw this denomination? -     */ -    count: number; -    denom: DenominationRecord; -  }[]; -} - -/**   * Selected denominations withn some extra info.   */  export interface DenomSelectionState { diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index a694d9f4d..9eee34cf0 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -31,7 +31,7 @@ import {  import {    WalletContractData,    DenomSelectionState, -  DenominationStatus, +  DenominationVerificationStatus,    CoinSource,    CoinSourceType,    CoinStatus, @@ -359,7 +359,7 @@ export async function importBackup(                stampExpireLegal: backupDenomination.stamp_expire_legal,                stampExpireWithdraw: backupDenomination.stamp_expire_withdraw,                stampStart: backupDenomination.stamp_start, -              status: DenominationStatus.VerifiedGood, +              verificationStatus: DenominationVerificationStatus.VerifiedGood,                value: Amounts.parseOrThrow(backupDenomination.value),                listIssueDate: backupDenomination.list_issue_date,              }); diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index 23459de92..cf52e00b6 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -44,7 +44,7 @@ import { decodeCrock, encodeCrock, hash } from "../crypto/talerCrypto.js";  import { CryptoApi } from "../crypto/workers/cryptoApi.js";  import {    DenominationRecord, -  DenominationStatus, +  DenominationVerificationStatus,    ExchangeDetailsRecord,    ExchangeRecord,    WalletStoresV1, @@ -95,7 +95,7 @@ function denominationRecordFromKeys(      stampExpireLegal: denomIn.stamp_expire_legal,      stampExpireWithdraw: denomIn.stamp_expire_withdraw,      stampStart: denomIn.stamp_start, -    status: DenominationStatus.Unverified, +    verificationStatus: DenominationVerificationStatus.Unverified,      value: Amounts.parseOrThrow(denomIn.value),      listIssueDate,    }; diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 8926559e3..a7b64f5d3 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -22,7 +22,6 @@ import {    DenominationRecord,    RefreshCoinStatus,    RefreshGroupRecord, -  RefreshPlanchet,    WalletStoresV1,  } from "../db.js";  import { @@ -32,6 +31,7 @@ import {    fnutil,    NotificationType,    RefreshGroupId, +  RefreshPlanchetInfo,    RefreshReason,    stringifyTimestamp,    TalerErrorDetails, @@ -534,7 +534,7 @@ async function refreshReveal(      throw Error("refresh index error");    } -  const evs = planchets.map((x: RefreshPlanchet) => x.coinEv); +  const evs = planchets.map((x: RefreshPlanchetInfo) => x.coinEv);    const newDenomsFlat: string[] = [];    const linkSigs: string[] = []; diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts index 061a42227..b4f0d35e6 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.test.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts @@ -16,7 +16,7 @@  import { Amounts } from "@gnu-taler/taler-util";  import test from "ava"; -import { DenominationRecord, DenominationStatus } from "../db.js"; +import { DenominationRecord, DenominationVerificationStatus } from "../db.js";  import { selectWithdrawalDenominations } from "./withdraw.js";  test("withdrawal selection bug repro", (t) => { @@ -70,7 +70,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 0, @@ -121,7 +121,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 0, @@ -172,7 +172,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 0, @@ -223,7 +223,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 0, @@ -274,7 +274,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 10000000, @@ -325,7 +325,7 @@ test("withdrawal selection bug repro", (t) => {        stampStart: {          t_ms: 1585229388000,        }, -      status: DenominationStatus.Unverified, +      verificationStatus: DenominationVerificationStatus.Unverified,        value: {          currency: "KUDOS",          fraction: 0, diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 521cfa113..e6b6e8746 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -47,8 +47,7 @@ import {    CoinSourceType,    CoinStatus,    DenominationRecord, -  DenominationSelectionInfo, -  DenominationStatus, +  DenominationVerificationStatus,    DenomSelectionState,    ExchangeDetailsRecord,    ExchangeRecord, @@ -74,6 +73,21 @@ import {  const logger = new Logger("withdraw.ts");  /** + * FIXME: Eliminate this in favor of DenomSelectionState. + */ +interface DenominationSelectionInfo { +  totalCoinValue: AmountJson; +  totalWithdrawCost: AmountJson; +  selectedDenoms: { +    /** +     * How many times do we withdraw this denomination? +     */ +    count: number; +    denom: DenominationRecord; +  }[]; +} + +/**   * Information about what will happen when creating a reserve.   *   * Sent to the wallet frontend to be rendered and shown to the user. @@ -231,9 +245,13 @@ export function selectWithdrawalDenominations(    }    if (logger.shouldLogTrace()) { -    logger.trace(`selected withdrawal denoms for ${Amounts.stringify(totalCoinValue)}`); +    logger.trace( +      `selected withdrawal denoms for ${Amounts.stringify(totalCoinValue)}`, +    );      for (const sd of selectedDenoms) { -      logger.trace(`denom_pub_hash=${sd.denom.denomPubHash}, count=${sd.count}`); +      logger.trace( +        `denom_pub_hash=${sd.denom.denomPubHash}, count=${sd.count}`, +      );      }      logger.trace("(end of withdrawal denom list)");    } @@ -314,7 +332,9 @@ export async function getCandidateWithdrawalDenoms(    return await ws.db      .mktx((x) => ({ denominations: x.denominations }))      .runReadOnly(async (tx) => { -      const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl.getAll(exchangeBaseUrl); +      const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl.getAll( +        exchangeBaseUrl, +      );        return allDenoms.filter(isWithdrawableDenom);      });  } @@ -708,7 +728,7 @@ export async function updateWithdrawalDenoms(        batchIdx++, current++      ) {        const denom = denominations[current]; -      if (denom.status === DenominationStatus.Unverified) { +      if (denom.verificationStatus === DenominationVerificationStatus.Unverified) {          logger.trace(            `Validating denomination (${current + 1}/${              denominations.length @@ -723,9 +743,9 @@ export async function updateWithdrawalDenoms(            logger.warn(              `Signature check for denomination h=${denom.denomPubHash} failed`,            ); -          denom.status = DenominationStatus.VerifiedBad; +          denom.verificationStatus = DenominationVerificationStatus.VerifiedBad;          } else { -          denom.status = DenominationStatus.VerifiedGood; +          denom.verificationStatus = DenominationVerificationStatus.VerifiedGood;          }          updatedDenominations.push(denom);        }  | 
