@oneaddress/partner-sdk 1.0.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 },
@@ -78,6 +89,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
78
89
  );
79
90
  return JSON.parse(new TextDecoder().decode(plaintext));
80
91
  }
92
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
93
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
94
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
95
+ const recipientKey = await crypto.subtle.importKey(
96
+ "spki",
97
+ pemToBuffer(recipientSpkiPem),
98
+ { name: "ECDH", namedCurve: "P-256" },
99
+ false,
100
+ []
101
+ );
102
+ const ephemeralPair = await crypto.subtle.generateKey(
103
+ { name: "ECDH", namedCurve: "P-256" },
104
+ true,
105
+ ["deriveBits"]
106
+ );
107
+ const sharedBits = await crypto.subtle.deriveBits(
108
+ { name: "ECDH", public: recipientKey },
109
+ ephemeralPair.privateKey,
110
+ 256
111
+ );
112
+ const hkdfSaltBytes = crypto.getRandomValues(new Uint8Array(32));
113
+ const hkdfKey = await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
114
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
115
+ const aesKeyBits = await crypto.subtle.deriveBits(
116
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
117
+ hkdfKey,
118
+ 256
119
+ );
120
+ const aesKey = await crypto.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
121
+ const ivBytes = crypto.getRandomValues(new Uint8Array(12));
122
+ const ciphertextBuf = await crypto.subtle.encrypt(
123
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
124
+ aesKey,
125
+ plaintextBytes
126
+ );
127
+ const ephemeralPublicKeyRaw = await crypto.subtle.exportKey("raw", ephemeralPair.publicKey);
128
+ return {
129
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
130
+ iv: Buffer.from(ivBytes).toString("base64"),
131
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
132
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
133
+ };
134
+ }
81
135
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
82
136
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
83
137
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -297,6 +351,7 @@ export {
297
351
  verifySignature,
298
352
  verifyWithGrace,
299
353
  decryptAddress,
354
+ transformAddress,
300
355
  fetchLoaPublicKey,
301
356
  verifyLOA,
302
357
  validateAddress,
package/dist/edge.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
1
+ export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, transform as transformAddress, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
2
2
  export { CURRENT_VERSION, SUPPORTED_VERSIONS } from '@oneaddress/protocol';
3
3
  export { DEFAULT_REPLAY_WINDOW_SECS, isFreshTimestamp } from '@oneaddress/crypto';
package/dist/edge.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';
1
+ export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, transform as transformAddress, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';
2
2
  export { CURRENT_VERSION, SUPPORTED_VERSIONS } from '@oneaddress/protocol';
3
3
  export { DEFAULT_REPLAY_WINDOW_SECS, isFreshTimestamp } from '@oneaddress/crypto';
package/dist/edge.js CHANGED
@@ -37,6 +37,7 @@ __export(edge_exports, {
37
37
  decryptAddress: () => decryptAddress,
38
38
  fetchLoaPublicKey: () => fetchLoaPublicKey,
39
39
  isFreshTimestamp: () => isFreshTimestamp,
40
+ transformAddress: () => transformAddress,
40
41
  validateAddress: () => validateAddress,
41
42
  verifyLOA: () => verifyLOA,
42
43
  verifySignature: () => verifySignature,
@@ -73,7 +74,7 @@ function verifySignature(rawBody, signature, timestamp, secret) {
73
74
  }
74
75
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
75
76
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
76
- if (previousSecret && graceUntil) {
77
+ if (previousSecret && previousSecret !== currentSecret && graceUntil) {
77
78
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
78
79
  if (!Number.isNaN(until) && Date.now() < until) {
79
80
  return verifySignature(rawBody, signature, timestamp, previousSecret);
@@ -109,7 +110,18 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
109
110
  256
110
111
  );
111
112
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
112
- 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
+ }
113
125
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
114
126
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
115
127
  { name: "HKDF", hash: "SHA-256", salt, info },
@@ -124,6 +136,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
124
136
  );
125
137
  return JSON.parse(new TextDecoder().decode(plaintext));
126
138
  }
139
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
140
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
141
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
142
+ const recipientKey = await import_crypto.default.subtle.importKey(
143
+ "spki",
144
+ pemToBuffer(recipientSpkiPem),
145
+ { name: "ECDH", namedCurve: "P-256" },
146
+ false,
147
+ []
148
+ );
149
+ const ephemeralPair = await import_crypto.default.subtle.generateKey(
150
+ { name: "ECDH", namedCurve: "P-256" },
151
+ true,
152
+ ["deriveBits"]
153
+ );
154
+ const sharedBits = await import_crypto.default.subtle.deriveBits(
155
+ { name: "ECDH", public: recipientKey },
156
+ ephemeralPair.privateKey,
157
+ 256
158
+ );
159
+ const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
160
+ const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
161
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
162
+ const aesKeyBits = await import_crypto.default.subtle.deriveBits(
163
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
164
+ hkdfKey,
165
+ 256
166
+ );
167
+ const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
168
+ const ivBytes = import_crypto.default.getRandomValues(new Uint8Array(12));
169
+ const ciphertextBuf = await import_crypto.default.subtle.encrypt(
170
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
171
+ aesKey,
172
+ plaintextBytes
173
+ );
174
+ const ephemeralPublicKeyRaw = await import_crypto.default.subtle.exportKey("raw", ephemeralPair.publicKey);
175
+ return {
176
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
177
+ iv: Buffer.from(ivBytes).toString("base64"),
178
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
179
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
180
+ };
181
+ }
127
182
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
128
183
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
129
184
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -343,6 +398,7 @@ function createOneAddressHandler(options) {
343
398
  decryptAddress,
344
399
  fetchLoaPublicKey,
345
400
  isFreshTimestamp,
401
+ transformAddress,
346
402
  validateAddress,
347
403
  verifyLOA,
348
404
  verifySignature,
package/dist/edge.mjs CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  decryptAddress,
7
7
  fetchLoaPublicKey,
8
8
  isFreshTimestamp,
9
+ transformAddress,
9
10
  validateAddress,
10
11
  verifyLOA,
11
12
  verifySignature,
12
13
  verifyWithGrace
13
- } from "./chunk-NBUGPU44.mjs";
14
+ } from "./chunk-ZZZLXF6X.mjs";
14
15
  export {
15
16
  CURRENT_VERSION,
16
17
  DEFAULT_REPLAY_WINDOW_SECS,
@@ -19,6 +20,7 @@ export {
19
20
  decryptAddress,
20
21
  fetchLoaPublicKey,
21
22
  isFreshTimestamp,
23
+ transformAddress,
22
24
  validateAddress,
23
25
  verifyLOA,
24
26
  verifySignature,
package/dist/index.d.mts CHANGED
@@ -219,6 +219,35 @@ declare function verifyWithGrace(rawBody: string, timestamp: string, signature:
219
219
  * @param partnerId - Your partner UUID (used as HKDF info string)
220
220
  */
221
221
  declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string): Promise<Record<string, unknown>>;
222
+ /**
223
+ * Decrypt a OneAddress payload and immediately re-encrypt it to a different
224
+ * ECDH P-256 public key — for example, your internal KMS or HSM public key.
225
+ *
226
+ * The plaintext address is held in memory only for the duration of this call
227
+ * and is never returned to the caller. This makes it suitable for pipelines
228
+ * where you want to store addresses in a secondary encrypted form without
229
+ * your application code ever seeing plaintext.
230
+ *
231
+ * **Typical use case:** you receive the OneAddress webhook, call `transformAddress`,
232
+ * and store the resulting ciphertext in your database. Decryption only happens
233
+ * inside your KMS/HSM, not in your application tier.
234
+ *
235
+ * @param payload - The `address_encrypted` object from the webhook body
236
+ * @param privateKeyPem - Your PKCS#8 PEM private key (OneAddress partner key)
237
+ * @param partnerId - Your partner UUID (used as HKDF info during decryption)
238
+ * @param recipientSpkiPem - SPKI PEM public key of the target recipient (e.g. KMS key)
239
+ * @returns A fresh `EncryptedPayload` encrypted to `recipientSpkiPem`
240
+ *
241
+ * @example
242
+ * const kmsBlob = await transformAddress(
243
+ * event.raw.address_encrypted as EncryptedPayload,
244
+ * process.env.OA_PRIVATE_KEY_PEM!,
245
+ * event.partner_id,
246
+ * process.env.KMS_PUBLIC_KEY_SPKI_PEM!,
247
+ * );
248
+ * await db.storeEncryptedAddress(event.customer.email, kmsBlob);
249
+ */
250
+ declare function transformAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
222
251
  /**
223
252
  * Fetch OneAddress's ECDSA P-256 LOA signing public key from the well-known endpoint.
224
253
  *
@@ -295,4 +324,4 @@ type HandlerResponse = Response;
295
324
  */
296
325
  declare function createOneAddressHandler(options: OneAddressHandlerOptions): (req: HandlerRequest) => Promise<HandlerResponse>;
297
326
 
298
- export { type EncryptedPayload, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, fetchLoaPublicKey, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
327
+ export { type EncryptedPayload, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, fetchLoaPublicKey, transformAddress as transform, transformAddress, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
package/dist/index.d.ts CHANGED
@@ -219,6 +219,35 @@ declare function verifyWithGrace(rawBody: string, timestamp: string, signature:
219
219
  * @param partnerId - Your partner UUID (used as HKDF info string)
220
220
  */
221
221
  declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string): Promise<Record<string, unknown>>;
222
+ /**
223
+ * Decrypt a OneAddress payload and immediately re-encrypt it to a different
224
+ * ECDH P-256 public key — for example, your internal KMS or HSM public key.
225
+ *
226
+ * The plaintext address is held in memory only for the duration of this call
227
+ * and is never returned to the caller. This makes it suitable for pipelines
228
+ * where you want to store addresses in a secondary encrypted form without
229
+ * your application code ever seeing plaintext.
230
+ *
231
+ * **Typical use case:** you receive the OneAddress webhook, call `transformAddress`,
232
+ * and store the resulting ciphertext in your database. Decryption only happens
233
+ * inside your KMS/HSM, not in your application tier.
234
+ *
235
+ * @param payload - The `address_encrypted` object from the webhook body
236
+ * @param privateKeyPem - Your PKCS#8 PEM private key (OneAddress partner key)
237
+ * @param partnerId - Your partner UUID (used as HKDF info during decryption)
238
+ * @param recipientSpkiPem - SPKI PEM public key of the target recipient (e.g. KMS key)
239
+ * @returns A fresh `EncryptedPayload` encrypted to `recipientSpkiPem`
240
+ *
241
+ * @example
242
+ * const kmsBlob = await transformAddress(
243
+ * event.raw.address_encrypted as EncryptedPayload,
244
+ * process.env.OA_PRIVATE_KEY_PEM!,
245
+ * event.partner_id,
246
+ * process.env.KMS_PUBLIC_KEY_SPKI_PEM!,
247
+ * );
248
+ * await db.storeEncryptedAddress(event.customer.email, kmsBlob);
249
+ */
250
+ declare function transformAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
222
251
  /**
223
252
  * Fetch OneAddress's ECDSA P-256 LOA signing public key from the well-known endpoint.
224
253
  *
@@ -295,4 +324,4 @@ type HandlerResponse = Response;
295
324
  */
296
325
  declare function createOneAddressHandler(options: OneAddressHandlerOptions): (req: HandlerRequest) => Promise<HandlerResponse>;
297
326
 
298
- export { type EncryptedPayload, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, fetchLoaPublicKey, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
327
+ export { type EncryptedPayload, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, fetchLoaPublicKey, transformAddress as transform, transformAddress, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
package/dist/index.js CHANGED
@@ -38,6 +38,8 @@ __export(index_exports, {
38
38
  decryptAddress: () => decryptAddress,
39
39
  fetchLoaPublicKey: () => fetchLoaPublicKey,
40
40
  isFreshTimestamp: () => isFreshTimestamp,
41
+ transform: () => transformAddress,
42
+ transformAddress: () => transformAddress,
41
43
  validateAddress: () => validateAddress,
42
44
  verify: () => verifySignature,
43
45
  verifyGrace: () => verifyWithGrace,
@@ -74,7 +76,7 @@ function verifySignature(rawBody, signature, timestamp, secret) {
74
76
  }
75
77
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
76
78
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
77
- if (previousSecret && graceUntil) {
79
+ if (previousSecret && previousSecret !== currentSecret && graceUntil) {
78
80
  const until = typeof graceUntil === "number" ? graceUntil : Date.parse(graceUntil);
79
81
  if (!Number.isNaN(until) && Date.now() < until) {
80
82
  return verifySignature(rawBody, signature, timestamp, previousSecret);
@@ -110,7 +112,18 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
110
112
  256
111
113
  );
112
114
  const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
113
- 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
+ }
114
127
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
115
128
  const aesKeyBits = await import_crypto.default.subtle.deriveBits(
116
129
  { name: "HKDF", hash: "SHA-256", salt, info },
@@ -125,6 +138,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
125
138
  );
126
139
  return JSON.parse(new TextDecoder().decode(plaintext));
127
140
  }
141
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
142
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
143
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
144
+ const recipientKey = await import_crypto.default.subtle.importKey(
145
+ "spki",
146
+ pemToBuffer(recipientSpkiPem),
147
+ { name: "ECDH", namedCurve: "P-256" },
148
+ false,
149
+ []
150
+ );
151
+ const ephemeralPair = await import_crypto.default.subtle.generateKey(
152
+ { name: "ECDH", namedCurve: "P-256" },
153
+ true,
154
+ ["deriveBits"]
155
+ );
156
+ const sharedBits = await import_crypto.default.subtle.deriveBits(
157
+ { name: "ECDH", public: recipientKey },
158
+ ephemeralPair.privateKey,
159
+ 256
160
+ );
161
+ const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
162
+ const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
163
+ const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
164
+ const aesKeyBits = await import_crypto.default.subtle.deriveBits(
165
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
166
+ hkdfKey,
167
+ 256
168
+ );
169
+ const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
170
+ const ivBytes = import_crypto.default.getRandomValues(new Uint8Array(12));
171
+ const ciphertextBuf = await import_crypto.default.subtle.encrypt(
172
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
173
+ aesKey,
174
+ plaintextBytes
175
+ );
176
+ const ephemeralPublicKeyRaw = await import_crypto.default.subtle.exportKey("raw", ephemeralPair.publicKey);
177
+ return {
178
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
179
+ iv: Buffer.from(ivBytes).toString("base64"),
180
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
181
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
182
+ };
183
+ }
128
184
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
129
185
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
130
186
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -345,6 +401,8 @@ function createOneAddressHandler(options) {
345
401
  decryptAddress,
346
402
  fetchLoaPublicKey,
347
403
  isFreshTimestamp,
404
+ transform,
405
+ transformAddress,
348
406
  validateAddress,
349
407
  verify,
350
408
  verifyGrace,
package/dist/index.mjs CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  decryptAddress,
7
7
  fetchLoaPublicKey,
8
8
  isFreshTimestamp,
9
+ transformAddress,
9
10
  validateAddress,
10
11
  verifyLOA,
11
12
  verifySignature,
12
13
  verifyWithGrace
13
- } from "./chunk-NBUGPU44.mjs";
14
+ } from "./chunk-ZZZLXF6X.mjs";
14
15
  export {
15
16
  CURRENT_VERSION,
16
17
  DEFAULT_REPLAY_WINDOW_SECS,
@@ -20,6 +21,8 @@ export {
20
21
  decryptAddress,
21
22
  fetchLoaPublicKey,
22
23
  isFreshTimestamp,
24
+ transformAddress as transform,
25
+ transformAddress,
23
26
  validateAddress,
24
27
  verifySignature as verify,
25
28
  verifyWithGrace as verifyGrace,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneaddress/partner-sdk",
3
- "version": "1.0.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",