@oneaddress/conformance 3.1.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.
package/dist/index.js CHANGED
@@ -3375,15 +3375,24 @@ function buildHeaders(partnerId, timestamp, signature, dispatchId, event = "addr
3375
3375
  };
3376
3376
  }
3377
3377
  var DEFAULT_ACCOUNT_REF = "CONF-0001";
3378
+ var DEFAULT_CONFORMANCE_KEY_ID = "conformance-key-1";
3379
+ function asConformanceKey(key) {
3380
+ if (!key) return null;
3381
+ if (typeof key === "string") {
3382
+ return { keyId: DEFAULT_CONFORMANCE_KEY_ID, publicKeyB64: key };
3383
+ }
3384
+ return key;
3385
+ }
3378
3386
  var CONFORMANCE_USER_ID = "conformance:drill";
3379
3387
  function conformanceUpdateId() {
3380
3388
  return import_node_crypto.default.randomInt(9e8, 901e6);
3381
3389
  }
3382
3390
  async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address", identity, retentionPeriodDays = DEFAULT_RETENTION_DAYS) {
3383
- const partnerKey = {
3391
+ const key = asConformanceKey(publicKeyB64);
3392
+ const partnerKey = key && {
3384
3393
  partner_id: partnerId,
3385
- key_id: "conformance-key-1",
3386
- public_key_b64: publicKeyB64,
3394
+ key_id: key.keyId,
3395
+ public_key_b64: key.publicKeyB64,
3387
3396
  algorithm: "ECDH-P256-AES-GCM-256"
3388
3397
  };
3389
3398
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
@@ -3413,7 +3422,7 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3413
3422
  // `verified_name`, which is set before the address block.
3414
3423
  ...identity ?? {}
3415
3424
  };
3416
- const envelope = await encryptSessionForPartner(sessionData, partnerKey);
3425
+ const envelope = partnerKey ? await encryptSessionForPartner(sessionData, partnerKey) : { session_envelope: null, session_key_share: null };
3417
3426
  const loa = {
3418
3427
  consumer_name: "Conformance Test",
3419
3428
  authorisation_date: nowIso,
@@ -3424,7 +3433,7 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3424
3433
  // placeholder r||s hex (128 chars)
3425
3434
  signature_algorithm: "ECDSA-P256"
3426
3435
  };
3427
- const loaEnvelope = await encryptEnvelopeForPartner(loa, partnerKey);
3436
+ const loaEnvelope = partnerKey ? await encryptEnvelopeForPartner(loa, partnerKey) : null;
3428
3437
  return JSON.stringify({
3429
3438
  // Body event and `X-OneAddress-Event` must agree — the relay derives both
3430
3439
  // from the same rule, and a receiver may route on either. An address-
@@ -3472,10 +3481,14 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
3472
3481
  platform: "oneaddress/v1"
3473
3482
  },
3474
3483
  // D5 per-partner encrypted signed LOA. No cleartext letter_of_authority.
3475
- loa_encrypted: {
3476
- session_envelope: loaEnvelope.session_envelope,
3477
- session_key_share: loaEnvelope.session_key_share
3478
- },
3484
+ // Omitted entirely with no key: there is nothing to seal it to, and an
3485
+ // unencrypted authorisation is not a thing this protocol has.
3486
+ ...loaEnvelope ? {
3487
+ loa_encrypted: {
3488
+ session_envelope: loaEnvelope.session_envelope,
3489
+ session_key_share: loaEnvelope.session_key_share
3490
+ }
3491
+ } : {},
3479
3492
  // On the wire with a `null` value when no PaymentIntent backed the update,
3480
3493
  // so the KEY is what a receiver sees either way.
3481
3494
  stripe_session_id: null,
@@ -3553,13 +3566,15 @@ async function get(url, headers, timeoutMs = 12e3) {
3553
3566
  clearTimeout(timer);
3554
3567
  }
3555
3568
  }
3556
- async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId = TEST_PARTNER_ID, publicKeyB64 = TEST_PARTNER_PUBLIC_KEY_SPKI_B64) {
3569
+ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId = TEST_PARTNER_ID, publicKeyB64 = TEST_PARTNER_PUBLIC_KEY_SPKI_B64) {
3557
3570
  let targetUrl;
3558
3571
  let customerUrl;
3559
3572
  let acceptedUpdateTypes = [];
3560
3573
  let verifiesAccountReference = false;
3561
3574
  let supportsKeyCrossover = false;
3562
3575
  let accountRef = DEFAULT_ACCOUNT_REF;
3576
+ let recipientKey;
3577
+ let retentionPeriodDays;
3563
3578
  if (typeof urlOrOptions === "object") {
3564
3579
  targetUrl = urlOrOptions.targetUrl;
3565
3580
  secret = urlOrOptions.secret ?? TEST_WEBHOOK_SECRET;
@@ -3570,12 +3585,15 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3570
3585
  verifiesAccountReference = urlOrOptions.verifiesAccountReference === true;
3571
3586
  supportsKeyCrossover = urlOrOptions.supportsKeyCrossover === true;
3572
3587
  accountRef = urlOrOptions.accountRef?.trim() || DEFAULT_ACCOUNT_REF;
3588
+ recipientKey = "key" in urlOrOptions ? urlOrOptions.key ?? null : asConformanceKey(publicKeyB64);
3589
+ retentionPeriodDays = urlOrOptions.retentionPeriodDays;
3573
3590
  } else {
3574
3591
  targetUrl = urlOrOptions;
3592
+ recipientKey = asConformanceKey(publicKeyB64);
3575
3593
  }
3576
3594
  const results = [];
3577
3595
  const matchable = { account_number: accountRef };
3578
- const sharedBody = await buildBody(partnerId, publicKeyB64, void 0, "address", matchable);
3596
+ const sharedBody = await buildBody(partnerId, recipientKey, void 0, "address", matchable, retentionPeriodDays);
3579
3597
  let declaration = readAcceptedUpdateKindsFromAck(null);
3580
3598
  let check1Accepted;
3581
3599
  {
@@ -3590,7 +3608,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3590
3608
  basis: "acceptance",
3591
3609
  label: "Accepts correctly signed webhook",
3592
3610
  passed,
3593
- detail: error ? `Network error: ${error}` : `HTTP ${status} \u2014 expected 2xx`
3611
+ detail: error ? `Network error: ${error}` : status === 401 ? "HTTP 401, expected 2xx. Your receiver is running and refused our signature, so the WEBHOOK_SECRET it holds is not the signing secret on this account's Webhook screen. Check it was set up for THIS partner account (its PARTNER_ID should match yours), then restart it. Every check below depends on this one." : `HTTP ${status} \u2014 expected 2xx`
3594
3612
  });
3595
3613
  }
3596
3614
  {
@@ -3649,10 +3667,11 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3649
3667
  {
3650
3668
  const futureBody = await buildBody(
3651
3669
  partnerId,
3652
- publicKeyB64,
3670
+ recipientKey,
3653
3671
  { future_field: "ignored", future_object: { x: 1 } },
3654
3672
  "address",
3655
- matchable
3673
+ matchable,
3674
+ retentionPeriodDays
3656
3675
  );
3657
3676
  const ts = String(Math.floor(Date.now() / 1e3));
3658
3677
  const sig = sign(futureBody, ts, secret);
@@ -3755,10 +3774,22 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3755
3774
  detail: error ? `Network error: ${error}` : `HTTP ${status} \u2014 expected 2xx (timestamp is within the \xB1300s window)`
3756
3775
  });
3757
3776
  }
3758
- {
3777
+ if (recipientKey) {
3759
3778
  const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
3760
3779
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
3761
- const foreignBody = await buildBody(partnerId, foreignKey);
3780
+ const foreignBody = await buildBody(
3781
+ partnerId,
3782
+ // The partner's OWN key_id over a key they do not hold: a receiver that
3783
+ // selects its private half by key_id must get as far as selecting one and
3784
+ // then fail to decrypt. Labelling it `conformance-key-1` instead would be
3785
+ // refused one step earlier, as an unknown key, which is a different
3786
+ // property from the one this check is named for.
3787
+ { keyId: recipientKey?.keyId ?? DEFAULT_CONFORMANCE_KEY_ID, publicKeyB64: foreignKey },
3788
+ void 0,
3789
+ "address",
3790
+ void 0,
3791
+ retentionPeriodDays
3792
+ );
3762
3793
  const ts = String(Math.floor(Date.now() / 1e3));
3763
3794
  const sig = sign(foreignBody, ts, secret);
3764
3795
  const res = await fetch(targetUrl, {
@@ -3786,13 +3817,13 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3786
3817
  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.`
3787
3818
  });
3788
3819
  }
3789
- if (verifiesAccountReference) {
3820
+ if (verifiesAccountReference && recipientKey) {
3790
3821
  const nonce = import_node_crypto.default.randomUUID();
3791
- const body = await buildBody(partnerId, publicKeyB64, void 0, "address", {
3822
+ const body = await buildBody(partnerId, recipientKey, void 0, "address", {
3792
3823
  account_number: `CONF-NOSUCH-${nonce}`,
3793
3824
  verified_name: `Nomatch ${nonce.slice(0, 8)}`,
3794
3825
  known_names: [`Nomatch ${nonce.slice(0, 8)}`]
3795
- });
3826
+ }, retentionPeriodDays);
3796
3827
  const ts = String(Math.floor(Date.now() / 1e3));
3797
3828
  const sig = sign(body, ts, secret);
3798
3829
  const res = await fetch(targetUrl, {
@@ -3833,7 +3864,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3833
3864
  const contactKinds = plan.accept;
3834
3865
  for (const kind of contactKinds) {
3835
3866
  const article = kind === "email" ? "an" : "a";
3836
- const body = await buildBody(partnerId, publicKeyB64, void 0, kind, matchable);
3867
+ const body = await buildBody(partnerId, recipientKey, void 0, kind, matchable, retentionPeriodDays);
3837
3868
  const ts = String(Math.floor(Date.now() / 1e3));
3838
3869
  const sig = sign(body, ts, secret);
3839
3870
  const res = await fetch(targetUrl, {
@@ -3886,7 +3917,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3886
3917
  });
3887
3918
  if (plan.refuse !== null) {
3888
3919
  const probe = plan.refuse;
3889
- const body = await buildBody(partnerId, publicKeyB64, void 0, probe, matchable);
3920
+ const body = await buildBody(partnerId, recipientKey, void 0, probe, matchable, retentionPeriodDays);
3890
3921
  const ts = String(Math.floor(Date.now() / 1e3));
3891
3922
  const sig = sign(body, ts, secret);
3892
3923
  const res = await fetch(targetUrl, {
@@ -3912,12 +3943,19 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3912
3943
  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.`
3913
3944
  });
3914
3945
  }
3915
- if (supportsKeyCrossover) {
3946
+ if (supportsKeyCrossover && recipientKey) {
3947
+ const stagedKeyId = "conformance-crossover-staged";
3916
3948
  const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
3917
3949
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
3918
- const base = JSON.parse(await buildBody(partnerId, foreignKey));
3919
- const heldKeyId = "conformance-key-1";
3920
- const stagedKeyId = "conformance-crossover-staged";
3950
+ const base = JSON.parse(await buildBody(
3951
+ partnerId,
3952
+ { keyId: stagedKeyId, publicKeyB64: foreignKey },
3953
+ void 0,
3954
+ "address",
3955
+ void 0,
3956
+ retentionPeriodDays
3957
+ ));
3958
+ const heldKeyId = recipientKey?.keyId ?? DEFAULT_CONFORMANCE_KEY_ID;
3921
3959
  base.session_key_share.key_id = stagedKeyId;
3922
3960
  base.crossover_key_ids = [stagedKeyId, heldKeyId];
3923
3961
  const body = JSON.stringify(base);
@@ -3948,7 +3986,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
3948
3986
  }
3949
3987
  {
3950
3988
  const nonce = import_node_crypto.default.randomUUID();
3951
- const body = await buildBody(partnerId, publicKeyB64, {
3989
+ const body = await buildBody(partnerId, recipientKey, {
3952
3990
  // `event` IS LOAD-BEARING HERE and setting only the header is the bug this
3953
3991
  // check shipped with for one run. `buildBody` defaults the body event to
3954
3992
  // `address.updated`, and both the SDK and the drop-in receiver route on the
@@ -4059,7 +4097,16 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
4059
4097
  });
4060
4098
  }
4061
4099
  }
4062
- return markUnprovenChecks(results);
4100
+ return { checks: markUnprovenChecks(results), declaration };
4101
+ }
4102
+ async function runChecks(urlOrOptions, secret, partnerId, publicKeyB64) {
4103
+ const run = typeof urlOrOptions === "string" ? await runChecksDetailed(
4104
+ urlOrOptions,
4105
+ secret ?? TEST_WEBHOOK_SECRET,
4106
+ partnerId ?? TEST_PARTNER_ID,
4107
+ publicKeyB64 ?? TEST_PARTNER_PUBLIC_KEY_SPKI_B64
4108
+ ) : await runChecksDetailed(urlOrOptions);
4109
+ return run.checks;
4063
4110
  }
4064
4111
  function markUnprovenChecks(results) {
4065
4112
  const anythingAccepted = results.some((r) => r.basis === "acceptance" && r.passed);
@@ -4263,7 +4310,9 @@ Options:
4263
4310
  Supply ALL THREE or none: a partial set is refused, because it passes every
4264
4311
  signature check while the payload stays sealed to the built-in test key, so
4265
4312
  the failures land on the acceptance checks and read as a fault in your code.
4266
- --customer-url <url> Customer app URL for pull API checks (adds checks 9 + 10)
4313
+ --customer-url <url> Customer app URL for pull API checks (adds checks 12 + 13;
4314
+ this line said "9 + 10" for months, which are the
4315
+ malformed-JSON and replay-edge checks and run always)
4267
4316
  --account-ref <ref> The account reference the dispatches carry (default: CONF-0001,
4268
4317
  which every scaffold seeds). Only matters if your receiver
4269
4318
  matches dispatches to your own customer records: it holds no
package/dist/plan.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * How big a conformance run will be, BEFORE it runs.
3
+ *
4
+ * ── WHY THIS IS ITS OWN MODULE WITH NO IMPORTS ─────────────────────────────
5
+ *
6
+ * The only caller that needs it is the partner portal's Testing card, which is
7
+ * a `'use client'` React component. `checks.ts` reaches `node:crypto` and
8
+ * `@oneaddress/crypto` on the first line, so importing the planner from there
9
+ * drags a key-agreement implementation into the browser bundle to answer a
10
+ * question about arithmetic. This file imports NOTHING, deliberately, and must
11
+ * stay that way: the next person to need a constant from `checks.ts` here
12
+ * should copy the constant, not add the import.
13
+ *
14
+ * `checks.ts` re-exports it so server-side callers keep one import.
15
+ */
16
+ /**
17
+ * Which NON-kind checks a given option set will produce, in run order.
18
+ *
19
+ * ── WHY THIS EXISTS AND WHY IT IS GUARDED BY EXECUTION ─────────────────────
20
+ *
21
+ * The partner portal's Testing card has to say how many checks it is about to
22
+ * run, before it runs them. It did that with `const BASE_CHECK_COUNT = 8` and
23
+ * two conditionals typed into the component, under a comment warning that the
24
+ * number "is the kind that gets reintroduced by the next optional check unless
25
+ * the number is derived rather than typed". It then stayed 8 while the suite
26
+ * the card now calls has eleven unconditional checks, so the card promised ten
27
+ * and ran fifteen.
28
+ *
29
+ * A PLANNER IS A SECOND ENCODING OF THE SUITE AND WOULD DRIFT TOO, so it is not
30
+ * trusted: `src/__tests__/planner-matches-run.test.ts` EXECUTES the suite
31
+ * against a stub receiver and asserts this function's output equals the
32
+ * non-kind ids the run actually produced, for every combination of the gates.
33
+ * A check added without a line here fails that test rather than quietly
34
+ * mis-sizing the card.
35
+ *
36
+ * KIND CHECKS ARE DELIBERATELY NOT COUNTED. How many there are depends on what
37
+ * the RECEIVER declares on its first acknowledgement, which is not known until
38
+ * check-1 has run. The card says "plus the update-kind checks your receiver's
39
+ * own declaration drives" instead of guessing, which is the honest form.
40
+ */
41
+ declare function plannedCoreCheckIds(opts: {
42
+ /** The partner has a registered encryption key. */
43
+ hasKey?: boolean;
44
+ /** `partners.verifies_account_reference` resolved to true. */
45
+ verifiesAccountReference?: boolean;
46
+ /** The receiver declared it handles key-crossover siblings. */
47
+ supportsKeyCrossover?: boolean;
48
+ /** A customer-app base URL was supplied, adding the pull-API checks. */
49
+ hasCustomerUrl?: boolean;
50
+ }): string[];
51
+
52
+ export { plannedCoreCheckIds };
package/dist/plan.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/plan.ts
21
+ var plan_exports = {};
22
+ __export(plan_exports, {
23
+ plannedCoreCheckIds: () => plannedCoreCheckIds
24
+ });
25
+ module.exports = __toCommonJS(plan_exports);
26
+ function plannedCoreCheckIds(opts) {
27
+ const ids = [
28
+ "check-1",
29
+ "check-2",
30
+ "check-3",
31
+ "check-4",
32
+ "check-5",
33
+ "check-6",
34
+ "check-7",
35
+ "check-8",
36
+ "check-9",
37
+ "check-10"
38
+ ];
39
+ if (opts.hasKey) ids.push("check-11");
40
+ if (opts.verifiesAccountReference && opts.hasKey) ids.push("check-14");
41
+ if (opts.supportsKeyCrossover && opts.hasKey) ids.push("check-15");
42
+ ids.push("check-16");
43
+ if (opts.hasCustomerUrl) ids.push("check-12", "check-13");
44
+ return ids;
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ plannedCoreCheckIds
49
+ });
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@oneaddress/conformance",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Conformance test tool for OneAddress partner integrations",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
7
7
  "oneaddress-conformance": "./dist/index.js"
8
8
  },
9
- "files": ["LICENSE", "dist", "README.md"],
9
+ "files": [
10
+ "LICENSE",
11
+ "dist",
12
+ "README.md"
13
+ ],
10
14
  "scripts": {
11
- "build": "tsup",
12
- "prepare": "tsup",
15
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
16
+ "prepare": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
13
17
  "type-check": "tsc --noEmit"
14
18
  },
15
19
  "publishConfig": {