@oneaddress/partner-sdk 1.1.0 → 1.1.1

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/README.md CHANGED
@@ -60,6 +60,10 @@ async onUpdate(event) {
60
60
 
61
61
  `dispatchId` falls back to `''` (empty string) if the header is absent — always guard before using it as a key.
62
62
 
63
+ > **At-least-once delivery:** The dispatch ID is recorded *after* `onUpdate` succeeds. This means if your process crashes between a successful `onUpdate` and the ID being stored, the same event will be delivered again on retry. This is intentional — the alternative (recording before processing) risks silently dropping updates if `onUpdate` fails.
64
+ >
65
+ > **Recommendation:** Make your database write idempotent (e.g. `INSERT … ON CONFLICT DO UPDATE`) rather than relying solely on the dispatchId check. That way a duplicate delivery is harmless even if the ID was never recorded.
66
+
63
67
  ---
64
68
 
65
69
  ## Secret rotation grace window
@@ -142,6 +146,7 @@ import {
142
146
  verifySignature, // single-secret HMAC verify
143
147
  verifyWithGrace, // two-secret grace-window verify
144
148
  decryptAddress, // ECDH + HKDF + AES-GCM decryption
149
+ transformAddress, // decrypt then re-encrypt to a different public key (e.g. KMS)
145
150
  isFreshTimestamp, // ±5-minute replay-window check
146
151
  CURRENT_VERSION, // '2026.1'
147
152
  SUPPORTED_VERSIONS, // ['2026.1']
@@ -160,6 +165,27 @@ Returns `true` if `timestamp` (Unix seconds string) is within `toleranceSecs` of
160
165
 
161
166
  Decrypts the `address_encrypted` blob using your PKCS#8 ECDH P-256 private key.
162
167
 
168
+ ### `transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem)`
169
+
170
+ Decrypts a OneAddress payload and immediately re-encrypts it to a different ECDH P-256 public key — for example, your internal KMS or HSM. The plaintext address is held in memory only for the duration of the call and is never returned to the caller.
171
+
172
+ ```typescript
173
+ import { transformAddress } from '@oneaddress/partner-sdk';
174
+
175
+ async onUpdate(event) {
176
+ // Re-encrypt to your KMS key — plaintext never leaves this function
177
+ const kmsBlob = await transformAddress(
178
+ event.raw.address_encrypted as EncryptedPayload,
179
+ process.env.OA_PRIVATE_KEY_PEM!,
180
+ event.partner_id,
181
+ process.env.KMS_PUBLIC_KEY_SPKI_PEM!, // your KMS/HSM SPKI PEM public key
182
+ );
183
+ await db.storeEncryptedAddress(event.customer.email, kmsBlob);
184
+ }
185
+ ```
186
+
187
+ Each call generates a fresh ephemeral key pair and random HKDF salt — full forward secrecy, no shared state between calls.
188
+
163
189
  ---
164
190
 
165
191
  ## Protocol versioning
@@ -27,7 +27,7 @@ function verifySignature(rawBody, signature, timestamp, secret) {
27
27
  }
28
28
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
29
29
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
30
- if (previousSecret && graceUntil) {
30
+ if (previousSecret && previousSecret !== currentSecret && graceUntil) {
31
31
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
32
32
  if (!Number.isNaN(until) && Date.now() < until) {
33
33
  return verifySignature(rawBody, signature, timestamp, previousSecret);
@@ -63,7 +63,18 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
63
63
  256
64
64
  );
65
65
  const hkdfKey = await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
66
- const salt = hkdfSalt ? base64urlToBuffer(hkdfSalt) : new Uint8Array(0);
66
+ let salt;
67
+ if (hkdfSalt) {
68
+ const saltBytes = base64urlToBuffer(hkdfSalt);
69
+ if (saltBytes.byteLength !== 32) {
70
+ throw new Error(
71
+ `[OneAddress SDK] hkdfSalt must be 32 bytes, received ${saltBytes.byteLength}. This may indicate a protocol version mismatch or a tampered payload.`
72
+ );
73
+ }
74
+ salt = saltBytes;
75
+ } else {
76
+ salt = new Uint8Array(0);
77
+ }
67
78
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
68
79
  const aesKeyBits = await crypto.subtle.deriveBits(
69
80
  { name: "HKDF", hash: "SHA-256", salt, info },
@@ -100,7 +111,7 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
100
111
  );
101
112
  const hkdfSaltBytes = crypto.getRandomValues(new Uint8Array(32));
102
113
  const hkdfKey = await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
103
- const info = new TextEncoder().encode(`oneaddress:transform`);
114
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
104
115
  const aesKeyBits = await crypto.subtle.deriveBits(
105
116
  { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
106
117
  hkdfKey,
package/dist/edge.js CHANGED
@@ -74,7 +74,7 @@ function verifySignature(rawBody, signature, timestamp, secret) {
74
74
  }
75
75
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
76
76
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
77
- if (previousSecret && graceUntil) {
77
+ if (previousSecret && previousSecret !== currentSecret && graceUntil) {
78
78
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
79
79
  if (!Number.isNaN(until) && Date.now() < until) {
80
80
  return verifySignature(rawBody, signature, timestamp, previousSecret);
@@ -110,7 +110,18 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
110
110
  256
111
111
  );
112
112
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
113
- const salt = hkdfSalt ? base64urlToBuffer(hkdfSalt) : new Uint8Array(0);
113
+ let salt;
114
+ if (hkdfSalt) {
115
+ const saltBytes = base64urlToBuffer(hkdfSalt);
116
+ if (saltBytes.byteLength !== 32) {
117
+ throw new Error(
118
+ `[OneAddress SDK] hkdfSalt must be 32 bytes, received ${saltBytes.byteLength}. This may indicate a protocol version mismatch or a tampered payload.`
119
+ );
120
+ }
121
+ salt = saltBytes;
122
+ } else {
123
+ salt = new Uint8Array(0);
124
+ }
114
125
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
115
126
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
116
127
  { name: "HKDF", hash: "SHA-256", salt, info },
@@ -147,7 +158,7 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
147
158
  );
148
159
  const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
149
160
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
150
- const info = new TextEncoder().encode(`oneaddress:transform`);
161
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
151
162
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
152
163
  { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
153
164
  hkdfKey,
package/dist/edge.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  verifyLOA,
12
12
  verifySignature,
13
13
  verifyWithGrace
14
- } from "./chunk-BCAOUGA6.mjs";
14
+ } from "./chunk-ZZZLXF6X.mjs";
15
15
  export {
16
16
  CURRENT_VERSION,
17
17
  DEFAULT_REPLAY_WINDOW_SECS,
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ function verifySignature(rawBody, signature, timestamp, secret) {
76
76
  }
77
77
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
78
78
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
79
- if (previousSecret && graceUntil) {
79
+ if (previousSecret && previousSecret !== currentSecret && graceUntil) {
80
80
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
81
81
  if (!Number.isNaN(until) && Date.now() < until) {
82
82
  return verifySignature(rawBody, signature, timestamp, previousSecret);
@@ -112,7 +112,18 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
112
112
  256
113
113
  );
114
114
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
115
- const salt = hkdfSalt ? base64urlToBuffer(hkdfSalt) : new Uint8Array(0);
115
+ let salt;
116
+ if (hkdfSalt) {
117
+ const saltBytes = base64urlToBuffer(hkdfSalt);
118
+ if (saltBytes.byteLength !== 32) {
119
+ throw new Error(
120
+ `[OneAddress SDK] hkdfSalt must be 32 bytes, received ${saltBytes.byteLength}. This may indicate a protocol version mismatch or a tampered payload.`
121
+ );
122
+ }
123
+ salt = saltBytes;
124
+ } else {
125
+ salt = new Uint8Array(0);
126
+ }
116
127
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
117
128
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
118
129
  { name: "HKDF", hash: "SHA-256", salt, info },
@@ -149,7 +160,7 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
149
160
  );
150
161
  const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
151
162
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
152
- const info = new TextEncoder().encode(`oneaddress:transform`);
163
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
153
164
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
154
165
  { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
155
166
  hkdfKey,
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  verifyLOA,
12
12
  verifySignature,
13
13
  verifyWithGrace
14
- } from "./chunk-BCAOUGA6.mjs";
14
+ } from "./chunk-ZZZLXF6X.mjs";
15
15
  export {
16
16
  CURRENT_VERSION,
17
17
  DEFAULT_REPLAY_WINDOW_SECS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaddress/partner-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Official OneAddress partner integration SDK — webhook verification, address decryption, LOA validation",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",