@oneaddress/partner-sdk 1.1.1 → 1.2.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/README.md +132 -0
- package/dist/{chunk-ZZZLXF6X.mjs → chunk-EHR6T6MA.mjs} +93 -16
- package/dist/chunk-TGLIJMGK.mjs +498 -0
- package/dist/edge.d.mts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +63 -14
- package/dist/edge.mjs +5 -3
- package/dist/index.d.mts +241 -3
- package/dist/index.d.ts +241 -3
- package/dist/index.js +621 -20
- package/dist/index.mjs +9 -3
- package/dist/src-NUBMOPDK.mjs +30 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -41,6 +41,35 @@ interface OneAddressLOA {
|
|
|
41
41
|
signature: string;
|
|
42
42
|
algorithm: string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Server-built attestation that the customer completed identity verification
|
|
46
|
+
* before this dispatch was authorised. Always emitted alongside an
|
|
47
|
+
* `address.updated` or `address.verify` payload when OneAddress consumed a
|
|
48
|
+
* live IDV credit (Global Data DVS + biometric, or the mock equivalent in
|
|
49
|
+
* sandbox builds).
|
|
50
|
+
*
|
|
51
|
+
* Partners should persist `verification_ref` against their record of the
|
|
52
|
+
* update — it is the immutable handle for the IDV that authorised this
|
|
53
|
+
* dispatch. Quote it back to OneAddress support to trace an update back to
|
|
54
|
+
* the underlying verification.
|
|
55
|
+
*
|
|
56
|
+
* Absent on test-mode dispatches that bypass the credit (BYPASS_STRIPE
|
|
57
|
+
* dev flows). Production dispatches always include it.
|
|
58
|
+
*/
|
|
59
|
+
interface OneAddressIdVerification {
|
|
60
|
+
/** UUID — immutable handle for the IDV credit consumed by this dispatch */
|
|
61
|
+
verification_ref: string;
|
|
62
|
+
/** Verification method, e.g. `global_data_idpass` or `mock` (sandbox) */
|
|
63
|
+
method: string;
|
|
64
|
+
/** ISO-8601 timestamp the verification was completed */
|
|
65
|
+
verified_at: string;
|
|
66
|
+
/** Provider-issued certificate id (Global Data api_reference); may be null */
|
|
67
|
+
certificate_id: string | null;
|
|
68
|
+
/** Always `true` on dispatches — partners can rely on the field's presence */
|
|
69
|
+
verified: true;
|
|
70
|
+
/** Format tag — currently `oneaddress/v1` */
|
|
71
|
+
platform: string;
|
|
72
|
+
}
|
|
44
73
|
interface OneAddressUpdateEvent {
|
|
45
74
|
event: 'address.updated';
|
|
46
75
|
version: string;
|
|
@@ -69,6 +98,12 @@ interface OneAddressUpdateEvent {
|
|
|
69
98
|
customer: OneAddressCustomer;
|
|
70
99
|
address: OneAddressAddress;
|
|
71
100
|
loa?: OneAddressLOA;
|
|
101
|
+
/**
|
|
102
|
+
* Identity-verification attestation for the customer behind this update.
|
|
103
|
+
* Present on every production dispatch; absent on BYPASS_STRIPE test
|
|
104
|
+
* flows. See {@link OneAddressIdVerification}.
|
|
105
|
+
*/
|
|
106
|
+
id_verification?: OneAddressIdVerification;
|
|
72
107
|
/** Raw decrypted + parsed payload (in case fields are extended) */
|
|
73
108
|
raw: Record<string, unknown>;
|
|
74
109
|
}
|
|
@@ -85,6 +120,40 @@ interface OneAddressVerifyEvent {
|
|
|
85
120
|
customer: OneAddressCustomer;
|
|
86
121
|
address: OneAddressAddress;
|
|
87
122
|
loa?: OneAddressLOA;
|
|
123
|
+
/**
|
|
124
|
+
* Identity-verification attestation for the customer behind this verify
|
|
125
|
+
* request. Present on every production dispatch; absent on BYPASS_STRIPE
|
|
126
|
+
* test flows. See {@link OneAddressIdVerification}.
|
|
127
|
+
*/
|
|
128
|
+
id_verification?: OneAddressIdVerification;
|
|
129
|
+
raw: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sent before a guest pays, to check whether the partner has a record of
|
|
133
|
+
* this customer at all. There is no address in this payload — the partner
|
|
134
|
+
* matches purely on name + account number. The wizard surfaces the result
|
|
135
|
+
* so the user can fix a mistyped account number before paying.
|
|
136
|
+
*
|
|
137
|
+
* Respond with `{ status: 'match' | 'no_match' | 'no_account' }`:
|
|
138
|
+
* - `match` — the name + account_number combination resolves to a record
|
|
139
|
+
* - `no_match` — the account number exists but the name doesn't line up
|
|
140
|
+
* (treated as a soft warning in the UI; user can retry)
|
|
141
|
+
* - `no_account` — no record matches the supplied account number
|
|
142
|
+
*
|
|
143
|
+
* Partners that don't implement `onAccountVerify` are silently skipped —
|
|
144
|
+
* the wizard treats the absence as "this partner doesn't support pre-pay
|
|
145
|
+
* verification" and lets the user proceed.
|
|
146
|
+
*/
|
|
147
|
+
interface OneAddressAccountVerifyEvent {
|
|
148
|
+
event: 'account.verify';
|
|
149
|
+
version: string;
|
|
150
|
+
id: string;
|
|
151
|
+
timestamp: number;
|
|
152
|
+
partner_id: string;
|
|
153
|
+
/** Unique dispatch ID from `X-OneAddress-Dispatch`. Falls back to `''` if header is absent — guard before using as idempotency key. */
|
|
154
|
+
dispatchId: string;
|
|
155
|
+
user_id: string;
|
|
156
|
+
customer: OneAddressCustomer;
|
|
88
157
|
raw: Record<string, unknown>;
|
|
89
158
|
}
|
|
90
159
|
interface EncryptedPayload {
|
|
@@ -135,6 +204,18 @@ interface OneAddressHandlerOptions {
|
|
|
135
204
|
match: boolean;
|
|
136
205
|
note?: string;
|
|
137
206
|
} | void>;
|
|
207
|
+
/**
|
|
208
|
+
* Called when a guest checkout runs a pre-payment account-existence
|
|
209
|
+
* check. Return `{ status: 'match' | 'no_match' | 'no_account' }`.
|
|
210
|
+
*
|
|
211
|
+
* Implement this if you support look-up by name + account number. If
|
|
212
|
+
* you don't, leave it unset and the wizard will mark your service as
|
|
213
|
+
* "skipped" — the guest can still proceed to pay and dispatch.
|
|
214
|
+
*/
|
|
215
|
+
onAccountVerify?: (event: OneAddressAccountVerifyEvent) => Promise<{
|
|
216
|
+
status: 'match' | 'no_match' | 'no_account';
|
|
217
|
+
note?: string;
|
|
218
|
+
}>;
|
|
138
219
|
/**
|
|
139
220
|
* Timestamp tolerance in seconds (default: 300 = 5 minutes).
|
|
140
221
|
* Requests with timestamps outside this window are rejected as potential replays.
|
|
@@ -219,6 +300,113 @@ declare function verifyWithGrace(rawBody: string, timestamp: string, signature:
|
|
|
219
300
|
* @param partnerId - Your partner UUID (used as HKDF info string)
|
|
220
301
|
*/
|
|
221
302
|
declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string): Promise<Record<string, unknown>>;
|
|
303
|
+
/**
|
|
304
|
+
* D5 — the structured `session_key_share` block delivered to your webhook
|
|
305
|
+
* alongside `session_envelope`. Carries `key_id` at the top level so your
|
|
306
|
+
* SDK can route to the right retained private key without parsing the wrap
|
|
307
|
+
* blob.
|
|
308
|
+
*
|
|
309
|
+
* Re-exported from `@oneaddress/crypto` for partner convenience — the type
|
|
310
|
+
* is identical on both sides of the wire.
|
|
311
|
+
*/
|
|
312
|
+
interface SessionKeyShare {
|
|
313
|
+
/** Stable identifier of the partner key OneAddress used to wrap SK_n. */
|
|
314
|
+
key_id: string;
|
|
315
|
+
/** Base64url ECDH-ES wrap of SK_n. */
|
|
316
|
+
wrapped_key: string;
|
|
317
|
+
/** Base64url SPKI of the ephemeral public key used in the wrap. */
|
|
318
|
+
epk: string;
|
|
319
|
+
/** Always `ECDH-ES+HKDF-SHA256+A256GCM`. */
|
|
320
|
+
alg: 'ECDH-ES+HKDF-SHA256+A256GCM';
|
|
321
|
+
/** Wrap-blob schema version. Always `2`. */
|
|
322
|
+
v: 2;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* D5 — the decrypted contents of a `session_envelope`.
|
|
326
|
+
*
|
|
327
|
+
* `update_uid` and `dispatch_timestamp` are OPTIONAL in `SessionData`
|
|
328
|
+
* because the wizard doesn't always know them at encrypt time; the outer
|
|
329
|
+
* webhook (the same JSON object that wraps this envelope) carries both
|
|
330
|
+
* cleartext as `update_id` and `timestamp`. Use those for correlation;
|
|
331
|
+
* use the envelope's embedded fields, when present, as the audit-grade
|
|
332
|
+
* source of truth.
|
|
333
|
+
*/
|
|
334
|
+
interface SessionData {
|
|
335
|
+
v: 2;
|
|
336
|
+
update_uid?: string;
|
|
337
|
+
dispatch_timestamp?: string;
|
|
338
|
+
verified_name: string;
|
|
339
|
+
new_address: {
|
|
340
|
+
street: string;
|
|
341
|
+
suburb: string;
|
|
342
|
+
state: string;
|
|
343
|
+
postcode: string;
|
|
344
|
+
country: string;
|
|
345
|
+
fullName?: string;
|
|
346
|
+
preferredName?: string;
|
|
347
|
+
knownNames?: string[];
|
|
348
|
+
accountReference?: string;
|
|
349
|
+
addressType?: 'residential' | 'postal' | 'both';
|
|
350
|
+
};
|
|
351
|
+
account_number: string;
|
|
352
|
+
id_verification_ref: string;
|
|
353
|
+
known_names?: string[];
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Decrypt a D5 session envelope using your retained private key matching
|
|
357
|
+
* `share.key_id`.
|
|
358
|
+
*
|
|
359
|
+
* The two-step decrypt:
|
|
360
|
+
* 1. Unwrap `share.wrapped_key` via ECDH-ES + HKDF-SHA-256 + AES-256-GCM
|
|
361
|
+
* using your private key. Recovers `SK_n`.
|
|
362
|
+
* 2. AES-256-GCM-decrypt `session_envelope` using `SK_n`. Recovers
|
|
363
|
+
* `SessionData`.
|
|
364
|
+
*
|
|
365
|
+
* The HKDF `info` string is bound to your `partner_id` for cryptographic
|
|
366
|
+
* protection against cross-partner share confusion — if you supply the
|
|
367
|
+
* wrong `partner_id`, the unwrap will fail with an authentication-tag
|
|
368
|
+
* error rather than silently returning garbled output.
|
|
369
|
+
*
|
|
370
|
+
* **Important — `key_id` routing.** Under D5 you may hold multiple
|
|
371
|
+
* private keys at once: one active (for new dispatches) plus zero-or-more
|
|
372
|
+
* retired keys still within their 90-day retention window. Look up the
|
|
373
|
+
* private key by `share.key_id` from your local key store before calling
|
|
374
|
+
* this function. The function does NOT pick a key for you.
|
|
375
|
+
*
|
|
376
|
+
* **Destroyed retired keys.** If you destroyed the private key for
|
|
377
|
+
* `share.key_id` before its `destroy_after`, you cannot decrypt this
|
|
378
|
+
* envelope. That is a key-custody breach of the partner agreement and is
|
|
379
|
+
* recorded on the OneAddress side as a `partner_key_custody_failure`
|
|
380
|
+
* outcome on the reconstruction audit log.
|
|
381
|
+
*
|
|
382
|
+
* @param share - The structured `session_key_share` block from the webhook.
|
|
383
|
+
* @param envelopeB64 - The `session_envelope` base64url string from the webhook.
|
|
384
|
+
* @param privateKeyPem - Your PKCS#8 PEM private key whose key_id matches `share.key_id`.
|
|
385
|
+
* @param partnerId - Your partner UUID (from the outer webhook payload).
|
|
386
|
+
* @returns The decrypted `SessionData`.
|
|
387
|
+
* @throws AES-GCM authentication-tag error if:
|
|
388
|
+
* - the wrong private key was supplied for `share.key_id`,
|
|
389
|
+
* - the wrong `partnerId` was supplied,
|
|
390
|
+
* - the ciphertext was tampered with or truncated,
|
|
391
|
+
* - or the share was forged.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* import { decryptSession } from '@oneaddress/partner-sdk';
|
|
395
|
+
*
|
|
396
|
+
* // Body of an address.updated webhook.
|
|
397
|
+
* const body = await req.json();
|
|
398
|
+
* const myPrivateKey = keyStore.get(body.session_key_share.key_id);
|
|
399
|
+
* if (!myPrivateKey) throw new Error(`No private key for ${body.session_key_share.key_id}`);
|
|
400
|
+
*
|
|
401
|
+
* const data = await decryptSession(
|
|
402
|
+
* body.session_key_share,
|
|
403
|
+
* body.session_envelope,
|
|
404
|
+
* myPrivateKey,
|
|
405
|
+
* body.partner_id,
|
|
406
|
+
* );
|
|
407
|
+
* // data.new_address.street, data.account_number, etc.
|
|
408
|
+
*/
|
|
409
|
+
declare function decryptSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string, partnerId: string): Promise<SessionData>;
|
|
222
410
|
/**
|
|
223
411
|
* Decrypt a OneAddress payload and immediately re-encrypt it to a different
|
|
224
412
|
* ECDH P-256 public key — for example, your internal KMS or HSM public key.
|
|
@@ -254,7 +442,7 @@ declare function transformAddress(payload: EncryptedPayload, privateKeyPem: stri
|
|
|
254
442
|
* Cache the result — the key only changes during a planned key rotation, which is
|
|
255
443
|
* announced in advance. Calling this on every request adds unnecessary latency.
|
|
256
444
|
*
|
|
257
|
-
* @param appBaseUrl Override the consumer-app base URL (default: https://
|
|
445
|
+
* @param appBaseUrl Override the consumer-app base URL (default: https://oneaddress.io)
|
|
258
446
|
*
|
|
259
447
|
* @example
|
|
260
448
|
* const publicKeyPem = await fetchLoaPublicKey();
|
|
@@ -271,7 +459,7 @@ declare function fetchLoaPublicKey(appBaseUrl?: string): Promise<string>;
|
|
|
271
459
|
* proof of consumer consent that stands up in an audit.
|
|
272
460
|
*
|
|
273
461
|
* The signing public key is served at:
|
|
274
|
-
* https://
|
|
462
|
+
* https://oneaddress.io/.well-known/oneaddress-loa-key.pem
|
|
275
463
|
*
|
|
276
464
|
* Fetch it once and cache it (it only changes during a planned key rotation):
|
|
277
465
|
* ```ts
|
|
@@ -310,6 +498,56 @@ declare function verifyLOA(loa: OneAddressLOA, publicKeyPem: string): Promise<bo
|
|
|
310
498
|
* await db.updateAddress(address);
|
|
311
499
|
*/
|
|
312
500
|
declare function validateAddress(raw: unknown): OneAddressAddress;
|
|
501
|
+
/**
|
|
502
|
+
* Address shape accepted by `compareAddresses`. Mirrors `OneAddressAddress`
|
|
503
|
+
* but every field is optional so partners can pass either their stored row
|
|
504
|
+
* (with extra fields) or the decrypted webhook payload (which has the full
|
|
505
|
+
* shape) without juggling adapters.
|
|
506
|
+
*/
|
|
507
|
+
interface ComparableAddress {
|
|
508
|
+
street?: string | null;
|
|
509
|
+
suburb?: string | null;
|
|
510
|
+
state?: string | null;
|
|
511
|
+
postcode?: string | null;
|
|
512
|
+
country?: string | null;
|
|
513
|
+
/** Some partners store "address_line1" instead of "street" — supported. */
|
|
514
|
+
address_line1?: string | null;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Are these two addresses the same after normalisation?
|
|
518
|
+
*
|
|
519
|
+
* Comparison rules:
|
|
520
|
+
* - Street line is normalised (case-fold, trim, expand common suffix
|
|
521
|
+
* abbreviations: St→Street, Rd→Road, Ave→Avenue, etc.)
|
|
522
|
+
* - Suburb + state are case-folded + trimmed
|
|
523
|
+
* - Postcode is left-padded to 4 digits (NT addresses with leading-zero
|
|
524
|
+
* postcodes round-trip correctly)
|
|
525
|
+
* - Country is treated as optional — when both sides have a value it
|
|
526
|
+
* must match; when either side omits it, country is ignored
|
|
527
|
+
*
|
|
528
|
+
* Designed to be conservative: returns `false` when in doubt. Partners
|
|
529
|
+
* who need looser matching (typo tolerance, fuzzy matching) should layer
|
|
530
|
+
* their own logic on top — this helper is the strict baseline.
|
|
531
|
+
*
|
|
532
|
+
* Use this in your `address.verify` handler to set the `address_match`
|
|
533
|
+
* field on the verify-result callback:
|
|
534
|
+
*
|
|
535
|
+
* ```ts
|
|
536
|
+
* import { compareAddresses } from '@oneaddress/partner-sdk';
|
|
537
|
+
*
|
|
538
|
+
* const stored = await db.lookupAddress(customer.account_number);
|
|
539
|
+
* const addressMatches = compareAddresses(stored, event.address);
|
|
540
|
+
* await fetch(callbackUrl, {
|
|
541
|
+
* method: 'POST',
|
|
542
|
+
* body: JSON.stringify({
|
|
543
|
+
* batch_id, partner_id, token,
|
|
544
|
+
* result: addressMatches ? 'match' : 'mismatch',
|
|
545
|
+
* address_match: addressMatches,
|
|
546
|
+
* }),
|
|
547
|
+
* });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare function compareAddresses(a: ComparableAddress, b: ComparableAddress): boolean;
|
|
313
551
|
type HandlerRequest = {
|
|
314
552
|
text(): Promise<string>;
|
|
315
553
|
headers: {
|
|
@@ -324,4 +562,4 @@ type HandlerResponse = Response;
|
|
|
324
562
|
*/
|
|
325
563
|
declare function createOneAddressHandler(options: OneAddressHandlerOptions): (req: HandlerRequest) => Promise<HandlerResponse>;
|
|
326
564
|
|
|
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 };
|
|
565
|
+
export { type ComparableAddress, type EncryptedPayload, type OneAddressAccountVerifyEvent, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressIdVerification, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, type SessionData, type SessionKeyShare, compareAddresses, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, decryptSession, fetchLoaPublicKey, transformAddress as transform, transformAddress, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,35 @@ interface OneAddressLOA {
|
|
|
41
41
|
signature: string;
|
|
42
42
|
algorithm: string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Server-built attestation that the customer completed identity verification
|
|
46
|
+
* before this dispatch was authorised. Always emitted alongside an
|
|
47
|
+
* `address.updated` or `address.verify` payload when OneAddress consumed a
|
|
48
|
+
* live IDV credit (Global Data DVS + biometric, or the mock equivalent in
|
|
49
|
+
* sandbox builds).
|
|
50
|
+
*
|
|
51
|
+
* Partners should persist `verification_ref` against their record of the
|
|
52
|
+
* update — it is the immutable handle for the IDV that authorised this
|
|
53
|
+
* dispatch. Quote it back to OneAddress support to trace an update back to
|
|
54
|
+
* the underlying verification.
|
|
55
|
+
*
|
|
56
|
+
* Absent on test-mode dispatches that bypass the credit (BYPASS_STRIPE
|
|
57
|
+
* dev flows). Production dispatches always include it.
|
|
58
|
+
*/
|
|
59
|
+
interface OneAddressIdVerification {
|
|
60
|
+
/** UUID — immutable handle for the IDV credit consumed by this dispatch */
|
|
61
|
+
verification_ref: string;
|
|
62
|
+
/** Verification method, e.g. `global_data_idpass` or `mock` (sandbox) */
|
|
63
|
+
method: string;
|
|
64
|
+
/** ISO-8601 timestamp the verification was completed */
|
|
65
|
+
verified_at: string;
|
|
66
|
+
/** Provider-issued certificate id (Global Data api_reference); may be null */
|
|
67
|
+
certificate_id: string | null;
|
|
68
|
+
/** Always `true` on dispatches — partners can rely on the field's presence */
|
|
69
|
+
verified: true;
|
|
70
|
+
/** Format tag — currently `oneaddress/v1` */
|
|
71
|
+
platform: string;
|
|
72
|
+
}
|
|
44
73
|
interface OneAddressUpdateEvent {
|
|
45
74
|
event: 'address.updated';
|
|
46
75
|
version: string;
|
|
@@ -69,6 +98,12 @@ interface OneAddressUpdateEvent {
|
|
|
69
98
|
customer: OneAddressCustomer;
|
|
70
99
|
address: OneAddressAddress;
|
|
71
100
|
loa?: OneAddressLOA;
|
|
101
|
+
/**
|
|
102
|
+
* Identity-verification attestation for the customer behind this update.
|
|
103
|
+
* Present on every production dispatch; absent on BYPASS_STRIPE test
|
|
104
|
+
* flows. See {@link OneAddressIdVerification}.
|
|
105
|
+
*/
|
|
106
|
+
id_verification?: OneAddressIdVerification;
|
|
72
107
|
/** Raw decrypted + parsed payload (in case fields are extended) */
|
|
73
108
|
raw: Record<string, unknown>;
|
|
74
109
|
}
|
|
@@ -85,6 +120,40 @@ interface OneAddressVerifyEvent {
|
|
|
85
120
|
customer: OneAddressCustomer;
|
|
86
121
|
address: OneAddressAddress;
|
|
87
122
|
loa?: OneAddressLOA;
|
|
123
|
+
/**
|
|
124
|
+
* Identity-verification attestation for the customer behind this verify
|
|
125
|
+
* request. Present on every production dispatch; absent on BYPASS_STRIPE
|
|
126
|
+
* test flows. See {@link OneAddressIdVerification}.
|
|
127
|
+
*/
|
|
128
|
+
id_verification?: OneAddressIdVerification;
|
|
129
|
+
raw: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sent before a guest pays, to check whether the partner has a record of
|
|
133
|
+
* this customer at all. There is no address in this payload — the partner
|
|
134
|
+
* matches purely on name + account number. The wizard surfaces the result
|
|
135
|
+
* so the user can fix a mistyped account number before paying.
|
|
136
|
+
*
|
|
137
|
+
* Respond with `{ status: 'match' | 'no_match' | 'no_account' }`:
|
|
138
|
+
* - `match` — the name + account_number combination resolves to a record
|
|
139
|
+
* - `no_match` — the account number exists but the name doesn't line up
|
|
140
|
+
* (treated as a soft warning in the UI; user can retry)
|
|
141
|
+
* - `no_account` — no record matches the supplied account number
|
|
142
|
+
*
|
|
143
|
+
* Partners that don't implement `onAccountVerify` are silently skipped —
|
|
144
|
+
* the wizard treats the absence as "this partner doesn't support pre-pay
|
|
145
|
+
* verification" and lets the user proceed.
|
|
146
|
+
*/
|
|
147
|
+
interface OneAddressAccountVerifyEvent {
|
|
148
|
+
event: 'account.verify';
|
|
149
|
+
version: string;
|
|
150
|
+
id: string;
|
|
151
|
+
timestamp: number;
|
|
152
|
+
partner_id: string;
|
|
153
|
+
/** Unique dispatch ID from `X-OneAddress-Dispatch`. Falls back to `''` if header is absent — guard before using as idempotency key. */
|
|
154
|
+
dispatchId: string;
|
|
155
|
+
user_id: string;
|
|
156
|
+
customer: OneAddressCustomer;
|
|
88
157
|
raw: Record<string, unknown>;
|
|
89
158
|
}
|
|
90
159
|
interface EncryptedPayload {
|
|
@@ -135,6 +204,18 @@ interface OneAddressHandlerOptions {
|
|
|
135
204
|
match: boolean;
|
|
136
205
|
note?: string;
|
|
137
206
|
} | void>;
|
|
207
|
+
/**
|
|
208
|
+
* Called when a guest checkout runs a pre-payment account-existence
|
|
209
|
+
* check. Return `{ status: 'match' | 'no_match' | 'no_account' }`.
|
|
210
|
+
*
|
|
211
|
+
* Implement this if you support look-up by name + account number. If
|
|
212
|
+
* you don't, leave it unset and the wizard will mark your service as
|
|
213
|
+
* "skipped" — the guest can still proceed to pay and dispatch.
|
|
214
|
+
*/
|
|
215
|
+
onAccountVerify?: (event: OneAddressAccountVerifyEvent) => Promise<{
|
|
216
|
+
status: 'match' | 'no_match' | 'no_account';
|
|
217
|
+
note?: string;
|
|
218
|
+
}>;
|
|
138
219
|
/**
|
|
139
220
|
* Timestamp tolerance in seconds (default: 300 = 5 minutes).
|
|
140
221
|
* Requests with timestamps outside this window are rejected as potential replays.
|
|
@@ -219,6 +300,113 @@ declare function verifyWithGrace(rawBody: string, timestamp: string, signature:
|
|
|
219
300
|
* @param partnerId - Your partner UUID (used as HKDF info string)
|
|
220
301
|
*/
|
|
221
302
|
declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string): Promise<Record<string, unknown>>;
|
|
303
|
+
/**
|
|
304
|
+
* D5 — the structured `session_key_share` block delivered to your webhook
|
|
305
|
+
* alongside `session_envelope`. Carries `key_id` at the top level so your
|
|
306
|
+
* SDK can route to the right retained private key without parsing the wrap
|
|
307
|
+
* blob.
|
|
308
|
+
*
|
|
309
|
+
* Re-exported from `@oneaddress/crypto` for partner convenience — the type
|
|
310
|
+
* is identical on both sides of the wire.
|
|
311
|
+
*/
|
|
312
|
+
interface SessionKeyShare {
|
|
313
|
+
/** Stable identifier of the partner key OneAddress used to wrap SK_n. */
|
|
314
|
+
key_id: string;
|
|
315
|
+
/** Base64url ECDH-ES wrap of SK_n. */
|
|
316
|
+
wrapped_key: string;
|
|
317
|
+
/** Base64url SPKI of the ephemeral public key used in the wrap. */
|
|
318
|
+
epk: string;
|
|
319
|
+
/** Always `ECDH-ES+HKDF-SHA256+A256GCM`. */
|
|
320
|
+
alg: 'ECDH-ES+HKDF-SHA256+A256GCM';
|
|
321
|
+
/** Wrap-blob schema version. Always `2`. */
|
|
322
|
+
v: 2;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* D5 — the decrypted contents of a `session_envelope`.
|
|
326
|
+
*
|
|
327
|
+
* `update_uid` and `dispatch_timestamp` are OPTIONAL in `SessionData`
|
|
328
|
+
* because the wizard doesn't always know them at encrypt time; the outer
|
|
329
|
+
* webhook (the same JSON object that wraps this envelope) carries both
|
|
330
|
+
* cleartext as `update_id` and `timestamp`. Use those for correlation;
|
|
331
|
+
* use the envelope's embedded fields, when present, as the audit-grade
|
|
332
|
+
* source of truth.
|
|
333
|
+
*/
|
|
334
|
+
interface SessionData {
|
|
335
|
+
v: 2;
|
|
336
|
+
update_uid?: string;
|
|
337
|
+
dispatch_timestamp?: string;
|
|
338
|
+
verified_name: string;
|
|
339
|
+
new_address: {
|
|
340
|
+
street: string;
|
|
341
|
+
suburb: string;
|
|
342
|
+
state: string;
|
|
343
|
+
postcode: string;
|
|
344
|
+
country: string;
|
|
345
|
+
fullName?: string;
|
|
346
|
+
preferredName?: string;
|
|
347
|
+
knownNames?: string[];
|
|
348
|
+
accountReference?: string;
|
|
349
|
+
addressType?: 'residential' | 'postal' | 'both';
|
|
350
|
+
};
|
|
351
|
+
account_number: string;
|
|
352
|
+
id_verification_ref: string;
|
|
353
|
+
known_names?: string[];
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Decrypt a D5 session envelope using your retained private key matching
|
|
357
|
+
* `share.key_id`.
|
|
358
|
+
*
|
|
359
|
+
* The two-step decrypt:
|
|
360
|
+
* 1. Unwrap `share.wrapped_key` via ECDH-ES + HKDF-SHA-256 + AES-256-GCM
|
|
361
|
+
* using your private key. Recovers `SK_n`.
|
|
362
|
+
* 2. AES-256-GCM-decrypt `session_envelope` using `SK_n`. Recovers
|
|
363
|
+
* `SessionData`.
|
|
364
|
+
*
|
|
365
|
+
* The HKDF `info` string is bound to your `partner_id` for cryptographic
|
|
366
|
+
* protection against cross-partner share confusion — if you supply the
|
|
367
|
+
* wrong `partner_id`, the unwrap will fail with an authentication-tag
|
|
368
|
+
* error rather than silently returning garbled output.
|
|
369
|
+
*
|
|
370
|
+
* **Important — `key_id` routing.** Under D5 you may hold multiple
|
|
371
|
+
* private keys at once: one active (for new dispatches) plus zero-or-more
|
|
372
|
+
* retired keys still within their 90-day retention window. Look up the
|
|
373
|
+
* private key by `share.key_id` from your local key store before calling
|
|
374
|
+
* this function. The function does NOT pick a key for you.
|
|
375
|
+
*
|
|
376
|
+
* **Destroyed retired keys.** If you destroyed the private key for
|
|
377
|
+
* `share.key_id` before its `destroy_after`, you cannot decrypt this
|
|
378
|
+
* envelope. That is a key-custody breach of the partner agreement and is
|
|
379
|
+
* recorded on the OneAddress side as a `partner_key_custody_failure`
|
|
380
|
+
* outcome on the reconstruction audit log.
|
|
381
|
+
*
|
|
382
|
+
* @param share - The structured `session_key_share` block from the webhook.
|
|
383
|
+
* @param envelopeB64 - The `session_envelope` base64url string from the webhook.
|
|
384
|
+
* @param privateKeyPem - Your PKCS#8 PEM private key whose key_id matches `share.key_id`.
|
|
385
|
+
* @param partnerId - Your partner UUID (from the outer webhook payload).
|
|
386
|
+
* @returns The decrypted `SessionData`.
|
|
387
|
+
* @throws AES-GCM authentication-tag error if:
|
|
388
|
+
* - the wrong private key was supplied for `share.key_id`,
|
|
389
|
+
* - the wrong `partnerId` was supplied,
|
|
390
|
+
* - the ciphertext was tampered with or truncated,
|
|
391
|
+
* - or the share was forged.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* import { decryptSession } from '@oneaddress/partner-sdk';
|
|
395
|
+
*
|
|
396
|
+
* // Body of an address.updated webhook.
|
|
397
|
+
* const body = await req.json();
|
|
398
|
+
* const myPrivateKey = keyStore.get(body.session_key_share.key_id);
|
|
399
|
+
* if (!myPrivateKey) throw new Error(`No private key for ${body.session_key_share.key_id}`);
|
|
400
|
+
*
|
|
401
|
+
* const data = await decryptSession(
|
|
402
|
+
* body.session_key_share,
|
|
403
|
+
* body.session_envelope,
|
|
404
|
+
* myPrivateKey,
|
|
405
|
+
* body.partner_id,
|
|
406
|
+
* );
|
|
407
|
+
* // data.new_address.street, data.account_number, etc.
|
|
408
|
+
*/
|
|
409
|
+
declare function decryptSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string, partnerId: string): Promise<SessionData>;
|
|
222
410
|
/**
|
|
223
411
|
* Decrypt a OneAddress payload and immediately re-encrypt it to a different
|
|
224
412
|
* ECDH P-256 public key — for example, your internal KMS or HSM public key.
|
|
@@ -254,7 +442,7 @@ declare function transformAddress(payload: EncryptedPayload, privateKeyPem: stri
|
|
|
254
442
|
* Cache the result — the key only changes during a planned key rotation, which is
|
|
255
443
|
* announced in advance. Calling this on every request adds unnecessary latency.
|
|
256
444
|
*
|
|
257
|
-
* @param appBaseUrl Override the consumer-app base URL (default: https://
|
|
445
|
+
* @param appBaseUrl Override the consumer-app base URL (default: https://oneaddress.io)
|
|
258
446
|
*
|
|
259
447
|
* @example
|
|
260
448
|
* const publicKeyPem = await fetchLoaPublicKey();
|
|
@@ -271,7 +459,7 @@ declare function fetchLoaPublicKey(appBaseUrl?: string): Promise<string>;
|
|
|
271
459
|
* proof of consumer consent that stands up in an audit.
|
|
272
460
|
*
|
|
273
461
|
* The signing public key is served at:
|
|
274
|
-
* https://
|
|
462
|
+
* https://oneaddress.io/.well-known/oneaddress-loa-key.pem
|
|
275
463
|
*
|
|
276
464
|
* Fetch it once and cache it (it only changes during a planned key rotation):
|
|
277
465
|
* ```ts
|
|
@@ -310,6 +498,56 @@ declare function verifyLOA(loa: OneAddressLOA, publicKeyPem: string): Promise<bo
|
|
|
310
498
|
* await db.updateAddress(address);
|
|
311
499
|
*/
|
|
312
500
|
declare function validateAddress(raw: unknown): OneAddressAddress;
|
|
501
|
+
/**
|
|
502
|
+
* Address shape accepted by `compareAddresses`. Mirrors `OneAddressAddress`
|
|
503
|
+
* but every field is optional so partners can pass either their stored row
|
|
504
|
+
* (with extra fields) or the decrypted webhook payload (which has the full
|
|
505
|
+
* shape) without juggling adapters.
|
|
506
|
+
*/
|
|
507
|
+
interface ComparableAddress {
|
|
508
|
+
street?: string | null;
|
|
509
|
+
suburb?: string | null;
|
|
510
|
+
state?: string | null;
|
|
511
|
+
postcode?: string | null;
|
|
512
|
+
country?: string | null;
|
|
513
|
+
/** Some partners store "address_line1" instead of "street" — supported. */
|
|
514
|
+
address_line1?: string | null;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Are these two addresses the same after normalisation?
|
|
518
|
+
*
|
|
519
|
+
* Comparison rules:
|
|
520
|
+
* - Street line is normalised (case-fold, trim, expand common suffix
|
|
521
|
+
* abbreviations: St→Street, Rd→Road, Ave→Avenue, etc.)
|
|
522
|
+
* - Suburb + state are case-folded + trimmed
|
|
523
|
+
* - Postcode is left-padded to 4 digits (NT addresses with leading-zero
|
|
524
|
+
* postcodes round-trip correctly)
|
|
525
|
+
* - Country is treated as optional — when both sides have a value it
|
|
526
|
+
* must match; when either side omits it, country is ignored
|
|
527
|
+
*
|
|
528
|
+
* Designed to be conservative: returns `false` when in doubt. Partners
|
|
529
|
+
* who need looser matching (typo tolerance, fuzzy matching) should layer
|
|
530
|
+
* their own logic on top — this helper is the strict baseline.
|
|
531
|
+
*
|
|
532
|
+
* Use this in your `address.verify` handler to set the `address_match`
|
|
533
|
+
* field on the verify-result callback:
|
|
534
|
+
*
|
|
535
|
+
* ```ts
|
|
536
|
+
* import { compareAddresses } from '@oneaddress/partner-sdk';
|
|
537
|
+
*
|
|
538
|
+
* const stored = await db.lookupAddress(customer.account_number);
|
|
539
|
+
* const addressMatches = compareAddresses(stored, event.address);
|
|
540
|
+
* await fetch(callbackUrl, {
|
|
541
|
+
* method: 'POST',
|
|
542
|
+
* body: JSON.stringify({
|
|
543
|
+
* batch_id, partner_id, token,
|
|
544
|
+
* result: addressMatches ? 'match' : 'mismatch',
|
|
545
|
+
* address_match: addressMatches,
|
|
546
|
+
* }),
|
|
547
|
+
* });
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare function compareAddresses(a: ComparableAddress, b: ComparableAddress): boolean;
|
|
313
551
|
type HandlerRequest = {
|
|
314
552
|
text(): Promise<string>;
|
|
315
553
|
headers: {
|
|
@@ -324,4 +562,4 @@ type HandlerResponse = Response;
|
|
|
324
562
|
*/
|
|
325
563
|
declare function createOneAddressHandler(options: OneAddressHandlerOptions): (req: HandlerRequest) => Promise<HandlerResponse>;
|
|
326
564
|
|
|
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 };
|
|
565
|
+
export { type ComparableAddress, type EncryptedPayload, type OneAddressAccountVerifyEvent, type OneAddressAddress, type OneAddressCustomer, type OneAddressHandlerOptions, type OneAddressIdVerification, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, type SessionData, type SessionKeyShare, compareAddresses, createOneAddressHandler, decryptAddress as decrypt, decryptAddress, decryptSession, fetchLoaPublicKey, transformAddress as transform, transformAddress, validateAddress, verifySignature as verify, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
|