@oneaddress/conformance 3.3.0 → 3.5.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
@@ -25,8 +25,11 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
25
25
  ));
26
26
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
27
27
 
28
+ // src/index.ts
29
+ var import_node_fs = require("fs");
30
+
28
31
  // src/checks.ts
29
- var import_node_crypto = __toESM(require("crypto"));
32
+ var import_node_crypto2 = __toESM(require("crypto"));
30
33
 
31
34
  // ../../node_modules/@noble/hashes/utils.js
32
35
  function isBytes(a) {
@@ -3922,12 +3925,25 @@ var ENDPOINT_STALE_AFTER_MINUTES = ENDPOINT_PROBE_INTERVAL_MINUTES * 4;
3922
3925
  var ENDPOINT_UNUSABLE_AFTER_MINUTES = ENDPOINT_PROBE_INTERVAL_MINUTES * 24;
3923
3926
 
3924
3927
  // ../crypto/src/registry-root-pin.ts
3925
- var PINNED_REGISTRY_ROOTS = Object.freeze([
3926
- Object.freeze({
3927
- root_key_id: "rk1_251368ec9b0a84ae",
3928
- spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
3929
- })
3928
+ var PRODUCTION_REGISTRY_HOSTS = Object.freeze([
3929
+ "oneaddress.io",
3930
+ "www.oneaddress.io",
3931
+ "app.oneaddress.io"
3930
3932
  ]);
3933
+ var PRODUCTION_ROOT = Object.freeze({
3934
+ root_key_id: "rk1_251368ec9b0a84ae",
3935
+ spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
3936
+ });
3937
+ var REGISTRY_ROOT_PINS = Object.freeze({
3938
+ production: Object.freeze([PRODUCTION_ROOT]),
3939
+ preview: Object.freeze([
3940
+ Object.freeze({
3941
+ root_key_id: "rk1_4690d67464893d48",
3942
+ spki_sha256: "4690d67464893d48ebb335bcd29f3203fbacefbc69afd8a047b639521296bfab"
3943
+ })
3944
+ ])
3945
+ });
3946
+ var PINNED_REGISTRY_ROOTS = REGISTRY_ROOT_PINS.production;
3931
3947
 
3932
3948
  // ../crypto/src/vault-pin-hardening.ts
3933
3949
  var oprf = ristretto255_oprf.oprf;
@@ -4180,7 +4196,6 @@ var D5_BODY_ALWAYS = [
4180
4196
  "partner_id",
4181
4197
  "session_envelope",
4182
4198
  "session_key_share",
4183
- "stripe_session_id",
4184
4199
  "timestamp",
4185
4200
  "update_id",
4186
4201
  "user_id"
@@ -4201,7 +4216,18 @@ var D5_BODY_CONDITIONAL = {
4201
4216
  */
4202
4217
  id: "key-crossover copy only",
4203
4218
  /** The sibling marker naming the other key_ids this update was sealed to. */
4204
- crossover_key_ids: "key-crossover copy only"
4219
+ crossover_key_ids: "key-crossover copy only",
4220
+ /**
4221
+ * The day the change takes effect, `YYYY-MM-DD` (31 Oct 2026). Set on every
4222
+ * dispatch made for a SCHEDULED MOVE, which is its move date. A scheduled
4223
+ * move sends each recipient early enough for its own notice period
4224
+ * (`resolveRecipientSendPlan` in `notice-period.ts`), so the update can
4225
+ * arrive days before the customer moves; a recipient that treated it as
4226
+ * immediate could start charging at the new address from the day it arrived.
4227
+ * Absent on an immediate update, which takes effect on receipt. Optional for
4228
+ * receivers: an SDK that does not know the field ignores it.
4229
+ */
4230
+ effective_date: "scheduled move only"
4205
4231
  };
4206
4232
  var D5_BODY_DRILL_ONLY = ["conformance"];
4207
4233
  var D5_BODY_ADDED_AT_SEND = ["dispatch_id"];
@@ -4230,6 +4256,159 @@ function keyShareExpiryIso(dispatchAt, retentionPeriodDays) {
4230
4256
  return new Date(dispatchAt.getTime() + days * DAY_MS).toISOString();
4231
4257
  }
4232
4258
 
4259
+ // ../protocol/src/loa-v2.ts
4260
+ var LOA_V2_VERSION_TAG = "oneaddress-loa/2";
4261
+ var LOA_V2_LEGACY_ENVELOPE_TAG = "oneaddress-legacy-envelope/1";
4262
+ var LOA_V2_FIELD_ORDER = [
4263
+ "consumer_name",
4264
+ "authorisation_date",
4265
+ "scope",
4266
+ "update_uid",
4267
+ "partner_id",
4268
+ "envelope_sha256"
4269
+ ];
4270
+ var LOA_MAX_TYPED_ALIASES = 3;
4271
+ var LoaV2FieldError = class extends Error {
4272
+ constructor(field, reason) {
4273
+ super(`LOA v2 field ${field} ${reason}`);
4274
+ this.field = field;
4275
+ this.name = "LoaV2FieldError";
4276
+ }
4277
+ };
4278
+ var CONTROL_RE = /[\u0000-\u001F\u007F]/;
4279
+ var LONE_SURROGATE_RE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
4280
+ function utf8Length(s) {
4281
+ return new TextEncoder().encode(s).length;
4282
+ }
4283
+ function encodeField(name, value) {
4284
+ if (typeof value !== "string") throw new LoaV2FieldError(name, "is not a string");
4285
+ if (CONTROL_RE.test(value)) throw new LoaV2FieldError(name, "contains a control character");
4286
+ if (LONE_SURROGATE_RE.test(value)) throw new LoaV2FieldError(name, "is not well-formed Unicode");
4287
+ return `${utf8Length(value)}:${value}
4288
+ `;
4289
+ }
4290
+ function canonicalLoaV2(fields) {
4291
+ let out = encodeField("version", LOA_V2_VERSION_TAG);
4292
+ for (const f of LOA_V2_FIELD_ORDER) out += encodeField(f, fields[f]);
4293
+ const aliases = fields.consumer_typed_aliases;
4294
+ if (!Array.isArray(aliases)) throw new LoaV2FieldError("consumer_typed_aliases", "is not a list");
4295
+ if (aliases.length > LOA_MAX_TYPED_ALIASES) {
4296
+ throw new LoaV2FieldError("consumer_typed_aliases", `has more than ${LOA_MAX_TYPED_ALIASES} entries`);
4297
+ }
4298
+ out += encodeField("consumer_typed_aliases", String(aliases.length));
4299
+ for (const a of aliases) out += encodeField("consumer_typed_aliases", a);
4300
+ return out;
4301
+ }
4302
+ function loaV2EnvelopeDigestInput(envelope) {
4303
+ if (typeof envelope === "string") return envelope;
4304
+ if (!envelope || typeof envelope !== "object") {
4305
+ throw new LoaV2FieldError("envelope", "is neither a session_envelope string nor an address_encrypted object");
4306
+ }
4307
+ return encodeField("tag", LOA_V2_LEGACY_ENVELOPE_TAG) + encodeField("ephemeralPublicKey", envelope.ephemeralPublicKey) + encodeField("iv", envelope.iv) + encodeField("ciphertext", envelope.ciphertext) + encodeField("hkdfSalt", envelope.hkdfSalt ?? "");
4308
+ }
4309
+ var ASCII_WS_RE = /[ \t\n\v\f\r]+/;
4310
+ var MARK_RE = /\p{M}/gu;
4311
+ function normaliseLoaName(name) {
4312
+ return name.normalize("NFKD").replace(MARK_RE, "").toLowerCase().replace(/\u03C2/g, "\u03C3").split(ASCII_WS_RE).filter((t) => t.length > 0).join(" ");
4313
+ }
4314
+ function loaFirstName(name) {
4315
+ const tokens = normaliseLoaName(name).split(" ").filter((t) => t.length > 0);
4316
+ return tokens.length > 0 ? tokens[0] : "";
4317
+ }
4318
+ var LOA_MIN_SHORT_FORM_LETTERS = 3;
4319
+ function codePoints(s) {
4320
+ return Array.from(s).length;
4321
+ }
4322
+ function isAcceptableAlias(verifiedName, alias) {
4323
+ const vFirst = loaFirstName(verifiedName);
4324
+ const aFirst = loaFirstName(alias);
4325
+ if (!vFirst || !aFirst) return false;
4326
+ if (aFirst === vFirst) return true;
4327
+ const [shorter, longer] = codePoints(aFirst) <= codePoints(vFirst) ? [aFirst, vFirst] : [vFirst, aFirst];
4328
+ return codePoints(shorter) >= LOA_MIN_SHORT_FORM_LETTERS && longer.startsWith(shorter);
4329
+ }
4330
+ function acceptTypedAliases(verifiedName, aliases) {
4331
+ const out = [];
4332
+ if (!Array.isArray(aliases)) return out;
4333
+ const seen = /* @__PURE__ */ new Set([normaliseLoaName(verifiedName)]);
4334
+ for (const a of aliases) {
4335
+ if (out.length >= LOA_MAX_TYPED_ALIASES) break;
4336
+ if (typeof a !== "string") continue;
4337
+ if (CONTROL_RE.test(a) || LONE_SURROGATE_RE.test(a)) continue;
4338
+ const n = normaliseLoaName(a);
4339
+ if (!n || seen.has(n)) continue;
4340
+ if (!isAcceptableAlias(verifiedName, a)) continue;
4341
+ seen.add(n);
4342
+ out.push(a);
4343
+ }
4344
+ return out;
4345
+ }
4346
+
4347
+ // ../protocol/src/drill-loa.ts
4348
+ var DRILL_LOA_CONSUMER_NAME = "CONFORMANCE DRILL";
4349
+ var DRILL_LOA_SCOPE = "CONFORMANCE DRILL. Issued by OneAddress for a receiver conformance run. Authorises no change to any record.";
4350
+ var ONEADDRESS_LOA_ACN = "696 078 869";
4351
+ var DRILL_UPDATE_UID_MIN = 9e8;
4352
+ var DRILL_UPDATE_UID_MAX = 901e6;
4353
+ function drillLoaTypedAliases(aliases) {
4354
+ return acceptTypedAliases(DRILL_LOA_CONSUMER_NAME, aliases);
4355
+ }
4356
+ function canonicalDrillLoaV2(loa) {
4357
+ return canonicalLoaV2({
4358
+ consumer_name: loa.consumer_name,
4359
+ authorisation_date: loa.authorisation_date,
4360
+ scope: loa.scope,
4361
+ update_uid: loa.update_uid,
4362
+ partner_id: loa.partner_id,
4363
+ envelope_sha256: loa.envelope_sha256,
4364
+ consumer_typed_aliases: loa.consumer_typed_aliases
4365
+ });
4366
+ }
4367
+ function canonicalD5LoaString(loa) {
4368
+ return [loa.consumer_name, loa.authorisation_date, loa.scope, loa.update_uid, loa.oneaddress_acn].join("|");
4369
+ }
4370
+ function isWellFormedDrillLoa(loa, request) {
4371
+ if (!loa || typeof loa !== "object") return false;
4372
+ const l = loa;
4373
+ const aliases = l.consumer_typed_aliases;
4374
+ const wantAliases = drillLoaTypedAliases(request.typedAliases);
4375
+ return l.consumer_name === DRILL_LOA_CONSUMER_NAME && l.scope === DRILL_LOA_SCOPE && l.oneaddress_acn === ONEADDRESS_LOA_ACN && l.update_uid === request.updateUid && l.partner_id === request.partnerId && l.envelope_sha256 === request.envelopeSha256 && Array.isArray(aliases) && aliases.length === wantAliases.length && aliases.every((a, i) => a === wantAliases[i]) && l.signature_algorithm === "ECDSA-P256" && typeof l.oneaddress_signature === "string" && /^[0-9a-f]{128}$/.test(l.oneaddress_signature) && typeof l.oneaddress_signature_v2 === "string" && /^[0-9a-f]{128}$/.test(l.oneaddress_signature_v2) && typeof l.authorisation_date === "string" && !Number.isNaN(Date.parse(l.authorisation_date));
4376
+ }
4377
+
4378
+ // ../protocol/src/verification-commitment.ts
4379
+ var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
4380
+ var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
4381
+ function normaliseCommitmentField(value) {
4382
+ if (typeof value !== "string") return "";
4383
+ const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
4384
+ const start = collapsed.startsWith(" ") ? 1 : 0;
4385
+ const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
4386
+ return collapsed.slice(start, end);
4387
+ }
4388
+ function verificationCommitmentString(verificationId, index, record) {
4389
+ if (!Number.isInteger(index) || index <= 0) {
4390
+ throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
4391
+ }
4392
+ return [
4393
+ VERIFICATION_COMMITMENT_VERSION,
4394
+ normaliseCommitmentField(verificationId),
4395
+ String(index),
4396
+ normaliseCommitmentField(record.name),
4397
+ normaliseCommitmentField(record.street),
4398
+ normaliseCommitmentField(record.suburb),
4399
+ normaliseCommitmentField(record.state),
4400
+ normaliseCommitmentField(record.postcode),
4401
+ normaliseCommitmentField(record.country)
4402
+ ].join("\n");
4403
+ }
4404
+ function isWellFormedCommitment(value) {
4405
+ return typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
4406
+ }
4407
+
4408
+ // src/loa-forms.ts
4409
+ var import_node_crypto = __toESM(require("crypto"));
4410
+ var PLACEHOLDER_SIGNATURE = "00".repeat(64);
4411
+
4233
4412
  // src/credentials.ts
4234
4413
  var TEST_WEBHOOK_SECRET = (
4235
4414
  // NOSONAR — intentional test credential, not a real secret
@@ -4240,7 +4419,7 @@ var TEST_PARTNER_PUBLIC_KEY_SPKI_B64 = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqFmY
4240
4419
 
4241
4420
  // src/checks.ts
4242
4421
  function sign(body, timestamp, secret) {
4243
- return import_node_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
4422
+ return import_node_crypto2.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
4244
4423
  }
4245
4424
  function buildHeaders(partnerId, timestamp, signature, dispatchId, event = "address.updated") {
4246
4425
  return {
@@ -4254,6 +4433,7 @@ function buildHeaders(partnerId, timestamp, signature, dispatchId, event = "addr
4254
4433
  };
4255
4434
  }
4256
4435
  var DEFAULT_ACCOUNT_REF = "CONF-0001";
4436
+ var MAX_PRODUCT_LINES_PROBED = 5;
4257
4437
  var DEFAULT_CONFORMANCE_KEY_ID = "conformance-key-1";
4258
4438
  function asConformanceKey(key) {
4259
4439
  if (!key) return null;
@@ -4264,15 +4444,102 @@ function asConformanceKey(key) {
4264
4444
  }
4265
4445
  var CONFORMANCE_USER_ID = "conformance:drill";
4266
4446
  function conformanceUpdateId() {
4267
- return import_node_crypto.default.randomInt(9e8, 901e6);
4447
+ return import_node_crypto2.default.randomInt(DRILL_UPDATE_UID_MIN, DRILL_UPDATE_UID_MAX);
4268
4448
  }
4269
- async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address", identity, retentionPeriodDays = DEFAULT_RETENTION_DAYS) {
4449
+ var LoaSignerError = class extends Error {
4450
+ constructor(message) {
4451
+ super(message);
4452
+ this.name = "LoaSignerError";
4453
+ }
4454
+ };
4455
+ function localDrillLoaSigner(privateKeyPem) {
4456
+ const key = import_node_crypto2.default.createPrivateKey(privateKeyPem);
4457
+ if (key.asymmetricKeyType !== "ec" || key.asymmetricKeyDetails?.namedCurve !== "prime256v1") {
4458
+ throw new LoaSignerError("the LOA signing key must be an EC P-256 private key (PKCS#8 PEM)");
4459
+ }
4460
+ return async (request) => {
4461
+ const unsigned = {
4462
+ consumer_name: DRILL_LOA_CONSUMER_NAME,
4463
+ authorisation_date: (/* @__PURE__ */ new Date()).toISOString(),
4464
+ scope: DRILL_LOA_SCOPE,
4465
+ update_uid: request.updateUid,
4466
+ oneaddress_acn: ONEADDRESS_LOA_ACN
4467
+ };
4468
+ const sign2 = (text) => import_node_crypto2.default.sign(
4469
+ "SHA256",
4470
+ Buffer.from(text, "utf8"),
4471
+ { key, dsaEncoding: "ieee-p1363" }
4472
+ ).toString("hex");
4473
+ const v2 = {
4474
+ partner_id: request.partnerId,
4475
+ envelope_sha256: request.envelopeSha256,
4476
+ consumer_typed_aliases: drillLoaTypedAliases(request.typedAliases)
4477
+ };
4478
+ return {
4479
+ ...unsigned,
4480
+ oneaddress_signature: sign2(canonicalD5LoaString(unsigned)),
4481
+ signature_algorithm: "ECDSA-P256",
4482
+ ...v2,
4483
+ oneaddress_signature_v2: sign2(canonicalDrillLoaV2({ ...unsigned, ...v2 }))
4484
+ };
4485
+ };
4486
+ }
4487
+ async function drillLoaFor(request, nowIso, plan) {
4488
+ const mode = plan?.mode ?? "signed";
4489
+ if (mode === "omitted") return null;
4490
+ if (!plan?.signer) {
4491
+ const v2 = {
4492
+ partner_id: request.partnerId,
4493
+ envelope_sha256: request.envelopeSha256,
4494
+ consumer_typed_aliases: drillLoaTypedAliases(request.typedAliases)
4495
+ };
4496
+ return {
4497
+ consumer_name: DRILL_LOA_CONSUMER_NAME,
4498
+ authorisation_date: nowIso,
4499
+ scope: DRILL_LOA_SCOPE,
4500
+ update_uid: request.updateUid,
4501
+ oneaddress_acn: ONEADDRESS_LOA_ACN,
4502
+ oneaddress_signature: "00".repeat(64),
4503
+ signature_algorithm: "ECDSA-P256",
4504
+ ...v2,
4505
+ oneaddress_signature_v2: "00".repeat(64)
4506
+ };
4507
+ }
4508
+ let loa;
4509
+ try {
4510
+ loa = await plan.signer(request);
4511
+ } catch (err) {
4512
+ if (err instanceof LoaSignerError) throw err;
4513
+ throw new LoaSignerError(`the drill LOA signer failed: ${err instanceof Error ? err.message : String(err)}`);
4514
+ }
4515
+ if (!isWellFormedDrillLoa(loa, request)) {
4516
+ throw new LoaSignerError("the drill LOA signer returned something that is not a drill LOA for this update");
4517
+ }
4518
+ if (mode === "forged") {
4519
+ return { ...loa, scope: `${DRILL_LOA_SCOPE} ALTERED` };
4520
+ }
4521
+ return loa;
4522
+ }
4523
+ var CONFORMANCE_ADDRESS = {
4524
+ street: "42 Collins Street",
4525
+ suburb: "Melbourne",
4526
+ state: "VIC",
4527
+ postcode: "3000",
4528
+ country: "AU"
4529
+ };
4530
+ function conformanceCommitmentCheck(answer, secret, verificationId, index, name) {
4531
+ if (answer === void 0 || answer === null) return "absent";
4532
+ if (!isWellFormedCommitment(answer)) return "mismatch";
4533
+ const expected = import_node_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, { name, ...CONFORMANCE_ADDRESS }), "utf8").digest("hex");
4534
+ return import_node_crypto2.default.timingSafeEqual(Buffer.from(answer, "hex"), Buffer.from(expected, "hex")) ? "match" : "mismatch";
4535
+ }
4536
+ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address", identity, retentionPeriodDays = DEFAULT_RETENTION_DAYS, loaPlan) {
4270
4537
  const key = asConformanceKey(publicKeyB64);
4271
4538
  const partnerKey = key && {
4272
4539
  partner_id: partnerId,
4273
4540
  key_id: key.keyId,
4274
4541
  public_key_b64: key.publicKeyB64,
4275
- algorithm: "ECDH-P256-AES-GCM-256"
4542
+ algorithm: key.algorithm ?? "ECDH-P256-AES-GCM-256"
4276
4543
  };
4277
4544
  const nowIso = (/* @__PURE__ */ new Date()).toISOString();
4278
4545
  const updateIdNum = conformanceUpdateId();
@@ -4281,38 +4548,30 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
4281
4548
  v: 2,
4282
4549
  update_uid: updateUid,
4283
4550
  dispatch_timestamp: nowIso,
4284
- verified_name: "Conformance Test",
4551
+ // The drill name, because the drill LOA names it (it is fixed at the
4552
+ // signer) and a v2 receiver refuses an envelope whose name differs.
4553
+ verified_name: DRILL_LOA_CONSUMER_NAME,
4285
4554
  ...kind === "address" ? {
4286
- new_address: {
4287
- street: "42 Collins Street",
4288
- suburb: "Melbourne",
4289
- state: "VIC",
4290
- postcode: "3000",
4291
- country: "AU"
4292
- }
4555
+ new_address: { ...CONFORMANCE_ADDRESS }
4293
4556
  } : {},
4294
4557
  ...kind === "phone" ? { new_phone: "+61412345678" } : {},
4295
4558
  ...kind === "email" ? { new_email: "conformance@example.com" } : {},
4296
4559
  update_types: [kind],
4297
4560
  account_number: DEFAULT_ACCOUNT_REF,
4298
- id_verification_ref: import_node_crypto.default.randomUUID(),
4561
+ id_verification_ref: import_node_crypto2.default.randomUUID(),
4299
4562
  known_names: ["Conformance Tester"],
4300
4563
  // Applied last so an override wins over the defaults above, including
4301
4564
  // `verified_name`, which is set before the address block.
4302
4565
  ...identity ?? {}
4303
4566
  };
4304
4567
  const envelope = partnerKey ? await encryptSessionForPartner(sessionData, partnerKey) : { session_envelope: null, session_key_share: null };
4305
- const loa = {
4306
- consumer_name: "Conformance Test",
4307
- authorisation_date: nowIso,
4308
- scope: "Authority to update address records on file.",
4309
- update_uid: updateUid,
4310
- oneaddress_acn: "696 078 869",
4311
- oneaddress_signature: "00".repeat(64),
4312
- // placeholder r||s hex (128 chars)
4313
- signature_algorithm: "ECDSA-P256"
4314
- };
4315
- const loaEnvelope = partnerKey ? await encryptEnvelopeForPartner(loa, partnerKey) : null;
4568
+ const loa = partnerKey && envelope.session_envelope ? await drillLoaFor({
4569
+ updateUid,
4570
+ partnerId,
4571
+ envelopeSha256: import_node_crypto2.default.createHash("sha256").update(loaV2EnvelopeDigestInput(envelope.session_envelope), "utf8").digest("hex"),
4572
+ typedAliases: sessionData.known_names ?? []
4573
+ }, nowIso, loaPlan) : null;
4574
+ const loaEnvelope = partnerKey && loa ? await encryptEnvelopeForPartner(loa, partnerKey) : null;
4316
4575
  return JSON.stringify({
4317
4576
  // Body event and `X-OneAddress-Event` must agree — the relay derives both
4318
4577
  // from the same rule, and a receiver may route on either. An address-
@@ -4368,9 +4627,7 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
4368
4627
  session_key_share: loaEnvelope.session_key_share
4369
4628
  }
4370
4629
  } : {},
4371
- // On the wire with a `null` value when no PaymentIntent backed the update,
4372
- // so the KEY is what a receiver sees either way.
4373
- stripe_session_id: null,
4630
+ // No `stripe_session_id`: the relay stopped sending it on 24 Oct 2026.
4374
4631
  /**
4375
4632
  * THIS DISPATCH IS A DRILL, AND IT SAYS SO IN THE SIGNED BODY.
4376
4633
  *
@@ -4401,12 +4658,20 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
4401
4658
  ...extraFields
4402
4659
  });
4403
4660
  }
4404
- async function post(url, body, headers, timeoutMs = 12e3) {
4661
+ function describeFetchError(err) {
4662
+ const cause = err?.cause;
4663
+ const text = `${String(err)} ${cause ? String(cause.message ?? cause) : ""}`;
4664
+ if (/redirect/i.test(text)) {
4665
+ return "the endpoint answered with a redirect (3xx). Conformance does not follow redirects, because OneAddress dispatches do not: point it at the final URL";
4666
+ }
4667
+ return String(err);
4668
+ }
4669
+ async function post(url, body, headers, timeoutMs = 12e3, fetchImpl = fetch) {
4405
4670
  const controller = new AbortController();
4406
4671
  const timer = setTimeout(() => controller.abort(), timeoutMs);
4407
4672
  const start = Date.now();
4408
4673
  try {
4409
- const res = await fetch(url, {
4674
+ const res = await fetchImpl(url, {
4410
4675
  method: "POST",
4411
4676
  headers,
4412
4677
  body,
@@ -4416,14 +4681,14 @@ async function post(url, body, headers, timeoutMs = 12e3) {
4416
4681
  const text = await res.text().catch(() => "");
4417
4682
  return { status: res.status, durationMs: Date.now() - start, body: text };
4418
4683
  } catch (err) {
4419
- return { status: 0, durationMs: Date.now() - start, body: "", error: String(err) };
4684
+ return { status: 0, durationMs: Date.now() - start, body: "", error: describeFetchError(err) };
4420
4685
  } finally {
4421
4686
  clearTimeout(timer);
4422
4687
  }
4423
4688
  }
4424
4689
  function signPullV2(timestamp, secret, url, method = "GET", body = "") {
4425
4690
  const u = new URL(url);
4426
- return import_node_crypto.default.createHmac("sha256", secret).update(`v2.${timestamp}.${method.toUpperCase()}.${u.pathname}${u.search}.${body}`).digest("hex");
4691
+ return import_node_crypto2.default.createHmac("sha256", secret).update(`v2.${timestamp}.${method.toUpperCase()}.${u.pathname}${u.search}.${body}`).digest("hex");
4427
4692
  }
4428
4693
  async function get(url, headers, timeoutMs = 12e3) {
4429
4694
  const controller = new AbortController();
@@ -4441,7 +4706,7 @@ async function get(url, headers, timeoutMs = 12e3) {
4441
4706
  res.headers.forEach((v, k) => resHdrs.set(k.toLowerCase(), v));
4442
4707
  return { status: res.status, headers: resHdrs, body, durationMs: Date.now() - start };
4443
4708
  } catch (err) {
4444
- return { status: 0, headers: /* @__PURE__ */ new Map(), body: "", durationMs: Date.now() - start, error: String(err) };
4709
+ return { status: 0, headers: /* @__PURE__ */ new Map(), body: "", durationMs: Date.now() - start, error: describeFetchError(err) };
4445
4710
  } finally {
4446
4711
  clearTimeout(timer);
4447
4712
  }
@@ -4452,10 +4717,14 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4452
4717
  let acceptedUpdateTypes = [];
4453
4718
  let verifiesAccountReference = false;
4454
4719
  let supportsKeyCrossover = false;
4720
+ let productLines = [];
4455
4721
  let accountRef = DEFAULT_ACCOUNT_REF;
4456
4722
  let recipientKey;
4457
4723
  let retentionPeriodDays;
4724
+ let loaSigner = null;
4725
+ let targetFetch = fetch;
4458
4726
  if (typeof urlOrOptions === "object") {
4727
+ targetFetch = urlOrOptions.fetchImpl ?? fetch;
4459
4728
  targetUrl = urlOrOptions.targetUrl;
4460
4729
  secret = urlOrOptions.secret ?? TEST_WEBHOOK_SECRET;
4461
4730
  partnerId = urlOrOptions.partnerId ?? TEST_PARTNER_ID;
@@ -4464,22 +4733,30 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4464
4733
  acceptedUpdateTypes = urlOrOptions.acceptedUpdateTypes ?? [];
4465
4734
  verifiesAccountReference = urlOrOptions.verifiesAccountReference === true;
4466
4735
  supportsKeyCrossover = urlOrOptions.supportsKeyCrossover === true;
4736
+ productLines = (urlOrOptions.productLines ?? []).slice(0, MAX_PRODUCT_LINES_PROBED);
4467
4737
  accountRef = urlOrOptions.accountRef?.trim() || DEFAULT_ACCOUNT_REF;
4468
4738
  recipientKey = "key" in urlOrOptions ? urlOrOptions.key ?? null : asConformanceKey(publicKeyB64);
4469
4739
  retentionPeriodDays = urlOrOptions.retentionPeriodDays;
4740
+ loaSigner = urlOrOptions.loaSigner ?? null;
4470
4741
  } else {
4471
4742
  targetUrl = urlOrOptions;
4472
4743
  recipientKey = asConformanceKey(publicKeyB64);
4473
4744
  }
4474
4745
  const results = [];
4746
+ const informational = [];
4747
+ const postTarget = (u, b, h, t) => post(u, b, h, t, targetFetch);
4748
+ const signedLoa = { signer: loaSigner };
4475
4749
  const matchable = { account_number: accountRef };
4476
- const sharedBody = await buildBody(partnerId, recipientKey, void 0, "address", matchable, retentionPeriodDays);
4750
+ const runId = import_node_crypto2.default.randomUUID().slice(0, 8);
4751
+ const runBase = 1e9 + import_node_crypto2.default.randomInt(0, 1e9);
4752
+ const runDispatch = (n) => String(runBase + n);
4753
+ const sharedBody = await buildBody(partnerId, recipientKey, void 0, "address", matchable, retentionPeriodDays, signedLoa);
4477
4754
  let declaration = readAcceptedUpdateKindsFromAck(null);
4478
4755
  let check1Accepted;
4479
4756
  {
4480
4757
  const ts = String(Math.floor(Date.now() / 1e3));
4481
4758
  const sig = sign(sharedBody, ts, secret);
4482
- const { status, error, body: ackBody } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "1"));
4759
+ const { status, error, body: ackBody } = await postTarget(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, runDispatch(1)));
4483
4760
  const passed = !error && status >= 200 && status < 300;
4484
4761
  check1Accepted = passed;
4485
4762
  if (passed) declaration = readAcceptedUpdateKindsFromAck(ackBody);
@@ -4488,14 +4765,14 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4488
4765
  basis: "acceptance",
4489
4766
  label: "Accepts correctly signed webhook",
4490
4767
  passed,
4491
- 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`
4768
+ detail: error ? `Network error: ${error}` : status === 401 ? "HTTP 401, expected 2xx. Your receiver is running and refused our signature, so the webhook signing secret it holds (WEBHOOK_SECRET in a setup scaffold, OA_WEBHOOK_SECRET in the drop-in receiver, webhookSecret in the SDK) is not the one 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`
4492
4769
  });
4493
4770
  }
4494
4771
  {
4495
4772
  const ts = String(Math.floor(Date.now() / 1e3));
4496
4773
  const sig = sign(sharedBody, ts, secret);
4497
4774
  const badSig = sig.slice(0, -1) + (sig.endsWith("a") ? "b" : "a");
4498
- const { status, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, badSig, "2"));
4775
+ const { status, error } = await postTarget(targetUrl, sharedBody, buildHeaders(partnerId, ts, badSig, runDispatch(2)));
4499
4776
  const passed = !error && status >= 400 && status < 500;
4500
4777
  results.push({
4501
4778
  id: "check-2",
@@ -4508,7 +4785,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4508
4785
  {
4509
4786
  const staleTs = String(Math.floor(Date.now() / 1e3) - 600);
4510
4787
  const staleSig = sign(sharedBody, staleTs, secret);
4511
- const { status, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, staleTs, staleSig, "3"));
4788
+ const { status, error } = await postTarget(targetUrl, sharedBody, buildHeaders(partnerId, staleTs, staleSig, runDispatch(3)));
4512
4789
  const passed = !error && status >= 400 && status < 500;
4513
4790
  results.push({
4514
4791
  id: "check-3",
@@ -4521,7 +4798,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4521
4798
  {
4522
4799
  const futureTs = String(Math.floor(Date.now() / 1e3) + 600);
4523
4800
  const futureSig = sign(sharedBody, futureTs, secret);
4524
- const { status, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, futureTs, futureSig, "4"));
4801
+ const { status, error } = await postTarget(targetUrl, sharedBody, buildHeaders(partnerId, futureTs, futureSig, runDispatch(4)));
4525
4802
  const passed = !error && status >= 400 && status < 500;
4526
4803
  results.push({
4527
4804
  id: "check-4",
@@ -4534,7 +4811,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4534
4811
  {
4535
4812
  const ts = String(Math.floor(Date.now() / 1e3));
4536
4813
  const sig = sign(sharedBody, ts, secret);
4537
- const { durationMs, error } = await post(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, "5"));
4814
+ const { durationMs, error } = await postTarget(targetUrl, sharedBody, buildHeaders(partnerId, ts, sig, runDispatch(5)));
4538
4815
  const passed = !error && durationMs < 1e4;
4539
4816
  results.push({
4540
4817
  id: "check-5",
@@ -4551,11 +4828,12 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4551
4828
  { future_field: "ignored", future_object: { x: 1 } },
4552
4829
  "address",
4553
4830
  matchable,
4554
- retentionPeriodDays
4831
+ retentionPeriodDays,
4832
+ signedLoa
4555
4833
  );
4556
4834
  const ts = String(Math.floor(Date.now() / 1e3));
4557
4835
  const sig = sign(futureBody, ts, secret);
4558
- const { status, error } = await post(targetUrl, futureBody, buildHeaders(partnerId, ts, sig, "6"));
4836
+ const { status, error } = await postTarget(targetUrl, futureBody, buildHeaders(partnerId, ts, sig, runDispatch(6)));
4559
4837
  const passed = !error && status >= 200 && status < 300;
4560
4838
  results.push({
4561
4839
  id: "check-6",
@@ -4574,10 +4852,10 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4574
4852
  });
4575
4853
  const ts = String(Math.floor(Date.now() / 1e3));
4576
4854
  const sig = sign(unknownBody, ts, secret);
4577
- const { status, error } = await post(
4855
+ const { status, error } = await postTarget(
4578
4856
  targetUrl,
4579
4857
  unknownBody,
4580
- buildHeaders(partnerId, ts, sig, "7", "address.future_event")
4858
+ buildHeaders(partnerId, ts, sig, runDispatch(7), "address.future_event")
4581
4859
  );
4582
4860
  const passed = !error && status >= 200 && status < 300;
4583
4861
  results.push({
@@ -4591,8 +4869,8 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4591
4869
  {
4592
4870
  const ts1 = String(Math.floor(Date.now() / 1e3));
4593
4871
  const sig1 = sign(sharedBody, ts1, secret);
4594
- const dedupId = import_node_crypto.default.randomUUID().slice(0, 8);
4595
- const { status: s1, error: e1 } = await post(
4872
+ const dedupId = import_node_crypto2.default.randomUUID().slice(0, 8);
4873
+ const { status: s1, error: e1 } = await postTarget(
4596
4874
  targetUrl,
4597
4875
  sharedBody,
4598
4876
  buildHeaders(partnerId, ts1, sig1, `dedup-${dedupId}`)
@@ -4600,11 +4878,12 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4600
4878
  await new Promise((r) => setTimeout(r, 200));
4601
4879
  const ts2 = String(Math.floor(Date.now() / 1e3));
4602
4880
  const sig2 = sign(sharedBody, ts2, secret);
4603
- const res2 = await fetch(targetUrl, {
4881
+ const res2 = await targetFetch(targetUrl, {
4604
4882
  redirect: "error",
4605
4883
  method: "POST",
4606
4884
  headers: buildHeaders(partnerId, ts2, sig2, `dedup-${dedupId}`),
4607
- body: sharedBody
4885
+ body: sharedBody,
4886
+ signal: AbortSignal.timeout(12e3)
4608
4887
  }).catch(() => null);
4609
4888
  const s2 = res2?.status ?? 0;
4610
4889
  const body2Text = res2 ? await res2.text().catch(() => "") : "";
@@ -4628,7 +4907,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4628
4907
  const badBody = "this is not { valid json";
4629
4908
  const ts = String(Math.floor(Date.now() / 1e3));
4630
4909
  const sig = sign(badBody, ts, secret);
4631
- const { status, error } = await post(targetUrl, badBody, buildHeaders(partnerId, ts, sig, "bad-json"));
4910
+ const { status, error } = await postTarget(targetUrl, badBody, buildHeaders(partnerId, ts, sig, `bad-json-${runId}`));
4632
4911
  const passed = !error && status >= 400 && status < 500;
4633
4912
  results.push({
4634
4913
  id: "check-9",
@@ -4641,10 +4920,10 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4641
4920
  {
4642
4921
  const nearEdgeTs = String(Math.floor(Date.now() / 1e3) - 295);
4643
4922
  const nearEdgeSig = sign(sharedBody, nearEdgeTs, secret);
4644
- const { status, error } = await post(
4923
+ const { status, error } = await postTarget(
4645
4924
  targetUrl,
4646
4925
  sharedBody,
4647
- buildHeaders(partnerId, nearEdgeTs, nearEdgeSig, "near-edge")
4926
+ buildHeaders(partnerId, nearEdgeTs, nearEdgeSig, `near-edge-${runId}`)
4648
4927
  );
4649
4928
  const passed = !error && status >= 200 && status < 300;
4650
4929
  results.push({
@@ -4656,7 +4935,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4656
4935
  });
4657
4936
  }
4658
4937
  if (recipientKey) {
4659
- const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
4938
+ const throwaway = import_node_crypto2.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
4660
4939
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
4661
4940
  const foreignBody = await buildBody(
4662
4941
  partnerId,
@@ -4673,10 +4952,10 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4673
4952
  );
4674
4953
  const ts = String(Math.floor(Date.now() / 1e3));
4675
4954
  const sig = sign(foreignBody, ts, secret);
4676
- const res = await fetch(targetUrl, {
4955
+ const res = await targetFetch(targetUrl, {
4677
4956
  redirect: "error",
4678
4957
  method: "POST",
4679
- headers: buildHeaders(partnerId, ts, sig, `undecryptable-${import_node_crypto.default.randomUUID().slice(0, 8)}`),
4958
+ headers: buildHeaders(partnerId, ts, sig, `undecryptable-${import_node_crypto2.default.randomUUID().slice(0, 8)}`),
4680
4959
  body: foreignBody,
4681
4960
  signal: AbortSignal.timeout(12e3)
4682
4961
  }).catch(() => null);
@@ -4696,19 +4975,19 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4696
4975
  basis: "rejection",
4697
4976
  label: "Reports undecryptable payload as a failure (not 200 ok:true)",
4698
4977
  passed,
4699
- 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.`
4978
+ 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 wherever your receiver keeps refused dispatches (on the setup scaffold's dashboard, press [d]).` : `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.`
4700
4979
  });
4701
4980
  }
4702
4981
  if (verifiesAccountReference && recipientKey) {
4703
- const nonce = import_node_crypto.default.randomUUID();
4982
+ const nonce = import_node_crypto2.default.randomUUID();
4704
4983
  const body = await buildBody(partnerId, recipientKey, void 0, "address", {
4705
4984
  account_number: `CONF-NOSUCH-${nonce}`,
4706
4985
  verified_name: `Nomatch ${nonce.slice(0, 8)}`,
4707
4986
  known_names: [`Nomatch ${nonce.slice(0, 8)}`]
4708
- }, retentionPeriodDays);
4987
+ }, retentionPeriodDays, signedLoa);
4709
4988
  const ts = String(Math.floor(Date.now() / 1e3));
4710
4989
  const sig = sign(body, ts, secret);
4711
- const res = await fetch(targetUrl, {
4990
+ const res = await targetFetch(targetUrl, {
4712
4991
  redirect: "error",
4713
4992
  method: "POST",
4714
4993
  headers: buildHeaders(partnerId, ts, sig, `nomatch-${nonce.slice(0, 8)}`),
@@ -4747,10 +5026,10 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4747
5026
  const contactKinds = plan.accept;
4748
5027
  for (const kind of contactKinds) {
4749
5028
  const article = kind === "email" ? "an" : "a";
4750
- const body = await buildBody(partnerId, recipientKey, void 0, kind, matchable, retentionPeriodDays);
5029
+ const body = await buildBody(partnerId, recipientKey, void 0, kind, matchable, retentionPeriodDays, signedLoa);
4751
5030
  const ts = String(Math.floor(Date.now() / 1e3));
4752
5031
  const sig = sign(body, ts, secret);
4753
- const res = await fetch(targetUrl, {
5032
+ const res = await targetFetch(targetUrl, {
4754
5033
  redirect: "error",
4755
5034
  method: "POST",
4756
5035
  // `contact.updated`, matching what the relay now sends for a dispatch
@@ -4768,7 +5047,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4768
5047
  partnerId,
4769
5048
  ts,
4770
5049
  sig,
4771
- `contact-${kind}-${import_node_crypto.default.randomUUID().slice(0, 8)}`,
5050
+ `contact-${kind}-${import_node_crypto2.default.randomUUID().slice(0, 8)}`,
4772
5051
  "contact.updated"
4773
5052
  ),
4774
5053
  body,
@@ -4801,20 +5080,26 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4801
5080
  });
4802
5081
  if (plan.refuse !== null) {
4803
5082
  const probe = plan.refuse;
4804
- const body = await buildBody(partnerId, recipientKey, void 0, probe, matchable, retentionPeriodDays);
5083
+ const body = await buildBody(partnerId, recipientKey, void 0, probe, matchable, retentionPeriodDays, signedLoa);
4805
5084
  const ts = String(Math.floor(Date.now() / 1e3));
4806
5085
  const sig = sign(body, ts, secret);
4807
- const res = await fetch(targetUrl, {
5086
+ const res = await targetFetch(targetUrl, {
4808
5087
  method: "POST",
4809
5088
  headers: buildHeaders(
4810
5089
  partnerId,
4811
5090
  ts,
4812
5091
  sig,
4813
- `refuse-${probe}-${import_node_crypto.default.randomUUID().slice(0, 8)}`,
5092
+ `refuse-${probe}-${import_node_crypto2.default.randomUUID().slice(0, 8)}`,
4814
5093
  "contact.updated"
4815
5094
  ),
4816
5095
  body,
4817
- signal: AbortSignal.timeout(12e3)
5096
+ signal: AbortSignal.timeout(12e3),
5097
+ // Every probe in this file refuses redirects. This one is the signed
5098
+ // body most worth stealing: a receiver that answers 307 would have
5099
+ // fetch re-POST it, signature and all, to whatever host the Location
5100
+ // names, including an internal metadata address. Guarded by
5101
+ // fetch-redirect-guard.test.ts.
5102
+ redirect: "error"
4818
5103
  }).catch(() => null);
4819
5104
  const status = res?.status ?? 0;
4820
5105
  if (res) await res.text().catch(() => "");
@@ -4824,12 +5109,12 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4824
5109
  basis: "rejection",
4825
5110
  label: `Refuses an update kind it did not declare (${probe})`,
4826
5111
  passed,
4827
- 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.`
5112
+ 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.` : status >= 500 ? `HTTP ${status}: the receiver errored on a dispatch carrying a kind (${probe}) it never declared, rather than refusing it. A 5xx is retried as an outage; refuse it with a 4xx (the SDK answers 422 update_type_not_accepted).` : `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.`
4828
5113
  });
4829
5114
  }
4830
5115
  if (supportsKeyCrossover && recipientKey) {
4831
5116
  const stagedKeyId = "conformance-crossover-staged";
4832
- const throwaway = import_node_crypto.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
5117
+ const throwaway = import_node_crypto2.default.generateKeyPairSync("ec", { namedCurve: "prime256v1" });
4833
5118
  const foreignKey = throwaway.publicKey.export({ type: "spki", format: "der" }).toString("base64");
4834
5119
  const base = JSON.parse(await buildBody(
4835
5120
  partnerId,
@@ -4845,11 +5130,14 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4845
5130
  const body = JSON.stringify(base);
4846
5131
  const ts = String(Math.floor(Date.now() / 1e3));
4847
5132
  const sig = sign(body, ts, secret);
4848
- const res = await fetch(targetUrl, {
5133
+ const res = await targetFetch(targetUrl, {
4849
5134
  method: "POST",
4850
- headers: buildHeaders(partnerId, ts, sig, `crossover-${import_node_crypto.default.randomUUID().slice(0, 8)}`),
5135
+ headers: buildHeaders(partnerId, ts, sig, `crossover-${import_node_crypto2.default.randomUUID().slice(0, 8)}`),
4851
5136
  body,
4852
- signal: AbortSignal.timeout(12e3)
5137
+ signal: AbortSignal.timeout(12e3),
5138
+ // Same reason as the refusal probe: a followed 307 re-sends a signed
5139
+ // body to a host nobody declared.
5140
+ redirect: "error"
4853
5141
  }).catch(() => null);
4854
5142
  const status = res?.status ?? 0;
4855
5143
  const bodyText = res ? await res.text().catch(() => "") : "";
@@ -4869,7 +5157,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4869
5157
  });
4870
5158
  }
4871
5159
  {
4872
- const nonce = import_node_crypto.default.randomUUID();
5160
+ const nonce = import_node_crypto2.default.randomUUID();
4873
5161
  const body = await buildBody(partnerId, recipientKey, {
4874
5162
  // `event` IS LOAD-BEARING HERE and setting only the header is the bug this
4875
5163
  // check shipped with for one run. `buildBody` defaults the body event to
@@ -4900,10 +5188,10 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4900
5188
  // into a real submission, where it would parse and then mismatch.
4901
5189
  verified_name: "CONFORMANCE DRILL",
4902
5190
  known_names: ["CONFORMANCE DRILL"]
4903
- });
5191
+ }, retentionPeriodDays, signedLoa);
4904
5192
  const ts = String(Math.floor(Date.now() / 1e3));
4905
5193
  const sig = sign(body, ts, secret);
4906
- const { status, error, body: ackBody } = await post(
5194
+ const { status, error, body: ackBody } = await postTarget(
4907
5195
  targetUrl,
4908
5196
  body,
4909
5197
  buildHeaders(partnerId, ts, sig, `conformance-${nonce}-1`, "address.test")
@@ -4913,17 +5201,118 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4913
5201
  parsed = JSON.parse(ackBody);
4914
5202
  } catch {
4915
5203
  }
5204
+ const commitment = conformanceCommitmentCheck(
5205
+ parsed.commitment,
5206
+ secret,
5207
+ `conformance-${nonce}`,
5208
+ 1,
5209
+ "CONFORMANCE DRILL"
5210
+ );
4916
5211
  const acknowledged = !error && status >= 200 && status < 300;
4917
- const passed = acknowledged && parsed.verification === true;
5212
+ const passed = acknowledged && parsed.verification === true && commitment !== "mismatch";
4918
5213
  const missing = typeof parsed.missing_callback === "string" ? parsed.missing_callback : null;
4919
5214
  results.push({
4920
5215
  id: "check-16",
4921
5216
  basis: "acceptance",
4922
5217
  label: "Answers a connection-verification record (address.test)",
4923
5218
  passed,
4924
- detail: error ? `Network error: ${error}` : !acknowledged ? `HTTP ${status} \u2014 expected 2xx. A test record is a real signed, encrypted dispatch; refusing it will fail connection verification.` : missing ? `HTTP ${status}, and your receiver reported no \`${missing}\` callback, so the record was acknowledged and SKIPPED. OneAddress sends five of these before go-live and counts how many you decrypt; with no \`${missing}\` you will score zero while every delivery looks clean. Add \`${missing}\` to createOneAddressHandler.` : parsed.verification === true ? `HTTP ${status} \u2014 verification record decrypted and acknowledged` : `HTTP ${status}, but the response did not carry { verification: true }. OneAddress counts that field as proof you decrypted the record, so without it a working receiver still reads as "decrypted 0 of 5" on the real run. Echo it from your test-record handler.`
5219
+ detail: error ? `Network error: ${error}` : !acknowledged ? `HTTP ${status} \u2014 expected 2xx. A test record is a real signed, encrypted dispatch; refusing it will fail connection verification.` : missing ? `HTTP ${status}, and your receiver reported no \`${missing}\` callback, so the record was acknowledged and SKIPPED. OneAddress sends five of these before go-live and counts how many you decrypt; with no \`${missing}\` you will score zero while every delivery looks clean. Add \`${missing}\` to createOneAddressHandler.` : parsed.verification === true && commitment === "mismatch" ? `HTTP ${status}, and the response said it decrypted the record, but its signed answer (\`commitment\`) does not match what was sent. OneAddress refuses that answer when you go live. Check the receiver keys it with the webhook secret that verified the request and builds it from the decrypted name and address, not a formatted copy.` : parsed.verification === true && commitment === "match" ? `HTTP ${status}: verification record decrypted, and its signed answer matches what was sent` : parsed.verification === true ? `HTTP ${status}: verification record decrypted and acknowledged, but with no signed answer (\`commitment\`). Going live will need one: update to the current OneAddress SDK or setup wizard, or, while older receivers are still accepted, ask us to run a connection verification and send back the block it prints.` : `HTTP ${status}, but the response did not carry { verification: true }. OneAddress counts that field as proof you decrypted the record, so without it a working receiver still reads as "decrypted 0 of 5" on the real run. Echo it from your test-record handler.`
5220
+ });
5221
+ }
5222
+ if (recipientKey) {
5223
+ const body = await buildBody(partnerId, recipientKey, void 0, "address", {
5224
+ ...matchable,
5225
+ x_conformance_unknown: "ignore me"
5226
+ }, retentionPeriodDays, signedLoa);
5227
+ const ts = String(Math.floor(Date.now() / 1e3));
5228
+ const sig = sign(body, ts, secret);
5229
+ const { status, error } = await postTarget(targetUrl, body, buildHeaders(partnerId, ts, sig, `sealed-unknown-${runId}`));
5230
+ const passed = !error && status >= 200 && status < 300;
5231
+ results.push({
5232
+ id: "check-17",
5233
+ basis: "acceptance",
5234
+ label: "Handles an unknown field inside the sealed envelope",
5235
+ passed,
5236
+ detail: error ? `Network error: ${error}` : passed ? `HTTP ${status}: an envelope carrying a field this receiver cannot know was acknowledged` : `HTTP ${status}, expected 2xx. The only difference from check-1 is an extra field inside the decrypted envelope. OneAddress adds optional envelope fields without a version change, so a receiver that refuses unknown fields will start refusing real updates. Ignore fields you do not read.`
4925
5237
  });
4926
5238
  }
5239
+ if (recipientKey && productLines.length > 0) {
5240
+ const refused = [];
5241
+ for (const line of productLines) {
5242
+ const body = await buildBody(partnerId, recipientKey, void 0, "address", {
5243
+ ...matchable,
5244
+ product: { id: line.id, code: line.code, name: line.name }
5245
+ }, retentionPeriodDays, signedLoa);
5246
+ const ts = String(Math.floor(Date.now() / 1e3));
5247
+ const sig = sign(body, ts, secret);
5248
+ const { status, error } = await postTarget(targetUrl, body, buildHeaders(partnerId, ts, sig, `product-${line.code}-${runId}`));
5249
+ if (error || status < 200 || status >= 300) refused.push(`${line.code} (${error ? `network error: ${error}` : `HTTP ${status}`})`);
5250
+ }
5251
+ const codes = productLines.map((l) => l.code).join(", ");
5252
+ results.push({
5253
+ id: "check-18",
5254
+ basis: "acceptance",
5255
+ label: "Accepts every product line",
5256
+ passed: refused.length === 0,
5257
+ detail: refused.length === 0 ? `Acknowledged an envelope for each product line: ${codes}` : `Not acknowledged: ${refused.join("; ")}. Each envelope matched check-1 apart from its \`product\`, so a receiver that routes on product.code has no route for these codes. Add one, or a default for codes it does not know.`
5258
+ });
5259
+ }
5260
+ if (loaSigner && recipientKey) {
5261
+ const acceptedSignedLoa = check1Accepted;
5262
+ const probes = [
5263
+ {
5264
+ id: "check-loa-forged",
5265
+ mode: "forged",
5266
+ label: "Refuses a consent proof (LOA) whose signature does not verify",
5267
+ what: "a LOA whose signed content was altered after signing"
5268
+ },
5269
+ {
5270
+ id: "check-loa-missing",
5271
+ mode: "omitted",
5272
+ label: "Refuses a dispatch carrying no consent proof (LOA)",
5273
+ what: "a dispatch with no loa_encrypted at all"
5274
+ }
5275
+ ];
5276
+ for (const probe of probes) {
5277
+ const body = await buildBody(
5278
+ partnerId,
5279
+ recipientKey,
5280
+ void 0,
5281
+ "address",
5282
+ matchable,
5283
+ retentionPeriodDays,
5284
+ { signer: loaSigner, mode: probe.mode }
5285
+ );
5286
+ const ts = String(Math.floor(Date.now() / 1e3));
5287
+ const sig = sign(body, ts, secret);
5288
+ const res = await targetFetch(targetUrl, {
5289
+ method: "POST",
5290
+ headers: buildHeaders(partnerId, ts, sig, `${probe.id.slice(6)}-${import_node_crypto2.default.randomUUID().slice(0, 8)}`),
5291
+ body,
5292
+ signal: AbortSignal.timeout(12e3),
5293
+ // Same reason as every probe in this file: a followed 307 re-sends a
5294
+ // signed body to a host nobody declared.
5295
+ redirect: "error"
5296
+ }).catch(() => null);
5297
+ const status = res?.status ?? 0;
5298
+ const bodyText = res ? await res.text().catch(() => "") : "";
5299
+ let parsed = {};
5300
+ try {
5301
+ parsed = JSON.parse(bodyText);
5302
+ } catch {
5303
+ }
5304
+ const refused = res !== null && (status >= 400 || parsed.ok === false);
5305
+ const passed = refused && acceptedSignedLoa;
5306
+ informational.push({
5307
+ id: probe.id,
5308
+ basis: "rejection",
5309
+ informational: true,
5310
+ label: probe.label,
5311
+ passed,
5312
+ detail: res === null ? "Network error: no response. Informational, does not affect go-live." : !acceptedSignedLoa ? `HTTP ${status}. Not proven: check-1, which carried a valid signed LOA, was not accepted, so a refusal here demonstrates nothing. Informational, does not affect go-live.` : refused ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""}: ${probe.what} was refused, so this receiver verifies the consent proof before it applies an update.` : `HTTP ${status}: ${probe.what} was ACCEPTED, so this receiver applies updates without verifying OneAddress's consent proof. Informational for now, and it does not affect go-live. @oneaddress/partner-sdk 2.8.0 and later verify it by default; on an earlier version set loaPublicKeyPem (from fetchLoaPublicKey, or /.well-known/oneaddress-loa-key.pem), and remove any requireLoa: false.`
5313
+ });
5314
+ }
5315
+ }
4927
5316
  if (customerUrl) {
4928
5317
  const pullBase = customerUrl.replace(/\/$/, "");
4929
5318
  {
@@ -4965,7 +5354,7 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4965
5354
  if (!resSig || !resTs) {
4966
5355
  detail = `Response missing X-OneAddress-Signature or X-OneAddress-Timestamp headers`;
4967
5356
  } else {
4968
- const expected = import_node_crypto.default.createHmac("sha256", secret).update(`${resTs}.${resBody}`).digest("hex");
5357
+ const expected = import_node_crypto2.default.createHmac("sha256", secret).update(`${resTs}.${resBody}`).digest("hex");
4969
5358
  if (resSig === expected) {
4970
5359
  passed = true;
4971
5360
  detail = `HTTP 200, response signature verified`;
@@ -4983,17 +5372,20 @@ async function runChecksDetailed(urlOrOptions, secret = TEST_WEBHOOK_SECRET, par
4983
5372
  });
4984
5373
  }
4985
5374
  }
4986
- return { checks: markUnprovenChecks(results), declaration };
5375
+ const checks = markUnprovenChecks(loaSigner ? results : annotateUnsignedLoa(results));
5376
+ return { checks, declaration, informational, loaSigned: loaSigner !== null };
4987
5377
  }
4988
- async function runChecks(urlOrOptions, secret, partnerId, publicKeyB64) {
4989
- const run = typeof urlOrOptions === "string" ? await runChecksDetailed(
4990
- urlOrOptions,
4991
- secret ?? TEST_WEBHOOK_SECRET,
4992
- partnerId ?? TEST_PARTNER_ID,
4993
- publicKeyB64 ?? TEST_PARTNER_PUBLIC_KEY_SPKI_B64
4994
- ) : await runChecksDetailed(urlOrOptions);
4995
- return run.checks;
5378
+ var LOA_BEARING_ACCEPTANCE = /* @__PURE__ */ new Set(["check-1", "check-6", "check-8", "check-10", "check-16", "check-17", "check-18"]);
5379
+ function annotateUnsignedLoa(results) {
5380
+ return results.map((r) => {
5381
+ if (r.passed) return r;
5382
+ if (!LOA_BEARING_ACCEPTANCE.has(r.id) && !r.id.startsWith("check-contact-")) return r;
5383
+ return { ...r, detail: `${r.detail}
5384
+
5385
+ ${UNSIGNED_LOA_NOTE}` };
5386
+ });
4996
5387
  }
5388
+ var UNSIGNED_LOA_NOTE = "THIS DRILL'S CONSENT PROOF (LOA) WAS UNSIGNED. If your receiver verifies LOAs (the default since @oneaddress/partner-sdk 2.8.0, and the drop-in receiver's OA_REQUIRE_LOA=1), it is RIGHT to refuse this: the CLI cannot sign with OneAddress's key. Either pass --loa-signing-key <file> with a P-256 test key whose public half your receiver is configured with for this run, or run the go-live check in the partner portal, which sends a LOA signed by OneAddress. Do not turn verification off to pass.";
4997
5389
  function markUnprovenChecks(results) {
4998
5390
  const anythingAccepted = results.some((r) => r.basis === "acceptance" && r.passed);
4999
5391
  if (anythingAccepted) return results;
@@ -5062,15 +5454,26 @@ function formatReport(results) {
5062
5454
  lines.push("");
5063
5455
  return lines;
5064
5456
  }
5065
- function printReport(results) {
5457
+ function formatInformational(results) {
5458
+ if (results.length === 0) return [];
5459
+ const lines = [" Informational (does not affect the result above or go-live):"];
5460
+ for (const r of results) {
5461
+ lines.push(` ${r.passed ? PASS : FAIL} ${r.label}`);
5462
+ lines.push(` \u21B3 ${r.detail}`);
5463
+ }
5464
+ lines.push("");
5465
+ return lines;
5466
+ }
5467
+ function printReport(results, informational = []) {
5066
5468
  for (const line of formatReport(results)) console.log(line);
5469
+ for (const line of formatInformational(informational)) console.log(line);
5067
5470
  }
5068
5471
  function exitCode(results) {
5069
5472
  return results.every((r) => r.passed) ? 0 : 1;
5070
5473
  }
5071
5474
 
5072
5475
  // src/resolve-credentials.ts
5073
- var import_node_crypto2 = require("crypto");
5476
+ var import_node_crypto3 = require("crypto");
5074
5477
  var FLAG_FOR = {
5075
5478
  ONEADDRESS_WEBHOOK_SECRET: "--secret",
5076
5479
  ONEADDRESS_PARTNER_ID: "--partner-id",
@@ -5115,7 +5518,7 @@ function publicKeyProblem(c) {
5115
5518
  return `${where} is not valid base64.`;
5116
5519
  }
5117
5520
  try {
5118
- const key = (0, import_node_crypto2.createPublicKey)({ key: der, format: "der", type: "spki" });
5521
+ const key = (0, import_node_crypto3.createPublicKey)({ key: der, format: "der", type: "spki" });
5119
5522
  if (key.asymmetricKeyType !== "ec") {
5120
5523
  return `${where} is a ${key.asymmetricKeyType ?? "non-EC"} key. OneAddress envelopes use ECDH P-256, so this key cannot unwrap them.`;
5121
5524
  }
@@ -5179,6 +5582,22 @@ function describeCredentials(c) {
5179
5582
  return [];
5180
5583
  }
5181
5584
 
5585
+ // src/recipient-options.ts
5586
+ function readRecipientOptions(getFlag, env, publicKeyB64) {
5587
+ const out = {};
5588
+ const keyId = (getFlag("--key-id") ?? env.ONEADDRESS_KEY_ID)?.trim();
5589
+ if (keyId) out.key = { keyId, publicKeyB64 };
5590
+ const raw = (getFlag("--retention-days") ?? env.ONEADDRESS_RETENTION_DAYS)?.trim();
5591
+ if (raw) {
5592
+ const days = Number(raw);
5593
+ if (!Number.isInteger(days) || days < 14 || days > 365) {
5594
+ return { error: `--retention-days must be a whole number from 14 to 365 (the portal's range), got "${raw}".` };
5595
+ }
5596
+ out.retentionPeriodDays = days;
5597
+ }
5598
+ return out;
5599
+ }
5600
+
5182
5601
  // src/index.ts
5183
5602
  var USAGE = `
5184
5603
  Usage: oneaddress-conformance test <webhook-url>
@@ -5196,6 +5615,11 @@ Options:
5196
5615
  Supply ALL THREE or none: a partial set is refused, because it passes every
5197
5616
  signature check while the payload stays sealed to the built-in test key, so
5198
5617
  the failures land on the acceptance checks and read as a fault in your code.
5618
+ --key-id <id> Your key_id from the partner portal. Without it every envelope
5619
+ names conformance-key-1, which a receiver that resolves its key
5620
+ by id cannot open. Also ONEADDRESS_KEY_ID.
5621
+ --retention-days <n> Your retention window from the portal (14 to 365, default 90),
5622
+ which sets key_share_expiry. Also ONEADDRESS_RETENTION_DAYS.
5199
5623
  --customer-url <url> Customer app URL for pull API checks (adds checks 12 + 13;
5200
5624
  this line said "9 + 10" for months, which are the
5201
5625
  malformed-JSON and replay-edge checks and run always)
@@ -5218,6 +5642,17 @@ Options:
5218
5642
  portal \u2014 a receiver that only writes to an outbox has no way
5219
5643
  to know whether a reference matches, so the check would
5220
5644
  report a defect it cannot have.
5645
+ --supports-key-crossover Set once your receiver understands crossover_key_ids (a copy of a
5646
+ rotation it cannot decrypt, whose sibling it can). Adds check-15.
5647
+ --loa-signing-key <file> A P-256 private key (PKCS#8 PEM) to sign the drill's consent
5648
+ proof (LOA) with. Without it the drill LOA is UNSIGNED, because
5649
+ this tool cannot hold OneAddress's key, and a receiver that
5650
+ verifies LOAs (the SDK default since 2.8.0) refuses every drill, which
5651
+ is it being right. Generate a TEST pair, give your receiver the
5652
+ public half for this run only, and pass the private half here.
5653
+ Adds two informational checks (forged and missing LOA refused)
5654
+ that never affect the result. Also ONEADDRESS_LOA_SIGNING_KEY_FILE.
5655
+ The go-live check in the partner portal signs with the real key.
5221
5656
 
5222
5657
  Example:
5223
5658
  # The wizard scaffold: no credentials at all, which is a meaningful run
@@ -5255,9 +5690,25 @@ async function main() {
5255
5690
  const partnerId = creds.partnerId.value;
5256
5691
  const publicKey = creds.publicKeyB64.value;
5257
5692
  const customerUrl = getFlag("--customer-url");
5693
+ const recipient = readRecipientOptions(getFlag, process.env, publicKey);
5694
+ if (recipient.error) {
5695
+ console.error(recipient.error);
5696
+ process.exit(1);
5697
+ }
5258
5698
  const accountRef = getFlag("--account-ref")?.trim() || process.env.ONEADDRESS_ACCOUNT_REF?.trim() || DEFAULT_ACCOUNT_REF;
5259
5699
  const acceptedUpdateTypes = (getFlag("--accept") ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
5260
5700
  const verifiesAccountReference = args.includes("--verifies-account-reference");
5701
+ const supportsKeyCrossover = args.includes("--supports-key-crossover");
5702
+ const loaKeyFile = getFlag("--loa-signing-key") ?? process.env.ONEADDRESS_LOA_SIGNING_KEY_FILE;
5703
+ let loaSigner = null;
5704
+ if (loaKeyFile) {
5705
+ try {
5706
+ loaSigner = localDrillLoaSigner((0, import_node_fs.readFileSync)(loaKeyFile, "utf8"));
5707
+ } catch (err) {
5708
+ console.error(`Error: --loa-signing-key ${loaKeyFile}: ${err instanceof Error ? err.message : String(err)}`);
5709
+ process.exit(1);
5710
+ }
5711
+ }
5261
5712
  const UNKNOWN = acceptedUpdateTypes.filter((t) => !["address", "phone", "email"].includes(t));
5262
5713
  if (UNKNOWN.length > 0) {
5263
5714
  console.error(`Error: --accept has unknown kind(s): ${UNKNOWN.join(", ")}. Known: address, phone, email.`);
@@ -5318,17 +5769,27 @@ Running conformance checks against: ${targetUrl}`);
5318
5769
  if (customerUrl) console.log(`Pull API checks against: ${customerUrl}`);
5319
5770
  console.log("");
5320
5771
  for (const line of describeCredentials(creds)) console.log(line ? ` ${line}` : "");
5321
- const results = await runChecks({
5772
+ if (loaSigner) {
5773
+ console.log(" Drill LOAs are signed with the key in --loa-signing-key. This is YOUR test key,");
5774
+ console.log(" not OneAddress's: configure your receiver with its public half for this run only.");
5775
+ console.log("");
5776
+ }
5777
+ const run = await runChecksDetailed({
5322
5778
  targetUrl,
5323
5779
  secret,
5324
5780
  partnerId,
5325
5781
  publicKeyB64: publicKey,
5782
+ ...recipient.key ? { key: recipient.key } : {},
5783
+ retentionPeriodDays: recipient.retentionPeriodDays,
5326
5784
  customerUrl,
5327
5785
  acceptedUpdateTypes,
5328
5786
  verifiesAccountReference,
5329
- accountRef
5787
+ supportsKeyCrossover,
5788
+ accountRef,
5789
+ loaSigner
5330
5790
  });
5331
- printReport(results);
5791
+ const results = run.checks;
5792
+ printReport(results, run.informational);
5332
5793
  const code = exitCode(results);
5333
5794
  process.exitCode = code;
5334
5795
  setTimeout(() => process.exit(code), 50).unref();