@oneaddress/partner-sdk 2.9.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/CHANGELOG.md CHANGED
@@ -7,7 +7,51 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ## [2.9.0] - unreleased (repo bump only, not published)
10
+ ### Added: the confirm names the SDK version
11
+
12
+ - Every confirm sends `X-OneAddress-Client: partner-sdk-ts/<version>`. Software name and version only, outside the signature. OneAddress records it after the confirm verifies and the partner portal shows whether an update exists.
13
+
14
+ ### Added: a read-only update check
15
+
16
+ - `startUpdateCheck()`, `checkForUpdate()` and `updateCheckMetric()`: ask the public registry, at most once a day, whether a newer SDK is published, and log one line, `update available: X -> Y, see <guide URL>`, when it is. Opt-in (nothing runs unless you start it), sends no identifying data, never installs anything, and `ONEADDRESS_UPDATE_CHECK=off` stops it.
17
+
18
+ ## [2.10.0] (repo bump only, not published)
19
+
20
+ ### Added: a signed answer to the connection verification
21
+
22
+ - **An indexed `address.test` / `address.test-dispatch` is answered with
23
+ `commitment`** beside `verification: true`: lowercase hex HMAC-SHA256, keyed
24
+ with the webhook secret that verified the request (the previous one inside a
25
+ rotation grace window), over one canonical string of the verification id,
26
+ the record index and the DECRYPTED name and structured address. OneAddress
27
+ recomputes it over the record it sent and records the verification itself,
28
+ so going live no longer rests on a bare `verification: true` and nobody has
29
+ to paste a block from the logs. Automatic when `onTest` is wired. A health
30
+ probe (no index) gets no commitment.
31
+ - **`computeVerificationCommitment`**, **`verificationCommitmentString`**,
32
+ **`normaliseCommitmentField`** and **`VERIFICATION_COMMITMENT_VERSION`**, for a
33
+ receiver that answers `address.test` without the handler. Checked against the
34
+ `verification_commitment` vectors the Python, Go, Java and C# SDKs share.
35
+ - **`matchingWebhookSecret`**: which secret verified a request, or null.
36
+ `verifyWithGrace` is now a wrapper over it and answers exactly as before.
37
+
38
+ ### Added: `product` on product-line accounts
39
+
40
+ - **`OneAddressUpdateEvent.product`** (`{ id, code, name }` or `null`), the partner
41
+ product line the customer's account sits under, sealed in the envelope beside
42
+ `account_number`. Route on `code`. `null` for a plain account and on legacy dispatches.
43
+ - **`SessionData.product`**, the same value from `decryptSession`, plus
44
+ `readSessionProduct` and `PRODUCT_CODE_PATTERN`.
45
+ - **Read tolerantly.** A `product` that is not an object, lacks a string `id` or
46
+ `code`, or has a `code` outside `^[a-z0-9][a-z0-9_-]{0,39}$` reads as `null` with a
47
+ warning, and the update is still handled. A missing `name` reads as the `code`.
48
+ Validated against the shared `session_product` vectors.
49
+
50
+ ## [2.9.0] - 2026-10-31
51
+
52
+ Published at registry timestamp `2026-10-31T17:14:06.672Z`. The tarball carries the heading this line
53
+ replaced, "unreleased (repo bump only, not published)", because the record is written after
54
+ the publish.
11
55
 
12
56
  ### Added: `effective_date` on scheduled moves
13
57
 
package/README.md CHANGED
@@ -840,6 +840,20 @@ The customer's device also seals the move date inside the envelope. The handler
840
840
 
841
841
  Rehearse it with `buildSignedTestWebhook({ ..., effectiveDate: '2026-12-07' })`, which puts the date in the body and seals it in the session.
842
842
 
843
+ ## Product lines and `product`
844
+
845
+ If you set up product lines in the partner portal (home and car insurance, say), the customer picks one when they add their account, and it is sealed in the envelope beside the account number. Route on its `code`, which is your own key and survives a rename:
846
+
847
+ ```ts
848
+ onUpdate: async (event) => {
849
+ // null for a plain account.
850
+ const queue = event.product?.code ?? 'default';
851
+ await queues[queue].push(event.customer, event.address);
852
+ },
853
+ ```
854
+
855
+ `event.product` is `{ id, code, name }` or `null`. A malformed sealed value is read as `null` (and logged as a warning), never as a refusal, so a sender fault cannot lose a change of address. `decryptSession` exposes the same field as `session.product`.
856
+
843
857
  ## Secret rotation grace window
844
858
 
845
859
  **Rotate with an overlap.** Staging a new secret in the Partner Portal does **not** change what we sign with: we keep using your current secret until you press *Switch over*. So the safe sequence is stage, deploy the new secret alongside the current one, verify with both, then switch. At every point the secret we sign with is one your receiver already holds.
@@ -1367,6 +1381,27 @@ npx @oneaddress/conformance test http://localhost:3001/webhook
1367
1381
 
1368
1382
  Or use the **Integration Conformance** card in the Partner Portal to run the same checks against your configured webhook URL from within the portal.
1369
1383
 
1384
+ ## Update check
1385
+
1386
+ Call it once at startup and the SDK tells you when a newer version is published. It never installs anything: a receiver holds your decryption key, so updating stays a change you review and deploy.
1387
+
1388
+ ```ts
1389
+ import { startUpdateCheck } from '@oneaddress/partner-sdk';
1390
+
1391
+ const updates = startUpdateCheck(); // logs one line via console.warn
1392
+ // in /metrics: updateCheckMetric(updates.current())
1393
+ ```
1394
+
1395
+ - Asks npm (`registry.npmjs.org/@oneaddress/partner-sdk/latest`) for one version number, at most once a day, in the background.
1396
+ - Sends a plain GET with no partner id and no identifying header.
1397
+ - When behind, logs one line: `update available: X -> Y, see https://partners.oneaddress.io/#updating-safely`.
1398
+ - A refused connection or a proxy 403 logs nothing.
1399
+ - `ONEADDRESS_UPDATE_CHECK=off` stops it. It does not run unless you start it.
1400
+
1401
+ Each confirm also sends `X-OneAddress-Client: partner-sdk-ts/<version>`, which names this SDK and its version and nothing about you or your customers. The partner portal's Webhook screen uses it to show when an update exists.
1402
+
1403
+ We recommend against auto-updating a receiver. The guide linked above covers upgrading and rolling back.
1404
+
1370
1405
  ## Licence
1371
1406
 
1372
1407
  Apache License 2.0. See [LICENSE](./LICENSE).
@@ -3901,6 +3901,11 @@ function isFreshTimestamp(timestampHeader, toleranceSecs = DEFAULT_REPLAY_WINDOW
3901
3901
  return Math.abs(now - ts) <= toleranceSecs;
3902
3902
  }
3903
3903
 
3904
+ // ../crypto/src/refund-review-notify.ts
3905
+ function refundReviewNotifySigningString(timestamp, rawBody) {
3906
+ return `oneaddress.refund-review-notify.v1.${timestamp}.${rawBody}`;
3907
+ }
3908
+
3904
3909
  // ../crypto/src/safe-url.ts
3905
3910
  var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
3906
3911
  "localhost",
@@ -4258,18 +4263,49 @@ async function verifyPartnerKeyAttestationWithRoots(input, signatureHex, rootKey
4258
4263
  }
4259
4264
 
4260
4265
  // ../crypto/src/registry-root-pin.ts
4261
- var PINNED_REGISTRY_ROOTS = Object.freeze([
4262
- Object.freeze({
4263
- root_key_id: "rk1_251368ec9b0a84ae",
4264
- spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4265
- })
4266
+ var PRODUCTION_REGISTRY_HOSTS = Object.freeze([
4267
+ "oneaddress.io",
4268
+ "www.oneaddress.io",
4269
+ "app.oneaddress.io"
4266
4270
  ]);
4271
+ function registryEnvironmentForOrigin(origin) {
4272
+ let o = origin ?? "";
4273
+ if (!o) {
4274
+ const loc = globalThis.location;
4275
+ o = loc?.origin ?? "";
4276
+ }
4277
+ if (!o) return "preview";
4278
+ try {
4279
+ const host = new URL(o).hostname.toLowerCase().replace(/\.$/, "");
4280
+ return PRODUCTION_REGISTRY_HOSTS.includes(host) ? "production" : "preview";
4281
+ } catch {
4282
+ return "preview";
4283
+ }
4284
+ }
4285
+ var PRODUCTION_ROOT = Object.freeze({
4286
+ root_key_id: "rk1_251368ec9b0a84ae",
4287
+ spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
4288
+ });
4289
+ var REGISTRY_ROOT_PINS = Object.freeze({
4290
+ production: Object.freeze([PRODUCTION_ROOT]),
4291
+ preview: Object.freeze([
4292
+ Object.freeze({
4293
+ root_key_id: "rk1_4690d67464893d48",
4294
+ spki_sha256: "4690d67464893d48ebb335bcd29f3203fbacefbc69afd8a047b639521296bfab"
4295
+ })
4296
+ ])
4297
+ });
4298
+ var PINNED_REGISTRY_ROOTS = REGISTRY_ROOT_PINS.production;
4267
4299
  var overrideForTests = null;
4268
4300
  function __setPinnedRegistryRootsForTests(pins) {
4269
4301
  overrideForTests = pins;
4270
4302
  }
4271
- function pinnedRegistryRoots() {
4272
- return overrideForTests ?? PINNED_REGISTRY_ROOTS;
4303
+ function pinnedRegistryRoots(env = "production") {
4304
+ if (overrideForTests) {
4305
+ if (Array.isArray(overrideForTests)) return overrideForTests;
4306
+ return overrideForTests[env] ?? [];
4307
+ }
4308
+ return REGISTRY_ROOT_PINS[env];
4273
4309
  }
4274
4310
  function b64ToBytes2(b64) {
4275
4311
  const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
@@ -4282,20 +4318,20 @@ async function spkiSha256HexFromB64(spkiB64) {
4282
4318
  const digest = await crypto.subtle.digest("SHA-256", b64ToBytes2(spkiB64));
4283
4319
  return bytesToHex3(new Uint8Array(digest));
4284
4320
  }
4285
- async function rootIsPinned(root) {
4321
+ async function rootIsPinned(root, env = "production") {
4286
4322
  try {
4287
4323
  const digest = await spkiSha256HexFromB64(root.public_key_b64);
4288
- return pinnedRegistryRoots().some(
4324
+ return pinnedRegistryRoots(env).some(
4289
4325
  (p) => p.root_key_id === root.root_key_id && p.spki_sha256 === digest
4290
4326
  );
4291
4327
  } catch {
4292
4328
  return false;
4293
4329
  }
4294
4330
  }
4295
- async function unpinnedRootIds(roots) {
4331
+ async function unpinnedRootIds(roots, env = "production") {
4296
4332
  const out = [];
4297
4333
  for (const root of roots) {
4298
- if (!await rootIsPinned(root)) out.push(String(root?.root_key_id ?? "(no id)"));
4334
+ if (!await rootIsPinned(root, env)) out.push(String(root?.root_key_id ?? "(no id)"));
4299
4335
  }
4300
4336
  return out;
4301
4337
  }
@@ -4482,6 +4518,30 @@ async function headNamesStagedKey(doc, partnerId, keyId, publicKeyB64) {
4482
4518
  // ../crypto/src/verify-partner-keys.ts
4483
4519
  var ACCEPTABLE = /* @__PURE__ */ new Set(["ok", "exempt"]);
4484
4520
  var EMPTY_BOUND = /* @__PURE__ */ new Set();
4521
+ function localStorageHeadHighWater(key = "oa-registry-head-issued-at") {
4522
+ return {
4523
+ read() {
4524
+ try {
4525
+ return globalThis.localStorage?.getItem(key) ?? null;
4526
+ } catch {
4527
+ return null;
4528
+ }
4529
+ },
4530
+ write(issuedAt) {
4531
+ try {
4532
+ globalThis.localStorage?.setItem(key, issuedAt);
4533
+ } catch {
4534
+ }
4535
+ }
4536
+ };
4537
+ }
4538
+ function isOlderThan(candidate, mark) {
4539
+ if (!mark) return false;
4540
+ const m = Date.parse(mark);
4541
+ const c = Date.parse(candidate);
4542
+ if (Number.isNaN(m)) return false;
4543
+ return Number.isNaN(c) || c < m;
4544
+ }
4485
4545
  async function saysRootNotConfigured(res) {
4486
4546
  if (res.status !== 503) return false;
4487
4547
  try {
@@ -4517,19 +4577,61 @@ async function crossoverOutcomeFor(partnerId, crossover, reg) {
4517
4577
  if (!reg.head) return "head-unusable";
4518
4578
  return await headNamesStagedKey(reg.head, partnerId, crossover.key_id, crossover.public_key_b64) ? "ok" : "not-authorised";
4519
4579
  }
4580
+ function refuseAll(keys, outcome) {
4581
+ const blocked = {};
4582
+ const crossoverBlocked = {};
4583
+ try {
4584
+ for (const [partnerId, key] of Object.entries(keys ?? {})) {
4585
+ blocked[partnerId] = outcome;
4586
+ if (key?.crossover) crossoverBlocked[partnerId] = "head-unusable";
4587
+ }
4588
+ } catch {
4589
+ }
4590
+ return { blocked, crossoverBlocked };
4591
+ }
4520
4592
  function createPartnerKeyVerifier(env = {}) {
4521
4593
  const baseUrl = env.baseUrl ?? "";
4522
- const report = env.report ?? (() => {
4523
- });
4594
+ const report = (context, detail) => {
4595
+ try {
4596
+ env.report?.(context, detail);
4597
+ } catch {
4598
+ }
4599
+ };
4524
4600
  let registryPromise = null;
4525
4601
  function worthCaching(load) {
4526
4602
  return load.ok && load.registry.head !== null;
4527
4603
  }
4604
+ async function readMark() {
4605
+ try {
4606
+ const v = await env.headHighWater?.read();
4607
+ return typeof v === "string" ? v : null;
4608
+ } catch {
4609
+ return null;
4610
+ }
4611
+ }
4612
+ async function writeMark(issuedAt) {
4613
+ try {
4614
+ await env.headHighWater?.write(issuedAt);
4615
+ } catch {
4616
+ }
4617
+ }
4618
+ async function judgeHead(headRes, roots) {
4619
+ if (!headRes.ok) return { head: null, headVerdict: "absent" };
4620
+ let head;
4621
+ try {
4622
+ head = await headRes.json();
4623
+ } catch {
4624
+ return { head: null, headVerdict: "unreadable" };
4625
+ }
4626
+ const headVerdict = await verifyRegistryHead(head, roots);
4627
+ return headVerdict === "ok" ? { head, headVerdict } : { head: null, headVerdict };
4628
+ }
4528
4629
  async function loadRegistry() {
4529
4630
  try {
4631
+ const headUrl = baseUrl + "/.well-known/oneaddress-key-registry-head.json";
4530
4632
  const [rootsRes, headRes] = await Promise.all([
4531
4633
  fetch(baseUrl + "/.well-known/oneaddress-key-registry.json", { cache: "no-cache" }),
4532
- fetch(baseUrl + "/.well-known/oneaddress-key-registry-head.json", { cache: "no-cache" })
4634
+ fetch(headUrl, { cache: "no-cache" })
4533
4635
  ]);
4534
4636
  if (!rootsRes.ok) {
4535
4637
  const configured = await saysRootNotConfigured(rootsRes);
@@ -4551,16 +4653,30 @@ function createPartnerKeyVerifier(env = {}) {
4551
4653
  if (roots.length === 0) {
4552
4654
  return { ok: false, failure: { reason: "roots-empty", status: rootsRes.status } };
4553
4655
  }
4554
- const unpinnedRoots = await unpinnedRootIds(roots);
4656
+ const unpinnedRoots = await unpinnedRootIds(roots, registryEnvironmentForOrigin(baseUrl));
4555
4657
  if (unpinnedRoots.length > 0) {
4556
4658
  return { ok: true, registry: { roots: [], head: null, headVerdict: "root-unpinned", unpinnedRoots } };
4557
4659
  }
4558
- let head = null;
4559
- let headVerdict = "absent";
4560
- if (headRes.ok) {
4561
- head = await headRes.json();
4562
- headVerdict = await verifyRegistryHead(head, roots);
4563
- if (headVerdict !== "ok" && headVerdict !== "expired") head = null;
4660
+ let { head, headVerdict } = await judgeHead(headRes, roots);
4661
+ if (head) {
4662
+ const mark = await readMark();
4663
+ if (isOlderThan(head.issued_at, mark)) {
4664
+ let fresh = { head: null, headVerdict: "absent" };
4665
+ try {
4666
+ fresh = await judgeHead(
4667
+ await fetch(`${headUrl}?fresh=${Date.now()}`, { cache: "reload" }),
4668
+ roots
4669
+ );
4670
+ } catch {
4671
+ }
4672
+ if (fresh.head && !isOlderThan(fresh.head.issued_at, mark)) {
4673
+ ({ head, headVerdict } = fresh);
4674
+ } else {
4675
+ head = null;
4676
+ headVerdict = "rolled-back";
4677
+ }
4678
+ }
4679
+ if (head && head.issued_at !== mark) await writeMark(head.issued_at);
4564
4680
  }
4565
4681
  return { ok: true, registry: { roots, head, headVerdict, unpinnedRoots: [] } };
4566
4682
  } catch {
@@ -4573,8 +4689,8 @@ function createPartnerKeyVerifier(env = {}) {
4573
4689
  const load = await pending;
4574
4690
  if (!worthCaching(load)) registryPromise = null;
4575
4691
  if (!load.ok) {
4576
- report(context, { registry: "unavailable", enforced: false, ...load.failure });
4577
- return { blocked: {}, crossoverBlocked: {} };
4692
+ report(context, { registry: "unavailable", enforced: true, ...load.failure });
4693
+ return refuseAll(keys, "registry-unavailable");
4578
4694
  }
4579
4695
  const reg = load.registry;
4580
4696
  let bound = EMPTY_BOUND;
@@ -4595,6 +4711,7 @@ function createPartnerKeyVerifier(env = {}) {
4595
4711
  "not-in-head": [],
4596
4712
  "head-unusable": [],
4597
4713
  "root-unpinned": [],
4714
+ "registry-unavailable": [],
4598
4715
  "error": []
4599
4716
  };
4600
4717
  const blocked = {};
@@ -4646,8 +4763,8 @@ function createPartnerKeyVerifier(env = {}) {
4646
4763
  }
4647
4764
  return { blocked, crossoverBlocked };
4648
4765
  } catch {
4649
- report(context, { registry: "verifier-error", enforced: false });
4650
- return { blocked: {}, crossoverBlocked: {} };
4766
+ report(context, { registry: "verifier-error", enforced: true });
4767
+ return refuseAll(keys, "error");
4651
4768
  }
4652
4769
  }
4653
4770
  function __resetRegistryCacheForTests() {
@@ -5461,6 +5578,7 @@ async function verifyWebhookSignature(payload, signature, secret) {
5461
5578
  export {
5462
5579
  DEFAULT_REPLAY_WINDOW_SECS,
5463
5580
  isFreshTimestamp,
5581
+ refundReviewNotifySigningString,
5464
5582
  isIpLiteralHost,
5465
5583
  isSafeWebhookUrl,
5466
5584
  blockedPublicKeyReason,
@@ -5477,6 +5595,9 @@ export {
5477
5595
  rootKeyIdFromSpkiB64,
5478
5596
  verifyPartnerKeyAttestation,
5479
5597
  verifyPartnerKeyAttestationWithRoots,
5598
+ PRODUCTION_REGISTRY_HOSTS,
5599
+ registryEnvironmentForOrigin,
5600
+ REGISTRY_ROOT_PINS,
5480
5601
  PINNED_REGISTRY_ROOTS,
5481
5602
  __setPinnedRegistryRootsForTests,
5482
5603
  pinnedRegistryRoots,
@@ -5492,6 +5613,7 @@ export {
5492
5613
  headNamesPartner,
5493
5614
  partnerKeyFingerprint,
5494
5615
  headNamesStagedKey,
5616
+ localStorageHeadHighWater,
5495
5617
  createPartnerKeyVerifier,
5496
5618
  PARTNER_KEY_REFUSED_MESSAGE,
5497
5619
  SENDER_HELD_KEY_ALGORITHM,