@oneaddress/conformance 2.0.0 → 3.0.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.
Files changed (3) hide show
  1. package/README.md +59 -3
  2. package/dist/index.js +352 -42
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -19,6 +19,40 @@ Runs a suite of end-to-end checks against a partner's webhook endpoint, covering
19
19
 
20
20
  Checks 9 and 10 are skipped unless `--customer-url` is provided.
21
21
 
22
+ ### Update kinds: what your receiver's code says it can take
23
+
24
+ A dispatch can carry a new address, a new phone number or a new email address.
25
+ Since 14 Aug 2026 the run has probed each contact kind you pass with `--accept`
26
+ (`check-contact-phone`, `check-contact-email`), sending a real contact-only
27
+ envelope announced as `contact.updated` and failing a receiver that
28
+ acknowledges it with `skipped: true`, which is a 200 with the value dropped.
29
+
30
+ A receiver on the current `@oneaddress/partner-sdk` also DECLARES, on every
31
+ authenticated acknowledgement, which kinds its code handles
32
+ (`accepted_update_types`, from the handler's `acceptedUpdateTypes` option).
33
+ The run reads that off `check-1` and adds:
34
+
35
+ - `check-kinds-declared`: the declaration is present and well-formed. A
36
+ receiver that makes none is not failed, but the run says so, because its
37
+ accept-set is then tested on trust.
38
+ - `check-kinds-consent-declared`: every kind in `--accept` (what a person
39
+ ticked in the partner portal) is also declared by the code. FAILS otherwise:
40
+ that is a dispatch that will be refused after the consumer has paid.
41
+ - `check-kinds-refuses-undeclared`: one kind the receiver did NOT declare is
42
+ sent and must be refused with a 4xx. This is the check that matters most: it
43
+ is the difference between a receiver that stores only what it promised and
44
+ one that acknowledges anything. Skipped for a receiver that made no
45
+ declaration, since check 7 requires such a receiver to acknowledge events it
46
+ does not recognise.
47
+
48
+ Contact kinds are probed only where `--accept` and the declaration agree, so a
49
+ kind the portal accepts but the code did not declare is reported once, by the
50
+ comparison, rather than probed into a second red row.
51
+
52
+ The partner portal's own conformance button runs the same checks with the same
53
+ ids and pass rules, reading the accept-set from your portal record instead of a
54
+ flag. A pass in one and a fail in the other is a bug in ours, not in yours.
55
+
22
56
  ## Installation
23
57
 
24
58
  ```bash
@@ -43,17 +77,39 @@ oneaddress-conformance test https://api.mycompany.com/oneaddress \
43
77
  oneaddress-conformance test https://api.mycompany.com/oneaddress \
44
78
  --secret whsec_xxx \
45
79
  --partner-id aaa... \
80
+ --public-key <base64-SPKI-of-your-ECDH-public-key> \
46
81
  --customer-url https://oneaddress.io
47
82
  ```
48
83
 
84
+ **All three credentials, or none.** A partial set is refused, and the refusal is
85
+ the point: supplying only the secret makes every signature check pass while the
86
+ payload stays sealed to this suite's built-in test key, so the failures land on
87
+ the acceptance checks and read as a decrypt fault in your receiver. Supplying
88
+ none is correct against a `npx @oneaddress/setup` scaffold, which is built
89
+ around those same test values. `--customer-url` only *adds* checks 9 and 10; the
90
+ webhook checks still encrypt to `--public-key`, which is why it belongs in the
91
+ pull-API example too.
92
+
93
+ The safer way to pass them keeps the secret out of your shell history and out of
94
+ `ps`, where any other process on the box can read it:
95
+
96
+ ```bash
97
+ export ONEADDRESS_WEBHOOK_SECRET=whsec_xxx
98
+ export ONEADDRESS_PARTNER_ID=aaa...
99
+ export ONEADDRESS_PUBLIC_KEY=MFkw...
100
+ oneaddress-conformance test https://api.mycompany.com/oneaddress --accept address,phone
101
+ ```
102
+
49
103
  ### Flags
50
104
 
51
105
  | Flag | Default | Purpose |
52
106
  |------|---------|---------|
53
- | `--secret` | Built-in synthetic test secret (used when partner is testing the wizard scaffold) | Your HMAC webhook secret |
54
- | `--partner-id` | Built-in test UUID | Your partner UUID |
55
- | `--public-key` | Built-in test ECDH SPKI | Your ECDH P-256 public key, base64 SPKI |
107
+ | `--secret` | Built-in synthetic test secret (used when partner is testing the wizard scaffold) | Your HMAC webhook secret. Also `ONEADDRESS_WEBHOOK_SECRET`. **Give all three of these or none** — a partial set is refused |
108
+ | `--partner-id` | Built-in test UUID | Your partner UUID. Also `ONEADDRESS_PARTNER_ID` |
109
+ | `--public-key` | Built-in test ECDH SPKI | Your ECDH P-256 public key, base64 SPKI. Also `ONEADDRESS_PUBLIC_KEY` |
56
110
  | `--customer-url` | — | Customer-app base URL; when set, adds pull-API checks |
111
+ | `--account-ref` | `CONF-0001` | The account reference every matching probe carries. Also `ONEADDRESS_ACCOUNT_REF`. Matters only if your receiver matches dispatches to your own customer records: it holds no `CONF-0001`, so it answers `no_match` — correctly — and the run cannot go green however good it is. Point this at a customer you already hold rather than writing test data into your system of record. The no-match probe does **not** derive from it; it sends `CONF-NOSUCH-<nonce>`, which cannot exist whatever you configure here |
112
+ | `--accept` | `address` | Comma-separated update kinds you accept in the partner portal (`address,phone,email`). Adds one contact probe per kind and is compared against what your receiver declares. Match it to the portal: the portal governs what OneAddress sends, this governs what gets tested. |
57
113
 
58
114
  ## Exit codes
59
115
 
package/dist/index.js CHANGED
@@ -3245,6 +3245,94 @@ async function encryptEnvelopeForPartner(payload, partner) {
3245
3245
  // ../protocol/src/types.ts
3246
3246
  var CURRENT_VERSION = "2026.1";
3247
3247
 
3248
+ // ../protocol/src/update-kinds.ts
3249
+ var UPDATE_KINDS = ["address", "phone", "email"];
3250
+ var CONTACT_KINDS = ["phone", "email"];
3251
+ function isUpdateKind(value) {
3252
+ return typeof value === "string" && UPDATE_KINDS.includes(value);
3253
+ }
3254
+ function normaliseUpdateKinds(raw) {
3255
+ const kept = new Set(
3256
+ (Array.isArray(raw) ? raw : []).filter((v) => typeof v === "string")
3257
+ );
3258
+ return UPDATE_KINDS.filter((k) => k === "address" || kept.has(k));
3259
+ }
3260
+ function readAcceptedUpdateKindsFromAck(body) {
3261
+ const none = (malformed = false) => ({
3262
+ declared: false,
3263
+ kinds: ["address"],
3264
+ malformed,
3265
+ ignored: []
3266
+ });
3267
+ let parsed = body;
3268
+ if (typeof body === "string") {
3269
+ try {
3270
+ parsed = JSON.parse(body);
3271
+ } catch {
3272
+ return none();
3273
+ }
3274
+ }
3275
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return none();
3276
+ const raw = parsed.accepted_update_types;
3277
+ if (raw === void 0 || raw === null) return none();
3278
+ if (!Array.isArray(raw)) return none(true);
3279
+ const ignored = [...new Set(
3280
+ raw.filter((v) => !isUpdateKind(v)).map((v) => typeof v === "string" ? v : JSON.stringify(v))
3281
+ )];
3282
+ return { declared: true, kinds: normaliseUpdateKinds(raw), malformed: false, ignored };
3283
+ }
3284
+ var UNDEFINED_PROBE_KIND = "conformance_undeclared_kind";
3285
+ function kindProbePlan(declaration, acceptedInPortal) {
3286
+ const accepted = normaliseUpdateKinds(acceptedInPortal).filter((k) => k !== "address");
3287
+ if (!declaration.declared) {
3288
+ return { accept: accepted, refuse: null, consentBeyondDeclaration: [] };
3289
+ }
3290
+ const declaredContact = declaration.kinds.filter((k) => k !== "address");
3291
+ const accept = accepted.filter((k) => declaredContact.includes(k));
3292
+ const consentBeyondDeclaration = accepted.filter((k) => !declaredContact.includes(k));
3293
+ const undeclared = CONTACT_KINDS.find((k) => !declaration.kinds.includes(k));
3294
+ return { accept, refuse: undeclared ?? UNDEFINED_PROBE_KIND, consentBeyondDeclaration };
3295
+ }
3296
+
3297
+ // ../protocol/src/d5-body.ts
3298
+ var D5_BODY_ALWAYS = [
3299
+ "event",
3300
+ "id_verification",
3301
+ "key_share_expiry",
3302
+ "oneaddress_version",
3303
+ "partner_id",
3304
+ "session_envelope",
3305
+ "session_key_share",
3306
+ "stripe_session_id",
3307
+ "timestamp",
3308
+ "update_id",
3309
+ "user_id"
3310
+ ];
3311
+ var D5_BODY_CONDITIONAL = {
3312
+ /**
3313
+ * The signed Letter of Authority, sealed to the same key_id as the session.
3314
+ * Present whenever the partner has a usable key — i.e. on every dispatch a
3315
+ * live partner receives. Omitted best-effort when no key is available, which
3316
+ * is a state a live partner is never in.
3317
+ */
3318
+ loa_encrypted: "partner has a usable encryption key",
3319
+ /**
3320
+ * The shared webhook event id. Set ONLY on a key-crossover copy, where every
3321
+ * copy of one update carries the same id so a receiver holding more than one
3322
+ * rotation key applies it once. Absent on an ordinary dispatch, whose
3323
+ * receiver idempotency falls back to the `X-OneAddress-Dispatch` header.
3324
+ */
3325
+ id: "key-crossover copy only",
3326
+ /** The sibling marker naming the other key_ids this update was sealed to. */
3327
+ crossover_key_ids: "key-crossover copy only"
3328
+ };
3329
+ var D5_BODY_DRILL_ONLY = ["conformance"];
3330
+ var D5_BODY_ALL_ALLOWED = [
3331
+ ...D5_BODY_ALWAYS,
3332
+ ...Object.keys(D5_BODY_CONDITIONAL),
3333
+ ...D5_BODY_DRILL_ONLY
3334
+ ];
3335
+
3248
3336
  // src/credentials.ts
3249
3337
  var TEST_WEBHOOK_SECRET = (
3250
3338
  // NOSONAR — intentional test credential, not a real secret
@@ -3268,6 +3356,11 @@ function buildHeaders(partnerId, timestamp, signature, dispatchId, event = "addr
3268
3356
  "X-OneAddress-Dispatch": dispatchId
3269
3357
  };
3270
3358
  }
3359
+ var DEFAULT_ACCOUNT_REF = "CONF-0001";
3360
+ var CONFORMANCE_USER_ID = "conformance:drill";
3361
+ function conformanceUpdateId() {
3362
+ return import_node_crypto.default.randomInt(9e8, 901e6);
3363
+ }
3271
3364
  async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address", identity) {
3272
3365
  const partnerKey = {
3273
3366
  partner_id: partnerId,
@@ -3276,7 +3369,8 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3276
3369
  algorithm: "ECDH-P256-AES-GCM-256"
3277
3370
  };
3278
3371
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
3279
- const updateUid = import_node_crypto.default.randomUUID();
3372
+ const updateIdNum = conformanceUpdateId();
3373
+ const updateUid = String(updateIdNum);
3280
3374
  const sessionData = {
3281
3375
  v: 2,
3282
3376
  update_uid: updateUid,
@@ -3294,7 +3388,7 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3294
3388
  ...kind === "phone" ? { new_phone: "+61412345678" } : {},
3295
3389
  ...kind === "email" ? { new_email: "conformance@example.com" } : {},
3296
3390
  update_types: [kind],
3297
- account_number: "CONF-0001",
3391
+ account_number: DEFAULT_ACCOUNT_REF,
3298
3392
  id_verification_ref: import_node_crypto.default.randomUUID(),
3299
3393
  known_names: ["Conformance Tester"],
3300
3394
  // Applied last so an override wins over the defaults above, including
@@ -3319,20 +3413,79 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3319
3413
  // bearing dispatch stays `address.updated` for every existing integration.
3320
3414
  event: kind === "address" ? "address.updated" : "contact.updated",
3321
3415
  oneaddress_version: CURRENT_VERSION,
3322
- version: CURRENT_VERSION,
3323
- id: import_node_crypto.default.randomUUID(),
3324
- update_id: updateUid,
3325
- timestamp: String(Math.floor(Date.now() / 1e3)),
3416
+ /**
3417
+ * ── THIS LIST IS THE D5 CONTRACT (`D5_BODY_ALWAYS`), NOT AN APPROXIMATION ─
3418
+ *
3419
+ * Measured on 25 Sep 2026 by executing this builder beside the relay's own
3420
+ * `composeD5OutgoingPayload`, it sent `version`, `id` and
3421
+ * `encryption_status`, which no D5 dispatch carries; omitted `user_id`,
3422
+ * `key_share_expiry`, `id_verification` and `stripe_session_id`, which every
3423
+ * one carries; sent `update_id` as a UUID where the relay sends the integer
3424
+ * `user_updates.id`; and sent `timestamp` as Unix-epoch seconds where the
3425
+ * relay sends ISO 8601 — the header's format, in the body, which is how the
3426
+ * mistake happened.
3427
+ *
3428
+ * Three of those fail in the silent direction. A receiver gated on
3429
+ * `encryption_status === 'encrypted'`, pinned to `body.version`, or keyed
3430
+ * for idempotency on `body.id` passed this suite and would then have
3431
+ * dropped — or double-written — every real update.
3432
+ *
3433
+ * `src/__tests__/body-contract.test.ts` executes this function and compares
3434
+ * it against `@oneaddress/protocol`'s lists; the customer app executes the
3435
+ * RELAY against the same lists. Neither half can bless a drift on its own.
3436
+ */
3437
+ update_id: updateIdNum,
3326
3438
  partner_id: partnerId,
3439
+ // Real on every dispatch. A drill has no consumer, so it announces itself
3440
+ // under a reserved subject rather than omitting the key and teaching a
3441
+ // receiver that the field is optional.
3442
+ user_id: CONFORMANCE_USER_ID,
3443
+ timestamp: nowIso,
3327
3444
  // D5 per-partner encrypted address envelope (identity is INSIDE it).
3328
3445
  session_envelope: envelope.session_envelope,
3329
3446
  session_key_share: envelope.session_key_share,
3447
+ key_share_expiry: new Date(Date.now() + 90 * 24 * 60 * 60 * 1e3).toISOString(),
3448
+ id_verification: {
3449
+ method: "identity_document",
3450
+ verified_at: nowIso,
3451
+ verified: true,
3452
+ platform: "oneaddress/v1"
3453
+ },
3330
3454
  // D5 per-partner encrypted signed LOA. No cleartext letter_of_authority.
3331
3455
  loa_encrypted: {
3332
3456
  session_envelope: loaEnvelope.session_envelope,
3333
3457
  session_key_share: loaEnvelope.session_key_share
3334
3458
  },
3335
- encryption_status: "encrypted",
3459
+ // On the wire with a `null` value when no PaymentIntent backed the update,
3460
+ // so the KEY is what a receiver sees either way.
3461
+ stripe_session_id: null,
3462
+ /**
3463
+ * THIS DISPATCH IS A DRILL, AND IT SAYS SO IN THE SIGNED BODY.
3464
+ *
3465
+ * Check 11 sends a payload the receiver CANNOT open, deliberately, and
3466
+ * passes the receiver for refusing it. A receiver that quarantines held
3467
+ * dispatches therefore ends a SUCCESSFUL conformance run with a red fault
3468
+ * panel, a `failed` counter that never returns to zero, and a `decrypt_failed`
3469
+ * line naming the partner's real `key_id`. Reported from a real run: the
3470
+ * dashboard said the receiver was broken at the moment it proved it was not.
3471
+ *
3472
+ * WHY THE BODY AND NOT THE DISPATCH-ID HEADER. `X-OneAddress-Dispatch`
3473
+ * carries a recognisable prefix already (`undecryptable-…`) and keying off it
3474
+ * would be wrong: the HMAC covers `${timestamp}.${rawBody}` and NOTHING ELSE,
3475
+ * so every header except the timestamp is outside the signature and anything
3476
+ * on the path can change it without invalidating anything. A marker that
3477
+ * changes how an operator's fault panel behaves has to be inside the signed
3478
+ * material. This field is.
3479
+ *
3480
+ * PRECEDENT: `crossover_key_ids` (check 15) is already a signed-body field
3481
+ * that tells a receiver how to treat a payload it cannot decrypt. Same shape,
3482
+ * different cause.
3483
+ *
3484
+ * Sent on EVERY conformance body, not only the undecryptable one, because a
3485
+ * receiver has a legitimate interest in knowing which of its stored records
3486
+ * came from a drill rather than from a consumer.
3487
+ */
3488
+ conformance: true,
3336
3489
  ...extraFields
3337
3490
  });
3338
3491
  }
@@ -3348,9 +3501,10 @@ async function post(url, body, headers, timeoutMs = 12e3) {
3348
3501
  signal: controller.signal,
3349
3502
  redirect: "error"
3350
3503
  });
3351
- return { status: res.status, durationMs: Date.now() - start };
3504
+ const text = await res.text().catch(() => "");
3505
+ return { status: res.status, durationMs: Date.now() - start, body: text };
3352
3506
  } catch (err) {
3353
- return { status: 0, durationMs: Date.now() - start, error: String(err) };
3507
+ return { status: 0, durationMs: Date.now() - start, body: "", error: String(err) };
3354
3508
  } finally {
3355
3509
  clearTimeout(timer);
3356
3510
  }
@@ -3385,6 +3539,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3385
3539
  let acceptedUpdateTypes = [];
3386
3540
  let verifiesAccountReference = false;
3387
3541
  let supportsKeyCrossover = false;
3542
+ let accountRef = DEFAULT_ACCOUNT_REF;
3388
3543
  if (typeof urlOrOptions === "object") {
3389
3544
  targetUrl = urlOrOptions.targetUrl;
3390
3545
  secret = urlOrOptions.secret ?? TEST_WEBHOOK_SECRET;
@@ -3394,16 +3549,22 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3394
3549
  acceptedUpdateTypes = urlOrOptions.acceptedUpdateTypes ?? [];
3395
3550
  verifiesAccountReference = urlOrOptions.verifiesAccountReference === true;
3396
3551
  supportsKeyCrossover = urlOrOptions.supportsKeyCrossover === true;
3552
+ accountRef = urlOrOptions.accountRef?.trim() || DEFAULT_ACCOUNT_REF;
3397
3553
  } else {
3398
3554
  targetUrl = urlOrOptions;
3399
3555
  }
3400
3556
  const results = [];
3401
- const sharedBody = await buildBody(partnerId, publicKeyB64);
3557
+ const matchable = { account_number: accountRef };
3558
+ const sharedBody = await buildBody(partnerId, publicKeyB64, void 0, "address", matchable);
3559
+ let declaration = readAcceptedUpdateKindsFromAck(null);
3560
+ let check1Accepted;
3402
3561
  {
3403
3562
  const ts = String(Math.floor(Date.now() / 1e3));
3404
3563
  const sig = sign(sharedBody, ts, secret);
3405
- const { status, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "1"));
3564
+ const { status, error, body: ackBody } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "1"));
3406
3565
  const passed = !error && status >= 200 && status < 300;
3566
+ check1Accepted = passed;
3567
+ if (passed) declaration = readAcceptedUpdateKindsFromAck(ackBody);
3407
3568
  results.push({
3408
3569
  id: "check-1",
3409
3570
  basis: "acceptance",
@@ -3466,7 +3627,13 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3466
3627
  });
3467
3628
  }
3468
3629
  {
3469
- const futureBody = await buildBody(partnerId, publicKeyB64, { future_field: "ignored", future_object: { x: 1 } });
3630
+ const futureBody = await buildBody(
3631
+ partnerId,
3632
+ publicKeyB64,
3633
+ { future_field: "ignored", future_object: { x: 1 } },
3634
+ "address",
3635
+ matchable
3636
+ );
3470
3637
  const ts = String(Math.floor(Date.now() / 1e3));
3471
3638
  const sig = sign(futureBody, ts, secret);
3472
3639
  const { status, error } = await post(targetUrl, futureBody, buildHeaders(partnerId, ts, sig, "6"));
@@ -3483,9 +3650,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3483
3650
  const unknownBody = JSON.stringify({
3484
3651
  event: "address.future_event",
3485
3652
  oneaddress_version: CURRENT_VERSION,
3486
- version: CURRENT_VERSION,
3487
- id: import_node_crypto.default.randomUUID(),
3488
- timestamp: String(Math.floor(Date.now() / 1e3)),
3653
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3489
3654
  partner_id: partnerId
3490
3655
  });
3491
3656
  const ts = String(Math.floor(Date.now() / 1e3));
@@ -3598,7 +3763,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3598
3763
  basis: "rejection",
3599
3764
  label: "Reports undecryptable payload as a failure (not 200 ok:true)",
3600
3765
  passed,
3601
- detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${bodyFailure ? " with ok:false" : ""} \u2014 correctly reported as a failed delivery` : `HTTP ${status} without ok:false \u2014 a payload this receiver CANNOT decrypt was reported as delivered. OneAddress will mark it delivered and never retry it. Return a 4xx/5xx, or 200 with { ok: false }, when decryption fails.`
3766
+ detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${bodyFailure ? " with ok:false" : ""} \u2014 correctly reported as a failed delivery. This probe is now held by your receiver, which is how the check was passed: it is one undecryptable dispatch, not a fault in your setup. Clear it with [d] on the dashboard.` : `HTTP ${status} without ok:false \u2014 a payload this receiver CANNOT decrypt was reported as delivered. OneAddress will mark it delivered and never retry it. Return a 4xx/5xx, or 200 with { ok: false }, when decryption fails.`
3602
3767
  });
3603
3768
  }
3604
3769
  if (verifiesAccountReference) {
@@ -3631,14 +3796,24 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3631
3796
  basis: "rejection",
3632
3797
  label: "Refuses an account reference that matches no record (no name fallback)",
3633
3798
  passed,
3634
- detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Report it as a failure so the consumer is told, which is what they were promised before they paid.`
3799
+ detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Answer the webhook with ok:false so the consumer is told, which is what they were promised before they paid, and confirm the dispatch as "no_match" rather than "failed": "failed" means YOUR system broke and makes the update refundable at your expense, while "no_match" says the person is simply not on your books. This check reads the webhook response only, so it cannot see which status you send; getting it wrong costs you money rather than failing here.
3800
+
3801
+ THERE IS A SECOND READING, and it is the likelier one on a first run: if this receiver does not match dispatches to customer records AT ALL \u2014 no lookup configured, it just queues what arrives \u2014 then the FLAG is wrong, not the receiver. This check asks a question only a matching receiver can answer, so drop --verifies-account-reference (and untick the same declaration in your partner portal, so the two agree) and run again. Nothing out here can tell the two apart: both look like ok:true to an unmatchable reference.`
3635
3802
  });
3636
3803
  }
3804
+ const plan = kindProbePlan(declaration, acceptedUpdateTypes);
3805
+ results.push({
3806
+ id: "check-kinds-declared",
3807
+ basis: "declaration",
3808
+ label: "Declares the update kinds its code accepts (accepted_update_types on the ack)",
3809
+ passed: check1Accepted && !declaration.malformed,
3810
+ detail: !check1Accepted ? "No acknowledgement to read: check-1 did not pass." : declaration.malformed ? "accepted_update_types was present but not an array. That is a broken receiver, not an older one: the field must be a list of kinds (address, phone, email)." : !declaration.declared ? "No declaration on the acknowledgement. This receiver predates capability declarations, so the kinds accepted in the partner portal are tested on trust and cannot be refused by the receiver when undeclared. Upgrade @oneaddress/partner-sdk and set acceptedUpdateTypes." : `Declares: ${declaration.kinds.join(", ")}` + (declaration.ignored.length > 0 ? `. Also named ${declaration.ignored.join(", ")}, which this tool does not define and did not record (newer SDK than conformance tool?).` : ".")
3811
+ });
3637
3812
  {
3638
- const contactKinds = ["phone", "email"].filter((k) => acceptedUpdateTypes.includes(k));
3813
+ const contactKinds = plan.accept;
3639
3814
  for (const kind of contactKinds) {
3640
3815
  const article = kind === "email" ? "an" : "a";
3641
- const body = await buildBody(partnerId, publicKeyB64, void 0, kind);
3816
+ const body = await buildBody(partnerId, publicKeyB64, void 0, kind, matchable);
3642
3817
  const ts = String(Math.floor(Date.now() / 1e3));
3643
3818
  const sig = sign(body, ts, secret);
3644
3819
  const res = await fetch(targetUrl, {
@@ -3671,16 +3846,52 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3671
3846
  parsed = JSON.parse(bodyText);
3672
3847
  } catch {
3673
3848
  }
3674
- const passed = res !== null && status >= 200 && status < 300 && parsed.ok !== false && parsed.skipped !== true;
3849
+ const refusedForItsAccount = verifiesAccountReference && parsed.ok === false && parsed.error === "account_not_matched";
3850
+ const passed = res !== null && status >= 200 && status < 300 && (parsed.ok !== false || refusedForItsAccount) && parsed.skipped !== true;
3675
3851
  results.push({
3676
3852
  id: `check-contact-${kind}`,
3677
3853
  basis: "acceptance",
3678
3854
  label: `Accepts ${article} ${kind}-only update (no address in the envelope)`,
3679
3855
  passed,
3680
- detail: res === null ? "Network error: no response" : passed ? `HTTP ${status} \u2014 accepted. NOTE: this proves the envelope was accepted, not that the ${kind} was stored. Confirm your outbox has a column for it.` : parsed.skipped === true ? `HTTP ${status} with skipped:true \u2014 this receiver ACKNOWLEDGED the update and stored nothing. It is treating '${"contact.updated"}' as an unknown event, which means it predates contact updates. Upgrade it, or narrow your accept-set in the partner portal until you have. A 200 here would otherwise look identical to a delivery.` : `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 this receiver did not accept ${article} ${kind}-only update, but your OneAddress accept-set says you take them. A contact update carries NO new_address: code that reads it unguarded will throw. Either handle the absent address, or narrow your accept-set in the partner portal.`
3856
+ detail: res === null ? "Network error: no response" : passed && refusedForItsAccount ? `HTTP ${status} with ok:false (account_not_matched) \u2014 handled. This probe's account is not one of yours, and you check the account reference, so refusing it is correct. It shows the envelope with no address was read and not thrown on; it does not show the ${kind} is stored.` : passed ? `HTTP ${status} \u2014 accepted. NOTE: this proves the envelope was accepted, not that the ${kind} was stored. Confirm your outbox has a column for it.` : parsed.skipped === true ? `HTTP ${status} with skipped:true \u2014 this receiver ACKNOWLEDGED the update and stored nothing. It is treating '${"contact.updated"}' as an unknown event, which means it predates contact updates. Upgrade it, or narrow your accept-set in the partner portal until you have. A 200 here would otherwise look identical to a delivery.` : `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 this receiver did not accept ${article} ${kind}-only update, but your OneAddress accept-set says you take them. A contact update carries NO new_address: code that reads it unguarded will throw. Either handle the absent address, or narrow your accept-set in the partner portal.`
3681
3857
  });
3682
3858
  }
3683
3859
  }
3860
+ results.push({
3861
+ id: "check-kinds-consent-declared",
3862
+ basis: "declaration",
3863
+ label: "Every kind accepted in the partner portal is declared by the receiver",
3864
+ passed: plan.consentBeyondDeclaration.length === 0,
3865
+ detail: !declaration.declared ? "Nothing to compare: the receiver made no declaration (see check-kinds-declared)." : plan.consentBeyondDeclaration.length === 0 ? `Portal accepts ${["address", ...plan.accept].join(", ")}; the receiver declares ${declaration.kinds.join(", ")}.` : `The portal accepts ${plan.consentBeyondDeclaration.join(" and ")} but the receiver's code declares only ${declaration.kinds.join(", ")}. A dispatch of that kind would be refused (422) and retried until it gave up, after the consumer had paid. Narrow the accept-set in the partner portal, or widen acceptedUpdateTypes once onUpdate stores the value.`
3866
+ });
3867
+ if (plan.refuse !== null) {
3868
+ const probe = plan.refuse;
3869
+ const body = await buildBody(partnerId, publicKeyB64, void 0, probe, matchable);
3870
+ const ts = String(Math.floor(Date.now() / 1e3));
3871
+ const sig = sign(body, ts, secret);
3872
+ const res = await fetch(targetUrl, {
3873
+ method: "POST",
3874
+ headers: buildHeaders(
3875
+ partnerId,
3876
+ ts,
3877
+ sig,
3878
+ `refuse-${probe}-${import_node_crypto.default.randomUUID().slice(0, 8)}`,
3879
+ "contact.updated"
3880
+ ),
3881
+ body,
3882
+ signal: AbortSignal.timeout(12e3)
3883
+ }).catch(() => null);
3884
+ const status = res?.status ?? 0;
3885
+ if (res) await res.text().catch(() => "");
3886
+ const passed = res !== null && status >= 400 && status < 500;
3887
+ results.push({
3888
+ id: "check-kinds-refuses-undeclared",
3889
+ basis: "rejection",
3890
+ label: `Refuses an update kind it did not declare (${probe})`,
3891
+ passed,
3892
+ detail: res === null ? "Network error: no response" : passed ? `HTTP ${status}, a dispatch carrying an undeclared kind was refused, so nothing it did not promise to handle can be acknowledged and dropped.` : `HTTP ${status}, this receiver ACKNOWLEDGED a dispatch carrying a kind (${probe}) it never declared. That is the silent-loss shape: the consumer is told the update was delivered and the value went nowhere. Refuse it with a 4xx (the SDK answers 422 update_type_not_accepted) so OneAddress retries once you have widened acceptedUpdateTypes.`
3893
+ });
3894
+ }
3684
3895
  if (supportsKeyCrossover) {
3685
3896
  const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
3686
3897
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
@@ -3792,10 +4003,10 @@ function markUnprovenChecks(results) {
3792
4003
  }
3793
4004
 
3794
4005
  // src/report.ts
3795
- var PASS = "\u2705";
3796
- var FAIL = "\u274C";
3797
- var UNPROVEN = "\u2754";
3798
- var ICON_COLUMNS = 2;
4006
+ var PASS = "\u2713";
4007
+ var FAIL = "\u2717";
4008
+ var UNPROVEN = "?";
4009
+ var ICON_COLUMNS = 1;
3799
4010
  function verdictOf(r) {
3800
4011
  if (r.unproven) return { icon: UNPROVEN, status: "UNPROVEN" };
3801
4012
  return r.passed ? { icon: PASS, status: "PASSED" } : { icon: FAIL, status: "FAILED" };
@@ -3850,6 +4061,12 @@ function exitCode(results) {
3850
4061
  }
3851
4062
 
3852
4063
  // src/resolve-credentials.ts
4064
+ var import_node_crypto2 = require("crypto");
4065
+ var FLAG_FOR = {
4066
+ ONEADDRESS_WEBHOOK_SECRET: "--secret",
4067
+ ONEADDRESS_PARTNER_ID: "--partner-id",
4068
+ ONEADDRESS_PUBLIC_KEY: "--public-key"
4069
+ };
3853
4070
  function resolveOne(flag, envVar, env, fallback) {
3854
4071
  if (flag !== void 0 && flag !== "") return { value: flag, source: "flag", envVar };
3855
4072
  const fromEnv = env[envVar]?.trim();
@@ -3872,6 +4089,66 @@ function resolveCredentials(flags, env = process.env) {
3872
4089
  allBuiltIn: [secret, partnerId, publicKeyB64].every((c) => c.source === "built-in test value")
3873
4090
  };
3874
4091
  }
4092
+ function publicKeyProblem(c) {
4093
+ const cred = c.publicKeyB64;
4094
+ if (cred.source === "built-in test value") return null;
4095
+ const where = `${cred.envVar} (--public-key)`;
4096
+ if (/BEGIN[^-]*PRIVATE/.test(cred.value)) {
4097
+ return `${where} is a PRIVATE key. That one belongs on your RECEIVER and must never leave it; this flag takes the PUBLIC half, as base64 of the DER SPKI form.`;
4098
+ }
4099
+ let der;
4100
+ try {
4101
+ der = Buffer.from(cred.value, "base64");
4102
+ if (der.length === 0 || der.toString("base64").replace(/=+$/, "") !== cred.value.trim().replace(/=+$/, "")) {
4103
+ return `${where} is not valid base64. Copy it again from your partner portal \u2014 a line break or a stray space is the usual cause.`;
4104
+ }
4105
+ } catch {
4106
+ return `${where} is not valid base64.`;
4107
+ }
4108
+ try {
4109
+ const key = (0, import_node_crypto2.createPublicKey)({ key: der, format: "der", type: "spki" });
4110
+ if (key.asymmetricKeyType !== "ec") {
4111
+ return `${where} is a ${key.asymmetricKeyType ?? "non-EC"} key. OneAddress envelopes use ECDH P-256, so this key cannot unwrap them.`;
4112
+ }
4113
+ const curve = key.asymmetricKeyDetails?.namedCurve;
4114
+ if (curve && curve !== "prime256v1") {
4115
+ return `${where} is on curve ${curve}, not P-256 (prime256v1).`;
4116
+ }
4117
+ } catch {
4118
+ return `${where} is valid base64 but not an SPKI public key. Expect the BASE64 of the DER SPKI form \u2014 not a PEM, not a private key, and not the key id.`;
4119
+ }
4120
+ return null;
4121
+ }
4122
+ function partialCredentials(c) {
4123
+ if (c.allBuiltIn) return [];
4124
+ return [c.secret, c.partnerId, c.publicKeyB64].filter((x) => x.source === "built-in test value");
4125
+ }
4126
+ function partialCredentialRefusal(c) {
4127
+ const missing = partialCredentials(c);
4128
+ if (missing.length === 0) return null;
4129
+ const named = missing.map((x) => `${x.envVar} (${FLAG_FOR[x.envVar]})`);
4130
+ return [
4131
+ "\u2717 INCOMPLETE CREDENTIALS \u2014 refusing to run.",
4132
+ "",
4133
+ `Some credentials were supplied and some were not: ${named.join(", ")} ${missing.length === 1 ? "is" : "are"} still a built-in test value.`,
4134
+ "",
4135
+ "Against a real receiver a partial set fails the same way a WRONG one does:",
4136
+ "the signature checks pass, so the run looks half-healthy, while the payload",
4137
+ "is sealed to this suite's test key that your receiver cannot decrypt. The",
4138
+ "failures land on the acceptance checks and read as a fault in your code.",
4139
+ "",
4140
+ "Supply all three, or none:",
4141
+ "",
4142
+ " export ONEADDRESS_WEBHOOK_SECRET=whsec_...",
4143
+ " export ONEADDRESS_PARTNER_ID=...",
4144
+ " export ONEADDRESS_PUBLIC_KEY=...",
4145
+ "",
4146
+ "Supplying none is correct for a scaffold from `npx @oneaddress/setup`,",
4147
+ "which is built around the same test values. If you truly mean the test",
4148
+ "value for one of these, pass it explicitly and this will run.",
4149
+ ""
4150
+ ];
4151
+ }
3875
4152
  function describeCredentials(c) {
3876
4153
  if (c.allBuiltIn) {
3877
4154
  return [
@@ -3882,19 +4159,15 @@ function describeCredentials(c) {
3882
4159
  "around these same values. A REAL receiver will reject every request, including",
3883
4160
  "the well-formed one, because it validates against its own secret. Your partner",
3884
4161
  "portal has the values, and the safer way to pass them keeps the secret out of",
3885
- "your shell history and out of `ps`:",
4162
+ "your shell history and out of `ps`. ALL THREE, or the run is refused:",
3886
4163
  "",
3887
4164
  " export ONEADDRESS_WEBHOOK_SECRET=whsec_...",
4165
+ " export ONEADDRESS_PARTNER_ID=...",
4166
+ " export ONEADDRESS_PUBLIC_KEY=...",
3888
4167
  ""
3889
4168
  ];
3890
4169
  }
3891
- const missing = [c.secret, c.partnerId, c.publicKeyB64].filter((x) => x.source === "built-in test value").map((x) => x.envVar);
3892
- if (missing.length === 0) return [];
3893
- return [
3894
- `Some credentials were supplied and some were not: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} still a built-in test value.`,
3895
- "Against a real receiver a partial set fails the same way a wrong one does.",
3896
- ""
3897
- ];
4170
+ return [];
3898
4171
  }
3899
4172
 
3900
4173
  // src/index.ts
@@ -3911,7 +4184,16 @@ Options:
3911
4184
  ONEADDRESS_WEBHOOK_SECRET same as --secret
3912
4185
  ONEADDRESS_PARTNER_ID same as --partner-id
3913
4186
  ONEADDRESS_PUBLIC_KEY same as --public-key
4187
+ Supply ALL THREE or none: a partial set is refused, because it passes every
4188
+ signature check while the payload stays sealed to the built-in test key, so
4189
+ the failures land on the acceptance checks and read as a fault in your code.
3914
4190
  --customer-url <url> Customer app URL for pull API checks (adds checks 9 + 10)
4191
+ --account-ref <ref> The account reference the dispatches carry (default: CONF-0001,
4192
+ which every scaffold seeds). Only matters if your receiver
4193
+ matches dispatches to your own customer records: it holds no
4194
+ CONF-0001, so it answers no_match \u2014 correctly \u2014 and the run
4195
+ cannot go green. Point this at a customer you already hold
4196
+ rather than writing test data into your system of record.
3915
4197
  --accept <kinds> Comma-separated update kinds you accept: address,phone,email.
3916
4198
  Adds a check per contact kind. Match this to your accept-set
3917
4199
  in the partner portal \u2014 a phone update carries NO address,
@@ -3927,15 +4209,20 @@ Options:
3927
4209
  report a defect it cannot have.
3928
4210
 
3929
4211
  Example:
4212
+ # The wizard scaffold: no credentials at all, which is a meaningful run
3930
4213
  oneaddress-conformance test http://localhost:3001/webhook
3931
- ONEADDRESS_WEBHOOK_SECRET=whsec_xxx oneaddress-conformance test https://api.mycompany.com/oneaddress
3932
- oneaddress-conformance test https://api.mycompany.com/oneaddress --secret whsec_real_xxx
3933
- oneaddress-conformance test https://api.mycompany.com/oneaddress \\
3934
- --secret whsec_xxx --accept address,phone
3935
- oneaddress-conformance test https://api.mycompany.com/oneaddress \\
3936
- --secret whsec_xxx --verifies-account-reference
4214
+
4215
+ # A real receiver: all three, kept out of argv and shell history
4216
+ export ONEADDRESS_WEBHOOK_SECRET=whsec_xxx
4217
+ export ONEADDRESS_PARTNER_ID=aaa...
4218
+ export ONEADDRESS_PUBLIC_KEY=MFkw...
4219
+ oneaddress-conformance test https://api.mycompany.com/oneaddress --accept address,phone
4220
+ oneaddress-conformance test https://api.mycompany.com/oneaddress --verifies-account-reference
4221
+ oneaddress-conformance test https://api.mycompany.com/oneaddress --customer-url https://oneaddress.io
4222
+
4223
+ # The same on one line, if you accept the secret landing in \`ps\`
3937
4224
  oneaddress-conformance test https://api.mycompany.com/oneaddress \\
3938
- --secret whsec_xxx --partner-id aaa... --customer-url https://oneaddress.io
4225
+ --secret whsec_xxx --partner-id aaa... --public-key MFkw...
3939
4226
  `.trim();
3940
4227
  async function main() {
3941
4228
  const args = process.argv.slice(2);
@@ -3957,6 +4244,7 @@ async function main() {
3957
4244
  const partnerId = creds.partnerId.value;
3958
4245
  const publicKey = creds.publicKeyB64.value;
3959
4246
  const customerUrl = getFlag("--customer-url");
4247
+ const accountRef = getFlag("--account-ref")?.trim() || process.env.ONEADDRESS_ACCOUNT_REF?.trim() || DEFAULT_ACCOUNT_REF;
3960
4248
  const acceptedUpdateTypes = (getFlag("--accept") ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
3961
4249
  const verifiesAccountReference = args.includes("--verifies-account-reference");
3962
4250
  const UNKNOWN = acceptedUpdateTypes.filter((t) => !["address", "phone", "email"].includes(t));
@@ -3991,7 +4279,28 @@ async function main() {
3991
4279
  process.exit(1);
3992
4280
  }
3993
4281
  if (parsedTarget.protocol === "http:" && isLocalhost) {
3994
- console.warn("\n \u26A0 HTTP detected \u2014 acceptable for local testing only.\n");
4282
+ console.warn("\n ! HTTP detected \u2014 acceptable for local testing only.\n");
4283
+ }
4284
+ const refusal = partialCredentialRefusal(creds);
4285
+ if (refusal) {
4286
+ console.error("");
4287
+ for (const line of refusal) console.error(line ? ` ${line}` : "");
4288
+ process.exit(1);
4289
+ }
4290
+ const keyProblem = publicKeyProblem(creds);
4291
+ if (keyProblem) {
4292
+ console.error("");
4293
+ console.error(" \u2717 UNUSABLE PUBLIC KEY \u2014 refusing to run.");
4294
+ console.error("");
4295
+ console.error(` ${keyProblem}`);
4296
+ console.error("");
4297
+ process.exit(1);
4298
+ }
4299
+ if (verifiesAccountReference) {
4300
+ console.log(
4301
+ accountRef === DEFAULT_ACCOUNT_REF ? ` This run sends account reference ${DEFAULT_ACCOUNT_REF}. Your receiver matches references itself, so it needs a customer with that reference, or pass --account-ref <one of yours>.` : ` Account reference: ${accountRef}. It must exist in your system of record, or the matching checks fail on a receiver that is behaving correctly.`
4302
+ );
4303
+ console.log("");
3995
4304
  }
3996
4305
  console.log(`
3997
4306
  Running conformance checks against: ${targetUrl}`);
@@ -4005,7 +4314,8 @@ Running conformance checks against: ${targetUrl}`);
4005
4314
  publicKeyB64: publicKey,
4006
4315
  customerUrl,
4007
4316
  acceptedUpdateTypes,
4008
- verifiesAccountReference
4317
+ verifiesAccountReference,
4318
+ accountRef
4009
4319
  });
4010
4320
  printReport(results);
4011
4321
  const code = exitCode(results);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaddress/conformance",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Conformance test tool for OneAddress partner integrations",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {