@oneaddress/partner-sdk 1.1.1 → 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 -218
- package/dist/chunk-2QGC7BHC.mjs +3752 -0
- package/dist/{chunk-ZZZLXF6X.mjs → chunk-O2RSPJVP.mjs} +277 -37
- package/dist/edge.d.mts +1 -3
- package/dist/edge.d.ts +1 -3
- package/dist/edge.js +4157 -50
- package/dist/edge.mjs +21 -3
- package/dist/index.d.mts +509 -9
- package/dist/index.d.ts +509 -9
- package/dist/index.js +4217 -51
- package/dist/index.mjs +23 -3
- package/dist/src-DYGFEKX6.mjs +42 -0
- package/package.json +38 -38
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Webhook timestamp / replay-window helper.
|
|
3
|
+
*
|
|
4
|
+
* OneAddress webhook dispatches carry an `X-OneAddress-Timestamp` header
|
|
5
|
+
* (Unix seconds) which is included in the signed material so it cannot be
|
|
6
|
+
* tampered with after the fact. Receivers SHOULD also enforce a freshness
|
|
7
|
+
* window so that a captured payload (e.g. from a partner's logs that later
|
|
8
|
+
* leak) cannot be replayed indefinitely.
|
|
9
|
+
*
|
|
10
|
+
* The check is intentionally tiny and dependency-free so that:
|
|
11
|
+
* - The customer app's webhook receiver and the partner app's receiver
|
|
12
|
+
* can share the exact same logic.
|
|
13
|
+
* - The official @oneaddress/partner-sdk can re-export it for external
|
|
14
|
+
* partners with no additional dependencies.
|
|
15
|
+
*
|
|
16
|
+
* The default tolerance is 5 minutes. That is wide enough to absorb realistic
|
|
17
|
+
* clock drift between OneAddress dispatch and a partner endpoint, and narrow
|
|
18
|
+
* enough that a captured webhook is not useful after the fact. The choice
|
|
19
|
+
* matches industry norms for HMAC-signed request freshness — Stripe webhooks
|
|
20
|
+
* (docs.stripe.com/webhooks/signatures), AWS SigV4 (5-minute default), and
|
|
21
|
+
* GitHub App webhooks all use comparable windows.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The default ±tolerance window enforced when none is provided. 300 seconds
|
|
25
|
+
* (5 minutes) — same value publicly documented on the OneAddress security
|
|
26
|
+
* page and in the partner integration guide.
|
|
27
|
+
*/
|
|
28
|
+
declare const DEFAULT_REPLAY_WINDOW_SECS = 300;
|
|
29
|
+
/**
|
|
30
|
+
* Returns true if `timestampHeader` represents a Unix-second value within
|
|
31
|
+
* `toleranceSecs` of the current time (i.e. abs(now - ts) <= toleranceSecs).
|
|
32
|
+
*
|
|
33
|
+
* - Returns `false` for non-numeric, empty, NaN, or non-finite inputs.
|
|
34
|
+
* - Returns `false` for negative values.
|
|
35
|
+
* - Compares against `nowSecs` if provided (used by tests for determinism);
|
|
36
|
+
* otherwise reads the current epoch.
|
|
37
|
+
*/
|
|
38
|
+
declare function isFreshTimestamp(timestampHeader: string | null | undefined, toleranceSecs?: number, nowSecs?: number): boolean;
|
|
39
|
+
|
|
40
|
+
/** Fields that can be turned into a blind index. */
|
|
41
|
+
type BlindIndexField = 'email' | 'name' | 'account_number';
|
|
42
|
+
/**
|
|
43
|
+
* Canonicalise a value before hashing. BOTH sides MUST normalise identically or
|
|
44
|
+
* the indexes won't match, so these rules are part of the wire contract:
|
|
45
|
+
* - `email` → NFKC, trim, lowercase.
|
|
46
|
+
* - `name` → NFKC, trim, lowercase, internal whitespace collapsed to one space.
|
|
47
|
+
* - `account_number` → NFKC, trim, ALL whitespace removed, case PRESERVED
|
|
48
|
+
* (account numbers can be case-sensitive).
|
|
49
|
+
*/
|
|
50
|
+
declare function normalizeForBlindIndex(field: BlindIndexField, value: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Compute the blind index for a single field:
|
|
53
|
+
* `base64url( HMAC-SHA256(secret, "oneaddress:bidx:<field>:<normalized>") )`.
|
|
54
|
+
*
|
|
55
|
+
* Returns the full 32-byte digest (43 base64url chars) — untruncated to keep
|
|
56
|
+
* collisions negligible.
|
|
57
|
+
*
|
|
58
|
+
* @param secret The shared per-partner blind-index secret.
|
|
59
|
+
* @param field Which field is being indexed (also domain-separates the hash).
|
|
60
|
+
* @param value The raw field value; normalised internally per {@link normalizeForBlindIndex}.
|
|
61
|
+
*/
|
|
62
|
+
declare function computeBlindIndex(secret: string, field: BlindIndexField, value: string): Promise<string>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @oneaddress/protocol
|
|
66
|
+
*
|
|
67
|
+
* Canonical wire-format types for the OneAddress webhook envelope.
|
|
68
|
+
* Version 2026.1 — frozen. Do not modify field names or remove fields.
|
|
69
|
+
*
|
|
70
|
+
* Versioning policy: versions are date-prefixed (YYYY.N).
|
|
71
|
+
* A new version is published only when a breaking change is required.
|
|
72
|
+
* Partners pin a version and trust it will not change under them.
|
|
73
|
+
*/
|
|
74
|
+
/** The current protocol version emitted by the OneAddress platform. */
|
|
75
|
+
declare const CURRENT_VERSION: "2026.1";
|
|
76
|
+
/** All protocol versions this build of the SDK recognises. */
|
|
77
|
+
declare const SUPPORTED_VERSIONS: readonly ["2026.1"];
|
|
3
78
|
|
|
4
79
|
/**
|
|
5
80
|
* @oneaddress/partner-sdk
|
|
@@ -32,6 +107,36 @@ interface OneAddressAddress {
|
|
|
32
107
|
interface OneAddressCustomer {
|
|
33
108
|
email: string;
|
|
34
109
|
name: string;
|
|
110
|
+
/** Account/policy/membership number the customer provided for this service.
|
|
111
|
+
* Null when the guest did not enter an account ref, or for account-flow
|
|
112
|
+
* dispatches that don't include this field. Use to match the customer in
|
|
113
|
+
* your records. */
|
|
114
|
+
account_number: string | null;
|
|
115
|
+
/** Additional names the customer is known by (maiden name, nickname, etc.).
|
|
116
|
+
* Always an array; empty when no aliases were provided. Partners should
|
|
117
|
+
* check `name` and each entry in `known_names` when matching their records. */
|
|
118
|
+
known_names: string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Blind-index match block — present INSTEAD of the cleartext `customer` block
|
|
122
|
+
* for partners who enabled blind-index matching in the portal. Each value is
|
|
123
|
+
* `base64url( HMAC-SHA256(yourBlindIndexSecret, normalize(field)) )`.
|
|
124
|
+
*
|
|
125
|
+
* Match a record by recomputing the same blind index over your own stored
|
|
126
|
+
* fields (with {@link computeBlindIndex} and your shared secret) and comparing
|
|
127
|
+
* for equality — no plaintext name/email/account crosses the wire and you do
|
|
128
|
+
* not need to decrypt the envelope to locate the record. The decrypted
|
|
129
|
+
* `SessionData` still carries the verified name + account number once you do
|
|
130
|
+
* decrypt.
|
|
131
|
+
*/
|
|
132
|
+
interface OneAddressCustomerMatch {
|
|
133
|
+
/** Blind index of the consumer's email, when present. */
|
|
134
|
+
email?: string;
|
|
135
|
+
/** Blind index of this partner's account_number, when present. */
|
|
136
|
+
account_number?: string;
|
|
137
|
+
/** Blind indexes of the legal name plus every known-name alias. Match if ANY
|
|
138
|
+
* of your stored name indexes appears here. */
|
|
139
|
+
names: string[];
|
|
35
140
|
}
|
|
36
141
|
interface OneAddressLOA {
|
|
37
142
|
reference: string;
|
|
@@ -41,6 +146,35 @@ interface OneAddressLOA {
|
|
|
41
146
|
signature: string;
|
|
42
147
|
algorithm: string;
|
|
43
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Server-built attestation that the customer completed identity verification
|
|
151
|
+
* before this dispatch was authorised. Always emitted alongside an
|
|
152
|
+
* `address.updated` or `address.verify` payload when OneAddress consumed a
|
|
153
|
+
* live IDV credit (Global Data DVS + biometric, or the mock equivalent in
|
|
154
|
+
* sandbox builds).
|
|
155
|
+
*
|
|
156
|
+
* This is a **cleartext** attestation — it carries no customer identity, only
|
|
157
|
+
* the fact and format of the verification. Under the zero-knowledge dispatch
|
|
158
|
+
* rules the immutable IDV handle (`verification_ref`) stays inside the
|
|
159
|
+
* encrypted `session_envelope`, exposed as {@link SessionData.id_verification_ref}
|
|
160
|
+
* after you decrypt it. Read the ref from the decrypted {@link SessionData}, not
|
|
161
|
+
* from this outer block — quote it back to OneAddress support to trace an
|
|
162
|
+
* update back to the underlying verification.
|
|
163
|
+
*
|
|
164
|
+
* Absent on test-mode dispatches that bypass the credit (BYPASS_STRIPE
|
|
165
|
+
* dev flows). Production dispatches always include it.
|
|
166
|
+
*/
|
|
167
|
+
interface OneAddressIdVerification {
|
|
168
|
+
/** Verification method — `identity_document` for a completed document +
|
|
169
|
+
* biometric check; `mock` in sandbox builds. Carries no provider identity. */
|
|
170
|
+
method: string;
|
|
171
|
+
/** ISO-8601 timestamp the verification was completed */
|
|
172
|
+
verified_at: string;
|
|
173
|
+
/** Always `true` on dispatches — partners can rely on the field's presence */
|
|
174
|
+
verified: true;
|
|
175
|
+
/** Format tag — currently `oneaddress/v1` */
|
|
176
|
+
platform: string;
|
|
177
|
+
}
|
|
44
178
|
interface OneAddressUpdateEvent {
|
|
45
179
|
event: 'address.updated';
|
|
46
180
|
version: string;
|
|
@@ -66,9 +200,29 @@ interface OneAddressUpdateEvent {
|
|
|
66
200
|
* Deduplicating on `(partner_id, dispatchId)` prevents double-processing.
|
|
67
201
|
*/
|
|
68
202
|
dispatchId: string;
|
|
69
|
-
|
|
203
|
+
/** Cleartext matching block. Present by default; ABSENT for partners who
|
|
204
|
+
* enabled blind-index matching (see `customer_match`). Exactly one of
|
|
205
|
+
* `customer` / `customer_match` is present on any given dispatch. */
|
|
206
|
+
customer?: OneAddressCustomer;
|
|
207
|
+
/** Blind-index matching block — present instead of `customer` for blind-index
|
|
208
|
+
* partners. See {@link OneAddressCustomerMatch}. */
|
|
209
|
+
customer_match?: OneAddressCustomerMatch;
|
|
70
210
|
address: OneAddressAddress;
|
|
71
|
-
|
|
211
|
+
/** The Letter of Authority. On D5 dispatches this is the structured
|
|
212
|
+
* {@link OneAddressD5LOA} recovered by decrypting `loa_encrypted`; on legacy
|
|
213
|
+
* dispatches it is the freeform {@link OneAddressLOA}. Verify with
|
|
214
|
+
* {@link verifyD5LOA} / {@link verifyLOA} respectively. */
|
|
215
|
+
loa?: OneAddressLOA | OneAddressD5LOA;
|
|
216
|
+
/** D5 only — `base64url(SHA-256(canonical LOA form))`, recomputed from the
|
|
217
|
+
* decrypted LOA. Echo this in your `/api/confirm` callback's `loa_ref` field
|
|
218
|
+
* so OneAddress can confirm you decrypted a valid signed consent. */
|
|
219
|
+
loa_ref?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Identity-verification attestation for the customer behind this update.
|
|
222
|
+
* Present on every production dispatch; absent on BYPASS_STRIPE test
|
|
223
|
+
* flows. See {@link OneAddressIdVerification}.
|
|
224
|
+
*/
|
|
225
|
+
id_verification?: OneAddressIdVerification;
|
|
72
226
|
/** Raw decrypted + parsed payload (in case fields are extended) */
|
|
73
227
|
raw: Record<string, unknown>;
|
|
74
228
|
}
|
|
@@ -82,9 +236,63 @@ interface OneAddressVerifyEvent {
|
|
|
82
236
|
dispatchId: string;
|
|
83
237
|
batch_id: number;
|
|
84
238
|
user_id: string;
|
|
85
|
-
|
|
239
|
+
/** Cleartext matching block. Present by default; ABSENT for partners who
|
|
240
|
+
* enabled blind-index matching (see `customer_match`). Exactly one of
|
|
241
|
+
* `customer` / `customer_match` is present on any given dispatch. */
|
|
242
|
+
customer?: OneAddressCustomer;
|
|
243
|
+
/** Blind-index matching block — present instead of `customer` for blind-index
|
|
244
|
+
* partners. See {@link OneAddressCustomerMatch}. */
|
|
245
|
+
customer_match?: OneAddressCustomerMatch;
|
|
86
246
|
address: OneAddressAddress;
|
|
87
|
-
|
|
247
|
+
/** The Letter of Authority. On D5 dispatches this is the structured
|
|
248
|
+
* {@link OneAddressD5LOA} recovered by decrypting `loa_encrypted`; on legacy
|
|
249
|
+
* dispatches it is the freeform {@link OneAddressLOA}. Verify with
|
|
250
|
+
* {@link verifyD5LOA} / {@link verifyLOA} respectively. */
|
|
251
|
+
loa?: OneAddressLOA | OneAddressD5LOA;
|
|
252
|
+
/** D5 only — `base64url(SHA-256(canonical LOA form))`, recomputed from the
|
|
253
|
+
* decrypted LOA. Echo this in your `/api/confirm` callback's `loa_ref` field
|
|
254
|
+
* so OneAddress can confirm you decrypted a valid signed consent. */
|
|
255
|
+
loa_ref?: string;
|
|
256
|
+
/**
|
|
257
|
+
* Identity-verification attestation for the customer behind this verify
|
|
258
|
+
* request. Present on every production dispatch; absent on BYPASS_STRIPE
|
|
259
|
+
* test flows. See {@link OneAddressIdVerification}.
|
|
260
|
+
*/
|
|
261
|
+
id_verification?: OneAddressIdVerification;
|
|
262
|
+
raw: Record<string, unknown>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Sent before a guest pays, to check whether the partner has a record of
|
|
266
|
+
* this customer at all. There is no address in this payload — the partner
|
|
267
|
+
* matches purely on name + account number. The wizard surfaces the result
|
|
268
|
+
* so the user can fix a mistyped account number before paying.
|
|
269
|
+
*
|
|
270
|
+
* Respond with `{ status: 'match' | 'no_match' | 'no_account' }`:
|
|
271
|
+
* - `match` — the name + account_number combination resolves to a record
|
|
272
|
+
* - `no_match` — the account number exists but the name doesn't line up
|
|
273
|
+
* (treated as a soft warning in the UI; user can retry)
|
|
274
|
+
* - `no_account` — no record matches the supplied account number
|
|
275
|
+
*
|
|
276
|
+
* Partners that don't implement `onAccountVerify` are silently skipped —
|
|
277
|
+
* the wizard treats the absence as "this partner doesn't support pre-pay
|
|
278
|
+
* verification" and lets the user proceed.
|
|
279
|
+
*/
|
|
280
|
+
interface OneAddressAccountVerifyEvent {
|
|
281
|
+
event: 'account.verify';
|
|
282
|
+
version: string;
|
|
283
|
+
id: string;
|
|
284
|
+
timestamp: number;
|
|
285
|
+
partner_id: string;
|
|
286
|
+
/** Unique dispatch ID from `X-OneAddress-Dispatch`. Falls back to `''` if header is absent — guard before using as idempotency key. */
|
|
287
|
+
dispatchId: string;
|
|
288
|
+
user_id: string;
|
|
289
|
+
/** Cleartext matching block. Present by default; ABSENT for partners who
|
|
290
|
+
* enabled blind-index matching (see `customer_match`). Exactly one of
|
|
291
|
+
* `customer` / `customer_match` is present on any given dispatch. */
|
|
292
|
+
customer?: OneAddressCustomer;
|
|
293
|
+
/** Blind-index matching block — present instead of `customer` for blind-index
|
|
294
|
+
* partners. See {@link OneAddressCustomerMatch}. */
|
|
295
|
+
customer_match?: OneAddressCustomerMatch;
|
|
88
296
|
raw: Record<string, unknown>;
|
|
89
297
|
}
|
|
90
298
|
interface EncryptedPayload {
|
|
@@ -119,6 +327,16 @@ interface OneAddressHandlerOptions {
|
|
|
119
327
|
webhookSecretGraceUntil?: string | number;
|
|
120
328
|
/** PKCS#8 PEM-encoded ECDH P-256 private key for address decryption */
|
|
121
329
|
privateKeyPem: string;
|
|
330
|
+
/**
|
|
331
|
+
* OPTIONAL — OneAddress's ECDSA P-256 LOA signing public key (SPKI PEM), from
|
|
332
|
+
* {@link fetchLoaPublicKey}. When set, the handler decrypts `loa_encrypted`,
|
|
333
|
+
* verifies the signed D5 LOA, and REJECTS the dispatch (500) if the signature
|
|
334
|
+
* is invalid — you never process an update whose consent proof doesn't verify.
|
|
335
|
+
* When unset, the decrypted LOA is still passed to your handler as
|
|
336
|
+
* `event.loa` (and `event.loa_ref`) for you to verify yourself. Cache the key;
|
|
337
|
+
* it only changes on a planned rotation.
|
|
338
|
+
*/
|
|
339
|
+
loaPublicKeyPem?: string;
|
|
122
340
|
/**
|
|
123
341
|
* Called when a consumer dispatches an address update to you.
|
|
124
342
|
* Return an object with optional `status` and `reference` for the confirmation callback.
|
|
@@ -135,6 +353,18 @@ interface OneAddressHandlerOptions {
|
|
|
135
353
|
match: boolean;
|
|
136
354
|
note?: string;
|
|
137
355
|
} | void>;
|
|
356
|
+
/**
|
|
357
|
+
* Called when a guest checkout runs a pre-payment account-existence
|
|
358
|
+
* check. Return `{ status: 'match' | 'no_match' | 'no_account' }`.
|
|
359
|
+
*
|
|
360
|
+
* Implement this if you support look-up by name + account number. If
|
|
361
|
+
* you don't, leave it unset and the wizard will mark your service as
|
|
362
|
+
* "skipped" — the guest can still proceed to pay and dispatch.
|
|
363
|
+
*/
|
|
364
|
+
onAccountVerify?: (event: OneAddressAccountVerifyEvent) => Promise<{
|
|
365
|
+
status: 'match' | 'no_match' | 'no_account';
|
|
366
|
+
note?: string;
|
|
367
|
+
}>;
|
|
138
368
|
/**
|
|
139
369
|
* Timestamp tolerance in seconds (default: 300 = 5 minutes).
|
|
140
370
|
* Requests with timestamps outside this window are rejected as potential replays.
|
|
@@ -219,6 +449,124 @@ declare function verifyWithGrace(rawBody: string, timestamp: string, signature:
|
|
|
219
449
|
* @param partnerId - Your partner UUID (used as HKDF info string)
|
|
220
450
|
*/
|
|
221
451
|
declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string): Promise<Record<string, unknown>>;
|
|
452
|
+
/**
|
|
453
|
+
* D5 — the structured `session_key_share` block delivered to your webhook
|
|
454
|
+
* alongside `session_envelope`. Carries `key_id` at the top level so your
|
|
455
|
+
* SDK can route to the right retained private key without parsing the wrap
|
|
456
|
+
* blob.
|
|
457
|
+
*
|
|
458
|
+
* Re-exported from `@oneaddress/crypto` for partner convenience — the type
|
|
459
|
+
* is identical on both sides of the wire.
|
|
460
|
+
*/
|
|
461
|
+
interface SessionKeyShare {
|
|
462
|
+
/** Stable identifier of the partner key OneAddress used to wrap SK_n. */
|
|
463
|
+
key_id: string;
|
|
464
|
+
/** Base64url wrap of SK_n. ECDH-ES: salt+iv+ct+tag. RSA-OAEP: the RSA ciphertext. MLKEM768X25519: salt+iv+ct+tag. */
|
|
465
|
+
wrapped_key: string;
|
|
466
|
+
/**
|
|
467
|
+
* ECDH-ES: base64url SPKI of the ephemeral public key. MLKEM768X25519:
|
|
468
|
+
* base64url of the X-Wing KEM ciphertext (1120 B). Absent for
|
|
469
|
+
* `RSA-OAEP-256+A256GCM` (key transport has no ephemeral/KEM part).
|
|
470
|
+
*/
|
|
471
|
+
epk?: string;
|
|
472
|
+
/**
|
|
473
|
+
* Wrap algorithm. `decryptSession` routes on this automatically — supply the
|
|
474
|
+
* private key matching `key_id`:
|
|
475
|
+
* - `ECDH-ES+HKDF-SHA256+A256GCM` (default) — ECDH P-256 private key.
|
|
476
|
+
* - `RSA-OAEP-256+A256GCM` — RSA private key (partners whose KMS/HSM is RSA).
|
|
477
|
+
* - `MLKEM768X25519+HKDF-SHA256+A256GCM` — post-quantum hybrid (X-Wing =
|
|
478
|
+
* ML-KEM-768 + X25519); supply your 32-byte X-Wing secret (base64).
|
|
479
|
+
*/
|
|
480
|
+
alg: 'ECDH-ES+HKDF-SHA256+A256GCM' | 'RSA-OAEP-256+A256GCM' | 'MLKEM768X25519+HKDF-SHA256+A256GCM';
|
|
481
|
+
/** Wrap-blob schema version. Always `2`. */
|
|
482
|
+
v: 2;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* D5 — the decrypted contents of a `session_envelope`.
|
|
486
|
+
*
|
|
487
|
+
* `update_uid` and `dispatch_timestamp` are OPTIONAL in `SessionData`
|
|
488
|
+
* because the wizard doesn't always know them at encrypt time; the outer
|
|
489
|
+
* webhook (the same JSON object that wraps this envelope) carries both
|
|
490
|
+
* cleartext as `update_id` and `timestamp`. Use those for correlation;
|
|
491
|
+
* use the envelope's embedded fields, when present, as the audit-grade
|
|
492
|
+
* source of truth.
|
|
493
|
+
*/
|
|
494
|
+
interface SessionData {
|
|
495
|
+
v: 2;
|
|
496
|
+
update_uid?: string;
|
|
497
|
+
dispatch_timestamp?: string;
|
|
498
|
+
verified_name: string;
|
|
499
|
+
new_address: {
|
|
500
|
+
street: string;
|
|
501
|
+
suburb: string;
|
|
502
|
+
state: string;
|
|
503
|
+
postcode: string;
|
|
504
|
+
country: string;
|
|
505
|
+
fullName?: string;
|
|
506
|
+
preferredName?: string;
|
|
507
|
+
knownNames?: string[];
|
|
508
|
+
accountReference?: string;
|
|
509
|
+
addressType?: 'residential' | 'postal' | 'both';
|
|
510
|
+
};
|
|
511
|
+
account_number: string;
|
|
512
|
+
id_verification_ref: string;
|
|
513
|
+
known_names?: string[];
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Decrypt a D5 session envelope using your retained private key matching
|
|
517
|
+
* `share.key_id`.
|
|
518
|
+
*
|
|
519
|
+
* The two-step decrypt:
|
|
520
|
+
* 1. Unwrap `share.wrapped_key` via ECDH-ES + HKDF-SHA-256 + AES-256-GCM
|
|
521
|
+
* using your private key. Recovers `SK_n`.
|
|
522
|
+
* 2. AES-256-GCM-decrypt `session_envelope` using `SK_n`. Recovers
|
|
523
|
+
* `SessionData`.
|
|
524
|
+
*
|
|
525
|
+
* The HKDF `info` string is bound to your `partner_id` for cryptographic
|
|
526
|
+
* protection against cross-partner share confusion — if you supply the
|
|
527
|
+
* wrong `partner_id`, the unwrap will fail with an authentication-tag
|
|
528
|
+
* error rather than silently returning garbled output.
|
|
529
|
+
*
|
|
530
|
+
* **Important — `key_id` routing.** Under D5 you may hold multiple
|
|
531
|
+
* private keys at once: one active (for new dispatches) plus zero-or-more
|
|
532
|
+
* retired keys still within their 90-day retention window. Look up the
|
|
533
|
+
* private key by `share.key_id` from your local key store before calling
|
|
534
|
+
* this function. The function does NOT pick a key for you.
|
|
535
|
+
*
|
|
536
|
+
* **Destroyed retired keys.** If you destroyed the private key for
|
|
537
|
+
* `share.key_id` before its `destroy_after`, you cannot decrypt this
|
|
538
|
+
* envelope. That is a key-custody breach of the partner agreement and is
|
|
539
|
+
* recorded on the OneAddress side as a `partner_key_custody_failure`
|
|
540
|
+
* outcome on the reconstruction audit log.
|
|
541
|
+
*
|
|
542
|
+
* @param share - The structured `session_key_share` block from the webhook.
|
|
543
|
+
* @param envelopeB64 - The `session_envelope` base64url string from the webhook.
|
|
544
|
+
* @param privateKeyPem - Your PKCS#8 PEM private key whose key_id matches `share.key_id`.
|
|
545
|
+
* @param partnerId - Your partner UUID (from the outer webhook payload).
|
|
546
|
+
* @returns The decrypted `SessionData`.
|
|
547
|
+
* @throws AES-GCM authentication-tag error if:
|
|
548
|
+
* - the wrong private key was supplied for `share.key_id`,
|
|
549
|
+
* - the wrong `partnerId` was supplied,
|
|
550
|
+
* - the ciphertext was tampered with or truncated,
|
|
551
|
+
* - or the share was forged.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* import { decryptSession } from '@oneaddress/partner-sdk';
|
|
555
|
+
*
|
|
556
|
+
* // Body of an address.updated webhook.
|
|
557
|
+
* const body = await req.json();
|
|
558
|
+
* const myPrivateKey = keyStore.get(body.session_key_share.key_id);
|
|
559
|
+
* if (!myPrivateKey) throw new Error(`No private key for ${body.session_key_share.key_id}`);
|
|
560
|
+
*
|
|
561
|
+
* const data = await decryptSession(
|
|
562
|
+
* body.session_key_share,
|
|
563
|
+
* body.session_envelope,
|
|
564
|
+
* myPrivateKey,
|
|
565
|
+
* body.partner_id,
|
|
566
|
+
* );
|
|
567
|
+
* // data.new_address.street, data.account_number, etc.
|
|
568
|
+
*/
|
|
569
|
+
declare function decryptSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string, partnerId: string): Promise<SessionData>;
|
|
222
570
|
/**
|
|
223
571
|
* Decrypt a OneAddress payload and immediately re-encrypt it to a different
|
|
224
572
|
* ECDH P-256 public key — for example, your internal KMS or HSM public key.
|
|
@@ -248,13 +596,60 @@ declare function decryptAddress(payload: EncryptedPayload, privateKeyPem: string
|
|
|
248
596
|
* await db.storeEncryptedAddress(event.customer.email, kmsBlob);
|
|
249
597
|
*/
|
|
250
598
|
declare function transformAddress(payload: EncryptedPayload, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
|
|
599
|
+
/**
|
|
600
|
+
* Decrypt a D5 `session_envelope` and immediately re-encrypt the recovered
|
|
601
|
+
* `SessionData` to a different ECDH P-256 public key — for example, your
|
|
602
|
+
* internal KMS or HSM public key.
|
|
603
|
+
*
|
|
604
|
+
* This is the D5 session-envelope counterpart to {@link transformAddress}
|
|
605
|
+
* (which handles the legacy single-blob `address_encrypted` path). The
|
|
606
|
+
* decrypted `SessionData` JSON is held in memory only for the duration of
|
|
607
|
+
* this call and is **never returned** to the caller — the function returns a
|
|
608
|
+
* fresh ciphertext only. Use it when you want your application tier to relay
|
|
609
|
+
* OneAddress dispatches into KMS-encrypted storage without ever handling the
|
|
610
|
+
* plaintext address.
|
|
611
|
+
*
|
|
612
|
+
* The re-encryption uses an ephemeral ECDH key pair (forward secrecy),
|
|
613
|
+
* HKDF-SHA256 with a fresh per-transform salt, and AES-256-GCM — identical to
|
|
614
|
+
* `transformAddress` but with a distinct HKDF `info` string
|
|
615
|
+
* (`oneaddress:transform-session:<partnerId>`) so the two transform paths
|
|
616
|
+
* never derive the same AES key.
|
|
617
|
+
*
|
|
618
|
+
* **Typical use case:** you receive the OneAddress webhook, call
|
|
619
|
+
* `transformSession` with `body.session_key_share`, `body.session_envelope`,
|
|
620
|
+
* your retained private key matching `share.key_id`, and your KMS public key,
|
|
621
|
+
* then store the resulting ciphertext. Decryption only happens inside your
|
|
622
|
+
* KMS/HSM, not in your application tier.
|
|
623
|
+
*
|
|
624
|
+
* @param share - The `session_key_share` block from the webhook body.
|
|
625
|
+
* @param envelopeB64 - The `session_envelope` base64url string from the webhook body.
|
|
626
|
+
* @param privateKeyPem - Your PKCS#8 PEM private key whose key_id matches `share.key_id`.
|
|
627
|
+
* @param partnerId - Your partner UUID (used as HKDF info during the session decrypt).
|
|
628
|
+
* @param recipientSpkiPem - SPKI PEM public key of the target recipient (e.g. KMS key).
|
|
629
|
+
* @returns A fresh `EncryptedPayload` encrypted to `recipientSpkiPem`.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* import { transformSession } from '@oneaddress/partner-sdk';
|
|
633
|
+
*
|
|
634
|
+
* const body = await req.json();
|
|
635
|
+
* const myPrivateKey = keyStore.get(body.session_key_share.key_id);
|
|
636
|
+
* const kmsBlob = await transformSession(
|
|
637
|
+
* body.session_key_share,
|
|
638
|
+
* body.session_envelope,
|
|
639
|
+
* myPrivateKey,
|
|
640
|
+
* body.partner_id,
|
|
641
|
+
* process.env.KMS_PUBLIC_KEY_SPKI_PEM!,
|
|
642
|
+
* );
|
|
643
|
+
* await db.storeEncryptedAddress(body.customer.email, kmsBlob);
|
|
644
|
+
*/
|
|
645
|
+
declare function transformSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string, partnerId: string, recipientSpkiPem: string): Promise<EncryptedPayload>;
|
|
251
646
|
/**
|
|
252
647
|
* Fetch OneAddress's ECDSA P-256 LOA signing public key from the well-known endpoint.
|
|
253
648
|
*
|
|
254
649
|
* Cache the result — the key only changes during a planned key rotation, which is
|
|
255
650
|
* announced in advance. Calling this on every request adds unnecessary latency.
|
|
256
651
|
*
|
|
257
|
-
* @param appBaseUrl Override the consumer-app base URL (default: https://
|
|
652
|
+
* @param appBaseUrl Override the consumer-app base URL (default: https://oneaddress.io)
|
|
258
653
|
*
|
|
259
654
|
* @example
|
|
260
655
|
* const publicKeyPem = await fetchLoaPublicKey();
|
|
@@ -271,7 +666,7 @@ declare function fetchLoaPublicKey(appBaseUrl?: string): Promise<string>;
|
|
|
271
666
|
* proof of consumer consent that stands up in an audit.
|
|
272
667
|
*
|
|
273
668
|
* The signing public key is served at:
|
|
274
|
-
* https://
|
|
669
|
+
* https://oneaddress.io/.well-known/oneaddress-loa-key.pem
|
|
275
670
|
*
|
|
276
671
|
* Fetch it once and cache it (it only changes during a planned key rotation):
|
|
277
672
|
* ```ts
|
|
@@ -294,6 +689,61 @@ declare function fetchLoaPublicKey(appBaseUrl?: string): Promise<string>;
|
|
|
294
689
|
* @returns `true` if the signature is valid; `false` if invalid or unrecognised algorithm
|
|
295
690
|
*/
|
|
296
691
|
declare function verifyLOA(loa: OneAddressLOA, publicKeyPem: string): Promise<boolean>;
|
|
692
|
+
/**
|
|
693
|
+
* The D5 Letter of Authority — the signed consent attestation recovered by
|
|
694
|
+
* decrypting `loa_encrypted`. Unlike the legacy {@link OneAddressLOA} (which
|
|
695
|
+
* carried a freeform `text` blob), the D5 LOA is structured: the signature
|
|
696
|
+
* covers the canonical pipe-joined form (see {@link canonicalD5LoaForm}).
|
|
697
|
+
*
|
|
698
|
+
* The consumer's legal name (`consumer_name`) is present here because this
|
|
699
|
+
* object only ever exists AFTER you decrypt `loa_encrypted` with your private
|
|
700
|
+
* key — it never travels in cleartext.
|
|
701
|
+
*/
|
|
702
|
+
interface OneAddressD5LOA {
|
|
703
|
+
consumer_name: string;
|
|
704
|
+
authorisation_date: string;
|
|
705
|
+
scope: string;
|
|
706
|
+
update_uid: string;
|
|
707
|
+
oneaddress_acn: string;
|
|
708
|
+
oneaddress_signature: string;
|
|
709
|
+
signature_algorithm: 'ECDSA-P256' | 'HMAC-SHA256';
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* The exact canonical string OneAddress signs for a D5 LOA — must be
|
|
713
|
+
* reproduced byte-for-byte before verifying the signature. Pipe-delimited:
|
|
714
|
+
* `consumer_name|authorisation_date|scope|update_uid|oneaddress_acn`.
|
|
715
|
+
* Mirrors `apps/customer/src/lib/loa-d5.ts → canonicalLoaForm`.
|
|
716
|
+
*/
|
|
717
|
+
declare function canonicalD5LoaForm(loa: OneAddressD5LOA): string;
|
|
718
|
+
/**
|
|
719
|
+
* Recompute the OneAddress LOA reference — `base64url(SHA-256(canonical form))`
|
|
720
|
+
* — from a decrypted D5 LOA. Echo the returned value in your `/api/confirm`
|
|
721
|
+
* callback (the `loa_ref` field) so OneAddress can verify, against the value it
|
|
722
|
+
* stored at dispatch time, that you decrypted a valid signed consent. The ref
|
|
723
|
+
* carries no name in the clear and is only computable after you decrypt the
|
|
724
|
+
* LOA. Mirrors `lib/loa-d5.ts → d5LoaRef`.
|
|
725
|
+
*/
|
|
726
|
+
declare function d5LoaRef(loa: OneAddressD5LOA): string;
|
|
727
|
+
/**
|
|
728
|
+
* Verify the ECDSA P-256 signature on a decrypted D5 Letter of Authority.
|
|
729
|
+
* Reconstructs {@link canonicalD5LoaForm} and verifies `oneaddress_signature`
|
|
730
|
+
* against OneAddress's public key (from {@link fetchLoaPublicKey}).
|
|
731
|
+
*
|
|
732
|
+
* @returns `true` if valid; `false` for an invalid signature or the deprecated
|
|
733
|
+
* HMAC algorithm (which partners cannot verify).
|
|
734
|
+
*/
|
|
735
|
+
declare function verifyD5LOA(loa: OneAddressD5LOA, publicKeyPem: string): Promise<boolean>;
|
|
736
|
+
/**
|
|
737
|
+
* Decrypt a per-partner `loa_encrypted` block (the `{ session_envelope,
|
|
738
|
+
* session_key_share }` shape emitted by OneAddress under the mandate) to
|
|
739
|
+
* recover the signed {@link OneAddressD5LOA}. Uses the same {@link decryptSession}
|
|
740
|
+
* machinery as the address envelope — the LOA is wrapped to the SAME key_id, so
|
|
741
|
+
* the private key matching `share.key_id` decrypts both.
|
|
742
|
+
*/
|
|
743
|
+
declare function decryptLoaEncrypted(loaEncrypted: {
|
|
744
|
+
session_envelope: string;
|
|
745
|
+
session_key_share: SessionKeyShare;
|
|
746
|
+
}, privateKeyPem: string, partnerId: string): Promise<OneAddressD5LOA>;
|
|
297
747
|
/**
|
|
298
748
|
* Validate and narrow the decrypted address payload to `OneAddressAddress`.
|
|
299
749
|
*
|
|
@@ -310,6 +760,56 @@ declare function verifyLOA(loa: OneAddressLOA, publicKeyPem: string): Promise<bo
|
|
|
310
760
|
* await db.updateAddress(address);
|
|
311
761
|
*/
|
|
312
762
|
declare function validateAddress(raw: unknown): OneAddressAddress;
|
|
763
|
+
/**
|
|
764
|
+
* Address shape accepted by `compareAddresses`. Mirrors `OneAddressAddress`
|
|
765
|
+
* but every field is optional so partners can pass either their stored row
|
|
766
|
+
* (with extra fields) or the decrypted webhook payload (which has the full
|
|
767
|
+
* shape) without juggling adapters.
|
|
768
|
+
*/
|
|
769
|
+
interface ComparableAddress {
|
|
770
|
+
street?: string | null;
|
|
771
|
+
suburb?: string | null;
|
|
772
|
+
state?: string | null;
|
|
773
|
+
postcode?: string | null;
|
|
774
|
+
country?: string | null;
|
|
775
|
+
/** Some partners store "address_line1" instead of "street" — supported. */
|
|
776
|
+
address_line1?: string | null;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Are these two addresses the same after normalisation?
|
|
780
|
+
*
|
|
781
|
+
* Comparison rules:
|
|
782
|
+
* - Street line is normalised (case-fold, trim, expand common suffix
|
|
783
|
+
* abbreviations: St→Street, Rd→Road, Ave→Avenue, etc.)
|
|
784
|
+
* - Suburb + state are case-folded + trimmed
|
|
785
|
+
* - Postcode is left-padded to 4 digits (NT addresses with leading-zero
|
|
786
|
+
* postcodes round-trip correctly)
|
|
787
|
+
* - Country is treated as optional — when both sides have a value it
|
|
788
|
+
* must match; when either side omits it, country is ignored
|
|
789
|
+
*
|
|
790
|
+
* Designed to be conservative: returns `false` when in doubt. Partners
|
|
791
|
+
* who need looser matching (typo tolerance, fuzzy matching) should layer
|
|
792
|
+
* their own logic on top — this helper is the strict baseline.
|
|
793
|
+
*
|
|
794
|
+
* Use this in your `address.verify` handler to set the `address_match`
|
|
795
|
+
* field on the verify-result callback:
|
|
796
|
+
*
|
|
797
|
+
* ```ts
|
|
798
|
+
* import { compareAddresses } from '@oneaddress/partner-sdk';
|
|
799
|
+
*
|
|
800
|
+
* const stored = await db.lookupAddress(customer.account_number);
|
|
801
|
+
* const addressMatches = compareAddresses(stored, event.address);
|
|
802
|
+
* await fetch(callbackUrl, {
|
|
803
|
+
* method: 'POST',
|
|
804
|
+
* body: JSON.stringify({
|
|
805
|
+
* batch_id, partner_id, token,
|
|
806
|
+
* result: addressMatches ? 'match' : 'mismatch',
|
|
807
|
+
* address_match: addressMatches,
|
|
808
|
+
* }),
|
|
809
|
+
* });
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
declare function compareAddresses(a: ComparableAddress, b: ComparableAddress): boolean;
|
|
313
813
|
type HandlerRequest = {
|
|
314
814
|
text(): Promise<string>;
|
|
315
815
|
headers: {
|
|
@@ -324,4 +824,4 @@ type HandlerResponse = Response;
|
|
|
324
824
|
*/
|
|
325
825
|
declare function createOneAddressHandler(options: OneAddressHandlerOptions): (req: HandlerRequest) => Promise<HandlerResponse>;
|
|
326
826
|
|
|
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 };
|
|
827
|
+
export { type BlindIndexField, CURRENT_VERSION, type ComparableAddress, DEFAULT_REPLAY_WINDOW_SECS, type EncryptedPayload, type OneAddressAccountVerifyEvent, type OneAddressAddress, type OneAddressCustomer, type OneAddressCustomerMatch, type OneAddressD5LOA, type OneAddressHandlerOptions, type OneAddressIdVerification, type OneAddressLOA, type OneAddressUpdateEvent, type OneAddressVerifyEvent, SUPPORTED_VERSIONS, type SessionData, type SessionKeyShare, canonicalD5LoaForm, compareAddresses, computeBlindIndex, createOneAddressHandler, d5LoaRef, decryptAddress as decrypt, decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, isFreshTimestamp, normalizeForBlindIndex, transformAddress as transform, transformAddress, transformSession, validateAddress, verifySignature as verify, verifyD5LOA, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
|