Add draft FinanceKit device provider and durable upload inbox

Closed
SU
3mo ago
+2861-5

FinanceKit collects Wallet changes on iOS, but the native client needs a durable provider ingestion boundary before synchronizing with Sure. This draft adds a default-off, family-scoped device provider: the phone signs and encrypts an immutable upload, Sure durably accepts it, and scheduled workers finish the import without another phone request.

Refs #3485. This is a candidate for controlled Swift integration testing, not a production contract revision or closure of the issue.

Resulting behavior

  • Foreground OAuth/API-key administration supports enrollment, account mapping, health, receipts, replacement and disconnect. Background uploads use only the enrolled device key, with ES256 signatures and RSA-OAEP/A256GCM encryption.
  • Generation fencing, unique source identities, ordered inbox processing, signed receipts and atomic ledger/receipt commits protect replay and revocation. A persistent downstream outbox waits for recalculation and successful rules, including asynchronous enrichment acknowledgments, and retries lost work.
  • Exact decimal/sign mapping, observed booked/available balances, pending transitions, identity-only imports and protected-entry tombstones preserve Sure's ledger boundaries. Mapping rejects existing providers, including legacy links.
  • Review fixes repair production JOSE algorithm allowlists, JWK thumbprints, mapping body parsing, API resource-owner scoping, the account-read adapter interface, tombstone locking and downstream completion. The missing database schema and generated OpenAPI are included.
  • Pipelock excludes only the public Apple interoperability vector file and its generator; deployment credentials remain scanned.

Validation

All GitHub checks pass on a0e849ebc411f499b1b35b542e228f9932bc5946: Rails/lint/security workflow and Pipelock. The separate GitHub system-test job passed in 5m44s.

Devcontainer: Ruby 3.4.9, Rails 8.1, PostgreSQL 16, Redis and remote Chromium. All database work used dedicated test databases.

  • Migration succeeded and generated db/schema.rb.
  • Full Rails suite: 8,701 tests, 35,208 assertions, zero failures/errors, 33 skips.
  • Focused FinanceKit/API architecture suite: 53 tests, 235 assertions, zero failures/errors/skips. Covers actual database races, revocation, retry recovery, replay, and eventual balances/categorization after the device stops requesting.
  • Apple wire vectors: 4 tests, 28 assertions, no skips; production JOSE verification and decryption also pass.
  • OpenAPI regenerated: 409 documentation examples, zero failures.
  • RuboCop, ERB lint, Biome, Brakeman, API consistency checks and the pinned Pipelock diff scan pass.
  • Local browser suite: 117 tests, one trade-toast timing failure under concurrent full-suite load. Its screenshot shows successful creation; both trade tests passed on isolated retry (2 tests, 5 assertions). No unrelated trade code was changed. GitHub's separate full system-test job subsequently passed.

Swift testing and remaining gates

Testing revision: a0e849ebc411f499b1b35b542e228f9932bc5946. Follow controlled Swift integration testing, the wire contract, and the review record. Enable only a disposable test family, provision fresh destination keys, and keep the scheduled worker running. Public fixture keys must never configure a real instance.

Migration 20260910060000_create_financekit_inbox.rb includes the downstream retry lease. This is an unmerged draft migration; use a fresh disposable database when testing against an earlier prototype schema.

Mappings remain immutable and snapshots additive. Unknown source/transaction UUID continuity explicitly returns identity_reconciliation_required. Reviewable reconciliation/cutover, mapping edits, snapshot coverage reporting, overlapping destination-key rotation and abandoned-inbox retention remain production-adoption gates. No merge, controlled deployment, production enablement or Swift client's shipping contract pin has been changed.