diff options
Diffstat (limited to 'packages/anastasis-core/src/provider-types.ts')
-rw-r--r-- | packages/anastasis-core/src/provider-types.ts | 142 |
1 files changed, 140 insertions, 2 deletions
diff --git a/packages/anastasis-core/src/provider-types.ts b/packages/anastasis-core/src/provider-types.ts index b477c09b9..1724b0ed1 100644 --- a/packages/anastasis-core/src/provider-types.ts +++ b/packages/anastasis-core/src/provider-types.ts @@ -1,4 +1,31 @@ -import { AmountString } from "@gnu-taler/taler-util"; +/* + This file is part of GNU Anastasis + (C) 2021-2022 Anastasis SARL + + GNU Anastasis is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Anastasis 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import { + AmountString, + buildCodecForObject, + buildCodecForUnion, + Codec, + codecForAmountString, + codecForAny, + codecForConstString, + codecForNumber, + codecForString, + TalerProtocolTimestamp, +} from "@gnu-taler/taler-util"; export interface EscrowConfigurationResponse { // Protocol identifier, clarifies that this is an Anastasis provider. @@ -35,8 +62,11 @@ export interface EscrowConfigurationResponse { // **provider salt** is then used in various operations to ensure // cryptographic operations differ by provider. A provider must // never change its salt value. - server_salt: string; + provider_salt: string; + /** + * Human-readable business name of the provider. + */ business_name: string; } @@ -72,3 +102,111 @@ export interface TruthUploadRequest { // store the truth? storage_duration_years: number; } + +export interface IbanExternalAuthResponse { + method: "iban"; + answer_code: number; + details: { + challenge_amount: AmountString; + credit_iban: string; + business_name: string; + wire_transfer_subject: string; + }; +} + +export interface RecoveryMetaResponse { + /** + * Version numbers as a string (!) are used as keys. + */ + [version: string]: RecoveryMetaDataItem; +} + +export interface RecoveryMetaDataItem { + // The meta value can be NULL if the document + // exists but no meta data was provided. + meta?: string; + + // Server-time indicative of when the recovery + // document was uploaded. + upload_time: TalerProtocolTimestamp; +} + +export type ChallengeInstructionMessage = + | FileChallengeInstructionMessage + | IbanChallengeInstructionMessage + | PinChallengeInstructionMessage; + +export interface IbanChallengeInstructionMessage { + // What kind of challenge is this? + challenge_type: "IBAN_WIRE"; + + wire_details: { + // How much should be wired? + challenge_amount: AmountString; + + // What is the target IBAN? + credit_iban: string; + + // What is the receiver name? + business_name: string; + + // What is the expected wire transfer subject? + wire_transfer_subject: string; + + // What is the numeric code (also part of the + // wire transfer subject) to be hashed when + // solving the challenge? + answer_code: number; + + // Hint about the origin account that must be used. + debit_account_hint: string; + }; +} + +export interface PinChallengeInstructionMessage { + // What kind of challenge is this? + challenge_type: "TAN_SENT"; + + // Where was the PIN code sent? Note that this + // address will most likely have been obscured + // to improve privacy. + tan_address_hint: string; +} + +export interface FileChallengeInstructionMessage { + // What kind of challenge is this? + challenge_type: "FILE_WRITTEN"; + + // Name of the file where the PIN code was written. + filename: string; +} + +export const codecForFileChallengeInstructionMessage = + (): Codec<FileChallengeInstructionMessage> => + buildCodecForObject<FileChallengeInstructionMessage>() + .property("challenge_type", codecForConstString("FILE_WRITTEN")) + .property("filename", codecForString()) + .build("FileChallengeInstructionMessage"); + +export const codecForPinChallengeInstructionMessage = + (): Codec<PinChallengeInstructionMessage> => + buildCodecForObject<PinChallengeInstructionMessage>() + .property("challenge_type", codecForConstString("TAN_SENT")) + .property("tan_address_hint", codecForString()) + .build("PinChallengeInstructionMessage"); + +export const codecForIbanChallengeInstructionMessage = + (): Codec<IbanChallengeInstructionMessage> => + buildCodecForObject<IbanChallengeInstructionMessage>() + .property("challenge_type", codecForConstString("IBAN_WIRE")) + .property("wire_details", codecForAny()) + .build("IbanChallengeInstructionMessage"); + +export const codecForChallengeInstructionMessage = + (): Codec<ChallengeInstructionMessage> => + buildCodecForUnion<ChallengeInstructionMessage>() + .discriminateOn("challenge_type") + .alternative("FILE_WRITTEN", codecForFileChallengeInstructionMessage()) + .alternative("IBAN_WIRE", codecForIbanChallengeInstructionMessage()) + .alternative("TAN_SENT", codecForPinChallengeInstructionMessage()) + .build("ChallengeInstructionMessage"); |