diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/backup')
3 files changed, 30 insertions, 31 deletions
diff --git a/packages/taler-wallet-core/src/operations/backup/export.ts b/packages/taler-wallet-core/src/operations/backup/export.ts index 12b309418..35306da63 100644 --- a/packages/taler-wallet-core/src/operations/backup/export.ts +++ b/packages/taler-wallet-core/src/operations/backup/export.ts @@ -49,14 +49,13 @@ import {    BackupWithdrawalGroup,    canonicalizeBaseUrl,    canonicalJson, -  getTimestampNow,    Logger, -  timestampToIsoString,    WalletBackupContentV1,    hash,    encodeCrock,    getRandomBytes,    stringToBytes, +  AbsoluteTime,  } from "@gnu-taler/taler-util";  import { InternalWalletState } from "../../common.js";  import { @@ -455,7 +454,7 @@ export async function exportBackup(          });        }); -      const ts = getTimestampNow(); +      const ts = AbsoluteTime.toTimestamp(AbsoluteTime.now());        if (!bs.lastBackupTimestamp) {          bs.lastBackupTimestamp = ts; @@ -496,9 +495,9 @@ export async function exportBackup(          );          bs.lastBackupNonce = encodeCrock(getRandomBytes(32));          logger.trace( -          `setting timestamp to ${timestampToIsoString(ts)} and nonce to ${ -            bs.lastBackupNonce -          }`, +          `setting timestamp to ${AbsoluteTime.toIsoString( +            AbsoluteTime.fromTimestamp(ts), +          )} and nonce to ${bs.lastBackupNonce}`,          );          await tx.config.put({            key: WALLET_BACKUP_STATE_KEY, diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index 35b62c2e4..4b17a5f33 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -20,7 +20,6 @@ import {    Amounts,    BackupDenomSel,    WalletBackupContentV1, -  getTimestampNow,    BackupCoinSourceType,    BackupProposalStatus,    codecForContractTerms, @@ -28,6 +27,8 @@ import {    RefreshReason,    BackupRefreshReason,    DenomKeyType, +  AbsoluteTime, +  TalerProtocolTimestamp,  } from "@gnu-taler/taler-util";  import {    WalletContractData, @@ -277,8 +278,8 @@ export async function importBackup(            permanent: true,            retryInfo: initRetryInfo(),            lastUpdate: undefined, -          nextUpdate: getTimestampNow(), -          nextRefreshCheck: getTimestampNow(), +          nextUpdate: TalerProtocolTimestamp.now(), +          nextRefreshCheck: TalerProtocolTimestamp.now(),          });        } @@ -465,7 +466,6 @@ export async function importBackup(                senderWire: backupReserve.sender_wire,                retryInfo: initRetryInfo(),                lastError: undefined, -              lastSuccessfulStatusQuery: { t_ms: "never" },                initialWithdrawalGroupId:                  backupReserve.initial_withdrawal_group_id,                initialWithdrawalStarted: @@ -752,7 +752,7 @@ export async function importBackup(              noncePub:                cryptoComp.proposalNoncePrivToPub[backupPurchase.nonce_priv],              lastPayError: undefined, -            autoRefundDeadline: { t_ms: "never" }, +            autoRefundDeadline: TalerProtocolTimestamp.never(),              refundStatusRetryInfo: initRetryInfo(),              lastRefundStatusError: undefined,              timestampAccept: backupPurchase.timestamp_accept, diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts b/packages/taler-wallet-core/src/operations/backup/index.ts index 2a1a774f1..48eea56ad 100644 --- a/packages/taler-wallet-core/src/operations/backup/index.ts +++ b/packages/taler-wallet-core/src/operations/backup/index.ts @@ -40,21 +40,19 @@ import {    ConfirmPayResultType,    DenomKeyType,    durationFromSpec, -  getTimestampNow,    hashDenomPub,    HttpStatusCode,    j2s, -  LibtoolVersion,    Logger,    notEmpty,    PreparePayResultType,    RecoveryLoadRequest,    RecoveryMergeStrategy,    TalerErrorDetails, -  Timestamp, -  timestampAddDuration, +  AbsoluteTime,    URL,    WalletBackupContentV1, +  TalerProtocolTimestamp,  } from "@gnu-taler/taler-util";  import { gunzipSync, gzipSync } from "fflate";  import { InternalWalletState } from "../../common.js"; @@ -250,11 +248,13 @@ interface BackupForProviderArgs {    retryAfterPayment: boolean;  } -function getNextBackupTimestamp(): Timestamp { +function getNextBackupTimestamp(): TalerProtocolTimestamp {    // FIXME:  Randomize! -  return timestampAddDuration( -    getTimestampNow(), -    durationFromSpec({ minutes: 5 }), +  return AbsoluteTime.toTimestamp( +    AbsoluteTime.addDuration( +      AbsoluteTime.now(), +      durationFromSpec({ minutes: 5 }), +    ),    );  } @@ -324,7 +324,7 @@ async function runBackupCycleForProvider(          if (!prov) {            return;          } -        prov.lastBackupCycleTimestamp = getTimestampNow(); +        prov.lastBackupCycleTimestamp = TalerProtocolTimestamp.now();          prov.state = {            tag: BackupProviderStateTag.Ready,            nextBackupTimestamp: getNextBackupTimestamp(), @@ -404,7 +404,7 @@ async function runBackupCycleForProvider(            return;          }          prov.lastBackupHash = encodeCrock(currentBackupHash); -        prov.lastBackupCycleTimestamp = getTimestampNow(); +        prov.lastBackupCycleTimestamp = TalerProtocolTimestamp.now();          prov.state = {            tag: BackupProviderStateTag.Ready,            nextBackupTimestamp: getNextBackupTimestamp(), @@ -641,7 +641,7 @@ export async function addBackupProvider(          if (req.activate) {            oldProv.state = {              tag: BackupProviderStateTag.Ready, -            nextBackupTimestamp: getTimestampNow(), +            nextBackupTimestamp: TalerProtocolTimestamp.now(),            };            logger.info("setting existing backup provider to active");            await tx.backupProviders.put(oldProv); @@ -662,7 +662,7 @@ export async function addBackupProvider(        if (req.activate) {          state = {            tag: BackupProviderStateTag.Ready, -          nextBackupTimestamp: getTimestampNow(), +          nextBackupTimestamp: TalerProtocolTimestamp.now(),          };        } else {          state = { @@ -701,8 +701,8 @@ export interface ProviderInfo {     * Last communication issue with the provider.     */    lastError?: TalerErrorDetails; -  lastSuccessfulBackupTimestamp?: Timestamp; -  lastAttemptedBackupTimestamp?: Timestamp; +  lastSuccessfulBackupTimestamp?: TalerProtocolTimestamp; +  lastAttemptedBackupTimestamp?: TalerProtocolTimestamp;    paymentProposalIds: string[];    backupProblem?: BackupProblem;    paymentStatus: ProviderPaymentStatus; @@ -724,7 +724,7 @@ export interface BackupConflictingDeviceProblem {    type: "backup-conflicting-device";    otherDeviceId: string;    myDeviceId: string; -  backupTimestamp: Timestamp; +  backupTimestamp: AbsoluteTime;  }  export type ProviderPaymentStatus = @@ -774,12 +774,12 @@ export interface ProviderPaymentPending {  export interface ProviderPaymentPaid {    type: ProviderPaymentType.Paid; -  paidUntil: Timestamp; +  paidUntil: AbsoluteTime;  }  export interface ProviderPaymentTermsChanged {    type: ProviderPaymentType.TermsChanged; -  paidUntil: Timestamp; +  paidUntil: AbsoluteTime;    oldTerms: BackupProviderTerms;    newTerms: BackupProviderTerms;  } @@ -811,8 +811,8 @@ async function getProviderPaymentInfo(      if (status.paid) {        return {          type: ProviderPaymentType.Paid, -        paidUntil: timestampAddDuration( -          status.contractTerms.timestamp, +        paidUntil: AbsoluteTime.addDuration( +          AbsoluteTime.fromTimestamp(status.contractTerms.timestamp),            durationFromSpec({ years: 1 }),          ),        }; @@ -915,7 +915,7 @@ async function backupRecoveryTheirs(              paymentProposalIds: [],              state: {                tag: BackupProviderStateTag.Ready, -              nextBackupTimestamp: getTimestampNow(), +              nextBackupTimestamp: TalerProtocolTimestamp.now(),              },              uids: [encodeCrock(getRandomBytes(32))],            });  | 
