@oneaddress/partner-sdk 2.8.0 → 2.10.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
@@ -4095,6 +4095,16 @@ var init_replay_window = __esm({
4095
4095
  }
4096
4096
  });
4097
4097
 
4098
+ // ../crypto/src/refund-review-notify.ts
4099
+ function refundReviewNotifySigningString(timestamp, rawBody) {
4100
+ return `oneaddress.refund-review-notify.v1.${timestamp}.${rawBody}`;
4101
+ }
4102
+ var init_refund_review_notify = __esm({
4103
+ "../crypto/src/refund-review-notify.ts"() {
4104
+ "use strict";
4105
+ }
4106
+ });
4107
+
4098
4108
  // ../crypto/src/safe-url.ts
4099
4109
  function parseIPv4Component(raw) {
4100
4110
  if (raw.length === 0) return null;
@@ -4476,11 +4486,29 @@ var init_partner_key_attestation = __esm({
4476
4486
  });
4477
4487
 
4478
4488
  // ../crypto/src/registry-root-pin.ts
4489
+ function registryEnvironmentForOrigin(origin) {
4490
+ let o = origin ?? "";
4491
+ if (!o) {
4492
+ const loc = globalThis.location;
4493
+ o = loc?.origin ?? "";
4494
+ }
4495
+ if (!o) return "preview";
4496
+ try {
4497
+ const host = new URL(o).hostname.toLowerCase().replace(/\.$/, "");
4498
+ return PRODUCTION_REGISTRY_HOSTS.includes(host) ? "production" : "preview";
4499
+ } catch {
4500
+ return "preview";
4501
+ }
4502
+ }
4479
4503
  function __setPinnedRegistryRootsForTests(pins) {
4480
4504
  overrideForTests = pins;
4481
4505
  }
4482
- function pinnedRegistryRoots() {
4483
- return overrideForTests ?? PINNED_REGISTRY_ROOTS;
4506
+ function pinnedRegistryRoots(env = "production") {
4507
+ if (overrideForTests) {
4508
+ if (Array.isArray(overrideForTests)) return overrideForTests;
4509
+ return overrideForTests[env] ?? [];
4510
+ }
4511
+ return REGISTRY_ROOT_PINS[env];
4484
4512
  }
4485
4513
  function b64ToBytes2(b64) {
4486
4514
  const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
@@ -4493,34 +4521,47 @@ async function spkiSha256HexFromB64(spkiB64) {
4493
4521
  const digest = await crypto.subtle.digest("SHA-256", b64ToBytes2(spkiB64));
4494
4522
  return bytesToHex3(new Uint8Array(digest));
4495
4523
  }
4496
- async function rootIsPinned(root) {
4524
+ async function rootIsPinned(root, env = "production") {
4497
4525
  try {
4498
4526
  const digest = await spkiSha256HexFromB64(root.public_key_b64);
4499
- return pinnedRegistryRoots().some(
4527
+ return pinnedRegistryRoots(env).some(
4500
4528
  (p) => p.root_key_id === root.root_key_id && p.spki_sha256 === digest
4501
4529
  );
4502
4530
  } catch {
4503
4531
  return false;
4504
4532
  }
4505
4533
  }
4506
- async function unpinnedRootIds(roots) {
4534
+ async function unpinnedRootIds(roots, env = "production") {
4507
4535
  const out = [];
4508
4536
  for (const root of roots) {
4509
- if (!await rootIsPinned(root)) out.push(String(root?.root_key_id ?? "(no id)"));
4537
+ if (!await rootIsPinned(root, env)) out.push(String(root?.root_key_id ?? "(no id)"));
4510
4538
  }
4511
4539
  return out;
4512
4540
  }
4513
- var PINNED_REGISTRY_ROOTS, overrideForTests;
4541
+ var PRODUCTION_REGISTRY_HOSTS, PRODUCTION_ROOT, REGISTRY_ROOT_PINS, PINNED_REGISTRY_ROOTS, overrideForTests;
4514
4542
  var init_registry_root_pin = __esm({
4515
4543
  "../crypto/src/registry-root-pin.ts"() {
4516
4544
  "use strict";
4517
4545
  init_partner_key_attestation();
4518
- PINNED_REGISTRY_ROOTS = Object.freeze([
4519
- Object.freeze({
4520
- root_key_id: "rk1_251368ec9b0a84ae",
4521
- spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4522
- })
4546
+ PRODUCTION_REGISTRY_HOSTS = Object.freeze([
4547
+ "oneaddress.io",
4548
+ "www.oneaddress.io",
4549
+ "app.oneaddress.io"
4523
4550
  ]);
4551
+ PRODUCTION_ROOT = Object.freeze({
4552
+ root_key_id: "rk1_251368ec9b0a84ae",
4553
+ spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4554
+ });
4555
+ REGISTRY_ROOT_PINS = Object.freeze({
4556
+ production: Object.freeze([PRODUCTION_ROOT]),
4557
+ preview: Object.freeze([
4558
+ Object.freeze({
4559
+ root_key_id: "rk1_4690d67464893d48",
4560
+ spki_sha256: "4690d67464893d48ebb335bcd29f3203fbacefbc69afd8a047b639521296bfab"
4561
+ })
4562
+ ])
4563
+ });
4564
+ PINNED_REGISTRY_ROOTS = REGISTRY_ROOT_PINS.production;
4524
4565
  overrideForTests = null;
4525
4566
  }
4526
4567
  });
@@ -4711,6 +4752,30 @@ var init_registry_head = __esm({
4711
4752
  });
4712
4753
 
4713
4754
  // ../crypto/src/verify-partner-keys.ts
4755
+ function localStorageHeadHighWater(key = "oa-registry-head-issued-at") {
4756
+ return {
4757
+ read() {
4758
+ try {
4759
+ return globalThis.localStorage?.getItem(key) ?? null;
4760
+ } catch {
4761
+ return null;
4762
+ }
4763
+ },
4764
+ write(issuedAt) {
4765
+ try {
4766
+ globalThis.localStorage?.setItem(key, issuedAt);
4767
+ } catch {
4768
+ }
4769
+ }
4770
+ };
4771
+ }
4772
+ function isOlderThan(candidate, mark) {
4773
+ if (!mark) return false;
4774
+ const m = Date.parse(mark);
4775
+ const c = Date.parse(candidate);
4776
+ if (Number.isNaN(m)) return false;
4777
+ return Number.isNaN(c) || c < m;
4778
+ }
4714
4779
  async function saysRootNotConfigured(res) {
4715
4780
  if (res.status !== 503) return false;
4716
4781
  try {
@@ -4746,19 +4811,61 @@ async function crossoverOutcomeFor(partnerId, crossover, reg) {
4746
4811
  if (!reg.head) return "head-unusable";
4747
4812
  return await headNamesStagedKey(reg.head, partnerId, crossover.key_id, crossover.public_key_b64) ? "ok" : "not-authorised";
4748
4813
  }
4814
+ function refuseAll(keys, outcome) {
4815
+ const blocked = {};
4816
+ const crossoverBlocked = {};
4817
+ try {
4818
+ for (const [partnerId, key] of Object.entries(keys ?? {})) {
4819
+ blocked[partnerId] = outcome;
4820
+ if (key?.crossover) crossoverBlocked[partnerId] = "head-unusable";
4821
+ }
4822
+ } catch {
4823
+ }
4824
+ return { blocked, crossoverBlocked };
4825
+ }
4749
4826
  function createPartnerKeyVerifier(env = {}) {
4750
4827
  const baseUrl = env.baseUrl ?? "";
4751
- const report = env.report ?? (() => {
4752
- });
4828
+ const report = (context, detail) => {
4829
+ try {
4830
+ env.report?.(context, detail);
4831
+ } catch {
4832
+ }
4833
+ };
4753
4834
  let registryPromise = null;
4754
4835
  function worthCaching(load) {
4755
4836
  return load.ok && load.registry.head !== null;
4756
4837
  }
4838
+ async function readMark() {
4839
+ try {
4840
+ const v = await env.headHighWater?.read();
4841
+ return typeof v === "string" ? v : null;
4842
+ } catch {
4843
+ return null;
4844
+ }
4845
+ }
4846
+ async function writeMark(issuedAt) {
4847
+ try {
4848
+ await env.headHighWater?.write(issuedAt);
4849
+ } catch {
4850
+ }
4851
+ }
4852
+ async function judgeHead(headRes, roots) {
4853
+ if (!headRes.ok) return { head: null, headVerdict: "absent" };
4854
+ let head;
4855
+ try {
4856
+ head = await headRes.json();
4857
+ } catch {
4858
+ return { head: null, headVerdict: "unreadable" };
4859
+ }
4860
+ const headVerdict = await verifyRegistryHead(head, roots);
4861
+ return headVerdict === "ok" ? { head, headVerdict } : { head: null, headVerdict };
4862
+ }
4757
4863
  async function loadRegistry() {
4758
4864
  try {
4865
+ const headUrl = baseUrl + "/.well-known/oneaddress-key-registry-head.json";
4759
4866
  const [rootsRes, headRes] = await Promise.all([
4760
4867
  fetch(baseUrl + "/.well-known/oneaddress-key-registry.json", { cache: "no-cache" }),
4761
- fetch(baseUrl + "/.well-known/oneaddress-key-registry-head.json", { cache: "no-cache" })
4868
+ fetch(headUrl, { cache: "no-cache" })
4762
4869
  ]);
4763
4870
  if (!rootsRes.ok) {
4764
4871
  const configured = await saysRootNotConfigured(rootsRes);
@@ -4780,16 +4887,30 @@ function createPartnerKeyVerifier(env = {}) {
4780
4887
  if (roots.length === 0) {
4781
4888
  return { ok: false, failure: { reason: "roots-empty", status: rootsRes.status } };
4782
4889
  }
4783
- const unpinnedRoots = await unpinnedRootIds(roots);
4890
+ const unpinnedRoots = await unpinnedRootIds(roots, registryEnvironmentForOrigin(baseUrl));
4784
4891
  if (unpinnedRoots.length > 0) {
4785
4892
  return { ok: true, registry: { roots: [], head: null, headVerdict: "root-unpinned", unpinnedRoots } };
4786
4893
  }
4787
- let head = null;
4788
- let headVerdict = "absent";
4789
- if (headRes.ok) {
4790
- head = await headRes.json();
4791
- headVerdict = await verifyRegistryHead(head, roots);
4792
- if (headVerdict !== "ok" && headVerdict !== "expired") head = null;
4894
+ let { head, headVerdict } = await judgeHead(headRes, roots);
4895
+ if (head) {
4896
+ const mark = await readMark();
4897
+ if (isOlderThan(head.issued_at, mark)) {
4898
+ let fresh = { head: null, headVerdict: "absent" };
4899
+ try {
4900
+ fresh = await judgeHead(
4901
+ await fetch(`${headUrl}?fresh=${Date.now()}`, { cache: "reload" }),
4902
+ roots
4903
+ );
4904
+ } catch {
4905
+ }
4906
+ if (fresh.head && !isOlderThan(fresh.head.issued_at, mark)) {
4907
+ ({ head, headVerdict } = fresh);
4908
+ } else {
4909
+ head = null;
4910
+ headVerdict = "rolled-back";
4911
+ }
4912
+ }
4913
+ if (head && head.issued_at !== mark) await writeMark(head.issued_at);
4793
4914
  }
4794
4915
  return { ok: true, registry: { roots, head, headVerdict, unpinnedRoots: [] } };
4795
4916
  } catch {
@@ -4802,8 +4923,8 @@ function createPartnerKeyVerifier(env = {}) {
4802
4923
  const load = await pending;
4803
4924
  if (!worthCaching(load)) registryPromise = null;
4804
4925
  if (!load.ok) {
4805
- report(context, { registry: "unavailable", enforced: false, ...load.failure });
4806
- return { blocked: {}, crossoverBlocked: {} };
4926
+ report(context, { registry: "unavailable", enforced: true, ...load.failure });
4927
+ return refuseAll(keys, "registry-unavailable");
4807
4928
  }
4808
4929
  const reg = load.registry;
4809
4930
  let bound = EMPTY_BOUND;
@@ -4824,6 +4945,7 @@ function createPartnerKeyVerifier(env = {}) {
4824
4945
  "not-in-head": [],
4825
4946
  "head-unusable": [],
4826
4947
  "root-unpinned": [],
4948
+ "registry-unavailable": [],
4827
4949
  "error": []
4828
4950
  };
4829
4951
  const blocked = {};
@@ -4875,8 +4997,8 @@ function createPartnerKeyVerifier(env = {}) {
4875
4997
  }
4876
4998
  return { blocked, crossoverBlocked };
4877
4999
  } catch {
4878
- report(context, { registry: "verifier-error", enforced: false });
4879
- return { blocked: {}, crossoverBlocked: {} };
5000
+ report(context, { registry: "verifier-error", enforced: true });
5001
+ return refuseAll(keys, "error");
4880
5002
  }
4881
5003
  }
4882
5004
  function __resetRegistryCacheForTests() {
@@ -5077,9 +5199,11 @@ __export(src_exports, {
5077
5199
  PARTNER_KEY_REFUSED_MESSAGE: () => PARTNER_KEY_REFUSED_MESSAGE,
5078
5200
  PINNED_REGISTRY_ROOTS: () => PINNED_REGISTRY_ROOTS,
5079
5201
  PIN_HARDENING_VERSION: () => PIN_HARDENING_VERSION,
5202
+ PRODUCTION_REGISTRY_HOSTS: () => PRODUCTION_REGISTRY_HOSTS,
5080
5203
  REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
5081
5204
  REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
5082
5205
  REGISTRY_HEAD_V2: () => REGISTRY_HEAD_V2,
5206
+ REGISTRY_ROOT_PINS: () => REGISTRY_ROOT_PINS,
5083
5207
  SENDER_HELD_KEY_ALGORITHM: () => SENDER_HELD_KEY_ALGORITHM,
5084
5208
  __setPinnedRegistryRootsForTests: () => __setPinnedRegistryRootsForTests,
5085
5209
  blockedPublicKeyReason: () => blockedPublicKeyReason,
@@ -5113,6 +5237,7 @@ __export(src_exports, {
5113
5237
  isIpLiteralHost: () => isIpLiteralHost,
5114
5238
  isSafeWebhookUrl: () => isSafeWebhookUrl,
5115
5239
  keyIdForPublicKey: () => keyIdForPublicKey,
5240
+ localStorageHeadHighWater: () => localStorageHeadHighWater,
5116
5241
  memorySenderHeldKeyStore: () => memorySenderHeldKeyStore,
5117
5242
  normaliseAddress: () => normaliseAddress,
5118
5243
  normalizeForBlindIndex: () => normalizeForBlindIndex,
@@ -5120,6 +5245,8 @@ __export(src_exports, {
5120
5245
  parseOprfSeed: () => parseOprfSeed,
5121
5246
  partnerKeyFingerprint: () => partnerKeyFingerprint,
5122
5247
  pinnedRegistryRoots: () => pinnedRegistryRoots,
5248
+ refundReviewNotifySigningString: () => refundReviewNotifySigningString,
5249
+ registryEnvironmentForOrigin: () => registryEnvironmentForOrigin,
5123
5250
  rootIsPinned: () => rootIsPinned,
5124
5251
  rootKeyIdFromSpki: () => rootKeyIdFromSpki,
5125
5252
  rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
@@ -5752,6 +5879,7 @@ var init_src = __esm({
5752
5879
  "use strict";
5753
5880
  init_hybrid();
5754
5881
  init_replay_window();
5882
+ init_refund_review_notify();
5755
5883
  init_safe_url();
5756
5884
  init_blocked_public_keys();
5757
5885
  init_endpoint_health();
@@ -5803,6 +5931,7 @@ __export(index_exports, {
5803
5931
  DEFAULT_IDEMPOTENCY_LEASE_SECS: () => DEFAULT_IDEMPOTENCY_LEASE_SECS,
5804
5932
  DEFAULT_MAX_BODY_BYTES: () => DEFAULT_MAX_BODY_BYTES,
5805
5933
  DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
5934
+ EffectiveDateMismatchError: () => EffectiveDateMismatchError,
5806
5935
  LOA_MAX_TYPED_ALIASES: () => LOA_MAX_TYPED_ALIASES,
5807
5936
  LOA_MIN_SHORT_FORM_LETTERS: () => LOA_MIN_SHORT_FORM_LETTERS,
5808
5937
  LOA_PUBLIC_KEY_CACHE_MS: () => LOA_PUBLIC_KEY_CACHE_MS,
@@ -5811,18 +5940,25 @@ __export(index_exports, {
5811
5940
  LoaV2RefusedError: () => LoaV2RefusedError,
5812
5941
  MAX_ADDRESS_FIELD_CHARS: () => MAX_ADDRESS_FIELD_CHARS,
5813
5942
  OUTBOX_LEASE_COLUMNS: () => OUTBOX_LEASE_COLUMNS,
5943
+ PRODUCT_CODE_PATTERN: () => PRODUCT_CODE_PATTERN,
5944
+ SDK_VERSION: () => SDK_VERSION,
5814
5945
  SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
5946
+ UPDATE_GUIDE_URL: () => UPDATE_GUIDE_URL,
5947
+ VERIFICATION_COMMITMENT_VERSION: () => VERIFICATION_COMMITMENT_VERSION,
5815
5948
  _resetLoaKeyCacheForTests: () => _resetLoaKeyCacheForTests,
5816
5949
  _resetOnceWarningsForTests: () => _resetOnceWarningsForTests,
5817
5950
  acceptTypedAliases: () => acceptTypedAliases,
5951
+ assertEffectiveDateBound: () => assertEffectiveDateBound,
5818
5952
  buildSignedTestWebhook: () => buildSignedTestWebhook,
5819
5953
  cachedLoaPublicKey: () => cachedLoaPublicKey,
5820
5954
  canonicalD5LoaForm: () => canonicalD5LoaForm,
5821
5955
  canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
5956
+ checkForUpdate: () => checkForUpdate,
5822
5957
  checkLoaV2: () => checkLoaV2,
5823
5958
  checkRegistryHead: () => checkRegistryHead,
5824
5959
  compareAddresses: () => compareAddresses,
5825
5960
  computeBlindIndex: () => computeBlindIndex,
5961
+ computeVerificationCommitment: () => computeVerificationCommitment,
5826
5962
  confirmUpdate: () => confirmUpdate,
5827
5963
  createOneAddressHandler: () => createOneAddressHandler,
5828
5964
  createOutboxConsumer: () => createOutboxConsumer,
@@ -5840,24 +5976,33 @@ __export(index_exports, {
5840
5976
  isAcceptableAlias: () => isAcceptableAlias,
5841
5977
  isEmailLike: () => isEmailLike2,
5842
5978
  isFreshTimestamp: () => isFreshTimestamp,
5979
+ isNewerVersion: () => isNewerVersion,
5843
5980
  loaEnvelopeSha256: () => loaEnvelopeSha256,
5844
5981
  loaFirstName: () => loaFirstName,
5845
5982
  loaNamesMatch: () => loaNamesMatch,
5846
5983
  loaSurname: () => loaSurname,
5984
+ matchingWebhookSecret: () => matchingWebhookSecret,
5847
5985
  namePoolMatches: () => namePoolMatches,
5986
+ normaliseCommitmentField: () => normaliseCommitmentField,
5848
5987
  normaliseLoaName: () => normaliseLoaName,
5849
5988
  normalizeForBlindIndex: () => normalizeForBlindIndex,
5850
5989
  parsePinnedRegistryRoots: () => parsePinnedRegistryRoots,
5851
5990
  readAddressParts: () => readAddressParts,
5991
+ readSessionProduct: () => readSessionProduct,
5852
5992
  sendVerifyResult: () => sendVerifyResult,
5853
5993
  signPullRequest: () => signPullRequest,
5994
+ startUpdateCheck: () => startUpdateCheck,
5854
5995
  toExpressHandler: () => toExpressHandler,
5855
5996
  toOutboxTimestamp: () => toOutboxTimestamp,
5856
5997
  transform: () => transformAddress,
5857
5998
  transformAddress: () => transformAddress,
5858
5999
  transformSession: () => transformSession,
5859
6000
  typedAliasesOf: () => typedAliasesOf,
6001
+ updateAvailableLine: () => updateAvailableLine,
6002
+ updateCheckEnabled: () => updateCheckEnabled,
6003
+ updateCheckMetric: () => updateCheckMetric,
5860
6004
  validateAddress: () => validateAddress,
6005
+ verificationCommitmentString: () => verificationCommitmentString,
5861
6006
  verify: () => verifySignature,
5862
6007
  verifyD5LOA: () => verifyD5LOA,
5863
6008
  verifyD5LOAv2: () => verifyD5LOAv2,
@@ -5874,6 +6019,19 @@ init_src();
5874
6019
  var CURRENT_VERSION = "2026.1";
5875
6020
  var SUPPORTED_VERSIONS = ["2026.1"];
5876
6021
 
6022
+ // ../protocol/src/notice-period.ts
6023
+ var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
6024
+ function isIsoDate(value) {
6025
+ if (typeof value !== "string") return false;
6026
+ const m = ISO_DATE.exec(value);
6027
+ if (!m) return false;
6028
+ const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
6029
+ return toIso(d) === value;
6030
+ }
6031
+ function toIso(d) {
6032
+ return d.toISOString().slice(0, 10);
6033
+ }
6034
+
5877
6035
  // ../protocol/src/d5-body.ts
5878
6036
  var D5_BODY_ALWAYS = [
5879
6037
  "event",
@@ -5903,7 +6061,18 @@ var D5_BODY_CONDITIONAL = {
5903
6061
  */
5904
6062
  id: "key-crossover copy only",
5905
6063
  /** The sibling marker naming the other key_ids this update was sealed to. */
5906
- crossover_key_ids: "key-crossover copy only"
6064
+ crossover_key_ids: "key-crossover copy only",
6065
+ /**
6066
+ * The day the change takes effect, `YYYY-MM-DD` (31 Oct 2026). Set on every
6067
+ * dispatch made for a SCHEDULED MOVE, which is its move date. A scheduled
6068
+ * move sends each recipient early enough for its own notice period
6069
+ * (`resolveRecipientSendPlan` in `notice-period.ts`), so the update can
6070
+ * arrive days before the customer moves; a recipient that treated it as
6071
+ * immediate could start charging at the new address from the day it arrived.
6072
+ * Absent on an immediate update, which takes effect on receipt. Optional for
6073
+ * receivers: an SDK that does not know the field ignores it.
6074
+ */
6075
+ effective_date: "scheduled move only"
5907
6076
  };
5908
6077
  var D5_BODY_DRILL_ONLY = ["conformance"];
5909
6078
  var D5_BODY_ADDED_AT_SEND = ["dispatch_id"];
@@ -6042,6 +6211,33 @@ var LOA_V2_REFUSALS = [
6042
6211
  "loa_v2_name_mismatch"
6043
6212
  ];
6044
6213
 
6214
+ // ../protocol/src/verification-commitment.ts
6215
+ var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
6216
+ var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
6217
+ function normaliseCommitmentField(value) {
6218
+ if (typeof value !== "string") return "";
6219
+ const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
6220
+ const start = collapsed.startsWith(" ") ? 1 : 0;
6221
+ const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
6222
+ return collapsed.slice(start, end);
6223
+ }
6224
+ function verificationCommitmentString(verificationId, index, record) {
6225
+ if (!Number.isInteger(index) || index <= 0) {
6226
+ throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
6227
+ }
6228
+ return [
6229
+ VERIFICATION_COMMITMENT_VERSION,
6230
+ normaliseCommitmentField(verificationId),
6231
+ String(index),
6232
+ normaliseCommitmentField(record.name),
6233
+ normaliseCommitmentField(record.street),
6234
+ normaliseCommitmentField(record.suburb),
6235
+ normaliseCommitmentField(record.state),
6236
+ normaliseCommitmentField(record.postcode),
6237
+ normaliseCommitmentField(record.country)
6238
+ ].join("\n");
6239
+ }
6240
+
6045
6241
  // src/app-hosts.ts
6046
6242
  function allowedAppHosts() {
6047
6243
  const hosts = ["oneaddress.io", "app.oneaddress.io"];
@@ -6075,6 +6271,96 @@ function resolveAppOrigin(baseUrl, label, extraHosts) {
6075
6271
  return parsed.origin;
6076
6272
  }
6077
6273
 
6274
+ // src/update-check.ts
6275
+ var SDK_VERSION = "2.10.0";
6276
+ var UPDATE_GUIDE_URL = "https://partners.oneaddress.io/#updating-safely";
6277
+ var REGISTRY_URL = "https://registry.npmjs.org/@oneaddress/partner-sdk/latest";
6278
+ var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
6279
+ var TIMEOUT_MS = 5e3;
6280
+ function updateCheckEnabled(setting) {
6281
+ const s = (setting ?? "").trim().toLowerCase();
6282
+ return !(s === "off" || s === "never" || s === "0" || s === "false");
6283
+ }
6284
+ function parseVersion(v) {
6285
+ if (typeof v !== "string") return null;
6286
+ const m = /^(\d{1,6})\.(\d{1,6})\.(\d{1,6})$/.exec(v.trim());
6287
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
6288
+ }
6289
+ function isNewerVersion(latest, running) {
6290
+ const a = parseVersion(latest);
6291
+ const b = parseVersion(running);
6292
+ if (!a || !b) return false;
6293
+ for (let i = 0; i < 3; i++) {
6294
+ if (a[i] !== b[i]) return a[i] > b[i];
6295
+ }
6296
+ return false;
6297
+ }
6298
+ function updateAvailableLine(running, latest) {
6299
+ return `update available: ${running} -> ${latest}, see ${UPDATE_GUIDE_URL}`;
6300
+ }
6301
+ function updateCheckMetric(result, product = "partner-sdk-ts") {
6302
+ const latest = result.latest ?? "unknown";
6303
+ const value = result.state === "available" ? 1 : 0;
6304
+ return `oneaddress_update_available{product="${product}",running="${result.running}",latest="${latest}"} ${value}`;
6305
+ }
6306
+ async function checkForUpdate(opts2 = {}) {
6307
+ const running = opts2.running ?? SDK_VERSION;
6308
+ const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
6309
+ if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) return { state: "disabled", running };
6310
+ const fetchImpl = opts2.fetchImpl ?? globalThis.fetch;
6311
+ const now = opts2.now ?? Date.now;
6312
+ if (typeof fetchImpl !== "function") return { state: "unknown", running };
6313
+ const abort = new AbortController();
6314
+ const timer = setTimeout(() => abort.abort(), opts2.timeoutMs ?? TIMEOUT_MS);
6315
+ try {
6316
+ const res = await fetchImpl(opts2.registryUrl ?? REGISTRY_URL, { signal: abort.signal });
6317
+ const checkedAt = now();
6318
+ if (!res.ok) return { state: "unknown", running, checkedAt };
6319
+ const body = await res.json();
6320
+ if (!parseVersion(body?.version)) return { state: "unknown", running, checkedAt };
6321
+ const latest = body.version.trim();
6322
+ return {
6323
+ state: isNewerVersion(latest, running) ? "available" : "current",
6324
+ running,
6325
+ latest,
6326
+ checkedAt
6327
+ };
6328
+ } catch {
6329
+ return { state: "unknown", running };
6330
+ } finally {
6331
+ clearTimeout(timer);
6332
+ }
6333
+ }
6334
+ function startUpdateCheck(opts2 = {}) {
6335
+ const running = opts2.running ?? SDK_VERSION;
6336
+ let last = { state: "unknown", running };
6337
+ let announced = null;
6338
+ const log = opts2.log ?? ((line) => console.warn(line));
6339
+ const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
6340
+ if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) {
6341
+ last = { state: "disabled", running };
6342
+ opts2.onResult?.(last);
6343
+ return { current: () => last, stop: () => {
6344
+ } };
6345
+ }
6346
+ const run = async () => {
6347
+ const result = await checkForUpdate({ ...opts2, running, env });
6348
+ if (result.state !== "unknown" || last.state === "unknown") last = result;
6349
+ if (last.state === "available" && last.latest && last.latest !== announced) {
6350
+ announced = last.latest;
6351
+ log(updateAvailableLine(running, last.latest));
6352
+ }
6353
+ opts2.onResult?.(last);
6354
+ };
6355
+ void run();
6356
+ const every = Math.max(opts2.intervalMs ?? ONE_DAY_MS, 60 * 60 * 1e3);
6357
+ const timer = setInterval(() => {
6358
+ void run();
6359
+ }, every);
6360
+ timer.unref?.();
6361
+ return { current: () => last, stop: () => clearInterval(timer) };
6362
+ }
6363
+
6078
6364
  // src/index.ts
6079
6365
  init_src();
6080
6366
  init_src();
@@ -6559,6 +6845,18 @@ async function checkRegistryHead(opts2) {
6559
6845
  headExpiresAt: expires
6560
6846
  };
6561
6847
  }
6848
+ if (expectedKeyId) {
6849
+ return {
6850
+ verdict: "names-key-we-lack",
6851
+ checked: true,
6852
+ alarm: true,
6853
+ detail: `the head names ${named} as the current key for this partner id, not ${expectedKeyId}, the key this recipient is configured with. If you did not rotate to ${named}, address envelopes are being sealed to a key you cannot read: contact OneAddress through a channel that is not oneaddress.io. If you did rotate, update keyId, or pass holdsKey so a key you hold is recognised.`,
6854
+ namedKeyId: named,
6855
+ expectedKeyId,
6856
+ headIssuedAt: issued,
6857
+ headExpiresAt: expires
6858
+ };
6859
+ }
6562
6860
  return {
6563
6861
  verdict: "key-identity-unknown",
6564
6862
  checked: false,
@@ -6718,14 +7016,21 @@ function signPullRequest(opts2) {
6718
7016
  };
6719
7017
  }
6720
7018
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6721
- if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
7019
+ return matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) !== null;
7020
+ }
7021
+ function matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
7022
+ if (verifySignature(rawBody, signature, timestamp, currentSecret)) return currentSecret;
6722
7023
  if (previousSecret && previousSecret !== currentSecret && graceUntil) {
6723
7024
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
6724
- if (!Number.isNaN(until) && Date.now() < until) {
6725
- return verifySignature(rawBody, signature, timestamp, previousSecret);
7025
+ if (!Number.isNaN(until) && Date.now() < until && verifySignature(rawBody, signature, timestamp, previousSecret)) {
7026
+ return previousSecret;
6726
7027
  }
6727
7028
  }
6728
- return false;
7029
+ return null;
7030
+ }
7031
+ function computeVerificationCommitment(secret, verificationId, index, record) {
7032
+ if (!secret) throw new Error("[OneAddress SDK] a verification commitment needs the webhook secret");
7033
+ return import_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, record), "utf8").digest("hex");
6729
7034
  }
6730
7035
  function base64urlToBuffer(b64) {
6731
7036
  return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
@@ -6791,15 +7096,34 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
6791
7096
  );
6792
7097
  return JSON.parse(new TextDecoder().decode(plaintext));
6793
7098
  }
7099
+ var PRODUCT_CODE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
7100
+ function readSessionProduct(raw) {
7101
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
7102
+ const { id, code, name } = raw;
7103
+ if (typeof id !== "string" || typeof code !== "string" || !PRODUCT_CODE_PATTERN.test(code)) return null;
7104
+ return { id, code, name: typeof name === "string" && name !== "" ? name : code };
7105
+ }
7106
+ function normaliseSessionProduct(data) {
7107
+ if (!data || typeof data !== "object" || !("product" in data)) return data;
7108
+ const product = readSessionProduct(data.product);
7109
+ if (product === null && data.product != null) {
7110
+ console.warn(
7111
+ // NOSONAR - intentional SDK diagnostic, not user-controlled data
7112
+ "[OneAddress SDK] the session envelope carried a malformed product, so it is treated as absent and the update is handled as a plain account."
7113
+ );
7114
+ }
7115
+ return { ...data, product };
7116
+ }
6794
7117
  async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
6795
7118
  const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
6796
- return decryptSessionCrypto(
7119
+ const data = await decryptSessionCrypto(
6797
7120
  share,
6798
7121
  envelopeB64,
6799
7122
  typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
6800
7123
  partnerId,
6801
7124
  expectedAlg
6802
7125
  );
7126
+ return normaliseSessionProduct(data);
6803
7127
  }
6804
7128
  async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
6805
7129
  const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
@@ -6875,6 +7199,13 @@ async function confirmUpdate(opts2) {
6875
7199
  } = opts2;
6876
7200
  if (!partnerId) return { ok: false, status: 0, error: "partnerId is required" };
6877
7201
  if (!secret) return { ok: false, status: 0, error: "secret is required" };
7202
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(partnerId)) {
7203
+ return {
7204
+ ok: false,
7205
+ status: 0,
7206
+ error: `partnerId must be your partner UUID from the portal, received ${JSON.stringify(partnerId)}`
7207
+ };
7208
+ }
6878
7209
  const id = typeof dispatchId === "string" ? Number(dispatchId) : dispatchId;
6879
7210
  if (!Number.isInteger(id) || id <= 0) {
6880
7211
  return {
@@ -6907,7 +7238,11 @@ async function confirmUpdate(opts2) {
6907
7238
  "Content-Type": "application/json",
6908
7239
  "X-OneAddress-Timestamp": timestamp,
6909
7240
  "X-OneAddress-Signature": signature,
6910
- [PULL_SIGNATURE_VERSION_HEADER]: "2"
7241
+ [PULL_SIGNATURE_VERSION_HEADER]: "2",
7242
+ // Which SDK sent this, so the partner portal can say when an update
7243
+ // exists. Software name and version only; outside the signature, and
7244
+ // recorded by OneAddress only after the signature verifies.
7245
+ "X-OneAddress-Client": `partner-sdk-ts/${SDK_VERSION}`
6911
7246
  },
6912
7247
  // The SAME string that was signed. Not an object, and not re-stringified.
6913
7248
  body
@@ -7447,6 +7782,21 @@ function requirePemFor(purpose, key) {
7447
7782
  `[OneAddress SDK] ${purpose} needs the raw private key; a PrivateKeyOperations delegate ("${key.name}") covers session envelopes only`
7448
7783
  );
7449
7784
  }
7785
+ var EffectiveDateMismatchError = class extends Error {
7786
+ constructor(sealed, body) {
7787
+ super(
7788
+ `[OneAddress SDK] effective_date in the body (${JSON.stringify(body ?? null)}) does not match the one sealed in the envelope (${JSON.stringify(sealed ?? null)}); refusing rather than applying a date the consumer did not seal`
7789
+ );
7790
+ this.sealed = sealed;
7791
+ this.body = body;
7792
+ this.name = "EffectiveDateMismatchError";
7793
+ }
7794
+ };
7795
+ function assertEffectiveDateBound(sealed, body) {
7796
+ if (sealed === void 0 && body === void 0) return;
7797
+ if (sealed !== void 0 && body !== void 0 && sealed === body) return;
7798
+ throw new EffectiveDateMismatchError(sealed, body);
7799
+ }
7450
7800
  function assertLoaBoundToEnvelope(loa, envelopeUpdateUid) {
7451
7801
  if (typeof loa.update_uid !== "string" || typeof envelopeUpdateUid !== "string") return;
7452
7802
  if (loa.update_uid !== envelopeUpdateUid) {
@@ -7587,7 +7937,9 @@ function createOneAddressHandler(options) {
7587
7937
  customer.known_names = typedAliasesOf(loa);
7588
7938
  }
7589
7939
  }
7590
- return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
7940
+ assertEffectiveDateBound(data.effective_date, body.effective_date);
7941
+ const product = data.product ?? null;
7942
+ return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, product, raw: data };
7591
7943
  }
7592
7944
  function isD5Body(body) {
7593
7945
  return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
@@ -7616,7 +7968,8 @@ function createOneAddressHandler(options) {
7616
7968
  headers: { "Content-Type": "application/json" }
7617
7969
  });
7618
7970
  }
7619
- if (!verifyWithGrace(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil)) {
7971
+ const signingSecret = matchingWebhookSecret(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil);
7972
+ if (signingSecret === null) {
7620
7973
  return new Response(JSON.stringify({ error: "Invalid signature" }), {
7621
7974
  status: 401,
7622
7975
  headers: { "Content-Type": "application/json" }
@@ -7702,6 +8055,12 @@ function createOneAddressHandler(options) {
7702
8055
  let event;
7703
8056
  enforceLoaPresence(body);
7704
8057
  if (isD5Body(body)) {
8058
+ if (body.effective_date !== void 0 && !isIsoDate(body.effective_date)) {
8059
+ return declared(400, {
8060
+ error: "invalid_effective_date",
8061
+ detail: "effective_date must be a YYYY-MM-DD calendar date. Nothing was processed."
8062
+ });
8063
+ }
7705
8064
  let d5;
7706
8065
  try {
7707
8066
  d5 = await buildD5Pieces(body, partnerId);
@@ -7753,6 +8112,8 @@ function createOneAddressHandler(options) {
7753
8112
  loa: d5.loa,
7754
8113
  loa_ref: d5.loa_ref,
7755
8114
  id_verification: body.id_verification,
8115
+ ...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
8116
+ product: d5.product,
7756
8117
  raw: d5.raw
7757
8118
  };
7758
8119
  } else {
@@ -7821,6 +8182,8 @@ function createOneAddressHandler(options) {
7821
8182
  loa,
7822
8183
  loa_ref,
7823
8184
  id_verification: body.id_verification,
8185
+ // The legacy blob predates product lines.
8186
+ product: null,
7824
8187
  raw: rawAddress
7825
8188
  };
7826
8189
  }
@@ -7835,11 +8198,13 @@ function createOneAddressHandler(options) {
7835
8198
  }
7836
8199
  if (confirm && dispatchId) {
7837
8200
  const status = result && typeof result === "object" && result.status ? result.status : "confirmed";
8201
+ const note = result && typeof result === "object" && typeof result.note === "string" ? result.note : void 0;
7838
8202
  void confirmUpdate({
7839
8203
  partnerId: confirm.partnerId,
7840
8204
  secret: confirm.confirmSecret,
7841
8205
  dispatchId,
7842
8206
  status,
8207
+ ...note !== void 0 ? { note } : {},
7843
8208
  loaRef: event.loa_ref,
7844
8209
  ...confirm.oneAddressApi ? { appBaseUrl: confirm.oneAddressApi } : {},
7845
8210
  ...confirm.allowedHosts ? { allowedHosts: confirm.allowedHosts } : {},
@@ -7960,11 +8325,26 @@ function createOneAddressHandler(options) {
7960
8325
  address: d5.address,
7961
8326
  raw: d5.raw
7962
8327
  });
8328
+ const index = typeof body.index === "number" ? body.index : void 0;
8329
+ const verificationId = typeof body.verification_id === "string" ? body.verification_id : "";
8330
+ let commitment;
8331
+ if (index !== void 0 && Number.isInteger(index) && index > 0 && verificationId) {
8332
+ const newAddress = d5.raw.new_address ?? {};
8333
+ commitment = computeVerificationCommitment(signingSecret, verificationId, index, {
8334
+ name: d5.raw.verified_name,
8335
+ street: newAddress.street,
8336
+ suburb: newAddress.suburb,
8337
+ state: newAddress.state,
8338
+ postcode: newAddress.postcode,
8339
+ country: newAddress.country
8340
+ });
8341
+ }
7963
8342
  return declared(200, {
7964
8343
  ok: true,
7965
8344
  test: true,
7966
8345
  verification: true,
7967
- index: typeof body.index === "number" ? body.index : void 0
8346
+ index,
8347
+ ...commitment ? { commitment } : {}
7968
8348
  });
7969
8349
  }
7970
8350
  const evt = typeof body.event === "string" ? body.event : "(none)";
@@ -8074,6 +8454,9 @@ async function buildSignedTestWebhook(opts2) {
8074
8454
  account_number: "TEST-0001",
8075
8455
  id_verification_ref: import_crypto2.default.randomUUID(),
8076
8456
  known_names: [],
8457
+ // Sealed beside the body copy, as the relay's pay step does, so a
8458
+ // rehearsed scheduled move passes the handler's binding check.
8459
+ ...opts2.effectiveDate !== void 0 ? { effective_date: opts2.effectiveDate } : {},
8077
8460
  ...opts2.session ?? {}
8078
8461
  };
8079
8462
  const envelope = await encryptSessionForPartner(sessionData, partnerKey);
@@ -8136,6 +8519,7 @@ async function buildSignedTestWebhook(opts2) {
8136
8519
  key_share_expiry: keyShareExpiryIso(new Date(nowSecs * 1e3), opts2.retentionPeriodDays),
8137
8520
  id_verification: { method: "identity_document", verified_at: nowIso, verified: true, platform: "oneaddress/v1" },
8138
8521
  ...loa_encrypted ? { loa_encrypted } : {},
8522
+ ...opts2.effectiveDate !== void 0 ? { effective_date: opts2.effectiveDate } : {},
8139
8523
  // On the wire with a `null` value when no PaymentIntent backed the update,
8140
8524
  // so the KEY is present either way.
8141
8525
  // `id` and `crossover_key_ids` are crossover-only and therefore NOT emitted
@@ -8174,6 +8558,7 @@ async function buildSignedTestWebhook(opts2) {
8174
8558
  DEFAULT_IDEMPOTENCY_LEASE_SECS,
8175
8559
  DEFAULT_MAX_BODY_BYTES,
8176
8560
  DEFAULT_REPLAY_WINDOW_SECS,
8561
+ EffectiveDateMismatchError,
8177
8562
  LOA_MAX_TYPED_ALIASES,
8178
8563
  LOA_MIN_SHORT_FORM_LETTERS,
8179
8564
  LOA_PUBLIC_KEY_CACHE_MS,
@@ -8182,18 +8567,25 @@ async function buildSignedTestWebhook(opts2) {
8182
8567
  LoaV2RefusedError,
8183
8568
  MAX_ADDRESS_FIELD_CHARS,
8184
8569
  OUTBOX_LEASE_COLUMNS,
8570
+ PRODUCT_CODE_PATTERN,
8571
+ SDK_VERSION,
8185
8572
  SUPPORTED_VERSIONS,
8573
+ UPDATE_GUIDE_URL,
8574
+ VERIFICATION_COMMITMENT_VERSION,
8186
8575
  _resetLoaKeyCacheForTests,
8187
8576
  _resetOnceWarningsForTests,
8188
8577
  acceptTypedAliases,
8578
+ assertEffectiveDateBound,
8189
8579
  buildSignedTestWebhook,
8190
8580
  cachedLoaPublicKey,
8191
8581
  canonicalD5LoaForm,
8192
8582
  canonicalD5LoaFormV2,
8583
+ checkForUpdate,
8193
8584
  checkLoaV2,
8194
8585
  checkRegistryHead,
8195
8586
  compareAddresses,
8196
8587
  computeBlindIndex,
8588
+ computeVerificationCommitment,
8197
8589
  confirmUpdate,
8198
8590
  createOneAddressHandler,
8199
8591
  createOutboxConsumer,
@@ -8211,24 +8603,33 @@ async function buildSignedTestWebhook(opts2) {
8211
8603
  isAcceptableAlias,
8212
8604
  isEmailLike,
8213
8605
  isFreshTimestamp,
8606
+ isNewerVersion,
8214
8607
  loaEnvelopeSha256,
8215
8608
  loaFirstName,
8216
8609
  loaNamesMatch,
8217
8610
  loaSurname,
8611
+ matchingWebhookSecret,
8218
8612
  namePoolMatches,
8613
+ normaliseCommitmentField,
8219
8614
  normaliseLoaName,
8220
8615
  normalizeForBlindIndex,
8221
8616
  parsePinnedRegistryRoots,
8222
8617
  readAddressParts,
8618
+ readSessionProduct,
8223
8619
  sendVerifyResult,
8224
8620
  signPullRequest,
8621
+ startUpdateCheck,
8225
8622
  toExpressHandler,
8226
8623
  toOutboxTimestamp,
8227
8624
  transform,
8228
8625
  transformAddress,
8229
8626
  transformSession,
8230
8627
  typedAliasesOf,
8628
+ updateAvailableLine,
8629
+ updateCheckEnabled,
8630
+ updateCheckMetric,
8231
8631
  validateAddress,
8632
+ verificationCommitmentString,
8232
8633
  verify,
8233
8634
  verifyD5LOA,
8234
8635
  verifyD5LOAv2,