@coderoftime/fints 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +28 -0
- package/README.md +156 -2
- package/dist/core/account.d.ts +140 -0
- package/dist/core/account.d.ts.map +1 -0
- package/dist/core/account.js +174 -0
- package/dist/core/account.js.map +1 -0
- package/dist/core/amount.d.ts +62 -0
- package/dist/core/amount.d.ts.map +1 -0
- package/dist/core/amount.js +189 -0
- package/dist/core/amount.js.map +1 -0
- package/dist/core/balance.d.ts +54 -0
- package/dist/core/balance.d.ts.map +1 -0
- package/dist/core/balance.js +53 -0
- package/dist/core/balance.js.map +1 -0
- package/dist/core/bank-info.d.ts +49 -0
- package/dist/core/bank-info.d.ts.map +1 -0
- package/dist/core/bank-info.js +52 -0
- package/dist/core/bank-info.js.map +1 -0
- package/dist/core/client.d.ts +126 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +2 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/config.d.ts +68 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +113 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +91 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +182 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/feedback.d.ts +69 -0
- package/dist/core/feedback.d.ts.map +1 -0
- package/dist/core/feedback.js +124 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/transaction.d.ts +98 -0
- package/dist/core/transaction.d.ts.map +1 -0
- package/dist/core/transaction.js +91 -0
- package/dist/core/transaction.js.map +1 -0
- package/dist/core/transport.d.ts +37 -0
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/transport.js +92 -0
- package/dist/core/transport.js.map +1 -0
- package/dist/formats/camt.d.ts +12 -0
- package/dist/formats/camt.d.ts.map +1 -0
- package/dist/formats/camt.js +159 -0
- package/dist/formats/camt.js.map +1 -0
- package/dist/formats/mt940.d.ts +42 -0
- package/dist/formats/mt940.d.ts.map +1 -0
- package/dist/formats/mt940.js +297 -0
- package/dist/formats/mt940.js.map +1 -0
- package/dist/formats/readers.d.ts +11 -0
- package/dist/formats/readers.d.ts.map +1 -0
- package/dist/formats/readers.js +47 -0
- package/dist/formats/readers.js.map +1 -0
- package/dist/formats/sepa-purpose.d.ts +22 -0
- package/dist/formats/sepa-purpose.d.ts.map +1 -0
- package/dist/formats/sepa-purpose.js +68 -0
- package/dist/formats/sepa-purpose.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/session/app-approval.d.ts +60 -0
- package/dist/session/app-approval.d.ts.map +1 -0
- package/dist/session/app-approval.js +215 -0
- package/dist/session/app-approval.js.map +1 -0
- package/dist/session/bank-connection.d.ts +28 -0
- package/dist/session/bank-connection.d.ts.map +1 -0
- package/dist/session/bank-connection.js +48 -0
- package/dist/session/bank-connection.js.map +1 -0
- package/dist/session/dialog-runner.d.ts +34 -0
- package/dist/session/dialog-runner.d.ts.map +1 -0
- package/dist/session/dialog-runner.js +112 -0
- package/dist/session/dialog-runner.js.map +1 -0
- package/dist/session/login-guard.d.ts +73 -0
- package/dist/session/login-guard.d.ts.map +1 -0
- package/dist/session/login-guard.js +109 -0
- package/dist/session/login-guard.js.map +1 -0
- package/dist/session/parameter-data.d.ts +83 -0
- package/dist/session/parameter-data.d.ts.map +1 -0
- package/dist/session/parameter-data.js +68 -0
- package/dist/session/parameter-data.js.map +1 -0
- package/dist/session/pin-tan-client.d.ts +54 -0
- package/dist/session/pin-tan-client.d.ts.map +1 -0
- package/dist/session/pin-tan-client.js +153 -0
- package/dist/session/pin-tan-client.js.map +1 -0
- package/dist/session/pin-tan-dialog.d.ts +71 -0
- package/dist/session/pin-tan-dialog.d.ts.map +1 -0
- package/dist/session/pin-tan-dialog.js +124 -0
- package/dist/session/pin-tan-dialog.js.map +1 -0
- package/dist/session/protocol.d.ts +209 -0
- package/dist/session/protocol.d.ts.map +1 -0
- package/dist/session/protocol.js +75 -0
- package/dist/session/protocol.js.map +1 -0
- package/dist/session/response-handler.d.ts +48 -0
- package/dist/session/response-handler.d.ts.map +1 -0
- package/dist/session/response-handler.js +121 -0
- package/dist/session/response-handler.js.map +1 -0
- package/dist/session/sepa-accounts.d.ts +34 -0
- package/dist/session/sepa-accounts.d.ts.map +1 -0
- package/dist/session/sepa-accounts.js +96 -0
- package/dist/session/sepa-accounts.js.map +1 -0
- package/dist/session/session-setup.d.ts +72 -0
- package/dist/session/session-setup.d.ts.map +1 -0
- package/dist/session/session-setup.js +160 -0
- package/dist/session/session-setup.js.map +1 -0
- package/dist/session/session-state.d.ts +47 -0
- package/dist/session/session-state.d.ts.map +1 -0
- package/dist/session/session-state.js +147 -0
- package/dist/session/session-state.js.map +1 -0
- package/dist/session/tan-selection.d.ts +88 -0
- package/dist/session/tan-selection.d.ts.map +1 -0
- package/dist/session/tan-selection.js +178 -0
- package/dist/session/tan-selection.js.map +1 -0
- package/dist/session/user-prompts.d.ts +61 -0
- package/dist/session/user-prompts.d.ts.map +1 -0
- package/dist/session/user-prompts.js +164 -0
- package/dist/session/user-prompts.js.map +1 -0
- package/dist/tan/challenge.d.ts +114 -0
- package/dist/tan/challenge.d.ts.map +1 -0
- package/dist/tan/challenge.js +185 -0
- package/dist/tan/challenge.js.map +1 -0
- package/dist/tan/flicker.d.ts +36 -0
- package/dist/tan/flicker.d.ts.map +1 -0
- package/dist/tan/flicker.js +262 -0
- package/dist/tan/flicker.js.map +1 -0
- package/dist/tan/tan-image.d.ts +21 -0
- package/dist/tan/tan-image.d.ts.map +1 -0
- package/dist/tan/tan-image.js +41 -0
- package/dist/tan/tan-image.js.map +1 -0
- package/dist/tan/tan-models.d.ts +145 -0
- package/dist/tan/tan-models.d.ts.map +1 -0
- package/dist/tan/tan-models.js +148 -0
- package/dist/tan/tan-models.js.map +1 -0
- package/dist/util/async.d.ts +24 -0
- package/dist/util/async.d.ts.map +1 -0
- package/dist/util/async.js +49 -0
- package/dist/util/async.js.map +1 -0
- package/dist/util/bytes.d.ts +23 -0
- package/dist/util/bytes.d.ts.map +1 -0
- package/dist/util/bytes.js +136 -0
- package/dist/util/bytes.js.map +1 -0
- package/dist/util/call-context.d.ts +12 -0
- package/dist/util/call-context.d.ts.map +1 -0
- package/dist/util/call-context.js +29 -0
- package/dist/util/call-context.js.map +1 -0
- package/dist/util/dates.d.ts +62 -0
- package/dist/util/dates.d.ts.map +1 -0
- package/dist/util/dates.js +169 -0
- package/dist/util/dates.js.map +1 -0
- package/dist/util/errors.d.ts +9 -0
- package/dist/util/errors.d.ts.map +1 -0
- package/dist/util/errors.js +15 -0
- package/dist/util/errors.js.map +1 -0
- package/dist/util/immutable-map.d.ts +16 -0
- package/dist/util/immutable-map.d.ts.map +1 -0
- package/dist/util/immutable-map.js +38 -0
- package/dist/util/immutable-map.js.map +1 -0
- package/dist/util/json.d.ts +13 -0
- package/dist/util/json.d.ts.map +1 -0
- package/dist/util/json.js +44 -0
- package/dist/util/json.js.map +1 -0
- package/dist/util/text.d.ts +20 -0
- package/dist/util/text.d.ts.map +1 -0
- package/dist/util/text.js +78 -0
- package/dist/util/text.js.map +1 -0
- package/dist/util/xml.d.ts +35 -0
- package/dist/util/xml.d.ts.map +1 -0
- package/dist/util/xml.js +183 -0
- package/dist/util/xml.js.map +1 -0
- package/dist/v3/account-extension.d.ts +25 -0
- package/dist/v3/account-extension.d.ts.map +1 -0
- package/dist/v3/account-extension.js +176 -0
- package/dist/v3/account-extension.js.map +1 -0
- package/dist/v3/client.d.ts +24 -0
- package/dist/v3/client.d.ts.map +1 -0
- package/dist/v3/client.js +16 -0
- package/dist/v3/client.js.map +1 -0
- package/dist/v3/dialog.d.ts +78 -0
- package/dist/v3/dialog.d.ts.map +1 -0
- package/dist/v3/dialog.js +138 -0
- package/dist/v3/dialog.js.map +1 -0
- package/dist/v3/message.d.ts +72 -0
- package/dist/v3/message.d.ts.map +1 -0
- package/dist/v3/message.js +259 -0
- package/dist/v3/message.js.map +1 -0
- package/dist/v3/parameters.d.ts +79 -0
- package/dist/v3/parameters.d.ts.map +1 -0
- package/dist/v3/parameters.js +396 -0
- package/dist/v3/parameters.js.map +1 -0
- package/dist/v3/protocol.d.ts +68 -0
- package/dist/v3/protocol.d.ts.map +1 -0
- package/dist/v3/protocol.js +263 -0
- package/dist/v3/protocol.js.map +1 -0
- package/dist/v3/segments.d.ts +89 -0
- package/dist/v3/segments.d.ts.map +1 -0
- package/dist/v3/segments.js +283 -0
- package/dist/v3/segments.js.map +1 -0
- package/dist/v3/syntax.d.ts +76 -0
- package/dist/v3/syntax.d.ts.map +1 -0
- package/dist/v3/syntax.js +301 -0
- package/dist/v3/syntax.js.map +1 -0
- package/package.json +63 -4
- package/src/core/account.ts +250 -0
- package/src/core/amount.ts +209 -0
- package/src/core/balance.ts +84 -0
- package/src/core/bank-info.ts +66 -0
- package/src/core/client.ts +149 -0
- package/src/core/config.ts +141 -0
- package/src/core/errors.ts +203 -0
- package/src/core/feedback.ts +137 -0
- package/src/core/transaction.ts +156 -0
- package/src/core/transport.ts +114 -0
- package/src/formats/camt.ts +169 -0
- package/src/formats/mt940.ts +333 -0
- package/src/formats/readers.ts +56 -0
- package/src/formats/sepa-purpose.ts +75 -0
- package/src/index.ts +68 -0
- package/src/session/app-approval.ts +265 -0
- package/src/session/bank-connection.ts +51 -0
- package/src/session/dialog-runner.ts +119 -0
- package/src/session/login-guard.ts +135 -0
- package/src/session/parameter-data.ts +137 -0
- package/src/session/pin-tan-client.ts +186 -0
- package/src/session/pin-tan-dialog.ts +160 -0
- package/src/session/protocol.ts +311 -0
- package/src/session/response-handler.ts +130 -0
- package/src/session/sepa-accounts.ts +97 -0
- package/src/session/session-setup.ts +165 -0
- package/src/session/session-state.ts +170 -0
- package/src/session/tan-selection.ts +192 -0
- package/src/session/user-prompts.ts +174 -0
- package/src/tan/challenge.ts +252 -0
- package/src/tan/flicker.ts +270 -0
- package/src/tan/tan-image.ts +36 -0
- package/src/tan/tan-models.ts +247 -0
- package/src/util/async.ts +53 -0
- package/src/util/bytes.ts +135 -0
- package/src/util/call-context.ts +40 -0
- package/src/util/dates.ts +193 -0
- package/src/util/errors.ts +16 -0
- package/src/util/immutable-map.ts +47 -0
- package/src/util/json.ts +51 -0
- package/src/util/text.ts +82 -0
- package/src/util/xml.ts +172 -0
- package/src/v3/account-extension.ts +190 -0
- package/src/v3/client.ts +29 -0
- package/src/v3/dialog.ts +199 -0
- package/src/v3/message.ts +321 -0
- package/src/v3/parameters.ts +451 -0
- package/src/v3/protocol.ts +331 -0
- package/src/v3/segments.ts +331 -0
- package/src/v3/syntax.ts +307 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Internal to the package, and named after the FinTS specification. Documentation is where the meaning is not evident.
|
|
2
|
+
|
|
3
|
+
import type { Account } from '../core/account.js';
|
|
4
|
+
import type { Balance } from '../core/balance.js';
|
|
5
|
+
import type { MessageLogger } from '../core/client.js';
|
|
6
|
+
import { requirePin, type FinTsConfig } from '../core/config.js';
|
|
7
|
+
import { FinTsError, FinTsTransportError, FinTsUnsupportedError } from '../core/errors.js';
|
|
8
|
+
import { hasErrors } from '../core/feedback.js';
|
|
9
|
+
import type { Transaction, TransactionFormat } from '../core/transaction.js';
|
|
10
|
+
import type { FinTsTransport } from '../core/transport.js';
|
|
11
|
+
import { camtTransactions, mt940Transactions } from '../formats/readers.js';
|
|
12
|
+
import { BankConnection, checkMessageSize } from '../session/bank-connection.js';
|
|
13
|
+
import { LoginGuard } from '../session/login-guard.js';
|
|
14
|
+
import { offeredVersion, requireBankParameters } from '../session/parameter-data.js';
|
|
15
|
+
import {
|
|
16
|
+
balanceQuery,
|
|
17
|
+
checkBeforeSigning,
|
|
18
|
+
chooseTransactions,
|
|
19
|
+
type PinTanProtocol,
|
|
20
|
+
type Query,
|
|
21
|
+
type Synchronization,
|
|
22
|
+
} from '../session/protocol.js';
|
|
23
|
+
import type { TanMedium, TanMethod } from '../tan/tan-models.js';
|
|
24
|
+
import { invalidArgument } from '../util/errors.js';
|
|
25
|
+
import { readOptionalString, type JsonObject } from '../util/json.js';
|
|
26
|
+
import { decodeBankText } from '../util/text.js';
|
|
27
|
+
import { FinTs3Dialog, type FinTs3DialogHost, type Signing3 } from './dialog.js';
|
|
28
|
+
import { buildMessage, decodeTransport, encodeTransport, IncomingMessage3 } from './message.js';
|
|
29
|
+
import { Bpd3, decodeSegments, encodeSegments, Upd3 } from './parameters.js';
|
|
30
|
+
import { balanceAccount, parseBalance, parseSepaAccounts, parseTanMedia, Segments } from './segments.js';
|
|
31
|
+
import { isLatin1, type Segment, type SegmentSpec } from './syntax.js';
|
|
32
|
+
|
|
33
|
+
/** Customer ID the specification reserves for anonymous dialogs. */
|
|
34
|
+
const anonymousCustomerId = '9999999999';
|
|
35
|
+
|
|
36
|
+
/** Longest product ID (Produktbezeichnung) and product version HKVVB takes. */
|
|
37
|
+
const maxProductIdLength = 25;
|
|
38
|
+
const maxProductVersionLength = 5;
|
|
39
|
+
|
|
40
|
+
/** A business transaction in FinTS 3.0. */
|
|
41
|
+
export type FinTs3Query<T> = Query<IncomingMessage3, SegmentSpec, T>;
|
|
42
|
+
|
|
43
|
+
function requireLatin1(text: string, name: string): string {
|
|
44
|
+
// The message leaves out the value, which may be the PIN.
|
|
45
|
+
if (!isLatin1(text)) throw invalidArgument(`${name} contains characters FinTS 3.0 cannot send (ISO 8859-1 only)`);
|
|
46
|
+
return text;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function requireMaxLength(text: string, maxLength: number, name: string): void {
|
|
50
|
+
if (text.length > maxLength) throw invalidArgument(`At most ${maxLength} characters in FinTS 3.0`, name);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function requireSendable(config: FinTsConfig): FinTsConfig {
|
|
54
|
+
requireLatin1(config.userId, 'userId');
|
|
55
|
+
requireLatin1(config.customerId, 'customerId');
|
|
56
|
+
requireLatin1(config.productId, 'productId');
|
|
57
|
+
requireLatin1(config.productVersion, 'productVersion');
|
|
58
|
+
// Cut short, the product would be one the bank does not know.
|
|
59
|
+
requireMaxLength(config.productId, maxProductIdLength, 'productId');
|
|
60
|
+
requireMaxLength(config.productVersion, maxProductVersionLength, 'productVersion');
|
|
61
|
+
return config;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The segments of `type` in all `pages`. */
|
|
65
|
+
function all(pages: readonly IncomingMessage3[], type: string): Segment[] {
|
|
66
|
+
return pages.flatMap((p) => p.findAll(type));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** FinTS 3.0 messages and business transactions (HBCI segment syntax, PIN/TAN security). */
|
|
70
|
+
export class FinTs3Protocol implements PinTanProtocol<IncomingMessage3, SegmentSpec>, FinTs3DialogHost {
|
|
71
|
+
readonly config: FinTsConfig;
|
|
72
|
+
private readonly pin: string;
|
|
73
|
+
private readonly connection: BankConnection;
|
|
74
|
+
readonly loginGuard = new LoginGuard();
|
|
75
|
+
|
|
76
|
+
/** Customer system ID the bank assigned in the synchronization. */
|
|
77
|
+
systemId: string | undefined;
|
|
78
|
+
private bpd: Bpd3 | undefined;
|
|
79
|
+
private upd: Upd3 | undefined;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Throws `TypeError` if the PIN is empty, if the PIN or login data contain characters FinTS 3.0 cannot send (ISO
|
|
83
|
+
* 8859-1 only), or the product ID or version is longer than its field in HKVVB.
|
|
84
|
+
*/
|
|
85
|
+
constructor(config: FinTsConfig, pin: string, transport?: FinTsTransport, logger?: MessageLogger) {
|
|
86
|
+
this.config = requireSendable(config);
|
|
87
|
+
this.pin = requireLatin1(requirePin(pin), 'pin');
|
|
88
|
+
this.connection = new BankConnection(config.url, transport, logger);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get bankParameters(): Bpd3 | undefined {
|
|
92
|
+
return this.bpd;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get userParameters(): Upd3 | undefined {
|
|
96
|
+
return this.upd;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Dialogs cannot start without the customer system ID. */
|
|
100
|
+
get synchronization(): Synchronization {
|
|
101
|
+
return this.systemId === undefined ? 'required' : 'none';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
forgetSystemId(): boolean {
|
|
105
|
+
const had = this.systemId !== undefined;
|
|
106
|
+
this.systemId = undefined;
|
|
107
|
+
return had;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
initSegments(systemId: string, anonymous = false): SegmentSpec[] {
|
|
111
|
+
return [
|
|
112
|
+
Segments.identification({
|
|
113
|
+
countryCode: this.config.countryCode,
|
|
114
|
+
bankCode: this.config.bankCode,
|
|
115
|
+
customerId: anonymous ? anonymousCustomerId : this.config.customerId,
|
|
116
|
+
systemId,
|
|
117
|
+
systemIdRequired: !anonymous,
|
|
118
|
+
}),
|
|
119
|
+
Segments.processingPreparation({
|
|
120
|
+
bpdVersion: this.bpd?.version ?? 0,
|
|
121
|
+
updVersion: anonymous ? 0 : (this.upd?.version ?? 0),
|
|
122
|
+
language: this.bpd?.dialogLanguage ?? 0,
|
|
123
|
+
productId: this.config.productId,
|
|
124
|
+
productVersion: this.config.productVersion,
|
|
125
|
+
}),
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async post(message: {
|
|
130
|
+
dialogId: string;
|
|
131
|
+
number: number;
|
|
132
|
+
segments: readonly SegmentSpec[];
|
|
133
|
+
signing: Signing3 | undefined;
|
|
134
|
+
tan: string | undefined;
|
|
135
|
+
}): Promise<Uint8Array> {
|
|
136
|
+
const signing = message.signing;
|
|
137
|
+
if (signing !== undefined) checkBeforeSigning(this.loginGuard, this.pin, this.bpd);
|
|
138
|
+
const outgoing = buildMessage({
|
|
139
|
+
dialogId: message.dialogId,
|
|
140
|
+
messageNumber: message.number,
|
|
141
|
+
segments: message.segments,
|
|
142
|
+
security:
|
|
143
|
+
signing === undefined
|
|
144
|
+
? undefined
|
|
145
|
+
: {
|
|
146
|
+
countryCode: this.config.countryCode,
|
|
147
|
+
bankCode: this.config.bankCode,
|
|
148
|
+
userId: this.config.userId,
|
|
149
|
+
systemId: signing.systemId,
|
|
150
|
+
pin: this.pin,
|
|
151
|
+
securityFunction: signing.securityFunction,
|
|
152
|
+
},
|
|
153
|
+
tan: message.tan,
|
|
154
|
+
});
|
|
155
|
+
checkMessageSize(outgoing.bytes.length, this.bpd?.bankInfo.maxMessageSize);
|
|
156
|
+
this.connection.log('outgoing', () => outgoing.masked);
|
|
157
|
+
const bytes = decodeTransport(await this.connection.post(encodeTransport(outgoing.bytes), 'text/plain'));
|
|
158
|
+
this.connection.log('incoming', () => decodeBankText(bytes));
|
|
159
|
+
return bytes;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
keepParameterData(response: IncomingMessage3): void {
|
|
163
|
+
this.keepBankParameters(response);
|
|
164
|
+
this.upd = Upd3.fromSegments(response.segments, this.config.bankCode, this.config.countryCode) ?? this.upd;
|
|
165
|
+
this.systemId = response.find('HISYN')?.text(1) ?? this.systemId;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private keepBankParameters(response: IncomingMessage3): void {
|
|
169
|
+
this.bpd = Bpd3.fromSegments(response.segments, this.config.bankCode) ?? this.bpd;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Keeps the bank parameter data of an anonymous dialog, and nothing that belongs to a user. */
|
|
173
|
+
async fetchBankParametersAnonymously(): Promise<IncomingMessage3> {
|
|
174
|
+
const response = await this.requestBankParametersAnonymously();
|
|
175
|
+
this.keepBankParameters(response);
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Asks for the bank parameter data in an anonymous dialog that announces strong customer authentication; a bank that
|
|
181
|
+
* rejects the announcement, with a return code or by failing on it, is asked again without it.
|
|
182
|
+
*
|
|
183
|
+
* A timeout or a broken connection is not a reason to ask again: it would only double the wait.
|
|
184
|
+
*/
|
|
185
|
+
private async requestBankParametersAnonymously(): Promise<IncomingMessage3> {
|
|
186
|
+
let announced: IncomingMessage3;
|
|
187
|
+
try {
|
|
188
|
+
announced = await this.anonymousDialog(true);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (error instanceof FinTsTransportError && error.statusCode === undefined) throw error;
|
|
191
|
+
if (!(error instanceof FinTsError)) throw error;
|
|
192
|
+
return this.anonymousDialog(false);
|
|
193
|
+
}
|
|
194
|
+
if (!hasErrors(announced.feedback) || announced.find('HIBPA') !== undefined) return announced;
|
|
195
|
+
return this.anonymousDialog(false);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async anonymousDialog(announceSca: boolean): Promise<IncomingMessage3> {
|
|
199
|
+
const dialog = FinTs3Dialog.anonymous(this);
|
|
200
|
+
try {
|
|
201
|
+
return await dialog.requestBankParameters(announceSca);
|
|
202
|
+
} finally {
|
|
203
|
+
await dialog.end();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
newDialog(method: TanMethod, tanMedium?: string): FinTs3Dialog {
|
|
208
|
+
return FinTs3Dialog.signed(this, method, tanMedium);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
combine(first: IncomingMessage3, second: IncomingMessage3): IncomingMessage3 {
|
|
212
|
+
return IncomingMessage3.combine(first, second);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// --- Business transactions ---
|
|
216
|
+
|
|
217
|
+
private version(
|
|
218
|
+
transaction: string,
|
|
219
|
+
implemented: readonly number[],
|
|
220
|
+
options: { account?: Account; requiresEntry?: boolean } = {},
|
|
221
|
+
): number | undefined {
|
|
222
|
+
return offeredVersion(this.bpd, this.upd, transaction, new Set(implemented), options);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
tanMedia(): FinTs3Query<TanMedium[]> | undefined {
|
|
226
|
+
const version = this.version('HKTAB', [4, 5]);
|
|
227
|
+
if (version === undefined) return undefined;
|
|
228
|
+
return {
|
|
229
|
+
order: () => Segments.tanMedia(version),
|
|
230
|
+
read: (pages) => all(pages, 'HITAB').flatMap(parseTanMedia),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
sepaAccounts(): FinTs3Query<Account[]> | undefined {
|
|
235
|
+
const version = this.version('HKSPA', [1, 2, 3], { requiresEntry: true });
|
|
236
|
+
if (version === undefined) return undefined;
|
|
237
|
+
return {
|
|
238
|
+
order: (continuation) => Segments.sepaAccounts(version, continuation),
|
|
239
|
+
read: (pages) =>
|
|
240
|
+
all(pages, 'HISPA').flatMap((s) => parseSepaAccounts(s, this.config.countryCode, this.config.bankCode)),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
balance(account: Account): FinTs3Query<Balance> {
|
|
245
|
+
const version = this.version('HKSAL', [6, 7, 8], { account });
|
|
246
|
+
if (version === undefined) {
|
|
247
|
+
throw new FinTsUnsupportedError('The bank reports no balance (HKSAL) for this account');
|
|
248
|
+
}
|
|
249
|
+
return balanceQuery<IncomingMessage3, SegmentSpec, Segment>(account, {
|
|
250
|
+
order: (continuation) => Segments.balance(version, account, continuation),
|
|
251
|
+
records: (pages) => all(pages, 'HISAL'),
|
|
252
|
+
accountOf: balanceAccount,
|
|
253
|
+
read: parseBalance,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
transactions(
|
|
258
|
+
account: Account,
|
|
259
|
+
format: TransactionFormat,
|
|
260
|
+
from: Date | undefined,
|
|
261
|
+
to: Date | undefined,
|
|
262
|
+
): FinTs3Query<Transaction[]> {
|
|
263
|
+
const request = chooseTransactions(format, account, this.upd, {
|
|
264
|
+
camt: { name: 'HKCAZ', version: this.version('HKCAZ', [1], { account }) },
|
|
265
|
+
camtFormats: requireBankParameters(this.bpd).camtFormats,
|
|
266
|
+
mt940: { name: 'HKKAZ', version: this.version('HKKAZ', [6, 7], { account }) },
|
|
267
|
+
});
|
|
268
|
+
const version = request.version;
|
|
269
|
+
if (request.camt) {
|
|
270
|
+
return {
|
|
271
|
+
order: (continuation) =>
|
|
272
|
+
Segments.transactionsCamt(version, account, request.camtFormats, { from, to, continuation }),
|
|
273
|
+
// The third element group holds the booked documents, the fourth element the pending one.
|
|
274
|
+
read: (pages) =>
|
|
275
|
+
camtTransactions(
|
|
276
|
+
all(pages, 'HICAZ').flatMap((s) =>
|
|
277
|
+
s
|
|
278
|
+
.group(3)
|
|
279
|
+
.filter((d) => !d.isEmpty)
|
|
280
|
+
.map((d) => d.bytes),
|
|
281
|
+
),
|
|
282
|
+
all(pages, 'HICAZ')
|
|
283
|
+
.map((s) => s.binary(4))
|
|
284
|
+
.filter((d) => d !== undefined),
|
|
285
|
+
),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
order: (continuation) => Segments.transactionsMt940(version, account, { from, to, continuation }),
|
|
290
|
+
// The first element holds the booked transactions, the second the pending ones.
|
|
291
|
+
read: (pages) =>
|
|
292
|
+
mt940Transactions(
|
|
293
|
+
all(pages, 'HIKAZ')
|
|
294
|
+
.map((s) => s.binary(1))
|
|
295
|
+
.filter((d) => d !== undefined),
|
|
296
|
+
all(pages, 'HIKAZ')
|
|
297
|
+
.map((s) => s.binary(2))
|
|
298
|
+
.filter((d) => d !== undefined),
|
|
299
|
+
request.currency,
|
|
300
|
+
),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// --- Saved state ---
|
|
305
|
+
|
|
306
|
+
saveState(): JsonObject {
|
|
307
|
+
return {
|
|
308
|
+
systemId: this.systemId ?? null,
|
|
309
|
+
bpd: this.bpd === undefined ? null : encodeSegments(this.bpd.segments),
|
|
310
|
+
upd: this.upd === undefined ? null : encodeSegments(this.upd.segments),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
restoreState(saved: JsonObject): void {
|
|
315
|
+
const bpd = readOptionalString(saved, 'bpd');
|
|
316
|
+
const upd = readOptionalString(saved, 'upd');
|
|
317
|
+
const restoredSystemId = readOptionalString(saved, 'systemId');
|
|
318
|
+
const restoredBpd = bpd === undefined ? undefined : Bpd3.fromSegments(decodeSegments(bpd), this.config.bankCode);
|
|
319
|
+
const restoredUpd =
|
|
320
|
+
upd === undefined
|
|
321
|
+
? undefined
|
|
322
|
+
: Upd3.fromSegments(decodeSegments(upd), this.config.bankCode, this.config.countryCode);
|
|
323
|
+
this.systemId = restoredSystemId;
|
|
324
|
+
this.bpd = restoredBpd;
|
|
325
|
+
this.upd = restoredUpd;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
close(): void {
|
|
329
|
+
this.connection.close();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// Internal to the package, and named after the FinTS specification. Documentation is where the meaning is not evident.
|
|
2
|
+
|
|
3
|
+
import { Account } from '../core/account.js';
|
|
4
|
+
import { Amount, withMark } from '../core/amount.js';
|
|
5
|
+
import { Balance } from '../core/balance.js';
|
|
6
|
+
import { noReference } from '../session/protocol.js';
|
|
7
|
+
import { TanMedium, tanMediumStatusOf } from '../tan/tan-models.js';
|
|
8
|
+
import { formatFintsDate, parseFintsDate, parseFintsDateTime } from '../util/dates.js';
|
|
9
|
+
import { FormatError } from '../util/errors.js';
|
|
10
|
+
import { type Segment, SegmentSpec, type SegmentValue } from './syntax.js';
|
|
11
|
+
|
|
12
|
+
/** Bank identification (KIK): country code and bank code. */
|
|
13
|
+
export function bankIdentification(countryCode: string, bankCode: string): SegmentValue {
|
|
14
|
+
return [countryCode, bankCode];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** National account (KTV): account number, sub-account and bank identification. */
|
|
18
|
+
export function nationalAccount(a: Account): SegmentValue[] {
|
|
19
|
+
return [a.accountNumber, a.subAccount, a.countryCode, a.bankCode];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** International account (KTI): IBAN, BIC, then the national account. */
|
|
23
|
+
export function internationalAccount(a: Account): SegmentValue[] {
|
|
24
|
+
return [a.iban, a.bic, ...nationalAccount(a)];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function dateOrEmpty(date: Date | undefined): string | undefined {
|
|
28
|
+
return date === undefined ? undefined : formatFintsDate(date);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// HKTAN fields: order reference (Auftragsreferenz), "more TANs follow" and the TAN medium name.
|
|
32
|
+
const orderReferenceField = 5;
|
|
33
|
+
const moreTansField = 6;
|
|
34
|
+
const tanMediumField = 11;
|
|
35
|
+
|
|
36
|
+
/** Builders for the request segments the client sends. */
|
|
37
|
+
export const Segments = Object.freeze({
|
|
38
|
+
/** HKIDN: who is logging in, from which customer system. */
|
|
39
|
+
identification(parts: {
|
|
40
|
+
countryCode: string;
|
|
41
|
+
bankCode: string;
|
|
42
|
+
customerId: string;
|
|
43
|
+
systemId: string;
|
|
44
|
+
systemIdRequired: boolean;
|
|
45
|
+
}): SegmentSpec {
|
|
46
|
+
return new SegmentSpec('HKIDN', 2, [
|
|
47
|
+
bankIdentification(parts.countryCode, parts.bankCode),
|
|
48
|
+
parts.customerId,
|
|
49
|
+
parts.systemId,
|
|
50
|
+
parts.systemIdRequired ? 1 : 0,
|
|
51
|
+
]);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/** HKVVB: the parameter data versions the client knows, the dialog language and the registered product. */
|
|
55
|
+
processingPreparation(parts: {
|
|
56
|
+
bpdVersion: number;
|
|
57
|
+
updVersion: number;
|
|
58
|
+
language: number;
|
|
59
|
+
productId: string;
|
|
60
|
+
productVersion: string;
|
|
61
|
+
}): SegmentSpec {
|
|
62
|
+
return new SegmentSpec('HKVVB', 3, [
|
|
63
|
+
parts.bpdVersion,
|
|
64
|
+
parts.updVersion,
|
|
65
|
+
parts.language,
|
|
66
|
+
parts.productId,
|
|
67
|
+
parts.productVersion,
|
|
68
|
+
]);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/** HKSYN: requests a new customer system ID. */
|
|
72
|
+
synchronization(): SegmentSpec {
|
|
73
|
+
return new SegmentSpec('HKSYN', 3, [0]);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
dialogEnd(dialogId: string): SegmentSpec {
|
|
77
|
+
return new SegmentSpec('HKEND', 1, [dialogId]);
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/** HKTAN process 4: asks for strong customer authentication of the `segmentType` sent in the same message. */
|
|
81
|
+
tanProcess4(version: number, segmentType: string, mediumName?: string): SegmentSpec {
|
|
82
|
+
return SegmentSpec.numbered('HKTAN', version, { 1: '4', 2: segmentType, [tanMediumField]: mediumName });
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/** HKTAN process 2: submits the TAN (carried in the signature) for the order with `reference`. */
|
|
86
|
+
tanProcess2(version: number, reference: string): SegmentSpec {
|
|
87
|
+
return SegmentSpec.numbered('HKTAN', version, { 1: '2', [orderReferenceField]: reference, [moreTansField]: false });
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/** HKTAN process S: asks whether the order with `reference` was approved in the banking app. */
|
|
91
|
+
tanProcessStatus(version: number, reference: string): SegmentSpec {
|
|
92
|
+
return SegmentSpec.numbered('HKTAN', version, { 1: 'S', [orderReferenceField]: reference, [moreTansField]: false });
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/** HKSAL: the balance of one account (not of all accounts). */
|
|
96
|
+
balance(version: number, account: Account, continuation?: string): SegmentSpec {
|
|
97
|
+
return new SegmentSpec('HKSAL', version, [
|
|
98
|
+
version >= 7 ? internationalAccount(account) : nationalAccount(account),
|
|
99
|
+
false,
|
|
100
|
+
null,
|
|
101
|
+
continuation,
|
|
102
|
+
]);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/** HKKAZ: MT940 transactions of one account. */
|
|
106
|
+
transactionsMt940(
|
|
107
|
+
version: number,
|
|
108
|
+
account: Account,
|
|
109
|
+
period: { from?: Date | undefined; to?: Date | undefined; continuation?: string | undefined },
|
|
110
|
+
): SegmentSpec {
|
|
111
|
+
return new SegmentSpec('HKKAZ', version, [
|
|
112
|
+
version >= 7 ? internationalAccount(account) : nationalAccount(account),
|
|
113
|
+
false,
|
|
114
|
+
dateOrEmpty(period.from),
|
|
115
|
+
dateOrEmpty(period.to),
|
|
116
|
+
null,
|
|
117
|
+
period.continuation,
|
|
118
|
+
]);
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/** HKCAZ: camt transactions of one account in one of `formats`. */
|
|
122
|
+
transactionsCamt(
|
|
123
|
+
version: number,
|
|
124
|
+
account: Account,
|
|
125
|
+
formats: readonly string[],
|
|
126
|
+
period: { from?: Date | undefined; to?: Date | undefined; continuation?: string | undefined },
|
|
127
|
+
): SegmentSpec {
|
|
128
|
+
return new SegmentSpec('HKCAZ', version, [
|
|
129
|
+
internationalAccount(account),
|
|
130
|
+
formats,
|
|
131
|
+
false,
|
|
132
|
+
dateOrEmpty(period.from),
|
|
133
|
+
dateOrEmpty(period.to),
|
|
134
|
+
null,
|
|
135
|
+
period.continuation,
|
|
136
|
+
]);
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/** HKSPA: IBAN and BIC of all accounts. */
|
|
140
|
+
sepaAccounts(version: number, continuation?: string): SegmentSpec {
|
|
141
|
+
return new SegmentSpec('HKSPA', version, [null, ...(version >= 2 ? [null, continuation] : [])]);
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
/** HKTAB: all TAN media of all classes. */
|
|
145
|
+
tanMedia(version: number): SegmentSpec {
|
|
146
|
+
return new SegmentSpec('HKTAB', version, [0, 'A']);
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
/** Positions of the data elements in the TAN part of a response (HITAN versions 6 and 7), after the segment header. */
|
|
151
|
+
const Hitan = { process: 1, reference: 3, challenge: 4, hhdUc: 5, validUntil: 6, mediumName: 7 } as const;
|
|
152
|
+
|
|
153
|
+
/** The TAN part of a response (HITAN). */
|
|
154
|
+
export class TanResponse {
|
|
155
|
+
constructor(
|
|
156
|
+
/** The TAN process the segment answers: `4` asks for an approval, `S` answers a status request. */
|
|
157
|
+
readonly process: string | undefined,
|
|
158
|
+
readonly reference: string | undefined,
|
|
159
|
+
readonly challenge: string | undefined,
|
|
160
|
+
readonly hhdUc: Uint8Array | undefined,
|
|
161
|
+
readonly validUntil: Date | undefined,
|
|
162
|
+
readonly mediumName: string | undefined,
|
|
163
|
+
) {}
|
|
164
|
+
|
|
165
|
+
static parse(s: Segment): TanResponse {
|
|
166
|
+
return new TanResponse(
|
|
167
|
+
s.text(Hitan.process),
|
|
168
|
+
s.text(Hitan.reference),
|
|
169
|
+
s.text(Hitan.challenge),
|
|
170
|
+
s.binary(Hitan.hhdUc),
|
|
171
|
+
parseFintsDateTime(s.text(Hitan.validUntil, 0), s.text(Hitan.validUntil, 1)),
|
|
172
|
+
s.text(Hitan.mediumName),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Whether the bank needs no approval although it answered with a TAN segment. */
|
|
177
|
+
get isDummy(): boolean {
|
|
178
|
+
return this.reference === undefined || this.reference === noReference;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Positions of the data elements in a balance (HISAL), after the segment header. */
|
|
183
|
+
const Hisal = {
|
|
184
|
+
account: 1,
|
|
185
|
+
productName: 2,
|
|
186
|
+
accountCurrency: 3,
|
|
187
|
+
bookedBalance: 4,
|
|
188
|
+
pendingBalance: 5,
|
|
189
|
+
creditLine: 6,
|
|
190
|
+
availableAmount: 7,
|
|
191
|
+
usedAmount: 8,
|
|
192
|
+
overdraft: 9,
|
|
193
|
+
bookingTime: 10,
|
|
194
|
+
} as const;
|
|
195
|
+
|
|
196
|
+
/** Positions inside a balance (SDO): credit/debit mark, value, currency, date and time. */
|
|
197
|
+
const Sdo = { mark: 0, value: 1, currency: 2, date: 3, time: 4 } as const;
|
|
198
|
+
|
|
199
|
+
/** An amount with currency (BTG) at `index`, or `undefined` if empty. */
|
|
200
|
+
function amountAt(s: Segment, index: number, fallbackCurrency: string): Amount | undefined {
|
|
201
|
+
const value = s.text(index, 0);
|
|
202
|
+
if (value === undefined) return undefined;
|
|
203
|
+
return Amount.parseDecimal(value, s.text(index, 1) ?? fallbackCurrency);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Parses a balance (HISAL); throws `FormatError` if the booked balance is missing or malformed, or a balance has no
|
|
208
|
+
* credit/debit mark.
|
|
209
|
+
*/
|
|
210
|
+
export function parseBalance(s: Segment, account: Account): Balance {
|
|
211
|
+
const currency = s.text(Hisal.accountCurrency) ?? account.currency;
|
|
212
|
+
const signedBalance = (index: number): Amount | undefined => {
|
|
213
|
+
const value = s.text(index, Sdo.value);
|
|
214
|
+
if (value === undefined) return undefined;
|
|
215
|
+
const amountCurrency = s.text(index, Sdo.currency) ?? currency;
|
|
216
|
+
if (amountCurrency === undefined) throw new FormatError('Balance without currency');
|
|
217
|
+
return withMark(Amount.parseDecimal(value, amountCurrency), s.text(index, Sdo.mark), 'C', 'D');
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const booked = signedBalance(Hisal.bookedBalance);
|
|
221
|
+
if (booked === undefined) throw new FormatError('Balance without booked amount');
|
|
222
|
+
const bookedDate = s.text(Hisal.bookedBalance, Sdo.date);
|
|
223
|
+
const bookedAsOf = parseFintsDate(bookedDate);
|
|
224
|
+
if (bookedAsOf === undefined) throw new FormatError('Balance without date');
|
|
225
|
+
return new Balance({
|
|
226
|
+
account,
|
|
227
|
+
productName: s.text(Hisal.productName),
|
|
228
|
+
booked,
|
|
229
|
+
bookedAsOf,
|
|
230
|
+
bookedAsOfTime: parseFintsDateTime(bookedDate, s.text(Hisal.bookedBalance, Sdo.time)),
|
|
231
|
+
pending: signedBalance(Hisal.pendingBalance),
|
|
232
|
+
creditLine: amountAt(s, Hisal.creditLine, booked.currency),
|
|
233
|
+
available: amountAt(s, Hisal.availableAmount, booked.currency),
|
|
234
|
+
used: amountAt(s, Hisal.usedAmount, booked.currency),
|
|
235
|
+
overdraft: amountAt(s, Hisal.overdraft, booked.currency),
|
|
236
|
+
bookingDate: parseFintsDate(s.text(Hisal.bookingTime, 0)),
|
|
237
|
+
bookingTime: parseFintsDateTime(s.text(Hisal.bookingTime, 0), s.text(Hisal.bookingTime, 1)),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The account a balance (HISAL) belongs to: international (IBAN, BIC, then national) from version 7, national before.
|
|
243
|
+
*/
|
|
244
|
+
export function balanceAccount(s: Segment): Account {
|
|
245
|
+
const fields = s.texts(Hisal.account);
|
|
246
|
+
const international = s.version >= 7;
|
|
247
|
+
const national = international ? 2 : 0;
|
|
248
|
+
return new Account({
|
|
249
|
+
iban: international ? fields[0] : undefined,
|
|
250
|
+
bic: international ? fields[1] : undefined,
|
|
251
|
+
accountNumber: fields[national],
|
|
252
|
+
subAccount: fields[national + 1],
|
|
253
|
+
countryCode: fields[national + 2] ?? '',
|
|
254
|
+
bankCode: fields[national + 3] ?? '',
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Positions inside an account of the SEPA account list (HISPA "Kontoverbindung SEPA"). */
|
|
259
|
+
const Hispa = {
|
|
260
|
+
isSepaAccount: 0,
|
|
261
|
+
iban: 1,
|
|
262
|
+
bic: 2,
|
|
263
|
+
accountNumber: 3,
|
|
264
|
+
subAccount: 4,
|
|
265
|
+
countryCode: 5,
|
|
266
|
+
bankCode: 6,
|
|
267
|
+
} as const;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Parses the SEPA account list (HISPA), one account per data element. An account the bank marks as no payment account
|
|
271
|
+
* ("Kontoverwendung SEPA" N) is left out: it has no SEPA connection.
|
|
272
|
+
*/
|
|
273
|
+
export function parseSepaAccounts(s: Segment, defaultCountry: string, defaultBank: string): Account[] {
|
|
274
|
+
const accounts: Account[] = [];
|
|
275
|
+
for (let i = 1; i < s.length; i++) {
|
|
276
|
+
if (s.text(i, Hispa.isSepaAccount) === 'N') continue;
|
|
277
|
+
if (s.text(i, Hispa.iban) === undefined && s.text(i, Hispa.accountNumber) === undefined) continue;
|
|
278
|
+
accounts.push(
|
|
279
|
+
new Account({
|
|
280
|
+
iban: s.text(i, Hispa.iban),
|
|
281
|
+
bic: s.text(i, Hispa.bic),
|
|
282
|
+
accountNumber: s.text(i, Hispa.accountNumber),
|
|
283
|
+
subAccount: s.text(i, Hispa.subAccount),
|
|
284
|
+
countryCode: s.text(i, Hispa.countryCode) ?? defaultCountry,
|
|
285
|
+
bankCode: s.text(i, Hispa.bankCode) ?? defaultBank,
|
|
286
|
+
}),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return accounts;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Elements of the account a TAN medium belongs to, a national account (`ktv`: account number, sub-account, country
|
|
294
|
+
* code, bank code), which shifts every field behind it.
|
|
295
|
+
*/
|
|
296
|
+
const accountWidth = 4;
|
|
297
|
+
|
|
298
|
+
/** Parses the TAN media list (HITAB versions 4 and 5, PIN/TAN "TAN-Medium-Liste"). */
|
|
299
|
+
export function parseTanMedia(s: Segment): TanMedium[] {
|
|
300
|
+
// Version 5 adds the security function in front of the card number.
|
|
301
|
+
const version5 = s.version >= 5;
|
|
302
|
+
const cardNumber = version5 ? 3 : 2;
|
|
303
|
+
// The card number, card sequence number and card type are followed by the account. Behind it come: valid from, valid
|
|
304
|
+
// until, TAN list number, name, masked and full mobile number, SMS charge account (six elements), number of free TANs,
|
|
305
|
+
// last use, activation.
|
|
306
|
+
const after = cardNumber + 3 + accountWidth;
|
|
307
|
+
const media: TanMedium[] = [];
|
|
308
|
+
// The first data element is the TAN usage option; the media follow.
|
|
309
|
+
for (let i = 2; i < s.length; i++) {
|
|
310
|
+
const fields = s.texts(i);
|
|
311
|
+
const mediumClass = fields[0];
|
|
312
|
+
if (mediumClass === undefined) continue;
|
|
313
|
+
media.push(
|
|
314
|
+
new TanMedium({
|
|
315
|
+
mediumClass,
|
|
316
|
+
status: tanMediumStatusOf(fields[1]),
|
|
317
|
+
securityFunction: version5 ? fields[2] : undefined,
|
|
318
|
+
cardNumber: fields[cardNumber],
|
|
319
|
+
cardSequenceNumber: fields[cardNumber + 1],
|
|
320
|
+
validFrom: parseFintsDate(fields[after]),
|
|
321
|
+
validUntil: parseFintsDate(fields[after + 1]),
|
|
322
|
+
name: fields[after + 3],
|
|
323
|
+
mobileNumberMasked: fields[after + 4],
|
|
324
|
+
mobileNumber: fields[after + 5],
|
|
325
|
+
lastUsed: parseFintsDate(fields[after + 13]),
|
|
326
|
+
activatedOn: parseFintsDate(fields[after + 14]),
|
|
327
|
+
}),
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
return media;
|
|
331
|
+
}
|