@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/index.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");
|
|
@@ -4216,12 +4247,14 @@ var index_exports = {};
|
|
|
4216
4247
|
__export(index_exports, {
|
|
4217
4248
|
CURRENT_VERSION: () => CURRENT_VERSION,
|
|
4218
4249
|
DEFAULT_REPLAY_WINDOW_SECS: () => DEFAULT_REPLAY_WINDOW_SECS,
|
|
4250
|
+
OUTBOX_LEASE_COLUMNS: () => OUTBOX_LEASE_COLUMNS,
|
|
4219
4251
|
SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
|
|
4220
4252
|
canonicalD5LoaForm: () => canonicalD5LoaForm,
|
|
4221
4253
|
compareAddresses: () => compareAddresses,
|
|
4222
4254
|
computeBlindIndex: () => computeBlindIndex,
|
|
4223
4255
|
confirmUpdate: () => confirmUpdate,
|
|
4224
4256
|
createOneAddressHandler: () => createOneAddressHandler,
|
|
4257
|
+
createOutboxConsumer: () => createOutboxConsumer,
|
|
4225
4258
|
createSqlIdempotencyStore: () => createSqlIdempotencyStore,
|
|
4226
4259
|
d5LoaRef: () => d5LoaRef,
|
|
4227
4260
|
decrypt: () => decryptAddress2,
|
|
@@ -4231,6 +4264,7 @@ __export(index_exports, {
|
|
|
4231
4264
|
fetchLoaPublicKey: () => fetchLoaPublicKey,
|
|
4232
4265
|
findMatchingStoredName: () => findMatchingStoredName,
|
|
4233
4266
|
formatAddressParts: () => formatAddressParts,
|
|
4267
|
+
fromOutboxTimestamp: () => fromOutboxTimestamp,
|
|
4234
4268
|
isEmailLike: () => isEmailLike2,
|
|
4235
4269
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
4236
4270
|
namePoolMatches: () => namePoolMatches,
|
|
@@ -4238,6 +4272,7 @@ __export(index_exports, {
|
|
|
4238
4272
|
readAddressParts: () => readAddressParts,
|
|
4239
4273
|
sendVerifyResult: () => sendVerifyResult,
|
|
4240
4274
|
toExpressHandler: () => toExpressHandler,
|
|
4275
|
+
toOutboxTimestamp: () => toOutboxTimestamp,
|
|
4241
4276
|
transform: () => transformAddress,
|
|
4242
4277
|
transformAddress: () => transformAddress,
|
|
4243
4278
|
transformSession: () => transformSession,
|
|
@@ -4303,6 +4338,206 @@ function findMatchingStoredName(providedNames, storedCandidates) {
|
|
|
4303
4338
|
return storedCandidates.find((candidate) => namePoolMatches(providedNames, candidate));
|
|
4304
4339
|
}
|
|
4305
4340
|
|
|
4341
|
+
// src/outbox.ts
|
|
4342
|
+
var import_node_crypto = require("crypto");
|
|
4343
|
+
var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
4344
|
+
var CLAIMED_AT = "oa_claimed_at";
|
|
4345
|
+
var CLAIM_TOKEN = "oa_claim_token";
|
|
4346
|
+
var ATTEMPTS = "oa_attempts";
|
|
4347
|
+
var OUTBOX_LEASE_COLUMNS = [CLAIMED_AT, CLAIM_TOKEN, ATTEMPTS];
|
|
4348
|
+
var SPECS = {
|
|
4349
|
+
postgres: {
|
|
4350
|
+
ph: (n) => `$${n}`,
|
|
4351
|
+
timestamp: "TIMESTAMPTZ",
|
|
4352
|
+
text: "TEXT",
|
|
4353
|
+
int: "INTEGER",
|
|
4354
|
+
// Scoped to the schema this connection actually resolves the bare table
|
|
4355
|
+
// name in. Without that, a same-named table on another search-path schema
|
|
4356
|
+
// returns a superset and a genuinely missing column looks present.
|
|
4357
|
+
existingColumns: (t) => ({
|
|
4358
|
+
sql: "SELECT column_name FROM information_schema.columns WHERE table_name = $1 AND table_schema = current_schema()",
|
|
4359
|
+
params: [t]
|
|
4360
|
+
}),
|
|
4361
|
+
addColumn: (t, c, type) => `ALTER TABLE ${t} ADD COLUMN ${c} ${type} NULL`
|
|
4362
|
+
},
|
|
4363
|
+
mysql: {
|
|
4364
|
+
ph: () => "?",
|
|
4365
|
+
timestamp: "DATETIME",
|
|
4366
|
+
text: "TEXT",
|
|
4367
|
+
int: "INTEGER",
|
|
4368
|
+
existingColumns: (t) => ({
|
|
4369
|
+
sql: "SELECT column_name FROM information_schema.columns WHERE table_name = ? AND table_schema = DATABASE()",
|
|
4370
|
+
params: [t]
|
|
4371
|
+
}),
|
|
4372
|
+
addColumn: (t, c, type) => `ALTER TABLE ${t} ADD COLUMN ${c} ${type} NULL`
|
|
4373
|
+
},
|
|
4374
|
+
sqlite: {
|
|
4375
|
+
ph: () => "?",
|
|
4376
|
+
timestamp: "TEXT",
|
|
4377
|
+
text: "TEXT",
|
|
4378
|
+
int: "INTEGER",
|
|
4379
|
+
existingColumns: (t) => ({ sql: `PRAGMA table_info(${t})`, params: [] }),
|
|
4380
|
+
addColumn: (t, c, type) => `ALTER TABLE ${t} ADD COLUMN ${c} ${type} NULL`
|
|
4381
|
+
},
|
|
4382
|
+
mssql: {
|
|
4383
|
+
ph: (n) => `@p${n}`,
|
|
4384
|
+
timestamp: "DATETIMEOFFSET",
|
|
4385
|
+
text: "NVARCHAR(MAX)",
|
|
4386
|
+
int: "INT",
|
|
4387
|
+
existingColumns: (t) => ({
|
|
4388
|
+
sql: "SELECT column_name FROM information_schema.columns WHERE table_name = @p1",
|
|
4389
|
+
params: [t]
|
|
4390
|
+
}),
|
|
4391
|
+
addColumn: (t, c, type) => `ALTER TABLE ${t} ADD ${c} ${type} NULL`
|
|
4392
|
+
}
|
|
4393
|
+
};
|
|
4394
|
+
function toOutboxTimestamp(dialect, when) {
|
|
4395
|
+
const iso = new Date(when).toISOString();
|
|
4396
|
+
return dialect === "mysql" ? iso.slice(0, 19).replace("T", " ") : iso;
|
|
4397
|
+
}
|
|
4398
|
+
function fromOutboxTimestamp(raw) {
|
|
4399
|
+
if (raw instanceof Date) return raw.getTime();
|
|
4400
|
+
if (typeof raw === "number") return raw;
|
|
4401
|
+
if (typeof raw !== "string") return null;
|
|
4402
|
+
const s = raw.trim();
|
|
4403
|
+
if (s === "") return null;
|
|
4404
|
+
const zoned = /(?:[Zz]|[+-]\d{2}:?\d{2})$/.test(s);
|
|
4405
|
+
const parsed = Date.parse(zoned ? s : `${s.replace(" ", "T")}Z`);
|
|
4406
|
+
return Number.isNaN(parsed) ? null : parsed;
|
|
4407
|
+
}
|
|
4408
|
+
function createOutboxConsumer(opts2) {
|
|
4409
|
+
const dialect = opts2.dialect ?? "postgres";
|
|
4410
|
+
const table = opts2.table ?? "oneaddress_updates";
|
|
4411
|
+
const leaseSeconds = opts2.leaseSeconds ?? 300;
|
|
4412
|
+
const maxAttempts = opts2.maxAttempts ?? 0;
|
|
4413
|
+
const now = opts2.now ?? Date.now;
|
|
4414
|
+
const d = SPECS[dialect];
|
|
4415
|
+
if (!d) throw new Error(`[OneAddress SDK] unknown dialect: ${dialect}`);
|
|
4416
|
+
if (!IDENTIFIER.test(table)) throw new Error(`[OneAddress SDK] invalid table name: ${table}`);
|
|
4417
|
+
const batchSize = Math.floor(opts2.batchSize ?? 50);
|
|
4418
|
+
if (!Number.isFinite(batchSize) || batchSize < 1) {
|
|
4419
|
+
throw new Error(`[OneAddress SDK] batchSize must be a positive integer, got ${opts2.batchSize}`);
|
|
4420
|
+
}
|
|
4421
|
+
const ph = d.ph;
|
|
4422
|
+
const token = () => (0, import_node_crypto.randomBytes)(16).toString("hex");
|
|
4423
|
+
const stamp = (at) => toOutboxTimestamp(dialect, at);
|
|
4424
|
+
const claimable = (cutoffPh) => `written_at IS NOT NULL AND processed_at IS NULL AND (${CLAIMED_AT} IS NULL OR ${CLAIMED_AT} < ${cutoffPh})` + (maxAttempts > 0 ? ` AND (${ATTEMPTS} IS NULL OR ${ATTEMPTS} < ${maxAttempts})` : "");
|
|
4425
|
+
const toRow = (r) => ({
|
|
4426
|
+
dispatchId: String(r.dispatch_id ?? r.dispatchId ?? ""),
|
|
4427
|
+
event: String(r.event ?? ""),
|
|
4428
|
+
attempts: Number(r[ATTEMPTS] ?? 0) || 0,
|
|
4429
|
+
fields: r
|
|
4430
|
+
});
|
|
4431
|
+
async function claimBatch() {
|
|
4432
|
+
const at = now();
|
|
4433
|
+
const claimedAt = stamp(at);
|
|
4434
|
+
const cutoff = stamp(at - leaseSeconds * 1e3);
|
|
4435
|
+
const tok = token();
|
|
4436
|
+
if (dialect === "postgres") {
|
|
4437
|
+
const rows2 = await opts2.query(
|
|
4438
|
+
`UPDATE ${table} SET ${CLAIMED_AT} = ${ph(1)}, ${CLAIM_TOKEN} = ${ph(2)} WHERE dispatch_id IN (SELECT dispatch_id FROM ${table} WHERE ${claimable(ph(3))} ORDER BY received_at LIMIT ${batchSize} FOR UPDATE SKIP LOCKED) RETURNING *`,
|
|
4439
|
+
[claimedAt, tok, cutoff]
|
|
4440
|
+
);
|
|
4441
|
+
return rows2.map(toRow);
|
|
4442
|
+
}
|
|
4443
|
+
if (dialect === "mssql") {
|
|
4444
|
+
const rows2 = await opts2.query(
|
|
4445
|
+
`UPDATE TOP (${batchSize}) ${table} WITH (UPDLOCK, READPAST, ROWLOCK) SET ${CLAIMED_AT} = ${ph(1)}, ${CLAIM_TOKEN} = ${ph(2)} OUTPUT INSERTED.* WHERE ${claimable(ph(3))}`,
|
|
4446
|
+
[claimedAt, tok, cutoff]
|
|
4447
|
+
);
|
|
4448
|
+
return rows2.map(toRow);
|
|
4449
|
+
}
|
|
4450
|
+
const claim = dialect === "mysql" ? `UPDATE ${table} SET ${CLAIMED_AT} = ${ph(1)}, ${CLAIM_TOKEN} = ${ph(2)} WHERE ${claimable(ph(3))} ORDER BY received_at LIMIT ${batchSize}` : `UPDATE ${table} SET ${CLAIMED_AT} = ${ph(1)}, ${CLAIM_TOKEN} = ${ph(2)} WHERE dispatch_id IN (SELECT dispatch_id FROM ${table} WHERE ${claimable(ph(3))} ORDER BY received_at LIMIT ${batchSize})`;
|
|
4451
|
+
await opts2.query(claim, [claimedAt, tok, cutoff]);
|
|
4452
|
+
const rows = await opts2.query(
|
|
4453
|
+
`SELECT * FROM ${table} WHERE ${CLAIM_TOKEN} = ${ph(1)} AND processed_at IS NULL`,
|
|
4454
|
+
[tok]
|
|
4455
|
+
);
|
|
4456
|
+
return rows.map(toRow);
|
|
4457
|
+
}
|
|
4458
|
+
return {
|
|
4459
|
+
async ensureSchema() {
|
|
4460
|
+
const wanted = [
|
|
4461
|
+
[CLAIMED_AT, d.timestamp],
|
|
4462
|
+
[CLAIM_TOKEN, d.text],
|
|
4463
|
+
[ATTEMPTS, d.int]
|
|
4464
|
+
];
|
|
4465
|
+
const q = d.existingColumns(table);
|
|
4466
|
+
const rows = await opts2.query(q.sql, q.params);
|
|
4467
|
+
const have = new Set(
|
|
4468
|
+
rows.map((r) => r.column_name ?? r.COLUMN_NAME ?? r.name).filter((v) => typeof v === "string").map((v) => v.toLowerCase())
|
|
4469
|
+
);
|
|
4470
|
+
if (have.size === 0) {
|
|
4471
|
+
throw new Error(
|
|
4472
|
+
`[OneAddress SDK] table ${table} has no visible columns. Is the receiver pointed at this database, and can this connection see the table?`
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
const added = [];
|
|
4476
|
+
for (const [col, type] of wanted) {
|
|
4477
|
+
if (have.has(col)) continue;
|
|
4478
|
+
await opts2.query(d.addColumn(table, col, type), []);
|
|
4479
|
+
added.push(col);
|
|
4480
|
+
}
|
|
4481
|
+
return { added };
|
|
4482
|
+
},
|
|
4483
|
+
claimBatch,
|
|
4484
|
+
async markProcessed(dispatchId) {
|
|
4485
|
+
await opts2.query(
|
|
4486
|
+
`UPDATE ${table} SET processed_at = ${ph(1)}, ${CLAIMED_AT} = NULL, ${CLAIM_TOKEN} = NULL WHERE dispatch_id = ${ph(2)}`,
|
|
4487
|
+
[stamp(now()), dispatchId]
|
|
4488
|
+
);
|
|
4489
|
+
},
|
|
4490
|
+
async markFailed(dispatchId, error) {
|
|
4491
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4492
|
+
await opts2.query(
|
|
4493
|
+
`UPDATE ${table} SET processing_error = ${ph(1)}, ${ATTEMPTS} = COALESCE(${ATTEMPTS}, 0) + 1, ${CLAIMED_AT} = NULL, ${CLAIM_TOKEN} = NULL WHERE dispatch_id = ${ph(2)}`,
|
|
4494
|
+
[message.slice(0, 500), dispatchId]
|
|
4495
|
+
);
|
|
4496
|
+
},
|
|
4497
|
+
async release(dispatchId) {
|
|
4498
|
+
await opts2.query(
|
|
4499
|
+
`UPDATE ${table} SET ${CLAIMED_AT} = NULL, ${CLAIM_TOKEN} = NULL WHERE dispatch_id = ${ph(1)}`,
|
|
4500
|
+
[dispatchId]
|
|
4501
|
+
);
|
|
4502
|
+
},
|
|
4503
|
+
async process(handler) {
|
|
4504
|
+
const rows = await claimBatch();
|
|
4505
|
+
let processed = 0;
|
|
4506
|
+
let failed = 0;
|
|
4507
|
+
for (const row of rows) {
|
|
4508
|
+
try {
|
|
4509
|
+
await handler(row);
|
|
4510
|
+
await this.markProcessed(row.dispatchId);
|
|
4511
|
+
processed++;
|
|
4512
|
+
} catch (err) {
|
|
4513
|
+
await this.markFailed(row.dispatchId, err);
|
|
4514
|
+
failed++;
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
return { processed, failed };
|
|
4518
|
+
},
|
|
4519
|
+
async backlog() {
|
|
4520
|
+
const rows = await opts2.query(
|
|
4521
|
+
`SELECT received_at, ${ATTEMPTS} FROM ${table} WHERE written_at IS NOT NULL AND processed_at IS NULL`,
|
|
4522
|
+
[]
|
|
4523
|
+
);
|
|
4524
|
+
let oldest = null;
|
|
4525
|
+
let stuck = 0;
|
|
4526
|
+
const at = now();
|
|
4527
|
+
for (const r of rows) {
|
|
4528
|
+
const t = fromOutboxTimestamp(r.received_at ?? r.receivedAt);
|
|
4529
|
+
if (t !== null && (oldest === null || t < oldest)) oldest = t;
|
|
4530
|
+
if (maxAttempts > 0 && (Number(r[ATTEMPTS] ?? 0) || 0) >= maxAttempts) stuck++;
|
|
4531
|
+
}
|
|
4532
|
+
return {
|
|
4533
|
+
pending: rows.length,
|
|
4534
|
+
oldestPendingAgeSeconds: oldest === null ? null : Math.max(0, Math.round((at - oldest) / 1e3)),
|
|
4535
|
+
stuck
|
|
4536
|
+
};
|
|
4537
|
+
}
|
|
4538
|
+
};
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4306
4541
|
// src/index.ts
|
|
4307
4542
|
function createSqlIdempotencyStore(opts2) {
|
|
4308
4543
|
const table = opts2.table ?? "oneaddress_dispatches";
|
|
@@ -4431,7 +4666,12 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
|
4431
4666
|
}
|
|
4432
4667
|
async function decryptSession2(share, envelopeB64, privateKeyPem, partnerId) {
|
|
4433
4668
|
const { decryptSession: decryptSessionCrypto } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
4434
|
-
return decryptSessionCrypto(
|
|
4669
|
+
return decryptSessionCrypto(
|
|
4670
|
+
share,
|
|
4671
|
+
envelopeB64,
|
|
4672
|
+
typeof privateKeyPem === "string" ? pemToBase64(privateKeyPem) : privateKeyPem,
|
|
4673
|
+
partnerId
|
|
4674
|
+
);
|
|
4435
4675
|
}
|
|
4436
4676
|
async function transformAddress(payload, privateKeyPem, partnerId, recipientSpkiPem) {
|
|
4437
4677
|
const plaintext = await decryptAddress2(payload, privateKeyPem, partnerId);
|
|
@@ -4784,7 +5024,7 @@ async function sendVerifyResult(params) {
|
|
|
4784
5024
|
throw new Error(`[OneAddress SDK] verify-result callback to ${callbackUrl} failed: HTTP ${res.status}`);
|
|
4785
5025
|
}
|
|
4786
5026
|
}
|
|
4787
|
-
var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test"];
|
|
5027
|
+
var HANDLED_EVENTS = ["address.updated", "address.verify", "account.verify", "address.test", "address.test-dispatch"];
|
|
4788
5028
|
var warnedUnhandledEvents = /* @__PURE__ */ new Set();
|
|
4789
5029
|
function createOneAddressHandler(options) {
|
|
4790
5030
|
const {
|
|
@@ -5057,16 +5297,16 @@ function createOneAddressHandler(options) {
|
|
|
5057
5297
|
headers: { "Content-Type": "application/json" }
|
|
5058
5298
|
});
|
|
5059
5299
|
}
|
|
5060
|
-
if (body.event === "address.test" && onTest) {
|
|
5300
|
+
if ((body.event === "address.test" || body.event === "address.test-dispatch") && onTest) {
|
|
5061
5301
|
if (!isD5Body(body)) {
|
|
5062
|
-
return new Response(JSON.stringify({ error: "
|
|
5302
|
+
return new Response(JSON.stringify({ error: "a test dispatch requires a session envelope" }), {
|
|
5063
5303
|
status: 400,
|
|
5064
5304
|
headers: { "Content-Type": "application/json" }
|
|
5065
5305
|
});
|
|
5066
5306
|
}
|
|
5067
5307
|
const d5 = await buildD5Pieces(body, partnerId);
|
|
5068
5308
|
await onTest({
|
|
5069
|
-
event:
|
|
5309
|
+
event: body.event,
|
|
5070
5310
|
index: typeof body.index === "number" ? body.index : void 0,
|
|
5071
5311
|
total: typeof body.total === "number" ? body.total : void 0,
|
|
5072
5312
|
verification_id: typeof body.verification_id === "string" ? body.verification_id : void 0,
|
|
@@ -5085,12 +5325,17 @@ function createOneAddressHandler(options) {
|
|
|
5085
5325
|
const callbackFor = {
|
|
5086
5326
|
"address.verify": onVerify,
|
|
5087
5327
|
"account.verify": onAccountVerify,
|
|
5088
|
-
"address.test": onTest
|
|
5328
|
+
"address.test": onTest,
|
|
5329
|
+
// Same callback as address.test: both test variants route to onTest, so
|
|
5330
|
+
// an unwired stress-test event must name onTest too — not fall through
|
|
5331
|
+
// to the "upgrade the SDK" remedy, which cannot help (marlowe-reports#126).
|
|
5332
|
+
"address.test-dispatch": onTest
|
|
5089
5333
|
};
|
|
5090
5334
|
const callbackNameFor = {
|
|
5091
5335
|
"address.verify": "onVerify",
|
|
5092
5336
|
"account.verify": "onAccountVerify",
|
|
5093
|
-
"address.test": "onTest"
|
|
5337
|
+
"address.test": "onTest",
|
|
5338
|
+
"address.test-dispatch": "onTest"
|
|
5094
5339
|
};
|
|
5095
5340
|
const unwired = evt in callbackFor && !callbackFor[evt] ? callbackNameFor[evt] : null;
|
|
5096
5341
|
if (!warnedUnhandledEvents.has(evt)) {
|
|
@@ -5151,12 +5396,14 @@ function toExpressHandler(handler) {
|
|
|
5151
5396
|
0 && (module.exports = {
|
|
5152
5397
|
CURRENT_VERSION,
|
|
5153
5398
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
5399
|
+
OUTBOX_LEASE_COLUMNS,
|
|
5154
5400
|
SUPPORTED_VERSIONS,
|
|
5155
5401
|
canonicalD5LoaForm,
|
|
5156
5402
|
compareAddresses,
|
|
5157
5403
|
computeBlindIndex,
|
|
5158
5404
|
confirmUpdate,
|
|
5159
5405
|
createOneAddressHandler,
|
|
5406
|
+
createOutboxConsumer,
|
|
5160
5407
|
createSqlIdempotencyStore,
|
|
5161
5408
|
d5LoaRef,
|
|
5162
5409
|
decrypt,
|
|
@@ -5166,6 +5413,7 @@ function toExpressHandler(handler) {
|
|
|
5166
5413
|
fetchLoaPublicKey,
|
|
5167
5414
|
findMatchingStoredName,
|
|
5168
5415
|
formatAddressParts,
|
|
5416
|
+
fromOutboxTimestamp,
|
|
5169
5417
|
isEmailLike,
|
|
5170
5418
|
isFreshTimestamp,
|
|
5171
5419
|
namePoolMatches,
|
|
@@ -5173,6 +5421,7 @@ function toExpressHandler(handler) {
|
|
|
5173
5421
|
readAddressParts,
|
|
5174
5422
|
sendVerifyResult,
|
|
5175
5423
|
toExpressHandler,
|
|
5424
|
+
toOutboxTimestamp,
|
|
5176
5425
|
transform,
|
|
5177
5426
|
transformAddress,
|
|
5178
5427
|
transformSession,
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CURRENT_VERSION,
|
|
3
|
+
OUTBOX_LEASE_COLUMNS,
|
|
3
4
|
SUPPORTED_VERSIONS,
|
|
4
5
|
canonicalD5LoaForm,
|
|
5
6
|
compareAddresses,
|
|
6
7
|
confirmUpdate,
|
|
7
8
|
createOneAddressHandler,
|
|
9
|
+
createOutboxConsumer,
|
|
8
10
|
createSqlIdempotencyStore,
|
|
9
11
|
d5LoaRef,
|
|
10
12
|
decryptAddress,
|
|
@@ -13,11 +15,13 @@ import {
|
|
|
13
15
|
fetchLoaPublicKey,
|
|
14
16
|
findMatchingStoredName,
|
|
15
17
|
formatAddressParts,
|
|
18
|
+
fromOutboxTimestamp,
|
|
16
19
|
isEmailLike,
|
|
17
20
|
namePoolMatches,
|
|
18
21
|
readAddressParts,
|
|
19
22
|
sendVerifyResult,
|
|
20
23
|
toExpressHandler,
|
|
24
|
+
toOutboxTimestamp,
|
|
21
25
|
transformAddress,
|
|
22
26
|
transformSession,
|
|
23
27
|
validateAddress,
|
|
@@ -25,22 +29,24 @@ import {
|
|
|
25
29
|
verifyLOA,
|
|
26
30
|
verifySignature,
|
|
27
31
|
verifyWithGrace
|
|
28
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-PUB6ZVJ2.mjs";
|
|
29
33
|
import {
|
|
30
34
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
31
35
|
computeBlindIndex,
|
|
32
36
|
isFreshTimestamp,
|
|
33
37
|
normalizeForBlindIndex
|
|
34
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-O2D5XGSN.mjs";
|
|
35
39
|
export {
|
|
36
40
|
CURRENT_VERSION,
|
|
37
41
|
DEFAULT_REPLAY_WINDOW_SECS,
|
|
42
|
+
OUTBOX_LEASE_COLUMNS,
|
|
38
43
|
SUPPORTED_VERSIONS,
|
|
39
44
|
canonicalD5LoaForm,
|
|
40
45
|
compareAddresses,
|
|
41
46
|
computeBlindIndex,
|
|
42
47
|
confirmUpdate,
|
|
43
48
|
createOneAddressHandler,
|
|
49
|
+
createOutboxConsumer,
|
|
44
50
|
createSqlIdempotencyStore,
|
|
45
51
|
d5LoaRef,
|
|
46
52
|
decryptAddress as decrypt,
|
|
@@ -50,6 +56,7 @@ export {
|
|
|
50
56
|
fetchLoaPublicKey,
|
|
51
57
|
findMatchingStoredName,
|
|
52
58
|
formatAddressParts,
|
|
59
|
+
fromOutboxTimestamp,
|
|
53
60
|
isEmailLike,
|
|
54
61
|
isFreshTimestamp,
|
|
55
62
|
namePoolMatches,
|
|
@@ -57,6 +64,7 @@ export {
|
|
|
57
64
|
readAddressParts,
|
|
58
65
|
sendVerifyResult,
|
|
59
66
|
toExpressHandler,
|
|
67
|
+
toOutboxTimestamp,
|
|
60
68
|
transformAddress as transform,
|
|
61
69
|
transformAddress,
|
|
62
70
|
transformSession,
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneaddress/partner-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Official OneAddress partner integration SDK — webhook verification, address decryption (legacy + D5 session-envelope), LOA validation",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/OneAddress-AU/oneaddress-app.git",
|
|
8
|
+
"directory": "packages/partner-sdk"
|
|
9
|
+
},
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
7
12
|
"exports": {
|