@coderoftime/fints 0.0.0-stage → 0.2.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.
Files changed (249) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/LICENSE +28 -0
  3. package/README.md +246 -2
  4. package/dist/client.d.ts +48 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +199 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/core/account.d.ts +168 -0
  9. package/dist/core/account.d.ts.map +1 -0
  10. package/dist/core/account.js +245 -0
  11. package/dist/core/account.js.map +1 -0
  12. package/dist/core/amount.d.ts +63 -0
  13. package/dist/core/amount.d.ts.map +1 -0
  14. package/dist/core/amount.js +192 -0
  15. package/dist/core/amount.js.map +1 -0
  16. package/dist/core/balance.d.ts +55 -0
  17. package/dist/core/balance.d.ts.map +1 -0
  18. package/dist/core/balance.js +54 -0
  19. package/dist/core/balance.js.map +1 -0
  20. package/dist/core/bank-info.d.ts +49 -0
  21. package/dist/core/bank-info.d.ts.map +1 -0
  22. package/dist/core/bank-info.js +52 -0
  23. package/dist/core/bank-info.js.map +1 -0
  24. package/dist/core/client.d.ts +161 -0
  25. package/dist/core/client.d.ts.map +1 -0
  26. package/dist/core/client.js +2 -0
  27. package/dist/core/client.js.map +1 -0
  28. package/dist/core/config.d.ts +80 -0
  29. package/dist/core/config.d.ts.map +1 -0
  30. package/dist/core/config.js +153 -0
  31. package/dist/core/config.js.map +1 -0
  32. package/dist/core/errors.d.ts +153 -0
  33. package/dist/core/errors.d.ts.map +1 -0
  34. package/dist/core/errors.js +247 -0
  35. package/dist/core/errors.js.map +1 -0
  36. package/dist/core/feedback.d.ts +72 -0
  37. package/dist/core/feedback.d.ts.map +1 -0
  38. package/dist/core/feedback.js +127 -0
  39. package/dist/core/feedback.js.map +1 -0
  40. package/dist/core/transaction.d.ts +103 -0
  41. package/dist/core/transaction.d.ts.map +1 -0
  42. package/dist/core/transaction.js +96 -0
  43. package/dist/core/transaction.js.map +1 -0
  44. package/dist/core/transport.d.ts +64 -0
  45. package/dist/core/transport.d.ts.map +1 -0
  46. package/dist/core/transport.js +149 -0
  47. package/dist/core/transport.js.map +1 -0
  48. package/dist/formats/camt.d.ts +32 -0
  49. package/dist/formats/camt.d.ts.map +1 -0
  50. package/dist/formats/camt.js +242 -0
  51. package/dist/formats/camt.js.map +1 -0
  52. package/dist/formats/mt940.d.ts +54 -0
  53. package/dist/formats/mt940.d.ts.map +1 -0
  54. package/dist/formats/mt940.js +376 -0
  55. package/dist/formats/mt940.js.map +1 -0
  56. package/dist/formats/readers.d.ts +15 -0
  57. package/dist/formats/readers.d.ts.map +1 -0
  58. package/dist/formats/readers.js +42 -0
  59. package/dist/formats/readers.js.map +1 -0
  60. package/dist/formats/record-budget.d.ts +7 -0
  61. package/dist/formats/record-budget.d.ts.map +1 -0
  62. package/dist/formats/record-budget.js +17 -0
  63. package/dist/formats/record-budget.js.map +1 -0
  64. package/dist/formats/sepa-purpose.d.ts +28 -0
  65. package/dist/formats/sepa-purpose.d.ts.map +1 -0
  66. package/dist/formats/sepa-purpose.js +89 -0
  67. package/dist/formats/sepa-purpose.js.map +1 -0
  68. package/dist/index.d.ts +28 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +27 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/session/app-approval.d.ts +66 -0
  73. package/dist/session/app-approval.d.ts.map +1 -0
  74. package/dist/session/app-approval.js +226 -0
  75. package/dist/session/app-approval.js.map +1 -0
  76. package/dist/session/dialog-runner.d.ts +31 -0
  77. package/dist/session/dialog-runner.d.ts.map +1 -0
  78. package/dist/session/dialog-runner.js +111 -0
  79. package/dist/session/dialog-runner.js.map +1 -0
  80. package/dist/session/login-guard.d.ts +78 -0
  81. package/dist/session/login-guard.d.ts.map +1 -0
  82. package/dist/session/login-guard.js +181 -0
  83. package/dist/session/login-guard.js.map +1 -0
  84. package/dist/session/sepa-accounts.d.ts +40 -0
  85. package/dist/session/sepa-accounts.d.ts.map +1 -0
  86. package/dist/session/sepa-accounts.js +112 -0
  87. package/dist/session/sepa-accounts.js.map +1 -0
  88. package/dist/session/session-setup.d.ts +80 -0
  89. package/dist/session/session-setup.d.ts.map +1 -0
  90. package/dist/session/session-setup.js +182 -0
  91. package/dist/session/session-setup.js.map +1 -0
  92. package/dist/session/session-state.d.ts +50 -0
  93. package/dist/session/session-state.d.ts.map +1 -0
  94. package/dist/session/session-state.js +182 -0
  95. package/dist/session/session-state.js.map +1 -0
  96. package/dist/session/signed-dialog.d.ts +77 -0
  97. package/dist/session/signed-dialog.d.ts.map +1 -0
  98. package/dist/session/signed-dialog.js +170 -0
  99. package/dist/session/signed-dialog.js.map +1 -0
  100. package/dist/session/tan-selection.d.ts +96 -0
  101. package/dist/session/tan-selection.d.ts.map +1 -0
  102. package/dist/session/tan-selection.js +189 -0
  103. package/dist/session/tan-selection.js.map +1 -0
  104. package/dist/session/user-prompts.d.ts +65 -0
  105. package/dist/session/user-prompts.d.ts.map +1 -0
  106. package/dist/session/user-prompts.js +184 -0
  107. package/dist/session/user-prompts.js.map +1 -0
  108. package/dist/tan/challenge.d.ts +135 -0
  109. package/dist/tan/challenge.d.ts.map +1 -0
  110. package/dist/tan/challenge.js +184 -0
  111. package/dist/tan/challenge.js.map +1 -0
  112. package/dist/tan/flicker.d.ts +42 -0
  113. package/dist/tan/flicker.d.ts.map +1 -0
  114. package/dist/tan/flicker.js +296 -0
  115. package/dist/tan/flicker.js.map +1 -0
  116. package/dist/tan/tan-image.d.ts +22 -0
  117. package/dist/tan/tan-image.d.ts.map +1 -0
  118. package/dist/tan/tan-image.js +43 -0
  119. package/dist/tan/tan-image.js.map +1 -0
  120. package/dist/tan/tan-models.d.ts +149 -0
  121. package/dist/tan/tan-models.d.ts.map +1 -0
  122. package/dist/tan/tan-models.js +153 -0
  123. package/dist/tan/tan-models.js.map +1 -0
  124. package/dist/util/async.d.ts +22 -0
  125. package/dist/util/async.d.ts.map +1 -0
  126. package/dist/util/async.js +45 -0
  127. package/dist/util/async.js.map +1 -0
  128. package/dist/util/bytes.d.ts +22 -0
  129. package/dist/util/bytes.d.ts.map +1 -0
  130. package/dist/util/bytes.js +128 -0
  131. package/dist/util/bytes.js.map +1 -0
  132. package/dist/util/call-context.d.ts +12 -0
  133. package/dist/util/call-context.d.ts.map +1 -0
  134. package/dist/util/call-context.js +30 -0
  135. package/dist/util/call-context.js.map +1 -0
  136. package/dist/util/dates.d.ts +55 -0
  137. package/dist/util/dates.d.ts.map +1 -0
  138. package/dist/util/dates.js +189 -0
  139. package/dist/util/dates.js.map +1 -0
  140. package/dist/util/errors.d.ts +17 -0
  141. package/dist/util/errors.d.ts.map +1 -0
  142. package/dist/util/errors.js +24 -0
  143. package/dist/util/errors.js.map +1 -0
  144. package/dist/util/immutable-map.d.ts +16 -0
  145. package/dist/util/immutable-map.d.ts.map +1 -0
  146. package/dist/util/immutable-map.js +38 -0
  147. package/dist/util/immutable-map.js.map +1 -0
  148. package/dist/util/json.d.ts +17 -0
  149. package/dist/util/json.d.ts.map +1 -0
  150. package/dist/util/json.js +62 -0
  151. package/dist/util/json.js.map +1 -0
  152. package/dist/util/text.d.ts +37 -0
  153. package/dist/util/text.d.ts.map +1 -0
  154. package/dist/util/text.js +107 -0
  155. package/dist/util/text.js.map +1 -0
  156. package/dist/util/xml.d.ts +36 -0
  157. package/dist/util/xml.d.ts.map +1 -0
  158. package/dist/util/xml.js +194 -0
  159. package/dist/util/xml.js.map +1 -0
  160. package/dist/v3/account-extension.d.ts +25 -0
  161. package/dist/v3/account-extension.d.ts.map +1 -0
  162. package/dist/v3/account-extension.js +173 -0
  163. package/dist/v3/account-extension.js.map +1 -0
  164. package/dist/v3/bank-connection.d.ts +34 -0
  165. package/dist/v3/bank-connection.d.ts.map +1 -0
  166. package/dist/v3/bank-connection.js +58 -0
  167. package/dist/v3/bank-connection.js.map +1 -0
  168. package/dist/v3/dialog.d.ts +112 -0
  169. package/dist/v3/dialog.d.ts.map +1 -0
  170. package/dist/v3/dialog.js +241 -0
  171. package/dist/v3/dialog.js.map +1 -0
  172. package/dist/v3/message.d.ts +85 -0
  173. package/dist/v3/message.d.ts.map +1 -0
  174. package/dist/v3/message.js +303 -0
  175. package/dist/v3/message.js.map +1 -0
  176. package/dist/v3/parameter-store.d.ts +75 -0
  177. package/dist/v3/parameter-store.d.ts.map +1 -0
  178. package/dist/v3/parameter-store.js +143 -0
  179. package/dist/v3/parameter-store.js.map +1 -0
  180. package/dist/v3/parameters.d.ts +105 -0
  181. package/dist/v3/parameters.d.ts.map +1 -0
  182. package/dist/v3/parameters.js +450 -0
  183. package/dist/v3/parameters.js.map +1 -0
  184. package/dist/v3/protocol.d.ts +61 -0
  185. package/dist/v3/protocol.d.ts.map +1 -0
  186. package/dist/v3/protocol.js +113 -0
  187. package/dist/v3/protocol.js.map +1 -0
  188. package/dist/v3/queries.d.ts +51 -0
  189. package/dist/v3/queries.d.ts.map +1 -0
  190. package/dist/v3/queries.js +120 -0
  191. package/dist/v3/queries.js.map +1 -0
  192. package/dist/v3/segments.d.ts +106 -0
  193. package/dist/v3/segments.d.ts.map +1 -0
  194. package/dist/v3/segments.js +325 -0
  195. package/dist/v3/segments.js.map +1 -0
  196. package/dist/v3/syntax.d.ts +127 -0
  197. package/dist/v3/syntax.d.ts.map +1 -0
  198. package/dist/v3/syntax.js +367 -0
  199. package/dist/v3/syntax.js.map +1 -0
  200. package/package.json +67 -4
  201. package/src/client.ts +252 -0
  202. package/src/core/account.ts +323 -0
  203. package/src/core/amount.ts +211 -0
  204. package/src/core/balance.ts +85 -0
  205. package/src/core/bank-info.ts +66 -0
  206. package/src/core/client.ts +186 -0
  207. package/src/core/config.ts +182 -0
  208. package/src/core/errors.ts +277 -0
  209. package/src/core/feedback.ts +140 -0
  210. package/src/core/transaction.ts +161 -0
  211. package/src/core/transport.ts +189 -0
  212. package/src/formats/camt.ts +266 -0
  213. package/src/formats/mt940.ts +419 -0
  214. package/src/formats/readers.ts +49 -0
  215. package/src/formats/record-budget.ts +18 -0
  216. package/src/formats/sepa-purpose.ts +94 -0
  217. package/src/index.ts +70 -0
  218. package/src/session/app-approval.ts +278 -0
  219. package/src/session/dialog-runner.ts +122 -0
  220. package/src/session/login-guard.ts +221 -0
  221. package/src/session/sepa-accounts.ts +115 -0
  222. package/src/session/session-setup.ts +184 -0
  223. package/src/session/session-state.ts +204 -0
  224. package/src/session/signed-dialog.ts +192 -0
  225. package/src/session/tan-selection.ts +203 -0
  226. package/src/session/user-prompts.ts +193 -0
  227. package/src/tan/challenge.ts +261 -0
  228. package/src/tan/flicker.ts +308 -0
  229. package/src/tan/tan-image.ts +38 -0
  230. package/src/tan/tan-models.ts +252 -0
  231. package/src/util/async.ts +48 -0
  232. package/src/util/bytes.ts +129 -0
  233. package/src/util/call-context.ts +41 -0
  234. package/src/util/dates.ts +210 -0
  235. package/src/util/errors.ts +27 -0
  236. package/src/util/immutable-map.ts +47 -0
  237. package/src/util/json.ts +67 -0
  238. package/src/util/text.ts +112 -0
  239. package/src/util/xml.ts +183 -0
  240. package/src/v3/account-extension.ts +185 -0
  241. package/src/v3/bank-connection.ts +67 -0
  242. package/src/v3/dialog.ts +283 -0
  243. package/src/v3/message.ts +373 -0
  244. package/src/v3/parameter-store.ts +160 -0
  245. package/src/v3/parameters.ts +524 -0
  246. package/src/v3/protocol.ts +148 -0
  247. package/src/v3/queries.ts +190 -0
  248. package/src/v3/segments.ts +374 -0
  249. package/src/v3/syntax.ts +369 -0
@@ -0,0 +1,182 @@
1
+ import { FinTsError, FinTsProtocolError, FinTsTransportError, parseBankData, tryLookUp } from '../core/errors.js';
2
+ import { hasErrors } from '../core/feedback.js';
3
+ import { FinTs3Dialog } from '../v3/dialog.js';
4
+ import { requireBankParameters } from '../v3/parameters.js';
5
+ import { tanMediaQuery } from '../v3/queries.js';
6
+ import { SignedDialog } from './signed-dialog.js';
7
+ /**
8
+ * What has to be settled before a login: the bank parameter data, the synchronization, and through `TanSelection` the
9
+ * TAN method and medium. Each of the dialogs this takes serves one purpose only.
10
+ *
11
+ * Where the bank refuses a login for a reason the session can take care of, `remedied` does so and logs in again.
12
+ */
13
+ export class SessionSetup {
14
+ session;
15
+ protocol;
16
+ tans;
17
+ constructor(session, protocol, tans) {
18
+ this.session = session;
19
+ this.protocol = protocol;
20
+ this.tans = tans;
21
+ }
22
+ /**
23
+ * The bank's general information: from an anonymous dialog where the bank answers one, else from the synchronization.
24
+ * No TAN method or medium is chosen for it.
25
+ */
26
+ async bankInfo() {
27
+ if (this.session.parameters.bankParameters === undefined)
28
+ await this.fetchBankParametersAnonymously();
29
+ if (this.session.parameters.bankParameters === undefined)
30
+ await this.synchronizeIfDue();
31
+ return requireBankParameters(this.session.parameters.bankParameters).bankInfo;
32
+ }
33
+ /** The TAN methods the bank allows for this user, which the synchronization reports. */
34
+ async methods() {
35
+ await this.loadParameters();
36
+ return this.tans.available();
37
+ }
38
+ /**
39
+ * Settles what is still open: the bank parameter data, the synchronization, the TAN method and medium. Returns the TAN
40
+ * media it looked up to choose the medium; `undefined` where it looked up none, or the bank listed none.
41
+ */
42
+ async prepare() {
43
+ await this.loadParameters();
44
+ await this.tans.ensureMethodChosen();
45
+ if (!this.tans.mediumToLookUp)
46
+ return undefined;
47
+ const media = await this.lookUpTanMedia();
48
+ await this.tans.chooseMedium(media);
49
+ return media;
50
+ }
51
+ /** A new dialog signed with the TAN method and medium in use, once `prepare` has settled them. */
52
+ async newDialog() {
53
+ await this.prepare();
54
+ return new SignedDialog(this.tans.newDialog(), this.session);
55
+ }
56
+ /** Runs `attempt`, which may log in, once more after each refused login `remedy` takes care of. */
57
+ remedied(attempt) {
58
+ return this.session.guard.remedied(attempt, (reason, rejected) => this.remedy(reason, rejected));
59
+ }
60
+ /**
61
+ * Takes care of `reason`, given for refusing a login signed with `rejected`, with another TAN method or a new
62
+ * synchronization; returns whether it could.
63
+ */
64
+ async remedy(reason, rejected) {
65
+ switch (reason) {
66
+ case 'tanMethodNotAllowed':
67
+ // The parameter data name the methods to choose from; the refusal may be the first to deliver them.
68
+ if (this.session.parameters.bankParameters === undefined)
69
+ await this.fetchBankParametersAnonymously();
70
+ return this.tans.replace(rejected);
71
+ case 'systemIdRejected':
72
+ // Without a customer system ID there is none to lose, and logging in once more would only send the PIN again.
73
+ return this.session.parameters.forgetSystemId();
74
+ }
75
+ }
76
+ /**
77
+ * Loads the bank parameter data if they are missing, then synchronizes if that is due.
78
+ *
79
+ * The bank parameter data come first, from an anonymous dialog: the dialogs signed with the PIN need them for the
80
+ * dialog language, the PIN length and the TAN methods (PIN/TAN B.4.3.1, Formals C.3.1.3). A bank that does not answer
81
+ * anonymously delivers them with the synchronization.
82
+ *
83
+ * After a refused login it throws the refusal right away, before the user is asked for a TAN method or medium.
84
+ */
85
+ async loadParameters() {
86
+ this.session.guard.check();
87
+ if (this.session.parameters.bankParameters === undefined)
88
+ await this.fetchBankParametersAnonymously();
89
+ await this.synchronizeIfDue();
90
+ }
91
+ /**
92
+ * Asks for the bank parameter data without logging in, keeps them where there are none from a dialog signed with the
93
+ * PIN (`ParameterStore.keepAnonymous`), and passes the bank's messages on: all an anonymous dialog tells, since the
94
+ * TAN methods it lists are not those of a user. A bank that does not answer anonymously is no error, but a failed
95
+ * connection is: the synchronization would only wait for the same server again.
96
+ */
97
+ async fetchBankParametersAnonymously() {
98
+ try {
99
+ const response = await this.requestBankParametersAnonymously();
100
+ this.session.parameters.keepAnonymous(response);
101
+ for (const message of response.bankMessages)
102
+ this.session.prompts.showBankMessage(message);
103
+ }
104
+ catch (error) {
105
+ // Optional: the login delivers the parameters as well.
106
+ if (error instanceof FinTsTransportError || !(error instanceof FinTsError))
107
+ throw error;
108
+ }
109
+ }
110
+ /**
111
+ * Asks for the bank parameter data in an anonymous dialog that announces strong customer authentication; a bank that
112
+ * rejects the announcement, with a return code or by failing on it, is asked again without it.
113
+ *
114
+ * A timeout or a broken connection is not a reason to ask again: it would only double the wait.
115
+ */
116
+ async requestBankParametersAnonymously() {
117
+ let announced;
118
+ try {
119
+ announced = await this.anonymousDialog(true);
120
+ }
121
+ catch (error) {
122
+ if (error instanceof FinTsTransportError && error.statusCode === undefined)
123
+ throw error;
124
+ if (!(error instanceof FinTsError))
125
+ throw error;
126
+ return this.anonymousDialog(false);
127
+ }
128
+ if (!hasErrors(announced.feedback) || announced.find('HIBPA') !== undefined)
129
+ return announced;
130
+ return this.anonymousDialog(false);
131
+ }
132
+ async anonymousDialog(announceSca) {
133
+ const dialog = FinTs3Dialog.anonymous(this.protocol);
134
+ try {
135
+ return await dialog.requestBankParameters(announceSca);
136
+ }
137
+ finally {
138
+ await dialog.end();
139
+ }
140
+ }
141
+ /**
142
+ * Runs the synchronization, a login in a dialog of its own, while there is no customer system ID, without which no
143
+ * regular dialog starts. It runs before the TAN method and medium are settled (`TanSelection.synchronizationDialog`
144
+ * tells which method signs it).
145
+ */
146
+ async synchronizeIfDue() {
147
+ if (this.session.parameters.systemId !== undefined)
148
+ return;
149
+ await this.once(this.tans.synchronizationDialog(), (dialog) => dialog.login(true));
150
+ // Set by the synchronization, which the compiler cannot see.
151
+ if (this.session.parameters.systemId === undefined) {
152
+ throw new FinTsProtocolError('The bank did not complete the synchronization');
153
+ }
154
+ }
155
+ /**
156
+ * The TAN media of the method in use; `undefined` if the bank does not list them or rejects the list, after which the
157
+ * client reports a missing medium before the login.
158
+ *
159
+ * The lookup runs in a dialog of its own, whose start asks for the list, since the regular dialog start needs the
160
+ * medium the list tells (PIN/TAN B.4.3.1.3).
161
+ */
162
+ async lookUpTanMedia() {
163
+ const query = tanMediaQuery(this.session.parameters);
164
+ if (query === undefined)
165
+ return undefined;
166
+ return tryLookUp(() => this.once(this.tans.lookupDialog(), async (dialog) => {
167
+ const answers = await dialog.loginWith(query.order(undefined));
168
+ return parseBankData(() => query.read(answers));
169
+ }));
170
+ }
171
+ /** Runs `use` in `dialog`, a dialog of its own, and ends it afterwards, however `use` ends. */
172
+ async once(dialog, use) {
173
+ const signed = new SignedDialog(dialog, this.session);
174
+ try {
175
+ return await use(signed);
176
+ }
177
+ finally {
178
+ await signed.end();
179
+ }
180
+ }
181
+ }
182
+ //# sourceMappingURL=session-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-setup.js","sourceRoot":"","sources":["../../src/session/session-setup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAEJ;IACA;IACA;IAHnB,YACmB,OAAqB,EACrB,QAAwB,EACxB,IAAkB;QAFlB,YAAO,GAAP,OAAO,CAAc;QACrB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,SAAI,GAAJ,IAAI,CAAc;IAClC,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,KAAK,SAAS;YAAE,MAAM,IAAI,CAAC,8BAA8B,EAAE,CAAC;QACtG,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,KAAK,SAAS;YAAE,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxF,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC;IAChF,CAAC;IAED,wFAAwF;IACxF,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,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AY,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YACnD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/D,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,+FAA+F;IACvF,KAAK,CAAC,IAAI,CAAI,MAAoB,EAAE,GAAyC;QACnF,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC;YACH,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { Account } from '../core/account.js';
2
+ import { type JsonObject } from '../util/json.js';
3
+ import type { ParameterStore } from '../v3/parameter-store.js';
4
+ import type { LoginGuard } from './login-guard.js';
5
+ /** The session, the parameter data and the guard's refusal as JSON, which `restoreSession` reads. */
6
+ export declare function saveSession(parameters: ParameterStore, guard: LoginGuard, session: SessionState): string;
7
+ /**
8
+ * The session saved in `json`, and the parameter data and the guard's refused login restored from it.
9
+ *
10
+ * A missing or damaged state, or one saved for another user, bank, server or protocol version, gives a new session,
11
+ * which only costs a new synchronization. The refused login belongs to the user at the bank, so it comes first: it holds
12
+ * for another server or protocol version as well, and where the rest is damaged; a state saved by the Dart package or
13
+ * an earlier version has none.
14
+ */
15
+ export declare function restoreSession(json: string | undefined, parameters: ParameterStore, guard: LoginGuard): SessionState;
16
+ /**
17
+ * The session data saved between app starts: the allowed TAN methods, the TAN method and medium in use, and the SEPA
18
+ * account list.
19
+ */
20
+ export declare class SessionState {
21
+ private allowedMethodsValue;
22
+ private tanMethodValue;
23
+ private tanMediumValue;
24
+ private sepaAccountsValue;
25
+ private sepaUpdVersion;
26
+ /** TAN methods the bank allows for this user (return code 3920); `undefined` until the bank has said. */
27
+ get allowedMethods(): readonly string[] | undefined;
28
+ /** Security function of the TAN method in use. */
29
+ get tanMethod(): string | undefined;
30
+ /** Name of the TAN medium in use. */
31
+ get tanMedium(): string | undefined;
32
+ /** Keeps the TAN methods the bank reports as allowed for this user. */
33
+ rememberAllowedMethods(securityFunctions: readonly string[]): void;
34
+ /**
35
+ * Switches to the TAN method `securityFunction` and the TAN `medium` together, so that no medium of another method
36
+ * stays behind; `undefined` leaves the choice to the next login.
37
+ */
38
+ useTanMethod(securityFunction: string | undefined, medium?: string): void;
39
+ /** Switches to the TAN `medium` of the method in use. */
40
+ useTanMedium(medium: string | undefined): void;
41
+ /** The SEPA account list read under the user parameter data of `updVersion`, if it is cached. */
42
+ sepaAccounts(updVersion: number | undefined): readonly Account[] | undefined;
43
+ /** Caches the SEPA account list `accounts`, read under the user parameter data of `updVersion`. */
44
+ cacheSepaAccounts(accounts: readonly Account[], updVersion: number | undefined): void;
45
+ /** Reads what `toJson` wrote; throws `FormatError` if `json` is damaged. */
46
+ static fromJson(json: JsonObject): SessionState;
47
+ /** The session as JSON data. */
48
+ toJson(): JsonObject;
49
+ }
50
+ //# sourceMappingURL=session-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-state.d.ts","sourceRoot":"","sources":["../../src/session/session-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAQL,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAQpE,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,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
2
+ import { hostOf } from '../core/config.js';
3
+ import { FinTsFeedback } from '../core/feedback.js';
4
+ import { FormatError } from '../util/errors.js';
5
+ import { isJsonObject, isString, readObject, readOptionalInt, readOptionalObject, readOptionalList, readOptionalString, } from '../util/json.js';
6
+ /** Layout of the saved session; a state of another layout is ignored. */
7
+ const stateFormat = 1;
8
+ /** The protocol version the state is for, named as the Dart package names it, so that both read each other's states. */
9
+ const protocolVersion = 'v300';
10
+ /** The session, the parameter data and the guard's refusal as JSON, which `restoreSession` reads. */
11
+ export function saveSession(parameters, guard, session) {
12
+ return JSON.stringify({
13
+ format: stateFormat,
14
+ version: protocolVersion,
15
+ owner: ownerOf(parameters.config),
16
+ session: session.toJson(),
17
+ // Under the key the Dart package reads as well.
18
+ protocol: parameters.saveState(),
19
+ loginGuard: guardStateToJson(guard.saveState()),
20
+ });
21
+ }
22
+ /**
23
+ * The session saved in `json`, and the parameter data and the guard's refused login restored from it.
24
+ *
25
+ * A missing or damaged state, or one saved for another user, bank, server or protocol version, gives a new session,
26
+ * which only costs a new synchronization. The refused login belongs to the user at the bank, so it comes first: it holds
27
+ * for another server or protocol version as well, and where the rest is damaged; a state saved by the Dart package or
28
+ * an earlier version has none.
29
+ */
30
+ export function restoreSession(json, parameters, guard) {
31
+ if (json === undefined)
32
+ return new SessionState();
33
+ try {
34
+ const saved = JSON.parse(json);
35
+ if (!isJsonObject(saved) || saved.format !== stateFormat)
36
+ return new SessionState();
37
+ const [server, ...user] = readOptionalList(saved, 'owner', isString) ?? [];
38
+ const expected = userOf(parameters.config);
39
+ if (user.length !== expected.length || user.some((value, i) => value !== expected[i]))
40
+ return new SessionState();
41
+ const loginGuard = readOptionalObject(saved, 'loginGuard');
42
+ if (loginGuard !== undefined)
43
+ guard.restoreState(guardStateFromJson(loginGuard));
44
+ if (server !== hostOf(parameters.config.url) || saved.version !== protocolVersion)
45
+ return new SessionState();
46
+ const session = SessionState.fromJson(readObject(saved, 'session'));
47
+ parameters.restoreState(readObject(saved, 'protocol'));
48
+ return session;
49
+ }
50
+ catch (error) {
51
+ // Damaged JSON, base64 or parameter data, and values of the wrong type, only cost a new synchronization.
52
+ if (error instanceof FormatError || error instanceof SyntaxError)
53
+ return new SessionState();
54
+ throw error;
55
+ }
56
+ }
57
+ /** Whose data a state holds, so that the state of another user or bank is never used: the server, then `userOf`. */
58
+ function ownerOf(config) {
59
+ return [hostOf(config.url), ...userOf(config)];
60
+ }
61
+ /** The user at the bank, whom a refused login belongs to. */
62
+ function userOf(config) {
63
+ return [config.bankCode, config.userId, config.customerId];
64
+ }
65
+ /**
66
+ * The session data saved between app starts: the allowed TAN methods, the TAN method and medium in use, and the SEPA
67
+ * account list.
68
+ */
69
+ export class SessionState {
70
+ allowedMethodsValue;
71
+ tanMethodValue;
72
+ tanMediumValue;
73
+ sepaAccountsValue;
74
+ sepaUpdVersion;
75
+ /** TAN methods the bank allows for this user (return code 3920); `undefined` until the bank has said. */
76
+ get allowedMethods() {
77
+ return this.allowedMethodsValue;
78
+ }
79
+ /** Security function of the TAN method in use. */
80
+ get tanMethod() {
81
+ return this.tanMethodValue;
82
+ }
83
+ /** Name of the TAN medium in use. */
84
+ get tanMedium() {
85
+ return this.tanMediumValue;
86
+ }
87
+ /** Keeps the TAN methods the bank reports as allowed for this user. */
88
+ rememberAllowedMethods(securityFunctions) {
89
+ this.allowedMethodsValue = Object.freeze([...securityFunctions]);
90
+ }
91
+ /**
92
+ * Switches to the TAN method `securityFunction` and the TAN `medium` together, so that no medium of another method
93
+ * stays behind; `undefined` leaves the choice to the next login.
94
+ */
95
+ useTanMethod(securityFunction, medium) {
96
+ this.tanMethodValue = securityFunction;
97
+ this.tanMediumValue = medium;
98
+ }
99
+ /** Switches to the TAN `medium` of the method in use. */
100
+ useTanMedium(medium) {
101
+ this.tanMediumValue = medium;
102
+ }
103
+ /** The SEPA account list read under the user parameter data of `updVersion`, if it is cached. */
104
+ sepaAccounts(updVersion) {
105
+ return updVersion !== undefined && updVersion === this.sepaUpdVersion ? this.sepaAccountsValue : undefined;
106
+ }
107
+ /** Caches the SEPA account list `accounts`, read under the user parameter data of `updVersion`. */
108
+ cacheSepaAccounts(accounts, updVersion) {
109
+ this.sepaAccountsValue = Object.freeze([...accounts]);
110
+ this.sepaUpdVersion = updVersion;
111
+ }
112
+ /** Reads what `toJson` wrote; throws `FormatError` if `json` is damaged. */
113
+ static fromJson(json) {
114
+ const allowedMethods = readOptionalList(json, 'allowedMethods', isString);
115
+ const sepaAccounts = readOptionalList(json, 'sepaAccounts', isJsonObject)?.map(accountFromJson);
116
+ const sepaUpdVersion = readOptionalInt(json, 'sepaUpdVersion');
117
+ const state = new SessionState();
118
+ state.useTanMethod(readOptionalString(json, 'tanMethod'), readOptionalString(json, 'tanMedium'));
119
+ if (allowedMethods !== undefined)
120
+ state.rememberAllowedMethods(allowedMethods);
121
+ if (sepaAccounts !== undefined)
122
+ state.cacheSepaAccounts(sepaAccounts, sepaUpdVersion);
123
+ return state;
124
+ }
125
+ /** The session as JSON data. */
126
+ toJson() {
127
+ return {
128
+ allowedMethods: this.allowedMethodsValue ?? null,
129
+ tanMethod: this.tanMethodValue ?? null,
130
+ tanMedium: this.tanMediumValue ?? null,
131
+ sepaUpdVersion: this.sepaUpdVersion ?? null,
132
+ sepaAccounts: this.sepaAccountsValue?.map(accountToJson) ?? null,
133
+ };
134
+ }
135
+ }
136
+ function accountToJson(a) {
137
+ return {
138
+ iban: a.iban ?? null,
139
+ bic: a.bic ?? null,
140
+ accountNumber: a.accountNumber ?? null,
141
+ subAccount: a.subAccount ?? null,
142
+ countryCode: a.countryCode,
143
+ bankCode: a.bankCode,
144
+ };
145
+ }
146
+ function accountFromJson(json) {
147
+ const bankCode = readOptionalString(json, 'bankCode');
148
+ if (bankCode === undefined)
149
+ throw new FormatError('Saved state: account without bank code');
150
+ return new Account({
151
+ iban: readOptionalString(json, 'iban'),
152
+ bic: readOptionalString(json, 'bic'),
153
+ accountNumber: readOptionalString(json, 'accountNumber'),
154
+ subAccount: readOptionalString(json, 'subAccount'),
155
+ countryCode: readOptionalString(json, 'countryCode'),
156
+ bankCode,
157
+ });
158
+ }
159
+ function guardStateToJson(state) {
160
+ return { refusal: state.refusal?.map(feedbackToJson) ?? null, unreadLogins: state.unreadLogins };
161
+ }
162
+ function guardStateFromJson(json) {
163
+ return {
164
+ refusal: readOptionalList(json, 'refusal', isJsonObject)?.map(feedbackFromJson),
165
+ unreadLogins: readOptionalInt(json, 'unreadLogins') ?? 0,
166
+ };
167
+ }
168
+ function feedbackToJson(f) {
169
+ return { code: f.code, reference: f.reference ?? null, text: f.text, parameters: [...f.parameters] };
170
+ }
171
+ function feedbackFromJson(json) {
172
+ const code = readOptionalString(json, 'code');
173
+ if (code === undefined)
174
+ throw new FormatError('Saved state: return code without code');
175
+ return new FinTsFeedback({
176
+ code,
177
+ reference: readOptionalString(json, 'reference'),
178
+ text: readOptionalString(json, 'text') ?? '',
179
+ parameters: readOptionalList(json, 'parameters', isString) ?? [],
180
+ });
181
+ }
182
+ //# sourceMappingURL=session-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-state.js","sourceRoot":"","sources":["../../src/session/session-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAoB,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,iBAAiB,CAAC;AAIzB,yEAAyE;AACzE,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,wHAAwH;AACxH,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,qGAAqG;AACrG,MAAM,UAAU,WAAW,CAAC,UAA0B,EAAE,KA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,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;QAC5C,UAAU,EAAE,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE;KACjE,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,77 @@
1
+ import type { FinTs3Dialog } from '../v3/dialog.js';
2
+ import { IncomingMessage3 } from '../v3/message.js';
3
+ import type { ParameterStore } from '../v3/parameter-store.js';
4
+ import type { SegmentSpec } from '../v3/syntax.js';
5
+ import type { LoginGuard } from './login-guard.js';
6
+ import type { SessionState } from './session-state.js';
7
+ import type { UserPrompts } from './user-prompts.js';
8
+ /** The parts of the session that every `SignedDialog` reports to. */
9
+ export interface SessionParts {
10
+ readonly parameters: ParameterStore;
11
+ readonly state: SessionState;
12
+ readonly prompts: UserPrompts;
13
+ readonly guard: LoginGuard;
14
+ }
15
+ /**
16
+ * A dialog signed with the PIN, which settles each answer before it hands it out: it keeps the parameter data of the
17
+ * dialog's opening, passes the notices on, has the `LoginGuard` judge the answer and throws its errors, and completes
18
+ * the approval the bank asks for. The session sends every message signed with the PIN through it, so that the guard
19
+ * judges every answer, that to the dialog's end included.
20
+ */
21
+ export declare class SignedDialog {
22
+ private readonly dialog;
23
+ private readonly session;
24
+ constructor(dialog: FinTs3Dialog, session: SessionParts);
25
+ /** Whether the bank knows this dialog and it has not ended. */
26
+ get isActive(): boolean;
27
+ /** Logs in, which opens the dialog; with `synchronize` the bank also assigns a customer system ID. */
28
+ login(synchronize?: boolean): Promise<IncomingMessage3>;
29
+ /**
30
+ * Logs in, asking strong authentication for `order`, then sends `order` in a message of its own, as for listing the
31
+ * TAN media while no medium is chosen yet (`FinTs3Dialog.startWith`); returns both answers.
32
+ */
33
+ loginWith(order: SegmentSpec): Promise<IncomingMessage3[]>;
34
+ /** Sends `order`, the first page of a query, and completes the approval the bank asks for. */
35
+ send(order: SegmentSpec): Promise<IncomingMessage3>;
36
+ /**
37
+ * Sends `order` for a further page of a query (Formals B.6.3), whose answer must not ask for an approval: the client
38
+ * completes that of the first page only, so that a bank that asks anew for every page cannot prompt the user once per
39
+ * page. Throws `FinTsProtocolError` if it asks for one.
40
+ */
41
+ sendFurtherPage(order: SegmentSpec): Promise<IncomingMessage3>;
42
+ /**
43
+ * Ends the dialog at the bank; does nothing if it is not active. Of the answer only a rejected PIN counts, which the
44
+ * guard judges: the dialog is over either way.
45
+ */
46
+ end(): Promise<void>;
47
+ /**
48
+ * Receives `response`, the answer to a request of `kind`: keeps its parameter data where it answers the `opening` of
49
+ * the dialog, the login or its approval, even alongside errors, since the remedy for a refused login may need them;
50
+ * passes its notices on; and has the guard judge it, then throws its errors, as the refusal of the login where they
51
+ * amount to one.
52
+ */
53
+ private receive;
54
+ /**
55
+ * Where `response` answers a login, a request of `kind` other than `order`, or its approval with new login data: ends
56
+ * the dialog, stops the client from logging in with the old ones, and fails the call with
57
+ * `FinTsLoginDataChangedError` (Rückmeldungscodes C.6). It runs before any approval, which would cost the user a TAN
58
+ * for a session that ends anyway. New login data next to an error are the login's refusal already
59
+ * (`loginRefusalFor`).
60
+ */
61
+ private retireOldLoginData;
62
+ /**
63
+ * Receives `response`, the answer to a request of `kind`, then completes the approval it asks for; returns it joined
64
+ * with the response that completes the approval.
65
+ *
66
+ * Throws `FinTsProtocolError` if that response asks for an approval once more: the bank has not executed the message
67
+ * then either, and read as done it would report an empty result.
68
+ */
69
+ private settle;
70
+ /** Passes on the notices in `response`: the TAN methods the user may use (3920), the bank's messages and warnings. */
71
+ private readNotices;
72
+ /** Asks the user for the TAN `approval` takes and sends it; `opening` tells whether it approves the login. */
73
+ private enterTan;
74
+ /** Waits for the user to approve in the banking app; `opening` tells whether the approval is that of the login. */
75
+ private awaitAppApproval;
76
+ }
77
+ //# sourceMappingURL=signed-dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-dialog.d.ts","sourceRoot":"","sources":["../../src/session/signed-dialog.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK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