@oneaddress/partner-sdk 1.6.3 → 1.8.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 +70 -0
- package/README.md +102 -5
- package/dist/{chunk-TAZD6PFZ.mjs → chunk-O2D5XGSN.mjs} +62 -31
- package/dist/{chunk-3VG6MTRH.mjs → chunk-PUB6ZVJ2.mjs} +223 -9
- package/dist/edge.js +82 -38
- package/dist/edge.mjs +2 -2
- package/dist/index.d.mts +228 -13
- package/dist/index.d.ts +228 -13
- package/dist/index.js +287 -38
- package/dist/index.mjs +10 -2
- package/dist/{src-ESYTJ2EY.mjs → src-UOJOUUGB.mjs} +1 -1
- package/package.json +6 -1
package/dist/edge.js
CHANGED
|
@@ -3853,6 +3853,9 @@ function b64UrlToBytes(b64url) {
|
|
|
3853
3853
|
const pad = b64url.length % 4 === 0 ? "" : "=".repeat(4 - b64url.length % 4);
|
|
3854
3854
|
return b64ToBytes3(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
|
|
3855
3855
|
}
|
|
3856
|
+
function toArrayBuffer(bytes) {
|
|
3857
|
+
return bytes.slice().buffer;
|
|
3858
|
+
}
|
|
3856
3859
|
async function encryptSessionForPartner(session_data, partner) {
|
|
3857
3860
|
return encryptEnvelopeForPartner(session_data, partner);
|
|
3858
3861
|
}
|
|
@@ -3976,6 +3979,20 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3976
3979
|
if (share.v !== 2) {
|
|
3977
3980
|
throw new Error(`decryptSession: unsupported share version ${share.v}`);
|
|
3978
3981
|
}
|
|
3982
|
+
const ops = typeof privateKeyB64 === "string" ? null : privateKeyB64;
|
|
3983
|
+
if (ops) {
|
|
3984
|
+
if (share.alg === "MLKEM768X25519+HKDF-SHA256+A256GCM") {
|
|
3985
|
+
throw new Error(
|
|
3986
|
+
`decryptSession: key source "${ops.name}" performs private-key operations without releasing the key, which no KMS offers for ML-KEM. Use an exportable key source for post-quantum shares.`
|
|
3987
|
+
);
|
|
3988
|
+
}
|
|
3989
|
+
const needed = share.alg === "RSA-OAEP-256+A256GCM" ? "decryptRsaOaep" : "deriveSharedSecret";
|
|
3990
|
+
if (typeof ops[needed] !== "function") {
|
|
3991
|
+
throw new Error(
|
|
3992
|
+
`decryptSession: key source "${ops.name}" cannot do ${needed}, which ${share.alg} requires.`
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3979
3996
|
let skRawBuf;
|
|
3980
3997
|
if (share.alg === "MLKEM768X25519+HKDF-SHA256+A256GCM") {
|
|
3981
3998
|
if (!share.epk) {
|
|
@@ -3997,41 +4014,55 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
|
|
|
3997
4014
|
const wrapKey = await subtle().importKey("raw", wrapKeyRaw, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
3998
4015
|
skRawBuf = await subtle().decrypt({ name: "AES-GCM", iv: wrapIv }, wrapKey, wrappedSkBytes);
|
|
3999
4016
|
} else if (share.alg === "RSA-OAEP-256+A256GCM") {
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4017
|
+
if (ops) {
|
|
4018
|
+
skRawBuf = toArrayBuffer(await ops.decryptRsaOaep(b64UrlToBytes(share.wrapped_key)));
|
|
4019
|
+
} else {
|
|
4020
|
+
const rsaPrivateKey = await subtle().importKey(
|
|
4021
|
+
"pkcs8",
|
|
4022
|
+
keyB64ToBytes(privateKeyB64),
|
|
4023
|
+
{ name: "RSA-OAEP", hash: "SHA-256" },
|
|
4024
|
+
false,
|
|
4025
|
+
["decrypt"]
|
|
4026
|
+
);
|
|
4027
|
+
skRawBuf = await subtle().decrypt(
|
|
4028
|
+
{ name: "RSA-OAEP" },
|
|
4029
|
+
rsaPrivateKey,
|
|
4030
|
+
b64UrlToBytes(share.wrapped_key)
|
|
4031
|
+
);
|
|
4032
|
+
}
|
|
4012
4033
|
} else {
|
|
4013
4034
|
if (!share.epk) {
|
|
4014
4035
|
throw new Error("decryptSession: ECDH-ES share missing epk");
|
|
4015
4036
|
}
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4037
|
+
let sharedSecret;
|
|
4038
|
+
if (ops) {
|
|
4039
|
+
sharedSecret = toArrayBuffer(await ops.deriveSharedSecret(b64UrlToBytes(share.epk)));
|
|
4040
|
+
if (sharedSecret.byteLength !== 32) {
|
|
4041
|
+
throw new Error(
|
|
4042
|
+
`decryptSession: key source "${ops.name}" returned a ${sharedSecret.byteLength}-byte shared secret; P-256 ECDH is 32 bytes with no KDF applied.`
|
|
4043
|
+
);
|
|
4044
|
+
}
|
|
4045
|
+
} else {
|
|
4046
|
+
const privateKey = await subtle().importKey(
|
|
4047
|
+
"pkcs8",
|
|
4048
|
+
keyB64ToBytes(privateKeyB64),
|
|
4049
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
4050
|
+
false,
|
|
4051
|
+
["deriveBits"]
|
|
4052
|
+
);
|
|
4053
|
+
const ephemeralPub = await subtle().importKey(
|
|
4054
|
+
"spki",
|
|
4055
|
+
b64UrlToBytes(share.epk),
|
|
4056
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
4057
|
+
false,
|
|
4058
|
+
[]
|
|
4059
|
+
);
|
|
4060
|
+
sharedSecret = await subtle().deriveBits(
|
|
4061
|
+
{ name: "ECDH", public: ephemeralPub },
|
|
4062
|
+
privateKey,
|
|
4063
|
+
256
|
|
4064
|
+
);
|
|
4065
|
+
}
|
|
4035
4066
|
const wrappedBytes = b64UrlToBytes(share.wrapped_key);
|
|
4036
4067
|
if (wrappedBytes.length < WRAP_SALT_LENGTH + WRAP_IV_LENGTH + 16) {
|
|
4037
4068
|
throw new Error("decryptSession: wrapped_key too short");
|
|
@@ -4296,6 +4327,9 @@ function findMatchingStoredName(providedNames, storedCandidates) {
|
|
|
4296
4327
|
return storedCandidates.find((candidate) => namePoolMatches(providedNames, candidate));
|
|
4297
4328
|
}
|
|
4298
4329
|
|
|
4330
|
+
// src/outbox.ts
|
|
4331
|
+
var import_node_crypto = require("crypto");
|
|
4332
|
+
|
|
4299
4333
|
// src/index.ts
|
|
4300
4334
|
function verifySignature(rawBody, signature, timestamp, secret) {
|
|
4301
4335
|
if (!/^[0-9a-f]{64}$/i.test(signature)) return false;
|
|
@@ -4381,7 +4415,12 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
|
4381
4415
|
}
|
|
4382
4416
|
async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId) {
|
|
4383
4417
|
const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
4384
|
-
return decryptSessionCrypto(
|
|
4418
|
+
return decryptSessionCrypto(
|
|
4419
|
+
share,
|
|
4420
|
+
envelopeB64,
|
|
4421
|
+
typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
|
|
4422
|
+
partnerId
|
|
4423
|
+
);
|
|
4385
4424
|
}
|
|
4386
4425
|
async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
4387
4426
|
const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
|
|
@@ -4647,7 +4686,7 @@ async function sendVerifyResult(params) {
|
|
|
4647
4686
|
throw new Error(`[OneAddress SDK] verify-result callback to ${callbackUrl} failed: HTTP ${res.status}`);
|
|
4648
4687
|
}
|
|
4649
4688
|
}
|
|
4650
|
-
var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test"];
|
|
4689
|
+
var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test", "address.test-dispatch"];
|
|
4651
4690
|
var warnedUnhandledEvents = /* @__PURE__ */ new Set();
|
|
4652
4691
|
function createOneAddressHandler(options) {
|
|
4653
4692
|
const {
|
|
@@ -4920,16 +4959,16 @@ function createOneAddressHandler(options) {
|
|
|
4920
4959
|
headers: { "Content-Type": "application/json" }
|
|
4921
4960
|
});
|
|
4922
4961
|
}
|
|
4923
|
-
if (body.event === "address.test" && onTest) {
|
|
4962
|
+
if ((body.event === "address.test" || body.event === "address.test-dispatch") && onTest) {
|
|
4924
4963
|
if (!isD5Body(body)) {
|
|
4925
|
-
return new Response(JSON.stringify({ error: "
|
|
4964
|
+
return new Response(JSON.stringify({ error: "a test dispatch requires a session envelope" }), {
|
|
4926
4965
|
status: 400,
|
|
4927
4966
|
headers: { "Content-Type": "application/json" }
|
|
4928
4967
|
});
|
|
4929
4968
|
}
|
|
4930
4969
|
const d5 = await buildD5Pieces(body, partnerId);
|
|
4931
4970
|
await onTest({
|
|
4932
|
-
event:
|
|
4971
|
+
event: body.event,
|
|
4933
4972
|
index: typeof body.index === "number" ? body.index : void 0,
|
|
4934
4973
|
total: typeof body.total === "number" ? body.total : void 0,
|
|
4935
4974
|
verification_id: typeof body.verification_id === "string" ? body.verification_id : void 0,
|
|
@@ -4948,12 +4987,17 @@ function createOneAddressHandler(options) {
|
|
|
4948
4987
|
const callbackFor = {
|
|
4949
4988
|
"address.verify": onVerify,
|
|
4950
4989
|
"account.verify": onAccountVerify,
|
|
4951
|
-
"address.test": onTest
|
|
4990
|
+
"address.test": onTest,
|
|
4991
|
+
// Same callback as address.test: both test variants route to onTest, so
|
|
4992
|
+
// an unwired stress-test event must name onTest too — not fall through
|
|
4993
|
+
// to the "upgrade the SDK" remedy, which cannot help (marlowe-reports#126).
|
|
4994
|
+
"address.test-dispatch": onTest
|
|
4952
4995
|
};
|
|
4953
4996
|
const callbackNameFor = {
|
|
4954
4997
|
"address.verify": "onVerify",
|
|
4955
4998
|
"account.verify": "onAccountVerify",
|
|
4956
|
-
"address.test": "onTest"
|
|
4999
|
+
"address.test": "onTest",
|
|
5000
|
+
"address.test-dispatch": "onTest"
|
|
4957
5001
|
};
|
|
4958
5002
|
const unwired = evt in callbackFor && !callbackFor[evt] ? callbackNameFor[evt] : null;
|
|
4959
5003
|
if (!warnedUnhandledEvents.has(evt)) {
|
package/dist/edge.mjs
CHANGED
|
@@ -20,13 +20,13 @@ import {
|
|
|
20
20
|
verifyLOA,
|
|
21
21
|
verifySignature,
|
|
22
22
|
verifyWithGrace
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-PUB6ZVJ2.mjs";
|
|
24
24
|
import {
|
|
25
25
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
26
26
|
computeBlindIndex,
|
|
27
27
|
isFreshTimestamp,
|
|
28
28
|
normalizeForBlindIndex
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-O2D5XGSN.mjs";
|
|
30
30
|
export {
|
|
31
31
|
CURRENT_VERSION,
|
|
32
32
|
DEFAULT_REPLAY_WINDOW_SECS,
|
package/dist/index.d.mts
CHANGED
|
@@ -37,6 +37,73 @@ declare const DEFAULT_REPLAY_WINDOW_SECS = 300;
|
|
|
37
37
|
*/
|
|
38
38
|
declare function isFreshTimestamp(timestampHeader: string | null | undefined, toleranceSecs?: number, nowSecs?: number): boolean;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The private-key half of `decryptSession`, delegated to whatever holds the key.
|
|
42
|
+
*
|
|
43
|
+
* ── WHY THIS EXISTS, AND WHY IT IS NOT SIMPLY "RETURN THE KEY" ──────────────
|
|
44
|
+
*
|
|
45
|
+
* A recipient large enough to have a security review will not put an unwrapped
|
|
46
|
+
* private key in an environment variable or on a disk, which is what a PEM is.
|
|
47
|
+
* They keep it in a KMS or an HSM, and the entire value of doing so is that the
|
|
48
|
+
* key **cannot be exported**. So a key source that answers "here is the PEM"
|
|
49
|
+
* cannot be backed by a KMS at all: the two designs are mutually exclusive, not
|
|
50
|
+
* merely inconvenient together.
|
|
51
|
+
*
|
|
52
|
+
* What a KMS DOES offer is the operation rather than the key, so that is what
|
|
53
|
+
* this interface asks for. The cut is deliberately at the smallest possible
|
|
54
|
+
* step - the one operation that genuinely requires the private key - and
|
|
55
|
+
* everything after it (HKDF, the AES-GCM unwrap, the envelope decrypt) stays
|
|
56
|
+
* here, in one implementation, exercised by the canonical vectors.
|
|
57
|
+
*
|
|
58
|
+
* The tempting alternative is to let the delegate return SK_n and be done. It
|
|
59
|
+
* is worse: the ECDH path would then have to reproduce the HKDF derivation and
|
|
60
|
+
* the unwrap on the far side of the interface, so every implementer would be
|
|
61
|
+
* re-implementing this file's crypto from its docstring, and a mistake there
|
|
62
|
+
* fails as an auth-tag error indistinguishable from a wrong key.
|
|
63
|
+
*
|
|
64
|
+
* ── WHAT EACH METHOD COSTS THE HOLDER ──────────────────────────────────────
|
|
65
|
+
*
|
|
66
|
+
* These are not equally protective, and a recipient choosing between wrap
|
|
67
|
+
* algorithms should know which they are buying:
|
|
68
|
+
*
|
|
69
|
+
* - `decryptRsaOaep` is the strongest. SK_n is recovered INSIDE the KMS and
|
|
70
|
+
* only SK_n comes back. Neither the private key nor any long-lived secret
|
|
71
|
+
* ever exists in the receiver's memory.
|
|
72
|
+
* - `deriveSharedSecret` is weaker but still sound. The private key never
|
|
73
|
+
* leaves the KMS, but the per-dispatch ECDH shared secret does come back,
|
|
74
|
+
* and anyone holding it can derive that one dispatch's wrap key. It is
|
|
75
|
+
* scoped to a single dispatch and useless for any other.
|
|
76
|
+
*
|
|
77
|
+
* There is deliberately no method for the post-quantum X-Wing path. No
|
|
78
|
+
* mainstream KMS implements ML-KEM decapsulation, so a delegate cannot honestly
|
|
79
|
+
* offer it, and `decryptSession` refuses that combination with a message saying
|
|
80
|
+
* so rather than falling back to something the operator did not ask for.
|
|
81
|
+
*
|
|
82
|
+
* Implementations MUST NOT log, cache or persist anything they return.
|
|
83
|
+
*/
|
|
84
|
+
interface PrivateKeyOperations {
|
|
85
|
+
/** Names the backing source, for error messages only. Never a credential. */
|
|
86
|
+
readonly name: string;
|
|
87
|
+
/**
|
|
88
|
+
* ECDH-ES: the raw shared secret for `epkSpki`, exactly as WebCrypto's
|
|
89
|
+
* `deriveBits({name:'ECDH', public}, priv, 256)` would return it - the X
|
|
90
|
+
* coordinate of the shared point, 32 bytes for P-256, with NO KDF applied.
|
|
91
|
+
*
|
|
92
|
+
* AWS KMS `DeriveSharedSecret` returns precisely this, which is what makes
|
|
93
|
+
* the two interchangeable. A KMS that applied its own KDF first would not be
|
|
94
|
+
* usable here and would fail as an auth-tag error, so the "no KDF" part is a
|
|
95
|
+
* requirement rather than a description.
|
|
96
|
+
*
|
|
97
|
+
* @param epkSpki The ephemeral public key from the share, DER SPKI encoded.
|
|
98
|
+
*/
|
|
99
|
+
deriveSharedSecret?(epkSpki: Uint8Array): Promise<Uint8Array>;
|
|
100
|
+
/**
|
|
101
|
+
* RSA-OAEP-SHA256: unwrap `wrappedKey` to SK_n directly.
|
|
102
|
+
*
|
|
103
|
+
* @param wrappedKey The raw `wrapped_key` bytes from the share.
|
|
104
|
+
*/
|
|
105
|
+
decryptRsaOaep?(wrappedKey: Uint8Array): Promise<Uint8Array>;
|
|
106
|
+
}
|
|
40
107
|
/** Fields that can be turned into a blind index. */
|
|
41
108
|
type BlindIndexField = 'email' | 'name' | 'account_number';
|
|
42
109
|
/**
|
|
@@ -89,6 +156,142 @@ declare const CURRENT_VERSION: "2026.1";
|
|
|
89
156
|
/** All protocol versions this build of the SDK recognises. */
|
|
90
157
|
declare const SUPPORTED_VERSIONS: readonly ["2026.1"];
|
|
91
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Draining the outbox.
|
|
161
|
+
*
|
|
162
|
+
* The receiver writes each delivered update into a table and stamps
|
|
163
|
+
* `written_at`. It never stamps `processed_at` — that column belongs to you,
|
|
164
|
+
* and the gap between the two is what makes the backlog metric mean anything.
|
|
165
|
+
* Until now the SDK gave you no help crossing that gap, so every integrator
|
|
166
|
+
* wrote their own polling loop and rediscovered the same three problems.
|
|
167
|
+
*
|
|
168
|
+
* ── WHY THIS IS NOT A `SELECT ... WHERE processed_at IS NULL` ────────────────
|
|
169
|
+
*
|
|
170
|
+
* That query is correct with exactly one consumer and quietly wrong with two.
|
|
171
|
+
* Both read the same rows, both apply the same address, and whichever finishes
|
|
172
|
+
* second overwrites the first. On a CRM that fires side effects on write — a
|
|
173
|
+
* confirmation email, an audit entry, a downstream sync — the duplicate is
|
|
174
|
+
* visible to the customer.
|
|
175
|
+
*
|
|
176
|
+
* So a claim has to be atomic against other consumers, which is dialect
|
|
177
|
+
* territory: `FOR UPDATE SKIP LOCKED` on postgres, `READPAST` on SQL Server,
|
|
178
|
+
* a lock-and-reread on MySQL (whose UPDATE cannot reference its own table in a
|
|
179
|
+
* subquery, and has no RETURNING). Getting that right is the work, and it is
|
|
180
|
+
* the part an integrator should not have to do twice.
|
|
181
|
+
*
|
|
182
|
+
* ── A CLAIM IS A LEASE, NOT A LOCK ──────────────────────────────────────────
|
|
183
|
+
*
|
|
184
|
+
* A consumer that dies mid-batch must not strand its rows forever. So a claim
|
|
185
|
+
* writes `oa_claimed_at` and expires: once `leaseSeconds` have passed the row
|
|
186
|
+
* is claimable again. That is why the handler must be idempotent — a lease that
|
|
187
|
+
* expires while the handler is still running means the row can be claimed
|
|
188
|
+
* twice, and no timeout is long enough to make that impossible.
|
|
189
|
+
*
|
|
190
|
+
* ── THE COLUMNS ARE OURS AND ARE PREFIXED ───────────────────────────────────
|
|
191
|
+
*
|
|
192
|
+
* `oa_claimed_at`, `oa_claim_token` and `oa_attempts` are added by
|
|
193
|
+
* {@link OutboxConsumer.ensureSchema}. They carry the `oa_` prefix because this
|
|
194
|
+
* consumer is also useful over a table you wrote yourself, where a bare
|
|
195
|
+
* `claimed_at` could already mean something.
|
|
196
|
+
*/
|
|
197
|
+
/** The databases the receiver supports, and therefore the ones this drains. */
|
|
198
|
+
type OutboxDialect = 'postgres' | 'mysql' | 'sqlite' | 'mssql';
|
|
199
|
+
/** Run parameterised SQL and return the result rows. Your pool, your driver. */
|
|
200
|
+
type OutboxQueryFn = (sql: string, params: unknown[]) => Promise<Record<string, unknown>[]>;
|
|
201
|
+
interface OutboxRow {
|
|
202
|
+
dispatchId: string;
|
|
203
|
+
event: string;
|
|
204
|
+
/** Every column the row carries, as the driver returned it. */
|
|
205
|
+
fields: Record<string, unknown>;
|
|
206
|
+
/** How many times a handler has already failed on this row. */
|
|
207
|
+
attempts: number;
|
|
208
|
+
}
|
|
209
|
+
interface OutboxBacklog {
|
|
210
|
+
/** Written, not yet processed. The number to graph. */
|
|
211
|
+
pending: number;
|
|
212
|
+
/** Age of the oldest unprocessed row. The number to alert on. */
|
|
213
|
+
oldestPendingAgeSeconds: number | null;
|
|
214
|
+
/** Rows parked because they hit `maxAttempts`. Zero unless you set it. */
|
|
215
|
+
stuck: number;
|
|
216
|
+
}
|
|
217
|
+
/** The lease columns, in the order `ensureSchema` adds them. */
|
|
218
|
+
declare const OUTBOX_LEASE_COLUMNS: readonly ["oa_claimed_at", "oa_claim_token", "oa_attempts"];
|
|
219
|
+
/**
|
|
220
|
+
* Bind a timestamp in the form the column will accept.
|
|
221
|
+
*
|
|
222
|
+
* An ISO-8601 string is the obvious thing and it is wrong on MySQL: a
|
|
223
|
+
* `DATETIME` rejects `2026-08-01T19:13:40.590Z` outright in strict mode,
|
|
224
|
+
* because it wants `YYYY-MM-DD HH:MM:SS` with a space and no zone. Everything
|
|
225
|
+
* is normalised to UTC first — a zone-less column carries no offset, so the
|
|
226
|
+
* only way two processes agree on what a stored value means is to agree that
|
|
227
|
+
* it is always UTC.
|
|
228
|
+
*
|
|
229
|
+
* This is deliberately identical to the receiver's own `toDbTimestamp`, and a
|
|
230
|
+
* guard in this repo fails if the two ever disagree. They cannot be one module:
|
|
231
|
+
* the receiver is not published and this package is.
|
|
232
|
+
*/
|
|
233
|
+
declare function toOutboxTimestamp(dialect: OutboxDialect, when: Date | number): string;
|
|
234
|
+
/**
|
|
235
|
+
* Read a timestamp back, and the reason this is not `Date.parse`.
|
|
236
|
+
*
|
|
237
|
+
* The binder above agrees that a zone-less column is always UTC. `Date.parse`
|
|
238
|
+
* does not hold up the other half of that agreement: ECMA-262 mandates that a
|
|
239
|
+
* date-time form with NO offset is read as LOCAL time. So a row stamped in UTC
|
|
240
|
+
* and read on a UTC+8 host comes back eight hours in the past, which skews the
|
|
241
|
+
* oldest-pending age by the deployment's whole offset — inflating it east of
|
|
242
|
+
* Greenwich (the alert screams and gets muted) and making it negative to the
|
|
243
|
+
* west (the alert can never fire, and a stuck outbox looks permanently
|
|
244
|
+
* healthy). CI never catches it, because CI runs UTC and the skew is exactly
|
|
245
|
+
* zero there.
|
|
246
|
+
*/
|
|
247
|
+
declare function fromOutboxTimestamp(raw: unknown): number | null;
|
|
248
|
+
interface OutboxConsumerOptions {
|
|
249
|
+
query: OutboxQueryFn;
|
|
250
|
+
/** Defaults to `postgres`, matching the rest of this SDK. */
|
|
251
|
+
dialect?: OutboxDialect;
|
|
252
|
+
/** Defaults to `oneaddress_updates`, which is what the receiver writes. */
|
|
253
|
+
table?: string;
|
|
254
|
+
/** Rows per claim. Defaults to 50. */
|
|
255
|
+
batchSize?: number;
|
|
256
|
+
/**
|
|
257
|
+
* How long a claim is held before another consumer may take the row.
|
|
258
|
+
* Defaults to 300 (five minutes). Set it comfortably longer than your
|
|
259
|
+
* slowest handler: an expired lease means the row gets processed twice.
|
|
260
|
+
*/
|
|
261
|
+
leaseSeconds?: number;
|
|
262
|
+
/**
|
|
263
|
+
* Stop claiming a row after this many failed handler runs. Defaults to `0`,
|
|
264
|
+
* meaning never stop, and that default is deliberate — giving up on a row is
|
|
265
|
+
* an address that never reaches your system, which is worse than a loop you
|
|
266
|
+
* can see. Set it only once you are alerting on `backlog().stuck`.
|
|
267
|
+
*/
|
|
268
|
+
maxAttempts?: number;
|
|
269
|
+
/** Injectable clock, for tests. */
|
|
270
|
+
now?: () => number;
|
|
271
|
+
}
|
|
272
|
+
interface OutboxConsumer {
|
|
273
|
+
/** Add the lease columns if they are absent. Safe to call on every boot. */
|
|
274
|
+
ensureSchema(): Promise<{
|
|
275
|
+
added: string[];
|
|
276
|
+
}>;
|
|
277
|
+
/** Atomically take up to `batchSize` rows. Other consumers skip them. */
|
|
278
|
+
claimBatch(): Promise<OutboxRow[]>;
|
|
279
|
+
/** Done. Stamps `processed_at` and releases the claim. */
|
|
280
|
+
markProcessed(dispatchId: string): Promise<void>;
|
|
281
|
+
/** Failed. Records the reason, counts the attempt, releases for a retry. */
|
|
282
|
+
markFailed(dispatchId: string, error: unknown): Promise<void>;
|
|
283
|
+
/** Put a row back untouched — for a clean shutdown mid-batch. */
|
|
284
|
+
release(dispatchId: string): Promise<void>;
|
|
285
|
+
/** Claim a batch, run `handler` per row, and mark each one. */
|
|
286
|
+
process(handler: (row: OutboxRow) => Promise<void> | void): Promise<{
|
|
287
|
+
processed: number;
|
|
288
|
+
failed: number;
|
|
289
|
+
}>;
|
|
290
|
+
/** The numbers to graph and alert on. */
|
|
291
|
+
backlog(): Promise<OutboxBacklog>;
|
|
292
|
+
}
|
|
293
|
+
declare function createOutboxConsumer(opts: OutboxConsumerOptions): OutboxConsumer;
|
|
294
|
+
|
|
92
295
|
/**
|
|
93
296
|
* @oneaddress/partner-sdk
|
|
94
297
|
*
|
|
@@ -444,11 +647,15 @@ interface OneAddressHandlerOptions {
|
|
|
444
647
|
note?: string;
|
|
445
648
|
}>;
|
|
446
649
|
/**
|
|
447
|
-
* Connection-verification test records (`address.test`
|
|
650
|
+
* Connection-verification and stress-test records (`address.test` and
|
|
651
|
+
* `address.test-dispatch`).
|
|
448
652
|
*
|
|
449
|
-
* OneAddress sends five
|
|
450
|
-
* ECDH-encrypted dispatches carrying fabricated TEST identities,
|
|
451
|
-
* decrypt and relay back so both sides can confirm the pipe works
|
|
653
|
+
* OneAddress sends five `address.test` records before a partner goes live:
|
|
654
|
+
* real signed, ECDH-encrypted dispatches carrying fabricated TEST identities,
|
|
655
|
+
* which you decrypt and relay back so both sides can confirm the pipe works
|
|
656
|
+
* end to end. The admin stress test sends `address.test-dispatch`, which is
|
|
657
|
+
* the SAME shape (a fabricated, encrypted test record) — both arrive here, and
|
|
658
|
+
* `event` tells them apart if you want to count stress dispatches separately.
|
|
452
659
|
*
|
|
453
660
|
* ── WHY THIS IS A SEPARATE CALLBACK AND NOT `onUpdate` ─────────────────────
|
|
454
661
|
*
|
|
@@ -459,11 +666,11 @@ interface OneAddressHandlerOptions {
|
|
|
459
666
|
*
|
|
460
667
|
* ── IF YOU DO NOT IMPLEMENT IT ─────────────────────────────────────────────
|
|
461
668
|
*
|
|
462
|
-
* `address.test`
|
|
463
|
-
* warning naming this option. That combination was
|
|
464
|
-
* marlowe-reports#125: the skip was correct, the silence was
|
|
465
|
-
* records were skipped, the partner saw five clean 200s, and
|
|
466
|
-
* surfaced was somebody decrypting the raw bodies by hand.
|
|
669
|
+
* `address.test` / `address.test-dispatch` are acknowledged with 200 and
|
|
670
|
+
* skipped, and the SDK logs a warning naming this option. That combination was
|
|
671
|
+
* the defect in marlowe-reports#125: the skip was correct, the silence was
|
|
672
|
+
* not. Five test records were skipped, the partner saw five clean 200s, and
|
|
673
|
+
* the only way it surfaced was somebody decrypting the raw bodies by hand.
|
|
467
674
|
*
|
|
468
675
|
* Implement it if you intend to complete connection verification through the
|
|
469
676
|
* SDK rather than by hand.
|
|
@@ -545,6 +752,7 @@ interface IdempotencyStore {
|
|
|
545
752
|
*/
|
|
546
753
|
complete?(dispatchId: string): Promise<void>;
|
|
547
754
|
}
|
|
755
|
+
|
|
548
756
|
/**
|
|
549
757
|
* A SQL-backed {@link IdempotencyStore} with an atomic claim, over whatever
|
|
550
758
|
* driver you already use.
|
|
@@ -807,7 +1015,7 @@ interface SessionData {
|
|
|
807
1015
|
* );
|
|
808
1016
|
* // data.new_address.street, data.account_number, etc.
|
|
809
1017
|
*/
|
|
810
|
-
declare function decryptSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string, partnerId: string): Promise<SessionData>;
|
|
1018
|
+
declare function decryptSession(share: SessionKeyShare, envelopeB64: string, privateKeyPem: string | PrivateKeyOperations, partnerId: string): Promise<SessionData>;
|
|
811
1019
|
/**
|
|
812
1020
|
* Decrypt a OneAddress payload and immediately re-encrypt it to a different
|
|
813
1021
|
* ECDH P-256 public key — for example, your internal KMS or HSM public key.
|
|
@@ -1075,7 +1283,7 @@ declare function verifyD5LOA(loa: OneAddressD5LOA, publicKeyPem: string): Promis
|
|
|
1075
1283
|
declare function decryptLoaEncrypted(loaEncrypted: {
|
|
1076
1284
|
session_envelope: string;
|
|
1077
1285
|
session_key_share: SessionKeyShare;
|
|
1078
|
-
}, privateKeyPem: string, partnerId: string): Promise<OneAddressD5LOA>;
|
|
1286
|
+
}, privateKeyPem: string | PrivateKeyOperations, partnerId: string): Promise<OneAddressD5LOA>;
|
|
1079
1287
|
/**
|
|
1080
1288
|
* Validate and narrow the decrypted address payload to `OneAddressAddress`.
|
|
1081
1289
|
*
|
|
@@ -1220,7 +1428,14 @@ type HandlerResponse = Response;
|
|
|
1220
1428
|
* of these, and the compiler is a better guard against that than a comment.
|
|
1221
1429
|
*/
|
|
1222
1430
|
interface OneAddressTestEvent {
|
|
1223
|
-
|
|
1431
|
+
/**
|
|
1432
|
+
* `address.test` is a single-partner connection-verification ping;
|
|
1433
|
+
* `address.test-dispatch` is the same fabricated, encrypted test record sent
|
|
1434
|
+
* by the admin stress test. Both route here — NEVER to `onUpdate` — because
|
|
1435
|
+
* the identity and address inside are fabricated. The field tells them apart
|
|
1436
|
+
* for a handler that wants to (e.g. count stress dispatches separately).
|
|
1437
|
+
*/
|
|
1438
|
+
event: 'address.test' | 'address.test-dispatch';
|
|
1224
1439
|
/** 1-based position within this verification run. */
|
|
1225
1440
|
index?: number;
|
|
1226
1441
|
/** How many records this run sends in total. */
|
|
@@ -1308,4 +1523,4 @@ interface ExpressLikeResponse {
|
|
|
1308
1523
|
*/
|
|
1309
1524
|
declare function toExpressHandler(handler: (req: HandlerRequest) => Promise<HandlerResponse>): (req: ExpressLikeRequest, res: ExpressLikeResponse) => Promise<void>;
|
|
1310
1525
|
|
|
1311
|
-
export { type AddressParts, type BlindIndexField, CURRENT_VERSION, type ComparableAddress, type ConfirmUpdateOptions, type ConfirmUpdateResult, DEFAULT_REPLAY_WINDOW_SECS, type EncryptedPayload, type ExpressLikeRequest, type ExpressLikeResponse, type IdempotencyClaim, type IdempotencyStore, type OneAddressAccountVerifyEvent, type OneAddressAddress, type OneAddressConfirmStatus, type OneAddressCustomer, type OneAddressCustomerMatch, type OneAddressD5LOA, type OneAddressHandlerOptions, type OneAddressIdVerification, type OneAddressLOA, type OneAddressTestEvent, type OneAddressUpdateEvent, type OneAddressVerifyEvent, SUPPORTED_VERSIONS, type SessionData, type SessionKeyShare, type SessionUpdateType, type VerifyResultCallbackParams, canonicalD5LoaForm, compareAddresses, computeBlindIndex, confirmUpdate, createOneAddressHandler, createSqlIdempotencyStore, d5LoaRef, decryptAddress as decrypt, decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, findMatchingStoredName, formatAddressParts, isEmailLike, isFreshTimestamp, namePoolMatches, normalizeForBlindIndex, readAddressParts, sendVerifyResult, toExpressHandler, transformAddress as transform, transformAddress, transformSession, validateAddress, verifySignature as verify, verifyD5LOA, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
|
|
1526
|
+
export { type AddressParts, type BlindIndexField, CURRENT_VERSION, type ComparableAddress, type ConfirmUpdateOptions, type ConfirmUpdateResult, DEFAULT_REPLAY_WINDOW_SECS, type EncryptedPayload, type ExpressLikeRequest, type ExpressLikeResponse, type IdempotencyClaim, type IdempotencyStore, OUTBOX_LEASE_COLUMNS, type OneAddressAccountVerifyEvent, type OneAddressAddress, type OneAddressConfirmStatus, type OneAddressCustomer, type OneAddressCustomerMatch, type OneAddressD5LOA, type OneAddressHandlerOptions, type OneAddressIdVerification, type OneAddressLOA, type OneAddressTestEvent, type OneAddressUpdateEvent, type OneAddressVerifyEvent, type OutboxBacklog, type OutboxConsumer, type OutboxConsumerOptions, type OutboxDialect, type OutboxQueryFn, type OutboxRow, type PrivateKeyOperations, SUPPORTED_VERSIONS, type SessionData, type SessionKeyShare, type SessionUpdateType, type VerifyResultCallbackParams, canonicalD5LoaForm, compareAddresses, computeBlindIndex, confirmUpdate, createOneAddressHandler, createOutboxConsumer, createSqlIdempotencyStore, d5LoaRef, decryptAddress as decrypt, decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, findMatchingStoredName, formatAddressParts, fromOutboxTimestamp, isEmailLike, isFreshTimestamp, namePoolMatches, normalizeForBlindIndex, readAddressParts, sendVerifyResult, toExpressHandler, toOutboxTimestamp, transformAddress as transform, transformAddress, transformSession, validateAddress, verifySignature as verify, verifyD5LOA, verifyWithGrace as verifyGrace, verifyLOA, verifySignature, verifyWithGrace };
|