@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/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;
@@ -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();
@@ -5812,7 +5955,11 @@ __export(index_exports, {
5812
5955
  LoaV2RefusedError: () => LoaV2RefusedError,
5813
5956
  MAX_ADDRESS_FIELD_CHARS: () => MAX_ADDRESS_FIELD_CHARS,
5814
5957
  OUTBOX_LEASE_COLUMNS: () => OUTBOX_LEASE_COLUMNS,
5958
+ PRODUCT_CODE_PATTERN: () => PRODUCT_CODE_PATTERN,
5959
+ SDK_VERSION: () => SDK_VERSION,
5815
5960
  SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
5961
+ UPDATE_GUIDE_URL: () => UPDATE_GUIDE_URL,
5962
+ VERIFICATION_COMMITMENT_VERSION: () => VERIFICATION_COMMITMENT_VERSION,
5816
5963
  _resetLoaKeyCacheForTests: () => _resetLoaKeyCacheForTests,
5817
5964
  _resetOnceWarningsForTests: () => _resetOnceWarningsForTests,
5818
5965
  acceptTypedAliases: () => acceptTypedAliases,
@@ -5821,10 +5968,12 @@ __export(index_exports, {
5821
5968
  cachedLoaPublicKey: () => cachedLoaPublicKey,
5822
5969
  canonicalD5LoaForm: () => canonicalD5LoaForm,
5823
5970
  canonicalD5LoaFormV2: () => canonicalD5LoaFormV2,
5971
+ checkForUpdate: () => checkForUpdate,
5824
5972
  checkLoaV2: () => checkLoaV2,
5825
5973
  checkRegistryHead: () => checkRegistryHead,
5826
5974
  compareAddresses: () => compareAddresses,
5827
5975
  computeBlindIndex: () => computeBlindIndex,
5976
+ computeVerificationCommitment: () => computeVerificationCommitment,
5828
5977
  confirmUpdate: () => confirmUpdate,
5829
5978
  createOneAddressHandler: () => createOneAddressHandler,
5830
5979
  createOutboxConsumer: () => createOutboxConsumer,
@@ -5842,24 +5991,34 @@ __export(index_exports, {
5842
5991
  isAcceptableAlias: () => isAcceptableAlias,
5843
5992
  isEmailLike: () => isEmailLike2,
5844
5993
  isFreshTimestamp: () => isFreshTimestamp,
5994
+ isIsoDate: () => isIsoDate,
5995
+ isNewerVersion: () => isNewerVersion,
5845
5996
  loaEnvelopeSha256: () => loaEnvelopeSha256,
5846
5997
  loaFirstName: () => loaFirstName,
5847
5998
  loaNamesMatch: () => loaNamesMatch,
5848
5999
  loaSurname: () => loaSurname,
6000
+ matchingWebhookSecret: () => matchingWebhookSecret,
5849
6001
  namePoolMatches: () => namePoolMatches,
6002
+ normaliseCommitmentField: () => normaliseCommitmentField,
5850
6003
  normaliseLoaName: () => normaliseLoaName,
5851
6004
  normalizeForBlindIndex: () => normalizeForBlindIndex,
5852
6005
  parsePinnedRegistryRoots: () => parsePinnedRegistryRoots,
5853
6006
  readAddressParts: () => readAddressParts,
6007
+ readSessionProduct: () => readSessionProduct,
5854
6008
  sendVerifyResult: () => sendVerifyResult,
5855
6009
  signPullRequest: () => signPullRequest,
6010
+ startUpdateCheck: () => startUpdateCheck,
5856
6011
  toExpressHandler: () => toExpressHandler,
5857
6012
  toOutboxTimestamp: () => toOutboxTimestamp,
5858
6013
  transform: () => transformAddress,
5859
6014
  transformAddress: () => transformAddress,
5860
6015
  transformSession: () => transformSession,
5861
6016
  typedAliasesOf: () => typedAliasesOf,
6017
+ updateAvailableLine: () => updateAvailableLine,
6018
+ updateCheckEnabled: () => updateCheckEnabled,
6019
+ updateCheckMetric: () => updateCheckMetric,
5862
6020
  validateAddress: () => validateAddress,
6021
+ verificationCommitmentString: () => verificationCommitmentString,
5863
6022
  verify: () => verifySignature,
5864
6023
  verifyD5LOA: () => verifyD5LOA,
5865
6024
  verifyD5LOAv2: () => verifyD5LOAv2,
@@ -6068,6 +6227,33 @@ var LOA_V2_REFUSALS = [
6068
6227
  "loa_v2_name_mismatch"
6069
6228
  ];
6070
6229
 
6230
+ // ../protocol/src/verification-commitment.ts
6231
+ var VERIFICATION_COMMITMENT_VERSION = "oa-verify.v1";
6232
+ var ASCII_WHITESPACE_RUN = /[\t\n\v\f\r ]+/g;
6233
+ function normaliseCommitmentField(value) {
6234
+ if (typeof value !== "string") return "";
6235
+ const collapsed = value.replace(ASCII_WHITESPACE_RUN, " ");
6236
+ const start = collapsed.startsWith(" ") ? 1 : 0;
6237
+ const end = collapsed.length > start && collapsed.endsWith(" ") ? collapsed.length - 1 : collapsed.length;
6238
+ return collapsed.slice(start, end);
6239
+ }
6240
+ function verificationCommitmentString(verificationId, index, record) {
6241
+ if (!Number.isInteger(index) || index <= 0) {
6242
+ throw new RangeError(`verification commitment index must be a positive integer, got ${String(index)}`);
6243
+ }
6244
+ return [
6245
+ VERIFICATION_COMMITMENT_VERSION,
6246
+ normaliseCommitmentField(verificationId),
6247
+ String(index),
6248
+ normaliseCommitmentField(record.name),
6249
+ normaliseCommitmentField(record.street),
6250
+ normaliseCommitmentField(record.suburb),
6251
+ normaliseCommitmentField(record.state),
6252
+ normaliseCommitmentField(record.postcode),
6253
+ normaliseCommitmentField(record.country)
6254
+ ].join("\n");
6255
+ }
6256
+
6071
6257
  // src/app-hosts.ts
6072
6258
  function allowedAppHosts() {
6073
6259
  const hosts = ["oneaddress.io", "app.oneaddress.io"];
@@ -6101,6 +6287,96 @@ function resolveAppOrigin(baseUrl, label, extraHosts) {
6101
6287
  return parsed.origin;
6102
6288
  }
6103
6289
 
6290
+ // src/update-check.ts
6291
+ var SDK_VERSION = "2.11.0";
6292
+ var UPDATE_GUIDE_URL = "https://partners.oneaddress.io/#updating-safely";
6293
+ var REGISTRY_URL = "https://registry.npmjs.org/@oneaddress/partner-sdk/latest";
6294
+ var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
6295
+ var TIMEOUT_MS = 5e3;
6296
+ function updateCheckEnabled(setting) {
6297
+ const s = (setting ?? "").trim().toLowerCase();
6298
+ return !(s === "off" || s === "never" || s === "0" || s === "false");
6299
+ }
6300
+ function parseVersion(v) {
6301
+ if (typeof v !== "string") return null;
6302
+ const m = /^(\d{1,6})\.(\d{1,6})\.(\d{1,6})$/.exec(v.trim());
6303
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
6304
+ }
6305
+ function isNewerVersion(latest, running) {
6306
+ const a = parseVersion(latest);
6307
+ const b = parseVersion(running);
6308
+ if (!a || !b) return false;
6309
+ for (let i = 0; i < 3; i++) {
6310
+ if (a[i] !== b[i]) return a[i] > b[i];
6311
+ }
6312
+ return false;
6313
+ }
6314
+ function updateAvailableLine(running, latest) {
6315
+ return `update available: ${running} -> ${latest}, see ${UPDATE_GUIDE_URL}`;
6316
+ }
6317
+ function updateCheckMetric(result, product = "partner-sdk-ts") {
6318
+ const latest = result.latest ?? "unknown";
6319
+ const value = result.state === "available" ? 1 : 0;
6320
+ return `oneaddress_update_available{product="${product}",running="${result.running}",latest="${latest}"} ${value}`;
6321
+ }
6322
+ async function checkForUpdate(opts2 = {}) {
6323
+ const running = opts2.running ?? SDK_VERSION;
6324
+ const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
6325
+ if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) return { state: "disabled", running };
6326
+ const fetchImpl = opts2.fetchImpl ?? globalThis.fetch;
6327
+ const now = opts2.now ?? Date.now;
6328
+ if (typeof fetchImpl !== "function") return { state: "unknown", running };
6329
+ const abort = new AbortController();
6330
+ const timer = setTimeout(() => abort.abort(), opts2.timeoutMs ?? TIMEOUT_MS);
6331
+ try {
6332
+ const res = await fetchImpl(opts2.registryUrl ?? REGISTRY_URL, { signal: abort.signal });
6333
+ const checkedAt = now();
6334
+ if (!res.ok) return { state: "unknown", running, checkedAt };
6335
+ const body = await res.json();
6336
+ if (!parseVersion(body?.version)) return { state: "unknown", running, checkedAt };
6337
+ const latest = body.version.trim();
6338
+ return {
6339
+ state: isNewerVersion(latest, running) ? "available" : "current",
6340
+ running,
6341
+ latest,
6342
+ checkedAt
6343
+ };
6344
+ } catch {
6345
+ return { state: "unknown", running };
6346
+ } finally {
6347
+ clearTimeout(timer);
6348
+ }
6349
+ }
6350
+ function startUpdateCheck(opts2 = {}) {
6351
+ const running = opts2.running ?? SDK_VERSION;
6352
+ let last = { state: "unknown", running };
6353
+ let announced = null;
6354
+ const log = opts2.log ?? ((line) => console.warn(line));
6355
+ const env = opts2.env ?? (typeof process !== "undefined" ? process.env : {});
6356
+ if (!updateCheckEnabled(env.ONEADDRESS_UPDATE_CHECK)) {
6357
+ last = { state: "disabled", running };
6358
+ opts2.onResult?.(last);
6359
+ return { current: () => last, stop: () => {
6360
+ } };
6361
+ }
6362
+ const run = async () => {
6363
+ const result = await checkForUpdate({ ...opts2, running, env });
6364
+ if (result.state !== "unknown" || last.state === "unknown") last = result;
6365
+ if (last.state === "available" && last.latest && last.latest !== announced) {
6366
+ announced = last.latest;
6367
+ log(updateAvailableLine(running, last.latest));
6368
+ }
6369
+ opts2.onResult?.(last);
6370
+ };
6371
+ void run();
6372
+ const every = Math.max(opts2.intervalMs ?? ONE_DAY_MS, 60 * 60 * 1e3);
6373
+ const timer = setInterval(() => {
6374
+ void run();
6375
+ }, every);
6376
+ timer.unref?.();
6377
+ return { current: () => last, stop: () => clearInterval(timer) };
6378
+ }
6379
+
6104
6380
  // src/index.ts
6105
6381
  init_src();
6106
6382
  init_src();
@@ -6756,14 +7032,21 @@ function signPullRequest(opts2) {
6756
7032
  };
6757
7033
  }
6758
7034
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
6759
- if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
7035
+ return matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) !== null;
7036
+ }
7037
+ function matchingWebhookSecret(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
7038
+ if (verifySignature(rawBody, signature, timestamp, currentSecret)) return currentSecret;
6760
7039
  if (previousSecret && previousSecret !== currentSecret && graceUntil) {
6761
7040
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
6762
- if (!Number.isNaN(until) && Date.now() < until) {
6763
- return verifySignature(rawBody, signature, timestamp, previousSecret);
7041
+ if (!Number.isNaN(until) && Date.now() < until && verifySignature(rawBody, signature, timestamp, previousSecret)) {
7042
+ return previousSecret;
6764
7043
  }
6765
7044
  }
6766
- return false;
7045
+ return null;
7046
+ }
7047
+ function computeVerificationCommitment(secret, verificationId, index, record) {
7048
+ if (!secret) throw new Error("[OneAddress SDK] a verification commitment needs the webhook secret");
7049
+ return import_crypto2.default.createHmac("sha256", secret).update(verificationCommitmentString(verificationId, index, record), "utf8").digest("hex");
6767
7050
  }
6768
7051
  function base64urlToBuffer(b64) {
6769
7052
  return Buffer.from(b64.replace(/-/g, "+").replace(/_/g, "/"), "base64");
@@ -6829,15 +7112,34 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
6829
7112
  );
6830
7113
  return JSON.parse(new TextDecoder().decode(plaintext));
6831
7114
  }
7115
+ var PRODUCT_CODE_PATTERN = /^[a-z0-9][a-z0-9_-]{0,39}$/;
7116
+ function readSessionProduct(raw) {
7117
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
7118
+ const { id, code, name } = raw;
7119
+ if (typeof id !== "string" || typeof code !== "string" || !PRODUCT_CODE_PATTERN.test(code)) return null;
7120
+ return { id, code, name: typeof name === "string" && name !== "" ? name : code };
7121
+ }
7122
+ function normaliseSessionProduct(data) {
7123
+ if (!data || typeof data !== "object" || !("product" in data)) return data;
7124
+ const product = readSessionProduct(data.product);
7125
+ if (product === null && data.product != null) {
7126
+ console.warn(
7127
+ // NOSONAR - intentional SDK diagnostic, not user-controlled data
7128
+ "[OneAddress SDK] the session envelope carried a malformed product, so it is treated as absent and the update is handled as a plain account."
7129
+ );
7130
+ }
7131
+ return { ...data, product };
7132
+ }
6832
7133
  async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
6833
7134
  const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
6834
- return decryptSessionCrypto(
7135
+ const data = await decryptSessionCrypto(
6835
7136
  share,
6836
7137
  envelopeB64,
6837
7138
  typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
6838
7139
  partnerId,
6839
7140
  expectedAlg
6840
7141
  );
7142
+ return normaliseSessionProduct(data);
6841
7143
  }
6842
7144
  async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
6843
7145
  const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
@@ -6952,7 +7254,11 @@ async function confirmUpdate(opts2) {
6952
7254
  "Content-Type": "application/json",
6953
7255
  "X-OneAddress-Timestamp": timestamp,
6954
7256
  "X-OneAddress-Signature": signature,
6955
- [PULL_SIGNATURE_VERSION_HEADER]: "2"
7257
+ [PULL_SIGNATURE_VERSION_HEADER]: "2",
7258
+ // Which SDK sent this, so the partner portal can say when an update
7259
+ // exists. Software name and version only; outside the signature, and
7260
+ // recorded by OneAddress only after the signature verifies.
7261
+ "X-OneAddress-Client": `partner-sdk-ts/${SDK_VERSION}`
6956
7262
  },
6957
7263
  // The SAME string that was signed. Not an object, and not re-stringified.
6958
7264
  body
@@ -6969,10 +7275,11 @@ async function confirmUpdate(opts2) {
6969
7275
  }
6970
7276
  return { ok: false, status: res.status, error };
6971
7277
  }
7278
+ var LOA_KEY_FETCH_TIMEOUT_MS = 1e4;
6972
7279
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL2) {
6973
7280
  const origin = resolveAppOrigin(appBaseUrl, "fetchLoaPublicKey");
6974
7281
  const url = `${origin}/.well-known/oneaddress-loa-key.pem`;
6975
- const res = await fetch(url);
7282
+ const res = await fetch(url, { redirect: "error", signal: AbortSignal.timeout(LOA_KEY_FETCH_TIMEOUT_MS) });
6976
7283
  if (!res.ok) {
6977
7284
  throw new Error(`[OneAddress SDK] Failed to fetch LOA public key: HTTP ${res.status}`);
6978
7285
  }
@@ -7486,6 +7793,9 @@ function assertUsablePrivateKey(privateKeyPem) {
7486
7793
  throw refused;
7487
7794
  }
7488
7795
  }
7796
+ function isSessionSealed(v) {
7797
+ return typeof v.session_envelope === "string" && !!v.session_key_share && typeof v.session_key_share === "object" && !Array.isArray(v.session_key_share);
7798
+ }
7489
7799
  function requirePemFor(purpose, key) {
7490
7800
  if (typeof key === "string") return key;
7491
7801
  throw new Error(
@@ -7648,7 +7958,8 @@ function createOneAddressHandler(options) {
7648
7958
  }
7649
7959
  }
7650
7960
  assertEffectiveDateBound(data.effective_date, body.effective_date);
7651
- return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, raw: data };
7961
+ const product = data.product ?? null;
7962
+ return { updateTypes, address, newPhone, newEmail, customer, loa, loa_ref, product, raw: data };
7652
7963
  }
7653
7964
  function isD5Body(body) {
7654
7965
  return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
@@ -7677,7 +7988,8 @@ function createOneAddressHandler(options) {
7677
7988
  headers: { "Content-Type": "application/json" }
7678
7989
  });
7679
7990
  }
7680
- if (!verifyWithGrace(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil)) {
7991
+ const signingSecret = matchingWebhookSecret(rawBody, tsHeader, sig, webhookSecret, previousWebhookSecret, webhookSecretGraceUntil);
7992
+ if (signingSecret === null) {
7681
7993
  return new Response(JSON.stringify({ error: "Invalid signature" }), {
7682
7994
  status: 401,
7683
7995
  headers: { "Content-Type": "application/json" }
@@ -7821,6 +8133,7 @@ function createOneAddressHandler(options) {
7821
8133
  loa_ref: d5.loa_ref,
7822
8134
  id_verification: body.id_verification,
7823
8135
  ...body.effective_date !== void 0 ? { effective_date: body.effective_date } : {},
8136
+ product: d5.product,
7824
8137
  raw: d5.raw
7825
8138
  };
7826
8139
  } else {
@@ -7889,6 +8202,8 @@ function createOneAddressHandler(options) {
7889
8202
  loa,
7890
8203
  loa_ref,
7891
8204
  id_verification: body.id_verification,
8205
+ // The legacy blob predates product lines.
8206
+ product: null,
7892
8207
  raw: rawAddress
7893
8208
  };
7894
8209
  }
@@ -7982,8 +8297,15 @@ function createOneAddressHandler(options) {
7982
8297
  if (body.event === "account.verify" && onAccountVerify) {
7983
8298
  let customer;
7984
8299
  if (body.customer_encrypted && typeof body.customer_encrypted === "object") {
7985
- const raw = await decryptAddress2(
7986
- body.customer_encrypted,
8300
+ const sealed = body.customer_encrypted;
8301
+ const raw = isSessionSealed(sealed) ? await decryptSession2(
8302
+ sealed.session_key_share,
8303
+ sealed.session_envelope,
8304
+ privateKeyPem,
8305
+ partnerId,
8306
+ expectedAlg
8307
+ ) : await decryptAddress2(
8308
+ sealed,
7987
8309
  requirePemFor("account.verify decryption", privateKeyPem),
7988
8310
  partnerId
7989
8311
  );
@@ -8030,11 +8352,26 @@ function createOneAddressHandler(options) {
8030
8352
  address: d5.address,
8031
8353
  raw: d5.raw
8032
8354
  });
8355
+ const index = typeof body.index === "number" ? body.index : void 0;
8356
+ const verificationId = typeof body.verification_id === "string" ? body.verification_id : "";
8357
+ let commitment;
8358
+ if (index !== void 0 && Number.isInteger(index) && index > 0 && verificationId) {
8359
+ const newAddress = d5.raw.new_address ?? {};
8360
+ commitment = computeVerificationCommitment(signingSecret, verificationId, index, {
8361
+ name: d5.raw.verified_name,
8362
+ street: newAddress.street,
8363
+ suburb: newAddress.suburb,
8364
+ state: newAddress.state,
8365
+ postcode: newAddress.postcode,
8366
+ country: newAddress.country
8367
+ });
8368
+ }
8033
8369
  return declared(200, {
8034
8370
  ok: true,
8035
8371
  test: true,
8036
8372
  verification: true,
8037
- index: typeof body.index === "number" ? body.index : void 0
8373
+ index,
8374
+ ...commitment ? { commitment } : {}
8038
8375
  });
8039
8376
  }
8040
8377
  const evt = typeof body.event === "string" ? body.event : "(none)";
@@ -8257,7 +8594,11 @@ async function buildSignedTestWebhook(opts2) {
8257
8594
  LoaV2RefusedError,
8258
8595
  MAX_ADDRESS_FIELD_CHARS,
8259
8596
  OUTBOX_LEASE_COLUMNS,
8597
+ PRODUCT_CODE_PATTERN,
8598
+ SDK_VERSION,
8260
8599
  SUPPORTED_VERSIONS,
8600
+ UPDATE_GUIDE_URL,
8601
+ VERIFICATION_COMMITMENT_VERSION,
8261
8602
  _resetLoaKeyCacheForTests,
8262
8603
  _resetOnceWarningsForTests,
8263
8604
  acceptTypedAliases,
@@ -8266,10 +8607,12 @@ async function buildSignedTestWebhook(opts2) {
8266
8607
  cachedLoaPublicKey,
8267
8608
  canonicalD5LoaForm,
8268
8609
  canonicalD5LoaFormV2,
8610
+ checkForUpdate,
8269
8611
  checkLoaV2,
8270
8612
  checkRegistryHead,
8271
8613
  compareAddresses,
8272
8614
  computeBlindIndex,
8615
+ computeVerificationCommitment,
8273
8616
  confirmUpdate,
8274
8617
  createOneAddressHandler,
8275
8618
  createOutboxConsumer,
@@ -8287,24 +8630,34 @@ async function buildSignedTestWebhook(opts2) {
8287
8630
  isAcceptableAlias,
8288
8631
  isEmailLike,
8289
8632
  isFreshTimestamp,
8633
+ isIsoDate,
8634
+ isNewerVersion,
8290
8635
  loaEnvelopeSha256,
8291
8636
  loaFirstName,
8292
8637
  loaNamesMatch,
8293
8638
  loaSurname,
8639
+ matchingWebhookSecret,
8294
8640
  namePoolMatches,
8641
+ normaliseCommitmentField,
8295
8642
  normaliseLoaName,
8296
8643
  normalizeForBlindIndex,
8297
8644
  parsePinnedRegistryRoots,
8298
8645
  readAddressParts,
8646
+ readSessionProduct,
8299
8647
  sendVerifyResult,
8300
8648
  signPullRequest,
8649
+ startUpdateCheck,
8301
8650
  toExpressHandler,
8302
8651
  toOutboxTimestamp,
8303
8652
  transform,
8304
8653
  transformAddress,
8305
8654
  transformSession,
8306
8655
  typedAliasesOf,
8656
+ updateAvailableLine,
8657
+ updateCheckEnabled,
8658
+ updateCheckMetric,
8307
8659
  validateAddress,
8660
+ verificationCommitmentString,
8308
8661
  verify,
8309
8662
  verifyD5LOA,
8310
8663
  verifyD5LOAv2,