2021-06-10 10:37:49 +02:00
|
|
|
/*
|
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2021 Taler Systems S.A.
|
|
|
|
|
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2021-01-13 00:50:56 +01:00
|
|
|
import {
|
2021-06-09 15:14:17 +02:00
|
|
|
describeStore,
|
|
|
|
describeContents,
|
|
|
|
describeIndex,
|
2021-06-14 16:08:58 +02:00
|
|
|
} from "./util/query.js";
|
2021-05-12 14:16:01 +02:00
|
|
|
import {
|
|
|
|
AmountJson,
|
|
|
|
AmountString,
|
2021-11-27 20:56:58 +01:00
|
|
|
ExchangeAuditor,
|
2021-05-12 14:16:01 +02:00
|
|
|
CoinDepositPermission,
|
|
|
|
ContractTerms,
|
2021-11-17 10:23:22 +01:00
|
|
|
DenominationPubKey,
|
2021-05-12 14:16:01 +02:00
|
|
|
Duration,
|
|
|
|
ExchangeSignKeyJson,
|
|
|
|
InternationalizedString,
|
|
|
|
MerchantInfo,
|
|
|
|
Product,
|
|
|
|
RefreshReason,
|
2022-03-22 21:16:38 +01:00
|
|
|
TalerErrorDetail,
|
2021-11-17 10:23:22 +01:00
|
|
|
UnblindedSignature,
|
2022-02-21 12:40:51 +01:00
|
|
|
CoinEnvelope,
|
2022-03-18 15:32:41 +01:00
|
|
|
TalerProtocolTimestamp,
|
|
|
|
TalerProtocolDuration,
|
2022-04-19 17:12:43 +02:00
|
|
|
AgeCommitmentProof,
|
2022-06-10 13:03:47 +02:00
|
|
|
PayCoinSelection,
|
2021-05-12 14:16:01 +02:00
|
|
|
} from "@gnu-taler/taler-util";
|
2021-03-17 17:56:37 +01:00
|
|
|
import { RetryInfo } from "./util/retries.js";
|
2021-12-01 18:16:40 +01:00
|
|
|
import { Event, IDBDatabase } from "@gnu-taler/idb-bridge";
|
2019-07-31 01:33:56 +02:00
|
|
|
|
2020-05-08 14:15:23 +02:00
|
|
|
/**
|
2020-09-08 17:46:11 +02:00
|
|
|
* Name of the Taler database. This is effectively the major
|
|
|
|
* version of the DB schema. Whenever it changes, custom import logic
|
|
|
|
* for all previous versions must be written, which should be
|
|
|
|
* avoided.
|
2020-05-08 14:15:23 +02:00
|
|
|
*/
|
2022-01-27 14:33:41 +01:00
|
|
|
export const TALER_DB_NAME = "taler-wallet-main-v4";
|
2021-01-13 00:50:56 +01:00
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* Name of the metadata database. This database is used
|
|
|
|
* to track major migrations of the main Taler database.
|
|
|
|
*
|
|
|
|
* (Minor migrations are handled via upgrade transactions.)
|
|
|
|
*/
|
|
|
|
export const TALER_META_DB_NAME = "taler-wallet-meta";
|
2021-01-13 00:50:56 +01:00
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
export const CURRENT_DB_CONFIG_KEY = "currentMainDbName";
|
2019-07-31 01:33:56 +02:00
|
|
|
|
2019-12-13 13:10:20 +01:00
|
|
|
/**
|
2020-05-08 14:15:23 +02:00
|
|
|
* Current database minor version, should be incremented
|
|
|
|
* each time we do minor schema changes on the database.
|
|
|
|
* A change is considered minor when fields are added in a
|
|
|
|
* backwards-compatible way or object stores and indices
|
|
|
|
* are added.
|
2019-12-13 13:10:20 +01:00
|
|
|
*/
|
2021-01-13 00:50:56 +01:00
|
|
|
export const WALLET_DB_MINOR_VERSION = 1;
|
2020-11-16 14:12:37 +01:00
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
export enum ReserveRecordStatus {
|
|
|
|
/**
|
|
|
|
* Reserve must be registered with the bank.
|
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
RegisteringBank = "registering-bank",
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We've registered reserve's information with the bank
|
|
|
|
* and are now waiting for the user to confirm the withdraw
|
|
|
|
* with the bank (typically 2nd factor auth).
|
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
WaitConfirmBank = "wait-confirm-bank",
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Querying reserve status with the exchange.
|
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
QueryingStatus = "querying-status",
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The corresponding withdraw record has been created.
|
|
|
|
* No further processing is done, unless explicitly requested
|
|
|
|
* by the user.
|
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
Dormant = "dormant",
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The bank aborted the withdrawal.
|
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
BankAborted = "bank-aborted",
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* Extra info about a reserve that is used
|
|
|
|
* with a bank-integrated withdrawal.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
export interface ReserveBankInfo {
|
|
|
|
/**
|
|
|
|
* Status URL that the wallet will use to query the status
|
|
|
|
* of the Taler withdrawal operation on the bank's side.
|
|
|
|
*/
|
|
|
|
statusUrl: string;
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* URL that the user can be redirected to, and allows
|
|
|
|
* them to confirm (or abort) the bank-integrated withdrawal.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
confirmUrl?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exchange payto URI that the bank will use to fund the reserve.
|
|
|
|
*/
|
|
|
|
exchangePaytoUri: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A reserve record as stored in the wallet's database.
|
|
|
|
*/
|
|
|
|
export interface ReserveRecord {
|
|
|
|
/**
|
|
|
|
* The reserve public key.
|
|
|
|
*/
|
|
|
|
reservePub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reserve private key.
|
|
|
|
*/
|
|
|
|
reservePriv: string;
|
|
|
|
|
|
|
|
/**
|
2022-01-12 15:51:56 +01:00
|
|
|
* The exchange base URL for the reserve.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Currency of the reserve.
|
|
|
|
*/
|
|
|
|
currency: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when the reserve was created.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampCreated: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when the information about this reserve was posted to the bank.
|
|
|
|
*
|
|
|
|
* Only applies if bankWithdrawStatusUrl is defined.
|
|
|
|
*
|
2022-01-12 16:54:38 +01:00
|
|
|
* Set to undefined if that hasn't happened yet.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampReserveInfoPosted: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when the reserve was confirmed by the bank.
|
|
|
|
*
|
|
|
|
* Set to undefined if not confirmed yet.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampBankConfirmed: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wire information (as payto URI) for the bank account that
|
2021-04-27 23:42:25 +02:00
|
|
|
* transferred funds for this reserve.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
senderWire?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount that was sent by the user to fund the reserve.
|
|
|
|
*/
|
|
|
|
instructedAmount: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra state for when this is a withdrawal involving
|
|
|
|
* a Taler-integrated bank.
|
|
|
|
*/
|
|
|
|
bankInfo?: ReserveBankInfo;
|
|
|
|
|
2022-04-19 17:12:43 +02:00
|
|
|
/**
|
|
|
|
* Restrict withdrawals from this reserve to this age.
|
|
|
|
*/
|
|
|
|
restrictAge?: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-allocated ID of the withdrawal group for the first withdrawal
|
|
|
|
* on this reserve.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
initialWithdrawalGroupId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Did we start the first withdrawal for this reserve?
|
|
|
|
*
|
|
|
|
* We only report a pending withdrawal for the reserve before
|
|
|
|
* the first withdrawal has started.
|
|
|
|
*/
|
|
|
|
initialWithdrawalStarted: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial denomination selection, stored here so that
|
|
|
|
* we can show this information in the transactions/balances
|
|
|
|
* before we have a withdrawal group.
|
|
|
|
*/
|
|
|
|
initialDenomSel: DenomSelectionState;
|
|
|
|
|
2022-01-12 15:51:56 +01:00
|
|
|
/**
|
|
|
|
* Current status of the reserve.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
reserveStatus: ReserveRecordStatus;
|
|
|
|
|
|
|
|
/**
|
2022-01-12 15:51:56 +01:00
|
|
|
* Is there any work to be done for this reserve?
|
2022-01-12 16:54:38 +01:00
|
|
|
*
|
2022-03-08 20:39:52 +01:00
|
|
|
* Technically redundant, since the reserveStatus would indicate this.
|
|
|
|
* However, we use the operationStatus for DB indexing of pending operations.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-01-12 15:51:56 +01:00
|
|
|
operationStatus: OperationStatus;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
2022-03-08 20:39:52 +01:00
|
|
|
* Retry info, in case the reserve needs to be processed again
|
|
|
|
* later, either due to an error or because the wallet needs to
|
|
|
|
* wait for something.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-08 20:39:52 +01:00
|
|
|
retryInfo: RetryInfo | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Last error that happened in a reserve operation
|
|
|
|
* (either talking to the bank or the exchange).
|
|
|
|
*/
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-19 13:48:36 +02:00
|
|
|
* Record that indicates the wallet trusts
|
|
|
|
* a particular auditor.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2021-05-20 13:14:47 +02:00
|
|
|
export interface AuditorTrustRecord {
|
|
|
|
/**
|
|
|
|
* Currency that we trust this auditor for.
|
|
|
|
*/
|
|
|
|
currency: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
2021-05-12 16:18:32 +02:00
|
|
|
* Base URL of the auditor.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2021-05-12 16:18:32 +02:00
|
|
|
auditorBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public key of the auditor.
|
|
|
|
*/
|
|
|
|
auditorPub: string;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
2021-05-12 16:18:32 +02:00
|
|
|
* UIDs for the operation of adding this auditor
|
|
|
|
* as a trusted auditor.
|
|
|
|
*/
|
|
|
|
uids: string[];
|
|
|
|
}
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* Record to indicate trust for a particular exchange.
|
|
|
|
*/
|
2021-05-20 13:14:47 +02:00
|
|
|
export interface ExchangeTrustRecord {
|
|
|
|
/**
|
|
|
|
* Currency that we trust this exchange for.
|
|
|
|
*/
|
|
|
|
currency: string;
|
|
|
|
|
2021-05-12 16:18:32 +02:00
|
|
|
/**
|
|
|
|
* Canonicalized exchange base URL.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
exchangeBaseUrl: string;
|
2021-05-12 16:18:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Master public key of the exchange.
|
|
|
|
*/
|
|
|
|
exchangeMasterPub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UIDs for the operation of adding this exchange
|
|
|
|
* as trusted.
|
|
|
|
*/
|
|
|
|
uids: string[];
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status of a denomination.
|
|
|
|
*/
|
2021-08-24 15:43:06 +02:00
|
|
|
export enum DenominationVerificationStatus {
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Verification was delayed.
|
|
|
|
*/
|
|
|
|
Unverified = "unverified",
|
|
|
|
/**
|
|
|
|
* Verified as valid.
|
|
|
|
*/
|
|
|
|
VerifiedGood = "verified-good",
|
|
|
|
/**
|
|
|
|
* Verified as invalid.
|
|
|
|
*/
|
|
|
|
VerifiedBad = "verified-bad",
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Denomination record as stored in the wallet's database.
|
|
|
|
*/
|
|
|
|
export interface DenominationRecord {
|
|
|
|
/**
|
|
|
|
* Value of one coin of the denomination.
|
|
|
|
*/
|
|
|
|
value: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The denomination public key.
|
|
|
|
*/
|
2021-11-17 10:23:22 +01:00
|
|
|
denomPub: DenominationPubKey;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash of the denomination public key.
|
|
|
|
* Stored in the database for faster lookups.
|
|
|
|
*/
|
|
|
|
denomPubHash: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fee for withdrawing.
|
|
|
|
*/
|
|
|
|
feeWithdraw: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fee for depositing.
|
|
|
|
*/
|
|
|
|
feeDeposit: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fee for refreshing.
|
|
|
|
*/
|
|
|
|
feeRefresh: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fee for refunding.
|
|
|
|
*/
|
|
|
|
feeRefund: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validity start date of the denomination.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
stampStart: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Date after which the currency can't be withdrawn anymore.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
stampExpireWithdraw: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Date after the denomination officially doesn't exist anymore.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
stampExpireLegal: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data after which coins of this denomination can't be deposited anymore.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
stampExpireDeposit: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signature by the exchange's master key over the denomination
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
masterSig: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Did we verify the signature on the denomination?
|
|
|
|
*/
|
2021-08-24 15:43:06 +02:00
|
|
|
verificationStatus: DenominationVerificationStatus;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Was this denomination still offered by the exchange the last time
|
|
|
|
* we checked?
|
|
|
|
* Only false when the exchange redacts a previously published denomination.
|
|
|
|
*/
|
|
|
|
isOffered: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Did the exchange revoke the denomination?
|
|
|
|
* When this field is set to true in the database, the same transaction
|
|
|
|
* should also mark all affected coins as revoked.
|
|
|
|
*/
|
|
|
|
isRevoked: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base URL of the exchange.
|
|
|
|
*/
|
|
|
|
exchangeBaseUrl: string;
|
2021-06-11 13:26:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Master public key of the exchange that made the signature
|
|
|
|
* on the denomination.
|
|
|
|
*/
|
|
|
|
exchangeMasterPub: string;
|
2021-08-19 13:48:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Latest list issue date of the "/keys" response
|
|
|
|
* that includes this denomination.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
listIssueDate: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* Information about one of the exchange's bank accounts.
|
|
|
|
*/
|
2021-06-02 13:23:51 +02:00
|
|
|
export interface ExchangeBankAccount {
|
|
|
|
payto_uri: string;
|
|
|
|
master_sig: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ExchangeDetailsRecord {
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Master public key of the exchange.
|
|
|
|
*/
|
|
|
|
masterPublicKey: string;
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
exchangeBaseUrl: string;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Currency that the exchange offers.
|
|
|
|
*/
|
|
|
|
currency: string;
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
/**
|
|
|
|
* Auditors (partially) auditing the exchange.
|
|
|
|
*/
|
2021-11-27 20:56:58 +01:00
|
|
|
auditors: ExchangeAuditor[];
|
2021-06-02 13:23:51 +02:00
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Last observed protocol version.
|
|
|
|
*/
|
|
|
|
protocolVersion: string;
|
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
reserveClosingDelay: TalerProtocolDuration;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signing keys we got from the exchange, can also contain
|
|
|
|
* older signing keys that are not returned by /keys anymore.
|
2021-08-19 13:48:36 +02:00
|
|
|
*
|
|
|
|
* FIXME: Should this be put into a separate object store?
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
signingKeys: ExchangeSignKeyJson[];
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
/**
|
|
|
|
* Terms of service text or undefined if not downloaded yet.
|
|
|
|
*
|
|
|
|
* This is just used as a cache of the last downloaded ToS.
|
|
|
|
*/
|
|
|
|
termsOfServiceText: string | undefined;
|
|
|
|
|
2021-09-13 20:32:06 +02:00
|
|
|
/**
|
|
|
|
* content-type of the last downloaded termsOfServiceText.
|
|
|
|
*/
|
2021-11-17 10:23:22 +01:00
|
|
|
termsOfServiceContentType: string | undefined;
|
2021-09-13 20:32:06 +02:00
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
/**
|
|
|
|
* ETag for last terms of service download.
|
|
|
|
*/
|
|
|
|
termsOfServiceLastEtag: string | undefined;
|
|
|
|
|
|
|
|
/**
|
2021-06-14 11:45:05 +02:00
|
|
|
* ETag for last terms of service accepted.
|
2021-06-02 13:23:51 +02:00
|
|
|
*/
|
|
|
|
termsOfServiceAcceptedEtag: string | undefined;
|
|
|
|
|
2021-06-14 11:45:05 +02:00
|
|
|
/**
|
|
|
|
* Timestamp when the ToS was accepted.
|
2021-06-15 18:52:43 +02:00
|
|
|
*
|
2021-06-14 11:45:05 +02:00
|
|
|
* Used during backup merging.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
termsOfServiceAcceptedTimestamp: TalerProtocolTimestamp | undefined;
|
2021-06-14 11:45:05 +02:00
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
wireInfo: WireInfo;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
export interface WireInfo {
|
2021-03-17 17:56:37 +01:00
|
|
|
feesForType: { [wireMethod: string]: WireFee[] };
|
2021-06-02 13:23:51 +02:00
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
accounts: ExchangeBankAccount[];
|
|
|
|
}
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
export interface ExchangeDetailsPointer {
|
|
|
|
masterPublicKey: string;
|
2021-11-23 23:51:12 +01:00
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
currency: string;
|
|
|
|
|
2021-11-23 23:51:12 +01:00
|
|
|
/**
|
|
|
|
* Last observed protocol version range offered by the exchange.
|
|
|
|
*/
|
|
|
|
protocolVersionRange: string;
|
|
|
|
|
2021-06-02 13:23:51 +02:00
|
|
|
/**
|
|
|
|
* Timestamp when the (masterPublicKey, currency) pointer
|
|
|
|
* has been updated.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
updateClock: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exchange record as stored in the wallet's database.
|
|
|
|
*/
|
|
|
|
export interface ExchangeRecord {
|
|
|
|
/**
|
|
|
|
* Base url of the exchange.
|
|
|
|
*/
|
|
|
|
baseUrl: string;
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
/**
|
|
|
|
* Pointer to the current exchange details.
|
|
|
|
*/
|
2021-06-02 13:23:51 +02:00
|
|
|
detailsPointer: ExchangeDetailsPointer | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this a permanent or temporary exchange record?
|
|
|
|
*/
|
|
|
|
permanent: boolean;
|
|
|
|
|
|
|
|
/**
|
2021-06-10 16:32:37 +02:00
|
|
|
* Last time when the exchange was updated.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
lastUpdate: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
2021-06-10 16:32:37 +02:00
|
|
|
* Next scheduled update for the exchange.
|
2021-06-09 15:14:17 +02:00
|
|
|
*
|
2021-06-10 16:32:37 +02:00
|
|
|
* (This field must always be present, so we can index on the timestamp.)
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
nextUpdate: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2021-06-10 16:32:37 +02:00
|
|
|
/**
|
|
|
|
* Next time that we should check if coins need to be refreshed.
|
|
|
|
*
|
|
|
|
* Updated whenever the exchange's denominations are updated or when
|
|
|
|
* the refresh check has been done.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
nextRefreshCheck: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2021-12-08 01:52:24 +01:00
|
|
|
/**
|
|
|
|
* Last error (if any) for fetching updated information about the
|
|
|
|
* exchange.
|
|
|
|
*/
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError?: TalerErrorDetail;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry status for fetching updated information about the exchange.
|
|
|
|
*/
|
2022-03-28 23:59:16 +02:00
|
|
|
retryInfo?: RetryInfo;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A coin that isn't yet signed by an exchange.
|
|
|
|
*/
|
|
|
|
export interface PlanchetRecord {
|
|
|
|
/**
|
|
|
|
* Public key of the coin.
|
|
|
|
*/
|
|
|
|
coinPub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private key of the coin.
|
|
|
|
*/
|
|
|
|
coinPriv: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Withdrawal group that this planchet belongs to
|
|
|
|
* (or the empty string).
|
|
|
|
*/
|
|
|
|
withdrawalGroupId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Index within the withdrawal group (or -1).
|
|
|
|
*/
|
|
|
|
coinIdx: number;
|
|
|
|
|
|
|
|
withdrawalDone: boolean;
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Public key of the reserve that this planchet
|
|
|
|
* is being withdrawn from.
|
|
|
|
*
|
|
|
|
* Can be the empty string (non-null/undefined for DB indexing)
|
|
|
|
* if this is a tipping reserve.
|
|
|
|
*/
|
|
|
|
reservePub: string;
|
|
|
|
|
|
|
|
denomPubHash: string;
|
|
|
|
|
|
|
|
blindingKey: string;
|
|
|
|
|
|
|
|
withdrawSig: string;
|
|
|
|
|
2022-02-21 12:40:51 +01:00
|
|
|
coinEv: CoinEnvelope;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
coinEvHash: string;
|
2022-04-19 17:12:43 +02:00
|
|
|
|
|
|
|
ageCommitmentProof?: AgeCommitmentProof;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status of a coin.
|
|
|
|
*/
|
|
|
|
export enum CoinStatus {
|
|
|
|
/**
|
|
|
|
* Withdrawn and never shown to anybody.
|
|
|
|
*/
|
|
|
|
Fresh = "fresh",
|
|
|
|
/**
|
|
|
|
* A coin that has been spent and refreshed.
|
|
|
|
*/
|
|
|
|
Dormant = "dormant",
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum CoinSourceType {
|
|
|
|
Withdraw = "withdraw",
|
|
|
|
Refresh = "refresh",
|
|
|
|
Tip = "tip",
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WithdrawCoinSource {
|
|
|
|
type: CoinSourceType.Withdraw;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can be the empty string for orphaned coins.
|
|
|
|
*/
|
|
|
|
withdrawalGroupId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Index of the coin in the withdrawal session.
|
|
|
|
*/
|
|
|
|
coinIndex: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserve public key for the reserve we got this coin from.
|
|
|
|
*/
|
|
|
|
reservePub: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RefreshCoinSource {
|
|
|
|
type: CoinSourceType.Refresh;
|
|
|
|
oldCoinPub: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TipCoinSource {
|
|
|
|
type: CoinSourceType.Tip;
|
|
|
|
walletTipId: string;
|
|
|
|
coinIndex: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type CoinSource = WithdrawCoinSource | RefreshCoinSource | TipCoinSource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CoinRecord as stored in the "coins" data store
|
|
|
|
* of the wallet database.
|
|
|
|
*/
|
|
|
|
export interface CoinRecord {
|
|
|
|
/**
|
|
|
|
* Where did the coin come from? Used for recouping coins.
|
|
|
|
*/
|
|
|
|
coinSource: CoinSource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public key of the coin.
|
|
|
|
*/
|
|
|
|
coinPub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private key to authorize operations on the coin.
|
|
|
|
*/
|
|
|
|
coinPriv: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash of the public key that signs the coin.
|
|
|
|
*/
|
|
|
|
denomPubHash: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unblinded signature by the exchange.
|
|
|
|
*/
|
2021-11-17 10:23:22 +01:00
|
|
|
denomSig: UnblindedSignature;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount that's left on the coin.
|
|
|
|
*/
|
|
|
|
currentAmount: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base URL that identifies the exchange from which we got the
|
|
|
|
* coin.
|
|
|
|
*/
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The coin is currently suspended, and will not be used for payments.
|
|
|
|
*/
|
|
|
|
suspended: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blinding key used when withdrawing the coin.
|
|
|
|
* Potentionally used again during payback.
|
|
|
|
*/
|
|
|
|
blindingKey: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash of the coin envelope.
|
|
|
|
*
|
|
|
|
* Stored here for indexing purposes, so that when looking at a
|
|
|
|
* reserve history, we can quickly find the coin for a withdrawal transaction.
|
|
|
|
*/
|
|
|
|
coinEvHash: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status of the coin.
|
|
|
|
*/
|
|
|
|
status: CoinStatus;
|
2021-06-22 18:43:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Information about what the coin has been allocated for.
|
|
|
|
* Used to prevent allocation of the same coin for two different payments.
|
|
|
|
*/
|
|
|
|
allocation?: CoinAllocation;
|
2022-04-19 17:12:43 +02:00
|
|
|
|
|
|
|
ageCommitmentProof?: AgeCommitmentProof;
|
2021-06-22 18:43:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CoinAllocation {
|
|
|
|
id: string;
|
|
|
|
amount: AmountString;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum ProposalStatus {
|
|
|
|
/**
|
|
|
|
* Not downloaded yet.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
Downloading = "downloading",
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Proposal downloaded, but the user needs to accept/reject it.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
Proposed = "proposed",
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* The user has accepted the proposal.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
Accepted = "accepted",
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* The user has rejected the proposal.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
Refused = "refused",
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Downloading or processing the proposal has failed permanently.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
PermanentlyFailed = "permanently-failed",
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Downloaded proposal was detected as a re-purchase.
|
|
|
|
*/
|
2022-03-08 23:09:20 +01:00
|
|
|
Repurchase = "repurchase",
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ProposalDownload {
|
|
|
|
/**
|
|
|
|
* The contract that was offered by the merchant.
|
|
|
|
*/
|
|
|
|
contractTermsRaw: any;
|
|
|
|
|
|
|
|
contractData: WalletContractData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record for a downloaded order, stored in the wallet's database.
|
|
|
|
*/
|
|
|
|
export interface ProposalRecord {
|
|
|
|
orderId: string;
|
|
|
|
|
|
|
|
merchantBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Downloaded data from the merchant.
|
|
|
|
*/
|
|
|
|
download: ProposalDownload | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique ID when the order is stored in the wallet DB.
|
|
|
|
*/
|
|
|
|
proposalId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp (in ms) of when the record
|
|
|
|
* was created.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private key for the nonce.
|
|
|
|
*/
|
|
|
|
noncePriv: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public key for the nonce.
|
|
|
|
*/
|
|
|
|
noncePub: string;
|
|
|
|
|
|
|
|
claimToken: string | undefined;
|
|
|
|
|
|
|
|
proposalStatus: ProposalStatus;
|
|
|
|
|
|
|
|
repurchaseProposalId: string | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Session ID we got when downloading the contract.
|
|
|
|
*/
|
|
|
|
downloadSessionId?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry info, even present when the operation isn't active to allow indexing
|
|
|
|
* on the next retry timestamp.
|
2022-03-08 23:09:20 +01:00
|
|
|
*
|
2022-03-08 20:39:52 +01:00
|
|
|
* FIXME: Clarify what we even retry.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2021-06-11 11:15:08 +02:00
|
|
|
retryInfo?: RetryInfo;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status of a tip we got from a merchant.
|
|
|
|
*/
|
|
|
|
export interface TipRecord {
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Has the user accepted the tip? Only after the tip has been accepted coins
|
|
|
|
* withdrawn from the tip may be used.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
acceptedTimestamp: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The tipped amount.
|
|
|
|
*/
|
|
|
|
tipAmountRaw: AmountJson;
|
|
|
|
|
|
|
|
tipAmountEffective: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp, the tip can't be picked up anymore after this deadline.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
tipExpiration: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The exchange that will sign our coins, chosen by the merchant.
|
|
|
|
*/
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base URL of the merchant that is giving us the tip.
|
|
|
|
*/
|
|
|
|
merchantBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Denomination selection made by the wallet for picking up
|
|
|
|
* this tip.
|
|
|
|
*/
|
|
|
|
denomsSel: DenomSelectionState;
|
|
|
|
|
2021-05-12 13:34:49 +02:00
|
|
|
denomSelUid: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Tip ID chosen by the wallet.
|
|
|
|
*/
|
|
|
|
walletTipId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secret seed used to derive planchets for this tip.
|
|
|
|
*/
|
|
|
|
secretSeed: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The merchant's identifier for this tip.
|
|
|
|
*/
|
|
|
|
merchantTipId: string;
|
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
createdTimestamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp for when the wallet finished picking up the tip
|
|
|
|
* from the merchant.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
pickedUpTimestamp: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry info, even present when the operation isn't active to allow indexing
|
|
|
|
* on the next retry timestamp.
|
|
|
|
*/
|
|
|
|
retryInfo: RetryInfo;
|
|
|
|
}
|
|
|
|
|
2021-08-24 14:25:46 +02:00
|
|
|
export enum RefreshCoinStatus {
|
|
|
|
Pending = "pending",
|
|
|
|
Finished = "finished",
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The refresh for this coin has been frozen, because of a permanent error.
|
|
|
|
* More info in lastErrorPerCoin.
|
|
|
|
*/
|
|
|
|
Frozen = "frozen",
|
|
|
|
}
|
|
|
|
|
2022-01-11 21:00:12 +01:00
|
|
|
export enum OperationStatus {
|
|
|
|
Finished = "finished",
|
|
|
|
Pending = "pending",
|
|
|
|
}
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
export interface RefreshGroupRecord {
|
2022-01-11 21:00:12 +01:00
|
|
|
operationStatus: OperationStatus;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Retry info, even present when the operation isn't active to allow indexing
|
|
|
|
* on the next retry timestamp.
|
2022-01-11 21:00:12 +01:00
|
|
|
*
|
|
|
|
* FIXME: No, this can be optional, indexing is still possible
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
retryInfo: RetryInfo;
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastErrorPerCoin: { [coinIndex: number]: TalerErrorDetail };
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2021-08-24 14:25:46 +02:00
|
|
|
/**
|
|
|
|
* Unique, randomly generated identifier for this group of
|
|
|
|
* refresh operations.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
refreshGroupId: string;
|
|
|
|
|
2021-08-24 14:25:46 +02:00
|
|
|
/**
|
|
|
|
* Reason why this refresh group has been created.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
reason: RefreshReason;
|
|
|
|
|
|
|
|
oldCoinPubs: string[];
|
|
|
|
|
2021-08-19 13:48:36 +02:00
|
|
|
// FIXME: Should this go into a separate
|
|
|
|
// object store for faster updates?
|
2021-03-17 17:56:37 +01:00
|
|
|
refreshSessionPerCoin: (RefreshSessionRecord | undefined)[];
|
|
|
|
|
|
|
|
inputPerCoin: AmountJson[];
|
|
|
|
|
|
|
|
estimatedOutputPerCoin: AmountJson[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag for each coin whether refreshing finished.
|
|
|
|
* If a coin can't be refreshed (remaining value too small),
|
|
|
|
* it will be marked as finished, but no refresh session will
|
|
|
|
* be created.
|
|
|
|
*/
|
2021-08-24 14:25:46 +02:00
|
|
|
statusPerCoin: RefreshCoinStatus[];
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampCreated: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp when the refresh session finished.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampFinished: TalerProtocolTimestamp | undefined;
|
2021-08-24 14:25:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* No coins are pending, but at least one is frozen.
|
|
|
|
*/
|
|
|
|
frozen?: boolean;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ongoing refresh
|
|
|
|
*/
|
|
|
|
export interface RefreshSessionRecord {
|
|
|
|
/**
|
|
|
|
* 512-bit secret that can be used to derive
|
|
|
|
* the other cryptographic material for the refresh session.
|
|
|
|
*/
|
|
|
|
sessionSecretSeed: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sum of the value of denominations we want
|
|
|
|
* to withdraw in this session, without fees.
|
|
|
|
*/
|
|
|
|
amountRefreshOutput: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hashed denominations of the newly requested coins.
|
|
|
|
*/
|
|
|
|
newDenoms: {
|
|
|
|
denomPubHash: string;
|
|
|
|
count: number;
|
|
|
|
}[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The no-reveal-index after we've done the melting.
|
|
|
|
*/
|
|
|
|
norevealIndex?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wire fee for one wire method as stored in the
|
|
|
|
* wallet's database.
|
|
|
|
*/
|
|
|
|
export interface WireFee {
|
|
|
|
/**
|
|
|
|
* Fee for wire transfers.
|
|
|
|
*/
|
|
|
|
wireFee: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fees to close and refund a reserve.
|
|
|
|
*/
|
|
|
|
closingFee: AmountJson;
|
|
|
|
|
2022-03-07 12:09:38 +01:00
|
|
|
/**
|
|
|
|
* Fees for inter-exchange transfers from P2P payments.
|
|
|
|
*/
|
|
|
|
wadFee: AmountJson;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Start date of the fee.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
startStamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* End date of the fee.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
endStamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signature made by the exchange master key.
|
|
|
|
*/
|
|
|
|
sig: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum RefundState {
|
|
|
|
Failed = "failed",
|
|
|
|
Applied = "applied",
|
|
|
|
Pending = "pending",
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* State of one refund from the merchant, maintained by the wallet.
|
|
|
|
*/
|
|
|
|
export type WalletRefundItem =
|
|
|
|
| WalletRefundFailedItem
|
|
|
|
| WalletRefundPendingItem
|
|
|
|
| WalletRefundAppliedItem;
|
|
|
|
|
|
|
|
export interface WalletRefundItemCommon {
|
|
|
|
// Execution time as claimed by the merchant
|
2022-03-18 15:32:41 +01:00
|
|
|
executionTime: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when the wallet became aware of the refund.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
obtainedTime: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
refundAmount: AmountJson;
|
|
|
|
|
|
|
|
refundFee: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upper bound on the refresh cost incurred by
|
|
|
|
* applying this refund.
|
|
|
|
*
|
|
|
|
* Might be lower in practice when two refunds on the same
|
|
|
|
* coin are refreshed in the same refresh operation.
|
|
|
|
*/
|
|
|
|
totalRefreshCostBound: AmountJson;
|
|
|
|
|
|
|
|
coinPub: string;
|
|
|
|
|
|
|
|
rtransactionId: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Failed refund, either because the merchant did
|
|
|
|
* something wrong or it expired.
|
|
|
|
*/
|
|
|
|
export interface WalletRefundFailedItem extends WalletRefundItemCommon {
|
|
|
|
type: RefundState.Failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WalletRefundPendingItem extends WalletRefundItemCommon {
|
|
|
|
type: RefundState.Pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WalletRefundAppliedItem extends WalletRefundItemCommon {
|
|
|
|
type: RefundState.Applied;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum RefundReason {
|
|
|
|
/**
|
|
|
|
* Normal refund given by the merchant.
|
|
|
|
*/
|
|
|
|
NormalRefund = "normal-refund",
|
|
|
|
/**
|
|
|
|
* Refund from an aborted payment.
|
|
|
|
*/
|
|
|
|
AbortRefund = "abort-pay-refund",
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AllowedAuditorInfo {
|
|
|
|
auditorBaseUrl: string;
|
|
|
|
auditorPub: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface AllowedExchangeInfo {
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
exchangePub: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data extracted from the contract terms that is relevant for payment
|
|
|
|
* processing in the wallet.
|
|
|
|
*/
|
|
|
|
export interface WalletContractData {
|
|
|
|
products?: Product[];
|
|
|
|
summaryI18n: { [lang_tag: string]: string } | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fulfillment URL, or the empty string if the order has no fulfillment URL.
|
|
|
|
*
|
|
|
|
* Stored as a non-nullable string as we use this field for IndexedDB indexing.
|
|
|
|
*/
|
|
|
|
fulfillmentUrl: string;
|
|
|
|
|
|
|
|
contractTermsHash: string;
|
|
|
|
fulfillmentMessage?: string;
|
|
|
|
fulfillmentMessageI18n?: InternationalizedString;
|
|
|
|
merchantSig: string;
|
|
|
|
merchantPub: string;
|
|
|
|
merchant: MerchantInfo;
|
|
|
|
amount: AmountJson;
|
|
|
|
orderId: string;
|
|
|
|
merchantBaseUrl: string;
|
|
|
|
summary: string;
|
2022-03-18 15:32:41 +01:00
|
|
|
autoRefund: TalerProtocolDuration | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
maxWireFee: AmountJson;
|
|
|
|
wireFeeAmortization: number;
|
2022-03-18 15:32:41 +01:00
|
|
|
payDeadline: TalerProtocolTimestamp;
|
|
|
|
refundDeadline: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
allowedAuditors: AllowedAuditorInfo[];
|
|
|
|
allowedExchanges: AllowedExchangeInfo[];
|
2022-03-18 15:32:41 +01:00
|
|
|
timestamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
wireMethod: string;
|
|
|
|
wireInfoHash: string;
|
|
|
|
maxDepositFee: AmountJson;
|
2022-04-19 17:12:43 +02:00
|
|
|
minimumAge?: number;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum AbortStatus {
|
|
|
|
None = "none",
|
|
|
|
AbortRefund = "abort-refund",
|
|
|
|
AbortFinished = "abort-finished",
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record that stores status information about one purchase, starting from when
|
|
|
|
* the customer accepts a proposal. Includes refund status if applicable.
|
|
|
|
*/
|
|
|
|
export interface PurchaseRecord {
|
|
|
|
/**
|
|
|
|
* Proposal ID for this purchase. Uniquely identifies the
|
|
|
|
* purchase and the proposal.
|
|
|
|
*/
|
|
|
|
proposalId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private key for the nonce.
|
|
|
|
*/
|
|
|
|
noncePriv: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public key for the nonce.
|
|
|
|
*/
|
|
|
|
noncePub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Downloaded and parsed proposal data.
|
2021-08-24 14:25:46 +02:00
|
|
|
*
|
|
|
|
* FIXME: Move this into another object store,
|
|
|
|
* to improve read/write perf on purchases.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
download: ProposalDownload;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deposit permissions, available once the user has accepted the payment.
|
|
|
|
*
|
|
|
|
* This value is cached and derived from payCoinSelection.
|
|
|
|
*/
|
|
|
|
coinDepositPermissions: CoinDepositPermission[] | undefined;
|
|
|
|
|
|
|
|
payCoinSelection: PayCoinSelection;
|
|
|
|
|
2021-05-12 13:34:49 +02:00
|
|
|
payCoinSelectionUid: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Pending removals from pay coin selection.
|
2021-05-12 14:16:01 +02:00
|
|
|
*
|
2021-03-17 17:56:37 +01:00
|
|
|
* Used when a the pay coin selection needs to be changed
|
|
|
|
* because a coin became known as double-spent or invalid,
|
|
|
|
* but a new coin selection can't immediately be done, as
|
|
|
|
* there is not enough balance (e.g. when waiting for a refresh).
|
|
|
|
*/
|
|
|
|
pendingRemovedCoinPubs?: string[];
|
|
|
|
|
|
|
|
totalPayCost: AmountJson;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp of the first time that sending a payment to the merchant
|
|
|
|
* for this purchase was successful.
|
2022-03-18 15:32:41 +01:00
|
|
|
*
|
2022-06-26 20:52:32 +02:00
|
|
|
* FIXME: Does this need to be a timestamp, doesn't boolean suffice?
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampFirstSuccessfulPay: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
merchantPaySig: string | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When was the purchase made?
|
|
|
|
* Refers to the time that the user accepted.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampAccept: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pending refunds for the purchase. A refund is pending
|
|
|
|
* when the merchant reports a transient error from the exchange.
|
|
|
|
*/
|
|
|
|
refunds: { [refundKey: string]: WalletRefundItem };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When was the last refund made?
|
|
|
|
* Set to 0 if no refund was made on the purchase.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampLastRefundStatus: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Last session signature that we submitted to /pay (if any).
|
|
|
|
*/
|
|
|
|
lastSessionId: string | undefined;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set for the first payment, or on re-plays.
|
|
|
|
*/
|
|
|
|
paymentSubmitPending: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do we need to query the merchant for the refund status
|
|
|
|
* of the payment?
|
|
|
|
*/
|
|
|
|
refundQueryRequested: boolean;
|
|
|
|
|
|
|
|
abortStatus: AbortStatus;
|
|
|
|
|
2021-06-11 13:18:33 +02:00
|
|
|
payRetryInfo?: RetryInfo;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastPayError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry information for querying the refund status with the merchant.
|
|
|
|
*/
|
|
|
|
refundStatusRetryInfo: RetryInfo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Last error (or undefined) for querying the refund status with the merchant.
|
|
|
|
*/
|
2022-03-22 21:16:38 +01:00
|
|
|
lastRefundStatusError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Continue querying the refund status until this deadline has expired.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
autoRefundDeadline: TalerProtocolTimestamp | undefined;
|
2021-08-24 15:08:34 +02:00
|
|
|
|
2022-05-14 23:09:33 +02:00
|
|
|
/**
|
|
|
|
* How much merchant has refund to be taken but the wallet
|
|
|
|
* did not picked up yet
|
|
|
|
*/
|
|
|
|
refundAwaiting: AmountJson | undefined;
|
|
|
|
|
2021-08-24 15:08:34 +02:00
|
|
|
/**
|
|
|
|
* Is the payment frozen? I.e. did we encounter
|
|
|
|
* an error where it doesn't make sense to retry.
|
|
|
|
*/
|
|
|
|
payFrozen?: boolean;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-06-14 11:21:29 +02:00
|
|
|
export const WALLET_BACKUP_STATE_KEY = "walletBackupState";
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Configuration key/value entries to configure
|
|
|
|
* the wallet.
|
|
|
|
*/
|
2021-06-14 11:21:29 +02:00
|
|
|
export type ConfigRecord =
|
|
|
|
| {
|
2022-04-29 18:16:29 +02:00
|
|
|
key: typeof WALLET_BACKUP_STATE_KEY;
|
|
|
|
value: WalletBackupConfState;
|
|
|
|
}
|
2021-06-14 11:21:29 +02:00
|
|
|
| { key: "currencyDefaultsApplied"; value: boolean };
|
|
|
|
|
|
|
|
export interface WalletBackupConfState {
|
|
|
|
deviceId: string;
|
|
|
|
walletRootPub: string;
|
|
|
|
walletRootPriv: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Last hash of the canonicalized plain-text backup.
|
|
|
|
*/
|
|
|
|
lastBackupPlainHash?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timestamp stored in the last backup.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
lastBackupTimestamp?: TalerProtocolTimestamp;
|
2021-06-14 11:21:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Last time we tried to do a backup.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
lastBackupCheckTimestamp?: TalerProtocolTimestamp;
|
2021-06-14 11:21:29 +02:00
|
|
|
lastBackupNonce?: string;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selected denominations withn some extra info.
|
|
|
|
*/
|
|
|
|
export interface DenomSelectionState {
|
|
|
|
totalCoinValue: AmountJson;
|
|
|
|
totalWithdrawCost: AmountJson;
|
|
|
|
selectedDenoms: {
|
|
|
|
denomPubHash: string;
|
|
|
|
count: number;
|
|
|
|
}[];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Group of withdrawal operations that need to be executed.
|
|
|
|
* (Either for a normal withdrawal or from a tip.)
|
|
|
|
*
|
|
|
|
* The withdrawal group record is only created after we know
|
|
|
|
* the coin selection we want to withdraw.
|
|
|
|
*/
|
|
|
|
export interface WithdrawalGroupRecord {
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* Unique identifier for the withdrawal group.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
withdrawalGroupId: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secret seed used to derive planchets.
|
|
|
|
*/
|
|
|
|
secretSeed: string;
|
|
|
|
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* Public key of the reserve that we're withdrawing from.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
reservePub: string;
|
|
|
|
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* The exchange base URL that we're withdrawing from.
|
|
|
|
* (Redundantly stored, as the reserve record also has this info.)
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
exchangeBaseUrl: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When was the withdrawal operation started started?
|
|
|
|
* Timestamp in milliseconds.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampStart: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When was the withdrawal operation completed?
|
2022-03-10 16:30:24 +01:00
|
|
|
*
|
|
|
|
* FIXME: We should probably drop this and introduce an OperationStatus field.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampFinish?: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* Operation status of the withdrawal group.
|
|
|
|
* Used for indexing in the database.
|
|
|
|
*/
|
2022-01-11 21:00:12 +01:00
|
|
|
operationStatus: OperationStatus;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Amount including fees (i.e. the amount subtracted from the
|
|
|
|
* reserve to withdraw all coins in this withdrawal session).
|
|
|
|
*/
|
|
|
|
rawWithdrawalAmount: AmountJson;
|
|
|
|
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* Denominations selected for withdrawal.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
denomsSel: DenomSelectionState;
|
|
|
|
|
2022-01-12 16:54:38 +01:00
|
|
|
/**
|
|
|
|
* UID of the denomination selection.
|
2022-02-21 12:40:51 +01:00
|
|
|
*
|
2022-01-12 16:54:38 +01:00
|
|
|
* Used for merging backups.
|
2022-02-21 12:40:51 +01:00
|
|
|
*
|
2022-01-12 16:54:38 +01:00
|
|
|
* FIXME: Should this not also include a timestamp for more logical merging?
|
|
|
|
*/
|
2021-05-12 13:34:49 +02:00
|
|
|
denomSelUid: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Retry info, always present even on completed operations so that indexing works.
|
|
|
|
*/
|
|
|
|
retryInfo: RetryInfo;
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface BankWithdrawUriRecord {
|
|
|
|
/**
|
|
|
|
* The withdraw URI we got from the bank.
|
|
|
|
*/
|
|
|
|
talerWithdrawUri: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserve that was created for the withdraw URI.
|
|
|
|
*/
|
|
|
|
reservePub: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status of recoup operations that were grouped together.
|
|
|
|
*
|
|
|
|
* The remaining amount of involved coins should be set to zero
|
|
|
|
* in the same transaction that inserts the RecoupGroupRecord.
|
|
|
|
*/
|
|
|
|
export interface RecoupGroupRecord {
|
|
|
|
/**
|
|
|
|
* Unique identifier for the recoup group record.
|
|
|
|
*/
|
|
|
|
recoupGroupId: string;
|
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampStarted: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampFinished: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Public keys that identify the coins being recouped
|
|
|
|
* as part of this session.
|
|
|
|
*
|
|
|
|
* (Structured like this to enable multiEntry indexing in IndexedDB.)
|
|
|
|
*/
|
|
|
|
coinPubs: string[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of flags to indicate whether the recoup finished on each individual coin.
|
|
|
|
*/
|
|
|
|
recoupFinishedPerCoin: boolean[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We store old amount (i.e. before recoup) of recouped coins here,
|
|
|
|
* as the balance of a recouped coin is set to zero when the
|
|
|
|
* recoup group is created.
|
|
|
|
*/
|
|
|
|
oldAmountPerCoin: AmountJson[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public keys of coins that should be scheduled for refreshing
|
|
|
|
* after all individual recoups are done.
|
|
|
|
*/
|
|
|
|
scheduleRefreshCoins: string[];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry info.
|
|
|
|
*/
|
|
|
|
retryInfo: RetryInfo;
|
|
|
|
|
|
|
|
/**
|
2021-04-27 23:42:25 +02:00
|
|
|
* Last error that occurred, if any.
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-06-25 13:27:06 +02:00
|
|
|
export enum BackupProviderStateTag {
|
|
|
|
Provisional = "provisional",
|
2021-03-17 17:56:37 +01:00
|
|
|
Ready = "ready",
|
2021-06-25 13:27:06 +02:00
|
|
|
Retrying = "retrying",
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
2021-06-25 13:27:06 +02:00
|
|
|
export type BackupProviderState =
|
|
|
|
| {
|
2022-04-29 18:16:29 +02:00
|
|
|
tag: BackupProviderStateTag.Provisional;
|
|
|
|
}
|
2021-06-25 13:27:06 +02:00
|
|
|
| {
|
2022-04-29 18:16:29 +02:00
|
|
|
tag: BackupProviderStateTag.Ready;
|
|
|
|
nextBackupTimestamp: TalerProtocolTimestamp;
|
|
|
|
}
|
2021-06-25 13:27:06 +02:00
|
|
|
| {
|
2022-04-29 18:16:29 +02:00
|
|
|
tag: BackupProviderStateTag.Retrying;
|
|
|
|
retryInfo: RetryInfo;
|
|
|
|
lastError?: TalerErrorDetail;
|
|
|
|
};
|
2021-06-25 13:27:06 +02:00
|
|
|
|
2021-05-12 14:16:01 +02:00
|
|
|
export interface BackupProviderTerms {
|
|
|
|
supportedProtocolVersion: string;
|
|
|
|
annualFee: AmountString;
|
|
|
|
storageLimitInMegabytes: number;
|
|
|
|
}
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
export interface BackupProviderRecord {
|
2021-05-21 11:47:11 +02:00
|
|
|
/**
|
|
|
|
* Base URL of the provider.
|
2021-06-02 13:23:51 +02:00
|
|
|
*
|
2021-05-21 11:47:11 +02:00
|
|
|
* Primary key for the record.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
baseUrl: string;
|
|
|
|
|
2021-07-15 20:03:45 +02:00
|
|
|
/**
|
|
|
|
* Name of the provider
|
|
|
|
*/
|
|
|
|
name: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
/**
|
|
|
|
* Terms of service of the provider.
|
|
|
|
* Might be unavailable in the DB in certain situations
|
|
|
|
* (such as loading a recovery document).
|
|
|
|
*/
|
2021-05-12 14:16:01 +02:00
|
|
|
terms?: BackupProviderTerms;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hash of the last encrypted backup that we already merged
|
|
|
|
* or successfully uploaded ourselves.
|
|
|
|
*/
|
|
|
|
lastBackupHash?: string;
|
|
|
|
|
2021-06-23 13:06:32 +02:00
|
|
|
/**
|
|
|
|
* Last time that we successfully uploaded a backup (or
|
|
|
|
* the uploaded backup was already current).
|
|
|
|
*
|
|
|
|
* Does NOT correspond to the timestamp of the backup,
|
|
|
|
* which only changes when the backup content changes.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
lastBackupCycleTimestamp?: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Proposal that we're currently trying to pay for.
|
|
|
|
*
|
|
|
|
* (Also included in paymentProposalIds.)
|
2021-06-25 13:27:06 +02:00
|
|
|
*
|
|
|
|
* FIXME: Make this part of a proper BackupProviderState?
|
2021-03-17 17:56:37 +01:00
|
|
|
*/
|
|
|
|
currentPaymentProposalId?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Proposals that were used to pay (or attempt to pay) the provider.
|
|
|
|
*
|
|
|
|
* Stored to display a history of payments to the provider, and
|
|
|
|
* to make sure that the wallet isn't overpaying.
|
|
|
|
*/
|
|
|
|
paymentProposalIds: string[];
|
|
|
|
|
2021-06-25 13:27:06 +02:00
|
|
|
state: BackupProviderState;
|
2021-05-12 14:16:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UIDs for the operation that added the backup provider.
|
|
|
|
*/
|
|
|
|
uids: string[];
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Group of deposits made by the wallet.
|
|
|
|
*/
|
|
|
|
export interface DepositGroupRecord {
|
|
|
|
depositGroupId: string;
|
|
|
|
|
|
|
|
merchantPub: string;
|
|
|
|
merchantPriv: string;
|
|
|
|
|
|
|
|
noncePriv: string;
|
|
|
|
noncePub: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wire information used by all deposits in this
|
|
|
|
* deposit group.
|
|
|
|
*/
|
|
|
|
wire: {
|
|
|
|
payto_uri: string;
|
|
|
|
salt: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verbatim contract terms.
|
|
|
|
*/
|
|
|
|
contractTermsRaw: ContractTerms;
|
|
|
|
|
|
|
|
contractTermsHash: string;
|
|
|
|
|
|
|
|
payCoinSelection: PayCoinSelection;
|
|
|
|
|
2021-06-22 18:43:11 +02:00
|
|
|
payCoinSelectionUid: string;
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
totalPayCost: AmountJson;
|
|
|
|
|
|
|
|
effectiveDepositAmount: AmountJson;
|
|
|
|
|
|
|
|
depositedPerCoin: boolean[];
|
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampCreated: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-03-18 15:32:41 +01:00
|
|
|
timestampFinished: TalerProtocolTimestamp | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
2022-01-11 21:00:12 +01:00
|
|
|
operationStatus: OperationStatus;
|
|
|
|
|
2022-03-22 21:16:38 +01:00
|
|
|
lastError: TalerErrorDetail | undefined;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retry info.
|
|
|
|
*/
|
2021-08-07 18:19:04 +02:00
|
|
|
retryInfo?: RetryInfo;
|
2021-03-17 17:56:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record for a deposits that the wallet observed
|
|
|
|
* as a result of double spending, but which is not
|
|
|
|
* present in the wallet's own database otherwise.
|
|
|
|
*/
|
|
|
|
export interface GhostDepositGroupRecord {
|
|
|
|
/**
|
|
|
|
* When multiple deposits for the same contract terms hash
|
|
|
|
* have a different timestamp, we choose the earliest one.
|
|
|
|
*/
|
2022-03-18 15:32:41 +01:00
|
|
|
timestamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
|
|
|
|
contractTermsHash: string;
|
|
|
|
|
|
|
|
deposits: {
|
|
|
|
coinPub: string;
|
|
|
|
amount: AmountString;
|
2022-03-18 15:32:41 +01:00
|
|
|
timestamp: TalerProtocolTimestamp;
|
2021-03-17 17:56:37 +01:00
|
|
|
depositFee: AmountString;
|
|
|
|
merchantPub: string;
|
|
|
|
coinSig: string;
|
|
|
|
wireHash: string;
|
|
|
|
}[];
|
|
|
|
}
|
|
|
|
|
2021-05-12 15:26:15 +02:00
|
|
|
export interface TombstoneRecord {
|
|
|
|
/**
|
|
|
|
* Tombstone ID, with the syntax "<type>:<key>".
|
|
|
|
*/
|
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
|
2022-01-11 21:00:12 +01:00
|
|
|
export interface BalancePerCurrencyRecord {
|
|
|
|
currency: string;
|
|
|
|
|
|
|
|
availableNow: AmountString;
|
|
|
|
|
|
|
|
availableExpected: AmountString;
|
|
|
|
|
|
|
|
pendingIncoming: AmountString;
|
|
|
|
|
|
|
|
pendingOutgoing: AmountString;
|
|
|
|
}
|
|
|
|
|
2021-06-09 15:14:17 +02:00
|
|
|
export const WalletStoresV1 = {
|
|
|
|
coins: describeStore(
|
|
|
|
describeContents<CoinRecord>("coins", {
|
|
|
|
keyPath: "coinPub",
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
byBaseUrl: describeIndex("byBaseUrl", "exchangeBaseUrl"),
|
|
|
|
byDenomPubHash: describeIndex("byDenomPubHash", "denomPubHash"),
|
|
|
|
byCoinEvHash: describeIndex("byCoinEvHash", "coinEvHash"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
config: describeStore(
|
2021-06-14 11:21:29 +02:00
|
|
|
describeContents<ConfigRecord>("config", { keyPath: "key" }),
|
2021-06-09 15:14:17 +02:00
|
|
|
{},
|
|
|
|
),
|
|
|
|
auditorTrust: describeStore(
|
|
|
|
describeContents<AuditorTrustRecord>("auditorTrust", {
|
|
|
|
keyPath: ["currency", "auditorBaseUrl"],
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
byAuditorPub: describeIndex("byAuditorPub", "auditorPub"),
|
|
|
|
byUid: describeIndex("byUid", "uids", {
|
|
|
|
multiEntry: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
exchangeTrust: describeStore(
|
|
|
|
describeContents<ExchangeTrustRecord>("exchangeTrust", {
|
|
|
|
keyPath: ["currency", "exchangeBaseUrl"],
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
byExchangeMasterPub: describeIndex(
|
|
|
|
"byExchangeMasterPub",
|
|
|
|
"exchangeMasterPub",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
denominations: describeStore(
|
|
|
|
describeContents<DenominationRecord>("denominations", {
|
|
|
|
keyPath: ["exchangeBaseUrl", "denomPubHash"],
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
byExchangeBaseUrl: describeIndex("byExchangeBaseUrl", "exchangeBaseUrl"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
exchanges: describeStore(
|
|
|
|
describeContents<ExchangeRecord>("exchanges", {
|
|
|
|
keyPath: "baseUrl",
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
exchangeDetails: describeStore(
|
|
|
|
describeContents<ExchangeDetailsRecord>("exchangeDetails", {
|
2021-06-02 13:23:51 +02:00
|
|
|
keyPath: ["exchangeBaseUrl", "currency", "masterPublicKey"],
|
2021-06-09 15:14:17 +02:00
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
proposals: describeStore(
|
|
|
|
describeContents<ProposalRecord>("proposals", { keyPath: "proposalId" }),
|
2021-03-17 17:56:37 +01:00
|
|
|
{
|
2021-06-09 15:14:17 +02:00
|
|
|
byUrlAndOrderId: describeIndex("byUrlAndOrderId", [
|
|
|
|
"merchantBaseUrl",
|
|
|
|
"orderId",
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
refreshGroups: describeStore(
|
|
|
|
describeContents<RefreshGroupRecord>("refreshGroups", {
|
2021-03-17 17:56:37 +01:00
|
|
|
keyPath: "refreshGroupId",
|
2021-06-09 15:14:17 +02:00
|
|
|
}),
|
2022-01-11 21:00:12 +01:00
|
|
|
{
|
|
|
|
byStatus: describeIndex("byStatus", "operationStatus"),
|
|
|
|
},
|
2021-06-09 15:14:17 +02:00
|
|
|
),
|
|
|
|
recoupGroups: describeStore(
|
|
|
|
describeContents<RecoupGroupRecord>("recoupGroups", {
|
|
|
|
keyPath: "recoupGroupId",
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
reserves: describeStore(
|
|
|
|
describeContents<ReserveRecord>("reserves", { keyPath: "reservePub" }),
|
|
|
|
{
|
|
|
|
byInitialWithdrawalGroupId: describeIndex(
|
|
|
|
"byInitialWithdrawalGroupId",
|
|
|
|
"initialWithdrawalGroupId",
|
|
|
|
),
|
2022-01-11 21:00:12 +01:00
|
|
|
byStatus: describeIndex("byStatus", "operationStatus"),
|
2021-03-17 17:56:37 +01:00
|
|
|
},
|
|
|
|
),
|
2021-06-09 15:14:17 +02:00
|
|
|
purchases: describeStore(
|
|
|
|
describeContents<PurchaseRecord>("purchases", { keyPath: "proposalId" }),
|
2021-03-17 17:56:37 +01:00
|
|
|
{
|
2021-06-09 15:14:17 +02:00
|
|
|
byFulfillmentUrl: describeIndex(
|
|
|
|
"byFulfillmentUrl",
|
|
|
|
"download.contractData.fulfillmentUrl",
|
|
|
|
),
|
2021-06-10 10:00:36 +02:00
|
|
|
byMerchantUrlAndOrderId: describeIndex("byMerchantUrlAndOrderId", [
|
2021-06-09 15:14:17 +02:00
|
|
|
"download.contractData.merchantBaseUrl",
|
|
|
|
"download.contractData.orderId",
|
|
|
|
]),
|
2021-03-17 17:56:37 +01:00
|
|
|
},
|
|
|
|
),
|
2021-06-09 15:14:17 +02:00
|
|
|
tips: describeStore(
|
|
|
|
describeContents<TipRecord>("tips", { keyPath: "walletTipId" }),
|
|
|
|
{
|
|
|
|
byMerchantTipIdAndBaseUrl: describeIndex("byMerchantTipIdAndBaseUrl", [
|
|
|
|
"merchantTipId",
|
|
|
|
"merchantBaseUrl",
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
withdrawalGroups: describeStore(
|
|
|
|
describeContents<WithdrawalGroupRecord>("withdrawalGroups", {
|
|
|
|
keyPath: "withdrawalGroupId",
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
byReservePub: describeIndex("byReservePub", "reservePub"),
|
2022-01-11 21:00:12 +01:00
|
|
|
byStatus: describeIndex("byStatus", "operationStatus"),
|
2021-06-09 15:14:17 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
planchets: describeStore(
|
|
|
|
describeContents<PlanchetRecord>("planchets", { keyPath: "coinPub" }),
|
|
|
|
{
|
|
|
|
byGroupAndIndex: describeIndex("byGroupAndIndex", [
|
|
|
|
"withdrawalGroupId",
|
|
|
|
"coinIdx",
|
|
|
|
]),
|
|
|
|
byGroup: describeIndex("byGroup", "withdrawalGroupId"),
|
|
|
|
byCoinEvHash: describeIndex("byCoinEv", "coinEvHash"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
bankWithdrawUris: describeStore(
|
|
|
|
describeContents<BankWithdrawUriRecord>("bankWithdrawUris", {
|
|
|
|
keyPath: "talerWithdrawUri",
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
backupProviders: describeStore(
|
|
|
|
describeContents<BackupProviderRecord>("backupProviders", {
|
|
|
|
keyPath: "baseUrl",
|
|
|
|
}),
|
2021-06-25 13:27:06 +02:00
|
|
|
{
|
|
|
|
byPaymentProposalId: describeIndex(
|
|
|
|
"byPaymentProposalId",
|
|
|
|
"paymentProposalIds",
|
|
|
|
{
|
|
|
|
multiEntry: true,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
2021-06-09 15:14:17 +02:00
|
|
|
),
|
|
|
|
depositGroups: describeStore(
|
|
|
|
describeContents<DepositGroupRecord>("depositGroups", {
|
|
|
|
keyPath: "depositGroupId",
|
|
|
|
}),
|
2022-01-11 21:00:12 +01:00
|
|
|
{
|
|
|
|
byStatus: describeIndex("byStatus", "operationStatus"),
|
|
|
|
},
|
2021-06-09 15:14:17 +02:00
|
|
|
),
|
|
|
|
tombstones: describeStore(
|
|
|
|
describeContents<TombstoneRecord>("tombstones", { keyPath: "id" }),
|
|
|
|
{},
|
|
|
|
),
|
|
|
|
ghostDepositGroups: describeStore(
|
|
|
|
describeContents<GhostDepositGroupRecord>("ghostDepositGroups", {
|
|
|
|
keyPath: "contractTermsHash",
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
2022-01-11 21:00:12 +01:00
|
|
|
balancesPerCurrency: describeStore(
|
|
|
|
describeContents<BalancePerCurrencyRecord>("balancesPerCurrency", {
|
|
|
|
keyPath: "currency",
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
),
|
2021-03-17 17:56:37 +01:00
|
|
|
};
|
|
|
|
|
2021-06-14 11:21:29 +02:00
|
|
|
export interface MetaConfigRecord {
|
|
|
|
key: string;
|
|
|
|
value: any;
|
|
|
|
}
|
|
|
|
|
2021-06-09 15:14:17 +02:00
|
|
|
export const walletMetadataStore = {
|
|
|
|
metaConfig: describeStore(
|
2021-06-14 11:21:29 +02:00
|
|
|
describeContents<MetaConfigRecord>("metaConfig", { keyPath: "key" }),
|
2021-06-09 15:14:17 +02:00
|
|
|
{},
|
|
|
|
),
|
2021-03-17 17:56:37 +01:00
|
|
|
};
|
2021-12-01 18:16:40 +01:00
|
|
|
|
|
|
|
export function exportDb(db: IDBDatabase): Promise<any> {
|
|
|
|
const dump = {
|
|
|
|
name: db.name,
|
|
|
|
stores: {} as { [s: string]: any },
|
|
|
|
version: db.version,
|
|
|
|
};
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const tx = db.transaction(Array.from(db.objectStoreNames));
|
|
|
|
tx.addEventListener("complete", () => {
|
|
|
|
resolve(dump);
|
|
|
|
});
|
|
|
|
// tslint:disable-next-line:prefer-for-of
|
|
|
|
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
|
|
|
const name = db.objectStoreNames[i];
|
|
|
|
const storeDump = {} as { [s: string]: any };
|
|
|
|
dump.stores[name] = storeDump;
|
|
|
|
tx.objectStore(name)
|
|
|
|
.openCursor()
|
|
|
|
.addEventListener("success", (e: Event) => {
|
|
|
|
const cursor = (e.target as any).result;
|
|
|
|
if (cursor) {
|
|
|
|
storeDump[cursor.key] = cursor.value;
|
|
|
|
cursor.continue();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-01-13 05:30:26 +01:00
|
|
|
|
|
|
|
export interface DatabaseDump {
|
2022-02-21 12:40:51 +01:00
|
|
|
name: string;
|
|
|
|
stores: { [s: string]: any };
|
|
|
|
version: string;
|
2022-01-13 05:30:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
|
|
|
|
tx.addEventListener("complete", () => {
|
|
|
|
resolve(db);
|
|
|
|
});
|
|
|
|
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
|
|
|
const name = db.objectStoreNames[i];
|
|
|
|
const storeDump = dump.stores[name];
|
|
|
|
if (!storeDump) continue;
|
2022-02-21 12:40:51 +01:00
|
|
|
Object.keys(storeDump).forEach(async (key) => {
|
|
|
|
const value = storeDump[key];
|
2022-01-13 05:30:26 +01:00
|
|
|
if (!value) return;
|
2022-02-21 12:40:51 +01:00
|
|
|
tx.objectStore(name).put(value);
|
|
|
|
});
|
2022-01-13 05:30:26 +01:00
|
|
|
}
|
2022-04-29 18:16:29 +02:00
|
|
|
tx.commit();
|
2022-01-13 05:30:26 +01:00
|
|
|
});
|
|
|
|
}
|