@oneaddress/partner-sdk 2.5.0 → 2.6.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 +28 -0
- package/README.md +39 -0
- package/dist/{chunk-ZY2K54LD.mjs → chunk-QAOGKPD3.mjs} +77 -19
- package/dist/{chunk-DIUGEFIK.mjs → chunk-XPQERNNN.mjs} +261 -30
- package/dist/edge.js +148 -70
- package/dist/edge.mjs +2 -2
- package/dist/index.d.mts +192 -1
- package/dist/index.d.ts +192 -1
- package/dist/index.js +378 -79
- package/dist/index.mjs +6 -2
- package/dist/{src-RBLFVBGY.mjs → src-BPES2DKY.mjs} +13 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3347,6 +3347,56 @@ var init_partner_key_attestation = __esm({
|
|
|
3347
3347
|
}
|
|
3348
3348
|
});
|
|
3349
3349
|
|
|
3350
|
+
// ../crypto/src/registry-root-pin.ts
|
|
3351
|
+
function __setPinnedRegistryRootsForTests(pins) {
|
|
3352
|
+
overrideForTests = pins;
|
|
3353
|
+
}
|
|
3354
|
+
function pinnedRegistryRoots() {
|
|
3355
|
+
return overrideForTests ?? PINNED_REGISTRY_ROOTS;
|
|
3356
|
+
}
|
|
3357
|
+
function b64ToBytes2(b64) {
|
|
3358
|
+
const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3359
|
+
const binary = atob(normalised);
|
|
3360
|
+
const out = new Uint8Array(binary.length);
|
|
3361
|
+
for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
|
|
3362
|
+
return out;
|
|
3363
|
+
}
|
|
3364
|
+
async function spkiSha256HexFromB64(spkiB64) {
|
|
3365
|
+
const digest = await crypto.subtle.digest("SHA-256", b64ToBytes2(spkiB64));
|
|
3366
|
+
return bytesToHex3(new Uint8Array(digest));
|
|
3367
|
+
}
|
|
3368
|
+
async function rootIsPinned(root) {
|
|
3369
|
+
try {
|
|
3370
|
+
const digest = await spkiSha256HexFromB64(root.public_key_b64);
|
|
3371
|
+
return pinnedRegistryRoots().some(
|
|
3372
|
+
(p) => p.root_key_id === root.root_key_id && p.spki_sha256 === digest
|
|
3373
|
+
);
|
|
3374
|
+
} catch {
|
|
3375
|
+
return false;
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
async function unpinnedRootIds(roots) {
|
|
3379
|
+
const out = [];
|
|
3380
|
+
for (const root of roots) {
|
|
3381
|
+
if (!await rootIsPinned(root)) out.push(String(root?.root_key_id ?? "(no id)"));
|
|
3382
|
+
}
|
|
3383
|
+
return out;
|
|
3384
|
+
}
|
|
3385
|
+
var PINNED_REGISTRY_ROOTS, overrideForTests;
|
|
3386
|
+
var init_registry_root_pin = __esm({
|
|
3387
|
+
"../crypto/src/registry-root-pin.ts"() {
|
|
3388
|
+
"use strict";
|
|
3389
|
+
init_partner_key_attestation();
|
|
3390
|
+
PINNED_REGISTRY_ROOTS = Object.freeze([
|
|
3391
|
+
Object.freeze({
|
|
3392
|
+
root_key_id: "rk1_251368ec9b0a84ae",
|
|
3393
|
+
spki_sha256: "251368ec9b0a84ae9881533bd1687efb7d439edd927aef47c1bb3bb069b3dc1d"
|
|
3394
|
+
})
|
|
3395
|
+
]);
|
|
3396
|
+
overrideForTests = null;
|
|
3397
|
+
}
|
|
3398
|
+
});
|
|
3399
|
+
|
|
3350
3400
|
// ../crypto/src/registry-head.ts
|
|
3351
3401
|
function assertNoLineBreak(field, value) {
|
|
3352
3402
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -3419,7 +3469,7 @@ function buildRegistryHeadStatement(payload) {
|
|
|
3419
3469
|
}
|
|
3420
3470
|
return lines.join("\n");
|
|
3421
3471
|
}
|
|
3422
|
-
function
|
|
3472
|
+
function b64ToBytes3(b64) {
|
|
3423
3473
|
const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
|
|
3424
3474
|
const binary = atob(normalised);
|
|
3425
3475
|
const out = new Uint8Array(binary.length);
|
|
@@ -3464,7 +3514,7 @@ async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date())
|
|
|
3464
3514
|
});
|
|
3465
3515
|
const rootKey = await crypto.subtle.importKey(
|
|
3466
3516
|
"spki",
|
|
3467
|
-
|
|
3517
|
+
b64ToBytes3(root.public_key_b64),
|
|
3468
3518
|
{ name: "ECDSA", namedCurve: "P-256" },
|
|
3469
3519
|
false,
|
|
3470
3520
|
["verify"]
|
|
@@ -3492,7 +3542,7 @@ function headNamesPartner(doc, partnerId) {
|
|
|
3492
3542
|
async function partnerKeyFingerprint(publicKeyB64) {
|
|
3493
3543
|
const digest = await crypto.subtle.digest(
|
|
3494
3544
|
"SHA-256",
|
|
3495
|
-
|
|
3545
|
+
b64ToBytes3(publicKeyB64)
|
|
3496
3546
|
);
|
|
3497
3547
|
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
3498
3548
|
}
|
|
@@ -3529,6 +3579,7 @@ async function saysRootNotConfigured(res) {
|
|
|
3529
3579
|
}
|
|
3530
3580
|
}
|
|
3531
3581
|
async function outcomeFor(partnerId, key, reg, bound) {
|
|
3582
|
+
if (reg.unpinnedRoots.length > 0) return "root-unpinned";
|
|
3532
3583
|
if (!reg.head) return "head-unusable";
|
|
3533
3584
|
if (!key.key_signature || !key.root_key_id) {
|
|
3534
3585
|
if (!key.countersignature_exempt) return "unsigned";
|
|
@@ -3587,6 +3638,10 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
3587
3638
|
if (roots.length === 0) {
|
|
3588
3639
|
return { ok: false, failure: { reason: "roots-empty", status: rootsRes.status } };
|
|
3589
3640
|
}
|
|
3641
|
+
const unpinnedRoots = await unpinnedRootIds(roots);
|
|
3642
|
+
if (unpinnedRoots.length > 0) {
|
|
3643
|
+
return { ok: true, registry: { roots: [], head: null, headVerdict: "root-unpinned", unpinnedRoots } };
|
|
3644
|
+
}
|
|
3590
3645
|
let head = null;
|
|
3591
3646
|
let headVerdict = "absent";
|
|
3592
3647
|
if (headRes.ok) {
|
|
@@ -3594,7 +3649,7 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
3594
3649
|
headVerdict = await verifyRegistryHead(head, roots);
|
|
3595
3650
|
if (headVerdict !== "ok" && headVerdict !== "expired") head = null;
|
|
3596
3651
|
}
|
|
3597
|
-
return { ok: true, registry: { roots, head, headVerdict } };
|
|
3652
|
+
return { ok: true, registry: { roots, head, headVerdict, unpinnedRoots: [] } };
|
|
3598
3653
|
} catch {
|
|
3599
3654
|
return { ok: false, failure: { reason: "fetch-failed" } };
|
|
3600
3655
|
}
|
|
@@ -3626,6 +3681,7 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
3626
3681
|
"bad-attestation": [],
|
|
3627
3682
|
"not-in-head": [],
|
|
3628
3683
|
"head-unusable": [],
|
|
3684
|
+
"root-unpinned": [],
|
|
3629
3685
|
"error": []
|
|
3630
3686
|
};
|
|
3631
3687
|
const blocked = {};
|
|
@@ -3669,6 +3725,9 @@ function createPartnerKeyVerifier(env = {}) {
|
|
|
3669
3725
|
// Counted, not listed: an operator reading a real finding needs to know
|
|
3670
3726
|
// how many keys were skipped as exempt, without the ids adding noise.
|
|
3671
3727
|
exempt: tally.exempt.length,
|
|
3728
|
+
// The served root ids the bundle refused, so a report of a rotation
|
|
3729
|
+
// that outran its client build names the root to add.
|
|
3730
|
+
...reg.unpinnedRoots.length > 0 ? { unpinnedRoots: reg.unpinnedRoots } : {},
|
|
3672
3731
|
...Object.fromEntries(failed.map((o) => [o, tally[o]]))
|
|
3673
3732
|
});
|
|
3674
3733
|
}
|
|
@@ -3688,6 +3747,7 @@ var init_verify_partner_keys = __esm({
|
|
|
3688
3747
|
"../crypto/src/verify-partner-keys.ts"() {
|
|
3689
3748
|
"use strict";
|
|
3690
3749
|
init_partner_key_attestation();
|
|
3750
|
+
init_registry_root_pin();
|
|
3691
3751
|
init_registry_head();
|
|
3692
3752
|
ACCEPTABLE = /* @__PURE__ */ new Set(["ok", "exempt"]);
|
|
3693
3753
|
EMPTY_BOUND = /* @__PURE__ */ new Set();
|
|
@@ -3824,10 +3884,12 @@ __export(src_exports, {
|
|
|
3824
3884
|
PARTNER_KEY_ATTESTATION_ALG: () => PARTNER_KEY_ATTESTATION_ALG,
|
|
3825
3885
|
PARTNER_KEY_ATTESTATION_V1: () => PARTNER_KEY_ATTESTATION_V1,
|
|
3826
3886
|
PARTNER_KEY_REFUSED_MESSAGE: () => PARTNER_KEY_REFUSED_MESSAGE,
|
|
3887
|
+
PINNED_REGISTRY_ROOTS: () => PINNED_REGISTRY_ROOTS,
|
|
3827
3888
|
REGISTRY_HEAD_ALG: () => REGISTRY_HEAD_ALG,
|
|
3828
3889
|
REGISTRY_HEAD_V1: () => REGISTRY_HEAD_V1,
|
|
3829
3890
|
REGISTRY_HEAD_V2: () => REGISTRY_HEAD_V2,
|
|
3830
3891
|
SENDER_HELD_KEY_ALGORITHM: () => SENDER_HELD_KEY_ALGORITHM,
|
|
3892
|
+
__setPinnedRegistryRootsForTests: () => __setPinnedRegistryRootsForTests,
|
|
3831
3893
|
blockedPublicKeyReason: () => blockedPublicKeyReason,
|
|
3832
3894
|
buildPartnerKeyAttestation: () => buildPartnerKeyAttestation,
|
|
3833
3895
|
buildRegistryHeadStatement: () => buildRegistryHeadStatement,
|
|
@@ -3861,15 +3923,19 @@ __export(src_exports, {
|
|
|
3861
3923
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
3862
3924
|
openSealedWithSenderHeldKey: () => openSealedWithSenderHeldKey,
|
|
3863
3925
|
partnerKeyFingerprint: () => partnerKeyFingerprint,
|
|
3926
|
+
pinnedRegistryRoots: () => pinnedRegistryRoots,
|
|
3927
|
+
rootIsPinned: () => rootIsPinned,
|
|
3864
3928
|
rootKeyIdFromSpki: () => rootKeyIdFromSpki,
|
|
3865
3929
|
rootKeyIdFromSpkiB64: () => rootKeyIdFromSpkiB64,
|
|
3866
3930
|
signWebhookPayload: () => signWebhookPayload,
|
|
3931
|
+
spkiSha256HexFromB64: () => spkiSha256HexFromB64,
|
|
3932
|
+
unpinnedRootIds: () => unpinnedRootIds,
|
|
3867
3933
|
verifyPartnerKeyAttestation: () => verifyPartnerKeyAttestation,
|
|
3868
3934
|
verifyPartnerKeyAttestationWithRoots: () => verifyPartnerKeyAttestationWithRoots,
|
|
3869
3935
|
verifyRegistryHead: () => verifyRegistryHead,
|
|
3870
3936
|
verifyWebhookSignature: () => verifyWebhookSignature
|
|
3871
3937
|
});
|
|
3872
|
-
function
|
|
3938
|
+
function b64ToBytes4(b64) {
|
|
3873
3939
|
const binary = atob(b64);
|
|
3874
3940
|
const bytes = new Uint8Array(binary.length);
|
|
3875
3941
|
for (let i = 0; i < binary.length; i++) bytes[i] = binary.codePointAt(i) ?? 0;
|
|
@@ -3877,13 +3943,13 @@ function b64ToBytes3(b64) {
|
|
|
3877
3943
|
}
|
|
3878
3944
|
function keyB64ToBytes(key) {
|
|
3879
3945
|
const begin = key.indexOf("-----BEGIN");
|
|
3880
|
-
if (begin === -1) return
|
|
3946
|
+
if (begin === -1) return b64ToBytes4(key.replace(/\s+/g, ""));
|
|
3881
3947
|
const armourEnd = key.indexOf("-----", begin + "-----BEGIN".length);
|
|
3882
|
-
if (armourEnd === -1) return
|
|
3948
|
+
if (armourEnd === -1) return b64ToBytes4(key.replace(/\s+/g, ""));
|
|
3883
3949
|
const bodyStart = armourEnd + "-----".length;
|
|
3884
3950
|
const end = key.indexOf("-----END", bodyStart);
|
|
3885
3951
|
const body = end === -1 ? key.slice(bodyStart) : key.slice(bodyStart, end);
|
|
3886
|
-
return
|
|
3952
|
+
return b64ToBytes4(body.replace(/\s+/g, ""));
|
|
3887
3953
|
}
|
|
3888
3954
|
function bytesToB64(bytes) {
|
|
3889
3955
|
return btoa(String.fromCodePoint(...bytes));
|
|
@@ -3967,7 +4033,7 @@ function generateHybridPartnerKeyPair() {
|
|
|
3967
4033
|
}
|
|
3968
4034
|
async function encryptAddressForPartner(address, partner) {
|
|
3969
4035
|
const address_ = normaliseAddress(address);
|
|
3970
|
-
const partnerPubKey = await importP256PublicKey(
|
|
4036
|
+
const partnerPubKey = await importP256PublicKey(b64ToBytes4(partner.publicKeyB64));
|
|
3971
4037
|
const ephemeral = await subtle().generateKey(
|
|
3972
4038
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
3973
4039
|
true,
|
|
@@ -4015,7 +4081,7 @@ async function encryptAddressForPartner(address, partner) {
|
|
|
4015
4081
|
};
|
|
4016
4082
|
}
|
|
4017
4083
|
async function encryptPayloadForPartner(payload, partner) {
|
|
4018
|
-
const partnerPubKey = await importP256PublicKey(
|
|
4084
|
+
const partnerPubKey = await importP256PublicKey(b64ToBytes4(partner.publicKeyB64));
|
|
4019
4085
|
const ephemeral = await subtle().generateKey(
|
|
4020
4086
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
4021
4087
|
true,
|
|
@@ -4068,7 +4134,7 @@ async function decryptAddress(encrypted, privateKeyB64) {
|
|
|
4068
4134
|
);
|
|
4069
4135
|
const ephemeralPub = await subtle().importKey(
|
|
4070
4136
|
"raw",
|
|
4071
|
-
|
|
4137
|
+
b64ToBytes4(encrypted.ephemeralPublicKey),
|
|
4072
4138
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
4073
4139
|
false,
|
|
4074
4140
|
[]
|
|
@@ -4078,7 +4144,7 @@ async function decryptAddress(encrypted, privateKeyB64) {
|
|
|
4078
4144
|
privateKey,
|
|
4079
4145
|
256
|
|
4080
4146
|
);
|
|
4081
|
-
const hkdfSalt = encrypted.hkdfSalt ?
|
|
4147
|
+
const hkdfSalt = encrypted.hkdfSalt ? b64ToBytes4(encrypted.hkdfSalt) : new Uint8Array(32);
|
|
4082
4148
|
const aesKey = await subtle().importKey(
|
|
4083
4149
|
"raw",
|
|
4084
4150
|
await subtle().deriveBits(
|
|
@@ -4096,9 +4162,9 @@ async function decryptAddress(encrypted, privateKeyB64) {
|
|
|
4096
4162
|
["decrypt"]
|
|
4097
4163
|
);
|
|
4098
4164
|
const plainBuf = await subtle().decrypt(
|
|
4099
|
-
{ name: "AES-GCM", iv:
|
|
4165
|
+
{ name: "AES-GCM", iv: b64ToBytes4(encrypted.iv) },
|
|
4100
4166
|
aesKey,
|
|
4101
|
-
|
|
4167
|
+
b64ToBytes4(encrypted.ciphertext)
|
|
4102
4168
|
);
|
|
4103
4169
|
return JSON.parse(new TextDecoder().decode(plainBuf));
|
|
4104
4170
|
}
|
|
@@ -4123,7 +4189,7 @@ function bytesToB64Url(bytes) {
|
|
|
4123
4189
|
}
|
|
4124
4190
|
function b64UrlToBytes(b64url) {
|
|
4125
4191
|
const pad = b64url.length % 4 === 0 ? "" : "=".repeat(4 - b64url.length % 4);
|
|
4126
|
-
return
|
|
4192
|
+
return b64ToBytes4(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
|
|
4127
4193
|
}
|
|
4128
4194
|
function toArrayBuffer(bytes) {
|
|
4129
4195
|
return bytes.slice().buffer;
|
|
@@ -4145,7 +4211,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
4145
4211
|
const session_envelope = bytesToB64Url(concat(sessionIv, sessionCt));
|
|
4146
4212
|
const skRawForWrap = new Uint8Array(await subtle().exportKey("raw", sk));
|
|
4147
4213
|
if (isHybridScheme(partner.algorithm)) {
|
|
4148
|
-
const { cipherText: kemCt, sharedSecret: sharedSecret2 } = ml_kem768_x25519.encapsulate(
|
|
4214
|
+
const { cipherText: kemCt, sharedSecret: sharedSecret2 } = ml_kem768_x25519.encapsulate(b64ToBytes4(partner.public_key_b64));
|
|
4149
4215
|
const wrapSalt2 = globalThis.crypto.getRandomValues(new Uint8Array(WRAP_SALT_LENGTH));
|
|
4150
4216
|
const wrapKeyRaw2 = await subtle().deriveBits(
|
|
4151
4217
|
{ name: "HKDF", hash: "SHA-256", salt: wrapSalt2, info: sessionWrapInfoPq(partner.partner_id) },
|
|
@@ -4172,7 +4238,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
4172
4238
|
};
|
|
4173
4239
|
}
|
|
4174
4240
|
if (isRsaScheme(partner.algorithm)) {
|
|
4175
|
-
const partnerRsaPub = await importRsaOaepPublicKey(
|
|
4241
|
+
const partnerRsaPub = await importRsaOaepPublicKey(b64ToBytes4(partner.public_key_b64));
|
|
4176
4242
|
const rsaWrapped = new Uint8Array(
|
|
4177
4243
|
await subtle().encrypt({ name: "RSA-OAEP" }, partnerRsaPub, skRawForWrap)
|
|
4178
4244
|
);
|
|
@@ -4189,7 +4255,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
|
|
|
4189
4255
|
}
|
|
4190
4256
|
};
|
|
4191
4257
|
}
|
|
4192
|
-
const partnerPub = await importP256PublicKey(
|
|
4258
|
+
const partnerPub = await importP256PublicKey(b64ToBytes4(partner.public_key_b64));
|
|
4193
4259
|
const ephemeral = await subtle().generateKey(
|
|
4194
4260
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
4195
4261
|
true,
|
|
@@ -4271,7 +4337,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId, expe
|
|
|
4271
4337
|
throw new Error("decryptSession: hybrid share missing epk (KEM ciphertext)");
|
|
4272
4338
|
}
|
|
4273
4339
|
const kemCiphertext = b64UrlToBytes(share.epk);
|
|
4274
|
-
const sharedSecret = ops ? toArrayBuffer(await ops.decapsulateXWing(kemCiphertext)) : toArrayBuffer(ml_kem768_x25519.decapsulate(kemCiphertext,
|
|
4340
|
+
const sharedSecret = ops ? toArrayBuffer(await ops.decapsulateXWing(kemCiphertext)) : toArrayBuffer(ml_kem768_x25519.decapsulate(kemCiphertext, b64ToBytes4(privateKeyB64)));
|
|
4275
4341
|
if (ops && sharedSecret.byteLength !== 32) {
|
|
4276
4342
|
throw new Error(
|
|
4277
4343
|
`decryptSession: key source "${ops.name}" returned a ${sharedSecret.byteLength}-byte shared secret; X-Wing decapsulation is 32 bytes with no KDF applied.`
|
|
@@ -4494,6 +4560,7 @@ var init_src = __esm({
|
|
|
4494
4560
|
init_blocked_public_keys();
|
|
4495
4561
|
init_endpoint_health();
|
|
4496
4562
|
init_partner_key_attestation();
|
|
4563
|
+
init_registry_root_pin();
|
|
4497
4564
|
init_registry_head();
|
|
4498
4565
|
init_verify_partner_keys();
|
|
4499
4566
|
init_sender_held_keys();
|
|
@@ -4542,6 +4609,7 @@ __export(index_exports, {
|
|
|
4542
4609
|
_resetOnceWarningsForTests: () => _resetOnceWarningsForTests,
|
|
4543
4610
|
buildSignedTestWebhook: () => buildSignedTestWebhook,
|
|
4544
4611
|
canonicalD5LoaForm: () => canonicalD5LoaForm,
|
|
4612
|
+
checkRegistryHead: () => checkRegistryHead,
|
|
4545
4613
|
compareAddresses: () => compareAddresses,
|
|
4546
4614
|
computeBlindIndex: () => computeBlindIndex,
|
|
4547
4615
|
confirmUpdate: () => confirmUpdate,
|
|
@@ -4561,6 +4629,7 @@ __export(index_exports, {
|
|
|
4561
4629
|
isFreshTimestamp: () => isFreshTimestamp,
|
|
4562
4630
|
namePoolMatches: () => namePoolMatches,
|
|
4563
4631
|
normalizeForBlindIndex: () => normalizeForBlindIndex,
|
|
4632
|
+
parsePinnedRegistryRoots: () => parsePinnedRegistryRoots,
|
|
4564
4633
|
readAddressParts: () => readAddressParts,
|
|
4565
4634
|
sendVerifyResult: () => sendVerifyResult,
|
|
4566
4635
|
toExpressHandler: () => toExpressHandler,
|
|
@@ -4577,7 +4646,7 @@ __export(index_exports, {
|
|
|
4577
4646
|
verifyWithGrace: () => verifyWithGrace
|
|
4578
4647
|
});
|
|
4579
4648
|
module.exports = __toCommonJS(index_exports);
|
|
4580
|
-
var
|
|
4649
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
4581
4650
|
init_src();
|
|
4582
4651
|
|
|
4583
4652
|
// ../protocol/src/types.ts
|
|
@@ -4641,6 +4710,36 @@ function keyShareExpiryIso(dispatchAt, retentionPeriodDays) {
|
|
|
4641
4710
|
return new Date(dispatchAt.getTime() + days * DAY_MS).toISOString();
|
|
4642
4711
|
}
|
|
4643
4712
|
|
|
4713
|
+
// src/app-hosts.ts
|
|
4714
|
+
function allowedAppHosts() {
|
|
4715
|
+
const hosts = ["oneaddress.io", "app.oneaddress.io"];
|
|
4716
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
|
|
4717
|
+
hosts.push("localhost", "127.0.0.1");
|
|
4718
|
+
}
|
|
4719
|
+
return new Set(hosts);
|
|
4720
|
+
}
|
|
4721
|
+
function resolveAppOrigin(baseUrl, label) {
|
|
4722
|
+
let parsed;
|
|
4723
|
+
try {
|
|
4724
|
+
parsed = new URL(baseUrl);
|
|
4725
|
+
} catch {
|
|
4726
|
+
throw new Error(`[OneAddress SDK] ${label}: appBaseUrl is not a valid URL`);
|
|
4727
|
+
}
|
|
4728
|
+
const allowed = allowedAppHosts();
|
|
4729
|
+
if (!allowed.has(parsed.hostname)) {
|
|
4730
|
+
throw new Error(
|
|
4731
|
+
`[OneAddress SDK] ${label}: appBaseUrl host must be one of: ${[...allowed].join(", ")}`
|
|
4732
|
+
);
|
|
4733
|
+
}
|
|
4734
|
+
const loopback = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
|
|
4735
|
+
if (parsed.protocol !== "https:" && !loopback) {
|
|
4736
|
+
throw new Error(
|
|
4737
|
+
`[OneAddress SDK] ${label}: appBaseUrl must use https (plain http is accepted for localhost only)`
|
|
4738
|
+
);
|
|
4739
|
+
}
|
|
4740
|
+
return parsed.origin;
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4644
4743
|
// src/index.ts
|
|
4645
4744
|
init_src();
|
|
4646
4745
|
init_src();
|
|
@@ -4905,6 +5004,226 @@ function createOutboxConsumer(opts2) {
|
|
|
4905
5004
|
};
|
|
4906
5005
|
}
|
|
4907
5006
|
|
|
5007
|
+
// src/registry-head-check.ts
|
|
5008
|
+
init_src();
|
|
5009
|
+
var OA_APP_BASE_URL = "https://oneaddress.io";
|
|
5010
|
+
var HEAD_PATH = "/.well-known/oneaddress-key-registry-head.json";
|
|
5011
|
+
function parsePinnedRegistryRoots(raw) {
|
|
5012
|
+
if (raw === void 0 || raw === null || raw.trim() === "") {
|
|
5013
|
+
return { ok: false, configured: false, reason: "no root set configured" };
|
|
5014
|
+
}
|
|
5015
|
+
let parsed;
|
|
5016
|
+
try {
|
|
5017
|
+
parsed = JSON.parse(raw);
|
|
5018
|
+
} catch {
|
|
5019
|
+
return { ok: false, configured: true, reason: "not valid JSON" };
|
|
5020
|
+
}
|
|
5021
|
+
const list = Array.isArray(parsed) ? parsed : parsed?.keys;
|
|
5022
|
+
if (!Array.isArray(list)) {
|
|
5023
|
+
return {
|
|
5024
|
+
ok: false,
|
|
5025
|
+
configured: true,
|
|
5026
|
+
reason: 'expected an array of roots, or the published document with a "keys" array'
|
|
5027
|
+
};
|
|
5028
|
+
}
|
|
5029
|
+
if (list.length === 0) {
|
|
5030
|
+
return { ok: false, configured: true, reason: "root set is empty" };
|
|
5031
|
+
}
|
|
5032
|
+
const roots = [];
|
|
5033
|
+
for (const [i, entry] of list.entries()) {
|
|
5034
|
+
const e = entry;
|
|
5035
|
+
if (typeof e?.root_key_id !== "string" || e.root_key_id === "" || typeof e?.algorithm !== "string" || e.algorithm === "" || typeof e?.public_key_b64 !== "string" || e.public_key_b64 === "") {
|
|
5036
|
+
return {
|
|
5037
|
+
ok: false,
|
|
5038
|
+
configured: true,
|
|
5039
|
+
reason: `root at index ${i} is missing root_key_id, algorithm or public_key_b64`
|
|
5040
|
+
};
|
|
5041
|
+
}
|
|
5042
|
+
roots.push({
|
|
5043
|
+
root_key_id: e.root_key_id,
|
|
5044
|
+
algorithm: e.algorithm,
|
|
5045
|
+
public_key_b64: e.public_key_b64
|
|
5046
|
+
});
|
|
5047
|
+
}
|
|
5048
|
+
return { ok: true, roots };
|
|
5049
|
+
}
|
|
5050
|
+
function fromHeadVerdict(v) {
|
|
5051
|
+
switch (v) {
|
|
5052
|
+
case "unknown-root":
|
|
5053
|
+
return {
|
|
5054
|
+
verdict: "head-unknown-root",
|
|
5055
|
+
alarm: true,
|
|
5056
|
+
detail: "the head is signed by a root that is not in the pinned set. Either OneAddress rotated its root and did not tell you, or this head was not signed by OneAddress. Do not update the pin from the same source that served this head."
|
|
5057
|
+
};
|
|
5058
|
+
case "bad-signature":
|
|
5059
|
+
return {
|
|
5060
|
+
verdict: "head-bad-signature",
|
|
5061
|
+
alarm: true,
|
|
5062
|
+
detail: "the root signature on the head did not verify. Treat as tampering until shown otherwise."
|
|
5063
|
+
};
|
|
5064
|
+
case "expired":
|
|
5065
|
+
return {
|
|
5066
|
+
verdict: "head-expired",
|
|
5067
|
+
alarm: true,
|
|
5068
|
+
detail: "the head is authentic but past its expiry, so consumers are refusing every dispatch. Usually a missed re-sign at OneAddress; it is also what suppression of head updates looks like, so raise it rather than waiting."
|
|
5069
|
+
};
|
|
5070
|
+
default:
|
|
5071
|
+
return {
|
|
5072
|
+
verdict: "head-malformed",
|
|
5073
|
+
alarm: true,
|
|
5074
|
+
detail: "the document served is not a head this build can verify."
|
|
5075
|
+
};
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
async function checkRegistryHead(opts2) {
|
|
5079
|
+
const expectedKeyId = opts2.keyId;
|
|
5080
|
+
if (!opts2.pinnedRoots || opts2.pinnedRoots.length === 0) {
|
|
5081
|
+
return {
|
|
5082
|
+
verdict: "roots-not-pinned",
|
|
5083
|
+
checked: false,
|
|
5084
|
+
alarm: false,
|
|
5085
|
+
detail: "no registry root pinned, so the head cannot be checked. Pin the published root set out of band; fetching it from OneAddress would prove nothing, because the same deployment serves the head.",
|
|
5086
|
+
expectedKeyId
|
|
5087
|
+
};
|
|
5088
|
+
}
|
|
5089
|
+
const origin = resolveAppOrigin(opts2.appBaseUrl ?? OA_APP_BASE_URL, "checkRegistryHead");
|
|
5090
|
+
const doFetch = opts2.fetchImpl ?? fetch;
|
|
5091
|
+
const timeoutMs = opts2.timeoutMs ?? 1e4;
|
|
5092
|
+
let res;
|
|
5093
|
+
try {
|
|
5094
|
+
res = await doFetch(`${origin}${HEAD_PATH}`, {
|
|
5095
|
+
// No custom headers and no cache-busting on purpose. The head carries no
|
|
5096
|
+
// per-caller variance and OneAddress edge-caches it for five minutes, so a
|
|
5097
|
+
// fleet of recipients polling hourly costs one origin read between them.
|
|
5098
|
+
...typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? { signal: AbortSignal.timeout(timeoutMs) } : {}
|
|
5099
|
+
});
|
|
5100
|
+
} catch (err) {
|
|
5101
|
+
return {
|
|
5102
|
+
verdict: "head-unreachable",
|
|
5103
|
+
checked: false,
|
|
5104
|
+
alarm: false,
|
|
5105
|
+
detail: `could not fetch the head: ${err instanceof Error ? err.message : String(err)}`,
|
|
5106
|
+
expectedKeyId
|
|
5107
|
+
};
|
|
5108
|
+
}
|
|
5109
|
+
if (res.status === 503) {
|
|
5110
|
+
return {
|
|
5111
|
+
verdict: "head-absent",
|
|
5112
|
+
checked: false,
|
|
5113
|
+
alarm: false,
|
|
5114
|
+
detail: "OneAddress is publishing no head right now (503). Consumers are refusing dispatches while this holds.",
|
|
5115
|
+
expectedKeyId
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5118
|
+
if (!res.ok) {
|
|
5119
|
+
return {
|
|
5120
|
+
verdict: "head-unreachable",
|
|
5121
|
+
checked: false,
|
|
5122
|
+
alarm: false,
|
|
5123
|
+
detail: `the head endpoint answered HTTP ${res.status}`,
|
|
5124
|
+
expectedKeyId
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
let doc;
|
|
5128
|
+
try {
|
|
5129
|
+
doc = await res.json();
|
|
5130
|
+
} catch {
|
|
5131
|
+
return {
|
|
5132
|
+
verdict: "head-malformed",
|
|
5133
|
+
checked: false,
|
|
5134
|
+
alarm: true,
|
|
5135
|
+
detail: "the head endpoint answered 200 with a body that is not JSON.",
|
|
5136
|
+
expectedKeyId
|
|
5137
|
+
};
|
|
5138
|
+
}
|
|
5139
|
+
const issued = typeof doc?.issued_at === "string" ? doc.issued_at : void 0;
|
|
5140
|
+
const expires = typeof doc?.expires_at === "string" ? doc.expires_at : void 0;
|
|
5141
|
+
const headVerdict = await verifyRegistryHead(doc, opts2.pinnedRoots, opts2.now ?? /* @__PURE__ */ new Date());
|
|
5142
|
+
if (headVerdict !== "ok") {
|
|
5143
|
+
const mapped = fromHeadVerdict(headVerdict);
|
|
5144
|
+
return {
|
|
5145
|
+
...mapped,
|
|
5146
|
+
checked: false,
|
|
5147
|
+
expectedKeyId,
|
|
5148
|
+
headIssuedAt: issued,
|
|
5149
|
+
headExpiresAt: expires
|
|
5150
|
+
};
|
|
5151
|
+
}
|
|
5152
|
+
const named = doc.heads?.[opts2.partnerId.toLowerCase()];
|
|
5153
|
+
if (typeof named !== "string" || named === "") {
|
|
5154
|
+
return {
|
|
5155
|
+
verdict: "partner-absent",
|
|
5156
|
+
checked: true,
|
|
5157
|
+
alarm: true,
|
|
5158
|
+
detail: "the head is valid and names no current key for this partner id, so OneAddress is not dispatching to you. Check the partner id first, then ask OneAddress.",
|
|
5159
|
+
expectedKeyId,
|
|
5160
|
+
headIssuedAt: issued,
|
|
5161
|
+
headExpiresAt: expires
|
|
5162
|
+
};
|
|
5163
|
+
}
|
|
5164
|
+
if (expectedKeyId && headNamesKey(doc, opts2.partnerId, expectedKeyId)) {
|
|
5165
|
+
return {
|
|
5166
|
+
verdict: "ok",
|
|
5167
|
+
checked: true,
|
|
5168
|
+
alarm: false,
|
|
5169
|
+
detail: "the head names the key this recipient expects.",
|
|
5170
|
+
namedKeyId: named,
|
|
5171
|
+
expectedKeyId,
|
|
5172
|
+
headIssuedAt: issued,
|
|
5173
|
+
headExpiresAt: expires
|
|
5174
|
+
};
|
|
5175
|
+
}
|
|
5176
|
+
if (opts2.holdsKey) {
|
|
5177
|
+
let holds;
|
|
5178
|
+
try {
|
|
5179
|
+
holds = await opts2.holdsKey(named);
|
|
5180
|
+
} catch (err) {
|
|
5181
|
+
return {
|
|
5182
|
+
verdict: "key-identity-unknown",
|
|
5183
|
+
checked: false,
|
|
5184
|
+
alarm: false,
|
|
5185
|
+
detail: `the head names ${named} and this recipient's key source could not say whether it holds it: ${err instanceof Error ? err.message : String(err)}`,
|
|
5186
|
+
namedKeyId: named,
|
|
5187
|
+
expectedKeyId,
|
|
5188
|
+
headIssuedAt: issued,
|
|
5189
|
+
headExpiresAt: expires
|
|
5190
|
+
};
|
|
5191
|
+
}
|
|
5192
|
+
if (holds) {
|
|
5193
|
+
return {
|
|
5194
|
+
verdict: "names-key-we-hold",
|
|
5195
|
+
checked: true,
|
|
5196
|
+
alarm: false,
|
|
5197
|
+
detail: `the head names ${named}, which this recipient holds. Consistent with a rotation cutover.`,
|
|
5198
|
+
namedKeyId: named,
|
|
5199
|
+
expectedKeyId,
|
|
5200
|
+
headIssuedAt: issued,
|
|
5201
|
+
headExpiresAt: expires
|
|
5202
|
+
};
|
|
5203
|
+
}
|
|
5204
|
+
return {
|
|
5205
|
+
verdict: "names-key-we-lack",
|
|
5206
|
+
checked: true,
|
|
5207
|
+
alarm: true,
|
|
5208
|
+
detail: `the head names ${named} as the current key for this partner id, and this recipient does not hold it. If you did not rotate to that key, address envelopes are being sealed to a key you cannot read. Contact OneAddress through a channel that is not oneaddress.io.`,
|
|
5209
|
+
namedKeyId: named,
|
|
5210
|
+
expectedKeyId,
|
|
5211
|
+
headIssuedAt: issued,
|
|
5212
|
+
headExpiresAt: expires
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5215
|
+
return {
|
|
5216
|
+
verdict: "key-identity-unknown",
|
|
5217
|
+
checked: false,
|
|
5218
|
+
alarm: false,
|
|
5219
|
+
detail: `the head is valid and names ${named}; configure keyId or holdsKey so this check can tell whether that key is yours.`,
|
|
5220
|
+
namedKeyId: named,
|
|
5221
|
+
expectedKeyId,
|
|
5222
|
+
headIssuedAt: issued,
|
|
5223
|
+
headExpiresAt: expires
|
|
5224
|
+
};
|
|
5225
|
+
}
|
|
5226
|
+
|
|
4908
5227
|
// src/index.ts
|
|
4909
5228
|
var IDEMPOTENCY_DIALECTS = ["postgres", "sqlite", "mysql", "mssql"];
|
|
4910
5229
|
function createSqlIdempotencyStore(opts2) {
|
|
@@ -4923,7 +5242,7 @@ function createSqlIdempotencyStore(opts2) {
|
|
|
4923
5242
|
const completedOf = (row) => row?.completed_at ?? row?.completedAt ?? null;
|
|
4924
5243
|
const tokenOf = (row) => row?.claim_token ?? row?.claimToken ?? null;
|
|
4925
5244
|
async function claimByToken(dispatchId) {
|
|
4926
|
-
const token =
|
|
5245
|
+
const token = import_crypto2.default.randomBytes(16).toString("hex");
|
|
4927
5246
|
await opts2.query(
|
|
4928
5247
|
dialect === "mysql" ? `INSERT IGNORE INTO ${table} (dispatch_id, claim_token) VALUES (${ph(1)}, ${ph(2)})` : `INSERT INTO ${table} (dispatch_id, claim_token) SELECT ${ph(1)}, ${ph(2)} WHERE NOT EXISTS (SELECT 1 FROM ${table} WHERE dispatch_id = ${ph(1)})`,
|
|
4929
5248
|
[dispatchId, token]
|
|
@@ -4996,11 +5315,11 @@ function createSqlIdempotencyStore(opts2) {
|
|
|
4996
5315
|
function verifySignature(rawBody, signature, timestamp, secret) {
|
|
4997
5316
|
if (!/^[0-9a-f]{64}$/i.test(signature)) return false;
|
|
4998
5317
|
const sigPayload = `${timestamp}.${rawBody}`;
|
|
4999
|
-
const expected =
|
|
5318
|
+
const expected = import_crypto2.default.createHmac("sha256", secret).update(sigPayload).digest("hex");
|
|
5000
5319
|
const sigBuffer = Buffer.from(signature, "hex");
|
|
5001
5320
|
const expBuffer = Buffer.from(expected, "hex");
|
|
5002
5321
|
if (sigBuffer.length !== expBuffer.length) return false;
|
|
5003
|
-
return
|
|
5322
|
+
return import_crypto2.default.timingSafeEqual(sigBuffer, expBuffer);
|
|
5004
5323
|
}
|
|
5005
5324
|
function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
|
|
5006
5325
|
if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
|
|
@@ -5030,26 +5349,26 @@ function pemToBuffer(pem) {
|
|
|
5030
5349
|
}
|
|
5031
5350
|
async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
5032
5351
|
const { ephemeralPublicKey, iv, ciphertext, hkdfSalt } = payload;
|
|
5033
|
-
const privateKey = await
|
|
5352
|
+
const privateKey = await import_crypto2.default.subtle.importKey(
|
|
5034
5353
|
"pkcs8",
|
|
5035
5354
|
pemToBuffer(privateKeyPem),
|
|
5036
5355
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
5037
5356
|
false,
|
|
5038
5357
|
["deriveBits"]
|
|
5039
5358
|
);
|
|
5040
|
-
const ephemeralKey = await
|
|
5359
|
+
const ephemeralKey = await import_crypto2.default.subtle.importKey(
|
|
5041
5360
|
"raw",
|
|
5042
5361
|
base64urlToBuffer(ephemeralPublicKey),
|
|
5043
5362
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
5044
5363
|
false,
|
|
5045
5364
|
[]
|
|
5046
5365
|
);
|
|
5047
|
-
const sharedBits = await
|
|
5366
|
+
const sharedBits = await import_crypto2.default.subtle.deriveBits(
|
|
5048
5367
|
{ name: "ECDH", public: ephemeralKey },
|
|
5049
5368
|
privateKey,
|
|
5050
5369
|
256
|
|
5051
5370
|
);
|
|
5052
|
-
const hkdfKey = await
|
|
5371
|
+
const hkdfKey = await import_crypto2.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
|
|
5053
5372
|
let salt;
|
|
5054
5373
|
if (hkdfSalt) {
|
|
5055
5374
|
const saltBytes = base64urlToBuffer(hkdfSalt);
|
|
@@ -5063,13 +5382,13 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
|
|
|
5063
5382
|
salt = new Uint8Array(32);
|
|
5064
5383
|
}
|
|
5065
5384
|
const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
|
|
5066
|
-
const aesKeyBits = await
|
|
5385
|
+
const aesKeyBits = await import_crypto2.default.subtle.deriveBits(
|
|
5067
5386
|
{ name: "HKDF", hash: "SHA-256", salt, info },
|
|
5068
5387
|
hkdfKey,
|
|
5069
5388
|
256
|
|
5070
5389
|
);
|
|
5071
|
-
const aesKey = await
|
|
5072
|
-
const plaintext = await
|
|
5390
|
+
const aesKey = await import_crypto2.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["decrypt"]);
|
|
5391
|
+
const plaintext = await import_crypto2.default.subtle.decrypt(
|
|
5073
5392
|
{ name: "AES-GCM", iv: base64urlToBuffer(iv), tagLength: 128 },
|
|
5074
5393
|
aesKey,
|
|
5075
5394
|
base64urlToBuffer(ciphertext)
|
|
@@ -5096,38 +5415,38 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
|
|
|
5096
5415
|
);
|
|
5097
5416
|
}
|
|
5098
5417
|
async function reEncryptForRecipient(plaintextBytes, recipientSpkiPem, info) {
|
|
5099
|
-
const recipientKey = await
|
|
5418
|
+
const recipientKey = await import_crypto2.default.subtle.importKey(
|
|
5100
5419
|
"spki",
|
|
5101
5420
|
pemToBuffer(recipientSpkiPem),
|
|
5102
5421
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
5103
5422
|
false,
|
|
5104
5423
|
[]
|
|
5105
5424
|
);
|
|
5106
|
-
const ephemeralPair = await
|
|
5425
|
+
const ephemeralPair = await import_crypto2.default.subtle.generateKey(
|
|
5107
5426
|
{ name: "ECDH", namedCurve: "P-256" },
|
|
5108
5427
|
true,
|
|
5109
5428
|
["deriveBits"]
|
|
5110
5429
|
);
|
|
5111
|
-
const sharedBits = await
|
|
5430
|
+
const sharedBits = await import_crypto2.default.subtle.deriveBits(
|
|
5112
5431
|
{ name: "ECDH", public: recipientKey },
|
|
5113
5432
|
ephemeralPair.privateKey,
|
|
5114
5433
|
256
|
|
5115
5434
|
);
|
|
5116
|
-
const hkdfSaltBytes =
|
|
5117
|
-
const hkdfKey = await
|
|
5118
|
-
const aesKeyBits = await
|
|
5435
|
+
const hkdfSaltBytes = import_crypto2.default.getRandomValues(new Uint8Array(32));
|
|
5436
|
+
const hkdfKey = await import_crypto2.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
|
|
5437
|
+
const aesKeyBits = await import_crypto2.default.subtle.deriveBits(
|
|
5119
5438
|
{ name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
|
|
5120
5439
|
hkdfKey,
|
|
5121
5440
|
256
|
|
5122
5441
|
);
|
|
5123
|
-
const aesKey = await
|
|
5124
|
-
const ivBytes =
|
|
5125
|
-
const ciphertextBuf = await
|
|
5442
|
+
const aesKey = await import_crypto2.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
|
|
5443
|
+
const ivBytes = import_crypto2.default.getRandomValues(new Uint8Array(12));
|
|
5444
|
+
const ciphertextBuf = await import_crypto2.default.subtle.encrypt(
|
|
5126
5445
|
{ name: "AES-GCM", iv: ivBytes, tagLength: 128 },
|
|
5127
5446
|
aesKey,
|
|
5128
5447
|
plaintextBytes
|
|
5129
5448
|
);
|
|
5130
|
-
const ephemeralPublicKeyRaw = await
|
|
5449
|
+
const ephemeralPublicKeyRaw = await import_crypto2.default.subtle.exportKey("raw", ephemeralPair.publicKey);
|
|
5131
5450
|
return {
|
|
5132
5451
|
ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
|
|
5133
5452
|
iv: Buffer.from(ivBytes).toString("base64"),
|
|
@@ -5144,7 +5463,7 @@ async function transformSession(share, envelopeB64, privateKeyPem, partnerId, re
|
|
|
5144
5463
|
new TextEncoder().encode(`oneaddress:transform-session:${partnerId}`)
|
|
5145
5464
|
);
|
|
5146
5465
|
}
|
|
5147
|
-
var
|
|
5466
|
+
var OA_APP_BASE_URL2 = "https://oneaddress.io";
|
|
5148
5467
|
async function confirmUpdate(opts2) {
|
|
5149
5468
|
const {
|
|
5150
5469
|
partnerId,
|
|
@@ -5154,7 +5473,7 @@ async function confirmUpdate(opts2) {
|
|
|
5154
5473
|
note,
|
|
5155
5474
|
loaRef,
|
|
5156
5475
|
memberName,
|
|
5157
|
-
appBaseUrl =
|
|
5476
|
+
appBaseUrl = OA_APP_BASE_URL2,
|
|
5158
5477
|
fetchImpl = fetch
|
|
5159
5478
|
} = opts2;
|
|
5160
5479
|
if (!partnerId) return { ok: false, status: 0, error: "partnerId is required" };
|
|
@@ -5176,7 +5495,7 @@ async function confirmUpdate(opts2) {
|
|
|
5176
5495
|
...memberName !== void 0 ? { member_name: memberName } : {}
|
|
5177
5496
|
});
|
|
5178
5497
|
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
5179
|
-
const signature =
|
|
5498
|
+
const signature = import_crypto2.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
5180
5499
|
let base = appBaseUrl;
|
|
5181
5500
|
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
5182
5501
|
let res;
|
|
@@ -5204,31 +5523,9 @@ async function confirmUpdate(opts2) {
|
|
|
5204
5523
|
}
|
|
5205
5524
|
return { ok: false, status: res.status, error };
|
|
5206
5525
|
}
|
|
5207
|
-
function
|
|
5208
|
-
const
|
|
5209
|
-
|
|
5210
|
-
hosts.push("localhost", "127.0.0.1");
|
|
5211
|
-
}
|
|
5212
|
-
return new Set(hosts);
|
|
5213
|
-
}
|
|
5214
|
-
async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
|
|
5215
|
-
let parsedBase;
|
|
5216
|
-
try {
|
|
5217
|
-
parsedBase = new URL(appBaseUrl);
|
|
5218
|
-
} catch {
|
|
5219
|
-
throw new Error("[OneAddress SDK] fetchLoaPublicKey: appBaseUrl is not a valid URL");
|
|
5220
|
-
}
|
|
5221
|
-
const allowedHosts = allowedLoaHosts();
|
|
5222
|
-
if (!allowedHosts.has(parsedBase.hostname)) {
|
|
5223
|
-
throw new Error(
|
|
5224
|
-
`[OneAddress SDK] fetchLoaPublicKey: appBaseUrl host must be one of: ${[...allowedHosts].join(", ")}`
|
|
5225
|
-
);
|
|
5226
|
-
}
|
|
5227
|
-
const loopback = parsedBase.hostname === "localhost" || parsedBase.hostname === "127.0.0.1";
|
|
5228
|
-
if (parsedBase.protocol !== "https:" && !loopback) {
|
|
5229
|
-
throw new Error("[OneAddress SDK] fetchLoaPublicKey: appBaseUrl must use https (plain http is accepted for localhost only)");
|
|
5230
|
-
}
|
|
5231
|
-
const url = `${parsedBase.origin}/.well-known/oneaddress-loa-key.pem`;
|
|
5526
|
+
async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL2) {
|
|
5527
|
+
const origin = resolveAppOrigin(appBaseUrl, "fetchLoaPublicKey");
|
|
5528
|
+
const url = `${origin}/.well-known/oneaddress-loa-key.pem`;
|
|
5232
5529
|
const res = await fetch(url);
|
|
5233
5530
|
if (!res.ok) {
|
|
5234
5531
|
throw new Error(`[OneAddress SDK] Failed to fetch LOA public key: HTTP ${res.status}`);
|
|
@@ -5244,7 +5541,7 @@ async function verifyLOA(loa, publicKeyPem) {
|
|
|
5244
5541
|
return false;
|
|
5245
5542
|
}
|
|
5246
5543
|
try {
|
|
5247
|
-
const key = await
|
|
5544
|
+
const key = await import_crypto2.default.subtle.importKey(
|
|
5248
5545
|
"spki",
|
|
5249
5546
|
pemToBuffer(publicKeyPem),
|
|
5250
5547
|
{ name: "ECDSA", namedCurve: "P-256" },
|
|
@@ -5253,7 +5550,7 @@ async function verifyLOA(loa, publicKeyPem) {
|
|
|
5253
5550
|
);
|
|
5254
5551
|
const sigBytes = Buffer.from(loa.signature, "hex");
|
|
5255
5552
|
const textBytes = new TextEncoder().encode(loa.text);
|
|
5256
|
-
return await
|
|
5553
|
+
return await import_crypto2.default.subtle.verify(
|
|
5257
5554
|
{ name: "ECDSA", hash: "SHA-256" },
|
|
5258
5555
|
key,
|
|
5259
5556
|
sigBytes,
|
|
@@ -5276,7 +5573,7 @@ function toB64Url(buf) {
|
|
|
5276
5573
|
return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
5277
5574
|
}
|
|
5278
5575
|
function d5LoaRef(loa) {
|
|
5279
|
-
return toB64Url(
|
|
5576
|
+
return toB64Url(import_crypto2.default.createHash("sha256").update(canonicalD5LoaForm(loa), "utf8").digest());
|
|
5280
5577
|
}
|
|
5281
5578
|
async function verifyD5LOA(loa, publicKeyPem) {
|
|
5282
5579
|
if (loa.signature_algorithm !== "ECDSA-P256") {
|
|
@@ -5287,14 +5584,14 @@ async function verifyD5LOA(loa, publicKeyPem) {
|
|
|
5287
5584
|
return false;
|
|
5288
5585
|
}
|
|
5289
5586
|
try {
|
|
5290
|
-
const key = await
|
|
5587
|
+
const key = await import_crypto2.default.subtle.importKey(
|
|
5291
5588
|
"spki",
|
|
5292
5589
|
pemToBuffer(publicKeyPem),
|
|
5293
5590
|
{ name: "ECDSA", namedCurve: "P-256" },
|
|
5294
5591
|
false,
|
|
5295
5592
|
["verify"]
|
|
5296
5593
|
);
|
|
5297
|
-
return await
|
|
5594
|
+
return await import_crypto2.default.subtle.verify(
|
|
5298
5595
|
{ name: "ECDSA", hash: "SHA-256" },
|
|
5299
5596
|
key,
|
|
5300
5597
|
Buffer.from(loa.oneaddress_signature, "hex"),
|
|
@@ -5531,7 +5828,7 @@ function assertUsablePrivateKey(privateKeyPem) {
|
|
|
5531
5828
|
const der = pemToBuffer(privateKeyPem);
|
|
5532
5829
|
if (der.length === XWING_SEED_BYTES) return;
|
|
5533
5830
|
try {
|
|
5534
|
-
|
|
5831
|
+
import_crypto2.default.createPrivateKey({ key: der, format: "der", type: "pkcs8" });
|
|
5535
5832
|
} catch (err) {
|
|
5536
5833
|
const refused = new Error(
|
|
5537
5834
|
`[OneAddress SDK] privateKeyPem does not import as a PKCS#8 private key (${err instanceof Error ? err.message : String(err)}). Paste the whole key including the BEGIN/END lines; a key stored as one line with literal \\n sequences is accepted, a truncated one is not.`
|
|
@@ -6078,7 +6375,7 @@ function toExpressHandler(handler) {
|
|
|
6078
6375
|
async function buildSignedTestWebhook(opts2) {
|
|
6079
6376
|
const nowSecs = opts2.timestamp ?? Math.floor(Date.now() / 1e3);
|
|
6080
6377
|
const nowIso = new Date(nowSecs * 1e3).toISOString();
|
|
6081
|
-
const updateIdNum =
|
|
6378
|
+
const updateIdNum = import_crypto2.default.randomInt(9e8, 901e6);
|
|
6082
6379
|
const updateUid = opts2.session?.update_uid ?? String(updateIdNum);
|
|
6083
6380
|
const partnerKey = {
|
|
6084
6381
|
partner_id: opts2.partnerId,
|
|
@@ -6096,7 +6393,7 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
6096
6393
|
...kinds.includes("phone") ? { new_phone: "+61412345678" } : {},
|
|
6097
6394
|
...kinds.includes("email") ? { new_email: "test.person@example.com" } : {},
|
|
6098
6395
|
account_number: "TEST-0001",
|
|
6099
|
-
id_verification_ref:
|
|
6396
|
+
id_verification_ref: import_crypto2.default.randomUUID(),
|
|
6100
6397
|
known_names: [],
|
|
6101
6398
|
...opts2.session ?? {}
|
|
6102
6399
|
};
|
|
@@ -6115,14 +6412,14 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
6115
6412
|
...opts2.loa ?? {}
|
|
6116
6413
|
};
|
|
6117
6414
|
if (opts2.loaSigningKeyPem) {
|
|
6118
|
-
const key = await
|
|
6415
|
+
const key = await import_crypto2.default.subtle.importKey(
|
|
6119
6416
|
"pkcs8",
|
|
6120
6417
|
pemToBuffer(opts2.loaSigningKeyPem),
|
|
6121
6418
|
{ name: "ECDSA", namedCurve: "P-256" },
|
|
6122
6419
|
false,
|
|
6123
6420
|
["sign"]
|
|
6124
6421
|
);
|
|
6125
|
-
const sig2 = await
|
|
6422
|
+
const sig2 = await import_crypto2.default.subtle.sign(
|
|
6126
6423
|
{ name: "ECDSA", hash: "SHA-256" },
|
|
6127
6424
|
key,
|
|
6128
6425
|
new TextEncoder().encode(canonicalD5LoaForm(loa))
|
|
@@ -6158,7 +6455,7 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
6158
6455
|
...opts2.extraBody ?? {}
|
|
6159
6456
|
});
|
|
6160
6457
|
const ts = String(nowSecs);
|
|
6161
|
-
const sig =
|
|
6458
|
+
const sig = import_crypto2.default.createHmac("sha256", opts2.webhookSecret).update(`${ts}.${body}`).digest("hex");
|
|
6162
6459
|
const dispatchId = opts2.dispatchId ?? "1";
|
|
6163
6460
|
const headers = {
|
|
6164
6461
|
"Content-Type": "application/json",
|
|
@@ -6191,6 +6488,7 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
6191
6488
|
_resetOnceWarningsForTests,
|
|
6192
6489
|
buildSignedTestWebhook,
|
|
6193
6490
|
canonicalD5LoaForm,
|
|
6491
|
+
checkRegistryHead,
|
|
6194
6492
|
compareAddresses,
|
|
6195
6493
|
computeBlindIndex,
|
|
6196
6494
|
confirmUpdate,
|
|
@@ -6210,6 +6508,7 @@ async function buildSignedTestWebhook(opts2) {
|
|
|
6210
6508
|
isFreshTimestamp,
|
|
6211
6509
|
namePoolMatches,
|
|
6212
6510
|
normalizeForBlindIndex,
|
|
6511
|
+
parsePinnedRegistryRoots,
|
|
6213
6512
|
readAddressParts,
|
|
6214
6513
|
sendVerifyResult,
|
|
6215
6514
|
toExpressHandler,
|