@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/dist/edge.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 b64ToBytes2(b64) {
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
- b64ToBytes2(root.public_key_b64),
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
- b64ToBytes2(publicKeyB64)
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 b64ToBytes3(b64) {
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 b64ToBytes3(key.replace(/\s+/g, ""));
3946
+ if (begin === -1) return b64ToBytes4(key.replace(/\s+/g, ""));
3881
3947
  const armourEnd = key.indexOf("-----", begin + "-----BEGIN".length);
3882
- if (armourEnd === -1) return b64ToBytes3(key.replace(/\s+/g, ""));
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 b64ToBytes3(body.replace(/\s+/g, ""));
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(b64ToBytes3(partner.publicKeyB64));
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(b64ToBytes3(partner.publicKeyB64));
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
- b64ToBytes3(encrypted.ephemeralPublicKey),
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 ? b64ToBytes3(encrypted.hkdfSalt) : new Uint8Array(32);
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: b64ToBytes3(encrypted.iv) },
4165
+ { name: "AES-GCM", iv: b64ToBytes4(encrypted.iv) },
4100
4166
  aesKey,
4101
- b64ToBytes3(encrypted.ciphertext)
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 b64ToBytes3(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
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(b64ToBytes3(partner.public_key_b64));
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(b64ToBytes3(partner.public_key_b64));
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(b64ToBytes3(partner.public_key_b64));
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, b64ToBytes3(privateKeyB64)));
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();
@@ -4564,7 +4631,7 @@ __export(edge_exports, {
4564
4631
  module.exports = __toCommonJS(edge_exports);
4565
4632
 
4566
4633
  // src/index.ts
4567
- var import_crypto = __toESM(require("crypto"));
4634
+ var import_crypto2 = __toESM(require("crypto"));
4568
4635
  init_src();
4569
4636
 
4570
4637
  // ../protocol/src/types.ts
@@ -4613,6 +4680,36 @@ var D5_BODY_ALL_ALLOWED = [
4613
4680
  // ../protocol/src/retention.ts
4614
4681
  var DAY_MS = 24 * 60 * 60 * 1e3;
4615
4682
 
4683
+ // src/app-hosts.ts
4684
+ function allowedAppHosts() {
4685
+ const hosts = ["oneaddress.io", "app.oneaddress.io"];
4686
+ if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
4687
+ hosts.push("localhost", "127.0.0.1");
4688
+ }
4689
+ return new Set(hosts);
4690
+ }
4691
+ function resolveAppOrigin(baseUrl, label) {
4692
+ let parsed;
4693
+ try {
4694
+ parsed = new URL(baseUrl);
4695
+ } catch {
4696
+ throw new Error(`[OneAddress SDK] ${label}: appBaseUrl is not a valid URL`);
4697
+ }
4698
+ const allowed = allowedAppHosts();
4699
+ if (!allowed.has(parsed.hostname)) {
4700
+ throw new Error(
4701
+ `[OneAddress SDK] ${label}: appBaseUrl host must be one of: ${[...allowed].join(", ")}`
4702
+ );
4703
+ }
4704
+ const loopback = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
4705
+ if (parsed.protocol !== "https:" && !loopback) {
4706
+ throw new Error(
4707
+ `[OneAddress SDK] ${label}: appBaseUrl must use https (plain http is accepted for localhost only)`
4708
+ );
4709
+ }
4710
+ return parsed.origin;
4711
+ }
4712
+
4616
4713
  // src/index.ts
4617
4714
  init_src();
4618
4715
  init_src();
@@ -4662,15 +4759,18 @@ function findMatchingStoredName(providedNames, storedCandidates) {
4662
4759
  // src/outbox.ts
4663
4760
  var import_node_crypto = require("crypto");
4664
4761
 
4762
+ // src/registry-head-check.ts
4763
+ init_src();
4764
+
4665
4765
  // src/index.ts
4666
4766
  function verifySignature(rawBody, signature, timestamp, secret) {
4667
4767
  if (!/^[0-9a-f]{64}$/i.test(signature)) return false;
4668
4768
  const sigPayload = `${timestamp}.${rawBody}`;
4669
- const expected = import_crypto.default.createHmac("sha256", secret).update(sigPayload).digest("hex");
4769
+ const expected = import_crypto2.default.createHmac("sha256", secret).update(sigPayload).digest("hex");
4670
4770
  const sigBuffer = Buffer.from(signature, "hex");
4671
4771
  const expBuffer = Buffer.from(expected, "hex");
4672
4772
  if (sigBuffer.length !== expBuffer.length) return false;
4673
- return import_crypto.default.timingSafeEqual(sigBuffer, expBuffer);
4773
+ return import_crypto2.default.timingSafeEqual(sigBuffer, expBuffer);
4674
4774
  }
4675
4775
  function verifyWithGrace(rawBody, timestamp, signature, currentSecret, previousSecret, graceUntil) {
4676
4776
  if (verifySignature(rawBody, signature, timestamp, currentSecret)) return true;
@@ -4700,26 +4800,26 @@ function pemToBuffer(pem) {
4700
4800
  }
4701
4801
  async function decryptAddress2(payload, privateKeyPem, partnerId) {
4702
4802
  const { ephemeralPublicKey, iv, ciphertext, hkdfSalt } = payload;
4703
- const privateKey = await import_crypto.default.subtle.importKey(
4803
+ const privateKey = await import_crypto2.default.subtle.importKey(
4704
4804
  "pkcs8",
4705
4805
  pemToBuffer(privateKeyPem),
4706
4806
  { name: "ECDH", namedCurve: "P-256" },
4707
4807
  false,
4708
4808
  ["deriveBits"]
4709
4809
  );
4710
- const ephemeralKey = await import_crypto.default.subtle.importKey(
4810
+ const ephemeralKey = await import_crypto2.default.subtle.importKey(
4711
4811
  "raw",
4712
4812
  base64urlToBuffer(ephemeralPublicKey),
4713
4813
  { name: "ECDH", namedCurve: "P-256" },
4714
4814
  false,
4715
4815
  []
4716
4816
  );
4717
- const sharedBits = await import_crypto.default.subtle.deriveBits(
4817
+ const sharedBits = await import_crypto2.default.subtle.deriveBits(
4718
4818
  { name: "ECDH", public: ephemeralKey },
4719
4819
  privateKey,
4720
4820
  256
4721
4821
  );
4722
- const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
4822
+ const hkdfKey = await import_crypto2.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
4723
4823
  let salt;
4724
4824
  if (hkdfSalt) {
4725
4825
  const saltBytes = base64urlToBuffer(hkdfSalt);
@@ -4733,13 +4833,13 @@ async function decryptAddress2(payload, privateKeyPem, partnerId) {
4733
4833
  salt = new Uint8Array(32);
4734
4834
  }
4735
4835
  const info = new TextEncoder().encode(`oneaddress:${partnerId}`);
4736
- const aesKeyBits = await import_crypto.default.subtle.deriveBits(
4836
+ const aesKeyBits = await import_crypto2.default.subtle.deriveBits(
4737
4837
  { name: "HKDF", hash: "SHA-256", salt, info },
4738
4838
  hkdfKey,
4739
4839
  256
4740
4840
  );
4741
- const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["decrypt"]);
4742
- const plaintext = await import_crypto.default.subtle.decrypt(
4841
+ const aesKey = await import_crypto2.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["decrypt"]);
4842
+ const plaintext = await import_crypto2.default.subtle.decrypt(
4743
4843
  { name: "AES-GCM", iv: base64urlToBuffer(iv), tagLength: 128 },
4744
4844
  aesKey,
4745
4845
  base64urlToBuffer(ciphertext)
@@ -4766,38 +4866,38 @@ async function transformAddress(payload, privateKeyPem, partnerId, recipientSpki
4766
4866
  );
4767
4867
  }
4768
4868
  async function reEncryptForRecipient(plaintextBytes, recipientSpkiPem, info) {
4769
- const recipientKey = await import_crypto.default.subtle.importKey(
4869
+ const recipientKey = await import_crypto2.default.subtle.importKey(
4770
4870
  "spki",
4771
4871
  pemToBuffer(recipientSpkiPem),
4772
4872
  { name: "ECDH", namedCurve: "P-256" },
4773
4873
  false,
4774
4874
  []
4775
4875
  );
4776
- const ephemeralPair = await import_crypto.default.subtle.generateKey(
4876
+ const ephemeralPair = await import_crypto2.default.subtle.generateKey(
4777
4877
  { name: "ECDH", namedCurve: "P-256" },
4778
4878
  true,
4779
4879
  ["deriveBits"]
4780
4880
  );
4781
- const sharedBits = await import_crypto.default.subtle.deriveBits(
4881
+ const sharedBits = await import_crypto2.default.subtle.deriveBits(
4782
4882
  { name: "ECDH", public: recipientKey },
4783
4883
  ephemeralPair.privateKey,
4784
4884
  256
4785
4885
  );
4786
- const hkdfSaltBytes = import_crypto.default.getRandomValues(new Uint8Array(32));
4787
- const hkdfKey = await import_crypto.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
4788
- const aesKeyBits = await import_crypto.default.subtle.deriveBits(
4886
+ const hkdfSaltBytes = import_crypto2.default.getRandomValues(new Uint8Array(32));
4887
+ const hkdfKey = await import_crypto2.default.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveBits"]);
4888
+ const aesKeyBits = await import_crypto2.default.subtle.deriveBits(
4789
4889
  { name: "HKDF", hash: "SHA-256", salt: hkdfSaltBytes, info },
4790
4890
  hkdfKey,
4791
4891
  256
4792
4892
  );
4793
- const aesKey = await import_crypto.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
4794
- const ivBytes = import_crypto.default.getRandomValues(new Uint8Array(12));
4795
- const ciphertextBuf = await import_crypto.default.subtle.encrypt(
4893
+ const aesKey = await import_crypto2.default.subtle.importKey("raw", aesKeyBits, "AES-GCM", false, ["encrypt"]);
4894
+ const ivBytes = import_crypto2.default.getRandomValues(new Uint8Array(12));
4895
+ const ciphertextBuf = await import_crypto2.default.subtle.encrypt(
4796
4896
  { name: "AES-GCM", iv: ivBytes, tagLength: 128 },
4797
4897
  aesKey,
4798
4898
  plaintextBytes
4799
4899
  );
4800
- const ephemeralPublicKeyRaw = await import_crypto.default.subtle.exportKey("raw", ephemeralPair.publicKey);
4900
+ const ephemeralPublicKeyRaw = await import_crypto2.default.subtle.exportKey("raw", ephemeralPair.publicKey);
4801
4901
  return {
4802
4902
  ephemeralPublicKey: Buffer.from(ephemeralPublicKeyRaw).toString("base64"),
4803
4903
  iv: Buffer.from(ivBytes).toString("base64"),
@@ -4846,7 +4946,7 @@ async function confirmUpdate(opts2) {
4846
4946
  ...memberName !== void 0 ? { member_name: memberName } : {}
4847
4947
  });
4848
4948
  const timestamp = String(Math.floor(Date.now() / 1e3));
4849
- const signature = import_crypto.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
4949
+ const signature = import_crypto2.default.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
4850
4950
  let base = appBaseUrl;
4851
4951
  while (base.endsWith("/")) base = base.slice(0, -1);
4852
4952
  let res;
@@ -4874,31 +4974,9 @@ async function confirmUpdate(opts2) {
4874
4974
  }
4875
4975
  return { ok: false, status: res.status, error };
4876
4976
  }
4877
- function allowedLoaHosts() {
4878
- const hosts = ["oneaddress.io", "app.oneaddress.io"];
4879
- if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
4880
- hosts.push("localhost", "127.0.0.1");
4881
- }
4882
- return new Set(hosts);
4883
- }
4884
4977
  async function fetchLoaPublicKey(appBaseUrl = OA_APP_BASE_URL) {
4885
- let parsedBase;
4886
- try {
4887
- parsedBase = new URL(appBaseUrl);
4888
- } catch {
4889
- throw new Error("[OneAddress SDK] fetchLoaPublicKey: appBaseUrl is not a valid URL");
4890
- }
4891
- const allowedHosts = allowedLoaHosts();
4892
- if (!allowedHosts.has(parsedBase.hostname)) {
4893
- throw new Error(
4894
- `[OneAddress SDK] fetchLoaPublicKey: appBaseUrl host must be one of: ${[...allowedHosts].join(", ")}`
4895
- );
4896
- }
4897
- const loopback = parsedBase.hostname === "localhost" || parsedBase.hostname === "127.0.0.1";
4898
- if (parsedBase.protocol !== "https:" && !loopback) {
4899
- throw new Error("[OneAddress SDK] fetchLoaPublicKey: appBaseUrl must use https (plain http is accepted for localhost only)");
4900
- }
4901
- const url = `${parsedBase.origin}/.well-known/oneaddress-loa-key.pem`;
4978
+ const origin = resolveAppOrigin(appBaseUrl, "fetchLoaPublicKey");
4979
+ const url = `${origin}/.well-known/oneaddress-loa-key.pem`;
4902
4980
  const res = await fetch(url);
4903
4981
  if (!res.ok) {
4904
4982
  throw new Error(`[OneAddress SDK] Failed to fetch LOA public key: HTTP ${res.status}`);
@@ -4914,7 +4992,7 @@ async function verifyLOA(loa, publicKeyPem) {
4914
4992
  return false;
4915
4993
  }
4916
4994
  try {
4917
- const key = await import_crypto.default.subtle.importKey(
4995
+ const key = await import_crypto2.default.subtle.importKey(
4918
4996
  "spki",
4919
4997
  pemToBuffer(publicKeyPem),
4920
4998
  { name: "ECDSA", namedCurve: "P-256" },
@@ -4923,7 +5001,7 @@ async function verifyLOA(loa, publicKeyPem) {
4923
5001
  );
4924
5002
  const sigBytes = Buffer.from(loa.signature, "hex");
4925
5003
  const textBytes = new TextEncoder().encode(loa.text);
4926
- return await import_crypto.default.subtle.verify(
5004
+ return await import_crypto2.default.subtle.verify(
4927
5005
  { name: "ECDSA", hash: "SHA-256" },
4928
5006
  key,
4929
5007
  sigBytes,
@@ -4946,7 +5024,7 @@ function toB64Url(buf) {
4946
5024
  return buf.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
4947
5025
  }
4948
5026
  function d5LoaRef(loa) {
4949
- return toB64Url(import_crypto.default.createHash("sha256").update(canonicalD5LoaForm(loa), "utf8").digest());
5027
+ return toB64Url(import_crypto2.default.createHash("sha256").update(canonicalD5LoaForm(loa), "utf8").digest());
4950
5028
  }
4951
5029
  async function verifyD5LOA(loa, publicKeyPem) {
4952
5030
  if (loa.signature_algorithm !== "ECDSA-P256") {
@@ -4957,14 +5035,14 @@ async function verifyD5LOA(loa, publicKeyPem) {
4957
5035
  return false;
4958
5036
  }
4959
5037
  try {
4960
- const key = await import_crypto.default.subtle.importKey(
5038
+ const key = await import_crypto2.default.subtle.importKey(
4961
5039
  "spki",
4962
5040
  pemToBuffer(publicKeyPem),
4963
5041
  { name: "ECDSA", namedCurve: "P-256" },
4964
5042
  false,
4965
5043
  ["verify"]
4966
5044
  );
4967
- return await import_crypto.default.subtle.verify(
5045
+ return await import_crypto2.default.subtle.verify(
4968
5046
  { name: "ECDSA", hash: "SHA-256" },
4969
5047
  key,
4970
5048
  Buffer.from(loa.oneaddress_signature, "hex"),
@@ -5169,7 +5247,7 @@ function assertUsablePrivateKey(privateKeyPem) {
5169
5247
  const der = pemToBuffer(privateKeyPem);
5170
5248
  if (der.length === XWING_SEED_BYTES) return;
5171
5249
  try {
5172
- import_crypto.default.createPrivateKey({ key: der, format: "der", type: "pkcs8" });
5250
+ import_crypto2.default.createPrivateKey({ key: der, format: "der", type: "pkcs8" });
5173
5251
  } catch (err) {
5174
5252
  const refused = new Error(
5175
5253
  `[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.`
package/dist/edge.mjs CHANGED
@@ -20,13 +20,13 @@ import {
20
20
  verifyLOA,
21
21
  verifySignature,
22
22
  verifyWithGrace
23
- } from "./chunk-DIUGEFIK.mjs";
23
+ } from "./chunk-XPQERNNN.mjs";
24
24
  import {
25
25
  DEFAULT_REPLAY_WINDOW_SECS,
26
26
  computeBlindIndex,
27
27
  isFreshTimestamp,
28
28
  normalizeForBlindIndex
29
- } from "./chunk-ZY2K54LD.mjs";
29
+ } from "./chunk-QAOGKPD3.mjs";
30
30
  export {
31
31
  CURRENT_VERSION,
32
32
  DEFAULT_REPLAY_WINDOW_SECS,