wallet-core/src/webex/messages.ts

251 lines
5.9 KiB
TypeScript
Raw Normal View History

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 */
import { AmountJson } from "../amounts";
import * as dbTypes from "../dbTypes";
import * as talerTypes from "../talerTypes";
import * as walletTypes from "../walletTypes";
2017-05-30 18:33:28 +02:00
2018-01-23 17:05:58 +01:00
import { UpgradeResponse } from "./wxApi";
/**
* Message type information.
*/
2017-05-30 18:33:28 +02:00
export interface MessageMap {
balances: {
request: {};
response: walletTypes.WalletBalance;
};
"dump-db": {
request: {};
response: any;
};
"import-db": {
request: {
dump: object;
};
response: void;
};
ping: {
request: {};
response: void;
};
2017-06-05 03:20:28 +02:00
"reset-db": {
request: {};
response: void;
};
"create-reserve": {
request: {
amount: AmountJson;
exchange: string;
};
response: void;
2017-10-15 19:28:35 +02:00
};
"confirm-reserve": {
request: { reservePub: string };
response: void;
2017-10-15 19:28:35 +02:00
};
"confirm-pay": {
request: { proposalId: number; sessionId?: string };
response: walletTypes.ConfirmPayResult;
};
"check-pay": {
request: { proposalId: number };
response: walletTypes.CheckPayResult;
};
"query-payment": {
request: {};
2018-01-23 17:05:58 +01:00
response: dbTypes.PurchaseRecord;
};
"exchange-info": {
request: { baseUrl: string };
response: dbTypes.ExchangeRecord;
};
"currency-info": {
request: { name: string };
response: dbTypes.CurrencyRecord;
};
"hash-contract": {
request: { contract: object };
response: string;
};
"reserve-creation-info": {
request: { baseUrl: string; amount: AmountJson };
response: walletTypes.ReserveCreationInfo;
2017-10-15 19:28:35 +02:00
};
"get-history": {
request: {};
response: walletTypes.HistoryRecord[];
};
"get-proposal": {
request: { proposalId: number };
response: dbTypes.ProposalDownloadRecord | undefined;
};
"get-coins": {
request: { exchangeBaseUrl: string };
response: any;
};
"refresh-coin": {
request: { coinPub: string };
response: any;
};
"get-currencies": {
request: {};
response: dbTypes.CurrencyRecord[];
};
"update-currency": {
request: { currencyRecord: dbTypes.CurrencyRecord };
response: void;
};
"get-exchanges": {
request: {};
response: dbTypes.ExchangeRecord[];
};
"get-reserves": {
request: { exchangeBaseUrl: string };
response: dbTypes.ReserveRecord[];
};
"get-payback-reserves": {
request: {};
response: dbTypes.ReserveRecord[];
};
"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
};
"get-precoins": {
request: { exchangeBaseUrl: string };
response: dbTypes.PreCoinRecord[];
};
"get-denoms": {
request: { exchangeBaseUrl: string };
response: dbTypes.DenominationRecord[];
};
"payback-coin": {
request: { coinPub: string };
response: void;
};
2017-06-05 03:20:28 +02:00
"check-upgrade": {
request: {};
2018-01-23 17:05:58 +01:00
response: UpgradeResponse;
2017-06-05 03:20:28 +02:00
};
"get-sender-wire-infos": {
request: {};
2018-01-23 17:05:58 +01:00
response: walletTypes.SenderWireInfos;
};
"return-coins": {
request: {};
response: void;
};
"log-and-display-error": {
request: any;
response: void;
};
"get-report": {
request: { reportUid: string };
response: void;
};
2017-08-27 03:56:19 +02:00
"get-purchase": {
2018-01-23 17:05:58 +01:00
request: { contractTermsHash: string };
response: dbTypes.PurchaseRecord;
};
"get-full-refund-fees": {
request: { refundPermissions: talerTypes.MerchantRefundPermission[] };
2018-01-23 17:05:58 +01:00
response: AmountJson;
};
2017-11-30 04:07:36 +01:00
"accept-tip": {
request: { tipToken: talerTypes.TipToken };
2018-01-23 17:05:58 +01:00
response: walletTypes.TipStatus;
2017-11-30 04:07:36 +01:00
};
"get-tip-status": {
request: { tipToken: talerTypes.TipToken };
2018-01-23 17:05:58 +01:00
response: walletTypes.TipStatus;
2017-11-30 04:07:36 +01:00
};
"clear-notification": {
request: {};
response: void;
};
"taler-pay": {
request: any;
response: void;
};
"download-proposal": {
2018-01-23 17:05:58 +01:00
request: { url: string };
response: number;
};
"submit-pay": {
request: { contractTermsHash: string; sessionId: string | undefined };
2018-01-23 17:05:58 +01:00
response: walletTypes.ConfirmPayResult;
};
2018-01-22 01:12:08 +01:00
"accept-refund": {
request: { refundUrl: string };
2018-01-22 01:12:08 +01:00
response: string;
};
"abort-failed-payment": {
request: { contractTermsHash: string };
response: void;
};
2018-09-20 02:56:13 +02:00
"benchmark-crypto": {
request: { repetitions: number };
2018-09-20 02:56:13 +02:00
response: walletTypes.BenchmarkResult;
};
"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;
};
2017-05-30 18:33:28 +02:00
}
/**
* String literal types for messages.
*/
2017-05-30 18:33:28 +02:00
export type MessageType = keyof MessageMap;
/**
* Make a request whose details match the request type.
*/
export function makeRequest<T extends MessageType>(
type: T,
details: MessageMap[T]["request"],
) {
return { type, details };
2017-05-30 18:33:28 +02:00
}
/**
* Make a response that matches the request type.
*/
export function makeResponse<T extends MessageType>(
type: T,
response: MessageMap[T]["response"],
) {
return response;
}