@oneaddress/partner-sdk 2.9.0 → 2.11.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;
@@ -4341,11 +4351,18 @@ function classifyEndpointProbe(input) {
4341
4351
  summary: `Receiver accepted a signed test request (HTTP ${status}).`
4342
4352
  };
4343
4353
  }
4344
- if (status === 401 || status === 403) {
4354
+ if (status === 401) {
4345
4355
  return {
4346
4356
  health: "auth",
4347
4357
  dispatchable: false,
4348
- summary: `Receiver rejected our signature (HTTP ${status}). Check the signing secret matches on both sides.`
4358
+ summary: `Receiver rejected our signature (HTTP 401). Check the signing secret matches on both sides.`
4359
+ };
4360
+ }
4361
+ if (status === 403) {
4362
+ return {
4363
+ health: "rejected",
4364
+ dispatchable: false,
4365
+ summary: `Something in front of the receiver refused the request (HTTP 403), usually a firewall rule on rate, location or bots. Our signature is refused with a 401, not this.`
4349
4366
  };
4350
4367
  }
4351
4368
  if (MISSING_STATUSES.has(status)) {
@@ -4476,11 +4493,29 @@ var init_partner_key_attestation = __esm({
4476
4493
  });
4477
4494
 
4478
4495
  // ../crypto/src/registry-root-pin.ts
4496
+ function registryEnvironmentForOrigin(origin) {
4497
+ let o = origin ?? "";
4498
+ if (!o) {
4499
+ const loc = globalThis.location;
4500
+ o = loc?.origin ?? "";
4501
+ }
4502
+ if (!o) return "preview";
4503
+ try {
4504
+ const host = new URL(o).hostname.toLowerCase().replace(/\.$/, "");
4505
+ return PRODUCTION_REGISTRY_HOSTS.includes(host) ? "production" : "preview";
4506
+ } catch {
4507
+ return "preview";
4508
+ }
4509
+ }
4479
4510
  function __setPinnedRegistryRootsForTests(pins) {
4480
4511
  overrideForTests = pins;
4481
4512
  }
4482
- function pinnedRegistryRoots() {
4483
- return overrideForTests ?? PINNED_REGISTRY_ROOTS;
4513
+ function pinnedRegistryRoots(env = "production") {
4514
+ if (overrideForTests) {
4515
+ if (Array.isArray(overrideForTests)) return overrideForTests;
4516
+ return overrideForTests[env] ?? [];
4517
+ }
4518
+ return REGISTRY_ROOT_PINS[env];
4484
4519
  }
4485
4520
  function b64ToBytes2(b64) {
4486
4521
  const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
@@ -4493,34 +4528,47 @@ async function spkiSha256HexFromB64(spkiB64) {
4493
4528
  const digest = await crypto.subtle.digest("SHA-256", b64ToBytes2(spkiB64));
4494
4529
  return bytesToHex3(new Uint8Array(digest));
4495
4530
  }
4496
- async function rootIsPinned(root) {
4531
+ async function rootIsPinned(root, env = "production") {
4497
4532
  try {
4498
4533
  const digest = await spkiSha256HexFromB64(root.public_key_b64);
4499
- return pinnedRegistryRoots().some(
4534
+ return pinnedRegistryRoots(env).some(
4500
4535
  (p) => p.root_key_id === root.root_key_id && p.spki_sha256 === digest
4501
4536
  );
4502
4537
  } catch {
4503
4538
  return false;
4504
4539
  }
4505
4540
  }
4506
- async function unpinnedRootIds(roots) {
4541
+ async function unpinnedRootIds(roots, env = "production") {
4507
4542
  const out = [];
4508
4543
  for (const root of roots) {
4509
- if (!await rootIsPinned(root)) out.push(String(root?.root_key_id ?? "(no id)"));
4544
+ if (!await rootIsPinned(root, env)) out.push(String(root?.root_key_id ?? "(no id)"));
4510
4545
  }
4511
4546
  return out;
4512
4547
  }
4513
- var PINNED_REGISTRY_ROOTS, overrideForTests;
4548
+ var PRODUCTION_REGISTRY_HOSTS, PRODUCTION_ROOT, REGISTRY_ROOT_PINS, PINNED_REGISTRY_ROOTS, overrideForTests;
4514
4549
  var init_registry_root_pin = __esm({
4515
4550
  "../crypto/src/registry-root-pin.ts"() {
4516
4551
  "use strict";
4517
4552
  init_partner_key_attestation();
4518
- PINNED_REGISTRY_ROOTS = Object.freeze([
4519
- Object.freeze({
4520
- root_key_id: "rk1_251368ec9b0a84ae",
4521
- spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4522
- })
4553
+ PRODUCTION_REGISTRY_HOSTS = Object.freeze([
4554
+ "oneaddress.io",
4555
+ "www.oneaddress.io",
4556
+ "app.oneaddress.io"
4523
4557
  ]);
4558
+ PRODUCTION_ROOT = Object.freeze({
4559
+ root_key_id: "rk1_251368ec9b0a84ae",
4560
+ spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4561
+ });
4562
+ REGISTRY_ROOT_PINS = Object.freeze({
4563
+ production: Object.freeze([PRODUCTION_ROOT]),
4564
+ preview: Object.freeze([
4565
+ Object.freeze({
4566
+ root_key_id: "rk1_4690d67464893d48",
4567
+ spki_sha256: "4690d67464893d48ebb335bcd29f3203fbacefbc69afd8a047b639521296bfab"
4568
+ })
4569
+ ])
4570
+ });
4571
+ PINNED_REGISTRY_ROOTS = REGISTRY_ROOT_PINS.production;
4524
4572
  overrideForTests = null;
4525
4573
  }
4526
4574
  });
@@ -4711,6 +4759,30 @@ var init_registry_head = __esm({
4711
4759
  });
4712
4760
 
4713
4761
  // ../crypto/src/verify-partner-keys.ts
4762
+ function localStorageHeadHighWater(key = "oa-registry-head-issued-at") {
4763
+ return {
4764
+ read() {
4765
+ try {
4766
+ return globalThis.localStorage?.getItem(key) ?? null;
4767
+ } catch {
4768
+ return null;
4769
+ }
4770
+ },
4771
+ write(issuedAt) {
4772
+ try {
4773
+ globalThis.localStorage?.setItem(key, issuedAt);
4774
+ } catch {
4775
+ }
4776
+ }
4777
+ };
4778
+ }
4779
+ function isOlderThan(candidate, mark) {
4780
+ if (!mark) return false;
4781
+ const m = Date.parse(mark);
4782
+ const c = Date.parse(candidate);
4783
+ if (Number.isNaN(m)) return false;
4784
+ return Number.isNaN(c) || c < m;
4785
+ }
4714
4786
  async function saysRootNotConfigured(res) {
4715
4787
  if (res.status !== 503) return false;
4716
4788
  try {
@@ -4746,19 +4818,61 @@ async function crossoverOutcomeFor(partnerId, crossover, reg) {
4746
4818
  if (!reg.head) return "head-unusable";
4747
4819
  return await headNamesStagedKey(reg.head, partnerId, crossover.key_id, crossover.public_key_b64) ? "ok" : "not-authorised";
4748
4820
  }
4821
+ function refuseAll(keys, outcome) {
4822
+ const blocked = {};
4823
+ const crossoverBlocked = {};
4824
+ try {
4825
+ for (const [partnerId, key] of Object.entries(keys ?? {})) {
4826
+ blocked[partnerId] = outcome;
4827
+ if (key?.crossover) crossoverBlocked[partnerId] = "head-unusable";
4828
+ }
4829
+ } catch {
4830
+ }
4831
+ return { blocked, crossoverBlocked };
4832
+ }
4749
4833
  function createPartnerKeyVerifier(env = {}) {
4750
4834
  const baseUrl = env.baseUrl ?? "";
4751
- const report = env.report ?? (() => {
4752
- });
4835
+ const report = (context, detail) => {
4836
+ try {
4837
+ env.report?.(context, detail);
4838
+ } catch {
4839
+ }
4840
+ };
4753
4841
  let registryPromise = null;
4754
4842
  function worthCaching(load) {
4755
4843
  return load.ok && load.registry.head !== null;
4756
4844
  }
4845
+ async function readMark() {
4846
+ try {
4847
+ const v = await env.headHighWater?.read();
4848
+ return typeof v === "string" ? v : null;
4849
+ } catch {
4850
+ return null;
4851
+ }
4852
+ }
4853
+ async function writeMark(issuedAt) {
4854
+ try {
4855
+ await env.headHighWater?.write(issuedAt);
4856
+ } catch {
4857
+ }
4858
+ }
4859
+ async function judgeHead(headRes, roots) {
4860
+ if (!headRes.ok) return { head: null, headVerdict: "absent" };
4861
+ let head;
4862
+ try {
4863
+ head = await headRes.json();
4864
+ } catch {
4865
+ return { head: null, headVerdict: "unreadable" };
4866
+ }
4867
+ const headVerdict = await verifyRegistryHead(head, roots);
4868
+ return headVerdict === "ok" ? { head, headVerdict } : { head: null, headVerdict };
4869
+ }
4757
4870
  async function loadRegistry() {
4758
4871
  try {
4872
+ const headUrl = baseUrl + "/.well-known/oneaddress-key-registry-head.json";
4759
4873
  const [rootsRes, headRes] = await Promise.all([
4760
4874
  fetch(baseUrl + "/.well-known/oneaddress-key-registry.json", { cache: "no-cache" }),
4761
- fetch(baseUrl + "/.well-known/oneaddress-key-registry-head.json", { cache: "no-cache" })
4875
+ fetch(headUrl, { cache: "no-cache" })
4762
4876
  ]);
4763
4877
  if (!rootsRes.ok) {
4764
4878
  const configured = await saysRootNotConfigured(rootsRes);
@@ -4780,16 +4894,30 @@ function createPartnerKeyVerifier(env = {}) {
4780
4894
  if (roots.length === 0) {
4781
4895
  return { ok: false, failure: { reason: "roots-empty", status: rootsRes.status } };
4782
4896
  }
4783
- const unpinnedRoots = await unpinnedRootIds(roots);
4897
+ const unpinnedRoots = await unpinnedRootIds(roots, registryEnvironmentForOrigin(baseUrl));
4784
4898
  if (unpinnedRoots.length > 0) {
4785
4899
  return { ok: true, registry: { roots: [], head: null, headVerdict: "root-unpinned", unpinnedRoots } };
4786
4900
  }
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;
4901
+ let { head, headVerdict } = await judgeHead(headRes, roots);
4902
+ if (head) {
4903
+ const mark = await readMark();
4904
+ if (isOlderThan(head.issued_at, mark)) {
4905
+ let fresh = { head: null, headVerdict: "absent" };
4906
+ try {
4907
+ fresh = await judgeHead(
4908
+ await fetch(`${headUrl}?fresh=${Date.now()}`, { cache: "reload" }),
4909
+ roots
4910
+ );
4911
+ } catch {
4912
+ }
4913
+ if (fresh.head && !isOlderThan(fresh.head.issued_at, mark)) {
4914
+ ({ head, headVerdict } = fresh);
4915
+ } else {
4916
+ head = null;
4917
+ headVerdict = "rolled-back";
4918
+ }
4919
+ }
4920
+ if (head && head.issued_at !== mark) await writeMark(head.issued_at);
4793
4921
  }
4794
4922
  return { ok: true, registry: { roots, head, headVerdict, unpinnedRoots: [] } };
4795
4923
  } catch {
@@ -4802,8 +4930,8 @@ function createPartnerKeyVerifier(env = {}) {
4802
4930
  const load = await pending;
4803
4931
  if (!worthCaching(load)) registryPromise = null;
4804
4932
  if (!load.ok) {
4805
- report(context, { registry: "unavailable", enforced: false, ...load.failure });
4806
- return { blocked: {}, crossoverBlocked: {} };
4933
+ report(context, { registry: "unavailable", enforced: true, ...load.failure });
4934
+ return refuseAll(keys, "registry-unavailable");
4807
4935
  }
4808
4936
  const reg = load.registry;
4809
4937
  let bound = EMPTY_BOUND;
@@ -4824,6 +4952,7 @@ function createPartnerKeyVerifier(env = {}) {
4824
4952
  "not-in-head": [],
4825
4953
  "head-unusable": [],
4826
4954
  "root-unpinned": [],
4955
+ "registry-unavailable": [],
4827
4956
  "error": []
4828
4957
  };
4829
4958
  const blocked = {};
@@ -4875,8 +5004,8 @@ function createPartnerKeyVerifier(env = {}) {
4875
5004
  }
4876
5005
  return { blocked, crossoverBlocked };
4877
5006
  } catch {
4878
- report(context, { registry: "verifier-error", enforced: false });
4879
- return { blocked: {}, crossoverBlocked: {} };
5007
+ report(context, { registry: "verifier-error", enforced: true });
5008
+ return refuseAll(keys, "error");
4880
5009
  }
4881
5010
  }
4882
5011
  function __resetRegistryCacheForTests() {
@@ -5077,9 +5206,11 @@ __export(src_exports, {
5077
5206
  PARTNER_KEY_REFUSED_MESSAGE: () => PARTNER_KEY_REFUSED_MESSAGE,
5078
5207
  PINNED_REGISTRY_ROOTS: () => PINNED_REGISTRY_ROOTS,
5079
5208
  PIN_HARDENING_VERSION: () => PIN_HARDENING_VERSION,
5209
+ PRODUCTION_REGISTRY_HOSTS: () => PRODUCTION_REGISTRY_HOSTS,
5080
5210
  REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
5081
5211
  REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
5082
5212
  REGISTRY_HEAD_V2: () => REGISTRY_HEAD_V2,
5213
+ REGISTRY_ROOT_PINS: () => REGISTRY_ROOT_PINS,
5083
5214
  SENDER_HELD_KEY_ALGORITHM: () => SENDER_HELD_KEY_ALGORITHM,
5084
5215
  __setPinnedRegistryRootsForTests: () => __setPinnedRegistryRootsForTests,
5085
5216
  blockedPublicKeyReason: () => blockedPublicKeyReason,
@@ -5094,6 +5225,7 @@ __export(src_exports, {
5094
5225
  createSenderHeldKeyBinder: () => createSenderHeldKeyBinder,
5095
5226
  decryptAddress: () => decryptAddress,
5096
5227
  decryptSession: () => decryptSession,
5228
+ encryptAccountCheckForPartner: () => encryptAccountCheckForPartner,
5097
5229
  encryptAddressForAll: () => encryptAddressForAll,
5098
5230
  encryptAddressForPartner: () => encryptAddressForPartner,
5099
5231
  encryptEnvelopeForPartner: () => encryptEnvelopeForPartner,
@@ -5113,6 +5245,7 @@ __export(src_exports, {
5113
5245
  isIpLiteralHost: () => isIpLiteralHost,
5114
5246
  isSafeWebhookUrl: () => isSafeWebhookUrl,
5115
5247
  keyIdForPublicKey: () => keyIdForPublicKey,
5248
+ localStorageHeadHighWater: () => localStorageHeadHighWater,
5116
5249
  memorySenderHeldKeyStore: () => memorySenderHeldKeyStore,
5117
5250
  normaliseAddress: () => normaliseAddress,
5118
5251
  normalizeForBlindIndex: () => normalizeForBlindIndex,
@@ -5120,6 +5253,8 @@ __export(src_exports, {
5120
5253
  parseOprfSeed: () => parseOprfSeed,
5121
5254
  partnerKeyFingerprint: () => partnerKeyFingerprint,
5122
5255
  pinnedRegistryRoots: () => pinnedRegistryRoots,
5256
+ refundReviewNotifySigningString: () => refundReviewNotifySigningString,
5257
+ registryEnvironmentForOrigin: () => registryEnvironmentForOrigin,
5123
5258
  rootIsPinned: () => rootIsPinned,
5124
5259
  rootKeyIdFromSpki: () => rootKeyIdFromSpki,
5125
5260
  rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
@@ -5314,6 +5449,13 @@ async function encryptPayloadForPartner(payload, partner) {
5314
5449
  hkdfSalt: bytesToB64(hkdfSaltBytes)
5315
5450
  };
5316
5451
  }
5452
+ async function encryptAccountCheckForPartner(payload, partner) {
5453
+ if (isRsaScheme(partner.algorithm) || isHybridScheme(partner.algorithm)) {
5454
+ const { session_envelope, session_key_share } = await encryptEnvelopeForPartner(payload, partner);
5455
+ return { session_envelope, session_key_share };
5456
+ }
5457
+ return encryptPayloadForPartner(payload, { partnerId: partner.partner_id, publicKeyB64: partner.public_key_b64 });
5458
+ }
5317
5459
  async function encryptAddressForAll(address, partners) {
5318
5460
  const results = await Promise.all(
5319
5461
  partners.map((p) => encryptAddressForPartner(address, p))
@@ -5752,6 +5894,7 @@ var init_src = __esm({
5752
5894
  "use strict";
5753
5895
  init_hybrid();
5754
5896
  init_replay_window();
5897
+ init_refund_review_notify();
5755
5898
  init_safe_url();
5756
5899
  init_blocked_public_keys();
5757
5900
  init_endpoint_health();
@@ -5803,12 +5946,14 @@ __export(edge_exports, {
5803
5946
  DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
5804
5947
  LoaV2RefusedError: () => LoaV2RefusedError,
5805
5948
  SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
5949
+ VERIFICATION_COMMITMENT_VERSION: () => VERIFICATION_COMMITMENT_VERSION,
5806
5950
  acceptTypedAliases: () => acceptTypedAliases,
5807
5951
  canonicalD5LoaForm: () => canonicalD5LoaForm,
5808
5952
  canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
5809
5953
  checkLoaV2: () => checkLoaV2,
5810
5954
  compareAddresses: () => compareAddresses,
5811
5955
  computeBlindIndex: () => computeBlindIndex,
5956
+ computeVerificationCommitment: () => computeVerificationCommitment,
5812
5957
  createOneAddressHandler: () => createOneAddressHandler,
5813
5958
  d5LoaRef: () => d5LoaRef,
5814
5959
  decryptAddress: () => decryptAddress2,
@@ -5824,7 +5969,9 @@ __export(edge_exports, {
5824
5969
  loaFirstName: () => loaFirstName,
5825
5970
  loaNamesMatch: () => loaNamesMatch,
5826
5971
  loaSurname: () => loaSurname,
5972
+ matchingWebhookSecret: () => matchingWebhookSecret,
5827
5973
  namePoolMatches: () => namePoolMatches,
5974
+ normaliseCommitmentField: () => normaliseCommitmentField,
5828
5975
  normaliseLoaName: () => normaliseLoaName,
5829
5976
  normalizeForBlindIndex: () => normalizeForBlindIndex,
5830
5977
  sendVerifyResult: () => sendVerifyResult,
@@ -5832,6 +5979,7 @@ __export(edge_exports, {
5832
5979
  transformSession: () => transformSession,
5833
5980
  typedAliasesOf: () => typedAliasesOf,
5834
5981
  validateAddress: () => validateAddress,
5982
+ verificationCommitmentString: () => verificationCommitmentString,
5835
5983
  verifyD5LOA: () => verifyD5LOA,
5836
5984
  verifyD5LOAv2: () => verifyD5LOAv2,
5837
5985
  verifyLOA: () => verifyLOA,
@@ -6017,6 +6165,33 @@ function acceptTypedAliases(verifiedName, aliases) {
6017
6165
  return out;
6018
6166
  }
6019
6167
 
6168
+ // ../protocol/src/verification-commitment.ts
6169
+ var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
6170
+ var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
6171
+ function normaliseCommitmentField(value) {
6172
+ if (typeof value !== "string") return "";
6173
+ const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
6174
+ const start = collapsed.startsWith(" ") ? 1 : 0;
6175
+ const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
6176
+ return collapsed.slice(start, end);
6177
+ }
6178
+ function verificationCommitmentString(verificationId, index, record) {
6179
+ if (!Number.isInteger(index) || index <= 0) {
6180
+ throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
6181
+ }
6182
+ return [
6183
+ VERIFICATION_COMMITMENT_VERSION,
6184
+ normaliseCommitmentField(verificationId),
6185
+ String(index),
6186
+ normaliseCommitmentField(record.name),
6187
+ normaliseCommitmentField(record.street),
6188
+ normaliseCommitmentField(record.suburb),
6189
+ normaliseCommitmentField(record.state),
6190
+ normaliseCommitmentField(record.postcode),
6191
+ normaliseCommitmentField(record.country)
6192
+ ].join("\n");
6193
+ }
6194
+
6020
6195
  // src/app-hosts.ts
6021
6196
  function allowedAppHosts() {
6022
6197
  const hosts = ["oneaddress.io", "app.oneaddress.io"];
@@ -6050,6 +6225,10 @@ function resolveAppOrigin(baseUrl, label, extraHosts) {
6050
6225
  return parsed.origin;
6051
6226
  }
6052
6227
 
6228
+ // src/update-check.ts
6229
+ var SDK_VERSION = "2.11.0";
6230
+ var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
6231
+
6053
6232
  // src/index.ts
6054
6233
  init_src();
6055
6234
  init_src();
@@ -6126,14 +6305,21 @@ function verifySignature(rawBody, signature, timestamp, secret) {
6126
6305
  return import_crypto2.default.timingSafeEqual(sigBuffer, expBuffer);
6127
6306
  }
6128
6307
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6129
- if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
6308
+ return matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) !== null;
6309
+ }
6310
+ function matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6311
+ if (verifySignature(rawBody, signature, timestamp, currentSecret)) return currentSecret;
6130
6312
  if (previousSecret && previousSecret !== currentSecret && graceUntil) {
6131
6313
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
6132
- if (!Number.isNaN(until) && Date.now() < until) {
6133
- return verifySignature(rawBody, signature, timestamp, previousSecret);
6314
+ if (!Number.isNaN(until) && Date.now() < until && verifySignature(rawBody, signature, timestamp, previousSecret)) {
6315
+ return previousSecret;
6134
6316
  }
6135
6317
  }
6136
- return false;
6318
+ return null;
6319
+ }
6320
+ function computeVerificationCommitment(secret, verificationId, index, record) {
6321
+ if (!secret) throw new Error("[OneAddress SDK] a verification commitment needs the webhook secret");
6322
+ return import_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, record), "utf8").digest("hex");
6137
6323
  }
6138
6324
  function base64urlToBuffer(b64) {
6139
6325
  return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
@@ -6199,15 +6385,34 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
6199
6385
  );
6200
6386
  return JSON.parse(new TextDecoder().decode(plaintext));
6201
6387
  }
6388
+ var PRODUCT_CODE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
6389
+ function readSessionProduct(raw) {
6390
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
6391
+ const { id, code, name } = raw;
6392
+ if (typeof id !== "string" || typeof code !== "string" || !PRODUCT_CODE_PATTERN.test(code)) return null;
6393
+ return { id, code, name: typeof name === "string" && name !== "" ? name : code };
6394
+ }
6395
+ function normaliseSessionProduct(data) {
6396
+ if (!data || typeof data !== "object" || !("product" in data)) return data;
6397
+ const product = readSessionProduct(data.product);
6398
+ if (product === null && data.product != null) {
6399
+ console.warn(
6400
+ // NOSONAR - intentional SDK diagnostic, not user-controlled data
6401
+ "[OneAddress SDK] the session envelope carried a malformed product, so it is treated as absent and the update is handled as a plain account."
6402
+ );
6403
+ }
6404
+ return { ...data, product };
6405
+ }
6202
6406
  async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
6203
6407
  const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
6204
- return decryptSessionCrypto(
6408
+ const data = await decryptSessionCrypto(
6205
6409
  share,
6206
6410
  envelopeB64,
6207
6411
  typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
6208
6412
  partnerId,
6209
6413
  expectedAlg
6210
6414
  );
6415
+ return normaliseSessionProduct(data);
6211
6416
  }
6212
6417
  async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
6213
6418
  const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
@@ -6322,7 +6527,11 @@ async function confirmUpdate(opts2) {
6322
6527
  "Content-Type": "application/json",
6323
6528
  "X-OneAddress-Timestamp": timestamp,
6324
6529
  "X-OneAddress-Signature": signature,
6325
- [PULL_SIGNATURE_VERSION_HEADER]: "2"
6530
+ [PULL_SIGNATURE_VERSION_HEADER]: "2",
6531
+ // Which SDK sent this, so the partner portal can say when an update
6532
+ // exists. Software name and version only; outside the signature, and
6533
+ // recorded by OneAddress only after the signature verifies.
6534
+ "X-OneAddress-Client": `partner-sdk-ts/${SDK_VERSION}`
6326
6535
  },
6327
6536
  // The SAME string that was signed. Not an object, and not re-stringified.
6328
6537
  body
@@ -6339,10 +6548,11 @@ async function confirmUpdate(opts2) {
6339
6548
  }
6340
6549
  return { ok: false, status: res.status, error };
6341
6550
  }
6551
+ var LOA_KEY_FETCH_TIMEOUT_MS = 1e4;
6342
6552
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
6343
6553
  const origin = resolveAppOrigin(appBaseUrl, "fetchLoaPublicKey");
6344
6554
  const url = `${origin}/.well-known/oneaddress-loa-key.pem`;
6345
- const res = await fetch(url);
6555
+ const res = await fetch(url, { redirect: "error", signal: AbortSignal.timeout(LOA_KEY_FETCH_TIMEOUT_MS) });
6346
6556
  if (!res.ok) {
6347
6557
  throw new Error(`[OneAddress SDK] Failed to fetch LOA public key: HTTP ${res.status}`);
6348
6558
  }
@@ -6820,6 +7030,9 @@ function assertUsablePrivateKey(privateKeyPem) {
6820
7030
  throw refused;
6821
7031
  }
6822
7032
  }
7033
+ function isSessionSealed(v) {
7034
+ return typeof v.session_envelope === "string" && !!v.session_key_share && typeof v.session_key_share === "object" && !Array.isArray(v.session_key_share);
7035
+ }
6823
7036
  function requirePemFor(purpose, key) {
6824
7037
  if (typeof key === "string") return key;
6825
7038
  throw new Error(
@@ -6982,7 +7195,8 @@ function createOneAddressHandler(options) {
6982
7195
  }
6983
7196
  }
6984
7197
  assertEffectiveDateBound(data.effective_date, body.effective_date);
6985
- return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
7198
+ const product = data.product ?? null;
7199
+ return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, product, raw: data };
6986
7200
  }
6987
7201
  function isD5Body(body) {
6988
7202
  return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
@@ -7011,7 +7225,8 @@ function createOneAddressHandler(options) {
7011
7225
  headers: { "Content-Type": "application/json" }
7012
7226
  });
7013
7227
  }
7014
- if (!verifyWithGrace(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil)) {
7228
+ const signingSecret = matchingWebhookSecret(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil);
7229
+ if (signingSecret === null) {
7015
7230
  return new Response(JSON.stringify({ error: "Invalid signature" }), {
7016
7231
  status: 401,
7017
7232
  headers: { "Content-Type": "application/json" }
@@ -7155,6 +7370,7 @@ function createOneAddressHandler(options) {
7155
7370
  loa_ref: d5.loa_ref,
7156
7371
  id_verification: body.id_verification,
7157
7372
  ...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
7373
+ product: d5.product,
7158
7374
  raw: d5.raw
7159
7375
  };
7160
7376
  } else {
@@ -7223,6 +7439,8 @@ function createOneAddressHandler(options) {
7223
7439
  loa,
7224
7440
  loa_ref,
7225
7441
  id_verification: body.id_verification,
7442
+ // The legacy blob predates product lines.
7443
+ product: null,
7226
7444
  raw: rawAddress
7227
7445
  };
7228
7446
  }
@@ -7316,8 +7534,15 @@ function createOneAddressHandler(options) {
7316
7534
  if (body.event === "account.verify" && onAccountVerify) {
7317
7535
  let customer;
7318
7536
  if (body.customer_encrypted && typeof body.customer_encrypted === "object") {
7319
- const raw = await decryptAddress2(
7320
- body.customer_encrypted,
7537
+ const sealed = body.customer_encrypted;
7538
+ const raw = isSessionSealed(sealed) ? await decryptSession2(
7539
+ sealed.session_key_share,
7540
+ sealed.session_envelope,
7541
+ privateKeyPem,
7542
+ partnerId,
7543
+ expectedAlg
7544
+ ) : await decryptAddress2(
7545
+ sealed,
7321
7546
  requirePemFor("account.verify decryption", privateKeyPem),
7322
7547
  partnerId
7323
7548
  );
@@ -7364,11 +7589,26 @@ function createOneAddressHandler(options) {
7364
7589
  address: d5.address,
7365
7590
  raw: d5.raw
7366
7591
  });
7592
+ const index = typeof body.index === "number" ? body.index : void 0;
7593
+ const verificationId = typeof body.verification_id === "string" ? body.verification_id : "";
7594
+ let commitment;
7595
+ if (index !== void 0 && Number.isInteger(index) && index > 0 && verificationId) {
7596
+ const newAddress = d5.raw.new_address ?? {};
7597
+ commitment = computeVerificationCommitment(signingSecret, verificationId, index, {
7598
+ name: d5.raw.verified_name,
7599
+ street: newAddress.street,
7600
+ suburb: newAddress.suburb,
7601
+ state: newAddress.state,
7602
+ postcode: newAddress.postcode,
7603
+ country: newAddress.country
7604
+ });
7605
+ }
7367
7606
  return declared(200, {
7368
7607
  ok: true,
7369
7608
  test: true,
7370
7609
  verification: true,
7371
- index: typeof body.index === "number" ? body.index : void 0
7610
+ index,
7611
+ ...commitment ? { commitment } : {}
7372
7612
  });
7373
7613
  }
7374
7614
  const evt = typeof body.event === "string" ? body.event : "(none)";
@@ -7428,12 +7668,14 @@ function createOneAddressHandler(options) {
7428
7668
  DEFAULT_REPLAY_WINDOW_SECS,
7429
7669
  LoaV2RefusedError,
7430
7670
  SUPPORTED_VERSIONS,
7671
+ VERIFICATION_COMMITMENT_VERSION,
7431
7672
  acceptTypedAliases,
7432
7673
  canonicalD5LoaForm,
7433
7674
  canonicalD5LoaFormV2,
7434
7675
  checkLoaV2,
7435
7676
  compareAddresses,
7436
7677
  computeBlindIndex,
7678
+ computeVerificationCommitment,
7437
7679
  createOneAddressHandler,
7438
7680
  d5LoaRef,
7439
7681
  decryptAddress,
@@ -7449,7 +7691,9 @@ function createOneAddressHandler(options) {
7449
7691
  loaFirstName,
7450
7692
  loaNamesMatch,
7451
7693
  loaSurname,
7694
+ matchingWebhookSecret,
7452
7695
  namePoolMatches,
7696
+ normaliseCommitmentField,
7453
7697
  normaliseLoaName,
7454
7698
  normalizeForBlindIndex,
7455
7699
  sendVerifyResult,
@@ -7457,6 +7701,7 @@ function createOneAddressHandler(options) {
7457
7701
  transformSession,
7458
7702
  typedAliasesOf,
7459
7703
  validateAddress,
7704
+ verificationCommitmentString,
7460
7705
  verifyD5LOA,
7461
7706
  verifyD5LOAv2,
7462
7707
  verifyLOA,