@oneaddress/partner-sdk 1.2.0 → 1.6.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/CHANGELOG.md ADDED
@@ -0,0 +1,238 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@oneaddress/partner-sdk` are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.6.0] - 2026-08-20
11
+
12
+ ### Added
13
+
14
+ - **`confirmUpdate` — the reply half of the protocol, which the SDK did not have.**
15
+ Everything here helped a partner RECEIVE a dispatch and nothing at all helped
16
+ them answer one, and answering is not optional: until the callback lands, the
17
+ consumer's dashboard shows that business stuck on "dispatched" indefinitely,
18
+ however correctly the change was applied.
19
+
20
+ What partners were left to derive from a README example whose auth step was
21
+ the comment `/* …auth… */`: a Bearer token, a fresh unix-**seconds**
22
+ timestamp, and an HMAC-SHA256 over `` `${timestamp}.${rawBody}` ``. The three
23
+ ways that goes wrong all surface as the same unhelpful `401` —
24
+
25
+ 1. signing a JSON string and then handing `fetch` an object, which
26
+ re-serialises it (a byte of whitespace or a different key order is enough);
27
+ 2. milliseconds instead of seconds, which is outside the ±300s replay window
28
+ by a factor of a thousand and reports "stale or future request", reading
29
+ as an auth failure rather than a units one;
30
+ 3. clock drift on the partner's host, which reports the same thing.
31
+
32
+ `confirmUpdate` serialises once and sends exactly the bytes it signed, stamps
33
+ seconds, and **returns `{ ok, status, error }` rather than throwing** — a
34
+ confirm that fails has to be something the caller can see, because partners
35
+ wrap this in fire-and-forget `.catch()` and an exception there is
36
+ indistinguishable from success. That is the shape of marlowe-reports#125 in
37
+ the other direction: the update looks applied on the partner's side and the
38
+ consumer never sees it land.
39
+
40
+ It also refuses a missing or non-numeric `dispatchId` **before** sending.
41
+ `createOneAddressHandler` surfaces `''` when the `X-OneAddress-Dispatch`
42
+ header was absent, and `/api/confirm` treats an absent `dispatch_id` as a
43
+ no-op for the dispatch record — so coercing it and posting would return `200`
44
+ having closed no loop, which is the worst outcome available.
45
+
46
+ ### Changed
47
+
48
+ - The README's LOA example no longer hides the hard part behind
49
+ `/* …auth… */`, and there is a **Confirming back** section covering the three
50
+ statuses, which secret to use, and why the result must be logged.
51
+
52
+ ## [1.5.0]
53
+
54
+ ### Added
55
+
56
+ - **`toExpressHandler` — the Express adapter the README always implied existed.**
57
+ `createOneAddressHandler` returns a **Fetch-shaped** function: it calls
58
+ `req.text()` and `req.headers.get()` and returns a `Response`. That contract is
59
+ deliberate and is not changing — it is what lets one handler run unchanged on
60
+ Next.js App Router, Cloudflare Workers, Deno and Bun. Express provides none of
61
+ it, and the README's Express line implied `express.raw` was the only
62
+ adjustment needed:
63
+
64
+ ```js
65
+ // app.post('/webhook/oneaddress', express.raw(...), handler); // crashes
66
+ ```
67
+
68
+ Passing the handler straight in throws `TypeError: req.text is not a function`
69
+ on the **first delivery**. Reported by an external integrator who followed that
70
+ line exactly (marlowe-reports#123).
71
+
72
+ ```js
73
+ import { createOneAddressHandler, toExpressHandler } from '@oneaddress/partner-sdk';
74
+
75
+ app.post(
76
+ '/webhook/oneaddress',
77
+ express.raw({ type: 'application/json' }), // required — see below
78
+ toExpressHandler(handler),
79
+ );
80
+ ```
81
+
82
+ Structurally typed against Express's request/response shape, so the SDK gains
83
+ no dependency on Express and the adapter also covers Connect and the several
84
+ frameworks that copy the API.
85
+
86
+ - **The raw-body requirement is now enforced by name rather than assumed**, and
87
+ this is worth more than the adapter itself. The webhook signature is an HMAC
88
+ over the **raw request bytes**. If `express.json()` has already parsed the
89
+ body, those bytes are gone, and re-serialising the object does not reproduce
90
+ them — a different key order or a single space of whitespace is enough. The
91
+ symptom is a `401 Invalid signature` that is **indistinguishable from a wrong
92
+ signing secret**, which is a long afternoon for whoever is debugging it.
93
+
94
+ `toExpressHandler` refuses a parsed or missing body with a 500 and a log line
95
+ naming the cause and the middleware to add, before it can become a mystery
96
+ signature failure.
97
+
98
+ ### Notes
99
+
100
+ - No breaking changes. Existing Fetch-style call sites (App Router, Workers,
101
+ Deno, Bun) are untouched — `toExpressHandler` is purely additive and opt-in.
102
+
103
+ ## [1.4.0]
104
+
105
+ ### Added
106
+
107
+ - **`createSqlIdempotencyStore` + atomic `claim`/`complete` on `idempotencyStore`.**
108
+ The existing `has`/`set` pair cannot be made correct under concurrency - they
109
+ are two round-trips, so two retries arriving together both observe "not seen"
110
+ and both apply the update. `claim` is a single atomic
111
+ `INSERT ... ON CONFLICT DO NOTHING`. It also distinguishes three states rather
112
+ than two, and the third is the one that matters: a dispatch whose previous
113
+ attempt never reported completion returns `retry-after-incomplete` and is
114
+ **re-processed**, where a two-state store has to guess - and guessing
115
+ "duplicate" loses a paid address update permanently the first time a process
116
+ dies mid-write, with both sides reporting success.
117
+ `createSqlIdempotencyStore` implements this over any SQL database via a
118
+ caller-supplied `query` function, so the SDK stays dependency-free.
119
+ `has`/`set` remain supported and are used when `claim` is absent.
120
+
121
+ - **`readAddressParts` / `formatAddressParts` - tolerant address field reader.**
122
+ Extracts `line1` / `suburb` / `state` / `postcode` / `country` from a decrypted
123
+ payload regardless of which field-name spelling it uses (`street`,
124
+ `address_line1`, `city`, `locality`, `postalCode`, `zip`, and friends), with
125
+ `country` defaulting to `AU`. Every OneAddress reference receiver had
126
+ hand-rolled the same `a.line1 ?? a.address_line1 ?? a.street ?? …` ladder, so a
127
+ fix to one copy silently left the others behind - this is now one
128
+ implementation with its own tests. It is a *tolerant reader*, not a schema
129
+ declaration: it describes what the helper accepts and says nothing about what
130
+ OneAddress guarantees to send.
131
+
132
+ - **`namePoolMatches` / `findMatchingStoredName` - canonical name matching.**
133
+ Re-exported from `@oneaddress/name-match`, the same component-aware matcher
134
+ OneAddress's own reference receivers run. Match a decrypted `verified_name` /
135
+ `known_names` pool against your stored record without writing your own
136
+ comparison - a naive substring/prefix approach treats an email address as
137
+ just another name token, which is a real false-positive-match vector we
138
+ found and closed in our own systems. See the README's "Name matching"
139
+ section.
140
+
141
+ ### Fixed
142
+
143
+ - **Published `.d.ts` no longer references unresolved workspace-only modules.**
144
+ A deep-dive audit found that the built `dist/index.d.ts` left
145
+ `@oneaddress/crypto`, `@oneaddress/name-match`, and `@oneaddress/protocol`
146
+ as unresolved external re-exports - private workspace packages, never
147
+ published to npm. Every TypeScript partner installing this package got
148
+ `TS2307: Cannot find module` on exactly the functions the README instructs
149
+ them to import (`namePoolMatches`, `isFreshTimestamp`, `computeBlindIndex`,
150
+ ...). Fixed via a dedicated `tsconfig.build.json` (Bundler resolution +
151
+ explicit `paths`) and `tsup --dts-resolve`, so the dts bundler now inlines
152
+ these types the same way esbuild already inlined the runtime code. Verified
153
+ by simulating a real external `npm install` (no workspace) and typechecking
154
+ against it - confirmed clean. Guarded going forward by
155
+ `src/dist-exports.test.ts`, which rebuilds `dist/` and asserts no
156
+ unresolved `@oneaddress/*` re-export ever reappears (no prior test touched
157
+ the built artifact at all - only the source).
158
+ - **Quick-start example no longer uses the field it warns readers away from.**
159
+ `event.customer.email` is always `''` on `address.updated` (documented one
160
+ section later in the same README) - the flagship quick-start, idempotency,
161
+ and both `transform*` examples all used it anyway, so a partner following
162
+ them verbatim would write an empty string to their database and log
163
+ `"Address updated for :"` on every real dispatch. All four now match on
164
+ `account_number` instead. The `account.verify` example's own name
165
+ comparison has also been swapped from a naive case-insensitive string
166
+ match to `namePoolMatches` - the exact anti-pattern the "Name matching"
167
+ section above warns against, previously present in the very next example.
168
+ - **`edge.ts` now re-exports everything the README claims it does.**
169
+ `namePoolMatches`, `findMatchingStoredName`, `isEmailLike`,
170
+ `compareAddresses`, and `sendVerifyResult` (plus their types) were missing
171
+ from the `/edge` entry point despite none of them using anything
172
+ Node-specific.
173
+ - **Doc corrections, no behaviour change:** `loaPublicKeyPem` and
174
+ `customer_match` doc comments now state precisely which event types they
175
+ actually apply to (`loaPublicKeyPem` only enforces on `address.updated`;
176
+ `customer_match` is only ever populated on `address.verify` - it's a dead,
177
+ always-`undefined` field on `address.updated` and `account.verify`,
178
+ previously documented as if universally present). The stale "legacy
179
+ decryptAddress removed in v1.3.x" claim has been corrected - no removal is
180
+ currently scheduled. `package.json`'s `exports` map condition order fixed
181
+ (`types` must be listed before `import`/`require`, previously reversed and
182
+ silently ignored by resolvers that respect ordering).
183
+
184
+ ## [1.3.0]
185
+
186
+ The D5 "no cleartext" dispatch release. Dispatches no longer carry a cleartext
187
+ `customer` block, blind-index `customer_match`, or cleartext `letter_of_authority`
188
+ by default — consumer identity, the account number, the IDV reference, and the
189
+ signed consent are all recovered by decrypting per-partner encrypted material.
190
+
191
+ ### Added
192
+
193
+ - **D5 session-envelope decryption.** `decryptSession(share, envelopeB64, privateKeyPem, partnerId)`
194
+ unwraps a per-partner `session_key_share` and decrypts the `session_envelope`
195
+ to recover the structured `SessionData` (new address, account number,
196
+ verified name, known names, and `id_verification_ref`). `transformSession`
197
+ is the KMS/HSM re-encryption counterpart.
198
+ - **`loa_encrypted` / `loa_ref` — structured D5 Letter of Authority.** New
199
+ standalone helpers `decryptLoaEncrypted`, `verifyD5LOA`, `d5LoaRef`, and
200
+ `canonicalD5LoaForm`, plus the `OneAddressD5LOA` type. Decrypt the signed
201
+ consent, verify its ECDSA P-256 signature, and recompute the `loa_ref` to
202
+ echo back in your `/api/confirm` callback. These are now also exported from
203
+ `@oneaddress/partner-sdk/edge` so Cloudflare Workers / Next.js Edge partners
204
+ can verify the LOA standalone, without the full `createOneAddressHandler`
205
+ factory.
206
+ - **Blind-index matching (`customer_match`).** Shipped earlier in the D5
207
+ migration, before the "no cleartext" mandate above superseded it as the
208
+ default: for partners who opted into blind-index matching, dispatches
209
+ carried a `customer_match` block instead of a cleartext `customer`. New
210
+ `computeBlindIndex` / `normalizeForBlindIndex` helpers compute the salted
211
+ indexes (email, name, account number) under your portal-issued blind-index
212
+ secret. See the README's "Blind-index matching" section for current status
213
+ (superseded for `address.updated`, but the helpers remain exported for
214
+ partners doing their own internal matching).
215
+ - **Additional key-wrap schemes for `session_key_share`.** Alongside the default
216
+ ECDH-ES (P-256) wrap, `decryptSession` now supports:
217
+ - `RSA-OAEP-256+A256GCM` — for partners whose KMS/HSM key is RSA.
218
+ - `MLKEM768X25519+HKDF-SHA256+A256GCM` — post-quantum hybrid wrap
219
+ (X-Wing = ML-KEM-768 + X25519).
220
+ - **Multi-language parity.** The D5 decryption + LOA verification flow now has
221
+ reference implementations in Go, Python, Java, and C# to match the TypeScript
222
+ SDK.
223
+
224
+ ### Changed
225
+
226
+ - **`OneAddressIdVerification` type corrected (zero-knowledge fix).** The
227
+ cleartext `id_verification` block no longer declares `verification_ref` or
228
+ `certificate_id` — those fields never travel in the clear. The immutable IDV
229
+ handle now lives inside the encrypted `session_envelope` and is exposed as
230
+ `SessionData.id_verification_ref` after you decrypt it. The cleartext block
231
+ carries only `{ method, verified_at, verified, platform }`, where `method` is
232
+ `identity_document` (or `mock` in sandbox builds). The README "Identity
233
+ verification attestation" section has been updated to read the ref from the
234
+ decrypted `SessionData` rather than the outer payload.
235
+
236
+ ## [1.2.0]
237
+
238
+ - Initial public D5-preview release with session-envelope decryption helpers.