@oneaddress/partner-sdk 2.6.0 → 2.7.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.
@@ -5,7 +5,7 @@ import {
5
5
  isFreshTimestamp,
6
6
  isSafeWebhookUrl,
7
7
  verifyRegistryHead
8
- } from "./chunk-QAOGKPD3.mjs";
8
+ } from "./chunk-CLV6TLSP.mjs";
9
9
 
10
10
  // src/index.ts
11
11
  import crypto from "crypto";
@@ -47,10 +47,12 @@ var D5_BODY_CONDITIONAL = {
47
47
  crossover_key_ids: "key-crossover copy only"
48
48
  };
49
49
  var D5_BODY_DRILL_ONLY = ["conformance"];
50
+ var D5_BODY_ADDED_AT_SEND = ["dispatch_id"];
50
51
  var D5_BODY_ALL_ALLOWED = [
51
52
  ...D5_BODY_ALWAYS,
52
53
  ...Object.keys(D5_BODY_CONDITIONAL),
53
- ...D5_BODY_DRILL_ONLY
54
+ ...D5_BODY_DRILL_ONLY,
55
+ ...D5_BODY_ADDED_AT_SEND
54
56
  ];
55
57
 
56
58
  // ../protocol/src/retention.ts
@@ -71,6 +73,12 @@ function keyShareExpiryIso(dispatchAt, retentionPeriodDays) {
71
73
  return new Date(dispatchAt.getTime() + days * DAY_MS).toISOString();
72
74
  }
73
75
 
76
+ // ../protocol/src/pull-signature.ts
77
+ var PULL_SIGNATURE_VERSION_HEADER = "X-OneAddress-Signature-Version";
78
+ function pullSigningStringV2(timestamp, method, pathAndQuery, body = "") {
79
+ return `v2.${timestamp}.${method.toUpperCase()}.${pathAndQuery}.${body}`;
80
+ }
81
+
74
82
  // src/app-hosts.ts
75
83
  function allowedAppHosts() {
76
84
  const hosts = ["oneaddress.io", "app.oneaddress.io"];
@@ -670,6 +678,7 @@ function createSqlIdempotencyStore(opts) {
670
678
  }
671
679
  function verifySignature(rawBody, signature, timestamp, secret) {
672
680
  if (!/^[0-9a-f]{64}$/i.test(signature)) return false;
681
+ if (!secret) return false;
673
682
  const sigPayload = `${timestamp}.${rawBody}`;
674
683
  const expected = crypto.createHmac("sha256", secret).update(sigPayload).digest("hex");
675
684
  const sigBuffer = Buffer.from(signature, "hex");
@@ -677,6 +686,17 @@ function verifySignature(rawBody, signature, timestamp, secret) {
677
686
  if (sigBuffer.length !== expBuffer.length) return false;
678
687
  return crypto.timingSafeEqual(sigBuffer, expBuffer);
679
688
  }
689
+ function signPullRequest(opts) {
690
+ if (!opts.secret) throw new Error("signPullRequest: secret is required");
691
+ const u = new URL(opts.url);
692
+ const ts = String(opts.timestamp ?? Math.floor(Date.now() / 1e3));
693
+ const signature = crypto.createHmac("sha256", opts.secret).update(pullSigningStringV2(ts, opts.method ?? "GET", `${u.pathname}${u.search}`, opts.body ?? "")).digest("hex");
694
+ return {
695
+ "X-OneAddress-Timestamp": ts,
696
+ "X-OneAddress-Signature": signature,
697
+ [PULL_SIGNATURE_VERSION_HEADER]: "2"
698
+ };
699
+ }
680
700
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
681
701
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
682
702
  if (previousSecret && previousSecret !== currentSecret && graceUntil) {
@@ -752,7 +772,7 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
752
772
  return JSON.parse(new TextDecoder().decode(plaintext));
753
773
  }
754
774
  async function decryptSession(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
755
- const { decryptSession: decryptSessionCrypto } = await import("./src-BPES2DKY.mjs");
775
+ const { decryptSession: decryptSessionCrypto } = await import("./src-FPYBM6X6.mjs");
756
776
  return decryptSessionCrypto(
757
777
  share,
758
778
  envelopeB64,
@@ -1363,14 +1383,22 @@ function createOneAddressHandler(options) {
1363
1383
  }
1364
1384
  const partnerId = body.partner_id ?? "";
1365
1385
  const tsNum = Number(tsHeader);
1366
- const dispatchId = req.headers.get("x-oneaddress-dispatch") ?? "";
1386
+ const headerDispatchId = req.headers.get("x-oneaddress-dispatch") ?? "";
1387
+ const bodyDispatchId = typeof body.dispatch_id === "string" ? body.dispatch_id : "";
1388
+ if (bodyDispatchId && headerDispatchId && bodyDispatchId !== headerDispatchId) {
1389
+ return new Response(JSON.stringify({ error: "dispatch_id_mismatch" }), {
1390
+ status: 400,
1391
+ headers: { "Content-Type": "application/json" }
1392
+ });
1393
+ }
1394
+ const dispatchId = bodyDispatchId || headerDispatchId;
1367
1395
  if (isCrossoverSiblingToSkip(body)) {
1368
1396
  return declared(200, { ok: true, skipped: true, crossover: true });
1369
1397
  }
1370
1398
  if (dispatchId) {
1371
1399
  if (!idempotencyStore) {
1372
1400
  const nodeEnv = typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
1373
- if (nodeEnv === "test") {
1401
+ if (nodeEnv === "test" && headerDispatchId) {
1374
1402
  throw new Error(
1375
1403
  "[OneAddress SDK] idempotencyStore is required in test mode when X-OneAddress-Dispatch is present. Wire up an idempotencyStore to prevent double-processing on retry."
1376
1404
  );
@@ -1850,6 +1878,7 @@ export {
1850
1878
  checkRegistryHead,
1851
1879
  createSqlIdempotencyStore,
1852
1880
  verifySignature,
1881
+ signPullRequest,
1853
1882
  verifyWithGrace,
1854
1883
  decryptAddress,
1855
1884
  decryptSession,