@oneaddress/partner-sdk 2.4.1 → 2.5.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,6 +7,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.5.0] - 2026-10-14
11
+
12
+ ### Changed
13
+
14
+ - **A key you do not hold no longer answers the same as your database being
15
+ down.** The handler holds one key and never looks one up, so a dispatch
16
+ sealed to a key it does not hold reached `decryptSession`, failed inside
17
+ AES-GCM tag verification, and fell through to the catch-all:
18
+ `500 {"error":"Internal handler error"}`. That is also this SDK's answer for
19
+ a database outage, a bug in your own `onUpdate`, and a missing LOA key, so
20
+ neither you nor OneAddress could tell them apart. OneAddress stores that body
21
+ verbatim, which means the one record that would have named a key mismatch
22
+ said nothing.
23
+
24
+ Two refusals now, because only one of them is yours to fix:
25
+
26
+ - `503` with `{"error":"missing_key","key_id":"..."}` when the dispatch names
27
+ a `key_id` that is not the one you configured. Refused before any crypto
28
+ runs, and retryable: installing the key fixes it. Only possible when you
29
+ pass the `keyId` option, since without it the SDK cannot know which key it
30
+ holds.
31
+ - `422` with `{"error":"decrypt_failed","detail":"..."}` when the unwrap
32
+ itself fails. Ambiguous by nature (wrong key, wrong `partner_id`, tampered
33
+ or truncated ciphertext), so it says so rather than guessing, and `detail`
34
+ carries the underlying message. An algorithm downgrade and a key-source
35
+ capability refusal still name themselves there rather than being relabelled
36
+ as a key problem.
37
+
38
+ Both still write the same `console.error` line they always did. The response
39
+ is for OneAddress; the log is for you.
40
+
41
+ **If you monitor on status codes, this is the change to read.** A receiver
42
+ that treated 500 as the signal for an undecryptable dispatch will now see 503
43
+ or 422. Nothing about the envelope, the wire format or the crypto changed.
44
+
45
+ This is the behaviour the drop-in receiver has had since it was written, so
46
+ the two now agree.
47
+
48
+ ### Fixed
49
+
50
+ - **The `decryptSession` docstring described a record we do not keep.** It said
51
+ a destroyed retired key is recorded on the OneAddress side as a
52
+ `partner_key_custody_failure` outcome on the reconstruction audit log. No such
53
+ outcome and no such log exist. Destroying a retired key before your configured
54
+ retention window closes is still a key-custody breach under the partner terms,
55
+ which is unchanged; what was wrong was the claim about what we record.
56
+
57
+ - **The same docstring called the retention window "90-day".** It is the window
58
+ you configure, with a 14 day minimum, and the authoritative horizon for any
59
+ key is its own `destroy_after` date. 90 is a column default. A partner on 14
60
+ days would have over-retained; one on 365 would have destroyed early.
61
+
10
62
  ## [2.4.1] - 2026-10-06
11
63
 
12
64
  ### Fixed
@@ -3,7 +3,7 @@ import {
3
3
  encryptSessionForPartner,
4
4
  isFreshTimestamp,
5
5
  isSafeWebhookUrl
6
- } from "./chunk-FDMB4BNC.mjs";
6
+ } from "./chunk-ZY2K54LD.mjs";
7
7
 
8
8
  // src/index.ts
9
9
  import crypto from "crypto";
@@ -501,7 +501,7 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
501
501
  return JSON.parse(new TextDecoder().decode(plaintext));
502
502
  }
503
503
  async function decryptSession(share, envelopeB64, privateKeyPem, partnerId, expectedAlg) {
504
- const { decryptSession: decryptSessionCrypto } = await import("./src-SNMMZ4BT.mjs");
504
+ const { decryptSession: decryptSessionCrypto } = await import("./src-RBLFVBGY.mjs");
505
505
  return decryptSessionCrypto(
506
506
  share,
507
507
  envelopeB64,
@@ -909,6 +909,21 @@ var InvalidUpdateTypesError = class extends Error {
909
909
  this.name = "InvalidUpdateTypesError";
910
910
  }
911
911
  };
912
+ var MissingKeyError = class extends Error {
913
+ constructor(keyId) {
914
+ super(`[OneAddress SDK] no private key for key_id ${keyId}`);
915
+ this.keyId = keyId;
916
+ this.name = "MissingKeyError";
917
+ }
918
+ };
919
+ var SessionDecryptError = class extends Error {
920
+ constructor(keyId, detail) {
921
+ super(`[OneAddress SDK] session decrypt failed${keyId ? ` for key_id ${keyId}` : ""}`);
922
+ this.keyId = keyId;
923
+ this.detail = detail;
924
+ this.name = "SessionDecryptError";
925
+ }
926
+ };
912
927
  function requireContactValue(kind, value) {
913
928
  if (typeof value !== "string" || value === "") {
914
929
  throw new Error(
@@ -1026,7 +1041,14 @@ function createOneAddressHandler(options) {
1026
1041
  }
1027
1042
  async function buildD5Pieces(body, partnerId) {
1028
1043
  const share = body.session_key_share;
1029
- const data = await decryptSession(share, body.session_envelope, privateKeyPem, partnerId, expectedAlg);
1044
+ const shareKeyId = typeof share?.key_id === "string" ? share.key_id : "";
1045
+ if (keyId && shareKeyId && shareKeyId !== keyId) throw new MissingKeyError(shareKeyId);
1046
+ let data;
1047
+ try {
1048
+ data = await decryptSession(share, body.session_envelope, privateKeyPem, partnerId, expectedAlg);
1049
+ } catch (err) {
1050
+ throw new SessionDecryptError(shareKeyId, err instanceof Error ? err.message : String(err));
1051
+ }
1030
1052
  const updateTypes = readUpdateTypes(data.update_types);
1031
1053
  if (updateTypes === null) throw new InvalidUpdateTypesError(data.update_types);
1032
1054
  const address = updateTypes.includes("address") ? validateAddress({
@@ -1159,6 +1181,22 @@ function createOneAddressHandler(options) {
1159
1181
  detail: "update_types must be an array of " + UPDATE_TYPE_ORDER.join("|") + ". A name this build does not know was refused rather than dropped. Update @oneaddress/partner-sdk."
1160
1182
  });
1161
1183
  }
1184
+ if (err instanceof MissingKeyError) {
1185
+ console.error("[OneAddress SDK] Handler error:", err.message);
1186
+ return declared(503, {
1187
+ error: "missing_key",
1188
+ key_id: err.keyId,
1189
+ detail: "This receiver is configured for a different key_id and holds no private key for the one this dispatch names. Retry once the key is installed. If the key was retired and destroyed before its destroy_after date, it cannot be recovered from either side."
1190
+ });
1191
+ }
1192
+ if (err instanceof SessionDecryptError) {
1193
+ console.error("[OneAddress SDK] Handler error:", err.detail);
1194
+ return declared(422, {
1195
+ error: "decrypt_failed",
1196
+ ...err.keyId ? { key_id: err.keyId } : {},
1197
+ detail: err.detail
1198
+ });
1199
+ }
1162
1200
  throw err;
1163
1201
  }
1164
1202
  const notAccepted = d5.updateTypes.filter((t) => !acceptedUpdateTypes.includes(t));