@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/edge.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,12 +5931,14 @@ __export(edge_exports, {
5803
5931
  DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
5804
5932
  LoaV2RefusedError: () => LoaV2RefusedError,
5805
5933
  SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
5934
+ VERIFICATION_COMMITMENT_VERSION: () => VERIFICATION_COMMITMENT_VERSION,
5806
5935
  acceptTypedAliases: () => acceptTypedAliases,
5807
5936
  canonicalD5LoaForm: () => canonicalD5LoaForm,
5808
5937
  canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
5809
5938
  checkLoaV2: () => checkLoaV2,
5810
5939
  compareAddresses: () => compareAddresses,
5811
5940
  computeBlindIndex: () => computeBlindIndex,
5941
+ computeVerificationCommitment: () => computeVerificationCommitment,
5812
5942
  createOneAddressHandler: () => createOneAddressHandler,
5813
5943
  d5LoaRef: () => d5LoaRef,
5814
5944
  decryptAddress: () => decryptAddress2,
@@ -5824,7 +5954,9 @@ __export(edge_exports, {
5824
5954
  loaFirstName: () => loaFirstName,
5825
5955
  loaNamesMatch: () => loaNamesMatch,
5826
5956
  loaSurname: () => loaSurname,
5957
+ matchingWebhookSecret: () => matchingWebhookSecret,
5827
5958
  namePoolMatches: () => namePoolMatches,
5959
+ normaliseCommitmentField: () => normaliseCommitmentField,
5828
5960
  normaliseLoaName: () => normaliseLoaName,
5829
5961
  normalizeForBlindIndex: () => normalizeForBlindIndex,
5830
5962
  sendVerifyResult: () => sendVerifyResult,
@@ -5832,6 +5964,7 @@ __export(edge_exports, {
5832
5964
  transformSession: () => transformSession,
5833
5965
  typedAliasesOf: () => typedAliasesOf,
5834
5966
  validateAddress: () => validateAddress,
5967
+ verificationCommitmentString: () => verificationCommitmentString,
5835
5968
  verifyD5LOA: () => verifyD5LOA,
5836
5969
  verifyD5LOAv2: () => verifyD5LOAv2,
5837
5970
  verifyLOA: () => verifyLOA,
@@ -5848,6 +5981,19 @@ init_src();
5848
5981
  var CURRENT_VERSION = "2026.1";
5849
5982
  var SUPPORTED_VERSIONS = ["2026.1"];
5850
5983
 
5984
+ // ../protocol/src/notice-period.ts
5985
+ var ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
5986
+ function isIsoDate(value) {
5987
+ if (typeof value !== "string") return false;
5988
+ const m = ISO_DATE.exec(value);
5989
+ if (!m) return false;
5990
+ const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
5991
+ return toIso(d) === value;
5992
+ }
5993
+ function toIso(d) {
5994
+ return d.toISOString().slice(0, 10);
5995
+ }
5996
+
5851
5997
  // ../protocol/src/d5-body.ts
5852
5998
  var D5_BODY_ALWAYS = [
5853
5999
  "event",
@@ -5877,7 +6023,18 @@ var D5_BODY_CONDITIONAL = {
5877
6023
  */
5878
6024
  id: "key-crossover copy only",
5879
6025
  /** The sibling marker naming the other key_ids this update was sealed to. */
5880
- crossover_key_ids: "key-crossover copy only"
6026
+ crossover_key_ids: "key-crossover copy only",
6027
+ /**
6028
+ * The day the change takes effect, `YYYY-MM-DD` (31 Oct 2026). Set on every
6029
+ * dispatch made for a SCHEDULED MOVE, which is its move date. A scheduled
6030
+ * move sends each recipient early enough for its own notice period
6031
+ * (`resolveRecipientSendPlan` in `notice-period.ts`), so the update can
6032
+ * arrive days before the customer moves; a recipient that treated it as
6033
+ * immediate could start charging at the new address from the day it arrived.
6034
+ * Absent on an immediate update, which takes effect on receipt. Optional for
6035
+ * receivers: an SDK that does not know the field ignores it.
6036
+ */
6037
+ effective_date: "scheduled move only"
5881
6038
  };
5882
6039
  var D5_BODY_DRILL_ONLY = ["conformance"];
5883
6040
  var D5_BODY_ADDED_AT_SEND = ["dispatch_id"];
@@ -5993,6 +6150,33 @@ function acceptTypedAliases(verifiedName, aliases) {
5993
6150
  return out;
5994
6151
  }
5995
6152
 
6153
+ // ../protocol/src/verification-commitment.ts
6154
+ var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
6155
+ var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
6156
+ function normaliseCommitmentField(value) {
6157
+ if (typeof value !== "string") return "";
6158
+ const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
6159
+ const start = collapsed.startsWith(" ") ? 1 : 0;
6160
+ const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
6161
+ return collapsed.slice(start, end);
6162
+ }
6163
+ function verificationCommitmentString(verificationId, index, record) {
6164
+ if (!Number.isInteger(index) || index <= 0) {
6165
+ throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
6166
+ }
6167
+ return [
6168
+ VERIFICATION_COMMITMENT_VERSION,
6169
+ normaliseCommitmentField(verificationId),
6170
+ String(index),
6171
+ normaliseCommitmentField(record.name),
6172
+ normaliseCommitmentField(record.street),
6173
+ normaliseCommitmentField(record.suburb),
6174
+ normaliseCommitmentField(record.state),
6175
+ normaliseCommitmentField(record.postcode),
6176
+ normaliseCommitmentField(record.country)
6177
+ ].join("\n");
6178
+ }
6179
+
5996
6180
  // src/app-hosts.ts
5997
6181
  function allowedAppHosts() {
5998
6182
  const hosts = ["oneaddress.io", "app.oneaddress.io"];
@@ -6026,6 +6210,10 @@ function resolveAppOrigin(baseUrl, label, extraHosts) {
6026
6210
  return parsed.origin;
6027
6211
  }
6028
6212
 
6213
+ // src/update-check.ts
6214
+ var SDK_VERSION = "2.10.0";
6215
+ var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
6216
+
6029
6217
  // src/index.ts
6030
6218
  init_src();
6031
6219
  init_src();
@@ -6102,14 +6290,21 @@ function verifySignature(rawBody, signature, timestamp, secret) {
6102
6290
  return import_crypto2.default.timingSafeEqual(sigBuffer, expBuffer);
6103
6291
  }
6104
6292
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6105
- if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
6293
+ return matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) !== null;
6294
+ }
6295
+ function matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6296
+ if (verifySignature(rawBody, signature, timestamp, currentSecret)) return currentSecret;
6106
6297
  if (previousSecret && previousSecret !== currentSecret && graceUntil) {
6107
6298
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
6108
- if (!Number.isNaN(until) && Date.now() < until) {
6109
- return verifySignature(rawBody, signature, timestamp, previousSecret);
6299
+ if (!Number.isNaN(until) && Date.now() < until && verifySignature(rawBody, signature, timestamp, previousSecret)) {
6300
+ return previousSecret;
6110
6301
  }
6111
6302
  }
6112
- return false;
6303
+ return null;
6304
+ }
6305
+ function computeVerificationCommitment(secret, verificationId, index, record) {
6306
+ if (!secret) throw new Error("[OneAddress SDK] a verification commitment needs the webhook secret");
6307
+ return import_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, record), "utf8").digest("hex");
6113
6308
  }
6114
6309
  function base64urlToBuffer(b64) {
6115
6310
  return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
@@ -6175,15 +6370,34 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
6175
6370
  );
6176
6371
  return JSON.parse(new TextDecoder().decode(plaintext));
6177
6372
  }
6373
+ var PRODUCT_CODE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
6374
+ function readSessionProduct(raw) {
6375
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
6376
+ const { id, code, name } = raw;
6377
+ if (typeof id !== "string" || typeof code !== "string" || !PRODUCT_CODE_PATTERN.test(code)) return null;
6378
+ return { id, code, name: typeof name === "string" && name !== "" ? name : code };
6379
+ }
6380
+ function normaliseSessionProduct(data) {
6381
+ if (!data || typeof data !== "object" || !("product" in data)) return data;
6382
+ const product = readSessionProduct(data.product);
6383
+ if (product === null && data.product != null) {
6384
+ console.warn(
6385
+ // NOSONAR - intentional SDK diagnostic, not user-controlled data
6386
+ "[OneAddress SDK] the session envelope carried a malformed product, so it is treated as absent and the update is handled as a plain account."
6387
+ );
6388
+ }
6389
+ return { ...data, product };
6390
+ }
6178
6391
  async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
6179
6392
  const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
6180
- return decryptSessionCrypto(
6393
+ const data = await decryptSessionCrypto(
6181
6394
  share,
6182
6395
  envelopeB64,
6183
6396
  typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
6184
6397
  partnerId,
6185
6398
  expectedAlg
6186
6399
  );
6400
+ return normaliseSessionProduct(data);
6187
6401
  }
6188
6402
  async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
6189
6403
  const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
@@ -6259,6 +6473,13 @@ async function confirmUpdate(opts2) {
6259
6473
  } = opts2;
6260
6474
  if (!partnerId) return { ok: false, status: 0, error: "partnerId is required" };
6261
6475
  if (!secret) return { ok: false, status: 0, error: "secret is required" };
6476
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(partnerId)) {
6477
+ return {
6478
+ ok: false,
6479
+ status: 0,
6480
+ error: `partnerId must be your partner UUID from the portal, received ${JSON.stringify(partnerId)}`
6481
+ };
6482
+ }
6262
6483
  const id = typeof dispatchId === "string" ? Number(dispatchId) : dispatchId;
6263
6484
  if (!Number.isInteger(id) || id <= 0) {
6264
6485
  return {
@@ -6291,7 +6512,11 @@ async function confirmUpdate(opts2) {
6291
6512
  "Content-Type": "application/json",
6292
6513
  "X-OneAddress-Timestamp": timestamp,
6293
6514
  "X-OneAddress-Signature": signature,
6294
- [PULL_SIGNATURE_VERSION_HEADER]: "2"
6515
+ [PULL_SIGNATURE_VERSION_HEADER]: "2",
6516
+ // Which SDK sent this, so the partner portal can say when an update
6517
+ // exists. Software name and version only; outside the signature, and
6518
+ // recorded by OneAddress only after the signature verifies.
6519
+ "X-OneAddress-Client": `partner-sdk-ts/${SDK_VERSION}`
6295
6520
  },
6296
6521
  // The SAME string that was signed. Not an object, and not re-stringified.
6297
6522
  body
@@ -6795,6 +7020,21 @@ function requirePemFor(purpose, key) {
6795
7020
  `[OneAddress SDK] ${purpose} needs the raw private key; a PrivateKeyOperations delegate ("${key.name}") covers session envelopes only`
6796
7021
  );
6797
7022
  }
7023
+ var EffectiveDateMismatchError = class extends Error {
7024
+ constructor(sealed, body) {
7025
+ super(
7026
+ `[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`
7027
+ );
7028
+ this.sealed = sealed;
7029
+ this.body = body;
7030
+ this.name = "EffectiveDateMismatchError";
7031
+ }
7032
+ };
7033
+ function assertEffectiveDateBound(sealed, body) {
7034
+ if (sealed === void 0 && body === void 0) return;
7035
+ if (sealed !== void 0 && body !== void 0 && sealed === body) return;
7036
+ throw new EffectiveDateMismatchError(sealed, body);
7037
+ }
6798
7038
  function assertLoaBoundToEnvelope(loa, envelopeUpdateUid) {
6799
7039
  if (typeof loa.update_uid !== "string" || typeof envelopeUpdateUid !== "string") return;
6800
7040
  if (loa.update_uid !== envelopeUpdateUid) {
@@ -6935,7 +7175,9 @@ function createOneAddressHandler(options) {
6935
7175
  customer.known_names = typedAliasesOf(loa);
6936
7176
  }
6937
7177
  }
6938
- return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
7178
+ assertEffectiveDateBound(data.effective_date, body.effective_date);
7179
+ const product = data.product ?? null;
7180
+ return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, product, raw: data };
6939
7181
  }
6940
7182
  function isD5Body(body) {
6941
7183
  return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
@@ -6964,7 +7206,8 @@ function createOneAddressHandler(options) {
6964
7206
  headers: { "Content-Type": "application/json" }
6965
7207
  });
6966
7208
  }
6967
- if (!verifyWithGrace(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil)) {
7209
+ const signingSecret = matchingWebhookSecret(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil);
7210
+ if (signingSecret === null) {
6968
7211
  return new Response(JSON.stringify({ error: "Invalid signature" }), {
6969
7212
  status: 401,
6970
7213
  headers: { "Content-Type": "application/json" }
@@ -7050,6 +7293,12 @@ function createOneAddressHandler(options) {
7050
7293
  let event;
7051
7294
  enforceLoaPresence(body);
7052
7295
  if (isD5Body(body)) {
7296
+ if (body.effective_date !== void 0 && !isIsoDate(body.effective_date)) {
7297
+ return declared(400, {
7298
+ error: "invalid_effective_date",
7299
+ detail: "effective_date must be a YYYY-MM-DD calendar date. Nothing was processed."
7300
+ });
7301
+ }
7053
7302
  let d5;
7054
7303
  try {
7055
7304
  d5 = await buildD5Pieces(body, partnerId);
@@ -7101,6 +7350,8 @@ function createOneAddressHandler(options) {
7101
7350
  loa: d5.loa,
7102
7351
  loa_ref: d5.loa_ref,
7103
7352
  id_verification: body.id_verification,
7353
+ ...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
7354
+ product: d5.product,
7104
7355
  raw: d5.raw
7105
7356
  };
7106
7357
  } else {
@@ -7169,6 +7420,8 @@ function createOneAddressHandler(options) {
7169
7420
  loa,
7170
7421
  loa_ref,
7171
7422
  id_verification: body.id_verification,
7423
+ // The legacy blob predates product lines.
7424
+ product: null,
7172
7425
  raw: rawAddress
7173
7426
  };
7174
7427
  }
@@ -7183,11 +7436,13 @@ function createOneAddressHandler(options) {
7183
7436
  }
7184
7437
  if (confirm && dispatchId) {
7185
7438
  const status = result && typeof result === "object" && result.status ? result.status : "confirmed";
7439
+ const note = result && typeof result === "object" && typeof result.note === "string" ? result.note : void 0;
7186
7440
  void confirmUpdate({
7187
7441
  partnerId: confirm.partnerId,
7188
7442
  secret: confirm.confirmSecret,
7189
7443
  dispatchId,
7190
7444
  status,
7445
+ ...note !== void 0 ? { note } : {},
7191
7446
  loaRef: event.loa_ref,
7192
7447
  ...confirm.oneAddressApi ? { appBaseUrl: confirm.oneAddressApi } : {},
7193
7448
  ...confirm.allowedHosts ? { allowedHosts: confirm.allowedHosts } : {},
@@ -7308,11 +7563,26 @@ function createOneAddressHandler(options) {
7308
7563
  address: d5.address,
7309
7564
  raw: d5.raw
7310
7565
  });
7566
+ const index = typeof body.index === "number" ? body.index : void 0;
7567
+ const verificationId = typeof body.verification_id === "string" ? body.verification_id : "";
7568
+ let commitment;
7569
+ if (index !== void 0 && Number.isInteger(index) && index > 0 && verificationId) {
7570
+ const newAddress = d5.raw.new_address ?? {};
7571
+ commitment = computeVerificationCommitment(signingSecret, verificationId, index, {
7572
+ name: d5.raw.verified_name,
7573
+ street: newAddress.street,
7574
+ suburb: newAddress.suburb,
7575
+ state: newAddress.state,
7576
+ postcode: newAddress.postcode,
7577
+ country: newAddress.country
7578
+ });
7579
+ }
7311
7580
  return declared(200, {
7312
7581
  ok: true,
7313
7582
  test: true,
7314
7583
  verification: true,
7315
- index: typeof body.index === "number" ? body.index : void 0
7584
+ index,
7585
+ ...commitment ? { commitment } : {}
7316
7586
  });
7317
7587
  }
7318
7588
  const evt = typeof body.event === "string" ? body.event : "(none)";
@@ -7372,12 +7642,14 @@ function createOneAddressHandler(options) {
7372
7642
  DEFAULT_REPLAY_WINDOW_SECS,
7373
7643
  LoaV2RefusedError,
7374
7644
  SUPPORTED_VERSIONS,
7645
+ VERIFICATION_COMMITMENT_VERSION,
7375
7646
  acceptTypedAliases,
7376
7647
  canonicalD5LoaForm,
7377
7648
  canonicalD5LoaFormV2,
7378
7649
  checkLoaV2,
7379
7650
  compareAddresses,
7380
7651
  computeBlindIndex,
7652
+ computeVerificationCommitment,
7381
7653
  createOneAddressHandler,
7382
7654
  d5LoaRef,
7383
7655
  decryptAddress,
@@ -7393,7 +7665,9 @@ function createOneAddressHandler(options) {
7393
7665
  loaFirstName,
7394
7666
  loaNamesMatch,
7395
7667
  loaSurname,
7668
+ matchingWebhookSecret,
7396
7669
  namePoolMatches,
7670
+ normaliseCommitmentField,
7397
7671
  normaliseLoaName,
7398
7672
  normalizeForBlindIndex,
7399
7673
  sendVerifyResult,
@@ -7401,6 +7675,7 @@ function createOneAddressHandler(options) {
7401
7675
  transformSession,
7402
7676
  typedAliasesOf,
7403
7677
  validateAddress,
7678
+ verificationCommitmentString,
7404
7679
  verifyD5LOA,
7405
7680
  verifyD5LOAv2,
7406
7681
  verifyLOA,