@open-banking-io/client 0.1.1 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 open-banking.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <p align="center">
2
+ <a href="https://open-banking.io">
3
+ <img src="https://raw.githubusercontent.com/open-banking-io/clients/main/.github/logo.png" alt="open-banking.io" height="56">
4
+ </a>
5
+ </p>
6
+
1
7
  # @open-banking-io/client (Node / TypeScript)
2
8
 
3
9
  Server-to-server client for [open-banking.io](https://open-banking.io). It authenticates with your
@@ -18,7 +24,9 @@ const client = OpenBankingClient.fromCredentials("credentials.json");
18
24
 
19
25
  for (const account of await client.getAccounts()) {
20
26
  const booked = account.balances.find((b) => b.type === "ITBD");
21
- console.log(`${account.displayName ?? account.ownerName} ${account.iban}: ${booked?.amount} ${account.currency}`);
27
+ console.log(
28
+ `${account.displayName ?? account.ownerName} ${account.iban}: ${booked?.amount} ${account.currency}`,
29
+ );
22
30
 
23
31
  const page = await client.getTransactions(account.id, { limit: 50 });
24
32
  for (const t of page.items) {
@@ -36,6 +44,9 @@ Or construct it explicitly:
36
44
  const client = new OpenBankingClient({ apiBaseUrl, apiKey, privateKeyPkcs8 });
37
45
  ```
38
46
 
47
+ Every request carries a `User-Agent: open-banking-io/node/<version>` header and a default 30s timeout
48
+ (override via the `timeoutMs` option) so a hung connection can't block forever.
49
+
39
50
  ## Money
40
51
 
41
52
  Amounts (`balance.amount`, `transaction.amount`, `transaction.balanceAfterTransaction`) are exposed
@@ -44,9 +55,10 @@ library to avoid precision loss.
44
55
 
45
56
  ## Encryption
46
57
 
47
- Envelopes use **ECDH P-256 → HKDF-SHA256 → AES-256-GCM**. Decryption requires the private key from
48
- your credentials bundle and happens entirely in-process. See the
49
- [repo README](https://github.com/open-banking-io/clients) for the full scheme and the other language
50
- clients (.NET, Python).
58
+ Envelopes use **ECDH P-256 → HKDF-SHA256 → AES-256-GCM**, implemented with the built-in `node:crypto`
59
+ WebCrypto. Decryption requires the private key from your credentials bundle and happens entirely
60
+ in-process. Full wire format and the other language clients:
61
+ [repo README](https://github.com/open-banking-io/clients) ·
62
+ [`THREAT_MODEL.md`](https://github.com/open-banking-io/clients/blob/main/THREAT_MODEL.md).
51
63
 
52
64
  MIT licensed.
package/dist/index.cjs CHANGED
@@ -94,35 +94,115 @@ function base64ToBytes(b64) {
94
94
  return new Uint8Array(Buffer.from(b64, "base64"));
95
95
  }
96
96
 
97
+ // package.json
98
+ var package_default = {
99
+ name: "@open-banking-io/client",
100
+ version: "0.3.0",
101
+ description: "Server-to-server client for open-banking.io: API-key auth + client-side decryption of the zero-knowledge data envelopes with your exported private key.",
102
+ type: "module",
103
+ license: "MIT",
104
+ author: "open-banking.io",
105
+ keywords: [
106
+ "open-banking",
107
+ "psd2",
108
+ "zero-knowledge",
109
+ "encryption",
110
+ "fintech"
111
+ ],
112
+ repository: {
113
+ type: "git",
114
+ url: "https://github.com/open-banking-io/clients"
115
+ },
116
+ engines: {
117
+ node: ">=20"
118
+ },
119
+ files: [
120
+ "dist",
121
+ "README.md"
122
+ ],
123
+ main: "./dist/index.cjs",
124
+ module: "./dist/index.js",
125
+ types: "./dist/index.d.ts",
126
+ exports: {
127
+ ".": {
128
+ types: "./dist/index.d.ts",
129
+ import: "./dist/index.js",
130
+ require: "./dist/index.cjs"
131
+ }
132
+ },
133
+ scripts: {
134
+ build: "tsup",
135
+ test: "vitest run",
136
+ coverage: "vitest run --coverage",
137
+ typecheck: "tsc --noEmit",
138
+ lint: "eslint .",
139
+ "format:check": "prettier --check ."
140
+ },
141
+ overrides: {
142
+ esbuild: "^0.28.1"
143
+ },
144
+ devDependencies: {
145
+ "@eslint/js": "^10.0.1",
146
+ "@types/node": "^25.9.3",
147
+ "@vitest/coverage-v8": "^4.1.9",
148
+ eslint: "^10.5.0",
149
+ prettier: "^3.8.4",
150
+ tsup: "^8.5.1",
151
+ typescript: "^6.0.3",
152
+ "typescript-eslint": "^8.61.1",
153
+ vitest: "^4.1.9"
154
+ }
155
+ };
156
+
157
+ // src/version.ts
158
+ var VERSION2 = package_default.version;
159
+ var USER_AGENT = `open-banking-io/node/${VERSION2}`;
160
+
97
161
  // src/client.ts
98
162
  var OpenBankingClient = class _OpenBankingClient {
163
+ /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */
164
+ static DEFAULT_TIMEOUT_MS = 3e4;
99
165
  baseUrl;
100
166
  apiKey;
167
+ timeoutMs;
168
+ fetchImpl;
101
169
  privateKey;
102
170
  constructor(options) {
103
- const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;
171
+ const { apiBaseUrl, apiKey, privateKeyPkcs8, timeoutMs } = options;
104
172
  if (!apiBaseUrl?.trim()) throw new Error("apiBaseUrl is required");
105
173
  if (!apiKey?.trim()) throw new Error("apiKey is required");
106
174
  if (!privateKeyPkcs8?.trim()) throw new Error("privateKeyPkcs8 is required");
107
- this.baseUrl = apiBaseUrl.replace(/\/+$/, "");
175
+ let end = apiBaseUrl.length;
176
+ while (end > 0 && apiBaseUrl.charCodeAt(end - 1) === 47) end--;
177
+ this.baseUrl = apiBaseUrl.slice(0, end);
108
178
  this.apiKey = apiKey;
179
+ this.timeoutMs = timeoutMs ?? _OpenBankingClient.DEFAULT_TIMEOUT_MS;
180
+ this.fetchImpl = options.fetch ?? fetch;
109
181
  this.privateKey = importPrivateKey(privateKeyPkcs8);
110
182
  }
111
- /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
112
- static fromCredentials(jsonOrPath) {
183
+ /**
184
+ * Builds a client from a credentials-bundle JSON string or a path to a bundle file.
185
+ *
186
+ * `overrides` (optional) lets the bundle path set the same transport knobs as the
187
+ * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or
188
+ * {@link OpenBankingClientOptions.timeoutMs}.
189
+ */
190
+ static fromCredentials(jsonOrPath, overrides = {}) {
113
191
  let json = jsonOrPath;
114
192
  if (!jsonOrPath.trimStart().startsWith("{")) {
115
193
  json = (0, import_node_fs.readFileSync)(jsonOrPath, "utf8");
116
194
  }
117
195
  const bundle = JSON.parse(json);
118
- return _OpenBankingClient.fromBundle(bundle);
196
+ return _OpenBankingClient.fromBundle(bundle, overrides);
119
197
  }
120
- static fromBundle(bundle) {
198
+ static fromBundle(bundle, overrides = {}) {
121
199
  if (!bundle.apiKey?.trim()) throw new Error("The credentials bundle has no apiKey");
122
200
  return new _OpenBankingClient({
123
201
  apiBaseUrl: bundle.apiBaseUrl,
124
202
  apiKey: bundle.apiKey,
125
- privateKeyPkcs8: bundle.encryptionKey.privateKey
203
+ privateKeyPkcs8: bundle.encryptionKey.privateKey,
204
+ timeoutMs: overrides.timeoutMs,
205
+ fetch: overrides.fetch
126
206
  });
127
207
  }
128
208
  /** Lists the user's accounts with all sensitive fields decrypted. */
@@ -257,17 +337,25 @@ var OpenBankingClient = class _OpenBankingClient {
257
337
  };
258
338
  }
259
339
  async getJson(path) {
260
- const res = await fetch(this.baseUrl + path, { headers: { "X-Api-Key": this.apiKey } });
340
+ const res = await this.fetchImpl(this.baseUrl + path, {
341
+ headers: { "X-Api-Key": this.apiKey, "User-Agent": USER_AGENT },
342
+ signal: AbortSignal.timeout(this.timeoutMs)
343
+ });
261
344
  if (!res.ok) {
262
345
  throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);
263
346
  }
264
347
  return await res.json();
265
348
  }
266
349
  async postJson(path, body) {
267
- const res = await fetch(this.baseUrl + path, {
350
+ const res = await this.fetchImpl(this.baseUrl + path, {
268
351
  method: "POST",
269
- headers: { "X-Api-Key": this.apiKey, "Content-Type": "application/json" },
270
- body: JSON.stringify(body)
352
+ headers: {
353
+ "X-Api-Key": this.apiKey,
354
+ "Content-Type": "application/json",
355
+ "User-Agent": USER_AGENT
356
+ },
357
+ body: JSON.stringify(body),
358
+ signal: AbortSignal.timeout(this.timeoutMs)
271
359
  });
272
360
  if (!res.ok) {
273
361
  throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/envelope.ts"],"sourcesContent":["export { OpenBankingClient } from \"./client.js\";\nexport {\n decryptEnvelope,\n decryptTo,\n importPrivateKey,\n} from \"./envelope.js\";\nexport type {\n Account,\n Balance,\n Transaction,\n TransactionPage,\n TransactionQuery,\n Connection,\n SyncResult,\n SyncAllResult,\n CredentialsBundle,\n EncryptionKey,\n OpenBankingClientOptions,\n} from \"./models.js\";\n","import { readFileSync } from \"node:fs\";\nimport { decryptTo, importPrivateKey, type CryptoKey } from \"./envelope.js\";\nimport type {\n Account,\n AccountEnc,\n AccountWire,\n BalanceEnc,\n Connection,\n ConnectionWire,\n CredentialsBundle,\n DisplayNameEnc,\n OpenBankingClientOptions,\n SyncAllResult,\n SyncAllResultWire,\n SyncResult,\n SyncResultWire,\n Transaction,\n TransactionEnc,\n TransactionPage,\n TransactionPageWire,\n TransactionQuery,\n TransactionWire,\n UidEnc,\n} from \"./models.js\";\n\n/**\n * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and\n * decrypts the zero-knowledge data envelopes locally with the exported private key — the service\n * only ever returns ciphertext it cannot read.\n */\nexport class OpenBankingClient {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly privateKey: Promise<CryptoKey>;\n\n constructor(options: OpenBankingClientOptions) {\n const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;\n if (!apiBaseUrl?.trim()) throw new Error(\"apiBaseUrl is required\");\n if (!apiKey?.trim()) throw new Error(\"apiKey is required\");\n if (!privateKeyPkcs8?.trim()) throw new Error(\"privateKeyPkcs8 is required\");\n\n this.baseUrl = apiBaseUrl.replace(/\\/+$/, \"\");\n this.apiKey = apiKey;\n this.privateKey = importPrivateKey(privateKeyPkcs8);\n }\n\n /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */\n static fromCredentials(jsonOrPath: string): OpenBankingClient {\n let json = jsonOrPath;\n if (!jsonOrPath.trimStart().startsWith(\"{\")) {\n json = readFileSync(jsonOrPath, \"utf8\");\n }\n const bundle = JSON.parse(json) as CredentialsBundle;\n return OpenBankingClient.fromBundle(bundle);\n }\n\n static fromBundle(bundle: CredentialsBundle): OpenBankingClient {\n if (!bundle.apiKey?.trim()) throw new Error(\"The credentials bundle has no apiKey\");\n return new OpenBankingClient({\n apiBaseUrl: bundle.apiBaseUrl,\n apiKey: bundle.apiKey,\n privateKeyPkcs8: bundle.encryptionKey.privateKey,\n });\n }\n\n /** Lists the user's accounts with all sensitive fields decrypted. */\n async getAccounts(): Promise<Account[]> {\n const wires = await this.getAccountWires();\n return Promise.all(wires.map((w) => this.mapAccount(w)));\n }\n\n /** Returns a page of an account's statement, newest first, with decrypted fields. */\n async getTransactions(accountId: string, query: TransactionQuery = {}): Promise<TransactionPage> {\n const qs = new URLSearchParams();\n if (query.from != null) qs.set(\"from\", query.from);\n if (query.to != null) qs.set(\"to\", query.to);\n if (query.limit != null) qs.set(\"limit\", String(query.limit));\n if (query.offset != null) qs.set(\"offset\", String(query.offset));\n const suffix = qs.toString() ? `?${qs.toString()}` : \"\";\n\n const page = await this.getJson<TransactionPageWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`,\n );\n\n const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));\n return { items, total: page.total };\n }\n\n /** Lists the user's bank connections. */\n async getConnections(): Promise<Connection[]> {\n const wires = await this.getJson<ConnectionWire[]>(\"/api/connections\");\n return wires.map((c) => ({\n sessionId: c.sessionId,\n aspspName: c.aspspName,\n aspspCountry: c.aspspCountry,\n validUntil: c.validUntil,\n status: c.status,\n accountCount: c.accountCount,\n lastSyncedAt: c.lastSyncedAt ?? null,\n psuType: c.psuType ?? null,\n }));\n }\n\n /**\n * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts\n * it, so the service can fetch fresh data without ever holding the uid in plaintext.\n */\n async sync(accountId: string): Promise<SyncResult> {\n const wires = await this.getAccountWires();\n const account = wires.find((a) => a.id === accountId);\n if (!account) throw new Error(`Account ${accountId} not found`);\n\n const uid = await this.decryptUid(account);\n if (uid == null) {\n throw new Error(\"Account has no active session (reconnect required) — cannot sync\");\n }\n\n const result = await this.postJson<SyncResultWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/sync`,\n { uid },\n );\n return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };\n }\n\n /** Triggers an online sync of every account that has an active session. */\n async syncAll(): Promise<SyncAllResult> {\n const wires = await this.getAccountWires();\n const decrypted = await Promise.all(\n wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) })),\n );\n const items = decrypted\n .filter((x): x is { accountId: string; uid: string } => x.uid != null)\n .map((x) => ({ accountId: x.accountId, uid: x.uid }));\n\n const result = await this.postJson<SyncAllResultWire>(\"/api/sync\", { items });\n return { accounts: result.accounts, newTransactions: result.newTransactions };\n }\n\n // ---- internals ---------------------------------------------------------------------------------\n\n private getAccountWires(): Promise<AccountWire[]> {\n return this.getJson<AccountWire[]>(\"/api/accounts\");\n }\n\n private async decryptUid(a: AccountWire): Promise<string | null> {\n const dec = await decryptTo<UidEnc>(await this.privateKey, a.uidEnc);\n return dec?.uid ?? null;\n }\n\n private async mapAccount(a: AccountWire): Promise<Account> {\n const priv = await this.privateKey;\n const acc = await decryptTo<AccountEnc>(priv, a.enc);\n const name = await decryptTo<DisplayNameEnc>(priv, a.displayNameEnc);\n const balances = await Promise.all(\n (a.balances ?? []).map(async (b) => {\n const dec = await decryptTo<BalanceEnc>(priv, b.enc);\n return {\n type: b.type,\n name: dec?.name ?? null,\n amount: dec?.amount ?? \"0\",\n currency: b.currency,\n referenceDate: b.referenceDate ?? null,\n };\n }),\n );\n\n return {\n id: a.id,\n aspspName: a.aspspName,\n aspspCountry: a.aspspCountry,\n currency: a.currency,\n accountType: a.accountType ?? null,\n bic: a.bic ?? null,\n needsReconnect: a.needsReconnect,\n iban: acc?.iban ?? null,\n bban: acc?.bban ?? null,\n ownerName: acc?.ownerName ?? null,\n accountName: acc?.accountName ?? null,\n product: acc?.product ?? null,\n displayName: name?.displayName ?? null,\n balances,\n };\n }\n\n private async mapTransaction(t: TransactionWire): Promise<Transaction> {\n const d = await decryptTo<TransactionEnc>(await this.privateKey, t.enc);\n return {\n id: t.id,\n currency: t.currency,\n creditDebitIndicator: t.creditDebitIndicator,\n status: t.status ?? null,\n bookingDate: t.bookingDate ?? null,\n valueDate: t.valueDate ?? null,\n transactionDate: t.transactionDate ?? null,\n bankTransactionCode: t.bankTransactionCode ?? null,\n amount: d?.amount ?? \"0\",\n creditorName: d?.creditorName ?? null,\n creditorIban: d?.creditorIban ?? null,\n creditorBban: d?.creditorBban ?? null,\n creditorAgentBic: d?.creditorAgentBic ?? null,\n debtorName: d?.debtorName ?? null,\n debtorIban: d?.debtorIban ?? null,\n debtorBban: d?.debtorBban ?? null,\n debtorAgentBic: d?.debtorAgentBic ?? null,\n remittanceInformation: d?.remittanceInformation ?? null,\n note: d?.note ?? null,\n referenceNumber: d?.referenceNumber ?? null,\n exchangeRate: d?.exchangeRate ?? null,\n merchantCategoryCode: d?.merchantCategoryCode ?? null,\n balanceAfterTransaction: d?.balanceAfter ?? null,\n balanceAfterCurrency: d?.balanceAfterCurrency ?? null,\n };\n }\n\n private async getJson<T>(path: string): Promise<T> {\n const res = await fetch(this.baseUrl + path, { headers: { \"X-Api-Key\": this.apiKey } });\n if (!res.ok) {\n throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n\n private async postJson<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(this.baseUrl + path, {\n method: \"POST\",\n headers: { \"X-Api-Key\": this.apiKey, \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n}\n","import { webcrypto } from \"node:crypto\";\n\nconst { subtle } = webcrypto;\n\n/** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */\nexport type CryptoKey = webcrypto.CryptoKey;\n\nconst VERSION = 0x01;\nconst POINT_LEN = 65;\nconst NONCE_LEN = 12;\nconst TAG_LEN = 16;\n\nconst HKDF_INFO = new TextEncoder().encode(\"bank.core.ci/zk/v1\");\nconst HKDF_SALT = new Uint8Array(32); // 32 zero bytes (must be exactly this).\n\n/**\n * Decrypts open-banking.io's zero-knowledge data envelopes.\n * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.\n * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.\n * Only the user's private key can decrypt — the service stores ciphertext it cannot read.\n */\nexport async function decryptEnvelope(\n privateKey: CryptoKey,\n envelopeBase64: string,\n): Promise<Uint8Array> {\n const bytes = base64ToBytes(envelopeBase64);\n if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {\n throw new Error(\"Invalid or unsupported envelope\");\n }\n\n const ephPub = bytes.subarray(1, 1 + POINT_LEN);\n const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);\n const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n\n const ephKey = await subtle.importKey(\n \"raw\",\n ephPub,\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [],\n );\n\n const shared = new Uint8Array(\n await subtle.deriveBits({ name: \"ECDH\", public: ephKey }, privateKey, 256),\n );\n\n const hkdf = await subtle.importKey(\"raw\", shared, \"HKDF\", false, [\"deriveKey\"]);\n\n const aesKey = await subtle.deriveKey(\n { name: \"HKDF\", hash: \"SHA-256\", salt: HKDF_SALT, info: HKDF_INFO },\n hkdf,\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"decrypt\"],\n );\n\n // Web Crypto AES-GCM expects ciphertext||tag.\n const ctWithTag = new Uint8Array(ciphertext.length + tag.length);\n ctWithTag.set(ciphertext, 0);\n ctWithTag.set(tag, ciphertext.length);\n\n const plaintext = await subtle.decrypt(\n { name: \"AES-GCM\", iv: nonce, tagLength: 128 },\n aesKey,\n ctWithTag,\n );\n\n return new Uint8Array(plaintext);\n}\n\n/** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */\nexport async function decryptTo<T>(\n privateKey: CryptoKey,\n envelopeBase64: string | null | undefined,\n): Promise<T | null> {\n if (envelopeBase64 == null) return null;\n const plaintext = await decryptEnvelope(privateKey, envelopeBase64);\n return JSON.parse(new TextDecoder().decode(plaintext)) as T;\n}\n\n/** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */\nexport async function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey> {\n return subtle.importKey(\n \"pkcs8\",\n base64ToBytes(pkcs8Base64),\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [\"deriveBits\"],\n );\n}\n\nfunction base64ToBytes(b64: string): Uint8Array {\n return new Uint8Array(Buffer.from(b64, \"base64\"));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA6B;;;ACA7B,yBAA0B;AAE1B,IAAM,EAAE,OAAO,IAAI;AAKnB,IAAM,UAAU;AAChB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,UAAU;AAEhB,IAAM,YAAY,IAAI,YAAY,EAAE,OAAO,oBAAoB;AAC/D,IAAM,YAAY,IAAI,WAAW,EAAE;AAQnC,eAAsB,gBACpB,YACA,gBACqB;AACrB,QAAM,QAAQ,cAAc,cAAc;AAC1C,MAAI,MAAM,SAAS,IAAI,YAAY,YAAY,WAAW,MAAM,CAAC,MAAM,SAAS;AAC9E,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,SAAS,MAAM,SAAS,GAAG,IAAI,SAAS;AAC9C,QAAM,QAAQ,MAAM,SAAS,IAAI,WAAW,IAAI,YAAY,SAAS;AACrE,QAAM,MAAM,MAAM,SAAS,IAAI,YAAY,WAAW,IAAI,YAAY,YAAY,OAAO;AACzF,QAAM,aAAa,MAAM,SAAS,IAAI,YAAY,YAAY,OAAO;AAErE,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,EAAE,MAAM,QAAQ,YAAY,QAAQ;AAAA,IACpC;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,IAAI;AAAA,IACjB,MAAM,OAAO,WAAW,EAAE,MAAM,QAAQ,QAAQ,OAAO,GAAG,YAAY,GAAG;AAAA,EAC3E;AAEA,QAAM,OAAO,MAAM,OAAO,UAAU,OAAO,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,SAAS,EAAE,aAAa,KAAK,OAAO,EAAE,CAAC;AACtF,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,OAAO,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IACvE;AACA,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AAAA,EAEA,MAAc,SAAY,MAAc,MAA2B;AACjE,UAAM,MAAM,MAAM,MAAM,KAAK,UAAU,MAAM;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS,EAAE,aAAa,KAAK,QAAQ,gBAAgB,mBAAmB;AAAA,MACxE,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,QAAQ,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/envelope.ts","../package.json","../src/version.ts"],"sourcesContent":["export { OpenBankingClient } from \"./client.js\";\nexport { decryptEnvelope, decryptTo, importPrivateKey } from \"./envelope.js\";\nexport type {\n Account,\n Balance,\n Transaction,\n TransactionPage,\n TransactionQuery,\n Connection,\n SyncResult,\n SyncAllResult,\n CredentialsBundle,\n EncryptionKey,\n OpenBankingClientOptions,\n} from \"./models.js\";\n","import { readFileSync } from \"node:fs\";\nimport { decryptTo, importPrivateKey, type CryptoKey } from \"./envelope.js\";\nimport { USER_AGENT } from \"./version.js\";\nimport type {\n Account,\n AccountEnc,\n AccountWire,\n BalanceEnc,\n Connection,\n ConnectionWire,\n CredentialsBundle,\n DisplayNameEnc,\n OpenBankingClientOptions,\n SyncAllResult,\n SyncAllResultWire,\n SyncResult,\n SyncResultWire,\n Transaction,\n TransactionEnc,\n TransactionPage,\n TransactionPageWire,\n TransactionQuery,\n TransactionWire,\n UidEnc,\n} from \"./models.js\";\n\n/**\n * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and\n * decrypts the zero-knowledge data envelopes locally with the exported private key — the service\n * only ever returns ciphertext it cannot read.\n */\nexport class OpenBankingClient {\n /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */\n static readonly DEFAULT_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly privateKey: Promise<CryptoKey>;\n\n constructor(options: OpenBankingClientOptions) {\n const { apiBaseUrl, apiKey, privateKeyPkcs8, timeoutMs } = options;\n if (!apiBaseUrl?.trim()) throw new Error(\"apiBaseUrl is required\");\n if (!apiKey?.trim()) throw new Error(\"apiKey is required\");\n if (!privateKeyPkcs8?.trim()) throw new Error(\"privateKeyPkcs8 is required\");\n\n // Strip all trailing \"/\" without a backtracking regex (avoids ReDoS on long inputs).\n let end = apiBaseUrl.length;\n while (end > 0 && apiBaseUrl.charCodeAt(end - 1) === 47 /* \"/\" */) end--;\n this.baseUrl = apiBaseUrl.slice(0, end);\n this.apiKey = apiKey;\n this.timeoutMs = timeoutMs ?? OpenBankingClient.DEFAULT_TIMEOUT_MS;\n this.fetchImpl = options.fetch ?? fetch;\n this.privateKey = importPrivateKey(privateKeyPkcs8);\n }\n\n /**\n * Builds a client from a credentials-bundle JSON string or a path to a bundle file.\n *\n * `overrides` (optional) lets the bundle path set the same transport knobs as the\n * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or\n * {@link OpenBankingClientOptions.timeoutMs}.\n */\n static fromCredentials(\n jsonOrPath: string,\n overrides: Partial<Pick<OpenBankingClientOptions, \"fetch\" | \"timeoutMs\">> = {},\n ): OpenBankingClient {\n let json = jsonOrPath;\n if (!jsonOrPath.trimStart().startsWith(\"{\")) {\n json = readFileSync(jsonOrPath, \"utf8\");\n }\n const bundle = JSON.parse(json) as CredentialsBundle;\n return OpenBankingClient.fromBundle(bundle, overrides);\n }\n\n static fromBundle(\n bundle: CredentialsBundle,\n overrides: Partial<Pick<OpenBankingClientOptions, \"fetch\" | \"timeoutMs\">> = {},\n ): OpenBankingClient {\n if (!bundle.apiKey?.trim()) throw new Error(\"The credentials bundle has no apiKey\");\n return new OpenBankingClient({\n apiBaseUrl: bundle.apiBaseUrl,\n apiKey: bundle.apiKey,\n privateKeyPkcs8: bundle.encryptionKey.privateKey,\n timeoutMs: overrides.timeoutMs,\n fetch: overrides.fetch,\n });\n }\n\n /** Lists the user's accounts with all sensitive fields decrypted. */\n async getAccounts(): Promise<Account[]> {\n const wires = await this.getAccountWires();\n return Promise.all(wires.map((w) => this.mapAccount(w)));\n }\n\n /** Returns a page of an account's statement, newest first, with decrypted fields. */\n async getTransactions(accountId: string, query: TransactionQuery = {}): Promise<TransactionPage> {\n const qs = new URLSearchParams();\n if (query.from != null) qs.set(\"from\", query.from);\n if (query.to != null) qs.set(\"to\", query.to);\n if (query.limit != null) qs.set(\"limit\", String(query.limit));\n if (query.offset != null) qs.set(\"offset\", String(query.offset));\n const suffix = qs.toString() ? `?${qs.toString()}` : \"\";\n\n const page = await this.getJson<TransactionPageWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`,\n );\n\n const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));\n return { items, total: page.total };\n }\n\n /** Lists the user's bank connections. */\n async getConnections(): Promise<Connection[]> {\n const wires = await this.getJson<ConnectionWire[]>(\"/api/connections\");\n return wires.map((c) => ({\n sessionId: c.sessionId,\n aspspName: c.aspspName,\n aspspCountry: c.aspspCountry,\n validUntil: c.validUntil,\n status: c.status,\n accountCount: c.accountCount,\n lastSyncedAt: c.lastSyncedAt ?? null,\n psuType: c.psuType ?? null,\n }));\n }\n\n /**\n * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts\n * it, so the service can fetch fresh data without ever holding the uid in plaintext.\n */\n async sync(accountId: string): Promise<SyncResult> {\n const wires = await this.getAccountWires();\n const account = wires.find((a) => a.id === accountId);\n if (!account) throw new Error(`Account ${accountId} not found`);\n\n const uid = await this.decryptUid(account);\n if (uid == null) {\n throw new Error(\"Account has no active session (reconnect required) — cannot sync\");\n }\n\n const result = await this.postJson<SyncResultWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/sync`,\n { uid },\n );\n return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };\n }\n\n /** Triggers an online sync of every account that has an active session. */\n async syncAll(): Promise<SyncAllResult> {\n const wires = await this.getAccountWires();\n const decrypted = await Promise.all(\n wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) })),\n );\n const items = decrypted\n .filter((x): x is { accountId: string; uid: string } => x.uid != null)\n .map((x) => ({ accountId: x.accountId, uid: x.uid }));\n\n const result = await this.postJson<SyncAllResultWire>(\"/api/sync\", { items });\n return { accounts: result.accounts, newTransactions: result.newTransactions };\n }\n\n // ---- internals ---------------------------------------------------------------------------------\n\n private getAccountWires(): Promise<AccountWire[]> {\n return this.getJson<AccountWire[]>(\"/api/accounts\");\n }\n\n private async decryptUid(a: AccountWire): Promise<string | null> {\n const dec = await decryptTo<UidEnc>(await this.privateKey, a.uidEnc);\n return dec?.uid ?? null;\n }\n\n private async mapAccount(a: AccountWire): Promise<Account> {\n const priv = await this.privateKey;\n const acc = await decryptTo<AccountEnc>(priv, a.enc);\n const name = await decryptTo<DisplayNameEnc>(priv, a.displayNameEnc);\n const balances = await Promise.all(\n (a.balances ?? []).map(async (b) => {\n const dec = await decryptTo<BalanceEnc>(priv, b.enc);\n return {\n type: b.type,\n name: dec?.name ?? null,\n amount: dec?.amount ?? \"0\",\n currency: b.currency,\n referenceDate: b.referenceDate ?? null,\n };\n }),\n );\n\n return {\n id: a.id,\n aspspName: a.aspspName,\n aspspCountry: a.aspspCountry,\n currency: a.currency,\n accountType: a.accountType ?? null,\n bic: a.bic ?? null,\n needsReconnect: a.needsReconnect,\n iban: acc?.iban ?? null,\n bban: acc?.bban ?? null,\n ownerName: acc?.ownerName ?? null,\n accountName: acc?.accountName ?? null,\n product: acc?.product ?? null,\n displayName: name?.displayName ?? null,\n balances,\n };\n }\n\n private async mapTransaction(t: TransactionWire): Promise<Transaction> {\n const d = await decryptTo<TransactionEnc>(await this.privateKey, t.enc);\n return {\n id: t.id,\n currency: t.currency,\n creditDebitIndicator: t.creditDebitIndicator,\n status: t.status ?? null,\n bookingDate: t.bookingDate ?? null,\n valueDate: t.valueDate ?? null,\n transactionDate: t.transactionDate ?? null,\n bankTransactionCode: t.bankTransactionCode ?? null,\n amount: d?.amount ?? \"0\",\n creditorName: d?.creditorName ?? null,\n creditorIban: d?.creditorIban ?? null,\n creditorBban: d?.creditorBban ?? null,\n creditorAgentBic: d?.creditorAgentBic ?? null,\n debtorName: d?.debtorName ?? null,\n debtorIban: d?.debtorIban ?? null,\n debtorBban: d?.debtorBban ?? null,\n debtorAgentBic: d?.debtorAgentBic ?? null,\n remittanceInformation: d?.remittanceInformation ?? null,\n note: d?.note ?? null,\n referenceNumber: d?.referenceNumber ?? null,\n exchangeRate: d?.exchangeRate ?? null,\n merchantCategoryCode: d?.merchantCategoryCode ?? null,\n balanceAfterTransaction: d?.balanceAfter ?? null,\n balanceAfterCurrency: d?.balanceAfterCurrency ?? null,\n };\n }\n\n private async getJson<T>(path: string): Promise<T> {\n const res = await this.fetchImpl(this.baseUrl + path, {\n headers: { \"X-Api-Key\": this.apiKey, \"User-Agent\": USER_AGENT },\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n if (!res.ok) {\n throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n\n private async postJson<T>(path: string, body: unknown): Promise<T> {\n const res = await this.fetchImpl(this.baseUrl + path, {\n method: \"POST\",\n headers: {\n \"X-Api-Key\": this.apiKey,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": USER_AGENT,\n },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n if (!res.ok) {\n throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n}\n","import { webcrypto } from \"node:crypto\";\n\nconst { subtle } = webcrypto;\n\n/** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */\nexport type CryptoKey = webcrypto.CryptoKey;\n\nconst VERSION = 0x01;\nconst POINT_LEN = 65;\nconst NONCE_LEN = 12;\nconst TAG_LEN = 16;\n\nconst HKDF_INFO = new TextEncoder().encode(\"bank.core.ci/zk/v1\");\nconst HKDF_SALT = new Uint8Array(32); // 32 zero bytes (must be exactly this).\n\n/**\n * Decrypts open-banking.io's zero-knowledge data envelopes.\n * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.\n * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.\n * Only the user's private key can decrypt — the service stores ciphertext it cannot read.\n */\nexport async function decryptEnvelope(\n privateKey: CryptoKey,\n envelopeBase64: string,\n): Promise<Uint8Array> {\n const bytes = base64ToBytes(envelopeBase64);\n if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {\n throw new Error(\"Invalid or unsupported envelope\");\n }\n\n const ephPub = bytes.subarray(1, 1 + POINT_LEN);\n const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);\n const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n\n // Guard against invalid-curve attacks: WebCrypto's P-256 `importKey` validates that the raw point\n // lies on the curve and is not the point at infinity, so a forged/off-curve ephemeral public key\n // throws here rather than yielding a derivable (and exploitable) shared secret below.\n const ephKey = await subtle.importKey(\n \"raw\",\n ephPub,\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [],\n );\n\n const shared = new Uint8Array(\n await subtle.deriveBits({ name: \"ECDH\", public: ephKey }, privateKey, 256),\n );\n\n const hkdf = await subtle.importKey(\"raw\", shared, \"HKDF\", false, [\"deriveKey\"]);\n\n const aesKey = await subtle.deriveKey(\n { name: \"HKDF\", hash: \"SHA-256\", salt: HKDF_SALT, info: HKDF_INFO },\n hkdf,\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"decrypt\"],\n );\n\n // Web Crypto AES-GCM expects ciphertext||tag.\n const ctWithTag = new Uint8Array(ciphertext.length + tag.length);\n ctWithTag.set(ciphertext, 0);\n ctWithTag.set(tag, ciphertext.length);\n\n const plaintext = await subtle.decrypt(\n { name: \"AES-GCM\", iv: nonce, tagLength: 128 },\n aesKey,\n ctWithTag,\n );\n\n return new Uint8Array(plaintext);\n}\n\n/** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */\nexport async function decryptTo<T>(\n privateKey: CryptoKey,\n envelopeBase64: string | null | undefined,\n): Promise<T | null> {\n if (envelopeBase64 == null) return null;\n const plaintext = await decryptEnvelope(privateKey, envelopeBase64);\n return JSON.parse(new TextDecoder().decode(plaintext)) as T;\n}\n\n/** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */\nexport async function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey> {\n return subtle.importKey(\n \"pkcs8\",\n base64ToBytes(pkcs8Base64),\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [\"deriveBits\"],\n );\n}\n\nfunction base64ToBytes(b64: string): Uint8Array<ArrayBuffer> {\n return new Uint8Array(Buffer.from(b64, \"base64\"));\n}\n","{\n \"name\": \"@open-banking-io/client\",\n \"version\": \"0.3.0\",\n \"description\": \"Server-to-server client for open-banking.io: API-key auth + client-side decryption of the zero-knowledge data envelopes with your exported private key.\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"open-banking.io\",\n \"keywords\": [\n \"open-banking\",\n \"psd2\",\n \"zero-knowledge\",\n \"encryption\",\n \"fintech\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/open-banking-io/clients\"\n },\n \"engines\": {\n \"node\": \">=20\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest run\",\n \"coverage\": \"vitest run --coverage\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format:check\": \"prettier --check .\"\n },\n \"overrides\": {\n \"esbuild\": \"^0.28.1\"\n },\n \"devDependencies\": {\n \"@eslint/js\": \"^10.0.1\",\n \"@types/node\": \"^25.9.3\",\n \"@vitest/coverage-v8\": \"^4.1.9\",\n \"eslint\": \"^10.5.0\",\n \"prettier\": \"^3.8.4\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^6.0.3\",\n \"typescript-eslint\": \"^8.61.1\",\n \"vitest\": \"^4.1.9\"\n }\n}\n","// The package version, sourced from package.json so it can never drift. tsup inlines the JSON at\n// build time (tree-shaken to the single string), and vitest/tsx resolve the import directly — so\n// this stays ESM/CJS-safe without a runtime file read.\nimport pkg from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION: string = pkg.version;\n\n/** The `User-Agent` sent on every request: `open-banking-io/node/<version>`. */\nexport const USER_AGENT = `open-banking-io/node/${VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA6B;;;ACA7B,yBAA0B;AAE1B,IAAM,EAAE,OAAO,IAAI;AAKnB,IAAM,UAAU;AAChB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,UAAU;AAEhB,IAAM,YAAY,IAAI,YAAY,EAAE,OAAO,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A,QACP,aAAa,KAAK;AAAA,QAClB,gBAAgB;AAAA,QAChB,cAAc;AAAA,MAChB;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,MACzB,QAAQ,YAAY,QAAQ,KAAK,SAAS;AAAA,IAC5C,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,QAAQ,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AACF;","names":["VERSION"]}
package/dist/index.d.cts CHANGED
@@ -106,6 +106,30 @@ interface OpenBankingClientOptions {
106
106
  apiKey: string;
107
107
  /** The base64 PKCS#8 encryption private key from your bundle. */
108
108
  privateKeyPkcs8: string;
109
+ /**
110
+ * Per-request timeout in milliseconds, so a hung connection can't block forever.
111
+ * Defaults to {@link DEFAULT_TIMEOUT_MS} (30s).
112
+ */
113
+ timeoutMs?: number;
114
+ /**
115
+ * Custom `fetch` implementation, used in place of the global `fetch` for every request.
116
+ * Typed to the WHATWG `fetch` signature only, so the SDK keeps zero runtime dependencies.
117
+ *
118
+ * A custom HTTP transport (proxy, custom CA/mTLS, keep-alive, connection pooling) is
119
+ * expressed by passing a `fetch` bound to an undici `Dispatcher`, e.g.:
120
+ *
121
+ * ```ts
122
+ * import { Agent, fetch as undiciFetch } from "undici";
123
+ * const dispatcher = new Agent({ keepAliveTimeout: 60_000 });
124
+ * const client = new OpenBankingClient({
125
+ * apiBaseUrl, apiKey, privateKeyPkcs8,
126
+ * fetch: (input, init) => undiciFetch(input, { ...init, dispatcher }),
127
+ * });
128
+ * ```
129
+ *
130
+ * Defaults to the global `fetch`.
131
+ */
132
+ fetch?: typeof globalThis.fetch;
109
133
  }
110
134
 
111
135
  /**
@@ -114,13 +138,23 @@ interface OpenBankingClientOptions {
114
138
  * only ever returns ciphertext it cannot read.
115
139
  */
116
140
  declare class OpenBankingClient {
141
+ /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */
142
+ static readonly DEFAULT_TIMEOUT_MS = 30000;
117
143
  private readonly baseUrl;
118
144
  private readonly apiKey;
145
+ private readonly timeoutMs;
146
+ private readonly fetchImpl;
119
147
  private readonly privateKey;
120
148
  constructor(options: OpenBankingClientOptions);
121
- /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
122
- static fromCredentials(jsonOrPath: string): OpenBankingClient;
123
- static fromBundle(bundle: CredentialsBundle): OpenBankingClient;
149
+ /**
150
+ * Builds a client from a credentials-bundle JSON string or a path to a bundle file.
151
+ *
152
+ * `overrides` (optional) lets the bundle path set the same transport knobs as the
153
+ * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or
154
+ * {@link OpenBankingClientOptions.timeoutMs}.
155
+ */
156
+ static fromCredentials(jsonOrPath: string, overrides?: Partial<Pick<OpenBankingClientOptions, "fetch" | "timeoutMs">>): OpenBankingClient;
157
+ static fromBundle(bundle: CredentialsBundle, overrides?: Partial<Pick<OpenBankingClientOptions, "fetch" | "timeoutMs">>): OpenBankingClient;
124
158
  /** Lists the user's accounts with all sensitive fields decrypted. */
125
159
  getAccounts(): Promise<Account[]>;
126
160
  /** Returns a page of an account's statement, newest first, with decrypted fields. */
package/dist/index.d.ts CHANGED
@@ -106,6 +106,30 @@ interface OpenBankingClientOptions {
106
106
  apiKey: string;
107
107
  /** The base64 PKCS#8 encryption private key from your bundle. */
108
108
  privateKeyPkcs8: string;
109
+ /**
110
+ * Per-request timeout in milliseconds, so a hung connection can't block forever.
111
+ * Defaults to {@link DEFAULT_TIMEOUT_MS} (30s).
112
+ */
113
+ timeoutMs?: number;
114
+ /**
115
+ * Custom `fetch` implementation, used in place of the global `fetch` for every request.
116
+ * Typed to the WHATWG `fetch` signature only, so the SDK keeps zero runtime dependencies.
117
+ *
118
+ * A custom HTTP transport (proxy, custom CA/mTLS, keep-alive, connection pooling) is
119
+ * expressed by passing a `fetch` bound to an undici `Dispatcher`, e.g.:
120
+ *
121
+ * ```ts
122
+ * import { Agent, fetch as undiciFetch } from "undici";
123
+ * const dispatcher = new Agent({ keepAliveTimeout: 60_000 });
124
+ * const client = new OpenBankingClient({
125
+ * apiBaseUrl, apiKey, privateKeyPkcs8,
126
+ * fetch: (input, init) => undiciFetch(input, { ...init, dispatcher }),
127
+ * });
128
+ * ```
129
+ *
130
+ * Defaults to the global `fetch`.
131
+ */
132
+ fetch?: typeof globalThis.fetch;
109
133
  }
110
134
 
111
135
  /**
@@ -114,13 +138,23 @@ interface OpenBankingClientOptions {
114
138
  * only ever returns ciphertext it cannot read.
115
139
  */
116
140
  declare class OpenBankingClient {
141
+ /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */
142
+ static readonly DEFAULT_TIMEOUT_MS = 30000;
117
143
  private readonly baseUrl;
118
144
  private readonly apiKey;
145
+ private readonly timeoutMs;
146
+ private readonly fetchImpl;
119
147
  private readonly privateKey;
120
148
  constructor(options: OpenBankingClientOptions);
121
- /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
122
- static fromCredentials(jsonOrPath: string): OpenBankingClient;
123
- static fromBundle(bundle: CredentialsBundle): OpenBankingClient;
149
+ /**
150
+ * Builds a client from a credentials-bundle JSON string or a path to a bundle file.
151
+ *
152
+ * `overrides` (optional) lets the bundle path set the same transport knobs as the
153
+ * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or
154
+ * {@link OpenBankingClientOptions.timeoutMs}.
155
+ */
156
+ static fromCredentials(jsonOrPath: string, overrides?: Partial<Pick<OpenBankingClientOptions, "fetch" | "timeoutMs">>): OpenBankingClient;
157
+ static fromBundle(bundle: CredentialsBundle, overrides?: Partial<Pick<OpenBankingClientOptions, "fetch" | "timeoutMs">>): OpenBankingClient;
124
158
  /** Lists the user's accounts with all sensitive fields decrypted. */
125
159
  getAccounts(): Promise<Account[]>;
126
160
  /** Returns a page of an account's statement, newest first, with decrypted fields. */
package/dist/index.js CHANGED
@@ -65,35 +65,115 @@ function base64ToBytes(b64) {
65
65
  return new Uint8Array(Buffer.from(b64, "base64"));
66
66
  }
67
67
 
68
+ // package.json
69
+ var package_default = {
70
+ name: "@open-banking-io/client",
71
+ version: "0.3.0",
72
+ description: "Server-to-server client for open-banking.io: API-key auth + client-side decryption of the zero-knowledge data envelopes with your exported private key.",
73
+ type: "module",
74
+ license: "MIT",
75
+ author: "open-banking.io",
76
+ keywords: [
77
+ "open-banking",
78
+ "psd2",
79
+ "zero-knowledge",
80
+ "encryption",
81
+ "fintech"
82
+ ],
83
+ repository: {
84
+ type: "git",
85
+ url: "https://github.com/open-banking-io/clients"
86
+ },
87
+ engines: {
88
+ node: ">=20"
89
+ },
90
+ files: [
91
+ "dist",
92
+ "README.md"
93
+ ],
94
+ main: "./dist/index.cjs",
95
+ module: "./dist/index.js",
96
+ types: "./dist/index.d.ts",
97
+ exports: {
98
+ ".": {
99
+ types: "./dist/index.d.ts",
100
+ import: "./dist/index.js",
101
+ require: "./dist/index.cjs"
102
+ }
103
+ },
104
+ scripts: {
105
+ build: "tsup",
106
+ test: "vitest run",
107
+ coverage: "vitest run --coverage",
108
+ typecheck: "tsc --noEmit",
109
+ lint: "eslint .",
110
+ "format:check": "prettier --check ."
111
+ },
112
+ overrides: {
113
+ esbuild: "^0.28.1"
114
+ },
115
+ devDependencies: {
116
+ "@eslint/js": "^10.0.1",
117
+ "@types/node": "^25.9.3",
118
+ "@vitest/coverage-v8": "^4.1.9",
119
+ eslint: "^10.5.0",
120
+ prettier: "^3.8.4",
121
+ tsup: "^8.5.1",
122
+ typescript: "^6.0.3",
123
+ "typescript-eslint": "^8.61.1",
124
+ vitest: "^4.1.9"
125
+ }
126
+ };
127
+
128
+ // src/version.ts
129
+ var VERSION2 = package_default.version;
130
+ var USER_AGENT = `open-banking-io/node/${VERSION2}`;
131
+
68
132
  // src/client.ts
69
133
  var OpenBankingClient = class _OpenBankingClient {
134
+ /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */
135
+ static DEFAULT_TIMEOUT_MS = 3e4;
70
136
  baseUrl;
71
137
  apiKey;
138
+ timeoutMs;
139
+ fetchImpl;
72
140
  privateKey;
73
141
  constructor(options) {
74
- const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;
142
+ const { apiBaseUrl, apiKey, privateKeyPkcs8, timeoutMs } = options;
75
143
  if (!apiBaseUrl?.trim()) throw new Error("apiBaseUrl is required");
76
144
  if (!apiKey?.trim()) throw new Error("apiKey is required");
77
145
  if (!privateKeyPkcs8?.trim()) throw new Error("privateKeyPkcs8 is required");
78
- this.baseUrl = apiBaseUrl.replace(/\/+$/, "");
146
+ let end = apiBaseUrl.length;
147
+ while (end > 0 && apiBaseUrl.charCodeAt(end - 1) === 47) end--;
148
+ this.baseUrl = apiBaseUrl.slice(0, end);
79
149
  this.apiKey = apiKey;
150
+ this.timeoutMs = timeoutMs ?? _OpenBankingClient.DEFAULT_TIMEOUT_MS;
151
+ this.fetchImpl = options.fetch ?? fetch;
80
152
  this.privateKey = importPrivateKey(privateKeyPkcs8);
81
153
  }
82
- /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
83
- static fromCredentials(jsonOrPath) {
154
+ /**
155
+ * Builds a client from a credentials-bundle JSON string or a path to a bundle file.
156
+ *
157
+ * `overrides` (optional) lets the bundle path set the same transport knobs as the
158
+ * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or
159
+ * {@link OpenBankingClientOptions.timeoutMs}.
160
+ */
161
+ static fromCredentials(jsonOrPath, overrides = {}) {
84
162
  let json = jsonOrPath;
85
163
  if (!jsonOrPath.trimStart().startsWith("{")) {
86
164
  json = readFileSync(jsonOrPath, "utf8");
87
165
  }
88
166
  const bundle = JSON.parse(json);
89
- return _OpenBankingClient.fromBundle(bundle);
167
+ return _OpenBankingClient.fromBundle(bundle, overrides);
90
168
  }
91
- static fromBundle(bundle) {
169
+ static fromBundle(bundle, overrides = {}) {
92
170
  if (!bundle.apiKey?.trim()) throw new Error("The credentials bundle has no apiKey");
93
171
  return new _OpenBankingClient({
94
172
  apiBaseUrl: bundle.apiBaseUrl,
95
173
  apiKey: bundle.apiKey,
96
- privateKeyPkcs8: bundle.encryptionKey.privateKey
174
+ privateKeyPkcs8: bundle.encryptionKey.privateKey,
175
+ timeoutMs: overrides.timeoutMs,
176
+ fetch: overrides.fetch
97
177
  });
98
178
  }
99
179
  /** Lists the user's accounts with all sensitive fields decrypted. */
@@ -228,17 +308,25 @@ var OpenBankingClient = class _OpenBankingClient {
228
308
  };
229
309
  }
230
310
  async getJson(path) {
231
- const res = await fetch(this.baseUrl + path, { headers: { "X-Api-Key": this.apiKey } });
311
+ const res = await this.fetchImpl(this.baseUrl + path, {
312
+ headers: { "X-Api-Key": this.apiKey, "User-Agent": USER_AGENT },
313
+ signal: AbortSignal.timeout(this.timeoutMs)
314
+ });
232
315
  if (!res.ok) {
233
316
  throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);
234
317
  }
235
318
  return await res.json();
236
319
  }
237
320
  async postJson(path, body) {
238
- const res = await fetch(this.baseUrl + path, {
321
+ const res = await this.fetchImpl(this.baseUrl + path, {
239
322
  method: "POST",
240
- headers: { "X-Api-Key": this.apiKey, "Content-Type": "application/json" },
241
- body: JSON.stringify(body)
323
+ headers: {
324
+ "X-Api-Key": this.apiKey,
325
+ "Content-Type": "application/json",
326
+ "User-Agent": USER_AGENT
327
+ },
328
+ body: JSON.stringify(body),
329
+ signal: AbortSignal.timeout(this.timeoutMs)
242
330
  });
243
331
  if (!res.ok) {
244
332
  throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/envelope.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { decryptTo, importPrivateKey, type CryptoKey } from \"./envelope.js\";\nimport type {\n Account,\n AccountEnc,\n AccountWire,\n BalanceEnc,\n Connection,\n ConnectionWire,\n CredentialsBundle,\n DisplayNameEnc,\n OpenBankingClientOptions,\n SyncAllResult,\n SyncAllResultWire,\n SyncResult,\n SyncResultWire,\n Transaction,\n TransactionEnc,\n TransactionPage,\n TransactionPageWire,\n TransactionQuery,\n TransactionWire,\n UidEnc,\n} from \"./models.js\";\n\n/**\n * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and\n * decrypts the zero-knowledge data envelopes locally with the exported private key — the service\n * only ever returns ciphertext it cannot read.\n */\nexport class OpenBankingClient {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly privateKey: Promise<CryptoKey>;\n\n constructor(options: OpenBankingClientOptions) {\n const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;\n if (!apiBaseUrl?.trim()) throw new Error(\"apiBaseUrl is required\");\n if (!apiKey?.trim()) throw new Error(\"apiKey is required\");\n if (!privateKeyPkcs8?.trim()) throw new Error(\"privateKeyPkcs8 is required\");\n\n this.baseUrl = apiBaseUrl.replace(/\\/+$/, \"\");\n this.apiKey = apiKey;\n this.privateKey = importPrivateKey(privateKeyPkcs8);\n }\n\n /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */\n static fromCredentials(jsonOrPath: string): OpenBankingClient {\n let json = jsonOrPath;\n if (!jsonOrPath.trimStart().startsWith(\"{\")) {\n json = readFileSync(jsonOrPath, \"utf8\");\n }\n const bundle = JSON.parse(json) as CredentialsBundle;\n return OpenBankingClient.fromBundle(bundle);\n }\n\n static fromBundle(bundle: CredentialsBundle): OpenBankingClient {\n if (!bundle.apiKey?.trim()) throw new Error(\"The credentials bundle has no apiKey\");\n return new OpenBankingClient({\n apiBaseUrl: bundle.apiBaseUrl,\n apiKey: bundle.apiKey,\n privateKeyPkcs8: bundle.encryptionKey.privateKey,\n });\n }\n\n /** Lists the user's accounts with all sensitive fields decrypted. */\n async getAccounts(): Promise<Account[]> {\n const wires = await this.getAccountWires();\n return Promise.all(wires.map((w) => this.mapAccount(w)));\n }\n\n /** Returns a page of an account's statement, newest first, with decrypted fields. */\n async getTransactions(accountId: string, query: TransactionQuery = {}): Promise<TransactionPage> {\n const qs = new URLSearchParams();\n if (query.from != null) qs.set(\"from\", query.from);\n if (query.to != null) qs.set(\"to\", query.to);\n if (query.limit != null) qs.set(\"limit\", String(query.limit));\n if (query.offset != null) qs.set(\"offset\", String(query.offset));\n const suffix = qs.toString() ? `?${qs.toString()}` : \"\";\n\n const page = await this.getJson<TransactionPageWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`,\n );\n\n const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));\n return { items, total: page.total };\n }\n\n /** Lists the user's bank connections. */\n async getConnections(): Promise<Connection[]> {\n const wires = await this.getJson<ConnectionWire[]>(\"/api/connections\");\n return wires.map((c) => ({\n sessionId: c.sessionId,\n aspspName: c.aspspName,\n aspspCountry: c.aspspCountry,\n validUntil: c.validUntil,\n status: c.status,\n accountCount: c.accountCount,\n lastSyncedAt: c.lastSyncedAt ?? null,\n psuType: c.psuType ?? null,\n }));\n }\n\n /**\n * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts\n * it, so the service can fetch fresh data without ever holding the uid in plaintext.\n */\n async sync(accountId: string): Promise<SyncResult> {\n const wires = await this.getAccountWires();\n const account = wires.find((a) => a.id === accountId);\n if (!account) throw new Error(`Account ${accountId} not found`);\n\n const uid = await this.decryptUid(account);\n if (uid == null) {\n throw new Error(\"Account has no active session (reconnect required) — cannot sync\");\n }\n\n const result = await this.postJson<SyncResultWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/sync`,\n { uid },\n );\n return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };\n }\n\n /** Triggers an online sync of every account that has an active session. */\n async syncAll(): Promise<SyncAllResult> {\n const wires = await this.getAccountWires();\n const decrypted = await Promise.all(\n wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) })),\n );\n const items = decrypted\n .filter((x): x is { accountId: string; uid: string } => x.uid != null)\n .map((x) => ({ accountId: x.accountId, uid: x.uid }));\n\n const result = await this.postJson<SyncAllResultWire>(\"/api/sync\", { items });\n return { accounts: result.accounts, newTransactions: result.newTransactions };\n }\n\n // ---- internals ---------------------------------------------------------------------------------\n\n private getAccountWires(): Promise<AccountWire[]> {\n return this.getJson<AccountWire[]>(\"/api/accounts\");\n }\n\n private async decryptUid(a: AccountWire): Promise<string | null> {\n const dec = await decryptTo<UidEnc>(await this.privateKey, a.uidEnc);\n return dec?.uid ?? null;\n }\n\n private async mapAccount(a: AccountWire): Promise<Account> {\n const priv = await this.privateKey;\n const acc = await decryptTo<AccountEnc>(priv, a.enc);\n const name = await decryptTo<DisplayNameEnc>(priv, a.displayNameEnc);\n const balances = await Promise.all(\n (a.balances ?? []).map(async (b) => {\n const dec = await decryptTo<BalanceEnc>(priv, b.enc);\n return {\n type: b.type,\n name: dec?.name ?? null,\n amount: dec?.amount ?? \"0\",\n currency: b.currency,\n referenceDate: b.referenceDate ?? null,\n };\n }),\n );\n\n return {\n id: a.id,\n aspspName: a.aspspName,\n aspspCountry: a.aspspCountry,\n currency: a.currency,\n accountType: a.accountType ?? null,\n bic: a.bic ?? null,\n needsReconnect: a.needsReconnect,\n iban: acc?.iban ?? null,\n bban: acc?.bban ?? null,\n ownerName: acc?.ownerName ?? null,\n accountName: acc?.accountName ?? null,\n product: acc?.product ?? null,\n displayName: name?.displayName ?? null,\n balances,\n };\n }\n\n private async mapTransaction(t: TransactionWire): Promise<Transaction> {\n const d = await decryptTo<TransactionEnc>(await this.privateKey, t.enc);\n return {\n id: t.id,\n currency: t.currency,\n creditDebitIndicator: t.creditDebitIndicator,\n status: t.status ?? null,\n bookingDate: t.bookingDate ?? null,\n valueDate: t.valueDate ?? null,\n transactionDate: t.transactionDate ?? null,\n bankTransactionCode: t.bankTransactionCode ?? null,\n amount: d?.amount ?? \"0\",\n creditorName: d?.creditorName ?? null,\n creditorIban: d?.creditorIban ?? null,\n creditorBban: d?.creditorBban ?? null,\n creditorAgentBic: d?.creditorAgentBic ?? null,\n debtorName: d?.debtorName ?? null,\n debtorIban: d?.debtorIban ?? null,\n debtorBban: d?.debtorBban ?? null,\n debtorAgentBic: d?.debtorAgentBic ?? null,\n remittanceInformation: d?.remittanceInformation ?? null,\n note: d?.note ?? null,\n referenceNumber: d?.referenceNumber ?? null,\n exchangeRate: d?.exchangeRate ?? null,\n merchantCategoryCode: d?.merchantCategoryCode ?? null,\n balanceAfterTransaction: d?.balanceAfter ?? null,\n balanceAfterCurrency: d?.balanceAfterCurrency ?? null,\n };\n }\n\n private async getJson<T>(path: string): Promise<T> {\n const res = await fetch(this.baseUrl + path, { headers: { \"X-Api-Key\": this.apiKey } });\n if (!res.ok) {\n throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n\n private async postJson<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(this.baseUrl + path, {\n method: \"POST\",\n headers: { \"X-Api-Key\": this.apiKey, \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n}\n","import { webcrypto } from \"node:crypto\";\n\nconst { subtle } = webcrypto;\n\n/** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */\nexport type CryptoKey = webcrypto.CryptoKey;\n\nconst VERSION = 0x01;\nconst POINT_LEN = 65;\nconst NONCE_LEN = 12;\nconst TAG_LEN = 16;\n\nconst HKDF_INFO = new TextEncoder().encode(\"bank.core.ci/zk/v1\");\nconst HKDF_SALT = new Uint8Array(32); // 32 zero bytes (must be exactly this).\n\n/**\n * Decrypts open-banking.io's zero-knowledge data envelopes.\n * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.\n * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.\n * Only the user's private key can decrypt — the service stores ciphertext it cannot read.\n */\nexport async function decryptEnvelope(\n privateKey: CryptoKey,\n envelopeBase64: string,\n): Promise<Uint8Array> {\n const bytes = base64ToBytes(envelopeBase64);\n if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {\n throw new Error(\"Invalid or unsupported envelope\");\n }\n\n const ephPub = bytes.subarray(1, 1 + POINT_LEN);\n const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);\n const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n\n const ephKey = await subtle.importKey(\n \"raw\",\n ephPub,\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [],\n );\n\n const shared = new Uint8Array(\n await subtle.deriveBits({ name: \"ECDH\", public: ephKey }, privateKey, 256),\n );\n\n const hkdf = await subtle.importKey(\"raw\", shared, \"HKDF\", false, [\"deriveKey\"]);\n\n const aesKey = await subtle.deriveKey(\n { name: \"HKDF\", hash: \"SHA-256\", salt: HKDF_SALT, info: HKDF_INFO },\n hkdf,\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"decrypt\"],\n );\n\n // Web Crypto AES-GCM expects ciphertext||tag.\n const ctWithTag = new Uint8Array(ciphertext.length + tag.length);\n ctWithTag.set(ciphertext, 0);\n ctWithTag.set(tag, ciphertext.length);\n\n const plaintext = await subtle.decrypt(\n { name: \"AES-GCM\", iv: nonce, tagLength: 128 },\n aesKey,\n ctWithTag,\n );\n\n return new Uint8Array(plaintext);\n}\n\n/** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */\nexport async function decryptTo<T>(\n privateKey: CryptoKey,\n envelopeBase64: string | null | undefined,\n): Promise<T | null> {\n if (envelopeBase64 == null) return null;\n const plaintext = await decryptEnvelope(privateKey, envelopeBase64);\n return JSON.parse(new TextDecoder().decode(plaintext)) as T;\n}\n\n/** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */\nexport async function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey> {\n return subtle.importKey(\n \"pkcs8\",\n base64ToBytes(pkcs8Base64),\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [\"deriveBits\"],\n );\n}\n\nfunction base64ToBytes(b64: string): Uint8Array {\n return new Uint8Array(Buffer.from(b64, \"base64\"));\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,iBAAiB;AAE1B,IAAM,EAAE,OAAO,IAAI;AAKnB,IAAM,UAAU;AAChB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,UAAU;AAEhB,IAAM,YAAY,IAAI,YAAY,EAAE,OAAO,oBAAoB;AAC/D,IAAM,YAAY,IAAI,WAAW,EAAE;AAQnC,eAAsB,gBACpB,YACA,gBACqB;AACrB,QAAM,QAAQ,cAAc,cAAc;AAC1C,MAAI,MAAM,SAAS,IAAI,YAAY,YAAY,WAAW,MAAM,CAAC,MAAM,SAAS;AAC9E,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,SAAS,MAAM,SAAS,GAAG,IAAI,SAAS;AAC9C,QAAM,QAAQ,MAAM,SAAS,IAAI,WAAW,IAAI,YAAY,SAAS;AACrE,QAAM,MAAM,MAAM,SAAS,IAAI,YAAY,WAAW,IAAI,YAAY,YAAY,OAAO;AACzF,QAAM,aAAa,MAAM,SAAS,IAAI,YAAY,YAAY,OAAO;AAErE,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,EAAE,MAAM,QAAQ,YAAY,QAAQ;AAAA,IACpC;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,IAAI;AAAA,IACjB,MAAM,OAAO,WAAW,EAAE,MAAM,QAAQ,QAAQ,OAAO,GAAG,YAAY,GAAG;AAAA,EAC3E;AAEA,QAAM,OAAO,MAAM,OAAO,UAAU,OAAO,QAAQ,QAAQ,OAAO,CA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OAAO,EAAE,CAAC;AACtF,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,OAAO,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IACvE;AACA,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AAAA,EAEA,MAAc,SAAY,MAAc,MAA2B;AACjE,UAAM,MAAM,MAAM,MAAM,KAAK,UAAU,MAAM;AAAA,MAC3C,QAAQ;AAAA,MACR,SAAS,EAAE,aAAa,KAAK,QAAQ,gBAAgB,mBAAmB;AAAA,MACxE,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,IAAI,MAAM,QAAQ,IAAI,YAAY,IAAI,MAAM,IAAI,IAAI,UAAU,EAAE;AAAA,IACxE;AACA,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/client.ts","../src/envelope.ts","../package.json","../src/version.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { decryptTo, importPrivateKey, type CryptoKey } from \"./envelope.js\";\nimport { USER_AGENT } from \"./version.js\";\nimport type {\n Account,\n AccountEnc,\n AccountWire,\n BalanceEnc,\n Connection,\n ConnectionWire,\n CredentialsBundle,\n DisplayNameEnc,\n OpenBankingClientOptions,\n SyncAllResult,\n SyncAllResultWire,\n SyncResult,\n SyncResultWire,\n Transaction,\n TransactionEnc,\n TransactionPage,\n TransactionPageWire,\n TransactionQuery,\n TransactionWire,\n UidEnc,\n} from \"./models.js\";\n\n/**\n * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and\n * decrypts the zero-knowledge data envelopes locally with the exported private key — the service\n * only ever returns ciphertext it cannot read.\n */\nexport class OpenBankingClient {\n /** Default per-request timeout (30s) when {@link OpenBankingClientOptions.timeoutMs} is unset. */\n static readonly DEFAULT_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly timeoutMs: number;\n private readonly fetchImpl: typeof globalThis.fetch;\n private readonly privateKey: Promise<CryptoKey>;\n\n constructor(options: OpenBankingClientOptions) {\n const { apiBaseUrl, apiKey, privateKeyPkcs8, timeoutMs } = options;\n if (!apiBaseUrl?.trim()) throw new Error(\"apiBaseUrl is required\");\n if (!apiKey?.trim()) throw new Error(\"apiKey is required\");\n if (!privateKeyPkcs8?.trim()) throw new Error(\"privateKeyPkcs8 is required\");\n\n // Strip all trailing \"/\" without a backtracking regex (avoids ReDoS on long inputs).\n let end = apiBaseUrl.length;\n while (end > 0 && apiBaseUrl.charCodeAt(end - 1) === 47 /* \"/\" */) end--;\n this.baseUrl = apiBaseUrl.slice(0, end);\n this.apiKey = apiKey;\n this.timeoutMs = timeoutMs ?? OpenBankingClient.DEFAULT_TIMEOUT_MS;\n this.fetchImpl = options.fetch ?? fetch;\n this.privateKey = importPrivateKey(privateKeyPkcs8);\n }\n\n /**\n * Builds a client from a credentials-bundle JSON string or a path to a bundle file.\n *\n * `overrides` (optional) lets the bundle path set the same transport knobs as the\n * constructor — e.g. a custom {@link OpenBankingClientOptions.fetch} or\n * {@link OpenBankingClientOptions.timeoutMs}.\n */\n static fromCredentials(\n jsonOrPath: string,\n overrides: Partial<Pick<OpenBankingClientOptions, \"fetch\" | \"timeoutMs\">> = {},\n ): OpenBankingClient {\n let json = jsonOrPath;\n if (!jsonOrPath.trimStart().startsWith(\"{\")) {\n json = readFileSync(jsonOrPath, \"utf8\");\n }\n const bundle = JSON.parse(json) as CredentialsBundle;\n return OpenBankingClient.fromBundle(bundle, overrides);\n }\n\n static fromBundle(\n bundle: CredentialsBundle,\n overrides: Partial<Pick<OpenBankingClientOptions, \"fetch\" | \"timeoutMs\">> = {},\n ): OpenBankingClient {\n if (!bundle.apiKey?.trim()) throw new Error(\"The credentials bundle has no apiKey\");\n return new OpenBankingClient({\n apiBaseUrl: bundle.apiBaseUrl,\n apiKey: bundle.apiKey,\n privateKeyPkcs8: bundle.encryptionKey.privateKey,\n timeoutMs: overrides.timeoutMs,\n fetch: overrides.fetch,\n });\n }\n\n /** Lists the user's accounts with all sensitive fields decrypted. */\n async getAccounts(): Promise<Account[]> {\n const wires = await this.getAccountWires();\n return Promise.all(wires.map((w) => this.mapAccount(w)));\n }\n\n /** Returns a page of an account's statement, newest first, with decrypted fields. */\n async getTransactions(accountId: string, query: TransactionQuery = {}): Promise<TransactionPage> {\n const qs = new URLSearchParams();\n if (query.from != null) qs.set(\"from\", query.from);\n if (query.to != null) qs.set(\"to\", query.to);\n if (query.limit != null) qs.set(\"limit\", String(query.limit));\n if (query.offset != null) qs.set(\"offset\", String(query.offset));\n const suffix = qs.toString() ? `?${qs.toString()}` : \"\";\n\n const page = await this.getJson<TransactionPageWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`,\n );\n\n const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));\n return { items, total: page.total };\n }\n\n /** Lists the user's bank connections. */\n async getConnections(): Promise<Connection[]> {\n const wires = await this.getJson<ConnectionWire[]>(\"/api/connections\");\n return wires.map((c) => ({\n sessionId: c.sessionId,\n aspspName: c.aspspName,\n aspspCountry: c.aspspCountry,\n validUntil: c.validUntil,\n status: c.status,\n accountCount: c.accountCount,\n lastSyncedAt: c.lastSyncedAt ?? null,\n psuType: c.psuType ?? null,\n }));\n }\n\n /**\n * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts\n * it, so the service can fetch fresh data without ever holding the uid in plaintext.\n */\n async sync(accountId: string): Promise<SyncResult> {\n const wires = await this.getAccountWires();\n const account = wires.find((a) => a.id === accountId);\n if (!account) throw new Error(`Account ${accountId} not found`);\n\n const uid = await this.decryptUid(account);\n if (uid == null) {\n throw new Error(\"Account has no active session (reconnect required) — cannot sync\");\n }\n\n const result = await this.postJson<SyncResultWire>(\n `/api/accounts/${encodeURIComponent(accountId)}/sync`,\n { uid },\n );\n return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };\n }\n\n /** Triggers an online sync of every account that has an active session. */\n async syncAll(): Promise<SyncAllResult> {\n const wires = await this.getAccountWires();\n const decrypted = await Promise.all(\n wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) })),\n );\n const items = decrypted\n .filter((x): x is { accountId: string; uid: string } => x.uid != null)\n .map((x) => ({ accountId: x.accountId, uid: x.uid }));\n\n const result = await this.postJson<SyncAllResultWire>(\"/api/sync\", { items });\n return { accounts: result.accounts, newTransactions: result.newTransactions };\n }\n\n // ---- internals ---------------------------------------------------------------------------------\n\n private getAccountWires(): Promise<AccountWire[]> {\n return this.getJson<AccountWire[]>(\"/api/accounts\");\n }\n\n private async decryptUid(a: AccountWire): Promise<string | null> {\n const dec = await decryptTo<UidEnc>(await this.privateKey, a.uidEnc);\n return dec?.uid ?? null;\n }\n\n private async mapAccount(a: AccountWire): Promise<Account> {\n const priv = await this.privateKey;\n const acc = await decryptTo<AccountEnc>(priv, a.enc);\n const name = await decryptTo<DisplayNameEnc>(priv, a.displayNameEnc);\n const balances = await Promise.all(\n (a.balances ?? []).map(async (b) => {\n const dec = await decryptTo<BalanceEnc>(priv, b.enc);\n return {\n type: b.type,\n name: dec?.name ?? null,\n amount: dec?.amount ?? \"0\",\n currency: b.currency,\n referenceDate: b.referenceDate ?? null,\n };\n }),\n );\n\n return {\n id: a.id,\n aspspName: a.aspspName,\n aspspCountry: a.aspspCountry,\n currency: a.currency,\n accountType: a.accountType ?? null,\n bic: a.bic ?? null,\n needsReconnect: a.needsReconnect,\n iban: acc?.iban ?? null,\n bban: acc?.bban ?? null,\n ownerName: acc?.ownerName ?? null,\n accountName: acc?.accountName ?? null,\n product: acc?.product ?? null,\n displayName: name?.displayName ?? null,\n balances,\n };\n }\n\n private async mapTransaction(t: TransactionWire): Promise<Transaction> {\n const d = await decryptTo<TransactionEnc>(await this.privateKey, t.enc);\n return {\n id: t.id,\n currency: t.currency,\n creditDebitIndicator: t.creditDebitIndicator,\n status: t.status ?? null,\n bookingDate: t.bookingDate ?? null,\n valueDate: t.valueDate ?? null,\n transactionDate: t.transactionDate ?? null,\n bankTransactionCode: t.bankTransactionCode ?? null,\n amount: d?.amount ?? \"0\",\n creditorName: d?.creditorName ?? null,\n creditorIban: d?.creditorIban ?? null,\n creditorBban: d?.creditorBban ?? null,\n creditorAgentBic: d?.creditorAgentBic ?? null,\n debtorName: d?.debtorName ?? null,\n debtorIban: d?.debtorIban ?? null,\n debtorBban: d?.debtorBban ?? null,\n debtorAgentBic: d?.debtorAgentBic ?? null,\n remittanceInformation: d?.remittanceInformation ?? null,\n note: d?.note ?? null,\n referenceNumber: d?.referenceNumber ?? null,\n exchangeRate: d?.exchangeRate ?? null,\n merchantCategoryCode: d?.merchantCategoryCode ?? null,\n balanceAfterTransaction: d?.balanceAfter ?? null,\n balanceAfterCurrency: d?.balanceAfterCurrency ?? null,\n };\n }\n\n private async getJson<T>(path: string): Promise<T> {\n const res = await this.fetchImpl(this.baseUrl + path, {\n headers: { \"X-Api-Key\": this.apiKey, \"User-Agent\": USER_AGENT },\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n if (!res.ok) {\n throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n\n private async postJson<T>(path: string, body: unknown): Promise<T> {\n const res = await this.fetchImpl(this.baseUrl + path, {\n method: \"POST\",\n headers: {\n \"X-Api-Key\": this.apiKey,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": USER_AGENT,\n },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n if (!res.ok) {\n throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);\n }\n return (await res.json()) as T;\n }\n}\n","import { webcrypto } from \"node:crypto\";\n\nconst { subtle } = webcrypto;\n\n/** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */\nexport type CryptoKey = webcrypto.CryptoKey;\n\nconst VERSION = 0x01;\nconst POINT_LEN = 65;\nconst NONCE_LEN = 12;\nconst TAG_LEN = 16;\n\nconst HKDF_INFO = new TextEncoder().encode(\"bank.core.ci/zk/v1\");\nconst HKDF_SALT = new Uint8Array(32); // 32 zero bytes (must be exactly this).\n\n/**\n * Decrypts open-banking.io's zero-knowledge data envelopes.\n * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.\n * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.\n * Only the user's private key can decrypt — the service stores ciphertext it cannot read.\n */\nexport async function decryptEnvelope(\n privateKey: CryptoKey,\n envelopeBase64: string,\n): Promise<Uint8Array> {\n const bytes = base64ToBytes(envelopeBase64);\n if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {\n throw new Error(\"Invalid or unsupported envelope\");\n }\n\n const ephPub = bytes.subarray(1, 1 + POINT_LEN);\n const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);\n const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);\n\n // Guard against invalid-curve attacks: WebCrypto's P-256 `importKey` validates that the raw point\n // lies on the curve and is not the point at infinity, so a forged/off-curve ephemeral public key\n // throws here rather than yielding a derivable (and exploitable) shared secret below.\n const ephKey = await subtle.importKey(\n \"raw\",\n ephPub,\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [],\n );\n\n const shared = new Uint8Array(\n await subtle.deriveBits({ name: \"ECDH\", public: ephKey }, privateKey, 256),\n );\n\n const hkdf = await subtle.importKey(\"raw\", shared, \"HKDF\", false, [\"deriveKey\"]);\n\n const aesKey = await subtle.deriveKey(\n { name: \"HKDF\", hash: \"SHA-256\", salt: HKDF_SALT, info: HKDF_INFO },\n hkdf,\n { name: \"AES-GCM\", length: 256 },\n false,\n [\"decrypt\"],\n );\n\n // Web Crypto AES-GCM expects ciphertext||tag.\n const ctWithTag = new Uint8Array(ciphertext.length + tag.length);\n ctWithTag.set(ciphertext, 0);\n ctWithTag.set(tag, ciphertext.length);\n\n const plaintext = await subtle.decrypt(\n { name: \"AES-GCM\", iv: nonce, tagLength: 128 },\n aesKey,\n ctWithTag,\n );\n\n return new Uint8Array(plaintext);\n}\n\n/** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */\nexport async function decryptTo<T>(\n privateKey: CryptoKey,\n envelopeBase64: string | null | undefined,\n): Promise<T | null> {\n if (envelopeBase64 == null) return null;\n const plaintext = await decryptEnvelope(privateKey, envelopeBase64);\n return JSON.parse(new TextDecoder().decode(plaintext)) as T;\n}\n\n/** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */\nexport async function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey> {\n return subtle.importKey(\n \"pkcs8\",\n base64ToBytes(pkcs8Base64),\n { name: \"ECDH\", namedCurve: \"P-256\" },\n false,\n [\"deriveBits\"],\n );\n}\n\nfunction base64ToBytes(b64: string): Uint8Array<ArrayBuffer> {\n return new Uint8Array(Buffer.from(b64, \"base64\"));\n}\n","{\n \"name\": \"@open-banking-io/client\",\n \"version\": \"0.3.0\",\n \"description\": \"Server-to-server client for open-banking.io: API-key auth + client-side decryption of the zero-knowledge data envelopes with your exported private key.\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"open-banking.io\",\n \"keywords\": [\n \"open-banking\",\n \"psd2\",\n \"zero-knowledge\",\n \"encryption\",\n \"fintech\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/open-banking-io/clients\"\n },\n \"engines\": {\n \"node\": \">=20\"\n },\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n }\n },\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest run\",\n \"coverage\": \"vitest run --coverage\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format:check\": \"prettier --check .\"\n },\n \"overrides\": {\n \"esbuild\": \"^0.28.1\"\n },\n \"devDependencies\": {\n \"@eslint/js\": \"^10.0.1\",\n \"@types/node\": \"^25.9.3\",\n \"@vitest/coverage-v8\": \"^4.1.9\",\n \"eslint\": \"^10.5.0\",\n \"prettier\": \"^3.8.4\",\n \"tsup\": \"^8.5.1\",\n \"typescript\": \"^6.0.3\",\n \"typescript-eslint\": \"^8.61.1\",\n \"vitest\": \"^4.1.9\"\n }\n}\n","// The package version, sourced from package.json so it can never drift. tsup inlines the JSON at\n// build time (tree-shaken to the single string), and vitest/tsx resolve the import directly — so\n// this stays ESM/CJS-safe without a runtime file read.\nimport pkg from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION: string = pkg.version;\n\n/** The `User-Agent` sent on every request: `open-banking-io/node/<version>`. */\nexport const USER_AGENT = `open-banking-io/node/${VERSION}`;\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,iBAAiB;AAE1B,IAAM,EAAE,OAAO,IAAI;AAKnB,IAAM,UAAU;AAChB,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,UAAU;AAEhB,IAAM,YAAY,IAAI,YAAY,EAAE,OAAO,oBAAoB;AAC/D,IAAM,YAAY,IAAI,WAAW,EAAE;AAQnC,eAAsB,gBACpB,YACA,gBACqB;AACrB,QAAM,QAAQ,cAAc,cAAc;AAC1C,MAAI,MAAM,SAAS,IAAI,YAAY,YAAY,WAAW,MAAM,CAAC,MAAM,SAAS;AAC9E,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,SAAS,MAAM,SAAS,GAAG,IAAI,SAAS;AAC9C,QAAM,QAAQ,MAAM,SAA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,KAAK;AAAA,EACzB;AACF;","names":["VERSION"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-banking-io/client",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Server-to-server client for open-banking.io: API-key auth + client-side decryption of the zero-knowledge data envelopes with your exported private key.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,13 +36,23 @@
36
36
  "scripts": {
37
37
  "build": "tsup",
38
38
  "test": "vitest run",
39
+ "coverage": "vitest run --coverage",
39
40
  "typecheck": "tsc --noEmit",
40
- "lint": "tsc --noEmit"
41
+ "lint": "eslint .",
42
+ "format:check": "prettier --check ."
43
+ },
44
+ "overrides": {
45
+ "esbuild": "^0.28.1"
41
46
  },
42
47
  "devDependencies": {
43
- "@types/node": "^20.19.42",
44
- "tsup": "^8.3.5",
45
- "typescript": "^5.7.2",
46
- "vitest": "^2.1.8"
48
+ "@eslint/js": "^10.0.1",
49
+ "@types/node": "^25.9.3",
50
+ "@vitest/coverage-v8": "^4.1.9",
51
+ "eslint": "^10.5.0",
52
+ "prettier": "^3.8.4",
53
+ "tsup": "^8.5.1",
54
+ "typescript": "^6.0.3",
55
+ "typescript-eslint": "^8.61.1",
56
+ "vitest": "^4.1.9"
47
57
  }
48
58
  }