diff options
Diffstat (limited to 'packages/taler-wallet-core/src/backup/index.ts')
-rw-r--r-- | packages/taler-wallet-core/src/backup/index.ts | 127 |
1 files changed, 10 insertions, 117 deletions
diff --git a/packages/taler-wallet-core/src/backup/index.ts b/packages/taler-wallet-core/src/backup/index.ts index 13bf95026..919e92c5a 100644 --- a/packages/taler-wallet-core/src/backup/index.ts +++ b/packages/taler-wallet-core/src/backup/index.ts @@ -26,7 +26,6 @@ */ import { AbsoluteTime, - AmountString, AttentionType, BackupRecovery, Codec, @@ -34,11 +33,12 @@ import { HttpStatusCode, Logger, PreparePayResult, + ProviderInfo, + ProviderPaymentStatus, RecoveryLoadRequest, RecoveryMergeStrategy, TalerError, TalerErrorCode, - TalerErrorDetail, TalerPreciseTimestamp, URL, buildCodecForObject, @@ -46,12 +46,11 @@ import { bytesToString, canonicalJson, canonicalizeBaseUrl, - codecForAmountString, codecForBoolean, codecForConstString, codecForList, - codecForNumber, codecForString, + codecForSyncTermsOfServiceResponse, codecOptional, decodeCrock, durationFromSpec, @@ -71,11 +70,16 @@ import { readTalerErrorResponse, } from "@gnu-taler/taler-util/http"; import { gunzipSync, gzipSync } from "fflate"; +import { addAttentionRequest, removeAttentionRequest } from "../attention.js"; +import { + TaskIdentifiers, + TaskRunResult, + TaskRunResultType, +} from "../common.js"; import { BackupProviderRecord, BackupProviderState, BackupProviderStateTag, - BackupProviderTerms, ConfigRecord, ConfigRecordKey, WalletBackupConfState, @@ -84,17 +88,8 @@ import { timestampPreciseToDb, } from "../db.js"; import { InternalWalletState } from "../internal-wallet-state.js"; -import { - checkDbInvariant, - checkLogicInvariant, -} from "../util/invariants.js"; -import { addAttentionRequest, removeAttentionRequest } from "../attention.js"; -import { - TaskIdentifiers, - TaskRunResult, - TaskRunResultType, -} from "../common.js"; import { preparePayForUri } from "../pay-merchant.js"; +import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js"; const logger = new Logger("operations/backup.ts"); @@ -496,26 +491,6 @@ export async function runBackupCycle( } } -export interface SyncTermsOfServiceResponse { - // maximum backup size supported - storage_limit_in_megabytes: number; - - // Fee for an account, per year. - annual_fee: AmountString; - - // protocol version supported by the server, - // for now always "0.0". - version: string; -} - -export const codecForSyncTermsOfServiceResponse = - (): Codec<SyncTermsOfServiceResponse> => - buildCodecForObject<SyncTermsOfServiceResponse>() - .property("storage_limit_in_megabytes", codecForNumber()) - .property("annual_fee", codecForAmountString()) - .property("version", codecForString()) - .build("SyncTermsOfServiceResponse"); - export interface AddBackupProviderRequest { backupProviderBaseUrl: string; @@ -664,94 +639,12 @@ export async function restoreFromRecoverySecret(): Promise<void> { return; } -/** - * Information about one provider. - * - * We don't store the account key here, - * as that's derived from the wallet root key. - */ -export interface ProviderInfo { - active: boolean; - syncProviderBaseUrl: string; - name: string; - terms?: BackupProviderTerms; - /** - * Last communication issue with the provider. - */ - lastError?: TalerErrorDetail; - lastSuccessfulBackupTimestamp?: TalerPreciseTimestamp; - lastAttemptedBackupTimestamp?: TalerPreciseTimestamp; - paymentProposalIds: string[]; - backupProblem?: BackupProblem; - paymentStatus: ProviderPaymentStatus; -} - -export type BackupProblem = - | BackupUnreadableProblem - | BackupConflictingDeviceProblem; - -export interface BackupUnreadableProblem { - type: "backup-unreadable"; -} - -export interface BackupUnreadableProblem { - type: "backup-unreadable"; -} - -export interface BackupConflictingDeviceProblem { - type: "backup-conflicting-device"; - otherDeviceId: string; - myDeviceId: string; - backupTimestamp: AbsoluteTime; -} - -export type ProviderPaymentStatus = - | ProviderPaymentTermsChanged - | ProviderPaymentPaid - | ProviderPaymentInsufficientBalance - | ProviderPaymentUnpaid - | ProviderPaymentPending; - export interface BackupInfo { walletRootPub: string; deviceId: string; providers: ProviderInfo[]; } -export enum ProviderPaymentType { - Unpaid = "unpaid", - Pending = "pending", - InsufficientBalance = "insufficient-balance", - Paid = "paid", - TermsChanged = "terms-changed", -} - -export interface ProviderPaymentUnpaid { - type: ProviderPaymentType.Unpaid; -} - -export interface ProviderPaymentInsufficientBalance { - type: ProviderPaymentType.InsufficientBalance; - amount: AmountString; -} - -export interface ProviderPaymentPending { - type: ProviderPaymentType.Pending; - talerUri?: string; -} - -export interface ProviderPaymentPaid { - type: ProviderPaymentType.Paid; - paidUntil: AbsoluteTime; -} - -export interface ProviderPaymentTermsChanged { - type: ProviderPaymentType.TermsChanged; - paidUntil: AbsoluteTime; - oldTerms: BackupProviderTerms; - newTerms: BackupProviderTerms; -} - async function getProviderPaymentInfo( ws: InternalWalletState, provider: BackupProviderRecord, |