Link ING and other European banks through Enable Banking

- Docker passes ENABLE_BANKING_APP_ID and ENABLE_BANKING_PRIVATE_KEY through
- transactions are keyed on entry_reference: Enable Banking says transaction_id
  may change between fetches, which imported rows twice
- a key pasted on one line keeps its own PEM label (PKCS#1 keys broke before)
- nginx keeps X-Forwarded-Proto/Host from a reverse proxy, so return links are https
- README: how to set up the app, the keys, and https if Enable Banking needs it

Checked against Enable Banking's API docs and tested end to end against a stand-in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MangaValkandClaude Opus 5.5 committed 2026-11-17 15:16:53 +01:00
1 parent cc22098868
commit ea53718e5d
6 files changed
+101 -7

No files matched your search

+15
View File
@@ -92,3 +92,18 @@ assert.equal(validCpf("123"), false);
}
console.log("feeds: ok");
// Enable Banking: transaction_id "may change" between fetches, entry_reference doesn't, so it is the id when both come.
{
const a = ebTxn({ transaction_id: "x1", entry_reference: "ref-9", booking_date: "2026-11-02", transaction_amount: { amount: "3.50" }, credit_debit_indicator: "DBIT", status: "BOOK" }, "u1")!;
const b = ebTxn({ transaction_id: "x2", entry_reference: "ref-9", booking_date: "2026-11-02", transaction_amount: { amount: "3.50" }, credit_debit_indicator: "DBIT", status: "BOOK" }, "u1")!;
assert.equal(a.plaid_transaction_id, b.plaid_transaction_id);
}
// A key pasted on one line keeps its own label, PKCS#1 included, and still signs.
{
const { generateKeyPairSync, createPrivateKey: load } = await import("node:crypto");
const rsa = generateKeyPairSync("rsa", { modulusLength: 2048 }).privateKey.export({ type: "pkcs1", format: "pem" }).toString();
const oneLine = rsa.replace(/\n/g, "");
assert.equal(pemFrom(oneLine), rsa);
assert.ok(load(pemFrom(oneLine)));
}
+6 -2
View File
@@ -27,9 +27,11 @@ async function call<T>(f: Fetch, label: string, url: string, init?: RequestInit)
// ---- Enable Banking (UK and Europe) ----
// A pasted key loses its line breaks in a one-line box: rebuild the PEM from whatever came in.
// Keeps the key's own label (PRIVATE KEY or RSA PRIVATE KEY): the body differs between the two, so one can't stand in for the other.
export function pemFrom(raw: string) {
const label = raw.match(/-----BEGIN ([A-Z ]+)-----/)?.[1] ?? "PRIVATE KEY";
const body = raw.replace(/\\n/g, "\n").replace(/-----[^-]+-----/g, "").replace(/\s+/g, "");
return `-----BEGIN PRIVATE KEY-----\n${body.match(/.{1,64}/g)?.join("\n") ?? ""}\n-----END PRIVATE KEY-----\n`;
return `-----BEGIN ${label}-----\n${body.match(/.{1,64}/g)?.join("\n") ?? ""}\n-----END ${label}-----\n`;
}
const b64 = (v: unknown) => Buffer.from(JSON.stringify(v)).toString("base64url");
export function ebJwt(env: Env, now = Date.now()) {
@@ -84,7 +86,9 @@ export function ebTxn(t: EbTxn, uid: string): FeedTxn | null {
const out = t.credit_debit_indicator === "DBIT";
const text = (Array.isArray(t.remittance_information) ? t.remittance_information.join(" ") : t.remittance_information) || t.note || "";
const other = (out ? t.creditor?.name : t.debtor?.name) ?? null;
const id = t.transaction_id || t.entry_reference || `${date}|${n}|${text}`; // no id from the bank: same day, amount and text is the same row
// entry_reference is fixed per account; Enable Banking says transaction_id "may change" between fetches, which would
// import the same row twice. No id from the bank: same day, amount and text is the same row.
const id = t.entry_reference || t.transaction_id || `${date}|${n}|${text}`;
return { plaid_transaction_id: `enablebanking:${uid}:${id}`, account_ref: `enablebanking:${uid}`, date: date.slice(0, 10), amount: out ? Math.abs(n) : -Math.abs(n), name: text || other || "Transaction", merchant_name: other, logo_url: null, pending: false, plaid_category: t.bank_transaction_code?.code ?? null };
}
async function ebFeed(env: Env, token: string, since: string, f?: Fetch) {