@coderoftime/fints 0.1.0 → 0.3.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 +519 -1
- package/README.md +138 -40
- package/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +242 -0
- package/dist/client.js.map +1 -0
- package/dist/core/account.d.ts +46 -7
- package/dist/core/account.d.ts.map +1 -1
- package/dist/core/account.js +143 -24
- package/dist/core/account.js.map +1 -1
- package/dist/core/amount.d.ts +15 -4
- package/dist/core/amount.d.ts.map +1 -1
- package/dist/core/amount.js +46 -9
- package/dist/core/amount.js.map +1 -1
- package/dist/core/balance.d.ts +4 -0
- package/dist/core/balance.d.ts.map +1 -1
- package/dist/core/balance.js +11 -5
- package/dist/core/balance.js.map +1 -1
- package/dist/core/bank-info.d.ts +21 -4
- package/dist/core/bank-info.d.ts.map +1 -1
- package/dist/core/bank-info.js +26 -5
- package/dist/core/bank-info.js.map +1 -1
- package/dist/core/client.d.ts +81 -19
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +40 -20
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +85 -30
- package/dist/core/config.js.map +1 -1
- package/dist/core/errors.d.ts +100 -26
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +136 -53
- package/dist/core/errors.js.map +1 -1
- package/dist/core/feedback.d.ts +11 -1
- package/dist/core/feedback.d.ts.map +1 -1
- package/dist/core/feedback.js +14 -2
- package/dist/core/feedback.js.map +1 -1
- package/dist/core/transaction.d.ts +11 -1
- package/dist/core/transaction.d.ts.map +1 -1
- package/dist/core/transaction.js +21 -4
- package/dist/core/transaction.js.map +1 -1
- package/dist/core/transport.d.ts +48 -6
- package/dist/core/transport.d.ts.map +1 -1
- package/dist/core/transport.js +126 -29
- package/dist/core/transport.js.map +1 -1
- package/dist/formats/camt.d.ts +28 -5
- package/dist/formats/camt.d.ts.map +1 -1
- package/dist/formats/camt.js +132 -50
- package/dist/formats/camt.js.map +1 -1
- package/dist/formats/mt940.d.ts +29 -5
- package/dist/formats/mt940.d.ts.map +1 -1
- package/dist/formats/mt940.js +209 -113
- package/dist/formats/mt940.js.map +1 -1
- package/dist/formats/readers.d.ts +6 -2
- package/dist/formats/readers.d.ts.map +1 -1
- package/dist/formats/readers.js +28 -29
- package/dist/formats/readers.js.map +1 -1
- package/dist/formats/record-budget.d.ts +7 -0
- package/dist/formats/record-budget.d.ts.map +1 -0
- package/dist/formats/record-budget.js +17 -0
- package/dist/formats/record-budget.js.map +1 -0
- package/dist/formats/sepa-purpose.d.ts +9 -0
- package/dist/formats/sepa-purpose.d.ts.map +1 -1
- package/dist/formats/sepa-purpose.js +32 -2
- package/dist/formats/sepa-purpose.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/session/app-approval.d.ts +11 -5
- package/dist/session/app-approval.d.ts.map +1 -1
- package/dist/session/app-approval.js +23 -12
- package/dist/session/app-approval.js.map +1 -1
- package/dist/session/dialog-runner.d.ts +11 -11
- package/dist/session/dialog-runner.d.ts.map +1 -1
- package/dist/session/dialog-runner.js +34 -19
- package/dist/session/dialog-runner.js.map +1 -1
- package/dist/session/login-guard.d.ts +54 -49
- package/dist/session/login-guard.d.ts.map +1 -1
- package/dist/session/login-guard.js +170 -83
- package/dist/session/login-guard.js.map +1 -1
- package/dist/session/sepa-accounts.d.ts +20 -14
- package/dist/session/sepa-accounts.d.ts.map +1 -1
- package/dist/session/sepa-accounts.js +62 -46
- package/dist/session/sepa-accounts.js.map +1 -1
- package/dist/session/session-setup.d.ts +41 -24
- package/dist/session/session-setup.d.ts.map +1 -1
- package/dist/session/session-setup.js +106 -63
- package/dist/session/session-setup.js.map +1 -1
- package/dist/session/session-state.d.ts +10 -6
- package/dist/session/session-state.d.ts.map +1 -1
- package/dist/session/session-state.js +72 -18
- package/dist/session/session-state.js.map +1 -1
- package/dist/session/signed-dialog.d.ts +83 -0
- package/dist/session/signed-dialog.d.ts.map +1 -0
- package/dist/session/signed-dialog.js +185 -0
- package/dist/session/signed-dialog.js.map +1 -0
- package/dist/session/tan-selection.d.ts +26 -18
- package/dist/session/tan-selection.d.ts.map +1 -1
- package/dist/session/tan-selection.js +44 -33
- package/dist/session/tan-selection.js.map +1 -1
- package/dist/session/user-prompts.d.ts +14 -5
- package/dist/session/user-prompts.d.ts.map +1 -1
- package/dist/session/user-prompts.js +53 -18
- package/dist/session/user-prompts.js.map +1 -1
- package/dist/tan/challenge.d.ts +47 -24
- package/dist/tan/challenge.d.ts.map +1 -1
- package/dist/tan/challenge.js +56 -51
- package/dist/tan/challenge.js.map +1 -1
- package/dist/tan/flicker.d.ts +11 -1
- package/dist/tan/flicker.d.ts.map +1 -1
- package/dist/tan/flicker.js +70 -24
- package/dist/tan/flicker.js.map +1 -1
- package/dist/tan/tan-image.d.ts +6 -2
- package/dist/tan/tan-image.d.ts.map +1 -1
- package/dist/tan/tan-image.js +14 -6
- package/dist/tan/tan-image.js.map +1 -1
- package/dist/tan/tan-models.d.ts +14 -2
- package/dist/tan/tan-models.d.ts.map +1 -1
- package/dist/tan/tan-models.js +24 -7
- package/dist/tan/tan-models.js.map +1 -1
- package/dist/util/arguments.d.ts +13 -0
- package/dist/util/arguments.d.ts.map +1 -0
- package/dist/util/arguments.js +40 -0
- package/dist/util/arguments.js.map +1 -0
- package/dist/util/async.d.ts +4 -3
- package/dist/util/async.d.ts.map +1 -1
- package/dist/util/async.js +6 -7
- package/dist/util/async.js.map +1 -1
- package/dist/util/bytes.d.ts +3 -4
- package/dist/util/bytes.d.ts.map +1 -1
- package/dist/util/bytes.js +13 -21
- package/dist/util/bytes.js.map +1 -1
- package/dist/util/call-context.d.ts.map +1 -1
- package/dist/util/call-context.js +3 -2
- package/dist/util/call-context.js.map +1 -1
- package/dist/util/dates.d.ts +6 -20
- package/dist/util/dates.d.ts.map +1 -1
- package/dist/util/dates.js +58 -28
- package/dist/util/dates.js.map +1 -1
- package/dist/util/errors.d.ts +13 -3
- package/dist/util/errors.d.ts.map +1 -1
- package/dist/util/errors.js +19 -6
- package/dist/util/errors.js.map +1 -1
- package/dist/util/immutable-map.d.ts +5 -2
- package/dist/util/immutable-map.d.ts.map +1 -1
- package/dist/util/immutable-map.js +15 -12
- package/dist/util/immutable-map.js.map +1 -1
- package/dist/util/inspect.d.ts +11 -0
- package/dist/util/inspect.d.ts.map +1 -0
- package/dist/util/inspect.js +14 -0
- package/dist/util/inspect.js.map +1 -0
- package/dist/util/json.d.ts +4 -0
- package/dist/util/json.d.ts.map +1 -1
- package/dist/util/json.js +18 -0
- package/dist/util/json.js.map +1 -1
- package/dist/util/text.d.ts +38 -5
- package/dist/util/text.d.ts.map +1 -1
- package/dist/util/text.js +90 -16
- package/dist/util/text.js.map +1 -1
- package/dist/util/xml.d.ts +9 -6
- package/dist/util/xml.d.ts.map +1 -1
- package/dist/util/xml.js +129 -56
- package/dist/util/xml.js.map +1 -1
- package/dist/v3/account-extension.d.ts.map +1 -1
- package/dist/v3/account-extension.js +7 -10
- package/dist/v3/account-extension.js.map +1 -1
- package/dist/v3/bank-connection.d.ts +54 -0
- package/dist/v3/bank-connection.d.ts.map +1 -0
- package/dist/v3/bank-connection.js +118 -0
- package/dist/v3/bank-connection.js.map +1 -0
- package/dist/v3/dialog.d.ts +84 -46
- package/dist/v3/dialog.d.ts.map +1 -1
- package/dist/v3/dialog.js +174 -60
- package/dist/v3/dialog.js.map +1 -1
- package/dist/v3/message.d.ts +32 -11
- package/dist/v3/message.d.ts.map +1 -1
- package/dist/v3/message.js +144 -83
- package/dist/v3/message.js.map +1 -1
- package/dist/v3/parameter-store.d.ts +111 -0
- package/dist/v3/parameter-store.d.ts.map +1 -0
- package/dist/v3/parameter-store.js +197 -0
- package/dist/v3/parameter-store.js.map +1 -0
- package/dist/v3/parameters.d.ts +44 -17
- package/dist/v3/parameters.d.ts.map +1 -1
- package/dist/v3/parameters.js +136 -60
- package/dist/v3/parameters.js.map +1 -1
- package/dist/v3/protocol.d.ts +50 -50
- package/dist/v3/protocol.d.ts.map +1 -1
- package/dist/v3/protocol.js +91 -210
- package/dist/v3/protocol.js.map +1 -1
- package/dist/v3/queries.d.ts +51 -0
- package/dist/v3/queries.d.ts.map +1 -0
- package/dist/v3/queries.js +128 -0
- package/dist/v3/queries.js.map +1 -0
- package/dist/v3/segments.d.ts +43 -19
- package/dist/v3/segments.d.ts.map +1 -1
- package/dist/v3/segments.js +84 -33
- package/dist/v3/segments.js.map +1 -1
- package/dist/v3/syntax.d.ts +68 -13
- package/dist/v3/syntax.d.ts.map +1 -1
- package/dist/v3/syntax.js +183 -102
- package/dist/v3/syntax.js.map +1 -1
- package/package.json +10 -6
- package/src/client.ts +293 -0
- package/src/core/account.ts +153 -24
- package/src/core/amount.ts +45 -10
- package/src/core/balance.ts +12 -5
- package/src/core/bank-info.ts +29 -5
- package/src/core/client.ts +83 -19
- package/src/core/config.ts +95 -35
- package/src/core/errors.ts +148 -54
- package/src/core/feedback.ts +16 -2
- package/src/core/transaction.ts +22 -4
- package/src/core/transport.ts +153 -32
- package/src/formats/camt.ts +153 -45
- package/src/formats/mt940.ts +244 -122
- package/src/formats/readers.ts +28 -31
- package/src/formats/record-budget.ts +18 -0
- package/src/formats/sepa-purpose.ts +29 -2
- package/src/index.ts +4 -2
- package/src/session/app-approval.ts +51 -38
- package/src/session/dialog-runner.ts +61 -31
- package/src/session/login-guard.ts +189 -87
- package/src/session/sepa-accounts.ts +63 -45
- package/src/session/session-setup.ts +105 -68
- package/src/session/session-state.ts +74 -23
- package/src/session/signed-dialog.ts +222 -0
- package/src/session/tan-selection.ts +50 -39
- package/src/session/user-prompts.ts +62 -18
- package/src/tan/challenge.ts +87 -64
- package/src/tan/flicker.ts +72 -23
- package/src/tan/tan-image.ts +15 -6
- package/src/tan/tan-models.ts +26 -7
- package/src/util/arguments.ts +40 -0
- package/src/util/async.ts +10 -9
- package/src/util/bytes.ts +14 -20
- package/src/util/call-context.ts +3 -2
- package/src/util/dates.ts +64 -33
- package/src/util/errors.ts +22 -6
- package/src/util/immutable-map.ts +15 -12
- package/src/util/inspect.ts +14 -0
- package/src/util/json.ts +16 -0
- package/src/util/text.ts +87 -15
- package/src/util/xml.ts +130 -52
- package/src/v3/account-extension.ts +7 -12
- package/src/v3/bank-connection.ts +126 -0
- package/src/v3/dialog.ts +186 -92
- package/src/v3/message.ts +140 -79
- package/src/v3/parameter-store.ts +226 -0
- package/src/v3/parameters.ts +166 -66
- package/src/v3/protocol.ts +103 -253
- package/src/v3/queries.ts +198 -0
- package/src/v3/segments.ts +86 -31
- package/src/v3/syntax.ts +172 -93
- package/dist/session/bank-connection.d.ts +0 -28
- package/dist/session/bank-connection.d.ts.map +0 -1
- package/dist/session/bank-connection.js +0 -48
- package/dist/session/bank-connection.js.map +0 -1
- package/dist/session/parameter-data.d.ts +0 -83
- package/dist/session/parameter-data.d.ts.map +0 -1
- package/dist/session/parameter-data.js +0 -68
- package/dist/session/parameter-data.js.map +0 -1
- package/dist/session/pin-tan-client.d.ts +0 -54
- package/dist/session/pin-tan-client.d.ts.map +0 -1
- package/dist/session/pin-tan-client.js +0 -153
- package/dist/session/pin-tan-client.js.map +0 -1
- package/dist/session/pin-tan-dialog.d.ts +0 -71
- package/dist/session/pin-tan-dialog.d.ts.map +0 -1
- package/dist/session/pin-tan-dialog.js +0 -124
- package/dist/session/pin-tan-dialog.js.map +0 -1
- package/dist/session/protocol.d.ts +0 -209
- package/dist/session/protocol.d.ts.map +0 -1
- package/dist/session/protocol.js +0 -75
- package/dist/session/protocol.js.map +0 -1
- package/dist/session/response-handler.d.ts +0 -48
- package/dist/session/response-handler.d.ts.map +0 -1
- package/dist/session/response-handler.js +0 -121
- package/dist/session/response-handler.js.map +0 -1
- package/dist/v3/client.d.ts +0 -24
- package/dist/v3/client.d.ts.map +0 -1
- package/dist/v3/client.js +0 -16
- package/dist/v3/client.js.map +0 -1
- package/src/session/bank-connection.ts +0 -51
- package/src/session/parameter-data.ts +0 -137
- package/src/session/pin-tan-client.ts +0 -186
- package/src/session/pin-tan-dialog.ts +0 -160
- package/src/session/protocol.ts +0 -311
- package/src/session/response-handler.ts +0 -130
- package/src/v3/client.ts +0 -29
|
@@ -2,7 +2,17 @@ import { FinTsBankError, FinTsProtocolError, parseBankData } from '../core/error
|
|
|
2
2
|
import { continuations, FeedbackCodes, hasCode } from '../core/feedback.js';
|
|
3
3
|
/** Most pages the client fetches for one query, far more than banks send. */
|
|
4
4
|
const maxPages = 1000;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Most further pages of one query that may ask for an approval, as its first page may: enough for a bank that asks anew
|
|
7
|
+
* for each page of a query of four pages, while the user approves four times per query at most, and loses the pages
|
|
8
|
+
* approved so far with any approval they cancel.
|
|
9
|
+
*/
|
|
10
|
+
const maxPageApprovals = 3;
|
|
11
|
+
/**
|
|
12
|
+
* Most data one query may hold, summed over its pages as `IncomingMessage3.size` measures it: the transport and the
|
|
13
|
+
* parser bound a single response only. The statements and transactions read from them have a budget of their own
|
|
14
|
+
* (`RecordBudget`).
|
|
15
|
+
*/
|
|
6
16
|
const maxQueryMebibytes = 128;
|
|
7
17
|
/**
|
|
8
18
|
* Keeps one dialog open for all calls and runs the queries in it.
|
|
@@ -13,13 +23,9 @@ const maxQueryMebibytes = 128;
|
|
|
13
23
|
*/
|
|
14
24
|
export class DialogRunner {
|
|
15
25
|
setup;
|
|
16
|
-
responses;
|
|
17
|
-
prompts;
|
|
18
26
|
dialog;
|
|
19
|
-
constructor(setup
|
|
27
|
+
constructor(setup) {
|
|
20
28
|
this.setup = setup;
|
|
21
|
-
this.responses = responses;
|
|
22
|
-
this.prompts = prompts;
|
|
23
29
|
}
|
|
24
30
|
/** The open dialog, or a new one once the setup is complete and the user has passed strong authentication. */
|
|
25
31
|
async open() {
|
|
@@ -34,7 +40,7 @@ export class DialogRunner {
|
|
|
34
40
|
async login() {
|
|
35
41
|
const dialog = await this.setup.newDialog();
|
|
36
42
|
try {
|
|
37
|
-
await
|
|
43
|
+
await dialog.login();
|
|
38
44
|
return dialog;
|
|
39
45
|
}
|
|
40
46
|
catch (error) {
|
|
@@ -61,31 +67,43 @@ export class DialogRunner {
|
|
|
61
67
|
const pages = await this.fetchPages(dialog, query.order);
|
|
62
68
|
return parseBankData(() => query.read(pages));
|
|
63
69
|
}
|
|
64
|
-
/** Sends `order` in `dialog` and completes its approval. */
|
|
65
|
-
async run(dialog, order) {
|
|
66
|
-
this.prompts.checkOpen();
|
|
70
|
+
/** Sends `order` in `dialog` and completes its approval, which `admitApproval` may refuse (`SignedDialog.send`). */
|
|
71
|
+
async run(dialog, order, admitApproval) {
|
|
67
72
|
try {
|
|
68
|
-
return await
|
|
73
|
+
return await dialog.send(order, admitApproval);
|
|
69
74
|
}
|
|
70
75
|
catch (error) {
|
|
71
76
|
// The bank rejected the order and the dialog stays usable, or the bank ended the dialog or rejected the PIN and
|
|
72
|
-
// the dialog is discarded already. A cancelled or
|
|
73
|
-
// unknown state.
|
|
77
|
+
// the dialog is discarded already. A cancelled, failed or refused approval, or a broken connection, leaves the
|
|
78
|
+
// dialog in an unknown state.
|
|
74
79
|
if (!(error instanceof FinTsBankError))
|
|
75
80
|
await this.end();
|
|
76
81
|
throw error;
|
|
77
82
|
}
|
|
78
83
|
}
|
|
79
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Sends the order built by `order` until the bank has delivered all pages (Formals B.6.3, "Aufsetzpunkt"), and
|
|
86
|
+
* completes the approval each asks for, that of `maxPageApprovals` further pages at most.
|
|
87
|
+
*/
|
|
80
88
|
async fetchPages(dialog, order) {
|
|
81
89
|
const pages = [];
|
|
82
90
|
const seen = new Set();
|
|
83
91
|
let size = 0;
|
|
92
|
+
let pageApprovals = 0;
|
|
93
|
+
const admitPageApproval = () => {
|
|
94
|
+
if (pageApprovals === maxPageApprovals) {
|
|
95
|
+
throw new FinTsProtocolError(`The bank asks for an approval of more than ${maxPageApprovals} further pages of one query; ask for a shorter period`);
|
|
96
|
+
}
|
|
97
|
+
pageApprovals++;
|
|
98
|
+
};
|
|
84
99
|
let continuation;
|
|
85
100
|
for (;;) {
|
|
86
|
-
const page = await this.run(dialog, order(continuation));
|
|
101
|
+
const page = await this.run(dialog, order(continuation), continuation === undefined ? undefined : admitPageApproval);
|
|
87
102
|
pages.push(page);
|
|
88
103
|
size += page.size;
|
|
104
|
+
if (size > maxQueryMebibytes * 1024 * 1024) {
|
|
105
|
+
throw new FinTsProtocolError(`The bank sends more than ${maxQueryMebibytes} MiB for one query; ask for a shorter period`);
|
|
106
|
+
}
|
|
89
107
|
const positions = [...continuations(page.feedback)];
|
|
90
108
|
// A message carries one order, so the bank names one position at most.
|
|
91
109
|
if (positions.length > 1)
|
|
@@ -98,14 +116,11 @@ export class DialogRunner {
|
|
|
98
116
|
}
|
|
99
117
|
return pages;
|
|
100
118
|
}
|
|
101
|
-
// A repeated position or endless pages would keep the client busy forever
|
|
119
|
+
// A repeated position or endless pages would keep the client busy forever.
|
|
102
120
|
if (seen.has(continuation) || pages.length === maxPages) {
|
|
103
121
|
throw new FinTsProtocolError('The bank does not stop sending pages');
|
|
104
122
|
}
|
|
105
123
|
seen.add(continuation);
|
|
106
|
-
if (size > maxQueryMebibytes * 1024 * 1024) {
|
|
107
|
-
throw new FinTsProtocolError(`The bank sends more than ${maxQueryMebibytes} MiB for one query; ask for a shorter period`);
|
|
108
|
-
}
|
|
109
124
|
}
|
|
110
125
|
}
|
|
111
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-runner.js","sourceRoot":"","sources":["../../src/session/dialog-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|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xD,MAAM,IAAI,kBAAkB,CAAC,sCAAsC,CAAC,CAAC;YACvE,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,73 +1,78 @@
|
|
|
1
|
-
import { FinTsBankError } from '../core/errors.js';
|
|
1
|
+
import { FinTsLoginRefusedError, type FinTsBankError } from '../core/errors.js';
|
|
2
|
+
import { type FinTsFeedback } from '../core/feedback.js';
|
|
2
3
|
import type { TanMethod } from '../tan/tan-models.js';
|
|
4
|
+
import type { PinGuard } from '../v3/protocol.js';
|
|
3
5
|
/**
|
|
4
6
|
* The kind of request a bank response answers, which decides what its errors mean for the login (`LoginGuard.judge`)
|
|
5
7
|
* and whether they can reject a TAN:
|
|
6
|
-
* - `login`: the login that opens a dialog;
|
|
7
|
-
* - `loginWithOrder`: a login that carries an order in the same message, whose errors may concern the order alone;
|
|
8
|
+
* - `login`: the login that opens a dialog, which carries no order;
|
|
8
9
|
* - `order`: an order in a dialog the bank has opened;
|
|
9
10
|
* - `approval`: a message that completes an approval, the TAN or the question whether the user approved in the app.
|
|
10
11
|
*/
|
|
11
|
-
export type RequestKind = 'login' | '
|
|
12
|
+
export type RequestKind = 'login' | 'order' | 'approval';
|
|
12
13
|
/**
|
|
13
14
|
* A reason for a refused login that the session can take care of by itself, after which it logs in once more: the user
|
|
14
15
|
* may not use the TAN method the login was signed with, or the bank no longer accepts the customer system ID.
|
|
15
16
|
*/
|
|
16
17
|
export type RefusalReason = 'tanMethodNotAllowed' | 'systemIdRejected';
|
|
18
|
+
/** What the saved state keeps of the guard: the return codes of the bank's refusal, and `unreadLogins`. */
|
|
19
|
+
export interface LoginGuardState {
|
|
20
|
+
readonly refusal: readonly FinTsFeedback[] | undefined;
|
|
21
|
+
readonly unreadLogins: number;
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* Banks lock the access after a few failed attempts, and a return code does not always tell whether the PIN was the
|
|
22
|
-
* reason. So `judge` counts as a refused login:
|
|
23
|
-
* - a rejected PIN, wherever the bank reports it;
|
|
24
|
-
* - any other error in the answer to a login, unless the login carries an order and the bank keeps the dialog open:
|
|
25
|
-
* then the error concerns the order.
|
|
26
|
-
*
|
|
27
|
-
* Errors in the answer to an order or an approval are no refusal, such as a wrong TAN at login: the bank checks the PIN
|
|
28
|
-
* before it asks for the approval. New login data (return code 3072) end the old ones for good (`refuse`).
|
|
24
|
+
* Holds the PIN and hands it out only while no login is refused (`pin`), so that a retrying app cannot lock the user's
|
|
25
|
+
* access. `FinTsLoginRefusedError` tells which logins count as refused; `judge` decides it for each answer.
|
|
29
26
|
*
|
|
30
|
-
*
|
|
31
|
-
* session has taken care of a
|
|
32
|
-
*
|
|
27
|
+
* A refusal counts at once and fails closed: only `remedied` lifts it, within the call that met it (`runCall`), once
|
|
28
|
+
* the session has taken care of a reason it names, or has failed the call trying, each reason once per call, so that a
|
|
29
|
+
* call sends at most three logins the bank refuses. A refusal that outlasts the call is final, and the guard forgets
|
|
30
|
+
* the PIN; only a PIN the user enters anew lifts it (`replacePin`), unless it brings new login data.
|
|
33
31
|
*/
|
|
34
|
-
export declare class LoginGuard {
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
export declare class LoginGuard implements PinGuard {
|
|
33
|
+
#private;
|
|
34
|
+
private refusalValue;
|
|
35
|
+
/** The TAN method of the login `refusalValue` refused, which a restored refusal does not tell. */
|
|
36
|
+
private refusedMethod;
|
|
37
|
+
/** Logins sent since the bank last took the PIN whose answer the client has not read. */
|
|
38
|
+
private unreadLogins;
|
|
39
|
+
/** The refusal of `maxUnreadLogins` unread logins, kept so that `check` throws the same error each time. */
|
|
40
|
+
private unreadLoginsRefusal;
|
|
41
|
+
/** The reasons `remedied` has lifted a refusal for in the running call. */
|
|
42
|
+
private readonly pardonedReasons;
|
|
43
|
+
constructor(pin: string);
|
|
44
|
+
/** The PIN to sign a message with; throws the refusal instead (`check`), and `FinTsStateError` once closed. */
|
|
45
|
+
get pin(): string;
|
|
46
|
+
/** Throws the refusal, if there is one. */
|
|
39
47
|
check(): void;
|
|
40
|
-
/**
|
|
41
|
-
get
|
|
42
|
-
/**
|
|
43
|
-
|
|
48
|
+
/** The bank's refusal, else that of `maxUnreadLogins` unread logins; `undefined` while there is none. */
|
|
49
|
+
get refusal(): FinTsLoginRefusedError | undefined;
|
|
50
|
+
/** Counts a login signed with the PIN as unread until `judge` reads its answer. */
|
|
51
|
+
loginSent(): void;
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* `dialogOpen` tells whether the bank keeps the dialog open after its answer.
|
|
53
|
+
* Judges `error`, if the answer to a request of `kind` in a dialog signed with `method` has one: returns the refusal
|
|
54
|
+
* of the login it amounts to, and records it unless the guard holds one already. Any error refuses a login; after the
|
|
55
|
+
* login only one that refuses it itself, a rejected PIN or new login data, since the bank checked the PIN before.
|
|
49
56
|
*/
|
|
50
|
-
judge(error: FinTsBankError, kind: RequestKind,
|
|
51
|
-
/**
|
|
52
|
-
|
|
57
|
+
judge(error: FinTsBankError | undefined, kind: RequestKind, method: TanMethod): FinTsLoginRefusedError | undefined;
|
|
58
|
+
/** Runs `call`, one call of the client; a refusal that outlasts it is final, and the next call remedies anew. */
|
|
59
|
+
runCall<T>(call: () => Promise<T>): Promise<T>;
|
|
53
60
|
/**
|
|
54
|
-
* Runs `
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* A refused login is thrown, and so is a wrong TAN, which the user must hear of. An aborted dialog counts as a
|
|
58
|
-
* rejection: banks end the dialog along with many.
|
|
61
|
+
* Runs `attempt`, which may log in, and runs it once more each time `remedy` takes care of a reason the refusal it
|
|
62
|
+
* failed with names; `remedy` gets the reason and the TAN method of the refused login, and returns whether it could.
|
|
59
63
|
*/
|
|
60
|
-
|
|
64
|
+
remedied<T>(attempt: () => Promise<T>, remedy: (reason: RefusalReason, rejected: TanMethod) => Promise<boolean>): Promise<T>;
|
|
61
65
|
/**
|
|
62
|
-
*
|
|
63
|
-
* the
|
|
64
|
-
* login data.
|
|
65
|
-
*
|
|
66
|
-
* Only the return codes of the refusal itself count: TAN methods listed earlier say nothing about this login.
|
|
66
|
+
* Signs with `pin` from now on, a PIN the user has entered anew and the protocol can send, and lifts the refusal.
|
|
67
|
+
* Throws the refusal instead where it brings new login data, which end the old ones for good.
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
replacePin(pin: string): void;
|
|
70
|
+
/** Forgets the PIN; the client calls it once it is closed. */
|
|
71
|
+
close(): void;
|
|
72
|
+
saveState(): LoginGuardState;
|
|
73
|
+
/** Restores what `saveState` returned; a restored refusal is final, also one without return codes. */
|
|
74
|
+
restoreState(saved: LoginGuardState): void;
|
|
75
|
+
private liftRefusal;
|
|
76
|
+
private forgetPinIfRefused;
|
|
72
77
|
}
|
|
73
78
|
//# sourceMappingURL=login-guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-guard.d.ts","sourceRoot":"","sources":["../../src/session/login-guard.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"login-guard.d.ts","sourceRoot":"","sources":["../../src/session/login-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EAGtB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA+C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD;;;GAGG;AACH,MAAM,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AE,MAAM,GAAG,IAAI;IAQ7B,8DAA8D;IAC9D,KAAK,IAAI,IAAI;IAIb,SAAS,IAAI,eAAe;IAI5B,sGAAsG;IACtG,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAW1C,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,kBAAkB;CAG3B"}
|
|
@@ -1,109 +1,196 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { clientClosedError, FinTsLoginDataChangedError, FinTsLoginRefusedError, FinTsPinError, loginRefusalFor, } from '../core/errors.js';
|
|
2
2
|
import { allowedTanMethodsIn, FeedbackCodes, hasCode } from '../core/feedback.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* PIN
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* then the error concerns the order.
|
|
12
|
-
*
|
|
13
|
-
* Errors in the answer to an order or an approval are no refusal, such as a wrong TAN at login: the bank checks the PIN
|
|
14
|
-
* before it asks for the approval. New login data (return code 3072) end the old ones for good (`refuse`).
|
|
4
|
+
* Logins in a row whose answer the client could not read, after which it sends the PIN no more: one may be a glitch of
|
|
5
|
+
* the connection, but with two the client would not learn of a wrong PIN before the bank locks the access.
|
|
6
|
+
*/
|
|
7
|
+
const maxUnreadLogins = 2;
|
|
8
|
+
/**
|
|
9
|
+
* Holds the PIN and hands it out only while no login is refused (`pin`), so that a retrying app cannot lock the user's
|
|
10
|
+
* access. `FinTsLoginRefusedError` tells which logins count as refused; `judge` decides it for each answer.
|
|
15
11
|
*
|
|
16
|
-
*
|
|
17
|
-
* session has taken care of a
|
|
18
|
-
*
|
|
12
|
+
* A refusal counts at once and fails closed: only `remedied` lifts it, within the call that met it (`runCall`), once
|
|
13
|
+
* the session has taken care of a reason it names, or has failed the call trying, each reason once per call, so that a
|
|
14
|
+
* call sends at most three logins the bank refuses. A refusal that outlasts the call is final, and the guard forgets
|
|
15
|
+
* the PIN; only a PIN the user enters anew lifts it (`replacePin`), unless it brings new login data.
|
|
19
16
|
*/
|
|
20
17
|
export class LoginGuard {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
18
|
+
// ECMAScript private, so that neither `util.inspect` nor `JSON.stringify` of the client reaches it.
|
|
19
|
+
#pin;
|
|
20
|
+
refusalValue;
|
|
21
|
+
/** The TAN method of the login `refusalValue` refused, which a restored refusal does not tell. */
|
|
22
|
+
refusedMethod;
|
|
23
|
+
/** Logins sent since the bank last took the PIN whose answer the client has not read. */
|
|
24
|
+
unreadLogins = 0;
|
|
25
|
+
/** The refusal of `maxUnreadLogins` unread logins, kept so that `check` throws the same error each time. */
|
|
26
|
+
unreadLoginsRefusal;
|
|
27
|
+
/** The reasons `remedied` has lifted a refusal for in the running call. */
|
|
28
|
+
pardonedReasons = new Set();
|
|
29
|
+
constructor(pin) {
|
|
30
|
+
this.#pin = pin;
|
|
31
|
+
}
|
|
32
|
+
/** The PIN to sign a message with; throws the refusal instead (`check`), and `FinTsStateError` once closed. */
|
|
33
|
+
get pin() {
|
|
34
|
+
this.check();
|
|
35
|
+
if (this.#pin === undefined)
|
|
36
|
+
throw clientClosedError();
|
|
37
|
+
return this.#pin;
|
|
38
|
+
}
|
|
39
|
+
/** Throws the refusal, if there is one. */
|
|
25
40
|
check() {
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
const refusal = this.refusal;
|
|
42
|
+
if (refusal !== undefined)
|
|
43
|
+
throw refusal;
|
|
28
44
|
}
|
|
29
|
-
/**
|
|
30
|
-
get
|
|
31
|
-
|
|
45
|
+
/** The bank's refusal, else that of `maxUnreadLogins` unread logins; `undefined` while there is none. */
|
|
46
|
+
get refusal() {
|
|
47
|
+
if (this.refusalValue !== undefined || this.unreadLogins < maxUnreadLogins)
|
|
48
|
+
return this.refusalValue;
|
|
49
|
+
this.unreadLoginsRefusal ??= new FinTsLoginRefusedError([], `The answers to the last ${maxUnreadLogins} logins were lost or unreadable, and the bank may have counted them ` +
|
|
50
|
+
'as failed attempts');
|
|
51
|
+
return this.unreadLoginsRefusal;
|
|
32
52
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
/** Counts a login signed with the PIN as unread until `judge` reads its answer. */
|
|
54
|
+
loginSent() {
|
|
55
|
+
this.unreadLogins++;
|
|
36
56
|
}
|
|
37
57
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* `dialogOpen` tells whether the bank keeps the dialog open after its answer.
|
|
58
|
+
* Judges `error`, if the answer to a request of `kind` in a dialog signed with `method` has one: returns the refusal
|
|
59
|
+
* of the login it amounts to, and records it unless the guard holds one already. Any error refuses a login; after the
|
|
60
|
+
* login only one that refuses it itself, a rejected PIN or new login data, since the bank checked the PIN before.
|
|
42
61
|
*/
|
|
43
|
-
judge(error, kind,
|
|
44
|
-
const refused = error instanceof
|
|
45
|
-
if (
|
|
46
|
-
this.
|
|
47
|
-
|
|
62
|
+
judge(error, kind, method) {
|
|
63
|
+
const refused = error instanceof FinTsLoginRefusedError || (error !== undefined && kind === 'login');
|
|
64
|
+
if (kind === 'login')
|
|
65
|
+
this.unreadLogins = refused ? Math.max(0, this.unreadLogins - 1) : 0;
|
|
66
|
+
if (!refused)
|
|
67
|
+
return undefined;
|
|
68
|
+
const refusal = loginRefusalFor(error.feedback);
|
|
69
|
+
if (this.refusalValue === undefined) {
|
|
70
|
+
this.refusalValue = refusal;
|
|
71
|
+
this.refusedMethod = method;
|
|
48
72
|
}
|
|
49
|
-
return
|
|
73
|
+
return refusal;
|
|
50
74
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
this.refusal ??= error;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Runs `lookup`, which only completes data, such as the SEPA account list; `undefined` where the bank rejects it, so
|
|
57
|
-
* that the caller carries on without it.
|
|
58
|
-
*
|
|
59
|
-
* A refused login is thrown, and so is a wrong TAN, which the user must hear of. An aborted dialog counts as a
|
|
60
|
-
* rejection: banks end the dialog along with many.
|
|
61
|
-
*/
|
|
62
|
-
async tryLookUp(lookup) {
|
|
75
|
+
/** Runs `call`, one call of the client; a refusal that outlasts it is final, and the next call remedies anew. */
|
|
76
|
+
async runCall(call) {
|
|
63
77
|
try {
|
|
64
|
-
return await
|
|
78
|
+
return await call();
|
|
65
79
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return undefined;
|
|
80
|
+
finally {
|
|
81
|
+
this.pardonedReasons.clear();
|
|
82
|
+
this.forgetPinIfRefused();
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* login data.
|
|
76
|
-
*
|
|
77
|
-
* Only the return codes of the refusal itself count: TAN methods listed earlier say nothing about this login.
|
|
86
|
+
* Runs `attempt`, which may log in, and runs it once more each time `remedy` takes care of a reason the refusal it
|
|
87
|
+
* failed with names; `remedy` gets the reason and the TAN method of the refused login, and returns whether it could.
|
|
78
88
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
async remedied(attempt, remedy) {
|
|
90
|
+
// A refusal of an earlier call stops the attempt before it sends the PIN; there is nothing to remedy.
|
|
91
|
+
if (this.refusal !== undefined)
|
|
92
|
+
return attempt();
|
|
93
|
+
for (;;) {
|
|
94
|
+
try {
|
|
95
|
+
return await attempt();
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const refusal = this.refusalValue;
|
|
99
|
+
const rejected = this.refusedMethod;
|
|
100
|
+
// Only the bank's refusal the guard holds names reasons; any other error, a second refusal too, fails the call.
|
|
101
|
+
if (refusal === undefined || error !== refusal || rejected === undefined)
|
|
102
|
+
throw error;
|
|
103
|
+
const reason = remediableReasons(refusal, rejected).find((r) => !this.pardonedReasons.has(r));
|
|
104
|
+
if (reason === undefined)
|
|
105
|
+
throw error;
|
|
106
|
+
this.pardonedReasons.add(reason);
|
|
107
|
+
// The refusal named a reason the session takes care of, not the PIN, so it does not outlast a remedy that fails,
|
|
108
|
+
// such as a TAN method prompt the app ends: the call fails with the remedy's own error. On a closed client the
|
|
109
|
+
// next attempt fails before it sends anything.
|
|
110
|
+
const remedied = await remedy(reason, rejected).catch((remedyError) => {
|
|
111
|
+
this.liftRefusal();
|
|
112
|
+
throw remedyError;
|
|
113
|
+
});
|
|
114
|
+
if (!remedied)
|
|
115
|
+
throw error;
|
|
116
|
+
this.liftRefusal();
|
|
117
|
+
}
|
|
86
118
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Signs with `pin` from now on, a PIN the user has entered anew and the protocol can send, and lifts the refusal.
|
|
122
|
+
* Throws the refusal instead where it brings new login data, which end the old ones for good.
|
|
123
|
+
*/
|
|
124
|
+
replacePin(pin) {
|
|
125
|
+
if (this.refusalValue instanceof FinTsLoginDataChangedError)
|
|
126
|
+
throw this.refusalValue;
|
|
127
|
+
this.#pin = pin;
|
|
128
|
+
this.liftRefusal();
|
|
129
|
+
this.unreadLogins = 0;
|
|
130
|
+
this.unreadLoginsRefusal = undefined;
|
|
131
|
+
}
|
|
132
|
+
/** Forgets the PIN; the client calls it once it is closed. */
|
|
133
|
+
close() {
|
|
134
|
+
this.#pin = undefined;
|
|
135
|
+
}
|
|
136
|
+
saveState() {
|
|
137
|
+
return { refusal: this.refusalValue?.feedback, unreadLogins: this.unreadLogins };
|
|
138
|
+
}
|
|
139
|
+
/** Restores what `saveState` returned; a restored refusal is final, also one without return codes. */
|
|
140
|
+
restoreState(saved) {
|
|
141
|
+
if (saved.refusal !== undefined) {
|
|
142
|
+
this.refusalValue =
|
|
143
|
+
saved.refusal.length > 0
|
|
144
|
+
? loginRefusalFor(saved.refusal)
|
|
145
|
+
: new FinTsLoginRefusedError([], 'A login was refused, and the saved state no longer tells why');
|
|
93
146
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return reasons;
|
|
147
|
+
this.unreadLogins = Math.max(0, saved.unreadLogins);
|
|
148
|
+
this.forgetPinIfRefused();
|
|
97
149
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return;
|
|
102
|
-
this.refusal = undefined;
|
|
103
|
-
this.refusedMethodValue = undefined;
|
|
150
|
+
liftRefusal() {
|
|
151
|
+
this.refusalValue = undefined;
|
|
152
|
+
this.refusedMethod = undefined;
|
|
104
153
|
}
|
|
105
|
-
|
|
106
|
-
|
|
154
|
+
forgetPinIfRefused() {
|
|
155
|
+
if (this.refusal !== undefined)
|
|
156
|
+
this.#pin = undefined;
|
|
107
157
|
}
|
|
108
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The reasons `refusal`, of a login signed with `method`, names that the session can take care of: a TAN method the
|
|
161
|
+
* refusal names as not allowed (`refusesMethod`), and 9391. None for a rejected PIN or new login data.
|
|
162
|
+
*/
|
|
163
|
+
function remediableReasons(refusal, method) {
|
|
164
|
+
if (refusal instanceof FinTsPinError || refusal instanceof FinTsLoginDataChangedError)
|
|
165
|
+
return [];
|
|
166
|
+
const reasons = [];
|
|
167
|
+
if (refusesMethod(refusal.feedback, method))
|
|
168
|
+
reasons.push('tanMethodNotAllowed');
|
|
169
|
+
if (hasCode(refusal.feedback, FeedbackCodes.newSystemIdRequired))
|
|
170
|
+
reasons.push('systemIdRejected');
|
|
171
|
+
return reasons;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Error codes that cannot be about the PIN: 9050 (the message contains errors) and 9800, which only say that the
|
|
175
|
+
* message failed, and 9955 (the one-step method is not allowed).
|
|
176
|
+
*/
|
|
177
|
+
const errorsNotAboutThePin = new Set(['9050', FeedbackCodes.dialogAborted, '9955']);
|
|
178
|
+
/**
|
|
179
|
+
* Whether `feedback`, which refuses a login signed with `method`, names the method as the reason: a 3920 that lists the
|
|
180
|
+
* methods the user may use without it, or 9075 after the one-step method.
|
|
181
|
+
*
|
|
182
|
+
* Only the return codes of the refusal itself count: TAN methods listed earlier say nothing about this login. Banks
|
|
183
|
+
* list two-step methods only, so a 3920 always leaves the one-step method out, also where the login succeeds. After
|
|
184
|
+
* the one-step method a 3920 counts only where the bank names no other error than one not about the PIN: any other,
|
|
185
|
+
* such as "Anmeldung fehlgeschlagen", may be about it. PIN/TAN B.8.2 has the bank answer a one-step dialog of a user
|
|
186
|
+
* bound to two-step methods with 9955 and 3920.
|
|
187
|
+
*/
|
|
188
|
+
function refusesMethod(feedback, method) {
|
|
189
|
+
if (method.isOneStep && hasCode(feedback, FeedbackCodes.scaRequired))
|
|
190
|
+
return true;
|
|
191
|
+
const allowed = allowedTanMethodsIn(feedback);
|
|
192
|
+
if (allowed.length === 0 || allowed.includes(method.securityFunction))
|
|
193
|
+
return false;
|
|
194
|
+
return !method.isOneStep || feedback.every((f) => !f.isError || errorsNotAboutThePin.has(f.code));
|
|
195
|
+
}
|
|
109
196
|
//# sourceMappingURL=login-guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-guard.js","sourceRoot":"","sources":["../../src/session/login-guard.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"login-guard.js","sourceRoot":"","sources":["../../src/session/login-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACtB,aAAa,EACb,eAAe,GAEhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,OAAO,EAAsB,MAAM,qBAAqB,CAAC;AAyBtG;;;GAGG;AACH,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,OAAO,UAAU;IACrB,oGAAoG;IACpG,IAAI,CAAqB;IAEjB,YAAY,CAA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