@oneaddress/partner-sdk 1.3.0 → 1.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.
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
 
5
- // ../../../noble-install/node_modules/@noble/hashes/utils.js
5
+ // ../../node_modules/@noble/hashes/utils.js
6
6
  function isBytes(a) {
7
7
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
8
8
  }
@@ -159,7 +159,7 @@ var oidNist = (suffix) => ({
159
159
  oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
160
160
  });
161
161
 
162
- // ../../../noble-install/node_modules/@noble/curves/utils.js
162
+ // ../../node_modules/@noble/curves/utils.js
163
163
  var abytes2 = (value, length, title) => abytes(value, length, title);
164
164
  var anumber2 = anumber;
165
165
  var bytesToHex2 = bytesToHex;
@@ -280,7 +280,7 @@ var notImplemented = () => {
280
280
  throw new Error("not implemented");
281
281
  };
282
282
 
283
- // ../../../noble-install/node_modules/@noble/curves/abstract/modular.js
283
+ // ../../node_modules/@noble/curves/abstract/modular.js
284
284
  var _0n2 = /* @__PURE__ */ BigInt(0);
285
285
  var _1n2 = /* @__PURE__ */ BigInt(1);
286
286
  var _2n = /* @__PURE__ */ BigInt(2);
@@ -672,7 +672,7 @@ function Field(ORDER, opts2 = {}) {
672
672
  return new _Field(ORDER, opts2);
673
673
  }
674
674
 
675
- // ../../../noble-install/node_modules/@noble/curves/abstract/curve.js
675
+ // ../../node_modules/@noble/curves/abstract/curve.js
676
676
  var _0n3 = /* @__PURE__ */ BigInt(0);
677
677
  var _1n3 = /* @__PURE__ */ BigInt(1);
678
678
  function negateCt(condition, item) {
@@ -891,7 +891,7 @@ function createKeygen(randomSecretKey, getPublicKey) {
891
891
  };
892
892
  }
893
893
 
894
- // ../../../noble-install/node_modules/@noble/curves/abstract/edwards.js
894
+ // ../../node_modules/@noble/curves/abstract/edwards.js
895
895
  var _0n4 = /* @__PURE__ */ BigInt(0);
896
896
  var _1n4 = /* @__PURE__ */ BigInt(1);
897
897
  var _2n2 = /* @__PURE__ */ BigInt(2);
@@ -1251,7 +1251,7 @@ __publicField(PrimeEdwardsPoint, "ZERO");
1251
1251
  __publicField(PrimeEdwardsPoint, "Fp");
1252
1252
  __publicField(PrimeEdwardsPoint, "Fn");
1253
1253
 
1254
- // ../../../noble-install/node_modules/@noble/curves/abstract/montgomery.js
1254
+ // ../../node_modules/@noble/curves/abstract/montgomery.js
1255
1255
  var _0n5 = BigInt(0);
1256
1256
  var _1n5 = BigInt(1);
1257
1257
  var _2n3 = BigInt(2);
@@ -1373,7 +1373,7 @@ function montgomery(curveDef) {
1373
1373
  });
1374
1374
  }
1375
1375
 
1376
- // ../../../noble-install/node_modules/@noble/hashes/_md.js
1376
+ // ../../node_modules/@noble/hashes/_md.js
1377
1377
  var HashMD = class {
1378
1378
  constructor(blockLen, outputLen, padOffset, isLE2) {
1379
1379
  __publicField(this, "blockLen");
@@ -1455,7 +1455,7 @@ var HashMD = class {
1455
1455
  return res;
1456
1456
  }
1457
1457
  _cloneInto(to) {
1458
- to || (to = new this.constructor());
1458
+ to ||= new this.constructor();
1459
1459
  to.set(...this.get());
1460
1460
  const { blockLen, buffer, length, finished, destroyed, pos } = this;
1461
1461
  to.destroyed = destroyed;
@@ -1489,7 +1489,7 @@ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
1489
1489
  327033209
1490
1490
  ]);
1491
1491
 
1492
- // ../../../noble-install/node_modules/@noble/hashes/_u64.js
1492
+ // ../../node_modules/@noble/hashes/_u64.js
1493
1493
  var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
1494
1494
  var _32n = /* @__PURE__ */ BigInt(32);
1495
1495
  function fromBig(n, le = false) {
@@ -1528,7 +1528,7 @@ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0
1528
1528
  var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
1529
1529
  var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
1530
1530
 
1531
- // ../../../noble-install/node_modules/@noble/hashes/sha2.js
1531
+ // ../../node_modules/@noble/hashes/sha2.js
1532
1532
  var K512 = /* @__PURE__ */ (() => split([
1533
1533
  "0x428a2f98d728ae22",
1534
1534
  "0x7137449123ef65cd",
@@ -1737,7 +1737,7 @@ var sha512 = /* @__PURE__ */ createHasher(
1737
1737
  /* @__PURE__ */ oidNist(3)
1738
1738
  );
1739
1739
 
1740
- // ../../../noble-install/node_modules/@noble/curves/abstract/fft.js
1740
+ // ../../node_modules/@noble/curves/abstract/fft.js
1741
1741
  function checkU32(n) {
1742
1742
  if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
1743
1743
  throw new Error("wrong u32 integer:" + n);
@@ -1822,7 +1822,7 @@ var FFTCore = (F2, coreOpts) => {
1822
1822
  };
1823
1823
  };
1824
1824
 
1825
- // ../../../noble-install/node_modules/@noble/curves/abstract/hash-to-curve.js
1825
+ // ../../node_modules/@noble/curves/abstract/hash-to-curve.js
1826
1826
  function i2osp(value, length) {
1827
1827
  asafenumber(value);
1828
1828
  asafenumber(length);
@@ -1877,7 +1877,7 @@ function expand_message_xmd(msg, DST, lenInBytes, H) {
1877
1877
  }
1878
1878
  var _DST_scalar = "HashToScalar-";
1879
1879
 
1880
- // ../../../noble-install/node_modules/@noble/curves/ed25519.js
1880
+ // ../../node_modules/@noble/curves/ed25519.js
1881
1881
  var _0n6 = /* @__PURE__ */ BigInt(0);
1882
1882
  var _1n6 = /* @__PURE__ */ BigInt(1);
1883
1883
  var _2n4 = /* @__PURE__ */ BigInt(2);
@@ -2147,7 +2147,7 @@ var ristretto255_hasher = Object.freeze({
2147
2147
  }
2148
2148
  });
2149
2149
 
2150
- // ../../../noble-install/node_modules/@noble/hashes/sha3.js
2150
+ // ../../node_modules/@noble/hashes/sha3.js
2151
2151
  var _0n7 = BigInt(0);
2152
2152
  var _1n7 = BigInt(1);
2153
2153
  var _2n5 = BigInt(2);
@@ -2329,7 +2329,7 @@ var Keccak = class _Keccak {
2329
2329
  }
2330
2330
  _cloneInto(to) {
2331
2331
  const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
2332
- to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
2332
+ to ||= new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
2333
2333
  to.blockLen = blockLen;
2334
2334
  to.state32.set(this.state32);
2335
2335
  to.pos = this.pos;
@@ -2361,7 +2361,7 @@ var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 =
2361
2361
  var shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
2362
2362
  var shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
2363
2363
 
2364
- // ../../../noble-install/node_modules/@noble/post-quantum/utils.js
2364
+ // ../../node_modules/@noble/post-quantum/utils.js
2365
2365
  var abytesDoc = abytes;
2366
2366
  var randomBytes3 = randomBytes;
2367
2367
  function equalBytes2(a, b) {
@@ -2448,7 +2448,7 @@ function getMask(bits) {
2448
2448
  return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
2449
2449
  }
2450
2450
 
2451
- // ../../../noble-install/node_modules/@noble/post-quantum/_crystals.js
2451
+ // ../../node_modules/@noble/post-quantum/_crystals.js
2452
2452
  var genCrystals = (opts2) => {
2453
2453
  const { newPoly, N: N2, Q: Q2, F: F2, ROOT_OF_UNITY: ROOT_OF_UNITY2, brvBits, isKyber } = opts2;
2454
2454
  const mod2 = (a, modulo = Q2) => {
@@ -2567,7 +2567,7 @@ var createXofShake = (shake) => (seed, blockLen) => {
2567
2567
  };
2568
2568
  var XOF128 = /* @__PURE__ */ createXofShake(shake128);
2569
2569
 
2570
- // ../../../noble-install/node_modules/@noble/post-quantum/ml-kem.js
2570
+ // ../../node_modules/@noble/post-quantum/ml-kem.js
2571
2571
  var N = 256;
2572
2572
  var Q = 3329;
2573
2573
  var F = 3303;
@@ -2849,7 +2849,7 @@ var mk = (params) => createKyber({
2849
2849
  });
2850
2850
  var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
2851
2851
 
2852
- // ../../../noble-install/node_modules/@noble/post-quantum/hybrid.js
2852
+ // ../../node_modules/@noble/post-quantum/hybrid.js
2853
2853
  function ecKeygen(curve, allowZeroKey = false) {
2854
2854
  const lengths = curve.lengths;
2855
2855
  let keygen = curve.keygen;
@@ -3050,11 +3050,48 @@ var BLOCKED_HOSTNAMES = /* @__PURE__ */ new Set([
3050
3050
  "metadata.goog",
3051
3051
  "metadata"
3052
3052
  ]);
3053
+ function parseIPv4Component(raw) {
3054
+ if (raw.length === 0) return null;
3055
+ let value;
3056
+ if (/^0[xX][0-9a-fA-F]+$/.test(raw)) value = Number.parseInt(raw.slice(2), 16);
3057
+ else if (/^0[0-7]+$/.test(raw)) value = Number.parseInt(raw.slice(1), 8);
3058
+ else if (/^\d+$/.test(raw)) value = Number.parseInt(raw, 10);
3059
+ else return null;
3060
+ return Number.isSafeInteger(value) && value >= 0 ? value : null;
3061
+ }
3062
+ function canonicalIPv4Octets(host) {
3063
+ const raw = host.split(".");
3064
+ if (raw.length < 1 || raw.length > 4) return null;
3065
+ const vals = [];
3066
+ for (const part of raw) {
3067
+ const v = parseIPv4Component(part);
3068
+ if (v === null) return null;
3069
+ vals.push(v);
3070
+ }
3071
+ const n = vals.length;
3072
+ for (let i = 0; i < n - 1; i++) if (vals[i] > 255) return null;
3073
+ const remainingBytes = 4 - (n - 1);
3074
+ const max = remainingBytes >= 4 ? 4294967295 : 256 ** remainingBytes - 1;
3075
+ if (vals[n - 1] > max) return null;
3076
+ let value = 0;
3077
+ for (let i = 0; i < n - 1; i++) value += vals[i] * 256 ** (3 - i);
3078
+ value += vals[n - 1];
3079
+ if (value > 4294967295) return null;
3080
+ return [value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255];
3081
+ }
3082
+ function looksLikeNumericLiteral(host) {
3083
+ return /^[\d.]+$/.test(host) || /^0[xX][0-9a-fA-F.]+$/.test(host);
3084
+ }
3085
+ function isIpLiteralHost(host) {
3086
+ const clean2 = host.toLowerCase();
3087
+ if (clean2.includes(":")) return true;
3088
+ return canonicalIPv4Octets(clean2) !== null || looksLikeNumericLiteral(clean2);
3089
+ }
3053
3090
  function isBlockedIPv4(host) {
3054
- const parts = host.split(".");
3055
- if (parts.length !== 4) return false;
3056
- const octets = parts.map((p) => /^\d{1,3}$/.test(p) ? Number(p) : Number.NaN);
3057
- if (octets.some((n) => !Number.isInteger(n) || n < 0 || n > 255)) return false;
3091
+ const octets = canonicalIPv4Octets(host);
3092
+ if (!octets) {
3093
+ return looksLikeNumericLiteral(host);
3094
+ }
3058
3095
  const [a, b] = octets;
3059
3096
  if (a === 0) return true;
3060
3097
  if (a === 127) return true;
@@ -3141,13 +3178,206 @@ function isSafeWebhookUrl(url, opts2 = {}) {
3141
3178
  return { ok: true };
3142
3179
  }
3143
3180
 
3144
- // ../crypto/src/index.ts
3181
+ // ../crypto/src/partner-key-attestation.ts
3182
+ var PARTNER_KEY_ATTESTATION_V1 = "oneaddress-partner-key-attestation:v1";
3183
+ var PARTNER_KEY_ATTESTATION_ALG = "ECDSA-P256";
3184
+ function assertNoDelimiter(field, value) {
3185
+ if (typeof value !== "string" || value.length === 0) {
3186
+ throw new Error(`[partner-key-attestation] ${field} must be a non-empty string`);
3187
+ }
3188
+ if (value.includes("\n") || value.includes("\r")) {
3189
+ throw new Error(`[partner-key-attestation] ${field} must not contain a line break`);
3190
+ }
3191
+ }
3192
+ function buildPartnerKeyAttestation(input) {
3193
+ assertNoDelimiter("partnerId", input.partnerId);
3194
+ assertNoDelimiter("keyId", input.keyId);
3195
+ assertNoDelimiter("algorithm", input.algorithm);
3196
+ assertNoDelimiter("publicKeyB64", input.publicKeyB64);
3197
+ return [
3198
+ PARTNER_KEY_ATTESTATION_V1,
3199
+ `partner_id:${input.partnerId.toLowerCase()}`,
3200
+ `key_id:${input.keyId.toLowerCase()}`,
3201
+ `algorithm:${input.algorithm}`,
3202
+ `public_key:${input.publicKeyB64}`
3203
+ ].join("\n");
3204
+ }
3145
3205
  function b64ToBytes(b64) {
3206
+ const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
3207
+ const binary = atob(normalised);
3208
+ const out = new Uint8Array(binary.length);
3209
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
3210
+ return out;
3211
+ }
3212
+ function hexToBytes3(hex) {
3213
+ if (hex.length % 2 !== 0) throw new Error("[partner-key-attestation] hex string has odd length");
3214
+ const out = new Uint8Array(hex.length / 2);
3215
+ for (let i = 0; i < out.length; i++) {
3216
+ const byte = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
3217
+ if (Number.isNaN(byte)) throw new Error("[partner-key-attestation] invalid hex");
3218
+ out[i] = byte;
3219
+ }
3220
+ return out;
3221
+ }
3222
+ function bytesToHex3(bytes) {
3223
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
3224
+ }
3225
+ async function rootKeyIdFromSpki(spki) {
3226
+ const digest = await crypto.subtle.digest("SHA-256", spki);
3227
+ return `rk1_${bytesToHex3(new Uint8Array(digest)).slice(0, 16)}`;
3228
+ }
3229
+ async function rootKeyIdFromSpkiB64(spkiB64) {
3230
+ return rootKeyIdFromSpki(b64ToBytes(spkiB64));
3231
+ }
3232
+ async function verifyPartnerKeyAttestation(input, signatureHex, rootPublicKeyB64) {
3233
+ try {
3234
+ if (typeof signatureHex !== "string" || !/^[0-9a-f]{128}$/i.test(signatureHex)) return false;
3235
+ const statement = buildPartnerKeyAttestation(input);
3236
+ const rootKey = await crypto.subtle.importKey(
3237
+ "spki",
3238
+ b64ToBytes(rootPublicKeyB64),
3239
+ { name: "ECDSA", namedCurve: "P-256" },
3240
+ false,
3241
+ ["verify"]
3242
+ );
3243
+ return await crypto.subtle.verify(
3244
+ { name: "ECDSA", hash: "SHA-256" },
3245
+ rootKey,
3246
+ hexToBytes3(signatureHex),
3247
+ new TextEncoder().encode(statement)
3248
+ );
3249
+ } catch {
3250
+ return false;
3251
+ }
3252
+ }
3253
+ async function verifyPartnerKeyAttestationWithRoots(input, signatureHex, rootKeyId, roots) {
3254
+ const root = roots.find((r) => r.root_key_id === rootKeyId);
3255
+ if (!root) return false;
3256
+ if (root.algorithm !== PARTNER_KEY_ATTESTATION_ALG) return false;
3257
+ return verifyPartnerKeyAttestation(input, signatureHex, root.public_key_b64);
3258
+ }
3259
+
3260
+ // ../crypto/src/registry-head.ts
3261
+ var REGISTRY_HEAD_V1 = "oneaddress-partner-key-registry-head:v1";
3262
+ var REGISTRY_HEAD_ALG = "ECDSA-P256";
3263
+ function assertNoLineBreak(field, value) {
3264
+ if (typeof value !== "string" || value.length === 0) {
3265
+ throw new Error(`[registry-head] ${field} must be a non-empty string`);
3266
+ }
3267
+ if (value.includes("\n") || value.includes("\r")) {
3268
+ throw new Error(`[registry-head] ${field} must not contain a line break`);
3269
+ }
3270
+ }
3271
+ function assertMapSafe(field, value) {
3272
+ assertNoLineBreak(field, value);
3273
+ if (value.includes(":")) {
3274
+ throw new Error(`[registry-head] ${field} must not contain a colon`);
3275
+ }
3276
+ }
3277
+ function buildRegistryHeadStatement(payload) {
3278
+ assertNoLineBreak("issued_at", payload.issued_at);
3279
+ assertNoLineBreak("expires_at", payload.expires_at);
3280
+ assertMapSafe("root_key_id", payload.root_key_id);
3281
+ const entries = Object.entries(payload.heads).map(([partnerId, keyId]) => {
3282
+ assertMapSafe("partner_id", partnerId);
3283
+ assertMapSafe("key_id", keyId);
3284
+ return [partnerId.toLowerCase(), keyId.toLowerCase()];
3285
+ });
3286
+ entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
3287
+ const seen = /* @__PURE__ */ new Set();
3288
+ for (const [partnerId] of entries) {
3289
+ if (seen.has(partnerId)) {
3290
+ throw new Error(`[registry-head] duplicate partner_id in heads: ${partnerId}`);
3291
+ }
3292
+ seen.add(partnerId);
3293
+ }
3294
+ return [
3295
+ REGISTRY_HEAD_V1,
3296
+ `issued_at:${payload.issued_at}`,
3297
+ `expires_at:${payload.expires_at}`,
3298
+ `root_key_id:${payload.root_key_id}`,
3299
+ `heads:${entries.length}`,
3300
+ ...entries.map(([partnerId, keyId]) => `${partnerId}:${keyId}`)
3301
+ ].join("\n");
3302
+ }
3303
+ function b64ToBytes2(b64) {
3304
+ const normalised = b64.replace(/-/g, "+").replace(/_/g, "/");
3305
+ const binary = atob(normalised);
3306
+ const out = new Uint8Array(binary.length);
3307
+ for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i);
3308
+ return out;
3309
+ }
3310
+ function hexToBytes4(hex) {
3311
+ if (hex.length % 2 !== 0) throw new Error("[registry-head] hex string has odd length");
3312
+ const out = new Uint8Array(hex.length / 2);
3313
+ for (let i = 0; i < out.length; i++) {
3314
+ const byte = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
3315
+ if (Number.isNaN(byte)) throw new Error("[registry-head] invalid hex");
3316
+ out[i] = byte;
3317
+ }
3318
+ return out;
3319
+ }
3320
+ async function verifyRegistryHead(doc, roots, now = /* @__PURE__ */ new Date()) {
3321
+ try {
3322
+ if (doc?.version !== REGISTRY_HEAD_V1) return "malformed";
3323
+ if (doc.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
3324
+ if (typeof doc.signature !== "string" || !/^[0-9a-f]{128}$/i.test(doc.signature)) return "malformed";
3325
+ if (!doc.heads || typeof doc.heads !== "object") return "malformed";
3326
+ const expires = Date.parse(doc.expires_at);
3327
+ const issued = Date.parse(doc.issued_at);
3328
+ if (Number.isNaN(expires) || Number.isNaN(issued)) return "malformed";
3329
+ const root = roots.find((r) => r.root_key_id === doc.root_key_id);
3330
+ if (!root) return "unknown-root";
3331
+ if (root.algorithm !== REGISTRY_HEAD_ALG) return "malformed";
3332
+ const statement = buildRegistryHeadStatement({
3333
+ version: doc.version,
3334
+ issued_at: doc.issued_at,
3335
+ expires_at: doc.expires_at,
3336
+ root_key_id: doc.root_key_id,
3337
+ heads: doc.heads
3338
+ });
3339
+ const rootKey = await crypto.subtle.importKey(
3340
+ "spki",
3341
+ b64ToBytes2(root.public_key_b64),
3342
+ { name: "ECDSA", namedCurve: "P-256" },
3343
+ false,
3344
+ ["verify"]
3345
+ );
3346
+ const valid = await crypto.subtle.verify(
3347
+ { name: "ECDSA", hash: "SHA-256" },
3348
+ rootKey,
3349
+ hexToBytes4(doc.signature),
3350
+ new TextEncoder().encode(statement)
3351
+ );
3352
+ if (!valid) return "bad-signature";
3353
+ if (now.getTime() >= expires) return "expired";
3354
+ return "ok";
3355
+ } catch {
3356
+ return "malformed";
3357
+ }
3358
+ }
3359
+ function headNamesKey(doc, partnerId, keyId) {
3360
+ const named = doc.heads?.[partnerId.toLowerCase()];
3361
+ return typeof named === "string" && named.toLowerCase() === keyId.toLowerCase();
3362
+ }
3363
+
3364
+ // ../crypto/src/index.ts
3365
+ function b64ToBytes3(b64) {
3146
3366
  const binary = atob(b64);
3147
3367
  const bytes = new Uint8Array(binary.length);
3148
3368
  for (let i = 0; i < binary.length; i++) bytes[i] = binary.codePointAt(i) ?? 0;
3149
3369
  return bytes;
3150
3370
  }
3371
+ function keyB64ToBytes(key) {
3372
+ const begin = key.indexOf("-----BEGIN");
3373
+ if (begin === -1) return b64ToBytes3(key.replace(/\s+/g, ""));
3374
+ const armourEnd = key.indexOf("-----", begin + "-----BEGIN".length);
3375
+ if (armourEnd === -1) return b64ToBytes3(key.replace(/\s+/g, ""));
3376
+ const bodyStart = armourEnd + "-----".length;
3377
+ const end = key.indexOf("-----END", bodyStart);
3378
+ const body = end === -1 ? key.slice(bodyStart) : key.slice(bodyStart, end);
3379
+ return b64ToBytes3(body.replace(/\s+/g, ""));
3380
+ }
3151
3381
  function bytesToB64(bytes) {
3152
3382
  return btoa(String.fromCodePoint(...bytes));
3153
3383
  }
@@ -3250,7 +3480,7 @@ function generateHybridPartnerKeyPair() {
3250
3480
  }
3251
3481
  async function encryptAddressForPartner(address, partner) {
3252
3482
  const address_ = normaliseAddress(address);
3253
- const partnerPubKey = await importP256PublicKey(b64ToBytes(partner.publicKeyB64));
3483
+ const partnerPubKey = await importP256PublicKey(b64ToBytes3(partner.publicKeyB64));
3254
3484
  const ephemeral = await subtle().generateKey(
3255
3485
  { name: "ECDH", namedCurve: "P-256" },
3256
3486
  true,
@@ -3298,7 +3528,7 @@ async function encryptAddressForPartner(address, partner) {
3298
3528
  };
3299
3529
  }
3300
3530
  async function encryptPayloadForPartner(payload, partner) {
3301
- const partnerPubKey = await importP256PublicKey(b64ToBytes(partner.publicKeyB64));
3531
+ const partnerPubKey = await importP256PublicKey(b64ToBytes3(partner.publicKeyB64));
3302
3532
  const ephemeral = await subtle().generateKey(
3303
3533
  { name: "ECDH", namedCurve: "P-256" },
3304
3534
  true,
@@ -3344,14 +3574,14 @@ async function encryptAddressForAll(address, partners) {
3344
3574
  async function decryptAddress(encrypted, privateKeyB64) {
3345
3575
  const privateKey = await subtle().importKey(
3346
3576
  "pkcs8",
3347
- b64ToBytes(privateKeyB64),
3577
+ keyB64ToBytes(privateKeyB64),
3348
3578
  { name: "ECDH", namedCurve: "P-256" },
3349
3579
  false,
3350
3580
  ["deriveBits"]
3351
3581
  );
3352
3582
  const ephemeralPub = await subtle().importKey(
3353
3583
  "raw",
3354
- b64ToBytes(encrypted.ephemeralPublicKey),
3584
+ b64ToBytes3(encrypted.ephemeralPublicKey),
3355
3585
  { name: "ECDH", namedCurve: "P-256" },
3356
3586
  false,
3357
3587
  []
@@ -3361,7 +3591,7 @@ async function decryptAddress(encrypted, privateKeyB64) {
3361
3591
  privateKey,
3362
3592
  256
3363
3593
  );
3364
- const hkdfSalt = encrypted.hkdfSalt ? b64ToBytes(encrypted.hkdfSalt) : new Uint8Array(32);
3594
+ const hkdfSalt = encrypted.hkdfSalt ? b64ToBytes3(encrypted.hkdfSalt) : new Uint8Array(32);
3365
3595
  const aesKey = await subtle().importKey(
3366
3596
  "raw",
3367
3597
  await subtle().deriveBits(
@@ -3379,9 +3609,9 @@ async function decryptAddress(encrypted, privateKeyB64) {
3379
3609
  ["decrypt"]
3380
3610
  );
3381
3611
  const plainBuf = await subtle().decrypt(
3382
- { name: "AES-GCM", iv: b64ToBytes(encrypted.iv) },
3612
+ { name: "AES-GCM", iv: b64ToBytes3(encrypted.iv) },
3383
3613
  aesKey,
3384
- b64ToBytes(encrypted.ciphertext)
3614
+ b64ToBytes3(encrypted.ciphertext)
3385
3615
  );
3386
3616
  return JSON.parse(new TextDecoder().decode(plainBuf));
3387
3617
  }
@@ -3410,7 +3640,7 @@ function bytesToB64Url(bytes) {
3410
3640
  }
3411
3641
  function b64UrlToBytes(b64url) {
3412
3642
  const pad = b64url.length % 4 === 0 ? "" : "=".repeat(4 - b64url.length % 4);
3413
- return b64ToBytes(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
3643
+ return b64ToBytes3(b64url.replace(/-/g, "+").replace(/_/g, "/") + pad);
3414
3644
  }
3415
3645
  async function encryptSessionForPartner(session_data, partner) {
3416
3646
  return encryptEnvelopeForPartner(session_data, partner);
@@ -3429,7 +3659,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
3429
3659
  const session_envelope = bytesToB64Url(concat(sessionIv, sessionCt));
3430
3660
  const skRawForWrap = new Uint8Array(await subtle().exportKey("raw", sk));
3431
3661
  if (isHybridScheme(partner.algorithm)) {
3432
- const { cipherText: kemCt, sharedSecret: sharedSecret2 } = XWing.encapsulate(b64ToBytes(partner.public_key_b64));
3662
+ const { cipherText: kemCt, sharedSecret: sharedSecret2 } = XWing.encapsulate(b64ToBytes3(partner.public_key_b64));
3433
3663
  const wrapSalt2 = globalThis.crypto.getRandomValues(new Uint8Array(WRAP_SALT_LENGTH));
3434
3664
  const wrapKeyRaw2 = await subtle().deriveBits(
3435
3665
  { name: "HKDF", hash: "SHA-256", salt: wrapSalt2, info: sessionWrapInfoPq(partner.partner_id) },
@@ -3456,7 +3686,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
3456
3686
  };
3457
3687
  }
3458
3688
  if (isRsaScheme(partner.algorithm)) {
3459
- const partnerRsaPub = await importRsaOaepPublicKey(b64ToBytes(partner.public_key_b64));
3689
+ const partnerRsaPub = await importRsaOaepPublicKey(b64ToBytes3(partner.public_key_b64));
3460
3690
  const rsaWrapped = new Uint8Array(
3461
3691
  await subtle().encrypt({ name: "RSA-OAEP" }, partnerRsaPub, skRawForWrap)
3462
3692
  );
@@ -3473,7 +3703,7 @@ async function encryptEnvelopeForPartner(payload, partner) {
3473
3703
  }
3474
3704
  };
3475
3705
  }
3476
- const partnerPub = await importP256PublicKey(b64ToBytes(partner.public_key_b64));
3706
+ const partnerPub = await importP256PublicKey(b64ToBytes3(partner.public_key_b64));
3477
3707
  const ephemeral = await subtle().generateKey(
3478
3708
  { name: "ECDH", namedCurve: "P-256" },
3479
3709
  true,
@@ -3540,7 +3770,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
3540
3770
  if (!share.epk) {
3541
3771
  throw new Error("decryptSession: hybrid share missing epk (KEM ciphertext)");
3542
3772
  }
3543
- const sharedSecret = XWing.decapsulate(b64UrlToBytes(share.epk), b64ToBytes(privateKeyB64));
3773
+ const sharedSecret = XWing.decapsulate(b64UrlToBytes(share.epk), b64ToBytes3(privateKeyB64));
3544
3774
  const wrappedBytes = b64UrlToBytes(share.wrapped_key);
3545
3775
  if (wrappedBytes.length < WRAP_SALT_LENGTH + WRAP_IV_LENGTH + 16) {
3546
3776
  throw new Error("decryptSession: wrapped_key too short");
@@ -3558,7 +3788,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
3558
3788
  } else if (share.alg === "RSA-OAEP-256+A256GCM") {
3559
3789
  const rsaPrivateKey = await subtle().importKey(
3560
3790
  "pkcs8",
3561
- b64ToBytes(privateKeyB64),
3791
+ keyB64ToBytes(privateKeyB64),
3562
3792
  { name: "RSA-OAEP", hash: "SHA-256" },
3563
3793
  false,
3564
3794
  ["decrypt"]
@@ -3574,7 +3804,7 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
3574
3804
  }
3575
3805
  const privateKey = await subtle().importKey(
3576
3806
  "pkcs8",
3577
- b64ToBytes(privateKeyB64),
3807
+ keyB64ToBytes(privateKeyB64),
3578
3808
  { name: "ECDH", namedCurve: "P-256" },
3579
3809
  false,
3580
3810
  ["deriveBits"]
@@ -3641,6 +3871,28 @@ async function decryptSession(share, envelopeB64, privateKeyB64, partnerId) {
3641
3871
  );
3642
3872
  return JSON.parse(new TextDecoder().decode(plainBuf));
3643
3873
  }
3874
+ function isEmailLike(value) {
3875
+ return value.includes("@");
3876
+ }
3877
+ function cleanNameAliases(primaryName, aliases, limit = 10) {
3878
+ const out = [];
3879
+ if (!Array.isArray(aliases)) return out;
3880
+ const seen = /* @__PURE__ */ new Set();
3881
+ const primary = (primaryName ?? "").trim().toLowerCase();
3882
+ if (primary) seen.add(primary);
3883
+ for (const raw of aliases) {
3884
+ if (typeof raw !== "string") continue;
3885
+ const trimmed = raw.trim();
3886
+ if (!trimmed) continue;
3887
+ if (isEmailLike(trimmed)) continue;
3888
+ const key = trimmed.toLowerCase();
3889
+ if (seen.has(key)) continue;
3890
+ seen.add(key);
3891
+ out.push(trimmed);
3892
+ if (out.length >= limit) break;
3893
+ }
3894
+ return out;
3895
+ }
3644
3896
  function normalizeForBlindIndex(field, value) {
3645
3897
  const base = value.normalize("NFKC").trim();
3646
3898
  switch (field) {
@@ -3674,9 +3926,9 @@ async function computeCustomerBlindIndex(secret, fields) {
3674
3926
  out.account_number = await computeBlindIndex(secret, "account_number", fields.account_number);
3675
3927
  }
3676
3928
  const nameValues = [];
3677
- if (fields.name && fields.name.trim()) nameValues.push(fields.name);
3929
+ if (fields.name && fields.name.trim() && !isEmailLike(fields.name)) nameValues.push(fields.name);
3678
3930
  for (const n of fields.known_names ?? []) {
3679
- if (n && n.trim()) nameValues.push(n);
3931
+ if (n && n.trim() && !isEmailLike(n)) nameValues.push(n);
3680
3932
  }
3681
3933
  const seen = /* @__PURE__ */ new Set();
3682
3934
  for (const v of nameValues) {
@@ -3716,7 +3968,20 @@ async function verifyWebhookSignature(payload, signature, secret) {
3716
3968
  export {
3717
3969
  DEFAULT_REPLAY_WINDOW_SECS,
3718
3970
  isFreshTimestamp,
3971
+ isIpLiteralHost,
3719
3972
  isSafeWebhookUrl,
3973
+ PARTNER_KEY_ATTESTATION_V1,
3974
+ PARTNER_KEY_ATTESTATION_ALG,
3975
+ buildPartnerKeyAttestation,
3976
+ rootKeyIdFromSpki,
3977
+ rootKeyIdFromSpkiB64,
3978
+ verifyPartnerKeyAttestation,
3979
+ verifyPartnerKeyAttestationWithRoots,
3980
+ REGISTRY_HEAD_V1,
3981
+ REGISTRY_HEAD_ALG,
3982
+ buildRegistryHeadStatement,
3983
+ verifyRegistryHead,
3984
+ headNamesKey,
3720
3985
  normaliseAddress,
3721
3986
  generatePartnerKeyPair,
3722
3987
  generateHybridPartnerKeyPair,
@@ -3728,6 +3993,8 @@ export {
3728
3993
  encryptEnvelopeForPartner,
3729
3994
  encryptSessionForAll,
3730
3995
  decryptSession,
3996
+ isEmailLike,
3997
+ cleanNameAliases,
3731
3998
  normalizeForBlindIndex,
3732
3999
  computeBlindIndex,
3733
4000
  computeCustomerBlindIndex,
package/dist/edge.d.mts CHANGED
@@ -1 +1 @@
1
- export { BlindIndexField, CURRENT_VERSION, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, canonicalD5LoaForm, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, isFreshTimestamp, normalizeForBlindIndex, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
1
+ export { BlindIndexField, CURRENT_VERSION, ComparableAddress, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAccountVerifyEvent, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, VerifyResultCallbackParams, canonicalD5LoaForm, compareAddresses, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, findMatchingStoredName, isEmailLike, isFreshTimestamp, namePoolMatches, normalizeForBlindIndex, sendVerifyResult, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.mjs';
package/dist/edge.d.ts CHANGED
@@ -1 +1 @@
1
- export { BlindIndexField, CURRENT_VERSION, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, canonicalD5LoaForm, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, isFreshTimestamp, normalizeForBlindIndex, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';
1
+ export { BlindIndexField, CURRENT_VERSION, ComparableAddress, DEFAULT_REPLAY_WINDOW_SECS, EncryptedPayload, OneAddressAccountVerifyEvent, OneAddressAddress, OneAddressCustomer, OneAddressCustomerMatch, OneAddressD5LOA, OneAddressHandlerOptions, OneAddressIdVerification, OneAddressLOA, OneAddressUpdateEvent, OneAddressVerifyEvent, SUPPORTED_VERSIONS, SessionData, SessionKeyShare, VerifyResultCallbackParams, canonicalD5LoaForm, compareAddresses, computeBlindIndex, createOneAddressHandler, d5LoaRef, decrypt as decryptAddress, decryptLoaEncrypted, decryptSession, fetchLoaPublicKey, findMatchingStoredName, isEmailLike, isFreshTimestamp, namePoolMatches, normalizeForBlindIndex, sendVerifyResult, transform as transformAddress, transformSession, validateAddress, verifyD5LOA, verifyLOA, verify as verifySignature, verifyGrace as verifyWithGrace } from './index.js';