2017-05-30 18:33:28 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
(C) 2017 Inria and GNUnet e.V.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type definitions for messages between content scripts/pages and backend.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Messages are already documented in wxApi.
|
|
|
|
/* tslint:disable:completed-docs */
|
|
|
|
|
2019-12-02 00:42:40 +01:00
|
|
|
import { AmountJson } from "../util/amounts";
|
2019-12-12 20:53:15 +01:00
|
|
|
import * as dbTypes from "../types/dbTypes";
|
|
|
|
import * as talerTypes from "../types/talerTypes";
|
|
|
|
import * as walletTypes from "../types/walletTypes";
|
2017-05-30 18:33:28 +02:00
|
|
|
|
2018-01-23 17:05:58 +01:00
|
|
|
import { UpgradeResponse } from "./wxApi";
|
2019-12-12 20:53:15 +01:00
|
|
|
import { HistoryEvent } from "../types/history";
|
2018-01-23 17:05:58 +01:00
|
|
|
|
2017-05-30 19:00:51 +02:00
|
|
|
/**
|
|
|
|
* Message type information.
|
|
|
|
*/
|
2017-05-30 18:33:28 +02:00
|
|
|
export interface MessageMap {
|
2019-08-29 23:12:55 +02:00
|
|
|
balances: {
|
|
|
|
request: {};
|
2018-01-03 14:42:06 +01:00
|
|
|
response: walletTypes.WalletBalance;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"dump-db": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2017-05-30 19:00:51 +02:00
|
|
|
response: any;
|
|
|
|
};
|
|
|
|
"import-db": {
|
|
|
|
request: {
|
|
|
|
dump: object;
|
|
|
|
};
|
|
|
|
response: void;
|
|
|
|
};
|
2019-08-29 23:12:55 +02:00
|
|
|
ping: {
|
|
|
|
request: {};
|
2017-05-30 19:00:51 +02:00
|
|
|
response: void;
|
|
|
|
};
|
2017-06-05 03:20:28 +02:00
|
|
|
"reset-db": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2017-05-30 19:00:51 +02:00
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"create-reserve": {
|
|
|
|
request: {
|
2018-01-03 14:42:06 +01:00
|
|
|
amount: AmountJson;
|
2019-08-29 23:12:55 +02:00
|
|
|
exchange: string;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
response: void;
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"confirm-reserve": {
|
|
|
|
request: { reservePub: string };
|
|
|
|
response: void;
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"confirm-pay": {
|
2019-11-30 00:36:20 +01:00
|
|
|
request: { proposalId: string; sessionId?: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: walletTypes.ConfirmPayResult;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"exchange-info": {
|
|
|
|
request: { baseUrl: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.ExchangeRecord;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"reserve-creation-info": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: { baseUrl: string; amount: AmountJson };
|
2019-12-09 19:59:08 +01:00
|
|
|
response: walletTypes.ExchangeWithdrawDetails;
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"get-history": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2019-12-12 20:53:15 +01:00
|
|
|
response: HistoryEvent[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
2017-05-31 16:04:14 +02:00
|
|
|
"get-coins": {
|
|
|
|
request: { exchangeBaseUrl: string };
|
|
|
|
response: any;
|
|
|
|
};
|
|
|
|
"refresh-coin": {
|
|
|
|
request: { coinPub: string };
|
|
|
|
response: any;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"get-currencies": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.CurrencyRecord[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"update-currency": {
|
2018-01-03 14:42:06 +01:00
|
|
|
request: { currencyRecord: dbTypes.CurrencyRecord };
|
2017-05-30 19:00:51 +02:00
|
|
|
response: void;
|
|
|
|
};
|
2017-05-31 16:04:14 +02:00
|
|
|
"get-exchanges": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.ExchangeRecord[];
|
2017-05-31 16:04:14 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"get-reserves": {
|
|
|
|
request: { exchangeBaseUrl: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.ReserveRecord[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"get-payback-reserves": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.ReserveRecord[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"withdraw-payback-reserve": {
|
|
|
|
request: { reservePub: string };
|
2018-01-23 17:05:58 +01:00
|
|
|
response: dbTypes.ReserveRecord[];
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"get-denoms": {
|
|
|
|
request: { exchangeBaseUrl: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.DenominationRecord[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"payback-coin": {
|
|
|
|
request: { coinPub: string };
|
|
|
|
response: void;
|
|
|
|
};
|
2017-06-05 03:20:28 +02:00
|
|
|
"check-upgrade": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2018-01-23 17:05:58 +01:00
|
|
|
response: UpgradeResponse;
|
2017-06-05 03:20:28 +02:00
|
|
|
};
|
2017-08-14 04:16:12 +02:00
|
|
|
"get-sender-wire-infos": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2018-01-23 17:05:58 +01:00
|
|
|
response: walletTypes.SenderWireInfos;
|
2017-08-14 04:16:12 +02:00
|
|
|
};
|
|
|
|
"return-coins": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: {};
|
2017-08-14 04:16:12 +02:00
|
|
|
response: void;
|
|
|
|
};
|
2019-08-31 13:27:12 +02:00
|
|
|
"get-purchase-details": {
|
2018-01-23 17:05:58 +01:00
|
|
|
request: { contractTermsHash: string };
|
2019-08-31 13:27:12 +02:00
|
|
|
response: walletTypes.PurchaseDetails;
|
2017-08-30 17:08:54 +02:00
|
|
|
};
|
2017-11-30 04:07:36 +01:00
|
|
|
"accept-tip": {
|
2019-08-30 17:27:59 +02:00
|
|
|
request: { talerTipUri: string };
|
|
|
|
response: void;
|
2017-11-30 04:07:36 +01:00
|
|
|
};
|
|
|
|
"get-tip-status": {
|
2019-08-30 17:27:59 +02:00
|
|
|
request: { talerTipUri: string };
|
2018-01-23 17:05:58 +01:00
|
|
|
response: walletTypes.TipStatus;
|
2017-11-30 04:07:36 +01:00
|
|
|
};
|
2018-01-22 01:12:08 +01:00
|
|
|
"accept-refund": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: { refundUrl: string };
|
2018-01-22 01:12:08 +01:00
|
|
|
response: string;
|
|
|
|
};
|
2018-01-29 16:41:17 +01:00
|
|
|
"abort-failed-payment": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: { contractTermsHash: string };
|
2018-01-29 16:41:17 +01:00
|
|
|
response: void;
|
|
|
|
};
|
2018-09-20 02:56:13 +02:00
|
|
|
"benchmark-crypto": {
|
2019-08-29 23:12:55 +02:00
|
|
|
request: { repetitions: number };
|
2018-09-20 02:56:13 +02:00
|
|
|
response: walletTypes.BenchmarkResult;
|
|
|
|
};
|
2019-08-29 23:12:55 +02:00
|
|
|
"get-withdraw-details": {
|
|
|
|
request: { talerWithdrawUri: string; maybeSelectedExchange: string | undefined };
|
|
|
|
response: walletTypes.WithdrawDetails;
|
|
|
|
};
|
|
|
|
"accept-withdrawal": {
|
|
|
|
request: { talerWithdrawUri: string; selectedExchange: string };
|
|
|
|
response: walletTypes.AcceptWithdrawalResponse;
|
|
|
|
};
|
|
|
|
"prepare-pay": {
|
|
|
|
request: { talerPayUri: string };
|
|
|
|
response: walletTypes.PreparePayResult;
|
|
|
|
};
|
2019-09-05 16:10:53 +02:00
|
|
|
"get-diagnostics": {
|
|
|
|
request: { };
|
|
|
|
response: walletTypes.WalletDiagnostics;
|
|
|
|
};
|
2017-05-30 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 23:12:55 +02:00
|
|
|
|
2017-05-30 19:00:51 +02:00
|
|
|
/**
|
|
|
|
* String literal types for messages.
|
|
|
|
*/
|
2017-05-30 18:33:28 +02:00
|
|
|
export type MessageType = keyof MessageMap;
|
|
|
|
|
2017-05-30 19:00:51 +02:00
|
|
|
/**
|
|
|
|
* Make a request whose details match the request type.
|
|
|
|
*/
|
2019-08-29 23:12:55 +02:00
|
|
|
export function makeRequest<T extends MessageType>(
|
|
|
|
type: T,
|
|
|
|
details: MessageMap[T]["request"],
|
|
|
|
) {
|
2017-05-30 19:00:51 +02:00
|
|
|
return { type, details };
|
2017-05-30 18:33:28 +02:00
|
|
|
}
|
2017-05-30 19:00:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a response that matches the request type.
|
|
|
|
*/
|
2019-08-29 23:12:55 +02:00
|
|
|
export function makeResponse<T extends MessageType>(
|
|
|
|
type: T,
|
|
|
|
response: MessageMap[T]["response"],
|
|
|
|
) {
|
2017-05-30 19:00:51 +02:00
|
|
|
return response;
|
|
|
|
}
|