feat: add decoupled TAN and CAMT.052 support#45
Open
dtrunk90 wants to merge 4 commits intolarsdecker:masterfrom
Open
feat: add decoupled TAN and CAMT.052 support#45dtrunk90 wants to merge 4 commits intolarsdecker:masterfrom
dtrunk90 wants to merge 4 commits intolarsdecker:masterfrom
Conversation
Implements FinTS 3.0 decoupled TAN flow (tanProcess=2) for async app-based approval. Adds DecoupledTanManager with configurable polling, state machine (INITIATED→CONFIRMED), cancellation, and timeout handling. Dialog gains handleDecoupledTan/cancelDecoupledTan/checkDecoupledTanStatus methods. Fixes HKTAN process code to use "S" for status polling. HITANS timing fields (seconds) are now correctly converted to ms. Integration tests updated to reflect 0-second server values and timing-safe mock delays.
Adds HKCAZ request segment, HICAZ/HICAZS response segments, and a regex-based CAMT.052 XML parser. The parser maps CAMT fields to the mt940-js Transaction interface including name, description, bankReference, isCredit, isExpense, currency, counterparty IBAN/BIC, EndToEndId, mandate reference, and creditor ID. Includes unit tests for all new segments and the parser (namespaced XML, credit/debit, descriptionStructured).
There was a problem hiding this comment.
Pull request overview
Adds FinTS decoupled TAN (asynchronous/pushTAN-style) handling and introduces CAMT.052-based transaction fetching (HKCAZ/HICAZ/HICAZS) as an alternative to MT940 statements.
Changes:
- Add new CAMT-related segments (HKCAZ request, HICAZ response, HICAZS parameter segment) plus a CAMT.052 parser and tests.
- Implement/adjust decoupled TAN polling behavior (HKTAN process
"S"for status polling; HITANS timing conversion to ms). - Extend
Client.statements()andDialog.sync()to detect/support CAMT transactions and route statement fetching accordingly.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fints/src/segments/index.ts | Exports newly added CAMT segment implementations. |
| packages/fints/src/segments/hktan.ts | Allows HKTAN process "S" and serializes it like process "2" for polling. |
| packages/fints/src/segments/hkcaz.ts | Adds HKCAZ request segment serialization for CAMT transaction fetching. |
| packages/fints/src/segments/hicaz.ts | Adds HICAZ response segment deserialization for CAMT payload fields. |
| packages/fints/src/segments/hicazs.ts | Adds HICAZS parameter segment deserialization (max days + format). |
| packages/fints/src/segments/tests/test-hkcaz.ts | Tests HKCAZ serialization. |
| packages/fints/src/segments/tests/test-hicaz.ts | Tests HICAZ deserialization cases. |
| packages/fints/src/segments/tests/test-hicazs.ts | Tests HICAZS deserialization. |
| packages/fints/src/dialog.ts | Tracks CAMT support/version/format from sync response (currently has critical issues). |
| packages/fints/src/decoupled-tan/decoupled-tan-manager.ts | Uses HKTAN process "S", converts HITANS timing seconds→ms, and syncs dialog state on direct sends. |
| packages/fints/src/decoupled-tan/tests/test-decoupled-tan-integration.ts | Adjusts integration timing and in-flight cancellation/status checks. |
| packages/fints/src/client.ts | Adds CAMT statement path (HKCAZ/HICAZ) and decoupled TAN handling during CAMT fetch (currently has critical issues). |
| packages/fints/src/camt052-parser.ts | Implements regex-based CAMT.052 XML → Statement/Transaction mapping (currently has a balance-date parsing issue). |
| packages/fints/src/tests/test-camt052-parser.ts | Adds unit tests for CAMT.052 parsing (missing assertion that would catch the balance-date issue). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rewrite camt052-parser to use fast-xml-parser instead of regex, consistent with the existing v4 camt-parser; fixes balance date extraction for nested <Dt><Dt>YYYY-MM-DD</Dt></Dt> structure - Inject HKCAZ touchdown into each loop iteration in sendCamtStatementRequest to correctly handle paginated responses - Guard TanRequiredError handling with isDecoupledTan() so non-decoupled TANs are not silently consumed as push TAN challenges - Add balance date assertions to camt052-parser tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two related features needed for Sparda Bank (and other banks using modern FinTS authentication and CAMT-based account statements):
Decoupled TAN (pushTAN / app-based authentication)
tanProcess=2) where transaction approval happens asynchronously on a separate device (e.g. a mobile banking app)DecoupledTanManagerwith configurable polling, a full state machine (INITIATED → CHALLENGE_SENT → PENDING_CONFIRMATION → CONFIRMED / CANCELLED / TIMED_OUT / FAILED), user cancellation, and total timeoutDialoggains three new methods:handleDecoupledTan(),cancelDecoupledTan(),checkDecoupledTanStatus()"S"instead of"4"decoupledWaitBeforeFirstStatusRequest,decoupledWaitBetweenStatusRequests) are in seconds per spec and are now correctly converted to milliseconds3956(SCA pending),3076(PSD2 SCA required),0030(order accepted / TAN confirmed)CAMT.052 account statement support (HKCAZ/HICAZ)
HKCAZrequest segment (request CAMT account transactions)HICAZresponse segment (binary-encoded CAMT XML payload)HICAZSparameter segment (server capabilities: max days, supported CAMT format)parseCamt052()parser that maps CAMT.052 XML to the existingmt940-jsStatement/Transactioninterface, including:name,description,bankReference(Verwendungszweck from<Ustrd>)isCredit,isExpense,currency,amount,date,valueDateidfrom<AcctSvcrRef>(usable as transaction ID in Firefly III etc.)descriptionStructuredwith counterparty IBAN/BIC, EndToEndId, mandate reference, creditor IDns2:Ntry)Tests
HICAZ,HICAZS,HKCAZsegment serialization/deserializationparseCamt052covering credit/debit transactions, balances, account identification,descriptionStructured, and namespaced XMLReferences
larsdecker/n8n-nodes-fints#105