@open-banking-io/client 0.1.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/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @open-banking-io/client (Node / TypeScript)
2
+
3
+ Server-to-server client for [open-banking.io](https://open-banking.io). It authenticates with your
4
+ **API key** and decrypts the **zero-knowledge** data envelopes locally with your exported **private
5
+ key** — the service only ever returns ciphertext it cannot read.
6
+
7
+ ```bash
8
+ npm install @open-banking-io/client
9
+ ```
10
+
11
+ Requires Node >= 20 (uses the built-in `node:crypto` WebCrypto and `fetch`; no runtime deps).
12
+
13
+ ```ts
14
+ import { OpenBankingClient } from "@open-banking-io/client";
15
+
16
+ // Load the credentials .json you exported from the app (API key + private key).
17
+ const client = OpenBankingClient.fromCredentials("credentials.json");
18
+
19
+ for (const account of await client.getAccounts()) {
20
+ const booked = account.balances.find((b) => b.type === "ITBD");
21
+ console.log(`${account.displayName ?? account.ownerName} ${account.iban}: ${booked?.amount} ${account.currency}`);
22
+
23
+ const page = await client.getTransactions(account.id, { limit: 50 });
24
+ for (const t of page.items) {
25
+ console.log(` ${t.bookingDate} ${t.creditorName ?? t.debtorName} ${t.amount} ${t.currency}`);
26
+ }
27
+ }
28
+
29
+ // Trigger an online sync (decrypts the account uid locally and posts it):
30
+ await client.sync(accountId);
31
+ ```
32
+
33
+ Or construct it explicitly:
34
+
35
+ ```ts
36
+ const client = new OpenBankingClient({ apiBaseUrl, apiKey, privateKeyPkcs8 });
37
+ ```
38
+
39
+ ## Money
40
+
41
+ Amounts (`balance.amount`, `transaction.amount`, `transaction.balanceAfterTransaction`) are exposed
42
+ as **decimal strings** and never parsed to floats — keep them as strings or feed them into a decimal
43
+ library to avoid precision loss.
44
+
45
+ ## Encryption
46
+
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).
51
+
52
+ MIT licensed.
package/dist/index.cjs ADDED
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ OpenBankingClient: () => OpenBankingClient,
24
+ decryptEnvelope: () => decryptEnvelope,
25
+ decryptTo: () => decryptTo,
26
+ importPrivateKey: () => importPrivateKey
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/client.ts
31
+ var import_node_fs = require("fs");
32
+
33
+ // src/envelope.ts
34
+ var import_node_crypto = require("crypto");
35
+ var { subtle } = import_node_crypto.webcrypto;
36
+ var VERSION = 1;
37
+ var POINT_LEN = 65;
38
+ var NONCE_LEN = 12;
39
+ var TAG_LEN = 16;
40
+ var HKDF_INFO = new TextEncoder().encode("bank.core.ci/zk/v1");
41
+ var HKDF_SALT = new Uint8Array(32);
42
+ async function decryptEnvelope(privateKey, envelopeBase64) {
43
+ const bytes = base64ToBytes(envelopeBase64);
44
+ if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {
45
+ throw new Error("Invalid or unsupported envelope");
46
+ }
47
+ const ephPub = bytes.subarray(1, 1 + POINT_LEN);
48
+ const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);
49
+ const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);
50
+ const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);
51
+ const ephKey = await subtle.importKey(
52
+ "raw",
53
+ ephPub,
54
+ { name: "ECDH", namedCurve: "P-256" },
55
+ false,
56
+ []
57
+ );
58
+ const shared = new Uint8Array(
59
+ await subtle.deriveBits({ name: "ECDH", public: ephKey }, privateKey, 256)
60
+ );
61
+ const hkdf = await subtle.importKey("raw", shared, "HKDF", false, ["deriveKey"]);
62
+ const aesKey = await subtle.deriveKey(
63
+ { name: "HKDF", hash: "SHA-256", salt: HKDF_SALT, info: HKDF_INFO },
64
+ hkdf,
65
+ { name: "AES-GCM", length: 256 },
66
+ false,
67
+ ["decrypt"]
68
+ );
69
+ const ctWithTag = new Uint8Array(ciphertext.length + tag.length);
70
+ ctWithTag.set(ciphertext, 0);
71
+ ctWithTag.set(tag, ciphertext.length);
72
+ const plaintext = await subtle.decrypt(
73
+ { name: "AES-GCM", iv: nonce, tagLength: 128 },
74
+ aesKey,
75
+ ctWithTag
76
+ );
77
+ return new Uint8Array(plaintext);
78
+ }
79
+ async function decryptTo(privateKey, envelopeBase64) {
80
+ if (envelopeBase64 == null) return null;
81
+ const plaintext = await decryptEnvelope(privateKey, envelopeBase64);
82
+ return JSON.parse(new TextDecoder().decode(plaintext));
83
+ }
84
+ async function importPrivateKey(pkcs8Base64) {
85
+ return subtle.importKey(
86
+ "pkcs8",
87
+ base64ToBytes(pkcs8Base64),
88
+ { name: "ECDH", namedCurve: "P-256" },
89
+ false,
90
+ ["deriveBits"]
91
+ );
92
+ }
93
+ function base64ToBytes(b64) {
94
+ return new Uint8Array(Buffer.from(b64, "base64"));
95
+ }
96
+
97
+ // src/client.ts
98
+ var OpenBankingClient = class _OpenBankingClient {
99
+ baseUrl;
100
+ apiKey;
101
+ privateKey;
102
+ constructor(options) {
103
+ const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;
104
+ if (!apiBaseUrl?.trim()) throw new Error("apiBaseUrl is required");
105
+ if (!apiKey?.trim()) throw new Error("apiKey is required");
106
+ if (!privateKeyPkcs8?.trim()) throw new Error("privateKeyPkcs8 is required");
107
+ this.baseUrl = apiBaseUrl.replace(/\/+$/, "");
108
+ this.apiKey = apiKey;
109
+ this.privateKey = importPrivateKey(privateKeyPkcs8);
110
+ }
111
+ /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
112
+ static fromCredentials(jsonOrPath) {
113
+ let json = jsonOrPath;
114
+ if (!jsonOrPath.trimStart().startsWith("{")) {
115
+ json = (0, import_node_fs.readFileSync)(jsonOrPath, "utf8");
116
+ }
117
+ const bundle = JSON.parse(json);
118
+ return _OpenBankingClient.fromBundle(bundle);
119
+ }
120
+ static fromBundle(bundle) {
121
+ if (!bundle.apiKey?.trim()) throw new Error("The credentials bundle has no apiKey");
122
+ return new _OpenBankingClient({
123
+ apiBaseUrl: bundle.apiBaseUrl,
124
+ apiKey: bundle.apiKey,
125
+ privateKeyPkcs8: bundle.encryptionKey.privateKey
126
+ });
127
+ }
128
+ /** Lists the user's accounts with all sensitive fields decrypted. */
129
+ async getAccounts() {
130
+ const wires = await this.getAccountWires();
131
+ return Promise.all(wires.map((w) => this.mapAccount(w)));
132
+ }
133
+ /** Returns a page of an account's statement, newest first, with decrypted fields. */
134
+ async getTransactions(accountId, query = {}) {
135
+ const qs = new URLSearchParams();
136
+ if (query.from != null) qs.set("from", query.from);
137
+ if (query.to != null) qs.set("to", query.to);
138
+ if (query.limit != null) qs.set("limit", String(query.limit));
139
+ if (query.offset != null) qs.set("offset", String(query.offset));
140
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
141
+ const page = await this.getJson(
142
+ `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`
143
+ );
144
+ const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));
145
+ return { items, total: page.total };
146
+ }
147
+ /** Lists the user's bank connections. */
148
+ async getConnections() {
149
+ const wires = await this.getJson("/api/connections");
150
+ return wires.map((c) => ({
151
+ sessionId: c.sessionId,
152
+ aspspName: c.aspspName,
153
+ aspspCountry: c.aspspCountry,
154
+ validUntil: c.validUntil,
155
+ status: c.status,
156
+ accountCount: c.accountCount,
157
+ lastSyncedAt: c.lastSyncedAt ?? null,
158
+ psuType: c.psuType ?? null
159
+ }));
160
+ }
161
+ /**
162
+ * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts
163
+ * it, so the service can fetch fresh data without ever holding the uid in plaintext.
164
+ */
165
+ async sync(accountId) {
166
+ const wires = await this.getAccountWires();
167
+ const account = wires.find((a) => a.id === accountId);
168
+ if (!account) throw new Error(`Account ${accountId} not found`);
169
+ const uid = await this.decryptUid(account);
170
+ if (uid == null) {
171
+ throw new Error("Account has no active session (reconnect required) \u2014 cannot sync");
172
+ }
173
+ const result = await this.postJson(
174
+ `/api/accounts/${encodeURIComponent(accountId)}/sync`,
175
+ { uid }
176
+ );
177
+ return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };
178
+ }
179
+ /** Triggers an online sync of every account that has an active session. */
180
+ async syncAll() {
181
+ const wires = await this.getAccountWires();
182
+ const decrypted = await Promise.all(
183
+ wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) }))
184
+ );
185
+ const items = decrypted.filter((x) => x.uid != null).map((x) => ({ accountId: x.accountId, uid: x.uid }));
186
+ const result = await this.postJson("/api/sync", { items });
187
+ return { accounts: result.accounts, newTransactions: result.newTransactions };
188
+ }
189
+ // ---- internals ---------------------------------------------------------------------------------
190
+ getAccountWires() {
191
+ return this.getJson("/api/accounts");
192
+ }
193
+ async decryptUid(a) {
194
+ const dec = await decryptTo(await this.privateKey, a.uidEnc);
195
+ return dec?.uid ?? null;
196
+ }
197
+ async mapAccount(a) {
198
+ const priv = await this.privateKey;
199
+ const acc = await decryptTo(priv, a.enc);
200
+ const name = await decryptTo(priv, a.displayNameEnc);
201
+ const balances = await Promise.all(
202
+ (a.balances ?? []).map(async (b) => {
203
+ const dec = await decryptTo(priv, b.enc);
204
+ return {
205
+ type: b.type,
206
+ name: dec?.name ?? null,
207
+ amount: dec?.amount ?? "0",
208
+ currency: b.currency,
209
+ referenceDate: b.referenceDate ?? null
210
+ };
211
+ })
212
+ );
213
+ return {
214
+ id: a.id,
215
+ aspspName: a.aspspName,
216
+ aspspCountry: a.aspspCountry,
217
+ currency: a.currency,
218
+ accountType: a.accountType ?? null,
219
+ bic: a.bic ?? null,
220
+ needsReconnect: a.needsReconnect,
221
+ iban: acc?.iban ?? null,
222
+ bban: acc?.bban ?? null,
223
+ ownerName: acc?.ownerName ?? null,
224
+ accountName: acc?.accountName ?? null,
225
+ product: acc?.product ?? null,
226
+ displayName: name?.displayName ?? null,
227
+ balances
228
+ };
229
+ }
230
+ async mapTransaction(t) {
231
+ const d = await decryptTo(await this.privateKey, t.enc);
232
+ return {
233
+ id: t.id,
234
+ currency: t.currency,
235
+ creditDebitIndicator: t.creditDebitIndicator,
236
+ status: t.status ?? null,
237
+ bookingDate: t.bookingDate ?? null,
238
+ valueDate: t.valueDate ?? null,
239
+ transactionDate: t.transactionDate ?? null,
240
+ bankTransactionCode: t.bankTransactionCode ?? null,
241
+ amount: d?.amount ?? "0",
242
+ creditorName: d?.creditorName ?? null,
243
+ creditorIban: d?.creditorIban ?? null,
244
+ creditorBban: d?.creditorBban ?? null,
245
+ creditorAgentBic: d?.creditorAgentBic ?? null,
246
+ debtorName: d?.debtorName ?? null,
247
+ debtorIban: d?.debtorIban ?? null,
248
+ debtorBban: d?.debtorBban ?? null,
249
+ debtorAgentBic: d?.debtorAgentBic ?? null,
250
+ remittanceInformation: d?.remittanceInformation ?? null,
251
+ note: d?.note ?? null,
252
+ referenceNumber: d?.referenceNumber ?? null,
253
+ exchangeRate: d?.exchangeRate ?? null,
254
+ merchantCategoryCode: d?.merchantCategoryCode ?? null,
255
+ balanceAfterTransaction: d?.balanceAfter ?? null,
256
+ balanceAfterCurrency: d?.balanceAfterCurrency ?? null
257
+ };
258
+ }
259
+ async getJson(path) {
260
+ const res = await fetch(this.baseUrl + path, { headers: { "X-Api-Key": this.apiKey } });
261
+ if (!res.ok) {
262
+ throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);
263
+ }
264
+ return await res.json();
265
+ }
266
+ async postJson(path, body) {
267
+ const res = await fetch(this.baseUrl + path, {
268
+ method: "POST",
269
+ headers: { "X-Api-Key": this.apiKey, "Content-Type": "application/json" },
270
+ body: JSON.stringify(body)
271
+ });
272
+ if (!res.ok) {
273
+ throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);
274
+ }
275
+ return await res.json();
276
+ }
277
+ };
278
+ // Annotate the CommonJS export names for ESM import in node:
279
+ 0 && (module.exports = {
280
+ OpenBankingClient,
281
+ decryptEnvelope,
282
+ decryptTo,
283
+ importPrivateKey
284
+ });
285
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,QAAQ,QAAQ,OAAO,CAAC,WAAW,CAAC;AAE/E,QA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,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":[]}
@@ -0,0 +1,159 @@
1
+ import { webcrypto } from 'node:crypto';
2
+
3
+ /** A bank account with its sensitive fields decrypted. */
4
+ interface Account {
5
+ id: string;
6
+ aspspName: string;
7
+ aspspCountry: string;
8
+ currency: string;
9
+ accountType: string | null;
10
+ bic: string | null;
11
+ needsReconnect: boolean;
12
+ iban: string | null;
13
+ bban: string | null;
14
+ ownerName: string | null;
15
+ accountName: string | null;
16
+ product: string | null;
17
+ displayName: string | null;
18
+ balances: Balance[];
19
+ }
20
+ /** A balance snapshot. `type` is the ISO 20022 code (ITBD booked, ITAV available, …). */
21
+ interface Balance {
22
+ type: string;
23
+ name: string | null;
24
+ /** Decimal as a string — never parsed to float. */
25
+ amount: string;
26
+ currency: string;
27
+ referenceDate: string | null;
28
+ }
29
+ /** A statement transaction with its sensitive fields decrypted. */
30
+ interface Transaction {
31
+ id: string;
32
+ currency: string;
33
+ creditDebitIndicator: string;
34
+ status: string | null;
35
+ bookingDate: string | null;
36
+ valueDate: string | null;
37
+ transactionDate: string | null;
38
+ bankTransactionCode: string | null;
39
+ /** Decimal as a string — never parsed to float. */
40
+ amount: string;
41
+ creditorName: string | null;
42
+ creditorIban: string | null;
43
+ creditorBban: string | null;
44
+ creditorAgentBic: string | null;
45
+ debtorName: string | null;
46
+ debtorIban: string | null;
47
+ debtorBban: string | null;
48
+ debtorAgentBic: string | null;
49
+ remittanceInformation: string | null;
50
+ note: string | null;
51
+ referenceNumber: string | null;
52
+ exchangeRate: string | null;
53
+ merchantCategoryCode: string | null;
54
+ /** Decimal as a string, or `null`. */
55
+ balanceAfterTransaction: string | null;
56
+ balanceAfterCurrency: string | null;
57
+ }
58
+ /** A page of transactions, newest first. */
59
+ interface TransactionPage {
60
+ items: Transaction[];
61
+ total: number;
62
+ }
63
+ /** A bank connection (consent). */
64
+ interface Connection {
65
+ sessionId: string;
66
+ aspspName: string;
67
+ aspspCountry: string;
68
+ validUntil: string;
69
+ status: string;
70
+ accountCount: number;
71
+ lastSyncedAt: string | null;
72
+ psuType: string | null;
73
+ }
74
+ interface SyncResult {
75
+ newTransactions: number;
76
+ totalFetched: number;
77
+ }
78
+ interface SyncAllResult {
79
+ accounts: number;
80
+ newTransactions: number;
81
+ }
82
+ /** Options for {@link OpenBankingClient.getTransactions}. */
83
+ interface TransactionQuery {
84
+ from?: string;
85
+ to?: string;
86
+ limit?: number;
87
+ offset?: number;
88
+ }
89
+ interface CredentialsBundle {
90
+ service?: string;
91
+ apiBaseUrl: string;
92
+ user?: string;
93
+ apiKey?: string;
94
+ encryptionKey: EncryptionKey;
95
+ }
96
+ interface EncryptionKey {
97
+ scheme?: string;
98
+ curve?: string;
99
+ privateKeyFormat?: string;
100
+ /** The PKCS#8 private key, base64-encoded. */
101
+ privateKey: string;
102
+ publicKey?: string;
103
+ }
104
+ interface OpenBankingClientOptions {
105
+ apiBaseUrl: string;
106
+ apiKey: string;
107
+ /** The base64 PKCS#8 encryption private key from your bundle. */
108
+ privateKeyPkcs8: string;
109
+ }
110
+
111
+ /**
112
+ * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and
113
+ * decrypts the zero-knowledge data envelopes locally with the exported private key — the service
114
+ * only ever returns ciphertext it cannot read.
115
+ */
116
+ declare class OpenBankingClient {
117
+ private readonly baseUrl;
118
+ private readonly apiKey;
119
+ private readonly privateKey;
120
+ 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;
124
+ /** Lists the user's accounts with all sensitive fields decrypted. */
125
+ getAccounts(): Promise<Account[]>;
126
+ /** Returns a page of an account's statement, newest first, with decrypted fields. */
127
+ getTransactions(accountId: string, query?: TransactionQuery): Promise<TransactionPage>;
128
+ /** Lists the user's bank connections. */
129
+ getConnections(): Promise<Connection[]>;
130
+ /**
131
+ * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts
132
+ * it, so the service can fetch fresh data without ever holding the uid in plaintext.
133
+ */
134
+ sync(accountId: string): Promise<SyncResult>;
135
+ /** Triggers an online sync of every account that has an active session. */
136
+ syncAll(): Promise<SyncAllResult>;
137
+ private getAccountWires;
138
+ private decryptUid;
139
+ private mapAccount;
140
+ private mapTransaction;
141
+ private getJson;
142
+ private postJson;
143
+ }
144
+
145
+ /** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */
146
+ type CryptoKey = webcrypto.CryptoKey;
147
+ /**
148
+ * Decrypts open-banking.io's zero-knowledge data envelopes.
149
+ * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.
150
+ * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.
151
+ * Only the user's private key can decrypt — the service stores ciphertext it cannot read.
152
+ */
153
+ declare function decryptEnvelope(privateKey: CryptoKey, envelopeBase64: string): Promise<Uint8Array>;
154
+ /** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */
155
+ declare function decryptTo<T>(privateKey: CryptoKey, envelopeBase64: string | null | undefined): Promise<T | null>;
156
+ /** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */
157
+ declare function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey>;
158
+
159
+ export { type Account, type Balance, type Connection, type CredentialsBundle, type EncryptionKey, OpenBankingClient, type OpenBankingClientOptions, type SyncAllResult, type SyncResult, type Transaction, type TransactionPage, type TransactionQuery, decryptEnvelope, decryptTo, importPrivateKey };
@@ -0,0 +1,159 @@
1
+ import { webcrypto } from 'node:crypto';
2
+
3
+ /** A bank account with its sensitive fields decrypted. */
4
+ interface Account {
5
+ id: string;
6
+ aspspName: string;
7
+ aspspCountry: string;
8
+ currency: string;
9
+ accountType: string | null;
10
+ bic: string | null;
11
+ needsReconnect: boolean;
12
+ iban: string | null;
13
+ bban: string | null;
14
+ ownerName: string | null;
15
+ accountName: string | null;
16
+ product: string | null;
17
+ displayName: string | null;
18
+ balances: Balance[];
19
+ }
20
+ /** A balance snapshot. `type` is the ISO 20022 code (ITBD booked, ITAV available, …). */
21
+ interface Balance {
22
+ type: string;
23
+ name: string | null;
24
+ /** Decimal as a string — never parsed to float. */
25
+ amount: string;
26
+ currency: string;
27
+ referenceDate: string | null;
28
+ }
29
+ /** A statement transaction with its sensitive fields decrypted. */
30
+ interface Transaction {
31
+ id: string;
32
+ currency: string;
33
+ creditDebitIndicator: string;
34
+ status: string | null;
35
+ bookingDate: string | null;
36
+ valueDate: string | null;
37
+ transactionDate: string | null;
38
+ bankTransactionCode: string | null;
39
+ /** Decimal as a string — never parsed to float. */
40
+ amount: string;
41
+ creditorName: string | null;
42
+ creditorIban: string | null;
43
+ creditorBban: string | null;
44
+ creditorAgentBic: string | null;
45
+ debtorName: string | null;
46
+ debtorIban: string | null;
47
+ debtorBban: string | null;
48
+ debtorAgentBic: string | null;
49
+ remittanceInformation: string | null;
50
+ note: string | null;
51
+ referenceNumber: string | null;
52
+ exchangeRate: string | null;
53
+ merchantCategoryCode: string | null;
54
+ /** Decimal as a string, or `null`. */
55
+ balanceAfterTransaction: string | null;
56
+ balanceAfterCurrency: string | null;
57
+ }
58
+ /** A page of transactions, newest first. */
59
+ interface TransactionPage {
60
+ items: Transaction[];
61
+ total: number;
62
+ }
63
+ /** A bank connection (consent). */
64
+ interface Connection {
65
+ sessionId: string;
66
+ aspspName: string;
67
+ aspspCountry: string;
68
+ validUntil: string;
69
+ status: string;
70
+ accountCount: number;
71
+ lastSyncedAt: string | null;
72
+ psuType: string | null;
73
+ }
74
+ interface SyncResult {
75
+ newTransactions: number;
76
+ totalFetched: number;
77
+ }
78
+ interface SyncAllResult {
79
+ accounts: number;
80
+ newTransactions: number;
81
+ }
82
+ /** Options for {@link OpenBankingClient.getTransactions}. */
83
+ interface TransactionQuery {
84
+ from?: string;
85
+ to?: string;
86
+ limit?: number;
87
+ offset?: number;
88
+ }
89
+ interface CredentialsBundle {
90
+ service?: string;
91
+ apiBaseUrl: string;
92
+ user?: string;
93
+ apiKey?: string;
94
+ encryptionKey: EncryptionKey;
95
+ }
96
+ interface EncryptionKey {
97
+ scheme?: string;
98
+ curve?: string;
99
+ privateKeyFormat?: string;
100
+ /** The PKCS#8 private key, base64-encoded. */
101
+ privateKey: string;
102
+ publicKey?: string;
103
+ }
104
+ interface OpenBankingClientOptions {
105
+ apiBaseUrl: string;
106
+ apiKey: string;
107
+ /** The base64 PKCS#8 encryption private key from your bundle. */
108
+ privateKeyPkcs8: string;
109
+ }
110
+
111
+ /**
112
+ * Server-to-server client for open-banking.io. Authenticates with an API key (`X-Api-Key`) and
113
+ * decrypts the zero-knowledge data envelopes locally with the exported private key — the service
114
+ * only ever returns ciphertext it cannot read.
115
+ */
116
+ declare class OpenBankingClient {
117
+ private readonly baseUrl;
118
+ private readonly apiKey;
119
+ private readonly privateKey;
120
+ 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;
124
+ /** Lists the user's accounts with all sensitive fields decrypted. */
125
+ getAccounts(): Promise<Account[]>;
126
+ /** Returns a page of an account's statement, newest first, with decrypted fields. */
127
+ getTransactions(accountId: string, query?: TransactionQuery): Promise<TransactionPage>;
128
+ /** Lists the user's bank connections. */
129
+ getConnections(): Promise<Connection[]>;
130
+ /**
131
+ * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts
132
+ * it, so the service can fetch fresh data without ever holding the uid in plaintext.
133
+ */
134
+ sync(accountId: string): Promise<SyncResult>;
135
+ /** Triggers an online sync of every account that has an active session. */
136
+ syncAll(): Promise<SyncAllResult>;
137
+ private getAccountWires;
138
+ private decryptUid;
139
+ private mapAccount;
140
+ private mapTransaction;
141
+ private getJson;
142
+ private postJson;
143
+ }
144
+
145
+ /** Re-export the WebCrypto key type so callers don't depend on the DOM lib. */
146
+ type CryptoKey = webcrypto.CryptoKey;
147
+ /**
148
+ * Decrypts open-banking.io's zero-knowledge data envelopes.
149
+ * Scheme: ephemeral ECDH on NIST P-256 -> HKDF-SHA256 -> AES-256-GCM.
150
+ * Wire: `version(1)=0x01 | ephemeralPublicKeyRaw(65) | nonce(12) | tag(16) | ciphertext`.
151
+ * Only the user's private key can decrypt — the service stores ciphertext it cannot read.
152
+ */
153
+ declare function decryptEnvelope(privateKey: CryptoKey, envelopeBase64: string): Promise<Uint8Array>;
154
+ /** Decrypts a base64 envelope and JSON-parses its payload. `null`/`undefined` in -> `null`. */
155
+ declare function decryptTo<T>(privateKey: CryptoKey, envelopeBase64: string | null | undefined): Promise<T | null>;
156
+ /** Imports a base64 PKCS#8 P-256 ECDH private key for use with {@link decryptEnvelope}. */
157
+ declare function importPrivateKey(pkcs8Base64: string): Promise<CryptoKey>;
158
+
159
+ export { type Account, type Balance, type Connection, type CredentialsBundle, type EncryptionKey, OpenBankingClient, type OpenBankingClientOptions, type SyncAllResult, type SyncResult, type Transaction, type TransactionPage, type TransactionQuery, decryptEnvelope, decryptTo, importPrivateKey };
package/dist/index.js ADDED
@@ -0,0 +1,255 @@
1
+ // src/client.ts
2
+ import { readFileSync } from "fs";
3
+
4
+ // src/envelope.ts
5
+ import { webcrypto } from "crypto";
6
+ var { subtle } = webcrypto;
7
+ var VERSION = 1;
8
+ var POINT_LEN = 65;
9
+ var NONCE_LEN = 12;
10
+ var TAG_LEN = 16;
11
+ var HKDF_INFO = new TextEncoder().encode("bank.core.ci/zk/v1");
12
+ var HKDF_SALT = new Uint8Array(32);
13
+ async function decryptEnvelope(privateKey, envelopeBase64) {
14
+ const bytes = base64ToBytes(envelopeBase64);
15
+ if (bytes.length < 1 + POINT_LEN + NONCE_LEN + TAG_LEN || bytes[0] !== VERSION) {
16
+ throw new Error("Invalid or unsupported envelope");
17
+ }
18
+ const ephPub = bytes.subarray(1, 1 + POINT_LEN);
19
+ const nonce = bytes.subarray(1 + POINT_LEN, 1 + POINT_LEN + NONCE_LEN);
20
+ const tag = bytes.subarray(1 + POINT_LEN + NONCE_LEN, 1 + POINT_LEN + NONCE_LEN + TAG_LEN);
21
+ const ciphertext = bytes.subarray(1 + POINT_LEN + NONCE_LEN + TAG_LEN);
22
+ const ephKey = await subtle.importKey(
23
+ "raw",
24
+ ephPub,
25
+ { name: "ECDH", namedCurve: "P-256" },
26
+ false,
27
+ []
28
+ );
29
+ const shared = new Uint8Array(
30
+ await subtle.deriveBits({ name: "ECDH", public: ephKey }, privateKey, 256)
31
+ );
32
+ const hkdf = await subtle.importKey("raw", shared, "HKDF", false, ["deriveKey"]);
33
+ const aesKey = await subtle.deriveKey(
34
+ { name: "HKDF", hash: "SHA-256", salt: HKDF_SALT, info: HKDF_INFO },
35
+ hkdf,
36
+ { name: "AES-GCM", length: 256 },
37
+ false,
38
+ ["decrypt"]
39
+ );
40
+ const ctWithTag = new Uint8Array(ciphertext.length + tag.length);
41
+ ctWithTag.set(ciphertext, 0);
42
+ ctWithTag.set(tag, ciphertext.length);
43
+ const plaintext = await subtle.decrypt(
44
+ { name: "AES-GCM", iv: nonce, tagLength: 128 },
45
+ aesKey,
46
+ ctWithTag
47
+ );
48
+ return new Uint8Array(plaintext);
49
+ }
50
+ async function decryptTo(privateKey, envelopeBase64) {
51
+ if (envelopeBase64 == null) return null;
52
+ const plaintext = await decryptEnvelope(privateKey, envelopeBase64);
53
+ return JSON.parse(new TextDecoder().decode(plaintext));
54
+ }
55
+ async function importPrivateKey(pkcs8Base64) {
56
+ return subtle.importKey(
57
+ "pkcs8",
58
+ base64ToBytes(pkcs8Base64),
59
+ { name: "ECDH", namedCurve: "P-256" },
60
+ false,
61
+ ["deriveBits"]
62
+ );
63
+ }
64
+ function base64ToBytes(b64) {
65
+ return new Uint8Array(Buffer.from(b64, "base64"));
66
+ }
67
+
68
+ // src/client.ts
69
+ var OpenBankingClient = class _OpenBankingClient {
70
+ baseUrl;
71
+ apiKey;
72
+ privateKey;
73
+ constructor(options) {
74
+ const { apiBaseUrl, apiKey, privateKeyPkcs8 } = options;
75
+ if (!apiBaseUrl?.trim()) throw new Error("apiBaseUrl is required");
76
+ if (!apiKey?.trim()) throw new Error("apiKey is required");
77
+ if (!privateKeyPkcs8?.trim()) throw new Error("privateKeyPkcs8 is required");
78
+ this.baseUrl = apiBaseUrl.replace(/\/+$/, "");
79
+ this.apiKey = apiKey;
80
+ this.privateKey = importPrivateKey(privateKeyPkcs8);
81
+ }
82
+ /** Builds a client from a credentials-bundle JSON string or a path to a bundle file. */
83
+ static fromCredentials(jsonOrPath) {
84
+ let json = jsonOrPath;
85
+ if (!jsonOrPath.trimStart().startsWith("{")) {
86
+ json = readFileSync(jsonOrPath, "utf8");
87
+ }
88
+ const bundle = JSON.parse(json);
89
+ return _OpenBankingClient.fromBundle(bundle);
90
+ }
91
+ static fromBundle(bundle) {
92
+ if (!bundle.apiKey?.trim()) throw new Error("The credentials bundle has no apiKey");
93
+ return new _OpenBankingClient({
94
+ apiBaseUrl: bundle.apiBaseUrl,
95
+ apiKey: bundle.apiKey,
96
+ privateKeyPkcs8: bundle.encryptionKey.privateKey
97
+ });
98
+ }
99
+ /** Lists the user's accounts with all sensitive fields decrypted. */
100
+ async getAccounts() {
101
+ const wires = await this.getAccountWires();
102
+ return Promise.all(wires.map((w) => this.mapAccount(w)));
103
+ }
104
+ /** Returns a page of an account's statement, newest first, with decrypted fields. */
105
+ async getTransactions(accountId, query = {}) {
106
+ const qs = new URLSearchParams();
107
+ if (query.from != null) qs.set("from", query.from);
108
+ if (query.to != null) qs.set("to", query.to);
109
+ if (query.limit != null) qs.set("limit", String(query.limit));
110
+ if (query.offset != null) qs.set("offset", String(query.offset));
111
+ const suffix = qs.toString() ? `?${qs.toString()}` : "";
112
+ const page = await this.getJson(
113
+ `/api/accounts/${encodeURIComponent(accountId)}/transactions${suffix}`
114
+ );
115
+ const items = await Promise.all((page.items ?? []).map((t) => this.mapTransaction(t)));
116
+ return { items, total: page.total };
117
+ }
118
+ /** Lists the user's bank connections. */
119
+ async getConnections() {
120
+ const wires = await this.getJson("/api/connections");
121
+ return wires.map((c) => ({
122
+ sessionId: c.sessionId,
123
+ aspspName: c.aspspName,
124
+ aspspCountry: c.aspspCountry,
125
+ validUntil: c.validUntil,
126
+ status: c.status,
127
+ accountCount: c.accountCount,
128
+ lastSyncedAt: c.lastSyncedAt ?? null,
129
+ psuType: c.psuType ?? null
130
+ }));
131
+ }
132
+ /**
133
+ * Triggers an online sync of one account: decrypts that account's Enable Banking uid and posts
134
+ * it, so the service can fetch fresh data without ever holding the uid in plaintext.
135
+ */
136
+ async sync(accountId) {
137
+ const wires = await this.getAccountWires();
138
+ const account = wires.find((a) => a.id === accountId);
139
+ if (!account) throw new Error(`Account ${accountId} not found`);
140
+ const uid = await this.decryptUid(account);
141
+ if (uid == null) {
142
+ throw new Error("Account has no active session (reconnect required) \u2014 cannot sync");
143
+ }
144
+ const result = await this.postJson(
145
+ `/api/accounts/${encodeURIComponent(accountId)}/sync`,
146
+ { uid }
147
+ );
148
+ return { newTransactions: result.newTransactions, totalFetched: result.totalFetched };
149
+ }
150
+ /** Triggers an online sync of every account that has an active session. */
151
+ async syncAll() {
152
+ const wires = await this.getAccountWires();
153
+ const decrypted = await Promise.all(
154
+ wires.map(async (a) => ({ accountId: a.id, uid: await this.decryptUid(a) }))
155
+ );
156
+ const items = decrypted.filter((x) => x.uid != null).map((x) => ({ accountId: x.accountId, uid: x.uid }));
157
+ const result = await this.postJson("/api/sync", { items });
158
+ return { accounts: result.accounts, newTransactions: result.newTransactions };
159
+ }
160
+ // ---- internals ---------------------------------------------------------------------------------
161
+ getAccountWires() {
162
+ return this.getJson("/api/accounts");
163
+ }
164
+ async decryptUid(a) {
165
+ const dec = await decryptTo(await this.privateKey, a.uidEnc);
166
+ return dec?.uid ?? null;
167
+ }
168
+ async mapAccount(a) {
169
+ const priv = await this.privateKey;
170
+ const acc = await decryptTo(priv, a.enc);
171
+ const name = await decryptTo(priv, a.displayNameEnc);
172
+ const balances = await Promise.all(
173
+ (a.balances ?? []).map(async (b) => {
174
+ const dec = await decryptTo(priv, b.enc);
175
+ return {
176
+ type: b.type,
177
+ name: dec?.name ?? null,
178
+ amount: dec?.amount ?? "0",
179
+ currency: b.currency,
180
+ referenceDate: b.referenceDate ?? null
181
+ };
182
+ })
183
+ );
184
+ return {
185
+ id: a.id,
186
+ aspspName: a.aspspName,
187
+ aspspCountry: a.aspspCountry,
188
+ currency: a.currency,
189
+ accountType: a.accountType ?? null,
190
+ bic: a.bic ?? null,
191
+ needsReconnect: a.needsReconnect,
192
+ iban: acc?.iban ?? null,
193
+ bban: acc?.bban ?? null,
194
+ ownerName: acc?.ownerName ?? null,
195
+ accountName: acc?.accountName ?? null,
196
+ product: acc?.product ?? null,
197
+ displayName: name?.displayName ?? null,
198
+ balances
199
+ };
200
+ }
201
+ async mapTransaction(t) {
202
+ const d = await decryptTo(await this.privateKey, t.enc);
203
+ return {
204
+ id: t.id,
205
+ currency: t.currency,
206
+ creditDebitIndicator: t.creditDebitIndicator,
207
+ status: t.status ?? null,
208
+ bookingDate: t.bookingDate ?? null,
209
+ valueDate: t.valueDate ?? null,
210
+ transactionDate: t.transactionDate ?? null,
211
+ bankTransactionCode: t.bankTransactionCode ?? null,
212
+ amount: d?.amount ?? "0",
213
+ creditorName: d?.creditorName ?? null,
214
+ creditorIban: d?.creditorIban ?? null,
215
+ creditorBban: d?.creditorBban ?? null,
216
+ creditorAgentBic: d?.creditorAgentBic ?? null,
217
+ debtorName: d?.debtorName ?? null,
218
+ debtorIban: d?.debtorIban ?? null,
219
+ debtorBban: d?.debtorBban ?? null,
220
+ debtorAgentBic: d?.debtorAgentBic ?? null,
221
+ remittanceInformation: d?.remittanceInformation ?? null,
222
+ note: d?.note ?? null,
223
+ referenceNumber: d?.referenceNumber ?? null,
224
+ exchangeRate: d?.exchangeRate ?? null,
225
+ merchantCategoryCode: d?.merchantCategoryCode ?? null,
226
+ balanceAfterTransaction: d?.balanceAfter ?? null,
227
+ balanceAfterCurrency: d?.balanceAfterCurrency ?? null
228
+ };
229
+ }
230
+ async getJson(path) {
231
+ const res = await fetch(this.baseUrl + path, { headers: { "X-Api-Key": this.apiKey } });
232
+ if (!res.ok) {
233
+ throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);
234
+ }
235
+ return await res.json();
236
+ }
237
+ async postJson(path, body) {
238
+ const res = await fetch(this.baseUrl + path, {
239
+ method: "POST",
240
+ headers: { "X-Api-Key": this.apiKey, "Content-Type": "application/json" },
241
+ body: JSON.stringify(body)
242
+ });
243
+ if (!res.ok) {
244
+ throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);
245
+ }
246
+ return await res.json();
247
+ }
248
+ };
249
+ export {
250
+ OpenBankingClient,
251
+ decryptEnvelope,
252
+ decryptTo,
253
+ importPrivateKey
254
+ };
255
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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EAEA,MAAc,QAAW,MAA0B;AACjD,UAAM,MAAM,MAAM,MAAM,KAAK,UAAU,MAAM,EAAE,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":[]}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@open-banking-io/client",
3
+ "version": "0.1.0",
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
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "open-banking.io",
8
+ "keywords": [
9
+ "open-banking",
10
+ "psd2",
11
+ "zero-knowledge",
12
+ "encryption",
13
+ "fintech"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/open-banking-io/clients"
18
+ },
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.cjs"
34
+ }
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "test": "vitest run",
39
+ "typecheck": "tsc --noEmit",
40
+ "lint": "tsc --noEmit"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.19.42",
44
+ "tsup": "^8.3.5",
45
+ "typescript": "^5.7.2",
46
+ "vitest": "^2.1.8"
47
+ }
48
+ }