@oneaddress/partner-sdk 1.0.0 → 1.1.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.
@@ -78,6 +78,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
78
78
  );
79
79
  return JSON.parse(new TextDecoder().decode(plaintext));
80
80
  }
81
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
82
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
83
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
84
+ const recipientKey = await crypto.subtle.importKey(
85
+ "spki",
86
+ pemToBuffer(recipientSpkiPem),
87
+ { name: "ECDH", namedCurve: "P-256" },
88
+ false,
89
+ []
90
+ );
91
+ const ephemeralPair = await crypto.subtle.generateKey(
92
+ { name: "ECDH", namedCurve: "P-256" },
93
+ true,
94
+ ["deriveBits"]
95
+ );
96
+ const sharedBits = await crypto.subtle.deriveBits(
97
+ { name: "ECDH", public: recipientKey },
98
+ ephemeralPair.privateKey,
99
+ 256
100
+ );
101
+ const hkdfSaltBytes = crypto.getRandomValues(new Uint8Array(32));
102
+ const hkdfKey = await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
103
+ const info = new TextEncoder().encode(`oneaddress:transform`);
104
+ const aesKeyBits = await crypto.subtle.deriveBits(
105
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
106
+ hkdfKey,
107
+ 256
108
+ );
109
+ const aesKey = await crypto.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
110
+ const ivBytes = crypto.getRandomValues(new Uint8Array(12));
111
+ const ciphertextBuf = await crypto.subtle.encrypt(
112
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
113
+ aesKey,
114
+ plaintextBytes
115
+ );
116
+ const ephemeralPublicKeyRaw = await crypto.subtle.exportKey("raw", ephemeralPair.publicKey);
117
+ return {
118
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
119
+ iv: Buffer.from(ivBytes).toString("base64"),
120
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
121
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
122
+ };
123
+ }
81
124
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
82
125
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
83
126
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -297,6 +340,7 @@ export {
297
340
  verifySignature,
298
341
  verifyWithGrace,
299
342
  decryptAddress,
343
+ transformAddress,
300
344
  fetchLoaPublicKey,
301
345
  verifyLOA,
302
346
  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,
@@ -124,6 +125,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
124
125
  );
125
126
  return JSON.parse(new TextDecoder().decode(plaintext));
126
127
  }
128
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
129
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
130
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
131
+ const recipientKey = await import_crypto.default.subtle.importKey(
132
+ "spki",
133
+ pemToBuffer(recipientSpkiPem),
134
+ { name: "ECDH", namedCurve: "P-256" },
135
+ false,
136
+ []
137
+ );
138
+ const ephemeralPair = await import_crypto.default.subtle.generateKey(
139
+ { name: "ECDH", namedCurve: "P-256" },
140
+ true,
141
+ ["deriveBits"]
142
+ );
143
+ const sharedBits = await import_crypto.default.subtle.deriveBits(
144
+ { name: "ECDH", public: recipientKey },
145
+ ephemeralPair.privateKey,
146
+ 256
147
+ );
148
+ const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
149
+ const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
150
+ const info = new TextEncoder().encode(`oneaddress:transform`);
151
+ const aesKeyBits = await import_crypto.default.subtle.deriveBits(
152
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
153
+ hkdfKey,
154
+ 256
155
+ );
156
+ const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
157
+ const ivBytes = import_crypto.default.getRandomValues(new Uint8Array(12));
158
+ const ciphertextBuf = await import_crypto.default.subtle.encrypt(
159
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
160
+ aesKey,
161
+ plaintextBytes
162
+ );
163
+ const ephemeralPublicKeyRaw = await import_crypto.default.subtle.exportKey("raw", ephemeralPair.publicKey);
164
+ return {
165
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
166
+ iv: Buffer.from(ivBytes).toString("base64"),
167
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
168
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
169
+ };
170
+ }
127
171
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
128
172
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
129
173
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -343,6 +387,7 @@ function createOneAddressHandler(options) {
343
387
  decryptAddress,
344
388
  fetchLoaPublicKey,
345
389
  isFreshTimestamp,
390
+ transformAddress,
346
391
  validateAddress,
347
392
  verifyLOA,
348
393
  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-BCAOUGA6.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,
@@ -125,6 +127,49 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
125
127
  );
126
128
  return JSON.parse(new TextDecoder().decode(plaintext));
127
129
  }
130
+ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
131
+ const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
132
+ const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
133
+ const recipientKey = await import_crypto.default.subtle.importKey(
134
+ "spki",
135
+ pemToBuffer(recipientSpkiPem),
136
+ { name: "ECDH", namedCurve: "P-256" },
137
+ false,
138
+ []
139
+ );
140
+ const ephemeralPair = await import_crypto.default.subtle.generateKey(
141
+ { name: "ECDH", namedCurve: "P-256" },
142
+ true,
143
+ ["deriveBits"]
144
+ );
145
+ const sharedBits = await import_crypto.default.subtle.deriveBits(
146
+ { name: "ECDH", public: recipientKey },
147
+ ephemeralPair.privateKey,
148
+ 256
149
+ );
150
+ const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
151
+ const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
152
+ const info = new TextEncoder().encode(`oneaddress:transform`);
153
+ const aesKeyBits = await import_crypto.default.subtle.deriveBits(
154
+ { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
155
+ hkdfKey,
156
+ 256
157
+ );
158
+ const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
159
+ const ivBytes = import_crypto.default.getRandomValues(new Uint8Array(12));
160
+ const ciphertextBuf = await import_crypto.default.subtle.encrypt(
161
+ { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
162
+ aesKey,
163
+ plaintextBytes
164
+ );
165
+ const ephemeralPublicKeyRaw = await import_crypto.default.subtle.exportKey("raw", ephemeralPair.publicKey);
166
+ return {
167
+ ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
168
+ iv: Buffer.from(ivBytes).toString("base64"),
169
+ ciphertext: Buffer.from(ciphertextBuf).toString("base64"),
170
+ hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
171
+ };
172
+ }
128
173
  var OA_APP_BASE_URL = "https://app.oneaddress.io";
129
174
  var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["app.oneaddress.io", "localhost", "127.0.0.1"]);
130
175
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
@@ -345,6 +390,8 @@ function createOneAddressHandler(options) {
345
390
  decryptAddress,
346
391
  fetchLoaPublicKey,
347
392
  isFreshTimestamp,
393
+ transform,
394
+ transformAddress,
348
395
  validateAddress,
349
396
  verify,
350
397
  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-BCAOUGA6.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.0",
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",