@oneaddress/partner-sdk 1.8.0 → 2.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.
package/dist/edge.js CHANGED
@@ -3364,6 +3364,70 @@ var init_safe_url = __esm({
3364
3364
  }
3365
3365
  });
3366
3366
 
3367
+ // ../crypto/src/endpoint-health.ts
3368
+ function classifyEndpointProbe(input) {
3369
+ const status = typeof input.httpStatus === "number" && Number.isFinite(input.httpStatus) ? input.httpStatus : null;
3370
+ if (status === null || status === 0) {
3371
+ const detail = input.error ? `: ${input.error}` : "";
3372
+ return {
3373
+ health: "unreachable",
3374
+ dispatchable: false,
3375
+ summary: `No response from the endpoint${detail}. Check the host is running and reachable.`
3376
+ };
3377
+ }
3378
+ if (status >= 200 && status < 300) {
3379
+ return {
3380
+ health: "healthy",
3381
+ dispatchable: true,
3382
+ summary: `Receiver accepted a signed test request (HTTP ${status}).`
3383
+ };
3384
+ }
3385
+ if (status === 401 || status === 403) {
3386
+ return {
3387
+ health: "auth",
3388
+ dispatchable: false,
3389
+ summary: `Receiver rejected our signature (HTTP ${status}). Check the signing secret matches on both sides.`
3390
+ };
3391
+ }
3392
+ if (MISSING_STATUSES.has(status)) {
3393
+ return {
3394
+ health: "missing",
3395
+ dispatchable: false,
3396
+ summary: `Host answered but no receiver is listening at this path (HTTP ${status}). A stopped tunnel or a stale URL looks exactly like this.`
3397
+ };
3398
+ }
3399
+ if (status === 429) {
3400
+ return {
3401
+ health: "throttled",
3402
+ dispatchable: false,
3403
+ summary: `Receiver is up and rate-limiting us (HTTP 429). Back off and retry, or raise the ceiling; nothing is wrong with the URL.`
3404
+ };
3405
+ }
3406
+ if (status >= 500) {
3407
+ return {
3408
+ health: "degraded",
3409
+ dispatchable: false,
3410
+ summary: `Receiver is present but erroring (HTTP ${status}).`
3411
+ };
3412
+ }
3413
+ return {
3414
+ health: "rejected",
3415
+ dispatchable: false,
3416
+ summary: `Receiver refused the request (HTTP ${status}).`
3417
+ };
3418
+ }
3419
+ function countsAsFailure(verdict) {
3420
+ return !verdict.dispatchable;
3421
+ }
3422
+ var ENDPOINT_FAILURE_THRESHOLD, MISSING_STATUSES;
3423
+ var init_endpoint_health = __esm({
3424
+ "../crypto/src/endpoint-health.ts"() {
3425
+ "use strict";
3426
+ ENDPOINT_FAILURE_THRESHOLD = 3;
3427
+ MISSING_STATUSES = /* @__PURE__ */ new Set([404, 405, 410]);
3428
+ }
3429
+ });
3430
+
3367
3431
  // ../crypto/src/partner-key-attestation.ts
3368
3432
  function assertNoDelimiter(field, value) {
3369
3433
  if (typeof value !== "string" || value.length === 0) {
@@ -3465,6 +3529,9 @@ function assertMapSafe(field, value) {
3465
3529
  }
3466
3530
  }
3467
3531
  function buildRegistryHeadStatement(payload) {
3532
+ if (!KNOWN_VERSIONS.has(payload.version)) {
3533
+ throw new Error(`[registry-head] unknown head version: ${String(payload.version)}`);
3534
+ }
3468
3535
  assertNoLineBreak("issued_at", payload.issued_at);
3469
3536
  assertNoLineBreak("expires_at", payload.expires_at);
3470
3537
  assertMapSafe("root_key_id", payload.root_key_id);
@@ -3481,14 +3548,42 @@ function buildRegistryHeadStatement(payload) {
3481
3548
  }
3482
3549
  seen.add(partnerId);
3483
3550
  }
3484
- return [
3485
- REGISTRY_HEAD_V1,
3551
+ const lines = [
3552
+ payload.version,
3486
3553
  `issued_at:${payload.issued_at}`,
3487
3554
  `expires_at:${payload.expires_at}`,
3488
3555
  `root_key_id:${payload.root_key_id}`,
3489
3556
  `heads:${entries.length}`,
3490
3557
  ...entries.map(([partnerId, keyId]) => `${partnerId}:${keyId}`)
3491
- ].join("\n");
3558
+ ];
3559
+ if (payload.version === REGISTRY_HEAD_V1) {
3560
+ if (payload.staged && Object.keys(payload.staged).length > 0) {
3561
+ throw new Error("[registry-head] v1 statement cannot carry staged entries");
3562
+ }
3563
+ return lines.join("\n");
3564
+ }
3565
+ const stagedEntries = Object.entries(payload.staged ?? {}).map(([partnerId, entry]) => {
3566
+ assertMapSafe("staged partner_id", partnerId);
3567
+ assertMapSafe("staged key_id", entry?.key_id);
3568
+ assertMapSafe("staged key_sha256", entry?.key_sha256);
3569
+ if (!/^[0-9a-f]{64}$/i.test(entry.key_sha256)) {
3570
+ throw new Error(`[registry-head] staged key_sha256 must be 64 hex chars: ${partnerId}`);
3571
+ }
3572
+ return [partnerId.toLowerCase(), entry.key_id.toLowerCase(), entry.key_sha256.toLowerCase()];
3573
+ });
3574
+ stagedEntries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
3575
+ const stagedSeen = /* @__PURE__ */ new Set();
3576
+ for (const [partnerId] of stagedEntries) {
3577
+ if (stagedSeen.has(partnerId)) {
3578
+ throw new Error(`[registry-head] duplicate partner_id in staged: ${partnerId}`);
3579
+ }
3580
+ stagedSeen.add(partnerId);
3581
+ }
3582
+ lines.push(`staged:${stagedEntries.length}`);
3583
+ for (const [partnerId, keyId, digest] of stagedEntries) {
3584
+ lines.push(`${partnerId}:${keyId}:${digest}`);
3585
+ }
3586
+ return lines.join("\n");
3492
3587
  }
3493
3588
  function b64ToBytes2(b64) {
3494
3589
  const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
@@ -3509,7 +3604,7 @@ function hexToBytes4(hex) {
3509
3604
  }
3510
3605
  async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date()) {
3511
3606
  try {
3512
- if (doc?.version !== REGISTRY_HEAD_V1) return "malformed";
3607
+ if (!doc || !KNOWN_VERSIONS.has(doc.version)) return "malformed";
3513
3608
  if (doc.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
3514
3609
  if (typeof doc.signature !== "string" || !/^[0-9a-f]{128}$/i.test(doc.signature)) return "malformed";
3515
3610
  if (!doc.heads || typeof doc.heads !== "object") return "malformed";
@@ -3524,7 +3619,14 @@ async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date())
3524
3619
  issued_at: doc.issued_at,
3525
3620
  expires_at: doc.expires_at,
3526
3621
  root_key_id: doc.root_key_id,
3527
- heads: doc.heads
3622
+ heads: doc.heads,
3623
+ // Passed through rather than dropped: the staged map is part of what the
3624
+ // root signed on a v2 head, so omitting it here would rebuild different
3625
+ // bytes and report `bad-signature` on a perfectly good document. On a v1
3626
+ // head the builder REFUSES a non-empty map, which lands here as
3627
+ // `malformed` — the right answer for a document claiming staged keys its
3628
+ // signature does not cover.
3629
+ staged: doc.staged
3528
3630
  });
3529
3631
  const rootKey = await crypto.subtle.importKey(
3530
3632
  "spki",
@@ -3550,11 +3652,34 @@ function headNamesKey(doc, partnerId, keyId) {
3550
3652
  const named = doc.heads?.[partnerId.toLowerCase()];
3551
3653
  return typeof named === "string" && named.toLowerCase() === keyId.toLowerCase();
3552
3654
  }
3553
- var REGISTRY_HEAD_V1, REGISTRY_HEAD_ALG;
3655
+ function headNamesPartner(doc, partnerId) {
3656
+ return typeof doc.heads?.[partnerId.toLowerCase()] === "string";
3657
+ }
3658
+ async function partnerKeyFingerprint(publicKeyB64) {
3659
+ const digest = await crypto.subtle.digest(
3660
+ "SHA-256",
3661
+ b64ToBytes2(publicKeyB64)
3662
+ );
3663
+ return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
3664
+ }
3665
+ async function headNamesStagedKey(doc, partnerId, keyId, publicKeyB64) {
3666
+ try {
3667
+ const entry = doc.staged?.[partnerId.toLowerCase()];
3668
+ if (!entry || typeof entry.key_id !== "string" || typeof entry.key_sha256 !== "string") return false;
3669
+ if (entry.key_id.toLowerCase() !== keyId.toLowerCase()) return false;
3670
+ if (!/^[0-9a-f]{64}$/i.test(entry.key_sha256)) return false;
3671
+ return await partnerKeyFingerprint(publicKeyB64) === entry.key_sha256.toLowerCase();
3672
+ } catch {
3673
+ return false;
3674
+ }
3675
+ }
3676
+ var REGISTRY_HEAD_V1, REGISTRY_HEAD_V2, KNOWN_VERSIONS, REGISTRY_HEAD_ALG;
3554
3677
  var init_registry_head = __esm({
3555
3678
  "../crypto/src/registry-head.ts"() {
3556
3679
  "use strict";
3557
3680
  REGISTRY_HEAD_V1 = "oneaddress-partner-key-registry-head:v1";
3681
+ REGISTRY_HEAD_V2 = "oneaddress-partner-key-registry-head:v2";
3682
+ KNOWN_VERSIONS = /* @__PURE__ */ new Set([REGISTRY_HEAD_V1, REGISTRY_HEAD_V2]);
3558
3683
  REGISTRY_HEAD_ALG = "ECDSA-P256";
3559
3684
  }
3560
3685
  });
@@ -3563,15 +3688,19 @@ var init_registry_head = __esm({
3563
3688
  var src_exports = {};
3564
3689
  __export(src_exports, {
3565
3690
  DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
3691
+ ENDPOINT_FAILURE_THRESHOLD: () => ENDPOINT_FAILURE_THRESHOLD,
3566
3692
  PARTNER_KEY_ATTESTATION_ALG: () => PARTNER_KEY_ATTESTATION_ALG,
3567
3693
  PARTNER_KEY_ATTESTATION_V1: () => PARTNER_KEY_ATTESTATION_V1,
3568
3694
  REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
3569
3695
  REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
3696
+ REGISTRY_HEAD_V2: () => REGISTRY_HEAD_V2,
3570
3697
  buildPartnerKeyAttestation: () => buildPartnerKeyAttestation,
3571
3698
  buildRegistryHeadStatement: () => buildRegistryHeadStatement,
3699
+ classifyEndpointProbe: () => classifyEndpointProbe,
3572
3700
  cleanNameAliases: () => cleanNameAliases,
3573
3701
  computeBlindIndex: () => computeBlindIndex,
3574
3702
  computeCustomerBlindIndex: () => computeCustomerBlindIndex,
3703
+ countsAsFailure: () => countsAsFailure,
3575
3704
  decryptAddress: () => decryptAddress,
3576
3705
  decryptSession: () => decryptSession,
3577
3706
  encryptAddressForAll: () => encryptAddressForAll,
@@ -3583,12 +3712,15 @@ __export(src_exports, {
3583
3712
  generateHybridPartnerKeyPair: () => generateHybridPartnerKeyPair,
3584
3713
  generatePartnerKeyPair: () => generatePartnerKeyPair,
3585
3714
  headNamesKey: () => headNamesKey,
3715
+ headNamesPartner: () => headNamesPartner,
3716
+ headNamesStagedKey: () => headNamesStagedKey,
3586
3717
  isEmailLike: () => isEmailLike,
3587
3718
  isFreshTimestamp: () => isFreshTimestamp,
3588
3719
  isIpLiteralHost: () => isIpLiteralHost,
3589
3720
  isSafeWebhookUrl: () => isSafeWebhookUrl,
3590
3721
  normaliseAddress: () => normaliseAddress,
3591
3722
  normalizeForBlindIndex: () => normalizeForBlindIndex,
3723
+ partnerKeyFingerprint: () => partnerKeyFingerprint,
3592
3724
  rootKeyIdFromSpki: () => rootKeyIdFromSpki,
3593
3725
  rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
3594
3726
  signWebhookPayload: () => signWebhookPayload,
@@ -3972,13 +4104,18 @@ async function encryptSessionForAll(partners) {
3972
4104
  );
3973
4105
  return Object.fromEntries(results.map((r) => [r.partner_id, r]));
3974
4106
  }
3975
- async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
4107
+ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId, expectedAlg) {
3976
4108
  if (share.alg !== "ECDH-ES+HKDF-SHA256+A256GCM" && share.alg !== "RSA-OAEP-256+A256GCM" && share.alg !== "MLKEM768X25519+HKDF-SHA256+A256GCM") {
3977
4109
  throw new Error(`decryptSession: unsupported alg ${share.alg}`);
3978
4110
  }
3979
4111
  if (share.v !== 2) {
3980
4112
  throw new Error(`decryptSession: unsupported share version ${share.v}`);
3981
4113
  }
4114
+ if (expectedAlg && share.alg !== expectedAlg) {
4115
+ throw new Error(
4116
+ `decryptSession: algorithm downgrade - the dispatch wraps SK_n as ${share.alg}, but this key is provisioned for ${expectedAlg}. Refusing rather than attempting a different wrap than the recipient chose.`
4117
+ );
4118
+ }
3982
4119
  const ops = typeof privateKeyB64 === "string" ? null : privateKeyB64;
3983
4120
  if (ops) {
3984
4121
  if (share.alg === "MLKEM768X25519+HKDF-SHA256+A256GCM") {
@@ -4213,9 +4350,18 @@ var init_src = __esm({
4213
4350
  init_hybrid();
4214
4351
  init_replay_window();
4215
4352
  init_safe_url();
4353
+ init_endpoint_health();
4216
4354
  init_partner_key_attestation();
4217
4355
  init_registry_head();
4218
- subtle = () => globalThis.crypto.subtle;
4356
+ subtle = () => {
4357
+ const webcrypto = globalThis.crypto;
4358
+ if (!webcrypto?.subtle) {
4359
+ throw new Error(
4360
+ "Web Crypto is unavailable in this runtime, so no encryption or key operation can run. In Node this needs version 19 or later, where globalThis.crypto is enabled by default (Node 18 has it behind --experimental-global-webcrypto, and is itself end-of-life). Check with `node -v` and upgrade, or re-run with NODE_OPTIONS=--experimental-global-webcrypto as a one-off."
4361
+ );
4362
+ }
4363
+ return webcrypto.subtle;
4364
+ };
4219
4365
  AU_STATE_FULL = {
4220
4366
  "new south wales": "NSW",
4221
4367
  "victoria": "VIC",
@@ -4413,13 +4559,14 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
4413
4559
  );
4414
4560
  return JSON.parse(new TextDecoder().decode(plaintext));
4415
4561
  }
4416
- async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId) {
4562
+ async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
4417
4563
  const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
4418
4564
  return decryptSessionCrypto(
4419
4565
  share,
4420
4566
  envelopeB64,
4421
4567
  typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
4422
- partnerId
4568
+ partnerId,
4569
+ expectedAlg
4423
4570
  );
4424
4571
  }
4425
4572
  async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
@@ -4664,12 +4811,32 @@ function compareAddresses(a, b) {
4664
4811
  if (aCountry && bCountry && aCountry !== bCountry) return false;
4665
4812
  return true;
4666
4813
  }
4814
+ function isAllowedCallbackHost(raw, extraHosts) {
4815
+ let host;
4816
+ try {
4817
+ const u = new URL(raw);
4818
+ if (u.protocol !== "https:") return false;
4819
+ host = u.hostname.toLowerCase();
4820
+ } catch {
4821
+ return false;
4822
+ }
4823
+ if (host === "oneaddress.io" || host.endsWith(".oneaddress.io")) return true;
4824
+ const envRaw = typeof process !== "undefined" ? process.env?.OA_CALLBACK_HOST_ALLOWLIST ?? "" : "";
4825
+ const allowed = [
4826
+ ...envRaw.split(",").map((h) => h.trim().toLowerCase()),
4827
+ ...(extraHosts ?? []).map((h) => h.trim().toLowerCase())
4828
+ ].filter(Boolean);
4829
+ return allowed.includes(host);
4830
+ }
4667
4831
  async function sendVerifyResult(params) {
4668
- const { callbackUrl, callbackToken, batchId, partnerId, match, note } = params;
4832
+ const { callbackUrl, callbackToken, batchId, partnerId, match, note, allowedCallbackHosts } = params;
4669
4833
  const safe = isSafeWebhookUrl(callbackUrl);
4670
4834
  if (!safe.ok) {
4671
4835
  throw new Error(`[OneAddress SDK] refusing verify-result callback to unsafe URL: ${safe.reason}`);
4672
4836
  }
4837
+ if (!isAllowedCallbackHost(callbackUrl, allowedCallbackHosts)) {
4838
+ throw new Error(`[OneAddress SDK] refusing verify-result callback to non-OneAddress host: ${callbackUrl}`);
4839
+ }
4673
4840
  const res = await fetch(callbackUrl, {
4674
4841
  method: "POST",
4675
4842
  headers: { "Content-Type": "application/json" },
@@ -4686,7 +4853,38 @@ async function sendVerifyResult(params) {
4686
4853
  throw new Error(`[OneAddress SDK] verify-result callback to ${callbackUrl} failed: HTTP ${res.status}`);
4687
4854
  }
4688
4855
  }
4689
- var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test", "address.test-dispatch"];
4856
+ var UPDATE_TYPE_ORDER = ["address", "phone", "email"];
4857
+ function normaliseAcceptedUpdateTypes(raw) {
4858
+ const kept = new Set(Array.isArray(raw) ? raw.filter((v) => typeof v === "string") : []);
4859
+ return UPDATE_TYPE_ORDER.filter((t) => t === "address" || kept.has(t));
4860
+ }
4861
+ function readUpdateTypes(raw) {
4862
+ if (raw === void 0 || raw === null) return ["address"];
4863
+ if (!Array.isArray(raw)) return null;
4864
+ if (raw.length === 0) return ["address"];
4865
+ const out = [];
4866
+ for (const v of raw) {
4867
+ if (typeof v !== "string" || !UPDATE_TYPE_ORDER.includes(v)) return null;
4868
+ if (!out.includes(v)) out.push(v);
4869
+ }
4870
+ return out;
4871
+ }
4872
+ var InvalidUpdateTypesError = class extends Error {
4873
+ constructor(raw) {
4874
+ super("[OneAddress SDK] update_types names a kind this build does not know");
4875
+ this.raw = raw;
4876
+ this.name = "InvalidUpdateTypesError";
4877
+ }
4878
+ };
4879
+ function requireContactValue(kind, value) {
4880
+ if (typeof value !== "string" || value === "") {
4881
+ throw new Error(
4882
+ `[OneAddress SDK] Decrypted envelope declares update_types "${kind}" but carries no new_${kind}. This may indicate a decryption error or a schema change. Update @oneaddress/partner-sdk.`
4883
+ );
4884
+ }
4885
+ return value;
4886
+ }
4887
+ var HANDLED_EVENTS = ["address.updated", "contact.updated", "address.verify", "account.verify", "address.test", "address.test-dispatch"];
4690
4888
  var warnedUnhandledEvents = /* @__PURE__ */ new Set();
4691
4889
  function createOneAddressHandler(options) {
4692
4890
  const {
@@ -4694,25 +4892,39 @@ function createOneAddressHandler(options) {
4694
4892
  previousWebhookSecret,
4695
4893
  webhookSecretGraceUntil,
4696
4894
  privateKeyPem,
4895
+ keyId,
4697
4896
  loaPublicKeyPem,
4698
4897
  onUpdate,
4699
4898
  onVerify,
4700
4899
  onAccountVerify,
4701
4900
  onTest,
4702
4901
  timestampToleranceSecs = 300,
4703
- idempotencyStore
4902
+ idempotencyStore,
4903
+ acceptedUpdateTypes: acceptedUpdateTypesRaw,
4904
+ allowedCallbackHosts
4704
4905
  } = options;
4906
+ const acceptedUpdateTypes = normaliseAcceptedUpdateTypes(acceptedUpdateTypesRaw);
4907
+ function declared(status, payload) {
4908
+ return new Response(JSON.stringify({ ...payload, accepted_update_types: acceptedUpdateTypes }), {
4909
+ status,
4910
+ headers: { "Content-Type": "application/json" }
4911
+ });
4912
+ }
4705
4913
  async function buildD5Pieces(body, partnerId) {
4706
4914
  const share = body.session_key_share;
4707
4915
  const data = await decryptSession2(share, body.session_envelope, privateKeyPem, partnerId);
4708
- const address = validateAddress({
4916
+ const updateTypes = readUpdateTypes(data.update_types);
4917
+ if (updateTypes === null) throw new InvalidUpdateTypesError(data.update_types);
4918
+ const address = updateTypes.includes("address") ? validateAddress({
4709
4919
  street: data.new_address?.street,
4710
4920
  suburb: data.new_address?.suburb,
4711
4921
  state: data.new_address?.state,
4712
4922
  postcode: data.new_address?.postcode,
4713
4923
  country: data.new_address?.country,
4714
4924
  updated_at: data.dispatch_timestamp ?? body.timestamp ?? ""
4715
- });
4925
+ }) : void 0;
4926
+ const newPhone = updateTypes.includes("phone") ? requireContactValue("phone", data.new_phone) : void 0;
4927
+ const newEmail = updateTypes.includes("email") ? requireContactValue("email", data.new_email) : void 0;
4716
4928
  const customer = {
4717
4929
  email: "",
4718
4930
  name: data.verified_name ?? "",
@@ -4733,11 +4945,19 @@ function createOneAddressHandler(options) {
4733
4945
  if (!valid) throw new Error("D5 LOA signature verification failed");
4734
4946
  }
4735
4947
  }
4736
- return { address, customer, loa, loa_ref, raw: data };
4948
+ return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
4737
4949
  }
4738
4950
  function isD5Body(body) {
4739
4951
  return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
4740
4952
  }
4953
+ function isCrossoverSiblingToSkip(body) {
4954
+ if (!keyId || !isD5Body(body)) return false;
4955
+ const share = body.session_key_share;
4956
+ const shareKeyId = typeof share?.key_id === "string" ? share.key_id : "";
4957
+ if (!shareKeyId || shareKeyId === keyId) return false;
4958
+ const siblings = body.crossover_key_ids;
4959
+ return Array.isArray(siblings) && siblings.includes(keyId);
4960
+ }
4741
4961
  return async function handler(req) {
4742
4962
  const rawBody = await req.text();
4743
4963
  const sig = req.headers.get("x-oneaddress-signature") ?? "";
@@ -4773,6 +4993,9 @@ function createOneAddressHandler(options) {
4773
4993
  const partnerId = body.partner_id ?? "";
4774
4994
  const tsNum = Number(tsHeader);
4775
4995
  const dispatchId = req.headers.get("x-oneaddress-dispatch") ?? "";
4996
+ if (isCrossoverSiblingToSkip(body)) {
4997
+ return declared(200, { ok: true, skipped: true, crossover: true });
4998
+ }
4776
4999
  if (dispatchId) {
4777
5000
  if (!idempotencyStore) {
4778
5001
  if (process.env.NODE_ENV === "test") {
@@ -4783,41 +5006,64 @@ function createOneAddressHandler(options) {
4783
5006
  } else if (idempotencyStore.claim) {
4784
5007
  const claim = await idempotencyStore.claim(dispatchId);
4785
5008
  if (claim === "duplicate") {
4786
- return new Response(JSON.stringify({ ok: true, duplicate: true }), {
4787
- status: 200,
4788
- headers: { "Content-Type": "application/json" }
4789
- });
5009
+ return declared(200, { ok: true, duplicate: true });
4790
5010
  }
4791
5011
  } else {
4792
5012
  const alreadySeen = await idempotencyStore.has(dispatchId);
4793
5013
  if (alreadySeen) {
4794
- return new Response(JSON.stringify({ ok: true, duplicate: true }), {
4795
- status: 200,
4796
- headers: { "Content-Type": "application/json" }
4797
- });
5014
+ return declared(200, { ok: true, duplicate: true });
4798
5015
  }
4799
5016
  }
4800
5017
  }
4801
5018
  try {
4802
- if (body.event === "address.updated") {
5019
+ if (body.event === "address.updated" || body.event === "contact.updated") {
5020
+ const wireEvent = body.event;
4803
5021
  let event;
4804
5022
  if (isD5Body(body)) {
4805
- const d5 = await buildD5Pieces(body, partnerId);
5023
+ let d5;
5024
+ try {
5025
+ d5 = await buildD5Pieces(body, partnerId);
5026
+ } catch (err) {
5027
+ if (err instanceof InvalidUpdateTypesError) {
5028
+ return declared(422, {
5029
+ error: "invalid_update_types",
5030
+ detail: "update_types must be an array of " + UPDATE_TYPE_ORDER.join("|") + ". A name this build does not know was refused rather than dropped. Update @oneaddress/partner-sdk."
5031
+ });
5032
+ }
5033
+ throw err;
5034
+ }
5035
+ const notAccepted = d5.updateTypes.filter((t) => !acceptedUpdateTypes.includes(t));
5036
+ if (notAccepted.length > 0) {
5037
+ return declared(422, {
5038
+ error: "update_type_not_accepted",
5039
+ update_types: notAccepted,
5040
+ detail: "This receiver declares acceptedUpdateTypes " + JSON.stringify(acceptedUpdateTypes) + " and the dispatch carries " + JSON.stringify(d5.updateTypes) + ". Nothing was processed. Widen acceptedUpdateTypes once onUpdate stores the new kind, then re-run conformance."
5041
+ });
5042
+ }
4806
5043
  event = {
4807
- event: "address.updated",
5044
+ event: wireEvent,
4808
5045
  version: body.oneaddress_version ?? body.version ?? "2.0",
4809
5046
  id: body.id ?? "",
4810
5047
  timestamp: tsNum,
4811
5048
  partner_id: partnerId,
4812
5049
  dispatchId,
4813
5050
  customer: d5.customer,
5051
+ update_types: d5.updateTypes,
4814
5052
  address: d5.address,
5053
+ new_phone: d5.newPhone,
5054
+ new_email: d5.newEmail,
4815
5055
  loa: d5.loa,
4816
5056
  loa_ref: d5.loa_ref,
4817
5057
  id_verification: body.id_verification,
4818
5058
  raw: d5.raw
4819
5059
  };
4820
5060
  } else {
5061
+ if (wireEvent === "contact.updated") {
5062
+ return declared(400, {
5063
+ error: "missing_session_envelope",
5064
+ detail: "contact.updated requires session_envelope + session_key_share"
5065
+ });
5066
+ }
4821
5067
  if (!body.address_encrypted || typeof body.address_encrypted !== "object") {
4822
5068
  return new Response(JSON.stringify({ error: "Missing or invalid address_encrypted payload" }), {
4823
5069
  status: 400,
@@ -4853,6 +5099,8 @@ function createOneAddressHandler(options) {
4853
5099
  partner_id: partnerId,
4854
5100
  dispatchId,
4855
5101
  customer,
5102
+ // The legacy blob predates kinds and always carries an address.
5103
+ update_types: ["address"],
4856
5104
  address: validateAddress(rawAddress),
4857
5105
  loa,
4858
5106
  loa_ref,
@@ -4868,10 +5116,7 @@ function createOneAddressHandler(options) {
4868
5116
  // NOSONAR
4869
5117
  );
4870
5118
  }
4871
- return new Response(JSON.stringify({ ok: true, ...result }), {
4872
- status: 200,
4873
- headers: { "Content-Type": "application/json" }
4874
- });
5119
+ return declared(200, { ok: true, ...result });
4875
5120
  }
4876
5121
  if (body.event === "address.verify" && onVerify) {
4877
5122
  if (!body.address_encrypted || typeof body.address_encrypted !== "object") {
@@ -4914,16 +5159,14 @@ function createOneAddressHandler(options) {
4914
5159
  batchId: body.batch_id ?? 0,
4915
5160
  partnerId,
4916
5161
  match: matched,
4917
- note: result && typeof result.note === "string" ? result.note : void 0
5162
+ note: result && typeof result.note === "string" ? result.note : void 0,
5163
+ allowedCallbackHosts
4918
5164
  });
4919
5165
  } catch (err) {
4920
5166
  console.error("[OneAddress SDK] verify-result callback failed:", err);
4921
5167
  }
4922
5168
  }
4923
- return new Response(JSON.stringify({ ok: true, match: matched }), {
4924
- status: 200,
4925
- headers: { "Content-Type": "application/json" }
4926
- });
5169
+ return declared(200, { ok: true, match: matched });
4927
5170
  }
4928
5171
  if (body.event === "account.verify" && onAccountVerify) {
4929
5172
  let customer;
@@ -4954,10 +5197,7 @@ function createOneAddressHandler(options) {
4954
5197
  raw: body
4955
5198
  };
4956
5199
  const result = await onAccountVerify(event);
4957
- return new Response(JSON.stringify({ ok: true, ...result }), {
4958
- status: 200,
4959
- headers: { "Content-Type": "application/json" }
4960
- });
5200
+ return declared(200, { ok: true, ...result });
4961
5201
  }
4962
5202
  if ((body.event === "address.test" || body.event === "address.test-dispatch") && onTest) {
4963
5203
  if (!isD5Body(body)) {
@@ -4967,6 +5207,7 @@ function createOneAddressHandler(options) {
4967
5207
  });
4968
5208
  }
4969
5209
  const d5 = await buildD5Pieces(body, partnerId);
5210
+ if (!d5.address) throw new Error("[OneAddress SDK] test record carries no address");
4970
5211
  await onTest({
4971
5212
  event: body.event,
4972
5213
  index: typeof body.index === "number" ? body.index : void 0,
@@ -4978,10 +5219,7 @@ function createOneAddressHandler(options) {
4978
5219
  address: d5.address,
4979
5220
  raw: d5.raw
4980
5221
  });
4981
- return new Response(JSON.stringify({ ok: true, test: true }), {
4982
- status: 200,
4983
- headers: { "Content-Type": "application/json" }
4984
- });
5222
+ return declared(200, { ok: true, test: true });
4985
5223
  }
4986
5224
  const evt = typeof body.event === "string" ? body.event : "(none)";
4987
5225
  const callbackFor = {
@@ -5007,7 +5245,7 @@ function createOneAddressHandler(options) {
5007
5245
  // NOSONAR
5008
5246
  );
5009
5247
  }
5010
- return new Response(JSON.stringify({ ok: true, skipped: true, event: evt }), {
5248
+ return new Response(JSON.stringify({ ok: true, skipped: true, event: evt, accepted_update_types: acceptedUpdateTypes }), {
5011
5249
  status: 200,
5012
5250
  headers: { "Content-Type": "application/json" }
5013
5251
  });
package/dist/edge.mjs CHANGED
@@ -20,13 +20,13 @@ import {
20
20
  verifyLOA,
21
21
  verifySignature,
22
22
  verifyWithGrace
23
- } from "./chunk-PUB6ZVJ2.mjs";
23
+ } from "./chunk-UPJU4HFR.mjs";
24
24
  import {
25
25
  DEFAULT_REPLAY_WINDOW_SECS,
26
26
  computeBlindIndex,
27
27
  isFreshTimestamp,
28
28
  normalizeForBlindIndex
29
- } from "./chunk-O2D5XGSN.mjs";
29
+ } from "./chunk-DUVPNFU6.mjs";
30
30
  export {
31
31
  CURRENT_VERSION,
32
32
  DEFAULT_REPLAY_WINDOW_SECS,