@oneaddress/partner-sdk 2.0.0 → 2.2.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 +180 -2
- package/README.md +265 -20
- package/dist/{chunk-DUVPNFU6.mjs → chunk-LIHXDUUA.mjs} +295 -7
- package/dist/{chunk-UPJU4HFR.mjs → chunk-PCYKV7RJ.mjs} +395 -29
- package/dist/edge.js +557 -19
- package/dist/edge.mjs +2 -2
- package/dist/index.d.mts +373 -35
- package/dist/index.d.ts +373 -35
- package/dist/index.js +704 -33
- package/dist/index.mjs +6 -2
- package/dist/{src-UACTYQGX.mjs → src-ENJJ6YZU.mjs} +15 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,182 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.2.0] - 2026-09-27
|
|
11
|
+
|
|
12
|
+
A minor rather than a patch, and it started life numbered 2.1.1. The change was
|
|
13
|
+
believed to be README prose alone, for which a patch is right. Diffing the built
|
|
14
|
+
tarball against published 2.1.0 showed an added optional option on an exported
|
|
15
|
+
interface, which is additive and therefore a minor. **A version number is cheap
|
|
16
|
+
until published and permanent after**, so it was corrected before the publish
|
|
17
|
+
rather than explained afterwards.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **`buildSignedTestWebhook` takes `retentionPeriodDays`.** Optional, defaulting
|
|
22
|
+
to 90 so existing callers are unaffected. Pass your own configured window to
|
|
23
|
+
rehearse the `key_share_expiry` you will actually receive.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **`buildSignedTestWebhook` advertised a `key_share_expiry` the relay does not
|
|
28
|
+
send.** It was hard-coded to `dispatch_at + 90 days`. The relay derives that
|
|
29
|
+
field per recipient from the retention window the recipient chooses themselves
|
|
30
|
+
(14 to 365 days, on the portal's Data Retention card), so the helper taught
|
|
31
|
+
every handler tested against it that the horizon is a constant. A handler built
|
|
32
|
+
on that assumption passes its own tests and then mis-handles its own 14-day
|
|
33
|
+
window against a real dispatch. The helper now computes the field from the same
|
|
34
|
+
resolver the relay uses.
|
|
35
|
+
|
|
36
|
+
### Documentation
|
|
37
|
+
|
|
38
|
+
- **Recipient obligation 2 restated to say what a recipient may do, not only what
|
|
39
|
+
OneAddress will not do.** It reads as a permission to destroy the
|
|
40
|
+
`session_key_share` on or after `key_share_expiry`, states that the date on the
|
|
41
|
+
dispatch you received is the one that binds you and is not extended later, and
|
|
42
|
+
says a reconstruction request should be treated as something that may or may not
|
|
43
|
+
still be possible by then rather than as something the date guarantees.
|
|
44
|
+
- **The guarantee table's declaration row scoped to contact kinds.** It said a
|
|
45
|
+
kind you did not declare is refused; that is true of `phone` and `email` and not
|
|
46
|
+
of `address`, which is not declinable. Stated explicitly beside the table.
|
|
47
|
+
|
|
48
|
+
## [2.1.0] - 2026-09-20
|
|
49
|
+
|
|
50
|
+
**PUBLISHED 2026-09-26, registry timestamp `2026-09-26T02:09:11.018Z`.** This
|
|
51
|
+
paragraph said "unpublished as at this entry, and still unpublished on 25 Sep
|
|
52
|
+
2026" until 27 Sep, which is the shape a version entry rots into: the statement
|
|
53
|
+
was true when written and nothing brings it back for a second look. The
|
|
54
|
+
dispatch-simulator correction below was folded into this version rather than given
|
|
55
|
+
one of its own — a version number is cheap until published and permanent
|
|
56
|
+
after, so work accumulates into the unpublished one.
|
|
57
|
+
|
|
58
|
+
A minor version: every change is additive or tightens a check that was
|
|
59
|
+
documented as already present. Two audits of the SDK on 20 Sep 2026 (one
|
|
60
|
+
security, one partner-usability) produced the original list; a
|
|
61
|
+
dashboard-to-receiver wiring audit on 25 Sep 2026 produced the addition.
|
|
62
|
+
|
|
63
|
+
### Fixed (25 Sep 2026)
|
|
64
|
+
|
|
65
|
+
- **`buildSignedTestWebhook` sent a payload OneAddress does not send.** The
|
|
66
|
+
helper exists so you can unit-test your handler against "what the relay
|
|
67
|
+
sends", and measured against the relay's own composer it did not: it added
|
|
68
|
+
`version` and `encryption_status` — fields of the superseded
|
|
69
|
+
`address_encrypted` shape that never appear beside a `session_envelope` — it
|
|
70
|
+
always sent the body `id`, which the relay sends only on a key-crossover
|
|
71
|
+
copy, it sent `update_id` as a UUID where the relay sends the integer
|
|
72
|
+
`user_updates.id`, and it omitted `user_id` and `stripe_session_id`
|
|
73
|
+
altogether.
|
|
74
|
+
|
|
75
|
+
**This could make a correct-looking handler fail in production.** A handler
|
|
76
|
+
gated on `encryption_status === 'encrypted'`, pinned to `body.version`, or
|
|
77
|
+
keyed for idempotency on `body.id` went green against this helper and would
|
|
78
|
+
then have dropped — or double-written — every real update. **If your tests
|
|
79
|
+
assert on any of those three fields, they will now fail, and that failure is
|
|
80
|
+
the bug surfacing: production never carried them.** Deduplicate on the
|
|
81
|
+
`X-OneAddress-Dispatch` header, which is on every delivery.
|
|
82
|
+
|
|
83
|
+
The body's `timestamp` is ISO 8601; the `X-OneAddress-Timestamp` *header* is
|
|
84
|
+
Unix-epoch seconds. Both formats are in every dispatch, which is how two
|
|
85
|
+
separate conformance implementations came to put the header's format in the
|
|
86
|
+
body.
|
|
87
|
+
|
|
88
|
+
The field list now comes from an explicit contract that is verified by
|
|
89
|
+
EXECUTING the relay's own composer, so the helper cannot drift from the wire
|
|
90
|
+
again without a test failing.
|
|
91
|
+
|
|
92
|
+
### Added (25 Sep 2026)
|
|
93
|
+
|
|
94
|
+
- `buildSignedTestWebhook` takes **`userId`** (default `test:consumer`) and
|
|
95
|
+
**`stripeSessionId`** (default `null` — the key is always present on the wire
|
|
96
|
+
even when the value is not). `id` and `crossover_key_ids` remain reachable
|
|
97
|
+
through `extraBody`, which is the circumstance the relay actually sends them
|
|
98
|
+
in. The helper also binds `update_id` to the envelope's `update_uid` as the
|
|
99
|
+
relay does, so a handler can bind a decrypted LOA to the update it arrived
|
|
100
|
+
with.
|
|
101
|
+
|
|
102
|
+
### Security
|
|
103
|
+
|
|
104
|
+
- **The Letter of Authority must be PRESENT, not merely valid when present.**
|
|
105
|
+
With `loaPublicKeyPem` set, a dispatch that carried no `loa_encrypted` was
|
|
106
|
+
processed with no check at all: "verified" meant "verified if the relay
|
|
107
|
+
chose to include it". Such a dispatch is now refused with a 500, so
|
|
108
|
+
OneAddress retries and records the failure rather than being told a
|
|
109
|
+
delivery succeeded whose consent proof nobody saw. New option `requireLoa`
|
|
110
|
+
(default `true` when `loaPublicKeyPem` is set, `false` otherwise); set it
|
|
111
|
+
`false` to keep processing without a proof, in which case the handler warns
|
|
112
|
+
once per process that consent is unverified.
|
|
113
|
+
- **The LOA is bound to its envelope.** A decrypted LOA whose `update_uid`
|
|
114
|
+
differs from the session envelope's is refused, so a genuine consent for one
|
|
115
|
+
update cannot be replayed beside the envelope of another. Older dispatches
|
|
116
|
+
lacking the field on either side are unaffected.
|
|
117
|
+
- **`fetchLoaPublicKey` requires `https:`** except for `localhost` and
|
|
118
|
+
`127.0.0.1`. The key it fetches is what every consent signature is checked
|
|
119
|
+
against, and `http://oneaddress.io` passed the host allowlist.
|
|
120
|
+
- **`createOutboxConsumer`: `markProcessed`, `markFailed` and `release` now
|
|
121
|
+
match on the claim token this consumer holds as well as `dispatch_id`,** so
|
|
122
|
+
a write that lands after the lease expired and another consumer re-claimed
|
|
123
|
+
the row touches nothing. `maxAttempts` is validated (integer, zero or more)
|
|
124
|
+
before it is inlined into the statement, like `batchSize` already was.
|
|
125
|
+
- **Configuration is refused at construction, by name**: an empty
|
|
126
|
+
`webhookSecret`, a `privateKeyPem` that does not import, a
|
|
127
|
+
`timestampToleranceSecs` outside `(0, 86400]`, an unparseable
|
|
128
|
+
`webhookSecretGraceUntil`. Each used to surface on the first real delivery
|
|
129
|
+
as a 500 that OneAddress then retried for two days.
|
|
130
|
+
- A correctly signed body that is valid JSON but not an object (`null`, a
|
|
131
|
+
number, an array) is answered `400 Invalid JSON` instead of throwing out
|
|
132
|
+
of the handler.
|
|
133
|
+
|
|
134
|
+
### Added
|
|
135
|
+
|
|
136
|
+
- **`confirm` option on `createOneAddressHandler`** (`{ partnerId,
|
|
137
|
+
confirmSecret, oneAddressApi? }`). When set, the handler calls
|
|
138
|
+
`confirmUpdate` after `onUpdate` returns, with the `status` it returned
|
|
139
|
+
(`confirmed` when omitted) and `event.loa_ref`. Fire-and-forget: a failed
|
|
140
|
+
confirm is logged and never fails the delivery. Exists because `onUpdate`'s
|
|
141
|
+
return value was only ever spread into the 200 body and reached nobody;
|
|
142
|
+
its docstring and the README said otherwise and are corrected.
|
|
143
|
+
- **`buildSignedTestWebhook`**: a correctly signed, correctly encrypted test
|
|
144
|
+
dispatch for your own unit tests, in the exact shape the relay sends,
|
|
145
|
+
lifted from the conformance suite. Optional real LOA signing with a key you
|
|
146
|
+
generate, so `loaPublicKeyPem` can be tested end to end. `HandlerRequest`
|
|
147
|
+
and `HandlerResponse` are exported alongside it.
|
|
148
|
+
- **`createSqlIdempotencyStore` takes `dialect`** (`postgres` | `sqlite` |
|
|
149
|
+
`mysql` | `mssql`). The claim statement was Postgres/SQLite-only
|
|
150
|
+
(`ON CONFLICT ... DO NOTHING RETURNING`) while the README said MySQL and
|
|
151
|
+
SQL Server "just change the placeholder". MySQL and SQL Server now get an
|
|
152
|
+
insert-if-absent under a per-call token; their table needs one extra
|
|
153
|
+
column, `claim_token VARCHAR(64) NULL`. An unknown dialect is refused with
|
|
154
|
+
the supported list.
|
|
155
|
+
- **`expectedAlg` option on `createOneAddressHandler`**, passed through to
|
|
156
|
+
`decryptSession` (and `decryptLoaEncrypted`, which gains the same optional
|
|
157
|
+
parameter) so the algorithm-downgrade pin is reachable from the handler.
|
|
158
|
+
- **A private key stored as one line with literal `\n` sequences is accepted**
|
|
159
|
+
everywhere a PEM is, which is what a secrets manager hands back when the key
|
|
160
|
+
was pasted as a single line.
|
|
161
|
+
- Outside test mode, a dispatch carrying `X-OneAddress-Dispatch` with no
|
|
162
|
+
`idempotencyStore` wired is processed and logged once per process, naming
|
|
163
|
+
`createSqlIdempotencyStore`. The test-mode throw is unchanged. The
|
|
164
|
+
`process.env` read is guarded for the edge build.
|
|
165
|
+
|
|
166
|
+
### Changed
|
|
167
|
+
|
|
168
|
+
- **`privateKeyPem` on the handler accepts `string | PrivateKeyOperations`,
|
|
169
|
+
and so does `transformSession`.** The 1.8.0 entry below said the handler
|
|
170
|
+
already did; it did not, and `transformSession` was PEM-only. A delegate
|
|
171
|
+
covers the session-envelope paths; the legacy single-blob paths
|
|
172
|
+
(`address_encrypted`, `customer_encrypted`) still need the raw key and say
|
|
173
|
+
so by name.
|
|
174
|
+
- Documentation: `onUpdate`'s return value is stated NOT to reach OneAddress on
|
|
175
|
+
its own; the README's quick start returns `no_match` for an unknown customer
|
|
176
|
+
instead of throwing; all four confirm statuses are listed; a "Delivery
|
|
177
|
+
contract" section states our 10-second timeout, 28 attempts over 48 hours,
|
|
178
|
+
the `ok:false`-in-a-2xx rule and what each response status means to us; an
|
|
179
|
+
identifier table tells `event.id`, `dispatchId`, `update_uid`, `batch_id`
|
|
180
|
+
and `verification_id` apart; the `/edge` section lists what that entry
|
|
181
|
+
actually exports and says Cloudflare Workers need `nodejs_compat`; a
|
|
182
|
+
"Never do" list; `formatAddressParts` and `confirmUpdate`'s `note` no
|
|
183
|
+
longer suggest putting the address in a log or a note; `BYPASS_STRIPE` is
|
|
184
|
+
gone from partner-facing text in favour of "sandbox dispatches".
|
|
185
|
+
|
|
10
186
|
## [2.0.0] - 2026-09-16
|
|
11
187
|
|
|
12
188
|
A major version because `OneAddressUpdateEvent.address` is now optional (see
|
|
@@ -64,8 +240,10 @@ Runtime behaviour for an integration that declares nothing is unchanged.
|
|
|
64
240
|
### Added
|
|
65
241
|
|
|
66
242
|
- **Delegated private-key operations for a KMS/HSM-held key
|
|
67
|
-
(`PrivateKeyOperations`).** `
|
|
68
|
-
|
|
243
|
+
(`PrivateKeyOperations`).** `decryptSession` and `decryptLoaEncrypted` now
|
|
244
|
+
accept `privateKeyPem: string | PrivateKeyOperations`. (Correction, 2.1.0:
|
|
245
|
+
this entry originally also named `createOneAddressHandler`, whose option
|
|
246
|
+
stayed `string` until 2.1.0 widened it.)
|
|
69
247
|
A key held in a KMS or HSM is never exported as a PEM by design, so passing a
|
|
70
248
|
raw key was impossible for those integrators; a `PrivateKeyOperations`
|
|
71
249
|
delegate performs the private-key step (ECDH-ES derivation / RSA-OAEP unwrap)
|
package/README.md
CHANGED
|
@@ -52,9 +52,21 @@ export const handler = createOneAddressHandler({
|
|
|
52
52
|
const providedNames = [customer.name, ...customer.known_names];
|
|
53
53
|
const record = await db.findByAccountNumber(customer.account_number);
|
|
54
54
|
if (!record || !namePoolMatches(providedNames, record.fullName)) {
|
|
55
|
-
|
|
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' };
|
|
56
59
|
}
|
|
57
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!,
|
|
58
70
|
},
|
|
59
71
|
// Connection-verification test records. OneAddress sends five of these
|
|
60
72
|
// before you go live: real signed, encrypted dispatches carrying FABRICATED
|
|
@@ -142,7 +154,7 @@ What the handler guarantees:
|
|
|
142
154
|
| Situation | Response | `onUpdate` |
|
|
143
155
|
|---|---|---|
|
|
144
156
|
| Every kind in the envelope is declared | `200 { ok: true, accepted_update_types }` | runs |
|
|
145
|
-
| A kind you did not declare | `422 update_type_not_accepted` | never runs |
|
|
157
|
+
| A **contact** kind you did not declare | `422 update_type_not_accepted` | never runs |
|
|
146
158
|
| A kind name this SDK build does not know | `422 invalid_update_types` | never runs |
|
|
147
159
|
| `contact.updated` without a session envelope | `400 missing_session_envelope` | never runs |
|
|
148
160
|
|
|
@@ -154,8 +166,20 @@ What the handler guarantees:
|
|
|
154
166
|
September 2026 has one, and if you declare nothing you will never see the
|
|
155
167
|
absent case, but TypeScript will ask you to narrow: bind it to a local and
|
|
156
168
|
check it, or test it with `if` as the example does.
|
|
169
|
+
- **`address` is not declinable, and it is the one kind the row above does not
|
|
170
|
+
cover.** Whatever you pass, `address` is forced into `acceptedUpdateTypes`, so
|
|
171
|
+
writing `['phone']` declares *and enforces* `['address', 'phone']`: an address
|
|
172
|
+
dispatch reaches `onUpdate` rather than being refused, and the
|
|
173
|
+
`accepted_update_types` on your acknowledgement says `['address', 'phone']`.
|
|
174
|
+
The portal side matches: a consent set without `address` is refused there with
|
|
175
|
+
a 400, and a database constraint backs that up. Every OneAddress partner
|
|
176
|
+
receives addresses; the declaration decides which **contact** kinds ride with
|
|
177
|
+
them. If you do not want addresses, the thing you are asking for is to be
|
|
178
|
+
deactivated, which is a separate control.
|
|
157
179
|
- **`update_types` is literal.** `['phone']` means the phone number changed and
|
|
158
|
-
nothing else. It is never widened to include `address`.
|
|
180
|
+
nothing else. It is never widened to include `address`. This is the envelope's
|
|
181
|
+
own field and is the opposite direction from the point above: your DECLARATION
|
|
182
|
+
always contains `address`, a DISPATCH says only what actually changed.
|
|
159
183
|
- **Refusal is deliberate.** Acknowledging a kind you cannot store would look
|
|
160
184
|
identical to success on both sides while the consumer has already paid. The
|
|
161
185
|
422 leaves the dispatch incomplete in your idempotency store, so once you
|
|
@@ -172,7 +196,7 @@ What the handler guarantees:
|
|
|
172
196
|
|
|
173
197
|
## D5 — session-envelope decryption (added in v1.3.0)
|
|
174
198
|
|
|
175
|
-
|
|
199
|
+
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:
|
|
176
200
|
|
|
177
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>.
|
|
178
202
|
- 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`.
|
|
@@ -227,6 +251,18 @@ await confirmUpdate({
|
|
|
227
251
|
|
|
228
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).
|
|
229
253
|
|
|
254
|
+
### LOA verification: present AND verified AND bound
|
|
255
|
+
|
|
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:
|
|
257
|
+
|
|
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).
|
|
260
|
+
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
|
+
|
|
262
|
+
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
|
+
|
|
264
|
+
`requireLoa: true` without `loaPublicKeyPem` enforces presence and binding only; verification needs the key.
|
|
265
|
+
|
|
230
266
|
> **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.
|
|
231
267
|
|
|
232
268
|
### Key versioning + retention obligations
|
|
@@ -236,7 +272,7 @@ Under D5 your `partner_keys` registry holds your **active** key plus zero-or-mor
|
|
|
236
272
|
**Your contractual obligations:**
|
|
237
273
|
|
|
238
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.
|
|
239
|
-
2. **Retain** the `session_key_share` object alongside the update record until `key_share_expiry
|
|
275
|
+
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.
|
|
240
276
|
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.
|
|
241
277
|
|
|
242
278
|
See the partner portal documentation at partners.oneaddress.io for the full integration spec.
|
|
@@ -338,6 +374,25 @@ naming conventions, verify this assumption holds before relying on it.
|
|
|
338
374
|
|
|
339
375
|
**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.
|
|
340
376
|
|
|
377
|
+
**`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:
|
|
378
|
+
|
|
379
|
+
**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.
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
createOneAddressHandler({
|
|
383
|
+
webhookSecret, privateKeyPem,
|
|
384
|
+
confirm: { partnerId: process.env.OA_PARTNER_ID!, confirmSecret: process.env.OA_CONFIRM_SECRET! },
|
|
385
|
+
async onUpdate(event) {
|
|
386
|
+
const record = await db.findByAccountNumber(event.customer?.account_number);
|
|
387
|
+
if (!record) return { status: 'no_match' };
|
|
388
|
+
await db.updateAddress({ id: record.id, ...event.address });
|
|
389
|
+
return { status: 'confirmed' };
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Or** call `confirmUpdate` yourself, from wherever the write actually completes (an outbox worker, a batch job):
|
|
395
|
+
|
|
341
396
|
```typescript
|
|
342
397
|
import { confirmUpdate } from '@oneaddress/partner-sdk';
|
|
343
398
|
|
|
@@ -346,19 +401,22 @@ const res = await confirmUpdate({
|
|
|
346
401
|
secret: process.env.OA_CONFIRM_SECRET!, // see "which secret" below
|
|
347
402
|
dispatchId: event.dispatchId, // from X-OneAddress-Dispatch
|
|
348
403
|
status: 'confirmed',
|
|
349
|
-
note: '
|
|
404
|
+
note: 'Applied to CRM record', // never the address itself
|
|
350
405
|
});
|
|
351
406
|
|
|
352
407
|
if (!res.ok) console.error('[oneaddress] confirm failed', res.status, res.error);
|
|
353
408
|
```
|
|
354
409
|
|
|
355
|
-
### The
|
|
410
|
+
### The four statuses mean different things
|
|
356
411
|
|
|
357
412
|
| Status | Meaning |
|
|
358
413
|
| --- | --- |
|
|
359
414
|
| `confirmed` | You applied the change. |
|
|
360
415
|
| `already_current` | You already held that address; nothing to write. **Not a failure** — return it honestly rather than reporting `confirmed`. |
|
|
361
|
-
| `failed` |
|
|
416
|
+
| `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). |
|
|
417
|
+
| `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. |
|
|
418
|
+
|
|
419
|
+
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.
|
|
362
420
|
|
|
363
421
|
### Which secret
|
|
364
422
|
|
|
@@ -378,9 +436,36 @@ It also refuses a missing or non-numeric `dispatchId` **before** sending, becaus
|
|
|
378
436
|
|
|
379
437
|
---
|
|
380
438
|
|
|
439
|
+
## Delivery contract
|
|
440
|
+
|
|
441
|
+
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.
|
|
442
|
+
|
|
443
|
+
| Fact | Value |
|
|
444
|
+
|---|---|
|
|
445
|
+
| Timeout per delivery attempt | **10 seconds**, on our side. Answer inside it; do slow work after the 200 (an outbox is the usual shape). |
|
|
446
|
+
| 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. |
|
|
447
|
+
| 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. |
|
|
448
|
+
| `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. |
|
|
449
|
+
| A redirect | Treated as an error. A 301/302 on a POST drops the body, so a redirecting webhook URL is a misconfiguration. |
|
|
450
|
+
|
|
451
|
+
What each response status means to us:
|
|
452
|
+
|
|
453
|
+
| You answer | We record | We do |
|
|
454
|
+
|---|---|---|
|
|
455
|
+
| `2xx` (and no `ok: false`) | delivered, awaiting your confirm | Wait for `confirmUpdate`. |
|
|
456
|
+
| `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. |
|
|
457
|
+
| `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). |
|
|
458
|
+
| `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. |
|
|
459
|
+
| `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. |
|
|
460
|
+
| no response / timeout | unreachable | Retry. |
|
|
461
|
+
|
|
462
|
+
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".
|
|
463
|
+
|
|
464
|
+
---
|
|
465
|
+
|
|
381
466
|
## Idempotency — handling retries
|
|
382
467
|
|
|
383
|
-
If your handler takes longer than
|
|
468
|
+
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:
|
|
384
469
|
|
|
385
470
|
```typescript
|
|
386
471
|
async onUpdate(event) {
|
|
@@ -415,6 +500,7 @@ CREATE TABLE oneaddress_dispatches (
|
|
|
415
500
|
dispatch_id TEXT PRIMARY KEY,
|
|
416
501
|
received_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
417
502
|
completed_at TIMESTAMP
|
|
503
|
+
-- MySQL and SQL Server only: add claim_token VARCHAR(64) NULL
|
|
418
504
|
);
|
|
419
505
|
```
|
|
420
506
|
|
|
@@ -426,7 +512,9 @@ export const handler = createOneAddressHandler({
|
|
|
426
512
|
privateKeyPem: process.env.OA_PRIVATE_KEY_PEM!,
|
|
427
513
|
|
|
428
514
|
idempotencyStore: createSqlIdempotencyStore({
|
|
429
|
-
// Postgres (node-postgres).
|
|
515
|
+
// Postgres (node-postgres). Pass `dialect: 'mysql' | 'sqlite' | 'mssql'`
|
|
516
|
+
// for the others: the placeholder AND the claim statement differ, since
|
|
517
|
+
// only Postgres and SQLite have `ON CONFLICT ... DO NOTHING RETURNING`.
|
|
430
518
|
query: (sql, params) => pool.query(sql, params).then((r) => r.rows),
|
|
431
519
|
}),
|
|
432
520
|
|
|
@@ -441,6 +529,17 @@ cannot be made correct under concurrency: `has` and `set` are separate round-tri
|
|
|
441
529
|
retries arriving at once both observe "not seen" and both apply the update. `claim` is a single
|
|
442
530
|
atomic `INSERT … ON CONFLICT DO NOTHING` and has no such window.
|
|
443
531
|
|
|
532
|
+
**Per dialect.** Postgres and SQLite use that statement as written. MySQL uses `INSERT IGNORE`
|
|
533
|
+
and SQL Server `INSERT ... WHERE NOT EXISTS`, each carrying a per-call token in `claim_token`
|
|
534
|
+
and reading the row back to see whose token landed, which is what makes the claim atomic without
|
|
535
|
+
`RETURNING`. On SQL Server the loser of a genuine race gets a primary-key error rather than an
|
|
536
|
+
empty insert; the handler answers 500, OneAddress retries, and the retry reads the winner's row.
|
|
537
|
+
A dialect the store has no SQL for is refused at construction with the supported list.
|
|
538
|
+
|
|
539
|
+
**Not wiring a store at all.** In test mode (`NODE_ENV=test`) the handler throws on the first
|
|
540
|
+
dispatch that carries `X-OneAddress-Dispatch`, so the omission is caught in development.
|
|
541
|
+
Everywhere else it processes the dispatch and logs once per process, naming this function.
|
|
542
|
+
|
|
444
543
|
It also distinguishes three states rather than two, and the third is the one that matters:
|
|
445
544
|
|
|
446
545
|
| Claim | Meaning | Handler does |
|
|
@@ -511,6 +610,11 @@ running, the row can be claimed twice — and no timeout is long enough to make
|
|
|
511
610
|
impossible. Set `leaseSeconds` comfortably longer than your slowest handler, and make the
|
|
512
611
|
write itself safe to repeat.
|
|
513
612
|
|
|
613
|
+
A release is scoped to the claim this consumer holds: `markProcessed`, `markFailed` and
|
|
614
|
+
`release` match on the claim token as well as the id, so a slow consumer's late write after
|
|
615
|
+
its lease expired and another consumer re-claimed the row touches nothing. Until 2.1.0 it
|
|
616
|
+
cleared the other consumer's claim.
|
|
617
|
+
|
|
514
618
|
### Failure, and why nothing is given up on by default
|
|
515
619
|
|
|
516
620
|
A handler that throws does not stop the batch: the row records its reason in
|
|
@@ -545,9 +649,9 @@ something.
|
|
|
545
649
|
| `query` | — | Runs parameterised SQL, returns rows. Your pool, your driver. |
|
|
546
650
|
| `dialect` | `postgres` | `postgres` \| `mysql` \| `sqlite` \| `mssql` |
|
|
547
651
|
| `table` | `oneaddress_updates` | What the receiver writes to |
|
|
548
|
-
| `batchSize` | `50` | Rows per claim |
|
|
652
|
+
| `batchSize` | `50` | Rows per claim. Positive integer; it is inlined into the statement, so it is validated. |
|
|
549
653
|
| `leaseSeconds` | `300` | How long a claim is held |
|
|
550
|
-
| `maxAttempts` | `0` | `0` = never give up |
|
|
654
|
+
| `maxAttempts` | `0` | `0` = never give up. Integer, zero or more; inlined and validated like `batchSize`. |
|
|
551
655
|
|
|
552
656
|
---
|
|
553
657
|
|
|
@@ -575,7 +679,7 @@ async onUpdate(event) {
|
|
|
575
679
|
| `verified` | Always `true` when the block is present. |
|
|
576
680
|
| `platform` | Format tag — currently `oneaddress/v1`. |
|
|
577
681
|
|
|
578
|
-
The block is absent on
|
|
682
|
+
The block is absent on sandbox dispatches, where no identity-verification credit was consumed. Production dispatches always include it.
|
|
579
683
|
|
|
580
684
|
### The verification reference lives inside the encrypted envelope
|
|
581
685
|
|
|
@@ -763,6 +867,8 @@ The three statuses surface to the consumer as:
|
|
|
763
867
|
|
|
764
868
|
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.
|
|
765
869
|
|
|
870
|
+
**`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.
|
|
871
|
+
|
|
766
872
|
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.
|
|
767
873
|
|
|
768
874
|
---
|
|
@@ -773,7 +879,13 @@ Failure mode: `no_match` and `no_account` are **informational only**. The consum
|
|
|
773
879
|
import { createOneAddressHandler } from '@oneaddress/partner-sdk/edge';
|
|
774
880
|
```
|
|
775
881
|
|
|
776
|
-
|
|
882
|
+
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.
|
|
883
|
+
|
|
884
|
+
**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.
|
|
885
|
+
|
|
886
|
+
**Not on `/edge`:** `confirmUpdate`, `createSqlIdempotencyStore`, `createOutboxConsumer`, `toExpressHandler`, `readAddressParts`, `formatAddressParts`, `buildSignedTestWebhook`. Import those from the main entry.
|
|
887
|
+
|
|
888
|
+
**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.
|
|
777
889
|
|
|
778
890
|
---
|
|
779
891
|
|
|
@@ -788,7 +900,7 @@ import {
|
|
|
788
900
|
transformAddress, // decrypt legacy blob then re-encrypt to a different public key (e.g. KMS)
|
|
789
901
|
transformSession, // decrypt D5 session then re-encrypt to a different public key (e.g. KMS)
|
|
790
902
|
readAddressParts, // tolerant address field reader (street/line1/address_line1/…)
|
|
791
|
-
formatAddressParts, // one-line summary
|
|
903
|
+
formatAddressParts, // one-line summary for a screen a person is entitled to see; NOT logs, NOT notes
|
|
792
904
|
isFreshTimestamp, // ±5-minute replay-window check
|
|
793
905
|
CURRENT_VERSION, // '2026.1'
|
|
794
906
|
SUPPORTED_VERSIONS, // ['2026.1']
|
|
@@ -810,9 +922,11 @@ await db.updateAddress({
|
|
|
810
922
|
suburb: parts.suburb || row.suburb,
|
|
811
923
|
postcode: parts.postcode || row.postcode,
|
|
812
924
|
});
|
|
813
|
-
|
|
925
|
+
reviewScreen.show(formatAddressParts(parts)); // "42 Collins Street, Melbourne, VIC, 3000"
|
|
814
926
|
```
|
|
815
927
|
|
|
928
|
+
`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.
|
|
929
|
+
|
|
816
930
|
This is a **tolerant reader**, not a schema declaration: it describes what the helper accepts and
|
|
817
931
|
says nothing about what OneAddress guarantees to send. Use it instead of hand-rolling the
|
|
818
932
|
`?? ?? ??` ladder — we did that in three receivers and a fix to one silently left the others
|
|
@@ -882,6 +996,130 @@ async onUpdate(event) {
|
|
|
882
996
|
|
|
883
997
|
---
|
|
884
998
|
|
|
999
|
+
## Never do
|
|
1000
|
+
|
|
1001
|
+
The address is encrypted to you and to nobody else. Four ways to undo that, each seen in a real integration:
|
|
1002
|
+
|
|
1003
|
+
- **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.
|
|
1004
|
+
- **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.
|
|
1005
|
+
- **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.
|
|
1006
|
+
- **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.
|
|
1007
|
+
- **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.
|
|
1008
|
+
|
|
1009
|
+
---
|
|
1010
|
+
|
|
1011
|
+
## Which identifier is which
|
|
1012
|
+
|
|
1013
|
+
Five identifiers arrive with a dispatch and they are easy to confuse. None of them identifies the consumer.
|
|
1014
|
+
|
|
1015
|
+
| Identifier | Where | What it identifies | Use it for |
|
|
1016
|
+
|---|---|---|---|
|
|
1017
|
+
| `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. |
|
|
1018
|
+
| `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`. |
|
|
1019
|
+
| `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. |
|
|
1020
|
+
| `batch_id` | Body, `address.verify` only | The verification batch a verify request belongs to. | Echo it in `sendVerifyResult`; the handler does this for you. |
|
|
1021
|
+
| `verification_id` | Body, `address.test` only | The connection-verification run a test record belongs to. | Counting the five test records. |
|
|
1022
|
+
|
|
1023
|
+
`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.
|
|
1024
|
+
|
|
1025
|
+
---
|
|
1026
|
+
|
|
1027
|
+
## Generating and registering your key
|
|
1028
|
+
|
|
1029
|
+
The default scheme is ECDH P-256. Generate a pair, register the PUBLIC half, keep the private half in your secret store:
|
|
1030
|
+
|
|
1031
|
+
```bash
|
|
1032
|
+
openssl ecparam -name prime256v1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -out oa-private.pem
|
|
1033
|
+
openssl ec -in oa-private.pem -pubout -out oa-public.pem
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
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.
|
|
1037
|
+
|
|
1038
|
+
---
|
|
1039
|
+
|
|
1040
|
+
## Recipes
|
|
1041
|
+
|
|
1042
|
+
### Fastify
|
|
1043
|
+
|
|
1044
|
+
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:
|
|
1045
|
+
|
|
1046
|
+
```typescript
|
|
1047
|
+
import Fastify from 'fastify';
|
|
1048
|
+
import { createOneAddressHandler, type HandlerRequest } from '@oneaddress/partner-sdk';
|
|
1049
|
+
|
|
1050
|
+
const app = Fastify();
|
|
1051
|
+
const handler = createOneAddressHandler({ /* ... */ });
|
|
1052
|
+
|
|
1053
|
+
app.addContentTypeParser('application/json', { parseAs: 'string' }, (_req, body, done) => done(null, body));
|
|
1054
|
+
|
|
1055
|
+
app.post('/webhook/oneaddress', async (req, reply) => {
|
|
1056
|
+
const fetchLike: HandlerRequest = {
|
|
1057
|
+
text: async () => req.body as string,
|
|
1058
|
+
headers: { get: (name) => {
|
|
1059
|
+
const v = req.headers[name.toLowerCase()];
|
|
1060
|
+
return v === undefined ? null : Array.isArray(v) ? v.join(', ') : v;
|
|
1061
|
+
} },
|
|
1062
|
+
};
|
|
1063
|
+
const res = await handler(fetchLike);
|
|
1064
|
+
reply.status(res.status);
|
|
1065
|
+
res.headers.forEach((value, key) => reply.header(key, value));
|
|
1066
|
+
return reply.send(await res.text());
|
|
1067
|
+
});
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
### AWS Lambda (API Gateway / Function URL)
|
|
1071
|
+
|
|
1072
|
+
API Gateway may base64-encode the body; decode it before it reaches the handler, and never re-serialise it.
|
|
1073
|
+
|
|
1074
|
+
```typescript
|
|
1075
|
+
import type { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
1076
|
+
import { createOneAddressHandler } from '@oneaddress/partner-sdk';
|
|
1077
|
+
|
|
1078
|
+
const handler = createOneAddressHandler({ /* ... */ });
|
|
1079
|
+
|
|
1080
|
+
export async function main(apiEvent: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> {
|
|
1081
|
+
const raw = apiEvent.isBase64Encoded
|
|
1082
|
+
? Buffer.from(apiEvent.body ?? '', 'base64').toString('utf8')
|
|
1083
|
+
: (apiEvent.body ?? '');
|
|
1084
|
+
const res = await handler({
|
|
1085
|
+
text: async () => raw,
|
|
1086
|
+
headers: { get: (name) => apiEvent.headers[name.toLowerCase()] ?? null },
|
|
1087
|
+
});
|
|
1088
|
+
return { statusCode: res.status, headers: { 'content-type': 'application/json' }, body: await res.text() };
|
|
1089
|
+
}
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
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.
|
|
1093
|
+
|
|
1094
|
+
### Testing your receiver without a network
|
|
1095
|
+
|
|
1096
|
+
```typescript
|
|
1097
|
+
import { generateKeyPairSync } from 'node:crypto';
|
|
1098
|
+
import { createOneAddressHandler, buildSignedTestWebhook } from '@oneaddress/partner-sdk';
|
|
1099
|
+
|
|
1100
|
+
const { publicKey, privateKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' });
|
|
1101
|
+
const handler = createOneAddressHandler({
|
|
1102
|
+
webhookSecret: 'test-secret',
|
|
1103
|
+
privateKeyPem: privateKey.export({ type: 'pkcs8', format: 'pem' }) as string,
|
|
1104
|
+
idempotencyStore: memoryStore,
|
|
1105
|
+
async onUpdate(event) { seen.push(event); },
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
const hook = await buildSignedTestWebhook({
|
|
1109
|
+
webhookSecret: 'test-secret',
|
|
1110
|
+
partnerId: '11111111-1111-1111-1111-111111111111',
|
|
1111
|
+
publicKey: publicKey.export({ type: 'spki', format: 'pem' }) as string,
|
|
1112
|
+
session: { account_number: 'ACME-42' },
|
|
1113
|
+
});
|
|
1114
|
+
const res = await handler(hook.request); // or handler(hook.toRequest())
|
|
1115
|
+
expect(res.status).toBe(200);
|
|
1116
|
+
expect(seen[0].customer?.account_number).toBe('ACME-42');
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
`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`.
|
|
1120
|
+
|
|
1121
|
+
---
|
|
1122
|
+
|
|
885
1123
|
## Protocol versioning
|
|
886
1124
|
|
|
887
1125
|
The SDK warns (but does not reject) if it receives a protocol version it doesn't recognise:
|
|
@@ -902,10 +1140,17 @@ This ensures you keep receiving events while updating your SDK. See `SUPPORTED_V
|
|
|
902
1140
|
**Full conformance suite** — run 10 checks against your endpoint using real crypto, no mocks:
|
|
903
1141
|
|
|
904
1142
|
```bash
|
|
905
|
-
# Against a live endpoint
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
#
|
|
1143
|
+
# Against a live endpoint: all three credentials, or none. A partial set is
|
|
1144
|
+
# REFUSED — it passes every signature check while the payload stays sealed to
|
|
1145
|
+
# the suite's built-in test key, so the failures land on the acceptance checks
|
|
1146
|
+
# and read as a decrypt fault in your own code.
|
|
1147
|
+
export ONEADDRESS_WEBHOOK_SECRET=whsec_...
|
|
1148
|
+
export ONEADDRESS_PARTNER_ID=...
|
|
1149
|
+
export ONEADDRESS_PUBLIC_KEY=...
|
|
1150
|
+
npx @oneaddress/conformance test https://your-endpoint.com/webhook
|
|
1151
|
+
|
|
1152
|
+
# Against a local wizard scaffold, which is built around those same test
|
|
1153
|
+
# values: no credentials at all, and the run still proves something.
|
|
909
1154
|
npx @oneaddress/conformance test http://localhost:3001/webhook
|
|
910
1155
|
```
|
|
911
1156
|
|