@oneaddress/partner-sdk 2.7.0 → 2.8.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 CHANGED
@@ -7,6 +7,144 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.8.0] - not yet published
11
+
12
+ Everything below, down to 2.7.0, ships in 2.8.0. **Not published.** Publishing
13
+ it is a release decision and starts a disclosure clock on what it carries.
14
+
15
+ ### Changed: the consent proof is required and verified by default
16
+
17
+ - **`requireLoa` defaults to `true`.** It defaulted to `true` only when
18
+ `loaPublicKeyPem` was set, so a handler configured with a webhook secret and
19
+ a private key, and nothing else, accepted any dispatch that secret signed.
20
+ Whoever held your webhook secret could impersonate OneAddress to you. A
21
+ dispatch must now carry a Letter of Authority signed by OneAddress's offline
22
+ LOA key, which the webhook secret cannot produce.
23
+ - **With no `loaPublicKeyPem`, the handler fetches the published key** from
24
+ `https://oneaddress.io/.well-known/oneaddress-loa-key.pem` on first use and
25
+ reuses it for a day (`LOA_PUBLIC_KEY_CACHE_MS`), sharing one fetch between
26
+ concurrent first deliveries and keeping the held key if a later refresh
27
+ fails. If no key can be had the dispatch is refused with a 500, so
28
+ OneAddress retries it, and the log names both ways out. New option
29
+ `loaPublicKeyBaseUrl` for a staging relay, held to the same host allowlist
30
+ and https rule as `fetchLoaPublicKey`. New exports `cachedLoaPublicKey` and
31
+ `LoaPublicKeyUnavailableError`.
32
+ - **What you need to do.** Nothing, if your receiver can reach
33
+ `oneaddress.io` over https. To avoid the fetch, pin the key with
34
+ `loaPublicKeyPem`. To keep the old behaviour, set `requireLoa: false`
35
+ explicitly; the handler then warns once per process that consent is
36
+ unverified. The conformance CLI's drill LOA is unsigned unless you pass
37
+ `--loa-signing-key`, so a receiver on 2.8.0 refuses the CLI's acceptance
38
+ checks by default: run the go-live check in the partner portal, which signs
39
+ with OneAddress's key, or configure a test key for the CLI run.
40
+
41
+ ### Changed: what the relay sends (24 Oct 2026)
42
+
43
+ - **`update_id` is your own id for the update.** It was `user_updates.id`,
44
+ the same at every partner one update went to and a running count besides.
45
+ Each partner now receives a keyed id, still a number (a safe integer up to
46
+ 2^53, so use a 64-bit column), stable across retries and crossover copies.
47
+ The LOA's `update_uid` is the same value, so the v2 check is unchanged.
48
+ - **`stripe_session_id` is no longer sent**, and `id_verification.verified_at`
49
+ is the day (midnight UTC) rather than the moment. Both were identical at
50
+ every partner. `buildSignedTestWebhook` follows, and its `stripeSessionId`
51
+ option is now ignored.
52
+
53
+ ### Security
54
+
55
+ - **`confirmUpdate` no longer sends your secret.** It sent
56
+ `Authorization: Bearer <secret>` beside the signature, so any egress proxy,
57
+ APM agent or debug log that records request headers held a secret that also
58
+ signs the dispatches OneAddress sends you. It now sends the signature alone,
59
+ as signature version 2 (`v2.${timestamp}.POST./api/confirm.${body}`, with
60
+ `X-OneAddress-Signature-Version: 2`), which `/api/confirm` accepts without a
61
+ Bearer. Version 2 covers the method and path, so the signature is valid for
62
+ that route and nothing else; the version 1 string is the form our dispatches
63
+ are signed in, and would verify in both directions on its own. No code change
64
+ is needed. If your egress records headers, rotate the secret once this
65
+ version is deployed. A hand-rolled confirm that still sends a Bearer keeps
66
+ working until OneAddress retires it, then answers `401` with
67
+ `code: "confirm_bearer_retired"`.
68
+
69
+ - **`event.address` is the six address fields on every path.** On the legacy
70
+ `address_encrypted` paths (`address.updated` without a session envelope, and
71
+ `address.verify`) the handler passed the whole decrypted blob as
72
+ `event.address`. The consumer seals that blob, so any key in it was theirs to
73
+ choose, and the README's `{ id: record.id, ...event.address }` let a blob
74
+ carrying `id` or `accountNumber` redirect the write to another record.
75
+ `validateAddress` now returns a new object holding `street`, `suburb`,
76
+ `state`, `postcode`, `country` and `updated_at` only, and refuses a field
77
+ that is not a string or is longer than `MAX_ADDRESS_FIELD_CHARS` (512). The
78
+ whole blob is still on `event.raw`. Identity fields read from a decrypted
79
+ payload (`customer.name`, `account_number`, `known_names`) are now taken only
80
+ when they are strings. The README examples write the partner's own key last.
81
+ - **The request body is capped before the signature check.** New option
82
+ `maxBodyBytes`, default 1 MiB (`DEFAULT_MAX_BODY_BYTES`). A declared
83
+ `Content-Length` over it is refused without reading; a Fetch request body is
84
+ read with the cap enforced as it arrives. Both answer `413` before any HMAC
85
+ is computed. Previously an unauthenticated caller could make the receiver
86
+ buffer and hash an arbitrary amount.
87
+ - **A dispatch still being processed is not processed again.** A second
88
+ delivery arriving while the first was inside `onUpdate` was told
89
+ `retry-after-incomplete` and ran it concurrently. `IdempotencyClaim` gains
90
+ `in-progress`, which the handler answers with `503 dispatch_in_progress` and
91
+ `Retry-After: 30`. `createSqlIdempotencyStore` keeps a lease (new option
92
+ `leaseSeconds`, default 120, `0` for the old behaviour) on the existing
93
+ `received_at` column, so no schema change is needed: a stale claim is taken
94
+ over in one conditional `UPDATE`, so two retries cannot both take it.
95
+ `IdempotencyStore` gains an optional `release`, which the handler calls on
96
+ every exit after a claim that did not complete (a throwing `onUpdate`, a
97
+ refused kind, a missing key), so the retry of a failed attempt need not wait
98
+ out the lease. A custom store that never returns `in-progress`, or has no
99
+ `release`, behaves as before. The SQL store needs the documented
100
+ `received_at` column; a table created without it will fail its first claim.
101
+ - **`confirmUpdate` only sends the secret to a OneAddress host.** It sent
102
+ `Authorization: Bearer <secret>` to whatever `appBaseUrl` it was given. The
103
+ base now passes the same https and host allowlist as `fetchLoaPublicKey`
104
+ (`oneaddress.io`, `app.oneaddress.io`, loopback outside production only), and
105
+ a refusal is returned as `{ ok: false, status: 0 }` with nothing sent. A
106
+ staging or self-hosted relay is named explicitly with the new `allowedHosts`
107
+ option, on `confirmUpdate` and on the handler's `confirm` block. Only the
108
+ origin of the base is used.
109
+ - **`namePoolMatches` is harder to satisfy with a crafted pool.** The pool is
110
+ the consumer's claim. One alias of every letter plus a surname matched every
111
+ holder of that surname, a pool of initials alone was a match, and a stored
112
+ name with no given name matched anyone with that surname. Now single-letter
113
+ tokens from an alias are ignored, at least one stored given name must be
114
+ explained by a full given name in the pool, a stored name without a given
115
+ name never matches, and the pool is bounded (10 aliases, 8 words per name,
116
+ 24 distinct words). Initials in the PRIMARY name still explain a second
117
+ stored token beside a full match (`John M Smith` matches `John Mary Smith`);
118
+ `J Smith` alone no longer matches `John Smith`.
119
+
120
+ ### Documentation
121
+
122
+ - The `decryptSession`, `transformSession` and `transformAddress` examples
123
+ verify the timestamp and signature before decrypting, and the two transform
124
+ examples now run on the raw body, where they previously read the already
125
+ decrypted `event.raw` and could not have worked.
126
+ - `verified_name` and `known_names` are described as consumer-supplied: match
127
+ them against the record you found by your own key, never use them to find one.
128
+
129
+ ### Added: LOA version 2 and the name rule (24 Oct 2026)
130
+
131
+ - When a decrypted LOA carries `oneaddress_signature_v2`, the handler verifies
132
+ it (with the LOA key configured) and refuses the dispatch if it was signed for
133
+ another recipient, another update or another envelope, or if the envelope's
134
+ `verified_name` differs from the LOA's `consumer_name` after normalisation
135
+ (case, whitespace, accents). Codes `loa_v2_*`, shared by all five SDKs.
136
+ - The LOA signs up to three typed aliases in `consumer_typed_aliases`, apart from
137
+ the verified name, and the handler hands on those (re-checked) rather than the
138
+ envelope's `known_names`. An alias must share the verified first name, or
139
+ be a short form of it of at least three letters, so a married name passes and
140
+ a relative sharing only the surname does not. Dropped, never
141
+ refused. A v2 LOA without the list is `loa_v2_malformed`.
142
+ - New: `checkLoaV2`, `hasLoaV2`, `acceptTypedAliases`, `isAcceptableAlias`, `typedAliasesOf`, `normaliseLoaName` and the
143
+ canonical-form and envelope-digest helpers, tested against the shared
144
+ `loa_v2` vectors in `packages/protocol/src/test-vectors.json`.
145
+ - An LOA without v2 fields behaves exactly as before.
146
+ - `buildSignedTestWebhook` now seals a v2 LOA by default; pass `loa: { oneaddress_signature_v2: undefined }` for a v1-only one.
147
+
10
148
  ## [2.7.0] - 2026-10-23
11
149
 
12
150
  ### Added
package/README.md CHANGED
@@ -49,6 +49,9 @@ export const handler = createOneAddressHandler({
49
49
  if (!customer?.account_number) {
50
50
  throw new Error('Dispatch carried no account number to match on');
51
51
  }
52
+ // The names are what the CONSUMER typed, sealed in their browser: not
53
+ // verified by anyone. Find the record by the account number YOU issued,
54
+ // then check the names against it. Never choose a record by name.
52
55
  const providedNames = [customer.name, ...customer.known_names];
53
56
  const record = await db.findByAccountNumber(customer.account_number);
54
57
  if (!record || !namePoolMatches(providedNames, record.fullName)) {
@@ -57,7 +60,10 @@ export const handler = createOneAddressHandler({
57
60
  // them, refunds the consumer at your expense. See "Confirming back".
58
61
  return { status: 'no_match' };
59
62
  }
60
- await db.updateAddress({ id: record.id, ...event.address });
63
+ // Your own key goes LAST, after anything decrypted: a spread placed
64
+ // after it could overwrite it. (event.address now holds only the six
65
+ // address fields, but write it this way regardless.)
66
+ await db.updateAddress({ ...event.address, id: record.id });
61
67
  return { status: 'confirmed' };
62
68
  },
63
69
 
@@ -198,7 +204,7 @@ What the handler guarantees:
198
204
 
199
205
  A **session envelope** is the address and identity for ONE partner, encrypted under a one-time key that is itself wrapped to that partner's registered public key, so only that partner can open it and OneAddress never can. Each `address.updated` webhook carries:
200
206
 
201
- - A per-partner `session_envelope` — AES-256-GCM ciphertext of the new address, account number, IDV reference, verified name, known-names, etc., encrypted under a fresh session key SK<sub>n</sub>.
207
+ - A per-partner `session_envelope`: AES-256-GCM ciphertext of the new address, account number, IDV reference, the consumer-supplied name and known-names, etc., encrypted under a fresh session key SK<sub>n</sub>.
202
208
  - A structured `session_key_share` block — ECDH-ES wrap of SK<sub>n</sub> under your specific registered key, identified by a stable `key_id`.
203
209
  - A per-partner `loa_encrypted` — the signed Letter of Authority, encrypted with the SAME scheme + key as the address envelope (`{ session_envelope, session_key_share }`).
204
210
 
@@ -207,7 +213,17 @@ A **session envelope** is the address and identity for ONE partner, encrypted un
207
213
  Decrypt via `decryptSession`:
208
214
 
209
215
  ```typescript
210
- import { decryptSession } from '@oneaddress/partner-sdk';
216
+ import { decryptSession, isFreshTimestamp, verifySignature } from '@oneaddress/partner-sdk';
217
+
218
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
219
+ // have not verified trusts whoever sent it.
220
+ const rawBody = await req.text();
221
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
222
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
223
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
224
+ return new Response('invalid signature', { status: 401 });
225
+ }
226
+ const body = JSON.parse(rawBody);
211
227
 
212
228
  const data = await decryptSession(
213
229
  body.session_key_share,
@@ -216,7 +232,9 @@ const data = await decryptSession(
216
232
  body.partner_id, // your partner UUID, used in HKDF info binding
217
233
  );
218
234
 
219
- // data.new_address.street, data.account_number, data.verified_name, etc.
235
+ // data.new_address.street, data.account_number, etc. data.verified_name and
236
+ // data.known_names are CONSUMER-SUPPLIED despite the field name: match them
237
+ // against your own record, never use them to choose one.
220
238
  ```
221
239
 
222
240
  `decryptSession` handles **both** wrap schemes transparently — it routes on `share.alg` and you just supply the private key matching `share.key_id`:
@@ -227,6 +245,46 @@ const data = await decryptSession(
227
245
 
228
246
  In all schemes the `session_envelope` is identical (AES-256-GCM under SK<sub>n</sub>) — only the SK<sub>n</sub> wrap differs.
229
247
 
248
+ ### The v2 consent record and the name rule (24 Oct 2026)
249
+
250
+ Every LOA OneAddress signs from 24 October 2026 carries two signatures. The
251
+ original one (`oneaddress_signature`) is unchanged, so an older SDK keeps
252
+ verifying. The second, `oneaddress_signature_v2`, is signed for **you alone**:
253
+ it binds your `partner_id`, the update id and the SHA-256 of the envelope it
254
+ arrived beside (`envelope_sha256`), over a length-prefixed form defined in
255
+ `@oneaddress/protocol` and shared by all five SDKs as test vectors.
256
+
257
+ The LOA's `consumer_name` is now the legal name from the identity check, and
258
+ the envelope's `verified_name` is that same name. When v2 is present the
259
+ handler runs `checkLoaV2` and refuses with a 500 (`LoaV2RefusedError`, carrying the code) if:
260
+
261
+ | Code | Meaning |
262
+ |---|---|
263
+ | `loa_v2_malformed` | a v2 field is missing or unencodable |
264
+ | `loa_v2_signature_invalid` | the v2 signature does not verify (checked only when the LOA key is configured) |
265
+ | `loa_v2_partner_mismatch` | it was signed for another recipient. Compared with the `partnerId` option (or `confirm.partnerId`); without either, the HMAC-signed body's `partner_id` |
266
+ | `loa_v2_update_mismatch` | its `update_uid` is not the body's `update_id` |
267
+ | `loa_v2_envelope_mismatch` | it was signed beside a different envelope |
268
+ | `loa_v2_name_mismatch` | the envelope names someone other than the LOA |
269
+
270
+ Names are compared after `normaliseLoaName`: Unicode NFKD, accents removed, lowercase,
271
+ whitespace collapsed. Punctuation is not folded. The binding checks run whether
272
+ or not you configured the LOA key; only the signature needs it.
273
+
274
+ **Typed aliases are signed, and checked after the verified name.** A v2 LOA carries
275
+ `consumer_typed_aliases`: up to three names the consumer typed, in a field of their
276
+ own so they cannot be mistaken for the verified `consumer_name`. For a v2 LOA the
277
+ handler hands on these signed aliases as the customer's known names (`typedAliasesOf`),
278
+ never the envelope's own `known_names`. Each must share the verified first name, or be a short form of it of at
279
+ least three letters; a shared surname alone is not enough
280
+ (`isAcceptableAlias`). So *Jane Doe* passes beside *Jane Citizen* (a married name),
281
+ *Tim Smith* passes beside *Timothy John Hooper*, and *Al Smith* beside
282
+ *Alexander Brown* does not, nor does *Robert Hooper* beside *Timothy Hooper*. An alias that fails is dropped, not refused. A v2 LOA
283
+ with no alias list, or more than three, is `loa_v2_malformed`. Match on the
284
+ verified name first and use an alias only when that fails.
285
+
286
+ An LOA without the v2 fields (`hasLoaV2` is false) is handled exactly as before.
287
+
230
288
  ### Decrypting + verifying the Letter of Authority
231
289
 
232
290
  The signed LOA travels as `loa_encrypted` (same `{ session_envelope, session_key_share }` shape, wrapped to the same `key_id`). Decrypt it, verify the signature, and echo the reference back in your confirm callback:
@@ -249,19 +307,19 @@ await confirmUpdate({
249
307
  });
250
308
  ```
251
309
 
252
- If you use `createOneAddressHandler`, this is done for you: pass `loaPublicKeyPem` and the handler decrypts + verifies + rejects on failure, and exposes `event.loa` (the decrypted LOA) and `event.loa_ref` (echo it in your confirm callback).
310
+ If you use `createOneAddressHandler`, this is done for you, by default since 2.8.0: the handler decrypts + verifies + rejects on failure, and exposes `event.loa` (the decrypted LOA) and `event.loa_ref` (echo it in your confirm callback). With no `loaPublicKeyPem` it fetches the published key from `https://oneaddress.io/.well-known/oneaddress-loa-key.pem` once and caches it for a day; pass `loaPublicKeyPem` to pin it instead.
253
311
 
254
312
  ### LOA verification: present AND verified AND bound
255
313
 
256
- With `loaPublicKeyPem` set, the handler checks three things on every `address.updated` / `contact.updated`, and refuses the dispatch (500, so OneAddress retries and records the failure) if any fails:
314
+ Unless you set `requireLoa: false`, the handler checks three things on every `address.updated` / `contact.updated`, and refuses the dispatch (500, so OneAddress retries and records the failure) if any fails. **Why it is the default (2.8.0):** your webhook secret authenticates a dispatch, but it sits on your receiver, so anyone who obtains it can sign one. The LOA is signed with OneAddress's offline key, which that secret cannot produce, so checking it is what stops a leaked secret being enough to impersonate OneAddress to you.
257
315
 
258
- 1. **Present.** A dispatch with no `loa_encrypted` at all is refused. Until 2.1.0 it was processed with no check, so "verified" meant "verified if the relay chose to include it". This is `requireLoa`, which defaults to `true` when `loaPublicKeyPem` is set. Set `requireLoa: false` to keep processing without a proof; the handler then warns once per process that consent is unverified.
259
- 2. **Verified.** The ECDSA P-256 signature over the canonical LOA form checks out against the key you fetched with `fetchLoaPublicKey` (which itself now insists on `https:` except for localhost).
316
+ 1. **Present.** A dispatch with no `loa_encrypted` at all is refused. Until 2.1.0 it was processed with no check, so "verified" meant "verified if the relay chose to include it". This is `requireLoa`, which defaults to `true` (before 2.8.0 it did so only when `loaPublicKeyPem` was set). Set `requireLoa: false` to keep processing without a proof; the handler then warns once per process that consent is unverified.
317
+ 2. **Verified.** The ECDSA P-256 signature over the canonical LOA form checks out against `loaPublicKeyPem`, or the published key the handler fetched (`fetchLoaPublicKey`, which insists on `https:` except for localhost). If the key cannot be fetched and none is held, the dispatch is refused with a 500 and the log says how to pin the key or opt out.
260
318
  3. **Bound.** The LOA's `update_uid` equals the session envelope's. A genuine, correctly signed consent for one update is not consent for another, and without this check a relay holding one real LOA could reuse it. Older dispatches that lack the field on either side are let through: this is a binding, not a requirement.
261
319
 
262
320
  The refusal is a 500 rather than a 200-and-skip on purpose: a 200 would tell OneAddress the delivery succeeded when nobody saw the consent proof.
263
321
 
264
- `requireLoa: true` without `loaPublicKeyPem` enforces presence and binding only; verification needs the key.
322
+ `requireLoa: false` with `loaPublicKeyPem` set still verifies an LOA that arrives, and lets one that is absent through. A staging relay can point the fetch elsewhere with `loaPublicKeyBaseUrl` (same allowlist as `fetchLoaPublicKey`). The conformance CLI's drill LOA is unsigned unless you pass `--loa-signing-key`, so on 2.8.0 run the go-live check in the partner portal, which signs with OneAddress's key.
265
323
 
266
324
  > **Post-quantum SDK availability.** The X-Wing (`MLKEM768X25519+…`) scheme is supported today in the **TypeScript** (this package) and **Go** SDKs. Python, Java, and C# X-Wing decapsulation is **available on request** — X-Wing is a 2024 draft without a mature drop-in library in those languages yet, so we build it per-SDK on demand (verified against the canonical `session_pq` test vector). Contact OneAddress engineering if you need a Python/Java/C# post-quantum build. ECDH-ES and RSA-OAEP are supported in all five SDKs.
267
325
 
@@ -282,6 +340,16 @@ See the partner portal documentation at partners.oneaddress.io for the full inte
282
340
  The pre-D5 `decryptAddress` helper is unchanged and still works for any webhook carrying the legacy `address_encrypted` field. A webhook will carry **either** the legacy shape **or** the D5 shape — never both. Detect by checking for `session_envelope`:
283
341
 
284
342
  ```typescript
343
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
344
+ // have not verified trusts whoever sent it.
345
+ const rawBody = await req.text();
346
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
347
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
348
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
349
+ return new Response('invalid signature', { status: 401 });
350
+ }
351
+ const body = JSON.parse(rawBody);
352
+
285
353
  if (body.session_envelope) {
286
354
  const data = await decryptSession(body.session_key_share, body.session_envelope, myKey, body.partner_id);
287
355
  } else {
@@ -301,8 +369,8 @@ The legacy helper is deprecated and will be removed in a future major version on
301
369
  > identity travels only inside the encrypted payload (`session_envelope` on
302
370
  > `address.updated`; `address_encrypted` on `address.verify`;
303
371
  > `customer_encrypted` on `account.verify`). `event.customer_match` is always
304
- > `undefined`. Match on the decrypted `verified_name` / `known_names` /
305
- > `account_number` instead; if you use `createOneAddressHandler`,
372
+ > `undefined`. Match on the decrypted `account_number` instead, then check the
373
+ > consumer-supplied `verified_name` / `known_names` against the record it finds; if you use `createOneAddressHandler`,
306
374
  > `event.customer` is populated for you after decryption. The section below is
307
375
  > retained for partners who adopted blind indexes while the feature was live
308
376
  > and still use them for their **own internal** matching columns; nothing in it
@@ -346,7 +414,9 @@ reference receivers run:
346
414
  ```typescript
347
415
  import { namePoolMatches } from '@oneaddress/partner-sdk';
348
416
 
349
- const data = await decryptSession(/* ... */);
417
+ const data = await decryptSession(/* ... after verifySignature, see above */);
418
+ // Consumer-supplied, whatever the field is called: the consumer typed these
419
+ // and sealed them in their browser. Look the record up by YOUR key first.
350
420
  const providedNames = [data.verified_name, ...(data.known_names ?? [])];
351
421
 
352
422
  const record = await db.findAccount(/* by account_number, etc. */);
@@ -364,6 +434,16 @@ permissive the rest of the pool is. `findMatchingStoredName(providedNames,
364
434
  candidates)` does the same over a list of candidate stored names and returns
365
435
  the first match, if any.
366
436
 
437
+ The pool is the consumer's claim, so it is bounded. A stored name
438
+ with no given name (`Smith`) never matches. At least one stored given name must
439
+ be explained by a FULL given name in the pool, so a pool of initials alone
440
+ (`J M Smith`) matches nothing. Single letters in an alias are ignored; a
441
+ single letter in the primary name may still explain a second stored token
442
+ beside a full match (`John M Smith` against `John Mary Smith`). Past ten
443
+ aliases, an alias of more than eight words, or more than 24 distinct words in
444
+ all, the extra is ignored or the pool refused. A match is still a check of the
445
+ record you found by your own key, never a way of finding one.
446
+
367
447
  Note: `namePoolMatches` assumes given-name-then-surname ordering (it treats the
368
448
  *last* token as the surname). If your customer base includes surname-first
369
449
  naming conventions, verify this assumption holds before relying on it.
@@ -385,7 +465,8 @@ createOneAddressHandler({
385
465
  async onUpdate(event) {
386
466
  const record = await db.findByAccountNumber(event.customer?.account_number);
387
467
  if (!record) return { status: 'no_match' };
388
- await db.updateAddress({ id: record.id, ...event.address });
468
+ // Your own key last, so nothing decrypted can overwrite it.
469
+ await db.updateAddress({ ...event.address, id: record.id });
389
470
  return { status: 'confirmed' };
390
471
  },
391
472
  });
@@ -430,11 +511,11 @@ A dispatch can carry an address together with a new phone number or email addres
430
511
 
431
512
  ### Which secret
432
513
 
433
- If you have minted a **confirm secret** in the Partner Portal, use that one — once it exists it is the only secret `/api/confirm` accepts, so that a leaked webhook secret cannot forge confirmations. If you have not, use your webhook signing secret. The same secret authenticates the request and signs the body.
514
+ If you have minted a **confirm secret** in the Partner Portal, use that one — once it exists it is the only secret `/api/confirm` accepts, so that a leaked webhook secret cannot forge confirmations. If you have not, use your webhook signing secret. The secret signs the request and is never sent: `confirmUpdate` puts no `Authorization` header on it, so nothing on your egress path that records request headers ever holds the secret.
434
515
 
435
516
  ### Why this helper exists
436
517
 
437
- The endpoint requires a Bearer token, a fresh unix-**seconds** timestamp, and an HMAC-SHA256 over `` `${timestamp}.${rawBody}` ``. Hand-rolling that has three failure modes which all surface as an indistinguishable `401`:
518
+ The endpoint requires a fresh unix-**seconds** timestamp, `X-OneAddress-Signature-Version: 2`, and an HMAC-SHA256 over `` `v2.${timestamp}.POST./api/confirm.${rawBody}` ``, and no `Authorization` header. Version 2 covers the method and path as well as the body, which is what lets the signature be the whole credential. Hand-rolling that has three failure modes which all surface as an indistinguishable `401`:
438
519
 
439
520
  - **Signing a string and then sending a re-serialised object.** A byte of whitespace or a different key order breaks the signature. `confirmUpdate` serialises once and sends exactly what it signed.
440
521
  - **Milliseconds instead of seconds.** That is outside the ±300s replay window by a factor of a thousand, and the error reads "stale or future request", which sounds like an auth problem.
@@ -505,7 +586,8 @@ async onUpdate(event) {
505
586
  if (seen) return; // idempotent no-op
506
587
  }
507
588
 
508
- await db.updateAddress({ accountNumber: event.customer?.account_number, ...event.address });
589
+ // Your own key last, so nothing decrypted can overwrite it.
590
+ await db.updateAddress({ ...event.address, accountNumber: event.customer?.account_number });
509
591
 
510
592
  if (event.dispatchId) {
511
593
  await db.dispatches.insert({ dispatchId: event.dispatchId });
@@ -550,7 +632,8 @@ export const handler = createOneAddressHandler({
550
632
  }),
551
633
 
552
634
  async onUpdate(event) {
553
- await db.updateAddress({ accountNumber: event.customer?.account_number, ...event.address });
635
+ // Your own key last, so nothing decrypted can overwrite it.
636
+ await db.updateAddress({ ...event.address, accountNumber: event.customer?.account_number });
554
637
  },
555
638
  });
556
639
  ```
@@ -717,21 +800,24 @@ The block is absent on sandbox dispatches, where no identity-verification credit
717
800
  The immutable IDV handle — the `verification_ref` UUID you quote back to OneAddress support to trace an update to its underlying verification — is **not** in this cleartext block. Per the zero-knowledge dispatch rules, customer identity (including the IDV reference) stays inside the encrypted `session_envelope`. After you decrypt it (via `decryptSession`, or automatically inside `createOneAddressHandler`), read it from the decrypted [`SessionData`](#d5--session-envelope-decryption-added-in-v130) as `id_verification_ref`:
718
801
 
719
802
  ```typescript
720
- import { decryptSession, type SessionData } from '@oneaddress/partner-sdk';
803
+ import type { SessionData } from '@oneaddress/partner-sdk';
721
804
 
722
- const session = await decryptSession(
723
- event.raw.session_key_share,
724
- event.raw.session_envelope,
725
- process.env.OA_PRIVATE_KEY_PEM!,
726
- process.env.OA_PARTNER_ID!,
727
- ) as SessionData;
728
-
729
- // Persist the ref against your record of the update — it never travels
730
- // in the clear and is only computable after you decrypt the envelope.
731
- await db.updateAddress({
732
- ...event.address,
733
- verification_ref: session.id_verification_ref,
734
- });
805
+ async onUpdate(event) {
806
+ // Inside createOneAddressHandler the envelope is already verified and
807
+ // decrypted: event.raw IS the SessionData, not the webhook body.
808
+ const session = event.raw as unknown as SessionData;
809
+ const account = event.customer?.account_number;
810
+ if (!account) throw new Error('Dispatch carried no account number to match on');
811
+
812
+ // Persist the ref against your record of the update. It never travels in
813
+ // the clear and is only readable after the envelope is decrypted. Your own
814
+ // key goes last, so nothing decrypted can overwrite it.
815
+ await db.updateAddress({
816
+ ...event.address,
817
+ verification_ref: session.id_verification_ref,
818
+ accountNumber: account,
819
+ });
820
+ }
735
821
  ```
736
822
 
737
823
  ---
@@ -819,7 +905,19 @@ If you handle `address.verify` **without** the SDK handler, call `sendVerifyResu
819
905
  yourself after verifying the HMAC signature and decrypting the address:
820
906
 
821
907
  ```typescript
822
- import { sendVerifyResult, compareAddresses, decryptAddress } from '@oneaddress/partner-sdk';
908
+ import {
909
+ sendVerifyResult, compareAddresses, decryptAddress, isFreshTimestamp, verifySignature,
910
+ } from '@oneaddress/partner-sdk';
911
+
912
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
913
+ // have not verified trusts whoever sent it.
914
+ const rawBody = await req.text();
915
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
916
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
917
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
918
+ return new Response('invalid signature', { status: 401 });
919
+ }
920
+ const body = JSON.parse(rawBody);
823
921
 
824
922
  const address = await decryptAddress(body.address_encrypted, privateKeyPem, partnerId);
825
923
  const match = compareAddresses(await db.getStoredAddress(body), address);
@@ -1018,19 +1116,32 @@ Decrypts the `address_encrypted` blob using your PKCS#8 ECDH P-256 private key.
1018
1116
 
1019
1117
  Decrypts a OneAddress payload and immediately re-encrypts it to a different ECDH P-256 public key — for example, your internal KMS or HSM. The plaintext address is held in memory only for the duration of the call and is never returned to the caller.
1020
1118
 
1021
- ```typescript
1022
- import { transformAddress } from '@oneaddress/partner-sdk';
1119
+ Call it from your own route, on the raw webhook body, not from inside
1120
+ `onUpdate`: by then the handler has decrypted the payload and `event.raw` is
1121
+ the plaintext, not the ciphertext.
1023
1122
 
1024
- async onUpdate(event) {
1025
- // Re-encrypt to your KMS key — plaintext never leaves this function
1026
- const kmsBlob = await transformAddress(
1027
- event.raw.address_encrypted as EncryptedPayload,
1028
- process.env.OA_PRIVATE_KEY_PEM!,
1029
- event.partner_id,
1030
- process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1031
- );
1032
- await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
1123
+ ```typescript
1124
+ import { transformAddress, isFreshTimestamp, verifySignature, type EncryptedPayload } from '@oneaddress/partner-sdk';
1125
+
1126
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
1127
+ // have not verified trusts whoever sent it.
1128
+ const rawBody = await req.text();
1129
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
1130
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
1131
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
1132
+ return new Response('invalid signature', { status: 401 });
1033
1133
  }
1134
+ const body = JSON.parse(rawBody);
1135
+
1136
+ // Re-encrypt to your KMS key. The plaintext never leaves this function.
1137
+ const kmsBlob = await transformAddress(
1138
+ body.address_encrypted as EncryptedPayload,
1139
+ process.env.OA_PRIVATE_KEY_PEM!,
1140
+ body.partner_id,
1141
+ process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1142
+ );
1143
+ // Filed by dispatch: the account is only knowable once your KMS decrypts it.
1144
+ await db.storeEncryptedAddress(body.dispatch_id, kmsBlob);
1034
1145
  ```
1035
1146
 
1036
1147
  Each call generates a fresh ephemeral key pair and random HKDF salt — full forward secrecy, no shared state between calls.
@@ -1041,25 +1152,37 @@ The **D5 session-envelope** counterpart to `transformAddress`. Decrypts a `sessi
1041
1152
 
1042
1153
  Use this for the current dispatch path (session envelopes); use `transformAddress` for the legacy single-blob `address_encrypted` path.
1043
1154
 
1044
- ```typescript
1045
- import { transformSession } from '@oneaddress/partner-sdk';
1155
+ Call it from your own route, on the raw webhook body. Inside `onUpdate`
1156
+ `event.raw` is the already-decrypted `SessionData`, which carries no
1157
+ `session_key_share` or `session_envelope` to transform.
1046
1158
 
1047
- async onUpdate(event) {
1048
- const body = event.raw; // the full webhook body
1049
- const myPrivateKey = keyStore.get(body.session_key_share.key_id);
1050
-
1051
- // Re-encrypt to your KMS key — the address never leaves this function in plaintext
1052
- const kmsBlob = await transformSession(
1053
- body.session_key_share,
1054
- body.session_envelope,
1055
- myPrivateKey,
1056
- body.partner_id,
1057
- process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1058
- );
1059
- // Use event.customer (decrypted by the handler), not body.customer - under
1060
- // D5 the raw webhook body carries no cleartext customer block at all.
1061
- await db.storeEncryptedAddress(event.customer?.account_number, kmsBlob);
1159
+ ```typescript
1160
+ import { transformSession, isFreshTimestamp, verifySignature } from '@oneaddress/partner-sdk';
1161
+
1162
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
1163
+ // have not verified trusts whoever sent it.
1164
+ const rawBody = await req.text();
1165
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
1166
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
1167
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
1168
+ return new Response('invalid signature', { status: 401 });
1062
1169
  }
1170
+ const body = JSON.parse(rawBody);
1171
+
1172
+ const myPrivateKey = keyStore.get(body.session_key_share.key_id);
1173
+
1174
+ // Re-encrypt to your KMS key. The address never leaves this function in plaintext.
1175
+ const kmsBlob = await transformSession(
1176
+ body.session_key_share,
1177
+ body.session_envelope,
1178
+ myPrivateKey,
1179
+ body.partner_id,
1180
+ process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1181
+ );
1182
+ // The raw body carries no cleartext customer block under D5, so file the blob
1183
+ // by dispatch, never by body.customer; the account is only knowable once your
1184
+ // KMS decrypts it.
1185
+ await db.storeEncryptedAddress(body.dispatch_id, kmsBlob);
1063
1186
  ```
1064
1187
 
1065
1188
  > **Zero plaintext in your app tier.** If your KMS/HSM exposes an ECDH P-256 public key, you can register *that* key as your OneAddress encryption key directly — then the consumer's browser encrypts straight to your KMS and you never need `transformSession` at all. `transformSession` is the bridge for when your OneAddress key and your KMS key differ. The HKDF `info` string differs from `transformAddress` (`oneaddress:transform-session:<partnerId>`) so the two paths never derive the same key.
@@ -1086,7 +1209,7 @@ Five identifiers arrive with a dispatch and they are easy to confuse. None of th
1086
1209
  |---|---|---|---|
1087
1210
  | `event.id` | Body `id` | The webhook event. Shared by every copy of a key-crossover dispatch, so a receiver holding both rotation keys applies it once. Absent on an ordinary dispatch. | Nothing, unless you hold more than one key. |
1088
1211
  | `event.dispatchId` | Header `X-OneAddress-Dispatch` | This delivery attempt, and its retries. A positive integer as a string; `''` when the header is absent. | **Idempotency**, and the `dispatchId` you pass to `confirmUpdate`. |
1089
- | `update_uid` | Body `update_id`, and inside the decrypted envelope and LOA | The consumer's update as a whole, across every partner it went to. The handler checks the LOA's copy against the envelope's. | Correlating one update across partners with OneAddress support. |
1212
+ | `update_uid` | Body `update_id` (a number), and its decimal string inside the LOA | The consumer's update, as YOUR id for it: since 24 Oct 2026 each partner receives its own keyed id for one update, stable across retries and crossover copies and unrelated to any other partner's. Up to 2^53, so store it in a 64-bit column. The handler checks the LOA's copy against the body's. | Correlating a dispatch with OneAddress support, who can resolve it. |
1090
1213
  | `batch_id` | Body, `address.verify` only | The verification batch a verify request belongs to. | Echo it in `sendVerifyResult`; the handler does this for you. |
1091
1214
  | `verification_id` | Body, `address.test` only | The connection-verification run a test record belongs to. | Counting the five test records. |
1092
1215