@oneaddress/partner-sdk 2.7.0 → 2.9.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,178 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.9.0] - unreleased (repo bump only, not published)
11
+
12
+ ### Added: `effective_date` on scheduled moves
13
+
14
+ - **`OneAddressUpdateEvent.effective_date`** (`YYYY-MM-DD`), the day the change
15
+ takes effect. OneAddress sends a scheduled move early enough for your declared
16
+ notice period, so it can arrive before the customer moves; apply it from this
17
+ date. Absent on an immediate update.
18
+ - **A malformed `effective_date` is refused with 400 `invalid_effective_date`**
19
+ before `onUpdate` runs, and the idempotency claim is left incomplete.
20
+ - **`buildSignedTestWebhook` takes `effectiveDate`** to rehearse a scheduled move.
21
+ - **The date is also sealed inside the envelope** (`SessionData.effective_date`).
22
+ A body date that differs from the sealed one, or either without the other, is
23
+ refused (500, `EffectiveDateMismatchError`) before `onUpdate`, like the other
24
+ consent bindings. Validated against the shared `session_effective_date` vectors.
25
+
26
+ ### Changed
27
+
28
+ - **`checkRegistryHead` with `keyId` and no `holdsKey`** now reports
29
+ `names-key-we-lack` (`alarm: true`) when the signed head names a different
30
+ key for your partner id. It used to report `key-identity-unknown`. Treat the
31
+ new verdict as an alarm: either you rotated and have not updated `keyId`, or
32
+ the head names a key you do not hold.
33
+ - **`confirmUpdate` refuses a `partnerId` that is not a UUID** with
34
+ `{ ok: false, status: 0 }` and a message naming the value, before signing or
35
+ sending anything. Use the partner id from the portal.
36
+
37
+ ### Added
38
+
39
+ - **`onUpdate` may return `note`** beside `status`. With auto-confirm on
40
+ (`confirm` set), it is sent as the confirm's `note`, so a `failed` can say
41
+ why. Shown to OneAddress support, never to the consumer. Never put the
42
+ address or any other decrypted detail in it.
43
+
44
+ ## [2.8.0] - 2026-10-25
45
+
46
+ Published at registry timestamp `2026-10-25T10:35:14.828Z`. Everything below,
47
+ down to 2.7.0, ships in 2.8.0.
48
+
49
+ ### Changed: the consent proof is required and verified by default
50
+
51
+ - **`requireLoa` defaults to `true`.** It defaulted to `true` only when
52
+ `loaPublicKeyPem` was set, so a handler configured with a webhook secret and
53
+ a private key, and nothing else, accepted any dispatch that secret signed.
54
+ Whoever held your webhook secret could impersonate OneAddress to you. A
55
+ dispatch must now carry a Letter of Authority signed by OneAddress's offline
56
+ LOA key, which the webhook secret cannot produce.
57
+ - **With no `loaPublicKeyPem`, the handler fetches the published key** from
58
+ `https://oneaddress.io/.well-known/oneaddress-loa-key.pem` on first use and
59
+ reuses it for a day (`LOA_PUBLIC_KEY_CACHE_MS`), sharing one fetch between
60
+ concurrent first deliveries and keeping the held key if a later refresh
61
+ fails. If no key can be had the dispatch is refused with a 500, so
62
+ OneAddress retries it, and the log names both ways out. New option
63
+ `loaPublicKeyBaseUrl` for a staging relay, held to the same host allowlist
64
+ and https rule as `fetchLoaPublicKey`. New exports `cachedLoaPublicKey` and
65
+ `LoaPublicKeyUnavailableError`.
66
+ - **What you need to do.** Nothing, if your receiver can reach
67
+ `oneaddress.io` over https. To avoid the fetch, pin the key with
68
+ `loaPublicKeyPem`. To keep the old behaviour, set `requireLoa: false`
69
+ explicitly; the handler then warns once per process that consent is
70
+ unverified. The conformance CLI's drill LOA is unsigned unless you pass
71
+ `--loa-signing-key`, so a receiver on 2.8.0 refuses the CLI's acceptance
72
+ checks by default: run the go-live check in the partner portal, which signs
73
+ with OneAddress's key, or configure a test key for the CLI run.
74
+
75
+ ### Changed: what the relay sends (24 Oct 2026)
76
+
77
+ - **`update_id` is your own id for the update.** It was `user_updates.id`,
78
+ the same at every partner one update went to and a running count besides.
79
+ Each partner now receives a keyed id, still a number (a safe integer up to
80
+ 2^53, so use a 64-bit column), stable across retries and crossover copies.
81
+ The LOA's `update_uid` is the same value, so the v2 check is unchanged.
82
+ - **`stripe_session_id` is no longer sent**, and `id_verification.verified_at`
83
+ is the day (midnight UTC) rather than the moment. Both were identical at
84
+ every partner. `buildSignedTestWebhook` follows, and its `stripeSessionId`
85
+ option is now ignored.
86
+
87
+ ### Security
88
+
89
+ - **`confirmUpdate` no longer sends your secret.** It sent
90
+ `Authorization: Bearer <secret>` beside the signature, so any egress proxy,
91
+ APM agent or debug log that records request headers held a secret that also
92
+ signs the dispatches OneAddress sends you. It now sends the signature alone,
93
+ as signature version 2 (`v2.${timestamp}.POST./api/confirm.${body}`, with
94
+ `X-OneAddress-Signature-Version: 2`), which `/api/confirm` accepts without a
95
+ Bearer. Version 2 covers the method and path, so the signature is valid for
96
+ that route and nothing else; the version 1 string is the form our dispatches
97
+ are signed in, and would verify in both directions on its own. No code change
98
+ is needed. If your egress records headers, rotate the secret once this
99
+ version is deployed. A hand-rolled confirm that still sends a Bearer keeps
100
+ working until OneAddress retires it, then answers `401` with
101
+ `code: "confirm_bearer_retired"`.
102
+
103
+ - **`event.address` is the six address fields on every path.** On the legacy
104
+ `address_encrypted` paths (`address.updated` without a session envelope, and
105
+ `address.verify`) the handler passed the whole decrypted blob as
106
+ `event.address`. The consumer seals that blob, so any key in it was theirs to
107
+ choose, and the README's `{ id: record.id, ...event.address }` let a blob
108
+ carrying `id` or `accountNumber` redirect the write to another record.
109
+ `validateAddress` now returns a new object holding `street`, `suburb`,
110
+ `state`, `postcode`, `country` and `updated_at` only, and refuses a field
111
+ that is not a string or is longer than `MAX_ADDRESS_FIELD_CHARS` (512). The
112
+ whole blob is still on `event.raw`. Identity fields read from a decrypted
113
+ payload (`customer.name`, `account_number`, `known_names`) are now taken only
114
+ when they are strings. The README examples write the partner's own key last.
115
+ - **The request body is capped before the signature check.** New option
116
+ `maxBodyBytes`, default 1 MiB (`DEFAULT_MAX_BODY_BYTES`). A declared
117
+ `Content-Length` over it is refused without reading; a Fetch request body is
118
+ read with the cap enforced as it arrives. Both answer `413` before any HMAC
119
+ is computed. Previously an unauthenticated caller could make the receiver
120
+ buffer and hash an arbitrary amount.
121
+ - **A dispatch still being processed is not processed again.** A second
122
+ delivery arriving while the first was inside `onUpdate` was told
123
+ `retry-after-incomplete` and ran it concurrently. `IdempotencyClaim` gains
124
+ `in-progress`, which the handler answers with `503 dispatch_in_progress` and
125
+ `Retry-After: 30`. `createSqlIdempotencyStore` keeps a lease (new option
126
+ `leaseSeconds`, default 120, `0` for the old behaviour) on the existing
127
+ `received_at` column, so no schema change is needed: a stale claim is taken
128
+ over in one conditional `UPDATE`, so two retries cannot both take it.
129
+ `IdempotencyStore` gains an optional `release`, which the handler calls on
130
+ every exit after a claim that did not complete (a throwing `onUpdate`, a
131
+ refused kind, a missing key), so the retry of a failed attempt need not wait
132
+ out the lease. A custom store that never returns `in-progress`, or has no
133
+ `release`, behaves as before. The SQL store needs the documented
134
+ `received_at` column; a table created without it will fail its first claim.
135
+ - **`confirmUpdate` only sends the secret to a OneAddress host.** It sent
136
+ `Authorization: Bearer <secret>` to whatever `appBaseUrl` it was given. The
137
+ base now passes the same https and host allowlist as `fetchLoaPublicKey`
138
+ (`oneaddress.io`, `app.oneaddress.io`, loopback outside production only), and
139
+ a refusal is returned as `{ ok: false, status: 0 }` with nothing sent. A
140
+ staging or self-hosted relay is named explicitly with the new `allowedHosts`
141
+ option, on `confirmUpdate` and on the handler's `confirm` block. Only the
142
+ origin of the base is used.
143
+ - **`namePoolMatches` is harder to satisfy with a crafted pool.** The pool is
144
+ the consumer's claim. One alias of every letter plus a surname matched every
145
+ holder of that surname, a pool of initials alone was a match, and a stored
146
+ name with no given name matched anyone with that surname. Now single-letter
147
+ tokens from an alias are ignored, at least one stored given name must be
148
+ explained by a full given name in the pool, a stored name without a given
149
+ name never matches, and the pool is bounded (10 aliases, 8 words per name,
150
+ 24 distinct words). Initials in the PRIMARY name still explain a second
151
+ stored token beside a full match (`John M Smith` matches `John Mary Smith`);
152
+ `J Smith` alone no longer matches `John Smith`.
153
+
154
+ ### Documentation
155
+
156
+ - The `decryptSession`, `transformSession` and `transformAddress` examples
157
+ verify the timestamp and signature before decrypting, and the two transform
158
+ examples now run on the raw body, where they previously read the already
159
+ decrypted `event.raw` and could not have worked.
160
+ - `verified_name` and `known_names` are described as consumer-supplied: match
161
+ them against the record you found by your own key, never use them to find one.
162
+
163
+ ### Added: LOA version 2 and the name rule (24 Oct 2026)
164
+
165
+ - When a decrypted LOA carries `oneaddress_signature_v2`, the handler verifies
166
+ it (with the LOA key configured) and refuses the dispatch if it was signed for
167
+ another recipient, another update or another envelope, or if the envelope's
168
+ `verified_name` differs from the LOA's `consumer_name` after normalisation
169
+ (case, whitespace, accents). Codes `loa_v2_*`, shared by all five SDKs.
170
+ - The LOA signs up to three typed aliases in `consumer_typed_aliases`, apart from
171
+ the verified name, and the handler hands on those (re-checked) rather than the
172
+ envelope's `known_names`. An alias must share the verified first name, or
173
+ be a short form of it of at least three letters, so a married name passes and
174
+ a relative sharing only the surname does not. Dropped, never
175
+ refused. A v2 LOA without the list is `loa_v2_malformed`.
176
+ - New: `checkLoaV2`, `hasLoaV2`, `acceptTypedAliases`, `isAcceptableAlias`, `typedAliasesOf`, `normaliseLoaName` and the
177
+ canonical-form and envelope-digest helpers, tested against the shared
178
+ `loa_v2` vectors in `packages/protocol/src/test-vectors.json`.
179
+ - An LOA without v2 fields behaves exactly as before.
180
+ - `buildSignedTestWebhook` now seals a v2 LOA by default; pass `loa: { oneaddress_signature_v2: undefined }` for a v1-only one.
181
+
10
182
  ## [2.7.0] - 2026-10-23
11
183
 
12
184
  ### 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
 
@@ -271,7 +329,7 @@ Under D5 your `partner_keys` registry holds your **active** key plus zero-or-mor
271
329
 
272
330
  **Your contractual obligations:**
273
331
 
274
- 1. **Retain** the private key for any `key_id` whose paired public key has a `destroy_after` date in the future. You may destroy the private key on or after `destroy_after` — the corresponding session ciphertext on OneAddress's side has been purged by then.
332
+ 1. **Retain** the private key for any `key_id` whose paired public key has a `destroy_after` date in the future. You may destroy the private key on or after `destroy_after` — the corresponding session ciphertext on OneAddress's side has been purged by then. A retired key's `destroy_after` can move LATER, never earlier: a consumer can schedule an update up to three months ahead, sealed to the key that was live when they booked it, and the date moves out to cover it plus your retention window. We email your contacts when it moves, and the partner portal always shows the current date. Check that date, not one you were given earlier, before you destroy a key.
275
333
  2. **Retain** the `session_key_share` object alongside the update record until `key_share_expiry`, and **you may destroy it on or after that date**. OneAddress will not request reconstruction beyond it. The date on the dispatch you received is the one that binds you; it is not extended later. Treat a reconstruction request as something that may or may not still be possible by then, never as something the date guarantees.
276
334
  3. **Cooperate** in good faith with OneAddress reconstruction requests for in-window envelopes citing a legitimate `reason_code` — by decrypting the relevant share and returning SK<sub>n</sub> over the mutually-authenticated reconstruction channel.
277
335
 
@@ -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,25 +800,46 @@ 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';
721
-
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;
803
+ import type { SessionData } from '@oneaddress/partner-sdk';
728
804
 
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
  ---
738
824
 
825
+ ## Scheduled moves and `effective_date`
826
+
827
+ A customer can book an update for a future move date. OneAddress sends it to you early enough for the notice period you set on the portal's Notice card (in business days), so it can arrive before the customer moves. Every scheduled-move dispatch carries the move date as `effective_date` (`YYYY-MM-DD`):
828
+
829
+ ```ts
830
+ onUpdate: async (event) => {
831
+ // Apply from the move date, not from receipt. Absent means "now".
832
+ const effectiveFrom = event.effective_date ?? today();
833
+ await accounts.scheduleAddressChange(event.customer, event.address, effectiveFrom);
834
+ },
835
+ ```
836
+
837
+ If you start charging from the date you receive an address, use `effective_date` instead, or the customer is billed at the new address before they live there. An immediate update carries no `effective_date`.
838
+
839
+ The customer's device also seals the move date inside the envelope. The handler compares the two after decrypting and refuses the dispatch (500) when they differ or only one is present, so the date you are handed is the one the customer authorised. A body whose `effective_date` is not a real `YYYY-MM-DD` date is refused with 400 `invalid_effective_date` before anything is decrypted.
840
+
841
+ Rehearse it with `buildSignedTestWebhook({ ..., effectiveDate: '2026-12-07' })`, which puts the date in the body and seals it in the session.
842
+
739
843
  ## Secret rotation grace window
740
844
 
741
845
  **Rotate with an overlap.** Staging a new secret in the Partner Portal does **not** change what we sign with: we keep using your current secret until you press *Switch over*. So the safe sequence is stage, deploy the new secret alongside the current one, verify with both, then switch. At every point the secret we sign with is one your receiver already holds.
@@ -819,7 +923,19 @@ If you handle `address.verify` **without** the SDK handler, call `sendVerifyResu
819
923
  yourself after verifying the HMAC signature and decrypting the address:
820
924
 
821
925
  ```typescript
822
- import { sendVerifyResult, compareAddresses, decryptAddress } from '@oneaddress/partner-sdk';
926
+ import {
927
+ sendVerifyResult, compareAddresses, decryptAddress, isFreshTimestamp, verifySignature,
928
+ } from '@oneaddress/partner-sdk';
929
+
930
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
931
+ // have not verified trusts whoever sent it.
932
+ const rawBody = await req.text();
933
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
934
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
935
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
936
+ return new Response('invalid signature', { status: 401 });
937
+ }
938
+ const body = JSON.parse(rawBody);
823
939
 
824
940
  const address = await decryptAddress(body.address_encrypted, privateKeyPem, partnerId);
825
941
  const match = compareAddresses(await db.getStoredAddress(body), address);
@@ -1018,19 +1134,32 @@ Decrypts the `address_encrypted` blob using your PKCS#8 ECDH P-256 private key.
1018
1134
 
1019
1135
  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
1136
 
1021
- ```typescript
1022
- import { transformAddress } from '@oneaddress/partner-sdk';
1137
+ Call it from your own route, on the raw webhook body, not from inside
1138
+ `onUpdate`: by then the handler has decrypted the payload and `event.raw` is
1139
+ the plaintext, not the ciphertext.
1023
1140
 
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);
1141
+ ```typescript
1142
+ import { transformAddress, isFreshTimestamp, verifySignature, type EncryptedPayload } from '@oneaddress/partner-sdk';
1143
+
1144
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
1145
+ // have not verified trusts whoever sent it.
1146
+ const rawBody = await req.text();
1147
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
1148
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
1149
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
1150
+ return new Response('invalid signature', { status: 401 });
1033
1151
  }
1152
+ const body = JSON.parse(rawBody);
1153
+
1154
+ // Re-encrypt to your KMS key. The plaintext never leaves this function.
1155
+ const kmsBlob = await transformAddress(
1156
+ body.address_encrypted as EncryptedPayload,
1157
+ process.env.OA_PRIVATE_KEY_PEM!,
1158
+ body.partner_id,
1159
+ process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1160
+ );
1161
+ // Filed by dispatch: the account is only knowable once your KMS decrypts it.
1162
+ await db.storeEncryptedAddress(body.dispatch_id, kmsBlob);
1034
1163
  ```
1035
1164
 
1036
1165
  Each call generates a fresh ephemeral key pair and random HKDF salt — full forward secrecy, no shared state between calls.
@@ -1041,25 +1170,37 @@ The **D5 session-envelope** counterpart to `transformAddress`. Decrypts a `sessi
1041
1170
 
1042
1171
  Use this for the current dispatch path (session envelopes); use `transformAddress` for the legacy single-blob `address_encrypted` path.
1043
1172
 
1044
- ```typescript
1045
- import { transformSession } from '@oneaddress/partner-sdk';
1173
+ Call it from your own route, on the raw webhook body. Inside `onUpdate`
1174
+ `event.raw` is the already-decrypted `SessionData`, which carries no
1175
+ `session_key_share` or `session_envelope` to transform.
1046
1176
 
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);
1177
+ ```typescript
1178
+ import { transformSession, isFreshTimestamp, verifySignature } from '@oneaddress/partner-sdk';
1179
+
1180
+ // Freshness and signature FIRST, over the raw bytes. Decrypting a body you
1181
+ // have not verified trusts whoever sent it.
1182
+ const rawBody = await req.text();
1183
+ const ts = req.headers.get('x-oneaddress-timestamp') ?? '';
1184
+ const sig = req.headers.get('x-oneaddress-signature') ?? '';
1185
+ if (!isFreshTimestamp(ts) || !verifySignature(rawBody, sig, ts, process.env.OA_WEBHOOK_SECRET!)) {
1186
+ return new Response('invalid signature', { status: 401 });
1062
1187
  }
1188
+ const body = JSON.parse(rawBody);
1189
+
1190
+ const myPrivateKey = keyStore.get(body.session_key_share.key_id);
1191
+
1192
+ // Re-encrypt to your KMS key. The address never leaves this function in plaintext.
1193
+ const kmsBlob = await transformSession(
1194
+ body.session_key_share,
1195
+ body.session_envelope,
1196
+ myPrivateKey,
1197
+ body.partner_id,
1198
+ process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
1199
+ );
1200
+ // The raw body carries no cleartext customer block under D5, so file the blob
1201
+ // by dispatch, never by body.customer; the account is only knowable once your
1202
+ // KMS decrypts it.
1203
+ await db.storeEncryptedAddress(body.dispatch_id, kmsBlob);
1063
1204
  ```
1064
1205
 
1065
1206
  > **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 +1227,7 @@ Five identifiers arrive with a dispatch and they are easy to confuse. None of th
1086
1227
  |---|---|---|---|
1087
1228
  | `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
1229
  | `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. |
1230
+ | `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
1231
  | `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
1232
  | `verification_id` | Body, `address.test` only | The connection-verification run a test record belongs to. | Counting the five test records. |
1092
1233