@oneaddress/partner-sdk 1.8.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +191 -2
- package/LICENSE +201 -0
- package/README.md +349 -18
- package/dist/{chunk-O2D5XGSN.mjs → chunk-LIHXDUUA.mjs} +441 -14
- package/dist/{chunk-PUB6ZVJ2.mjs → chunk-P55E2BQT.mjs} +503 -64
- package/dist/edge.d.mts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +835 -62
- package/dist/edge.mjs +2 -2
- package/dist/index.d.mts +487 -41
- package/dist/index.d.ts +487 -41
- package/dist/index.js +966 -76
- package/dist/index.mjs +6 -2
- package/dist/{src-UOJOUUGB.mjs → src-ENJJ6YZU.mjs} +29 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -31,6 +31,11 @@ export const handler = createOneAddressHandler({
|
|
|
31
31
|
webhookSecret: process.env.OA_WEBHOOK_SECRET!,
|
|
32
32
|
privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
33
33
|
|
|
34
|
+
// Which kinds of changed detail THIS CODE can handle. Address only is the
|
|
35
|
+
// default. Declare phone or email only once onUpdate stores them; see
|
|
36
|
+
// "Phone and email updates" below.
|
|
37
|
+
acceptedUpdateTypes: ['address'],
|
|
38
|
+
|
|
34
39
|
async onUpdate(event) {
|
|
35
40
|
// event.address is already decrypted. event.customer.email is always ''
|
|
36
41
|
// on this event (OneAddress never learns a consumer's email for a
|
|
@@ -47,9 +52,21 @@ export const handler = createOneAddressHandler({
|
|
|
47
52
|
const providedNames = [customer.name, ...customer.known_names];
|
|
48
53
|
const record = await db.findByAccountNumber(customer.account_number);
|
|
49
54
|
if (!record || !namePoolMatches(providedNames, record.fullName)) {
|
|
50
|
-
|
|
55
|
+
// Not a customer of yours: say so. Throwing here would be reported as
|
|
56
|
+
// YOUR system failing, which OneAddress retries and, after enough of
|
|
57
|
+
// them, refunds the consumer at your expense. See "Confirming back".
|
|
58
|
+
return { status: 'no_match' };
|
|
51
59
|
}
|
|
52
60
|
await db.updateAddress({ id: record.id, ...event.address });
|
|
61
|
+
return { status: 'confirmed' };
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// The return value above reaches OneAddress ONLY because this is set: it
|
|
65
|
+
// makes the handler call confirmUpdate for you after onUpdate returns.
|
|
66
|
+
// Without it the status goes into the HTTP response body and no further.
|
|
67
|
+
confirm: {
|
|
68
|
+
partnerId: process.env.OA_PARTNER_ID!,
|
|
69
|
+
confirmSecret: process.env.OA_CONFIRM_SECRET!,
|
|
53
70
|
},
|
|
54
71
|
// Connection-verification test records. OneAddress sends five of these
|
|
55
72
|
// before you go live: real signed, encrypted dispatches carrying FABRICATED
|
|
@@ -96,9 +113,78 @@ export { handler as POST };
|
|
|
96
113
|
|
|
97
114
|
---
|
|
98
115
|
|
|
116
|
+
## Phone and email updates
|
|
117
|
+
|
|
118
|
+
*Available from 2.0.0.*
|
|
119
|
+
|
|
120
|
+
A OneAddress dispatch can carry a new **postal address**, a new **telephone
|
|
121
|
+
number** or a new **email address**, alone or together. Two things decide what
|
|
122
|
+
you receive:
|
|
123
|
+
|
|
124
|
+
1. **Consent**, ticked by a person in the partner portal (`accepted_update_types`).
|
|
125
|
+
2. **Capability**, declared by this code with `acceptedUpdateTypes`.
|
|
126
|
+
|
|
127
|
+
A kind is dispatched to you only where BOTH hold, and the conformance run is
|
|
128
|
+
what ties them together: it reads your declaration off your first
|
|
129
|
+
acknowledgement, sends a real contact-only envelope for every kind you declared,
|
|
130
|
+
sends one kind you did NOT declare and requires you to refuse it, and fails the
|
|
131
|
+
run if the portal promises a kind this code has not declared.
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
export const handler = createOneAddressHandler({
|
|
135
|
+
webhookSecret: process.env.OA_WEBHOOK_SECRET!,
|
|
136
|
+
privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
137
|
+
acceptedUpdateTypes: ['address', 'phone', 'email'],
|
|
138
|
+
|
|
139
|
+
async onUpdate(event) {
|
|
140
|
+
const account = event.customer?.account_number;
|
|
141
|
+
if (!account) throw new Error('Dispatch carried no account number to match on');
|
|
142
|
+
|
|
143
|
+
// `update_types` says what is inside; read it rather than probing fields.
|
|
144
|
+
// A phone-only change arrives as ['phone'] with NO address at all.
|
|
145
|
+
if (event.address) await db.updateAddress(account, event.address);
|
|
146
|
+
if (event.new_phone) await db.updatePhone(account, event.new_phone); // E.164
|
|
147
|
+
if (event.new_email) await db.updateEmail(account, event.new_email); // lowercased
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
What the handler guarantees:
|
|
153
|
+
|
|
154
|
+
| Situation | Response | `onUpdate` |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| Every kind in the envelope is declared | `200 { ok: true, accepted_update_types }` | runs |
|
|
157
|
+
| A kind you did not declare | `422 update_type_not_accepted` | never runs |
|
|
158
|
+
| A kind name this SDK build does not know | `422 invalid_update_types` | never runs |
|
|
159
|
+
| `contact.updated` without a session envelope | `400 missing_session_envelope` | never runs |
|
|
160
|
+
|
|
161
|
+
- **`address.updated` vs `contact.updated`.** A dispatch carrying an address is
|
|
162
|
+
`address.updated` exactly as before, whether or not a contact detail rides
|
|
163
|
+
beside it. One carrying no address is `contact.updated`. Both reach the same
|
|
164
|
+
`onUpdate`; route on `update_types`, not on the event name.
|
|
165
|
+
- **`event.address` is optional now.** Every dispatch that existed before
|
|
166
|
+
September 2026 has one, and if you declare nothing you will never see the
|
|
167
|
+
absent case, but TypeScript will ask you to narrow: bind it to a local and
|
|
168
|
+
check it, or test it with `if` as the example does.
|
|
169
|
+
- **`update_types` is literal.** `['phone']` means the phone number changed and
|
|
170
|
+
nothing else. It is never widened to include `address`.
|
|
171
|
+
- **Refusal is deliberate.** Acknowledging a kind you cannot store would look
|
|
172
|
+
identical to success on both sides while the consumer has already paid. The
|
|
173
|
+
422 leaves the dispatch incomplete in your idempotency store, so once you
|
|
174
|
+
widen `acceptedUpdateTypes` OneAddress's retry is processed rather than
|
|
175
|
+
dismissed as a duplicate.
|
|
176
|
+
- **`accepted_update_types` rides every authenticated 2xx.** It is how the
|
|
177
|
+
conformance run discovers what you declared. It is never included in a 401,
|
|
178
|
+
so an unsigned caller learns nothing about your receiver.
|
|
179
|
+
- **Declare a kind only once you store it.** The conformance run can prove your
|
|
180
|
+
code ACCEPTED a phone-only envelope. It cannot see whether your outbox has a
|
|
181
|
+
column for the number.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
99
185
|
## D5 — session-envelope decryption (added in v1.3.0)
|
|
100
186
|
|
|
101
|
-
|
|
187
|
+
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:
|
|
102
188
|
|
|
103
189
|
- 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>.
|
|
104
190
|
- 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`.
|
|
@@ -153,6 +239,18 @@ await confirmUpdate({
|
|
|
153
239
|
|
|
154
240
|
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).
|
|
155
241
|
|
|
242
|
+
### LOA verification: present AND verified AND bound
|
|
243
|
+
|
|
244
|
+
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:
|
|
245
|
+
|
|
246
|
+
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.
|
|
247
|
+
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).
|
|
248
|
+
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.
|
|
249
|
+
|
|
250
|
+
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.
|
|
251
|
+
|
|
252
|
+
`requireLoa: true` without `loaPublicKeyPem` enforces presence and binding only; verification needs the key.
|
|
253
|
+
|
|
156
254
|
> **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.
|
|
157
255
|
|
|
158
256
|
### Key versioning + retention obligations
|
|
@@ -264,6 +362,25 @@ naming conventions, verify this assumption holds before relying on it.
|
|
|
264
362
|
|
|
265
363
|
**Receiving a dispatch is only half the protocol.** Until you call back, the consumer's dashboard shows your business stuck on "dispatched" indefinitely — no matter how correctly you applied the change.
|
|
266
364
|
|
|
365
|
+
**`onUpdate`'s return value does NOT reach OneAddress on its own.** It is spread into the 200 response body, and OneAddress reads nothing from that body. Until 2.1.0 this README said the return value was "for the confirmation callback"; a receiver that believed it returned `{ status: 'confirmed' }` and left the consumer waiting forever. There are two ways to close the loop:
|
|
366
|
+
|
|
367
|
+
**Either** pass `confirm` to the handler and it calls `confirmUpdate` for you after `onUpdate` returns, with the `status` you returned (`confirmed` when omitted) and `event.loa_ref`. Fire-and-forget: a failed confirm is logged and never fails the delivery. A THROWING `onUpdate` confirms nothing, correctly, because the 500 makes OneAddress retry.
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
createOneAddressHandler({
|
|
371
|
+
webhookSecret, privateKeyPem,
|
|
372
|
+
confirm: { partnerId: process.env.OA_PARTNER_ID!, confirmSecret: process.env.OA_CONFIRM_SECRET! },
|
|
373
|
+
async onUpdate(event) {
|
|
374
|
+
const record = await db.findByAccountNumber(event.customer?.account_number);
|
|
375
|
+
if (!record) return { status: 'no_match' };
|
|
376
|
+
await db.updateAddress({ id: record.id, ...event.address });
|
|
377
|
+
return { status: 'confirmed' };
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**Or** call `confirmUpdate` yourself, from wherever the write actually completes (an outbox worker, a batch job):
|
|
383
|
+
|
|
267
384
|
```typescript
|
|
268
385
|
import { confirmUpdate } from '@oneaddress/partner-sdk';
|
|
269
386
|
|
|
@@ -272,19 +389,22 @@ const res = await confirmUpdate({
|
|
|
272
389
|
secret: process.env.OA_CONFIRM_SECRET!, // see "which secret" below
|
|
273
390
|
dispatchId: event.dispatchId, // from X-OneAddress-Dispatch
|
|
274
391
|
status: 'confirmed',
|
|
275
|
-
note: '
|
|
392
|
+
note: 'Applied to CRM record', // never the address itself
|
|
276
393
|
});
|
|
277
394
|
|
|
278
395
|
if (!res.ok) console.error('[oneaddress] confirm failed', res.status, res.error);
|
|
279
396
|
```
|
|
280
397
|
|
|
281
|
-
### The
|
|
398
|
+
### The four statuses mean different things
|
|
282
399
|
|
|
283
400
|
| Status | Meaning |
|
|
284
401
|
| --- | --- |
|
|
285
402
|
| `confirmed` | You applied the change. |
|
|
286
403
|
| `already_current` | You already held that address; nothing to write. **Not a failure** — return it honestly rather than reporting `confirmed`. |
|
|
287
|
-
| `failed` |
|
|
404
|
+
| `failed` | Your system could not apply it. OneAddress retries, and a run of these makes the update our fault and refunds the consumer. Send a `note` saying why (what happened, never the address). |
|
|
405
|
+
| `no_match` | You looked, and this person is not a customer of yours. Nothing is broken and retrying cannot help, so the consumer is told to check their account reference with you. No refund is triggered. |
|
|
406
|
+
|
|
407
|
+
The last two cost different people money. `failed` for a stranger bills a refund against a receiver that behaved correctly; `no_match` during a real outage tells a genuine customer to fix an account number that was never wrong. **If you cannot tell the two apart, send `failed`**, which is the one that is safe to be wrong about.
|
|
288
408
|
|
|
289
409
|
### Which secret
|
|
290
410
|
|
|
@@ -304,9 +424,36 @@ It also refuses a missing or non-numeric `dispatchId` **before** sending, becaus
|
|
|
304
424
|
|
|
305
425
|
---
|
|
306
426
|
|
|
427
|
+
## Delivery contract
|
|
428
|
+
|
|
429
|
+
What OneAddress does on its side of the wire, so you can size timeouts, retention and error handling against the real numbers rather than guesses. The figures are read from the dispatcher's own source.
|
|
430
|
+
|
|
431
|
+
| Fact | Value |
|
|
432
|
+
|---|---|
|
|
433
|
+
| Timeout per delivery attempt | **10 seconds**, on our side. Answer inside it; do slow work after the 200 (an outbox is the usual shape). |
|
|
434
|
+
| Retries | Up to **28 attempts over 48 hours**, whichever comes first. Backoff 30s, 2m, 8m, 32m, then every 2 hours. After that the dispatch is marked exhausted and stops; recovering it is a support request. |
|
|
435
|
+
| Duplicates | Retries can overlap with a slow response, so the same `dispatchId` can arrive more than once. **Keep your dedup record for at least 48 hours**, or a late retry re-applies an update you already processed. |
|
|
436
|
+
| `ok: false` in a 2xx body | Counts as a **failure** and is retried. The HTTP status says "received"; a body that says `ok: false` overrides it. The handler never does this by itself. |
|
|
437
|
+
| A redirect | Treated as an error. A 301/302 on a POST drops the body, so a redirecting webhook URL is a misconfiguration. |
|
|
438
|
+
|
|
439
|
+
What each response status means to us:
|
|
440
|
+
|
|
441
|
+
| You answer | We record | We do |
|
|
442
|
+
|---|---|---|
|
|
443
|
+
| `2xx` (and no `ok: false`) | delivered, awaiting your confirm | Wait for `confirmUpdate`. |
|
|
444
|
+
| `400` | auth failed | Retry on the backoff. A malformed request cannot be fixed by retrying, but the class of problem (a stale timestamp, a body that is not JSON) usually clears on the next attempt. |
|
|
445
|
+
| `401` | auth failed, our signature rejected | Retry. A run of these across partners is an alert on OUR side (a broken signing deploy or an unsynced secret). |
|
|
446
|
+
| `422` | auth failed (client-side refusal) | Retry. The handler sends this for a kind you have not declared in `acceptedUpdateTypes`; once you widen the declaration the retry is processed. |
|
|
447
|
+
| `500` | partner error | Retry. This is what the handler answers for a decrypt failure, a missing or invalid consent proof, or a throwing `onUpdate`, and it is the right answer for anything you want retried. |
|
|
448
|
+
| no response / timeout | unreachable | Retry. |
|
|
449
|
+
|
|
450
|
+
Every 4xx is filed under the same "auth failed" state on the consumer's dashboard, so a 4xx you send deliberately reads, to the consumer, as a problem between you and OneAddress. Prefer a 500 for "try again" and a confirm of `no_match` for "not my customer".
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
307
454
|
## Idempotency — handling retries
|
|
308
455
|
|
|
309
|
-
If your handler takes longer than
|
|
456
|
+
If your handler takes longer than 10 seconds OneAddress will time out and retry the webhook. Your `onUpdate` can be called more than once for the same address change. Use `event.dispatchId` (from the `X-OneAddress-Dispatch` header) as an idempotency key:
|
|
310
457
|
|
|
311
458
|
```typescript
|
|
312
459
|
async onUpdate(event) {
|
|
@@ -341,6 +488,7 @@ CREATE TABLE oneaddress_dispatches (
|
|
|
341
488
|
dispatch_id TEXT PRIMARY KEY,
|
|
342
489
|
received_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
343
490
|
completed_at TIMESTAMP
|
|
491
|
+
-- MySQL and SQL Server only: add claim_token VARCHAR(64) NULL
|
|
344
492
|
);
|
|
345
493
|
```
|
|
346
494
|
|
|
@@ -352,7 +500,9 @@ export const handler = createOneAddressHandler({
|
|
|
352
500
|
privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
353
501
|
|
|
354
502
|
idempotencyStore: createSqlIdempotencyStore({
|
|
355
|
-
// Postgres (node-postgres).
|
|
503
|
+
// Postgres (node-postgres). Pass `dialect: 'mysql' | 'sqlite' | 'mssql'`
|
|
504
|
+
// for the others: the placeholder AND the claim statement differ, since
|
|
505
|
+
// only Postgres and SQLite have `ON CONFLICT ... DO NOTHING RETURNING`.
|
|
356
506
|
query: (sql, params) => pool.query(sql, params).then((r) => r.rows),
|
|
357
507
|
}),
|
|
358
508
|
|
|
@@ -367,6 +517,17 @@ cannot be made correct under concurrency: `has` and `set` are separate round-tri
|
|
|
367
517
|
retries arriving at once both observe "not seen" and both apply the update. `claim` is a single
|
|
368
518
|
atomic `INSERT … ON CONFLICT DO NOTHING` and has no such window.
|
|
369
519
|
|
|
520
|
+
**Per dialect.** Postgres and SQLite use that statement as written. MySQL uses `INSERT IGNORE`
|
|
521
|
+
and SQL Server `INSERT ... WHERE NOT EXISTS`, each carrying a per-call token in `claim_token`
|
|
522
|
+
and reading the row back to see whose token landed, which is what makes the claim atomic without
|
|
523
|
+
`RETURNING`. On SQL Server the loser of a genuine race gets a primary-key error rather than an
|
|
524
|
+
empty insert; the handler answers 500, OneAddress retries, and the retry reads the winner's row.
|
|
525
|
+
A dialect the store has no SQL for is refused at construction with the supported list.
|
|
526
|
+
|
|
527
|
+
**Not wiring a store at all.** In test mode (`NODE_ENV=test`) the handler throws on the first
|
|
528
|
+
dispatch that carries `X-OneAddress-Dispatch`, so the omission is caught in development.
|
|
529
|
+
Everywhere else it processes the dispatch and logs once per process, naming this function.
|
|
530
|
+
|
|
370
531
|
It also distinguishes three states rather than two, and the third is the one that matters:
|
|
371
532
|
|
|
372
533
|
| Claim | Meaning | Handler does |
|
|
@@ -437,6 +598,11 @@ running, the row can be claimed twice — and no timeout is long enough to make
|
|
|
437
598
|
impossible. Set `leaseSeconds` comfortably longer than your slowest handler, and make the
|
|
438
599
|
write itself safe to repeat.
|
|
439
600
|
|
|
601
|
+
A release is scoped to the claim this consumer holds: `markProcessed`, `markFailed` and
|
|
602
|
+
`release` match on the claim token as well as the id, so a slow consumer's late write after
|
|
603
|
+
its lease expired and another consumer re-claimed the row touches nothing. Until 2.1.0 it
|
|
604
|
+
cleared the other consumer's claim.
|
|
605
|
+
|
|
440
606
|
### Failure, and why nothing is given up on by default
|
|
441
607
|
|
|
442
608
|
A handler that throws does not stop the batch: the row records its reason in
|
|
@@ -471,9 +637,9 @@ something.
|
|
|
471
637
|
| `query` | — | Runs parameterised SQL, returns rows. Your pool, your driver. |
|
|
472
638
|
| `dialect` | `postgres` | `postgres` \| `mysql` \| `sqlite` \| `mssql` |
|
|
473
639
|
| `table` | `oneaddress_updates` | What the receiver writes to |
|
|
474
|
-
| `batchSize` | `50` | Rows per claim |
|
|
640
|
+
| `batchSize` | `50` | Rows per claim. Positive integer; it is inlined into the statement, so it is validated. |
|
|
475
641
|
| `leaseSeconds` | `300` | How long a claim is held |
|
|
476
|
-
| `maxAttempts` | `0` | `0` = never give up |
|
|
642
|
+
| `maxAttempts` | `0` | `0` = never give up. Integer, zero or more; inlined and validated like `batchSize`. |
|
|
477
643
|
|
|
478
644
|
---
|
|
479
645
|
|
|
@@ -501,7 +667,7 @@ async onUpdate(event) {
|
|
|
501
667
|
| `verified` | Always `true` when the block is present. |
|
|
502
668
|
| `platform` | Format tag — currently `oneaddress/v1`. |
|
|
503
669
|
|
|
504
|
-
The block is absent on
|
|
670
|
+
The block is absent on sandbox dispatches, where no identity-verification credit was consumed. Production dispatches always include it.
|
|
505
671
|
|
|
506
672
|
### The verification reference lives inside the encrypted envelope
|
|
507
673
|
|
|
@@ -628,6 +794,20 @@ await sendVerifyResult({
|
|
|
628
794
|
(OneAddress skips the dispatch) and `match: false → 'mismatch' + address_match false`
|
|
629
795
|
(the update proceeds). It throws if the callback POST returns a non-2xx status.
|
|
630
796
|
|
|
797
|
+
### The callback host is pinned
|
|
798
|
+
|
|
799
|
+
`callback_url` arrives on the wire, so it is only as trustworthy as the webhook
|
|
800
|
+
secret. The SDK has always refused SSRF targets (loopback, private ranges, cloud
|
|
801
|
+
metadata) but would POST to any public host, which meant a leaked secret let an
|
|
802
|
+
attacker forge an `address.verify` and have your server send the callback token,
|
|
803
|
+
batch id and match result wherever they liked. `sendVerifyResult` now posts only
|
|
804
|
+
to `https://oneaddress.io` or a subdomain of it, and near-miss hostnames
|
|
805
|
+
(`notoneaddress.io`, `evil-oneaddress.io`, `oneaddress.io.evil.com`) are
|
|
806
|
+
refused. For a staging or self-hosted relay, name the extra host in
|
|
807
|
+
`OA_CALLBACK_HOST_ALLOWLIST` (comma-separated) or pass `allowedCallbackHosts` to
|
|
808
|
+
`sendVerifyResult` or `createOneAddressHandler`. Every host you add is a host a
|
|
809
|
+
forged request could reach, so keep it empty in production.
|
|
810
|
+
|
|
631
811
|
---
|
|
632
812
|
|
|
633
813
|
## Account verification (pre-payment, guest flow)
|
|
@@ -670,11 +850,13 @@ The three statuses surface to the consumer as:
|
|
|
670
850
|
| Returned | Consumer sees |
|
|
671
851
|
|----------|--------------|
|
|
672
852
|
| `{ status: 'match' }` | ✓ Account found |
|
|
673
|
-
| `{ status: 'no_match' }` |
|
|
853
|
+
| `{ status: 'no_match' }` | Couldn't verify — check your account number (editable, retriable) |
|
|
674
854
|
| `{ status: 'no_account' }` | ✗ No account found (editable, retriable) |
|
|
675
855
|
|
|
676
856
|
Any other 2xx response — including the default behaviour when you don't supply `onAccountVerify` at all — surfaces as "—" (skipped). The consumer can still pay and dispatch.
|
|
677
857
|
|
|
858
|
+
**`onAccountVerify` is never called unless `verifiesAccountReference` is declared on your portal profile**: the relay does not send `account.verify` to a partner that has not said it supports the check, so implementing the callback without ticking the box does nothing.
|
|
859
|
+
|
|
678
860
|
Failure mode: `no_match` and `no_account` are **informational only**. The consumer is told and may correct their input, but the wizard does not block them from paying. After payment your usual `onUpdate` handler still fires — apply the same matching rules you would for an account-flow update.
|
|
679
861
|
|
|
680
862
|
---
|
|
@@ -685,7 +867,13 @@ Failure mode: `no_match` and `no_account` are **informational only**. The consum
|
|
|
685
867
|
import { createOneAddressHandler } from '@oneaddress/partner-sdk/edge';
|
|
686
868
|
```
|
|
687
869
|
|
|
688
|
-
|
|
870
|
+
The `/edge` entry is a **subset** of the main entry, and it is not free of Node.js APIs. Until 2.1.0 this section said "all exports, no Node.js-specific APIs", and neither half was true.
|
|
871
|
+
|
|
872
|
+
**What `/edge` exports:** `verifySignature`, `verifyWithGrace`, `decryptAddress`, `decryptSession`, `transformAddress`, `transformSession`, `validateAddress`, `verifyLOA`, `fetchLoaPublicKey`, `decryptLoaEncrypted`, `verifyD5LOA`, `d5LoaRef`, `canonicalD5LoaForm`, `createOneAddressHandler`, `isFreshTimestamp`, `DEFAULT_REPLAY_WINDOW_SECS`, `computeBlindIndex`, `normalizeForBlindIndex`, `CURRENT_VERSION`, `SUPPORTED_VERSIONS`, `namePoolMatches`, `findMatchingStoredName`, `isEmailLike`, `compareAddresses`, `sendVerifyResult`, plus the event, option and session types.
|
|
873
|
+
|
|
874
|
+
**Not on `/edge`:** `confirmUpdate`, `createSqlIdempotencyStore`, `createOutboxConsumer`, `toExpressHandler`, `readAddressParts`, `formatAddressParts`, `buildSignedTestWebhook`. Import those from the main entry.
|
|
875
|
+
|
|
876
|
+
**Node APIs.** The handler signs and verifies with `node:crypto` (`createHmac`, `timingSafeEqual`, `createPrivateKey` at construction) and decodes keys with `Buffer`. On **Cloudflare Workers** set `compatibility_flags = ["nodejs_compat"]` in `wrangler.toml`; without it the import fails at deploy. Next.js Edge Runtime and Deno provide these already. `decryptSession`, `decryptAddress` and the LOA verification use Web Crypto and run anywhere.
|
|
689
877
|
|
|
690
878
|
---
|
|
691
879
|
|
|
@@ -700,7 +888,7 @@ import {
|
|
|
700
888
|
transformAddress, // decrypt legacy blob then re-encrypt to a different public key (e.g. KMS)
|
|
701
889
|
transformSession, // decrypt D5 session then re-encrypt to a different public key (e.g. KMS)
|
|
702
890
|
readAddressParts, // tolerant address field reader (street/line1/address_line1/…)
|
|
703
|
-
formatAddressParts, // one-line summary
|
|
891
|
+
formatAddressParts, // one-line summary for a screen a person is entitled to see; NOT logs, NOT notes
|
|
704
892
|
isFreshTimestamp, // ±5-minute replay-window check
|
|
705
893
|
CURRENT_VERSION, // '2026.1'
|
|
706
894
|
SUPPORTED_VERSIONS, // ['2026.1']
|
|
@@ -722,9 +910,11 @@ await db.updateAddress({
|
|
|
722
910
|
suburb: parts.suburb || row.suburb,
|
|
723
911
|
postcode: parts.postcode || row.postcode,
|
|
724
912
|
});
|
|
725
|
-
|
|
913
|
+
reviewScreen.show(formatAddressParts(parts)); // "42 Collins Street, Melbourne, VIC, 3000"
|
|
726
914
|
```
|
|
727
915
|
|
|
916
|
+
`formatAddressParts` renders the decrypted address in the clear, so it belongs on a screen a person is entitled to see and nowhere else. Not in a log line (a plaintext copy at rest that outlives every retention rule you set for the record) and not in a confirm `note` (sent back to OneAddress). This README used to say "for logs + notes"; the reference receiver did exactly that.
|
|
917
|
+
|
|
728
918
|
This is a **tolerant reader**, not a schema declaration: it describes what the helper accepts and
|
|
729
919
|
says nothing about what OneAddress guarantees to send. Use it instead of hand-rolling the
|
|
730
920
|
`?? ?? ??` ladder — we did that in three receivers and a fix to one silently left the others
|
|
@@ -794,6 +984,130 @@ async onUpdate(event) {
|
|
|
794
984
|
|
|
795
985
|
---
|
|
796
986
|
|
|
987
|
+
## Never do
|
|
988
|
+
|
|
989
|
+
The address is encrypted to you and to nobody else. Four ways to undo that, each seen in a real integration:
|
|
990
|
+
|
|
991
|
+
- **Never log the plaintext address**, at any level, in any format. A log line is a copy at rest with no retention policy and a wider audience than your database.
|
|
992
|
+
- **Never persist the plaintext address anywhere but the record it belongs to.** Not a debug table, not a queue payload, not a crash dump. `transformSession` exists so an outbox can hold it re-encrypted to your own key.
|
|
993
|
+
- **Never put the address in a confirm `note`.** The note travels back to OneAddress in the clear and is stored there. Say what happened, not what the address was.
|
|
994
|
+
- **Never route a test record to `onUpdate`.** `address.test` and `address.test-dispatch` carry fabricated identities and go to `onTest`; the handler keeps them apart, and so must anything you build beside it.
|
|
995
|
+
- **Never skip the idempotency store in production.** Retries are normal (28 over 48 hours); without a store each one applies the update again. The handler will tell you once, in the log, and then keep going.
|
|
996
|
+
|
|
997
|
+
---
|
|
998
|
+
|
|
999
|
+
## Which identifier is which
|
|
1000
|
+
|
|
1001
|
+
Five identifiers arrive with a dispatch and they are easy to confuse. None of them identifies the consumer.
|
|
1002
|
+
|
|
1003
|
+
| Identifier | Where | What it identifies | Use it for |
|
|
1004
|
+
|---|---|---|---|
|
|
1005
|
+
| `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. |
|
|
1006
|
+
| `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`. |
|
|
1007
|
+
| `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. |
|
|
1008
|
+
| `batch_id` | Body, `address.verify` only | The verification batch a verify request belongs to. | Echo it in `sendVerifyResult`; the handler does this for you. |
|
|
1009
|
+
| `verification_id` | Body, `address.test` only | The connection-verification run a test record belongs to. | Counting the five test records. |
|
|
1010
|
+
|
|
1011
|
+
`id_verification_ref` (inside the decrypted envelope) is a sixth: the immutable handle of the identity verification that authorised the dispatch, for quoting to OneAddress support. It is not an identifier of the dispatch.
|
|
1012
|
+
|
|
1013
|
+
---
|
|
1014
|
+
|
|
1015
|
+
## Generating and registering your key
|
|
1016
|
+
|
|
1017
|
+
The default scheme is ECDH P-256. Generate a pair, register the PUBLIC half, keep the private half in your secret store:
|
|
1018
|
+
|
|
1019
|
+
```bash
|
|
1020
|
+
openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out oa-private.pem
|
|
1021
|
+
openssl ec -in oa-private.pem -pubout -out oa-public.pem
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
Register `oa-public.pem` in the Partner Portal under **My Profile, Encryption Key** (the portal can also generate the pair for you and hand you the private key once). The portal shows the key's `key_id`; set it as `keyId` on the handler if you want rotation crossovers skipped cleanly. `oa-private.pem` is what `privateKeyPem` takes, as the file's contents or as one line with literal `\n` sequences. The same page is where an RSA or post-quantum public key is registered instead, and where `verifiesAccountReference` is declared.
|
|
1025
|
+
|
|
1026
|
+
---
|
|
1027
|
+
|
|
1028
|
+
## Recipes
|
|
1029
|
+
|
|
1030
|
+
### Fastify
|
|
1031
|
+
|
|
1032
|
+
Fastify parses JSON by default, which destroys the bytes the signature covers. Register a content-type parser that keeps the raw string for this route:
|
|
1033
|
+
|
|
1034
|
+
```typescript
|
|
1035
|
+
import Fastify from 'fastify';
|
|
1036
|
+
import { createOneAddressHandler, type HandlerRequest } from '@oneaddress/partner-sdk';
|
|
1037
|
+
|
|
1038
|
+
const app = Fastify();
|
|
1039
|
+
const handler = createOneAddressHandler({ /* ... */ });
|
|
1040
|
+
|
|
1041
|
+
app.addContentTypeParser('application/json', { parseAs: 'string' }, (_req, body, done) => done(null, body));
|
|
1042
|
+
|
|
1043
|
+
app.post('/webhook/oneaddress', async (req, reply) => {
|
|
1044
|
+
const fetchLike: HandlerRequest = {
|
|
1045
|
+
text: async () => req.body as string,
|
|
1046
|
+
headers: { get: (name) => {
|
|
1047
|
+
const v = req.headers[name.toLowerCase()];
|
|
1048
|
+
return v === undefined ? null : Array.isArray(v) ? v.join(', ') : v;
|
|
1049
|
+
} },
|
|
1050
|
+
};
|
|
1051
|
+
const res = await handler(fetchLike);
|
|
1052
|
+
reply.status(res.status);
|
|
1053
|
+
res.headers.forEach((value, key) => reply.header(key, value));
|
|
1054
|
+
return reply.send(await res.text());
|
|
1055
|
+
});
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
### AWS Lambda (API Gateway / Function URL)
|
|
1059
|
+
|
|
1060
|
+
API Gateway may base64-encode the body; decode it before it reaches the handler, and never re-serialise it.
|
|
1061
|
+
|
|
1062
|
+
```typescript
|
|
1063
|
+
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
1064
|
+
import { createOneAddressHandler } from '@oneaddress/partner-sdk';
|
|
1065
|
+
|
|
1066
|
+
const handler = createOneAddressHandler({ /* ... */ });
|
|
1067
|
+
|
|
1068
|
+
export async function main(apiEvent: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> {
|
|
1069
|
+
const raw = apiEvent.isBase64Encoded
|
|
1070
|
+
? Buffer.from(apiEvent.body ?? '', 'base64').toString('utf8')
|
|
1071
|
+
: (apiEvent.body ?? '');
|
|
1072
|
+
const res = await handler({
|
|
1073
|
+
text: async () => raw,
|
|
1074
|
+
headers: { get: (name) => apiEvent.headers[name.toLowerCase()] ?? null },
|
|
1075
|
+
});
|
|
1076
|
+
return { statusCode: res.status, headers: { 'content-type': 'application/json' }, body: await res.text() };
|
|
1077
|
+
}
|
|
1078
|
+
```
|
|
1079
|
+
|
|
1080
|
+
Do your slow work after the response (an SQS queue, an outbox table) so the 10-second delivery timeout is never in play, and keep the idempotency store in a real database: a Lambda's memory is per instance and per cold start.
|
|
1081
|
+
|
|
1082
|
+
### Testing your receiver without a network
|
|
1083
|
+
|
|
1084
|
+
```typescript
|
|
1085
|
+
import { generateKeyPairSync } from 'node:crypto';
|
|
1086
|
+
import { createOneAddressHandler, buildSignedTestWebhook } from '@oneaddress/partner-sdk';
|
|
1087
|
+
|
|
1088
|
+
const { publicKey, privateKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' });
|
|
1089
|
+
const handler = createOneAddressHandler({
|
|
1090
|
+
webhookSecret: 'test-secret',
|
|
1091
|
+
privateKeyPem: privateKey.export({ type: 'pkcs8', format: 'pem' }) as string,
|
|
1092
|
+
idempotencyStore: memoryStore,
|
|
1093
|
+
async onUpdate(event) { seen.push(event); },
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
const hook = await buildSignedTestWebhook({
|
|
1097
|
+
webhookSecret: 'test-secret',
|
|
1098
|
+
partnerId: '11111111-1111-1111-1111-111111111111',
|
|
1099
|
+
publicKey: publicKey.export({ type: 'spki', format: 'pem' }) as string,
|
|
1100
|
+
session: { account_number: 'ACME-42' },
|
|
1101
|
+
});
|
|
1102
|
+
const res = await handler(hook.request); // or handler(hook.toRequest())
|
|
1103
|
+
expect(res.status).toBe(200);
|
|
1104
|
+
expect(seen[0].customer?.account_number).toBe('ACME-42');
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
`buildSignedTestWebhook` produces the exact shape the relay sends, signed and encrypted, lifted from the conformance suite. Pass `loa: false` to test `requireLoa`, `loaSigningKeyPem` (an ECDSA P-256 key you generate) to test `loaPublicKeyPem` for real, `session: { update_types: ['phone'] }` for a contact-only envelope, and `extraBody` for `crossover_key_ids` or the test-record `index` / `total`.
|
|
1108
|
+
|
|
1109
|
+
---
|
|
1110
|
+
|
|
797
1111
|
## Protocol versioning
|
|
798
1112
|
|
|
799
1113
|
The SDK warns (but does not reject) if it receives a protocol version it doesn't recognise:
|
|
@@ -814,11 +1128,28 @@ This ensures you keep receiving events while updating your SDK. See `SUPPORTED_V
|
|
|
814
1128
|
**Full conformance suite** — run 10 checks against your endpoint using real crypto, no mocks:
|
|
815
1129
|
|
|
816
1130
|
```bash
|
|
817
|
-
# Against a live endpoint
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
#
|
|
1131
|
+
# Against a live endpoint: all three credentials, or none. A partial set is
|
|
1132
|
+
# REFUSED — it passes every signature check while the payload stays sealed to
|
|
1133
|
+
# the suite's built-in test key, so the failures land on the acceptance checks
|
|
1134
|
+
# and read as a decrypt fault in your own code.
|
|
1135
|
+
export ONEADDRESS_WEBHOOK_SECRET=whsec_...
|
|
1136
|
+
export ONEADDRESS_PARTNER_ID=...
|
|
1137
|
+
export ONEADDRESS_PUBLIC_KEY=...
|
|
1138
|
+
npx @oneaddress/conformance test https://your-endpoint.com/webhook
|
|
1139
|
+
|
|
1140
|
+
# Against a local wizard scaffold, which is built around those same test
|
|
1141
|
+
# values: no credentials at all, and the run still proves something.
|
|
821
1142
|
npx @oneaddress/conformance test http://localhost:3001/webhook
|
|
822
1143
|
```
|
|
823
1144
|
|
|
824
1145
|
Or use the **Integration Conformance** card in the Partner Portal to run the same checks against your configured webhook URL from within the portal.
|
|
1146
|
+
|
|
1147
|
+
## Licence
|
|
1148
|
+
|
|
1149
|
+
Apache License 2.0. See [LICENSE](./LICENSE).
|
|
1150
|
+
|
|
1151
|
+
Apache-2.0 rather than MIT deliberately: it carries an **express patent grant**,
|
|
1152
|
+
bounded to this package. OneAddress holds a pending patent application over the
|
|
1153
|
+
address-change notification architecture, and this SDK is the recipient half of
|
|
1154
|
+
it. Partners using it is the entire point, so an explicit, bounded grant is
|
|
1155
|
+
clearer for you than MIT's silence on patents.
|