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 */
|
|
|
|
|
2018-01-03 14:42:06 +01:00
|
|
|
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
|
|
|
|
2017-05-30 19:00:51 +02:00
|
|
|
/**
|
|
|
|
* Message type information.
|
|
|
|
*/
|
2017-05-30 18:33:28 +02:00
|
|
|
export interface MessageMap {
|
2017-05-30 19:00:51 +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": {
|
|
|
|
request: { };
|
|
|
|
response: any;
|
|
|
|
};
|
|
|
|
"import-db": {
|
|
|
|
request: {
|
|
|
|
dump: object;
|
|
|
|
};
|
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"ping": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
2017-06-05 03:20:28 +02:00
|
|
|
"reset-db": {
|
2017-05-30 19:00:51 +02:00
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"create-reserve": {
|
|
|
|
request: {
|
2018-01-03 14:42:06 +01:00
|
|
|
amount: AmountJson;
|
2017-10-15 19:28:35 +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": {
|
2018-01-17 03:49:54 +01:00
|
|
|
request: { proposalId: number; sessionId?: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: walletTypes.ConfirmPayResult;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"check-pay": {
|
2017-05-31 16:04:14 +02:00
|
|
|
request: { proposalId: number; };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: walletTypes.CheckPayResult;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"query-payment": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"exchange-info": {
|
|
|
|
request: { baseUrl: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.ExchangeRecord;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"currency-info": {
|
|
|
|
request: { name: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.CurrencyRecord;
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
|
|
|
"hash-contract": {
|
|
|
|
request: { contract: object };
|
|
|
|
response: string;
|
|
|
|
};
|
|
|
|
"reserve-creation-info": {
|
2018-01-03 14:42:06 +01:00
|
|
|
request: { baseUrl: string, amount: AmountJson };
|
|
|
|
response: walletTypes.ReserveCreationInfo;
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"get-history": {
|
|
|
|
request: { };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: walletTypes.HistoryRecord[];
|
2017-05-30 19:00:51 +02:00
|
|
|
};
|
2017-05-31 16:04:14 +02:00
|
|
|
"get-proposal": {
|
|
|
|
request: { proposalId: number };
|
2018-01-17 03:49:54 +01:00
|
|
|
response: dbTypes.ProposalDownloadRecord | undefined;
|
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": {
|
|
|
|
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": {
|
|
|
|
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": {
|
|
|
|
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 };
|
|
|
|
response: void;
|
2017-10-15 19:28:35 +02:00
|
|
|
};
|
2017-05-30 19:00:51 +02:00
|
|
|
"get-precoins": {
|
|
|
|
request: { exchangeBaseUrl: string };
|
2018-01-03 14:42:06 +01:00
|
|
|
response: dbTypes.PreCoinRecord[];
|
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": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
2017-08-14 04:16:12 +02:00
|
|
|
"get-sender-wire-infos": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"return-coins": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
2017-08-25 18:08:37 +02:00
|
|
|
"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": {
|
|
|
|
request: any;
|
|
|
|
response: void;
|
2017-08-30 17:08:54 +02:00
|
|
|
};
|
|
|
|
"get-full-refund-fees": {
|
2018-01-03 14:42:06 +01:00
|
|
|
request: { refundPermissions: talerTypes.RefundPermission[] };
|
2017-08-30 17:08:54 +02:00
|
|
|
response: void;
|
|
|
|
};
|
2017-11-30 04:07:36 +01:00
|
|
|
"accept-tip": {
|
2018-01-19 01:27:27 +01:00
|
|
|
request: { tipToken: talerTypes.TipToken };
|
2017-11-30 04:07:36 +01:00
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"get-tip-status": {
|
2018-01-19 01:27:27 +01:00
|
|
|
request: { tipToken: talerTypes.TipToken };
|
2017-11-30 04:07:36 +01:00
|
|
|
response: void;
|
|
|
|
};
|
2017-12-12 16:39:55 +01:00
|
|
|
"clear-notification": {
|
|
|
|
request: { };
|
|
|
|
response: void;
|
|
|
|
};
|
2018-01-17 03:49:54 +01:00
|
|
|
"taler-pay": {
|
|
|
|
request: any;
|
|
|
|
response: void;
|
|
|
|
};
|
|
|
|
"download-proposal": {
|
|
|
|
request: any;
|
|
|
|
response: void;
|
|
|
|
};
|
2018-01-19 01:27:27 +01:00
|
|
|
"submit-pay": {
|
|
|
|
request: { contractTermsHash: string, sessionId: string | undefined };
|
|
|
|
response: void;
|
|
|
|
};
|
2018-01-22 01:12:08 +01:00
|
|
|
"accept-refund": {
|
|
|
|
request: { refundUrl: string }
|
|
|
|
response: string;
|
|
|
|
};
|
2017-05-30 18:33:28 +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.
|
|
|
|
*/
|
|
|
|
export function makeRequest<T extends MessageType>(type: T, details: MessageMap[T]["request"]) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
export function makeResponse<T extends MessageType>(type: T, response: MessageMap[T]["response"]) {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|