@oneaddress/conformance 3.0.0 → 3.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.
@@ -0,0 +1,369 @@
1
+ export { plannedCoreCheckIds } from './plan.js';
2
+
3
+ /**
4
+ * Conformance-side helpers for the update-kind capability declaration.
5
+ *
6
+ * ── WHY THIS LIVES IN THE PROTOCOL PACKAGE ───────────────────────────────────
7
+ *
8
+ * There are TWO conformance implementations: `packages/conformance` (the CLI a
9
+ * partner runs from their own machine) and `apps/partner/src/lib/conformance-
10
+ * checks.ts` (the button in the partner portal). They have already diverged
11
+ * once, in check numbering, and a capability check that reads an
12
+ * acknowledgement differently in each would mean local testing and portal
13
+ * certification disagree about the same receiver. Both read the ack through the
14
+ * functions here, so they cannot.
15
+ *
16
+ * ── THE MECHANISM, IN ONE PARAGRAPH ──────────────────────────────────────────
17
+ *
18
+ * A receiver built on `@oneaddress/partner-sdk` declares the kinds of changed
19
+ * detail its code can handle (`acceptedUpdateTypes`) and puts the normalised
20
+ * list in the body of every authenticated 2xx acknowledgement as
21
+ * `accepted_update_types`. The conformance run reads it off check 1 (the first
22
+ * correctly signed dispatch), probes each declared contact kind with a real
23
+ * contact-only envelope, probes ONE kind the receiver did not declare and
24
+ * requires a refusal, and compares the declaration with what the operator
25
+ * ACCEPTED in the partner portal. Consent is the human act; capability is the
26
+ * proved fact; a kind should be dispatched only where both hold.
27
+ */
28
+ /** The closed vocabulary of changed-detail kinds, in canonical order. */
29
+ declare const UPDATE_KINDS: readonly ["address", "phone", "email"];
30
+ type UpdateKind = (typeof UPDATE_KINDS)[number];
31
+ /**
32
+ * What a receiver's acknowledgement says about the kinds it accepts.
33
+ */
34
+ interface AckKindDeclaration {
35
+ /**
36
+ * True when the body carried an `accepted_update_types` array. False for a
37
+ * receiver that predates the declaration, which is read as "unknown": the
38
+ * run then has nothing to compare the portal's accept-set against and says
39
+ * so, rather than treating silence as either address-only or as agreement.
40
+ */
41
+ declared: boolean;
42
+ /** The normalised declaration. Always contains `address`. */
43
+ kinds: UpdateKind[];
44
+ /**
45
+ * `accepted_update_types` was present but not an array. That is a broken
46
+ * receiver, not a legacy one, and a conformance run should say so rather
47
+ * than quietly read it as no declaration.
48
+ */
49
+ malformed: boolean;
50
+ /**
51
+ * Names in the declaration this build does not define. Dropped from `kinds`
52
+ * (fail closed: a name we cannot probe must not be recorded as accepted) and
53
+ * surfaced so the run can report them. Usually means the receiver is on a
54
+ * newer SDK than the conformance tool.
55
+ */
56
+ ignored: string[];
57
+ }
58
+
59
+ /**
60
+ * What a check's PASS actually rests on.
61
+ *
62
+ * Required, and required on purpose: a new check cannot be added without
63
+ * declaring this, because TypeScript refuses the object literal without it.
64
+ * A central id-to-basis map would have been fewer edits and one more place to
65
+ * forget - which is the failure mode this whole field exists to close.
66
+ *
67
+ * acceptance - passes only when the receiver ACCEPTED something (a 2xx, or a
68
+ * 2xx carrying a required body field). Cannot pass against a
69
+ * wall, so it is always meaningful on its own.
70
+ * rejection - passes when the receiver REFUSED something (a 4xx, or a body
71
+ * reporting failure). Satisfied by ANY endpoint that refuses
72
+ * everything, so it is meaningful only alongside an acceptance.
73
+ * liveness - passes on any timely response at all. Weakest of the three.
74
+ */
75
+ type CheckBasis = 'acceptance' | 'rejection' | 'liveness' | 'declaration';
76
+ interface CheckResult {
77
+ id: string;
78
+ label: string;
79
+ passed: boolean;
80
+ detail: string;
81
+ /** What this check's pass rests on. See {@link CheckBasis}. */
82
+ basis: CheckBasis;
83
+ /**
84
+ * Set when the check's own condition was met but the result proves nothing,
85
+ * because no acceptance check passed. `passed` is forced to false alongside
86
+ * it: an unproven check has NOT demonstrated conformance.
87
+ */
88
+ unproven?: true;
89
+ }
90
+ /**
91
+ * Build a conformance `address.updated` body in the current D5 (no-cleartext)
92
+ * shape that OneAddress actually dispatches under the mandate:
93
+ *
94
+ * - the address + identity (verified_name / account_number / known_names)
95
+ * travel INSIDE the per-partner `session_envelope` (decrypt with the
96
+ * partner private key matching `session_key_share.key_id`);
97
+ * - the signed Letter of Authority travels encrypted per-partner as
98
+ * `loa_encrypted` ({ session_envelope, session_key_share }), wrapped to the
99
+ * SAME key_id;
100
+ * - there is NO cleartext `customer` block, NO `customer_match` blind-index
101
+ * block, and NO cleartext `letter_of_authority`. Nothing about the consumer
102
+ * is knowable before the partner decrypts.
103
+ *
104
+ * A conforming receiver must accept this shape and recover identity from the
105
+ * decrypted envelope, never from a cleartext wire field.
106
+ */
107
+ /**
108
+ * What kind of detail the conformance envelope should carry.
109
+ *
110
+ * `address` is the historic shape and the default. The contact kinds produce an
111
+ * envelope with **no `new_address` at all** — see {@link buildBody}.
112
+ */
113
+ type ConformanceKind = 'address' | 'phone' | 'email';
114
+ /**
115
+ * The account reference the acceptance probes carry when nothing overrides it.
116
+ *
117
+ * Every scaffold seeds a customer with this reference, so a generated receiver
118
+ * matches out of the box. It stays the default for exactly that reason: CI
119
+ * drives the scaffolds and expects the matching checks to pass, so changing it
120
+ * would break the runs that prove the scaffolds work.
121
+ */
122
+ declare const DEFAULT_ACCOUNT_REF = "CONF-0001";
123
+ /**
124
+ * The key_id this suite labels its envelopes with when the caller does not name
125
+ * one. The built-in test key is a single key with no rotation history, so any
126
+ * stable label does; this is the one every scaffold and fixture expects.
127
+ */
128
+ declare const DEFAULT_CONFORMANCE_KEY_ID = "conformance-key-1";
129
+ /**
130
+ * The recipient key an envelope is sealed to.
131
+ *
132
+ * ── WHY THIS IS AN OBJECT AND NOT A BASE64 STRING ──────────────────────────
133
+ *
134
+ * It was a bare `publicKeyB64` for this suite's whole life, with `key_id`
135
+ * hard-coded to `conformance-key-1` beside it. That is correct for the CLI's
136
+ * built-in test key and WRONG for a real partner, who routinely holds more than
137
+ * one: a rotation before the old row is retired leaves two, and the receiver
138
+ * resolves its private half by the `key_id` stamped into `session_key_share`.
139
+ * A drill that always says `conformance-key-1` therefore rehearses a lookup
140
+ * that will never happen, and a receiver which selects strictly by key_id
141
+ * cannot pass it however correct it is.
142
+ *
143
+ * The partner portal has always passed the real key id, which is one of the
144
+ * things that kept the two implementations apart. Carrying it here is what lets
145
+ * the portal call this suite instead of keeping its own.
146
+ *
147
+ * `null` means the partner has registered NO key. The envelope is then absent
148
+ * rather than empty, exactly as a real dispatch to such a partner would be, and
149
+ * the checks that can only ask a question of an encrypted payload (11, 14, 15)
150
+ * skip rather than fail.
151
+ */
152
+ interface ConformanceKey {
153
+ keyId: string;
154
+ publicKeyB64: string;
155
+ }
156
+ /**
157
+ * Accept either form at every call site, so the CLI's `buildBody(id, b64)` and
158
+ * the portal's `buildBody(id, { keyId, publicKeyB64 })` are one function.
159
+ */
160
+ declare function asConformanceKey(key: string | ConformanceKey | null | undefined): ConformanceKey | null;
161
+ /**
162
+ * Exported for `body-contract.test.ts` ONLY — nothing outside this package
163
+ * should build a dispatch body. It is exported rather than duplicated in the
164
+ * test because a test that rebuilds the body it is meant to check can only ever
165
+ * agree with itself; the guard has to run THIS function.
166
+ */
167
+ declare function buildBody(partnerId: string,
168
+ /**
169
+ * The recipient key: a bare SPKI base64 string (the CLI's built-in test key,
170
+ * labelled `conformance-key-1`), a `ConformanceKey` naming the partner's real
171
+ * key id, or `null` for a partner who has registered no key at all.
172
+ */
173
+ publicKeyB64: string | ConformanceKey | null, extraFields?: Record<string, unknown>,
174
+ /**
175
+ * Widened from the closed `ConformanceKind` so the undeclared-kind refusal
176
+ * probe can send a name the protocol does not define. Every other caller
177
+ * passes a real kind.
178
+ */
179
+ kind?: ConformanceKind | string,
180
+ /**
181
+ * Override the identity fields INSIDE the session envelope.
182
+ *
183
+ * Only check-14 uses this, and it needs the override to be inside the
184
+ * envelope rather than in `extraFields`: `extraFields` lands on the cleartext
185
+ * wire, where the receiver cannot act on it and where identity has not
186
+ * travelled since the D5 cutover. A no-match has to be a real no-match after
187
+ * decryption, or the check proves nothing.
188
+ */
189
+ identity?: {
190
+ account_number?: string;
191
+ verified_name?: string;
192
+ known_names?: string[];
193
+ },
194
+ /**
195
+ * The retention window to advertise as `key_share_expiry`, in days.
196
+ *
197
+ * The relay derives this per recipient from `partners.retention_period_days`
198
+ * (14 to 365), so a receiver must not assume a constant. This CLI runs outside
199
+ * our database and cannot look the value up, so it defaults to the same 90 the
200
+ * column defaults to and takes an override: pass your OWN configured window to
201
+ * rehearse the horizon you will actually receive.
202
+ *
203
+ * Why it matters even though the value is only a date a receiver stores: a
204
+ * receiver that hard-codes "expiry is 90 days out" passes a drill that sends 90
205
+ * and then mis-handles its own 14-day window in production.
206
+ */
207
+ retentionPeriodDays?: number | null | undefined): Promise<string>;
208
+ interface RunChecksOptions {
209
+ /** Target webhook URL (required) */
210
+ targetUrl: string;
211
+ /** Webhook secret (default: built-in test secret) */
212
+ secret?: string;
213
+ /** Partner UUID (default: built-in test partner) */
214
+ partnerId?: string;
215
+ /** ECDH public key SPKI Base64 (default: built-in test key) */
216
+ publicKeyB64?: string;
217
+ /**
218
+ * The recipient key, naming the real `key_id` the receiver will resolve its
219
+ * private half by. Wins over `publicKeyB64`, which labels every envelope
220
+ * `conformance-key-1` and is right only for the built-in test key.
221
+ *
222
+ * `null` means the partner has registered NO key: the envelope fields go out
223
+ * null, and checks 11, 14 and 15 skip rather than fail, because none of them
224
+ * can ask its question of a payload that was never sealed.
225
+ */
226
+ key?: ConformanceKey | null;
227
+ /**
228
+ * The recipient's own retention window (`partners.retention_period_days`),
229
+ * which decides the `key_share_expiry` every body advertises.
230
+ *
231
+ * A CALLER THAT KNOWS THE VALUE MUST PASS IT. `buildBody` has taken this
232
+ * since 25 Sep 2026 and `runChecks` never threaded it, so every CLI run
233
+ * advertised the 90-day default whatever the recipient had configured: a
234
+ * receiver that hard-codes 90 passed a drill that sent 90, then mis-handled
235
+ * its own 14-day window in production. That is the exact failure the
236
+ * parameter was added to catch, surviving one level up.
237
+ */
238
+ retentionPeriodDays?: number | null;
239
+ /**
240
+ * Customer-app base URL for pull API checks (e.g. https://oneaddress.io).
241
+ * When provided, /updates and /audit checks are included.
242
+ */
243
+ customerUrl?: string;
244
+ /**
245
+ * The account reference the dispatches carry, for a receiver that matches
246
+ * dispatches to its own customer records.
247
+ *
248
+ * Defaults to `CONF-0001`, which is what the scaffolds seed. A receiver that
249
+ * verifies account references and holds no such customer answers `no_match`
250
+ * — CORRECTLY — and the suite then cannot go green however good that
251
+ * receiver is: an unseeded store is indistinguishable from a broken one from
252
+ * out here. Pointing this at a record the recipient already holds is the way
253
+ * out that does not involve writing test data into their system of record.
254
+ *
255
+ * The no-match probe (check-14) deliberately does NOT derive from this. It
256
+ * builds `CONF-NOSUCH-<nonce>` so that what it sends cannot exist, whatever
257
+ * is configured here; deriving it would let a configured prefix make the
258
+ * "cannot match anything" probe send something that legitimately matches.
259
+ */
260
+ accountRef?: string;
261
+ /**
262
+ * The update kinds this receiver's operator has declared they accept.
263
+ *
264
+ * Adds one check per contact kind. Omitted or address-only runs exactly the
265
+ * checks it always did, so an existing integration's result cannot change.
266
+ *
267
+ * WHY THIS IS OPT-IN RATHER THAN ALWAYS-ON: a receiver is only ever SENT a
268
+ * kind its operator declared in the partner portal, so failing an
269
+ * address-only partner on a phone envelope would report a defect that cannot
270
+ * occur. The declaration is the thing that makes the check meaningful, and it
271
+ * is also the moment the risk begins — which is why the wizard should pass
272
+ * this through the instant a partner widens their accept-set.
273
+ */
274
+ acceptedUpdateTypes?: string[];
275
+ /**
276
+ * True when this recipient's operator has declared that they match a dispatch
277
+ * to a customer record themselves, rather than queueing it for a system that
278
+ * matches later.
279
+ *
280
+ * Gates check-14, and gated for the same reason `acceptedUpdateTypes` gates
281
+ * the contact checks: a receiver that only ever WRITES TO AN OUTBOX has no
282
+ * way to know whether an account reference matches anything, so failing it
283
+ * for not refusing a no-match reports a defect that cannot exist. Our own
284
+ * drop-in receiver is exactly that shape when `OA_LOOKUP_SQL` is unset.
285
+ *
286
+ * The declaration is what makes the check meaningful, and it is also the
287
+ * moment the consumer-facing promise attaches: the wizard tells the consumer
288
+ * their address will not be changed if their details do not match, and only a
289
+ * recipient that matches can honour that. A recipient that queues instead
290
+ * moves the obligation downstream, which is a fact worth knowing about them.
291
+ */
292
+ verifiesAccountReference?: boolean;
293
+ /**
294
+ * True when this receiver's operator has declared it understands the
295
+ * key-crossover sibling marker (`crossover_key_ids`) — see
296
+ * `docs/architecture/key-crossover-dual-wrap.md`.
297
+ *
298
+ * Gates check-15, and gated for the same reason the others are: during a key
299
+ * rotation OneAddress briefly sends the same update once per key the recipient
300
+ * is crossing between, each copy naming the siblings it was also sent to. A
301
+ * receiver that understands the marker skip-acks a copy it cannot decrypt when
302
+ * one of its own keys is a named sibling (a decryptable copy is coming);
303
+ * everything else it still errors on. A receiver that has NOT upgraded 500s on
304
+ * such a copy, which is exactly today's behaviour and safe while the sender is
305
+ * not yet emitting the marker — so failing it for that would report a defect it
306
+ * does not have. The declaration is the moment the receiver is ready to be
307
+ * dual-wrapped, which is why it opts the check in.
308
+ */
309
+ supportsKeyCrossover?: boolean;
310
+ }
311
+ /**
312
+ * A run, with the receiver's own capability declaration beside the results.
313
+ *
314
+ * ── WHY THE DECLARATION COMES BACK AND IS NOT JUST A CHECK ─────────────────
315
+ *
316
+ * `check-kinds-declared` reports whether the receiver declared, and what. The
317
+ * partner portal needs the declaration ITSELF: it writes the list to
318
+ * `partners.receiver_declared_update_types` in BOTH databases, which is what
319
+ * `effectiveAcceptedTypes` narrows consent by before a dispatch is composed.
320
+ * Re-parsing it out of a check's prose `detail` would be the kind of derivation
321
+ * that works until somebody improves the wording.
322
+ *
323
+ * `runChecks` is the CLI's view of the same run and returns the checks alone.
324
+ */
325
+ interface ConformanceRun {
326
+ checks: CheckResult[];
327
+ declaration: AckKindDeclaration;
328
+ }
329
+ declare function runChecksDetailed(options: RunChecksOptions): Promise<ConformanceRun>;
330
+ declare function runChecksDetailed(url: string, secret?: string, partnerId?: string, publicKeyB64?: string): Promise<ConformanceRun>;
331
+ /**
332
+ * The CLI's entry point: the checks alone.
333
+ *
334
+ * A WRAPPER, NOT A SECOND IMPLEMENTATION, for the reason this whole module now
335
+ * exists: the partner portal kept its own copy of this suite for two months and
336
+ * the two drifted on three check IDs, on how strictly idempotency was read, and
337
+ * on four checks the portal never ran at all. One body, two views of it.
338
+ */
339
+ declare function runChecks(options: RunChecksOptions): Promise<CheckResult[]>;
340
+ /**
341
+ * ── You cannot prove "refuses bad input" without proving "accepts good input" ──
342
+ *
343
+ * Every rejection check above passes on a 4xx. **404 is a 4xx.** So an endpoint
344
+ * that does not exist satisfies "rejects invalid signature", "rejects stale
345
+ * timestamp", "rejects future timestamp" and "rejects malformed JSON" - and a
346
+ * 404 is fast, so it satisfies "responds within 10 seconds" too. Pointed at an
347
+ * offline ngrok tunnel on 5 Sep 2026 this reported FIVE PASSES, four of them
348
+ * security properties, against a host running nothing at all. The identical
349
+ * score comes back from `https://example.com/nothing`.
350
+ *
351
+ * A receiver holding the WRONG WEBHOOK SECRET is the same defect wearing a
352
+ * different status code: it 401s every request, including the well-formed one,
353
+ * and scores those same five. That is why the rule keys on whether anything was
354
+ * ACCEPTED rather than on which status codes look like "no endpoint here" -
355
+ * a list of such codes would have caught the 404 and waved the 401 through.
356
+ *
357
+ * Checks 11, 14 and 15 already guard on a `reachable` of `res !== null`. That
358
+ * instinct was right and the test was too weak: a 404 is a response, so
359
+ * `reachable` is true for it. This is the same guard at the strength it needed.
360
+ *
361
+ * An unproven check is NOT a pass. `passed` is forced to false, so the exit code
362
+ * is non-zero and a partner cannot self-certify against a wall. It is kept
363
+ * distinct from a fail because the receiver did not do anything wrong - there
364
+ * was simply nothing there to test, and telling someone their replay protection
365
+ * FAILED when it was never exercised sends them to debug working code.
366
+ */
367
+ declare function markUnprovenChecks(results: CheckResult[]): CheckResult[];
368
+
369
+ export { type CheckBasis, type CheckResult, type ConformanceKey, type ConformanceRun, DEFAULT_ACCOUNT_REF, DEFAULT_CONFORMANCE_KEY_ID, type RunChecksOptions, asConformanceKey, buildBody, markUnprovenChecks, runChecks, runChecksDetailed };