@oneaddress/partner-sdk 1.2.0 → 1.3.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 +59 -0
- package/README.md +482 -350
- package/dist/chunk-2QGC7BHC.mjs +3752 -0
- package/dist/{chunk-EHR6T6MA.mjs → chunk-O2RSPJVP.mjs} +188 -25
- package/dist/edge.d.mts +1 -3
- package/dist/edge.d.ts +1 -3
- package/dist/edge.js +4089 -31
- package/dist/edge.mjs +19 -3
- package/dist/index.d.mts +284 -22
- package/dist/index.d.ts +284 -22
- package/dist/index.js +3682 -117
- package/dist/index.mjs +17 -3
- package/dist/{src-NUBMOPDK.mjs → src-DYGFEKX6.mjs} +13 -1
- package/package.json +38 -38
- package/dist/chunk-TGLIJMGK.mjs +0 -498
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isFreshTimestamp
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2QGC7BHC.mjs";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import crypto from "crypto";
|
|
@@ -84,13 +84,20 @@ async function decryptAddress(payload, privateKeyPem, partnerId) {
|
|
|
84
84
|
return JSON.parse(new TextDecoder().decode(plaintext));
|
|
85
85
|
}
|
|
86
86
|
async function decryptSession(share, envelopeB64, privateKeyPem, partnerId) {
|
|
87
|
-
const { decryptSession: decryptSessionCrypto } = await import("./src-
|
|
87
|
+
const { decryptSession: decryptSessionCrypto } = await import("./src-DYGFEKX6.mjs");
|
|
88
88
|
const privateKeyB64 = privateKeyPem.replace(/-----[^-]+-----/g, "").replace(/\s/g, "");
|
|
89
89
|
return decryptSessionCrypto(share, envelopeB64, privateKeyB64, partnerId);
|
|
90
90
|
}
|
|
91
91
|
async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
92
92
|
const plaintext = await decryptAddress(payload, privateKeyPem, partnerId);
|
|
93
93
|
const plaintextBytes = new TextEncoder().encode(JSON.stringify(plaintext));
|
|
94
|
+
return reEncryptForRecipient(
|
|
95
|
+
plaintextBytes,
|
|
96
|
+
recipientSpkiPem,
|
|
97
|
+
new TextEncoder().encode(`oneaddress:transform:${partnerId}`)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
async function reEncryptForRecipient(plaintextBytes, recipientSpkiPem, info) {
|
|
94
101
|
const recipientKey = await crypto.subtle.importKey(
|
|
95
102
|
"spki",
|
|
96
103
|
pemToBuffer(recipientSpkiPem),
|
|
@@ -110,7 +117,6 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
|
|
|
110
117
|
);
|
|
111
118
|
const hkdfSaltBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
112
119
|
const hkdfKey = await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
|
|
113
|
-
const info = new TextEncoder().encode(`oneaddress:transform:${partnerId}`);
|
|
114
120
|
const aesKeyBits = await crypto.subtle.deriveBits(
|
|
115
121
|
{ name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
|
|
116
122
|
hkdfKey,
|
|
@@ -131,6 +137,15 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
|
|
|
131
137
|
hkdfSalt: Buffer.from(hkdfSaltBytes).toString("base64")
|
|
132
138
|
};
|
|
133
139
|
}
|
|
140
|
+
async function transformSession(share, envelopeB64, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
141
|
+
const sessionData = await decryptSession(share, envelopeB64, privateKeyPem, partnerId);
|
|
142
|
+
const plaintextBytes = new TextEncoder().encode(JSON.stringify(sessionData));
|
|
143
|
+
return reEncryptForRecipient(
|
|
144
|
+
plaintextBytes,
|
|
145
|
+
recipientSpkiPem,
|
|
146
|
+
new TextEncoder().encode(`oneaddress:transform-session:${partnerId}`)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
134
149
|
var OA_APP_BASE_URL = "https://oneaddress.io";
|
|
135
150
|
var ALLOWED_LOA_HOSTS = /* @__PURE__ */ new Set(["oneaddress.io", "app.oneaddress.io", "localhost", "127.0.0.1"]);
|
|
136
151
|
async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
@@ -180,6 +195,56 @@ async function verifyLOA(loa, publicKeyPem) {
|
|
|
180
195
|
return false;
|
|
181
196
|
}
|
|
182
197
|
}
|
|
198
|
+
function canonicalD5LoaForm(loa) {
|
|
199
|
+
return [
|
|
200
|
+
loa.consumer_name,
|
|
201
|
+
loa.authorisation_date,
|
|
202
|
+
loa.scope,
|
|
203
|
+
loa.update_uid,
|
|
204
|
+
loa.oneaddress_acn
|
|
205
|
+
].join("|");
|
|
206
|
+
}
|
|
207
|
+
function toB64Url(buf) {
|
|
208
|
+
return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
209
|
+
}
|
|
210
|
+
function d5LoaRef(loa) {
|
|
211
|
+
return toB64Url(crypto.createHash("sha256").update(canonicalD5LoaForm(loa), "utf8").digest());
|
|
212
|
+
}
|
|
213
|
+
async function verifyD5LOA(loa, publicKeyPem) {
|
|
214
|
+
if (loa.signature_algorithm !== "ECDSA-P256") {
|
|
215
|
+
console.warn(
|
|
216
|
+
// NOSONAR — intentional SDK diagnostic, not user-controlled data
|
|
217
|
+
"[OneAddress SDK] D5 LOA algorithm is HMAC-SHA256 (deprecated) \u2014 cannot be verified by partners."
|
|
218
|
+
);
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const key = await crypto.subtle.importKey(
|
|
223
|
+
"spki",
|
|
224
|
+
pemToBuffer(publicKeyPem),
|
|
225
|
+
{ name: "ECDSA", namedCurve: "P-256" },
|
|
226
|
+
false,
|
|
227
|
+
["verify"]
|
|
228
|
+
);
|
|
229
|
+
return await crypto.subtle.verify(
|
|
230
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
231
|
+
key,
|
|
232
|
+
Buffer.from(loa.oneaddress_signature, "hex"),
|
|
233
|
+
new TextEncoder().encode(canonicalD5LoaForm(loa))
|
|
234
|
+
);
|
|
235
|
+
} catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function decryptLoaEncrypted(loaEncrypted, privateKeyPem, partnerId) {
|
|
240
|
+
const data = await decryptSession(
|
|
241
|
+
loaEncrypted.session_key_share,
|
|
242
|
+
loaEncrypted.session_envelope,
|
|
243
|
+
privateKeyPem,
|
|
244
|
+
partnerId
|
|
245
|
+
);
|
|
246
|
+
return data;
|
|
247
|
+
}
|
|
183
248
|
var ADDRESS_REQUIRED_FIELDS = [
|
|
184
249
|
"street",
|
|
185
250
|
"suburb",
|
|
@@ -264,12 +329,49 @@ function createOneAddressHandler(options) {
|
|
|
264
329
|
previousWebhookSecret,
|
|
265
330
|
webhookSecretGraceUntil,
|
|
266
331
|
privateKeyPem,
|
|
332
|
+
loaPublicKeyPem,
|
|
267
333
|
onUpdate,
|
|
268
334
|
onVerify,
|
|
269
335
|
onAccountVerify,
|
|
270
336
|
timestampToleranceSecs = 300,
|
|
271
337
|
idempotencyStore
|
|
272
338
|
} = options;
|
|
339
|
+
async function buildD5Pieces(body, partnerId) {
|
|
340
|
+
const share = body.session_key_share;
|
|
341
|
+
const data = await decryptSession(share, body.session_envelope, privateKeyPem, partnerId);
|
|
342
|
+
const address = validateAddress({
|
|
343
|
+
street: data.new_address?.street,
|
|
344
|
+
suburb: data.new_address?.suburb,
|
|
345
|
+
state: data.new_address?.state,
|
|
346
|
+
postcode: data.new_address?.postcode,
|
|
347
|
+
country: data.new_address?.country,
|
|
348
|
+
updated_at: data.dispatch_timestamp ?? body.timestamp ?? ""
|
|
349
|
+
});
|
|
350
|
+
const customer = {
|
|
351
|
+
email: "",
|
|
352
|
+
name: data.verified_name ?? "",
|
|
353
|
+
account_number: data.account_number ?? null,
|
|
354
|
+
known_names: Array.isArray(data.known_names) ? data.known_names : []
|
|
355
|
+
};
|
|
356
|
+
let loa;
|
|
357
|
+
let loa_ref;
|
|
358
|
+
if (body.loa_encrypted && typeof body.loa_encrypted === "object") {
|
|
359
|
+
loa = await decryptLoaEncrypted(
|
|
360
|
+
body.loa_encrypted,
|
|
361
|
+
privateKeyPem,
|
|
362
|
+
partnerId
|
|
363
|
+
);
|
|
364
|
+
loa_ref = d5LoaRef(loa);
|
|
365
|
+
if (loaPublicKeyPem) {
|
|
366
|
+
const valid = await verifyD5LOA(loa, loaPublicKeyPem);
|
|
367
|
+
if (!valid) throw new Error("D5 LOA signature verification failed");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return { address, customer, loa, loa_ref, raw: data };
|
|
371
|
+
}
|
|
372
|
+
function isD5Body(body) {
|
|
373
|
+
return typeof body.session_envelope === "string" && !!body.session_key_share && typeof body.session_key_share === "object";
|
|
374
|
+
}
|
|
273
375
|
return async function handler(req) {
|
|
274
376
|
const rawBody = await req.text();
|
|
275
377
|
const sig = req.headers.get("x-oneaddress-signature") ?? "";
|
|
@@ -324,27 +426,66 @@ function createOneAddressHandler(options) {
|
|
|
324
426
|
}
|
|
325
427
|
try {
|
|
326
428
|
if (body.event === "address.updated") {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
429
|
+
let event;
|
|
430
|
+
if (isD5Body(body)) {
|
|
431
|
+
const d5 = await buildD5Pieces(body, partnerId);
|
|
432
|
+
event = {
|
|
433
|
+
event: "address.updated",
|
|
434
|
+
version: body.oneaddress_version ?? body.version ?? "2.0",
|
|
435
|
+
id: body.id ?? "",
|
|
436
|
+
timestamp: tsNum,
|
|
437
|
+
partner_id: partnerId,
|
|
438
|
+
dispatchId,
|
|
439
|
+
customer: d5.customer,
|
|
440
|
+
address: d5.address,
|
|
441
|
+
loa: d5.loa,
|
|
442
|
+
loa_ref: d5.loa_ref,
|
|
443
|
+
id_verification: body.id_verification,
|
|
444
|
+
raw: d5.raw
|
|
445
|
+
};
|
|
446
|
+
} else {
|
|
447
|
+
if (!body.address_encrypted || typeof body.address_encrypted !== "object") {
|
|
448
|
+
return new Response(JSON.stringify({ error: "Missing or invalid address_encrypted payload" }), {
|
|
449
|
+
status: 400,
|
|
450
|
+
headers: { "Content-Type": "application/json" }
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
const encrypted = body.address_encrypted;
|
|
454
|
+
const rawAddress = await decryptAddress(encrypted, privateKeyPem, partnerId);
|
|
455
|
+
let loa;
|
|
456
|
+
let loa_ref;
|
|
457
|
+
if (body.loa_encrypted && typeof body.loa_encrypted === "object") {
|
|
458
|
+
loa = await decryptLoaEncrypted(
|
|
459
|
+
body.loa_encrypted,
|
|
460
|
+
privateKeyPem,
|
|
461
|
+
partnerId
|
|
462
|
+
);
|
|
463
|
+
loa_ref = d5LoaRef(loa);
|
|
464
|
+
if (loaPublicKeyPem && !await verifyD5LOA(loa, loaPublicKeyPem)) {
|
|
465
|
+
throw new Error("D5 LOA signature verification failed");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const customer = {
|
|
469
|
+
email: "",
|
|
470
|
+
name: rawAddress.fullName ?? "",
|
|
471
|
+
account_number: rawAddress.accountReference ?? null,
|
|
472
|
+
known_names: Array.isArray(rawAddress.knownNames) ? rawAddress.knownNames : []
|
|
473
|
+
};
|
|
474
|
+
event = {
|
|
475
|
+
event: "address.updated",
|
|
476
|
+
version: body.oneaddress_version ?? body.version ?? "1",
|
|
477
|
+
id: body.id ?? "",
|
|
478
|
+
timestamp: tsNum,
|
|
479
|
+
partner_id: partnerId,
|
|
480
|
+
dispatchId,
|
|
481
|
+
customer,
|
|
482
|
+
address: validateAddress(rawAddress),
|
|
483
|
+
loa,
|
|
484
|
+
loa_ref,
|
|
485
|
+
id_verification: body.id_verification,
|
|
486
|
+
raw: rawAddress
|
|
487
|
+
};
|
|
332
488
|
}
|
|
333
|
-
const encrypted = body.address_encrypted;
|
|
334
|
-
const rawAddress = await decryptAddress(encrypted, privateKeyPem, partnerId);
|
|
335
|
-
const event = {
|
|
336
|
-
event: "address.updated",
|
|
337
|
-
version: body.oneaddress_version ?? body.version ?? "1",
|
|
338
|
-
id: body.id ?? "",
|
|
339
|
-
timestamp: tsNum,
|
|
340
|
-
partner_id: partnerId,
|
|
341
|
-
dispatchId,
|
|
342
|
-
customer: body.customer,
|
|
343
|
-
address: validateAddress(rawAddress),
|
|
344
|
-
loa: body.loa,
|
|
345
|
-
id_verification: body.id_verification,
|
|
346
|
-
raw: rawAddress
|
|
347
|
-
};
|
|
348
489
|
const result = await onUpdate(event);
|
|
349
490
|
if (dispatchId && idempotencyStore) {
|
|
350
491
|
await idempotencyStore.set(dispatchId).catch(
|
|
@@ -375,7 +516,8 @@ function createOneAddressHandler(options) {
|
|
|
375
516
|
dispatchId,
|
|
376
517
|
batch_id: body.batch_id ?? 0,
|
|
377
518
|
user_id: body.user_id ?? "",
|
|
378
|
-
customer: body.customer
|
|
519
|
+
customer: body.customer,
|
|
520
|
+
customer_match: body.customer_match,
|
|
379
521
|
address: validateAddress(rawAddress),
|
|
380
522
|
loa: body.loa,
|
|
381
523
|
id_verification: body.id_verification,
|
|
@@ -388,6 +530,22 @@ function createOneAddressHandler(options) {
|
|
|
388
530
|
});
|
|
389
531
|
}
|
|
390
532
|
if (body.event === "account.verify" && onAccountVerify) {
|
|
533
|
+
let customer;
|
|
534
|
+
if (body.customer_encrypted && typeof body.customer_encrypted === "object") {
|
|
535
|
+
const raw = await decryptAddress(
|
|
536
|
+
body.customer_encrypted,
|
|
537
|
+
privateKeyPem,
|
|
538
|
+
partnerId
|
|
539
|
+
);
|
|
540
|
+
customer = {
|
|
541
|
+
email: raw.email ?? "",
|
|
542
|
+
name: raw.name ?? "",
|
|
543
|
+
account_number: raw.account_number ?? null,
|
|
544
|
+
known_names: Array.isArray(raw.known_names) ? raw.known_names : []
|
|
545
|
+
};
|
|
546
|
+
} else {
|
|
547
|
+
customer = body.customer ?? {};
|
|
548
|
+
}
|
|
391
549
|
const event = {
|
|
392
550
|
event: "account.verify",
|
|
393
551
|
version: body.oneaddress_version ?? body.version ?? "1",
|
|
@@ -396,7 +554,7 @@ function createOneAddressHandler(options) {
|
|
|
396
554
|
partner_id: partnerId,
|
|
397
555
|
dispatchId,
|
|
398
556
|
user_id: body.user_id ?? "",
|
|
399
|
-
customer
|
|
557
|
+
customer,
|
|
400
558
|
raw: body
|
|
401
559
|
};
|
|
402
560
|
const result = await onAccountVerify(event);
|
|
@@ -428,8 +586,13 @@ export {
|
|
|
428
586
|
decryptAddress,
|
|
429
587
|
decryptSession,
|
|
430
588
|
transformAddress,
|
|
589
|
+
transformSession,
|
|
431
590
|
fetchLoaPublicKey,
|
|
432
591
|
verifyLOA,
|
|
592
|
+
canonicalD5LoaForm,
|
|
593
|
+
d5LoaRef,
|
|
594
|
+
verifyD5LOA,
|
|
595
|
+
decryptLoaEncrypted,
|
|
433
596
|
validateAddress,
|
|
434
597
|
compareAddresses,
|
|
435
598
|
createOneAddressHandler
|
package/dist/edge.d.mts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, transform as transformAddress, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
|
|
2
|
-
export { CURRENT_VERSION, SUPPORTED_VERSIONS } from '@oneaddress/protocol';
|
|
3
|
-
export { DEFAULT_REPLAY_WINDOW_SECS, isFreshTimestamp } from '@oneaddress/crypto';
|
|
1
|
+
export { BlindIndexField, CURRENT_VERSION, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, canonicalD5LoaForm, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, isFreshTimestamp, normalizeForBlindIndex, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
|
package/dist/edge.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export { EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, createOneAddressHandler, decrypt as decryptAddress, fetchLoaPublicKey, transform as transformAddress, validateAddress, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';
|
|
2
|
-
export { CURRENT_VERSION, SUPPORTED_VERSIONS } from '@oneaddress/protocol';
|
|
3
|
-
export { DEFAULT_REPLAY_WINDOW_SECS, isFreshTimestamp } from '@oneaddress/crypto';
|
|
1
|
+
export { BlindIndexField, CURRENT_VERSION, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, canonicalD5LoaForm, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, isFreshTimestamp, normalizeForBlindIndex, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';
|