@did-btcr2/api 0.7.0 → 0.9.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/browser.js CHANGED
@@ -225,7 +225,7 @@ var BTCR2 = (() => {
225
225
  "../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js"(exports) {
226
226
  "use strict";
227
227
  init_shim();
228
- var base648 = require_base64_js();
228
+ var base647 = require_base64_js();
229
229
  var ieee754 = require_ieee754();
230
230
  var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
231
231
  exports.Buffer = Buffer3;
@@ -926,9 +926,9 @@ var BTCR2 = (() => {
926
926
  };
927
927
  function base64Slice(buf2, start2, end) {
928
928
  if (start2 === 0 && end === buf2.length) {
929
- return base648.fromByteArray(buf2);
929
+ return base647.fromByteArray(buf2);
930
930
  } else {
931
- return base648.fromByteArray(buf2.slice(start2, end));
931
+ return base647.fromByteArray(buf2.slice(start2, end));
932
932
  }
933
933
  }
934
934
  function utf8Slice2(buf2, start2, end) {
@@ -1563,7 +1563,7 @@ var BTCR2 = (() => {
1563
1563
  return byteArray;
1564
1564
  }
1565
1565
  function base64ToBytes(str) {
1566
- return base648.toByteArray(base64clean(str));
1566
+ return base647.toByteArray(base64clean(str));
1567
1567
  }
1568
1568
  function blitBuffer(src6, dst, offset, length9) {
1569
1569
  for (var i5 = 0; i5 < length9; ++i5) {
@@ -58469,11 +58469,11 @@ ${[...listenStats.errors.entries()].map(([addr, err]) => {
58469
58469
  return "";
58470
58470
  }
58471
58471
  const dif = fullLength - str.length;
58472
- const padding3 = new Array(dif);
58472
+ const padding2 = new Array(dif);
58473
58473
  for (let i42 = 0; i42 < dif; i42++) {
58474
- padding3[i42] = "0";
58474
+ padding2[i42] = "0";
58475
58475
  }
58476
- const paddingString = padding3.join("");
58476
+ const paddingString = padding2.join("");
58477
58477
  return paddingString.concat(str);
58478
58478
  }
58479
58479
  var log22;
@@ -105320,32 +105320,6 @@ a=end-of-candidates
105320
105320
  };
105321
105321
  }
105322
105322
  // @__NO_SIDE_EFFECTS__
105323
- function padding(bits, chr = "=") {
105324
- anumber2(bits);
105325
- astr("padding", chr);
105326
- return {
105327
- encode(data) {
105328
- astrArr("padding.encode", data);
105329
- while (data.length * bits % 8)
105330
- data.push(chr);
105331
- return data;
105332
- },
105333
- decode(input) {
105334
- astrArr("padding.decode", input);
105335
- let end = input.length;
105336
- if (end * bits % 8)
105337
- throw new Error("padding: invalid, string should have whole number of bytes");
105338
- for (; end > 0 && input[end - 1] === chr; end--) {
105339
- const last = end - 1;
105340
- const byte = last * bits;
105341
- if (byte % 8 === 0)
105342
- throw new Error("padding: invalid, string has too much padding");
105343
- }
105344
- return input.slice(0, end);
105345
- }
105346
- };
105347
- }
105348
- // @__NO_SIDE_EFFECTS__
105349
105323
  function normalize(fn) {
105350
105324
  afn(fn);
105351
105325
  return { encode: (from82) => from82, decode: (to) => fn(to) };
@@ -105406,7 +105380,7 @@ a=end-of-candidates
105406
105380
  res.push(2 ** i42);
105407
105381
  return res;
105408
105382
  })();
105409
- function convertRadix2(data, from82, to, padding3) {
105383
+ function convertRadix2(data, from82, to, padding2) {
105410
105384
  aArr(data);
105411
105385
  if (from82 <= 0 || from82 > 32)
105412
105386
  throw new Error(`convertRadix2: wrong from=${from82}`);
@@ -105436,11 +105410,11 @@ a=end-of-candidates
105436
105410
  carry &= pow32 - 1;
105437
105411
  }
105438
105412
  carry = carry << to - pos & mask;
105439
- if (!padding3 && pos >= from82)
105413
+ if (!padding2 && pos >= from82)
105440
105414
  throw new Error("Excess padding");
105441
- if (!padding3 && carry > 0)
105415
+ if (!padding2 && carry > 0)
105442
105416
  throw new Error(`Non-zero padding: ${carry}`);
105443
- if (padding3 && pos > 0)
105417
+ if (padding2 && pos > 0)
105444
105418
  res.push(carry >>> 0);
105445
105419
  return res;
105446
105420
  }
@@ -105514,24 +105488,6 @@ a=end-of-candidates
105514
105488
  }
105515
105489
  };
105516
105490
  }
105517
- var hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
105518
- var decodeBase64Builtin = (s2, isUrl) => {
105519
- astr("base64", s2);
105520
- const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
105521
- const alphabet52 = isUrl ? "base64url" : "base64";
105522
- if (s2.length > 0 && !re.test(s2))
105523
- throw new Error("invalid base64");
105524
- return Uint8Array.fromBase64(s2, { alphabet: alphabet52, lastChunkHandling: "strict" });
105525
- };
105526
- var base64 = hasBase64Builtin ? {
105527
- encode(b) {
105528
- abytes2(b);
105529
- return b.toBase64();
105530
- },
105531
- decode(s2) {
105532
- return decodeBase64Builtin(s2, false);
105533
- }
105534
- } : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join(""));
105535
105491
  var base64urlnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ join(""));
105536
105492
  var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
105537
105493
  var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
@@ -109857,7 +109813,7 @@ a=end-of-candidates
109857
109813
  };
109858
109814
  }
109859
109815
  // @__NO_SIDE_EFFECTS__
109860
- function padding2(bits, chr = "=") {
109816
+ function padding(bits, chr = "=") {
109861
109817
  anumber4(bits);
109862
109818
  astr2("padding", chr);
109863
109819
  return {
@@ -109938,7 +109894,7 @@ a=end-of-candidates
109938
109894
  res.push(2 ** i42);
109939
109895
  return res;
109940
109896
  })();
109941
- function convertRadix22(data, from82, to, padding3) {
109897
+ function convertRadix22(data, from82, to, padding2) {
109942
109898
  aArr2(data);
109943
109899
  if (from82 <= 0 || from82 > 32)
109944
109900
  throw new Error(`convertRadix2: wrong from=${from82}`);
@@ -109968,11 +109924,11 @@ a=end-of-candidates
109968
109924
  carry &= pow32 - 1;
109969
109925
  }
109970
109926
  carry = carry << to - pos & mask;
109971
- if (!padding3 && pos >= from82)
109927
+ if (!padding2 && pos >= from82)
109972
109928
  throw new Error("Excess padding");
109973
- if (!padding3 && carry > 0)
109929
+ if (!padding2 && carry > 0)
109974
109930
  throw new Error(`Non-zero padding: ${carry}`);
109975
- if (padding3 && pos > 0)
109931
+ if (padding2 && pos > 0)
109976
109932
  res.push(carry >>> 0);
109977
109933
  return res;
109978
109934
  }
@@ -110020,8 +109976,8 @@ a=end-of-candidates
110020
109976
  }
110021
109977
  };
110022
109978
  }
110023
- var hasBase64Builtin2 = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
110024
- var decodeBase64Builtin2 = (s2, isUrl) => {
109979
+ var hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
109980
+ var decodeBase64Builtin = (s2, isUrl) => {
110025
109981
  astr2("base64", s2);
110026
109982
  const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
110027
109983
  const alphabet52 = isUrl ? "base64url" : "base64";
@@ -110029,15 +109985,15 @@ a=end-of-candidates
110029
109985
  throw new Error("invalid base64");
110030
109986
  return Uint8Array.fromBase64(s2, { alphabet: alphabet52, lastChunkHandling: "strict" });
110031
109987
  };
110032
- var base642 = hasBase64Builtin2 ? {
109988
+ var base64 = hasBase64Builtin ? {
110033
109989
  encode(b) {
110034
109990
  abytes4(b);
110035
109991
  return b.toBase64();
110036
109992
  },
110037
109993
  decode(s2) {
110038
- return decodeBase64Builtin2(s2, false);
109994
+ return decodeBase64Builtin(s2, false);
110039
109995
  }
110040
- } : /* @__PURE__ */ chain2(/* @__PURE__ */ radix22(6), /* @__PURE__ */ alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding2(6), /* @__PURE__ */ join2(""));
109996
+ } : /* @__PURE__ */ chain2(/* @__PURE__ */ radix22(6), /* @__PURE__ */ alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join2(""));
110041
109997
  var genBase582 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain2(/* @__PURE__ */ radix3(58), /* @__PURE__ */ alphabet2(abc), /* @__PURE__ */ join2(""));
110042
109998
  var base582 = /* @__PURE__ */ genBase582("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
110043
109999
  var BECH_ALPHABET2 = /* @__PURE__ */ chain2(/* @__PURE__ */ alphabet2("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join2(""));
@@ -112263,123 +112219,23 @@ a=end-of-candidates
112263
112219
  }
112264
112220
  return s2;
112265
112221
  }
112266
- function hexToHash(hex22) {
112267
- validateHex(hex22, true);
112268
- const hash32 = new Uint8Array(HASH_BYTE_LENGTH);
112269
- for (let i42 = 0; i42 < HASH_BYTE_LENGTH; i42++) {
112270
- hash32[i42] = Number.parseInt(hex22.substring(i42 * 2, i42 * 2 + 2), 16);
112271
- }
112272
- return hash32;
112273
- }
112274
- function bigIntToHex(value2, padded) {
112275
- const s2 = value2.toString(16);
112276
- return padded ? s2.padStart(HASH_HEX_LENGTH, "0") : s2;
112277
- }
112278
- function hexToBigInt(hex22, padded) {
112279
- validateHex(hex22, padded);
112280
- return BigInt(`0x${hex22}`);
112281
- }
112282
112222
  function hashesEqual(a2, b) {
112283
112223
  if (!isValidHash(a2) || !isValidHash(b))
112284
112224
  return false;
112285
112225
  return equalBytes(a2, b);
112286
112226
  }
112287
- function hashToBase64(hash32) {
112227
+ function hashToBase64Url(hash32) {
112288
112228
  validateHash(hash32);
112289
- return base64.encode(hash32);
112229
+ return base64urlnopad.encode(hash32);
112290
112230
  }
112291
- function base64ToHash(b64) {
112292
- const hash32 = base64.decode(b64);
112231
+ function base64UrlToHash(b64u) {
112232
+ const hash32 = base64urlnopad.decode(b64u);
112293
112233
  if (hash32.length !== HASH_BYTE_LENGTH) {
112294
- throw new RangeError(`Invalid base64 hash: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${hash32.length}`);
112234
+ throw new RangeError(`Invalid base64url hash: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${hash32.length}`);
112295
112235
  }
112296
112236
  return hash32;
112297
112237
  }
112298
- function bigIntToBase64(value2, padded) {
112299
- let bytes32 = bigIntToHash(value2);
112300
- if (!padded) {
112301
- const firstNonZero = bytes32.findIndex((b) => b !== 0);
112302
- bytes32 = firstNonZero === -1 ? new Uint8Array(1) : bytes32.slice(firstNonZero);
112303
- }
112304
- return base64.encode(bytes32);
112305
- }
112306
- function base64ToBigInt(b64, padded) {
112307
- const bytes32 = base64.decode(b64);
112308
- if (padded && bytes32.length !== HASH_BYTE_LENGTH) {
112309
- throw new RangeError(`Invalid padded base64 bigint: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${bytes32.length}`);
112310
- }
112311
- if (bytes32.length > HASH_BYTE_LENGTH) {
112312
- throw new RangeError(`Value exceeds ${HASH_BYTE_LENGTH} bytes`);
112313
- }
112314
- let value2 = 0n;
112315
- for (const byte of bytes32) {
112316
- value2 = value2 << 8n | BigInt(byte);
112317
- }
112318
- return value2;
112319
- }
112320
- var HEX_RE = /^[0-9A-Fa-f]+$/;
112321
- function validateHex(s2, requireHashLength) {
112322
- const len = s2.length;
112323
- const minLen = requireHashLength ? HASH_HEX_LENGTH : 1;
112324
- if (len < minLen || len > HASH_HEX_LENGTH || !HEX_RE.test(s2)) {
112325
- throw new RangeError(`Invalid hex string: expected ${requireHashLength ? HASH_HEX_LENGTH : "1-" + HASH_HEX_LENGTH} hex characters, got ${len}`);
112326
- }
112327
- }
112328
112238
  init_shim2();
112329
- var BaseNode = class {
112330
- #index;
112331
- #depth;
112332
- constructor(index, depth) {
112333
- this.#index = index;
112334
- this.#depth = depth;
112335
- }
112336
- get index() {
112337
- return this.#index;
112338
- }
112339
- get depth() {
112340
- return this.#depth;
112341
- }
112342
- };
112343
- var LeafNode = class extends BaseNode {
112344
- #hash = null;
112345
- get hash() {
112346
- return this.#hash;
112347
- }
112348
- set hash(value2) {
112349
- if (this.#hash !== null) {
112350
- throw new RangeError("Leaf hash already set");
112351
- }
112352
- this.#hash = value2;
112353
- }
112354
- reset() {
112355
- this.#hash = null;
112356
- }
112357
- };
112358
- var ParentNode = class extends BaseNode {
112359
- #left;
112360
- #right;
112361
- constructor(index, depth, left, right) {
112362
- super(index, depth);
112363
- this.#left = left;
112364
- this.#right = right;
112365
- }
112366
- get left() {
112367
- return this.#left;
112368
- }
112369
- set left(node) {
112370
- this.#left = node;
112371
- }
112372
- get right() {
112373
- return this.#right;
112374
- }
112375
- set right(node) {
112376
- this.#right = node;
112377
- }
112378
- reset() {
112379
- this.#left.reset();
112380
- this.#right.reset();
112381
- }
112382
- };
112383
112239
  init_shim2();
112384
112240
  var ValidationState;
112385
112241
  (function(ValidationState2) {
@@ -112387,375 +112243,80 @@ a=end-of-candidates
112387
112243
  ValidationState2[ValidationState2["Valid"] = 1] = "Valid";
112388
112244
  ValidationState2[ValidationState2["Invalid"] = 2] = "Invalid";
112389
112245
  })(ValidationState || (ValidationState = {}));
112390
- var SMTProof = class _SMTProof {
112391
- #converge;
112392
- #hashes;
112393
- constructor(converge, hashes2) {
112394
- this.#converge = converge;
112395
- this.#hashes = hashes2;
112396
- }
112397
- /** Converge bitmap: bit `i` set means a sibling hash exists at depth `256 - i - 1`. */
112398
- get converge() {
112399
- return this.#converge;
112400
- }
112401
- /** Sibling hashes at converge points, ordered leaf-to-root. */
112402
- get hashes() {
112403
- return this.#hashes;
112404
- }
112405
- /**
112406
- * Verify this proof for a single leaf.
112407
- *
112408
- * @param index - Leaf index in the 256-bit key space.
112409
- * @param candidateHash - Expected leaf hash.
112410
- * @param rootHash - Expected root hash.
112411
- * @returns `true` if the proof is valid.
112412
- */
112413
- isValid(index, candidateHash, rootHash) {
112414
- return this.#validate(index, candidateHash, rootHash);
112415
- }
112416
- /**
112417
- * Batch-validate multiple proofs against the same root hash.
112418
- *
112419
- * Caches intermediate (partial) proofs so that subsequent candidates
112420
- * sharing an ancestor path can short-circuit once a cached match is found.
112421
- *
112422
- * @yields One {@link SMTProofResult} per candidate.
112423
- */
112424
- static *isValidBatch(candidates, rootHash) {
112425
- const cache42 = /* @__PURE__ */ new Map();
112426
- for (const candidate of candidates) {
112427
- const added = [];
112428
- const { index } = candidate;
112429
- const valid = candidate.proof.#validate(index | OUTER_BIT, candidate.hash, rootHash, (nodeIndex, partial) => {
112430
- const cached = cache42.get(nodeIndex);
112431
- if (cached === void 0) {
112432
- cache42.set(nodeIndex, partial);
112433
- added.push(nodeIndex);
112434
- return ValidationState.Pending;
112435
- }
112436
- if (hashesEqual(partial.hash, cached.hash) && partial.converge === cached.converge && partial.hashes.length === cached.hashes.length && partial.hashes.every((h, i42) => hashesEqual(h, cached.hashes[i42]))) {
112437
- return ValidationState.Valid;
112438
- }
112439
- return ValidationState.Invalid;
112440
- });
112441
- if (!valid) {
112442
- for (const key of added)
112443
- cache42.delete(key);
112444
- }
112445
- yield { index, valid, additional: candidate.additional };
112446
- }
112447
- }
112448
- /**
112449
- * Export to JSON.
112450
- * @param base64 - Use base64 encoding instead of hex (default: `false`).
112451
- * @param compact - Omit whitespace (default: `true`).
112452
- */
112453
- toJSON(base6462 = false, compact = true) {
112454
- const convergeStr = base6462 ? bigIntToBase64(this.#converge, false) : bigIntToHex(this.#converge, false);
112455
- const hashStrs = this.#hashes.map((h) => base6462 ? hashToBase64(h) : hashToHex(h));
112456
- const obj = { converge: convergeStr, hashes: hashStrs };
112457
- return JSON.stringify(obj, null, compact ? 0 : 2);
112458
- }
112459
- /**
112460
- * Import from JSON.
112461
- * @param json - JSON string.
112462
- * @param base64 - Parse base64 instead of hex (default: `false`).
112463
- */
112464
- static fromJSON(json, base6462 = false) {
112465
- const raw = JSON.parse(json);
112466
- if (typeof raw?.converge !== "string" || !Array.isArray(raw.hashes)) {
112467
- throw new RangeError("Invalid SMTProof JSON: expected { converge, hashes }");
112468
- }
112469
- const converge = base6462 ? base64ToBigInt(raw.converge, false) : hexToBigInt(raw.converge, false);
112470
- const hashes2 = raw.hashes.map((h) => base6462 ? base64ToHash(h) : hexToHash(h));
112471
- return new _SMTProof(converge, hashes2);
112472
- }
112473
- /**
112474
- * Export to compact binary format.
112475
- *
112476
- * Layout: `[convergeZeroCount : 1] [truncatedConverge : 32-zc] [hashCount : 1] [hashes : N*32]`
112477
- */
112478
- toBinary() {
112479
- const convergeBin = bigIntToHash(this.#converge);
112480
- let zc = 0;
112481
- while (zc < HASH_BYTE_LENGTH && convergeBin[zc] === 0)
112482
- zc++;
112483
- const truncated = convergeBin.slice(zc);
112484
- const hashCount = this.#hashes.length;
112485
- const totalBytes = 1 + truncated.length + 1 + hashCount * HASH_BYTE_LENGTH;
112486
- const out = new Uint8Array(totalBytes);
112487
- let pos = 0;
112488
- out[pos++] = zc;
112489
- out.set(truncated, pos);
112490
- pos += truncated.length;
112491
- out[pos++] = hashCount;
112492
- for (const h of this.#hashes) {
112493
- out.set(h, pos);
112494
- pos += HASH_BYTE_LENGTH;
112495
- }
112496
- return out;
112497
- }
112498
- /**
112499
- * Import from compact binary format.
112500
- * Accepts any sync or async byte iterable (e.g. `Uint8Array`, `ReadableStream`).
112501
- */
112502
- static async fromBinary(source) {
112503
- const iter = Symbol.iterator in source ? source[Symbol.iterator]() : source[Symbol.asyncIterator]();
112504
- async function readBytes(n2) {
112505
- const buf2 = new Uint8Array(n2);
112506
- for (let i42 = 0; i42 < n2; i42++) {
112507
- const r2 = await iter.next();
112508
- if (r2.done)
112509
- throw new Error("Unexpected end of binary source");
112510
- buf2[i42] = r2.value;
112511
- }
112512
- return buf2;
112513
- }
112514
- const zc = (await readBytes(1))[0];
112515
- const convergeBin = new Uint8Array(HASH_BYTE_LENGTH);
112516
- convergeBin.set(await readBytes(HASH_BYTE_LENGTH - zc), zc);
112517
- const hashCount = (await readBytes(1))[0];
112518
- const hashes2 = new Array(hashCount);
112519
- for (let i42 = 0; i42 < hashCount; i42++) {
112520
- hashes2[i42] = await readBytes(HASH_BYTE_LENGTH);
112521
- }
112522
- return new _SMTProof(hashToBigInt(convergeBin), hashes2);
112523
- }
112524
- #validate(index, candidateHash, rootHash, onMerge) {
112525
- let nodeIndex = index;
112526
- let nodeHash = candidateHash;
112527
- let remaining = this.#converge;
112528
- const hashes2 = this.#hashes;
112529
- let hi = 0;
112530
- const leftPad = [];
112531
- const rightPad = [];
112532
- const finalizePadding = () => {
112533
- if (leftPad.length > 0 || rightPad.length > 0) {
112534
- nodeHash = blockHash(new Uint8Array(leftPad), nodeHash, new Uint8Array(rightPad));
112535
- leftPad.length = 0;
112536
- rightPad.length = 0;
112537
- }
112538
- };
112539
- let state = ValidationState.Pending;
112540
- for (let i42 = 0; state === ValidationState.Pending && i42 < HASH_BIT_LENGTH; i42++) {
112541
- const isLeft = (nodeIndex & 1n) === 0n;
112542
- nodeIndex >>= 1n;
112543
- const bit = BITS[i42];
112544
- if ((remaining & bit) !== 0n) {
112545
- remaining ^= bit;
112546
- finalizePadding();
112547
- if (hi >= hashes2.length) {
112548
- state = ValidationState.Invalid;
112549
- } else {
112550
- const peer = hashes2[hi++];
112551
- nodeHash = isLeft ? blockHash(nodeHash, peer) : blockHash(peer, nodeHash);
112552
- if (onMerge !== void 0) {
112553
- state = onMerge(nodeIndex, {
112554
- hash: nodeHash,
112555
- converge: remaining,
112556
- hashes: hashes2.slice(hi)
112557
- });
112558
- }
112559
- }
112560
- } else {
112561
- const depth = HASH_BIT_LENGTH - i42 - 1;
112562
- if (isLeft) {
112563
- rightPad.push(depth);
112564
- } else {
112565
- leftPad.unshift(depth);
112566
- }
112567
- }
112568
- }
112569
- finalizePadding();
112570
- if (state === ValidationState.Pending) {
112571
- state = hi === hashes2.length && hashesEqual(nodeHash, rootHash) ? ValidationState.Valid : ValidationState.Invalid;
112572
- }
112573
- return state === ValidationState.Valid;
112574
- }
112575
- };
112576
112246
  init_shim2();
112577
- var OptimizedSMT = class _OptimizedSMT {
112578
- /** `2^256` sentinel bit above the key space. Used by batch validation. */
112579
- static OUTER_BIT = OUTER_BIT;
112580
- /** Pre-computed MSB-first bit masks for tree traversal. */
112581
- static BITS = BITS;
112582
- #allowNonInclusion;
112583
- #root = null;
112584
- #rootHash = null;
112585
- #proofs = /* @__PURE__ */ new Map();
112586
- constructor(allowNonInclusion) {
112587
- this.#allowNonInclusion = allowNonInclusion;
112588
- }
112589
- get allowNonInclusion() {
112590
- return this.#allowNonInclusion;
112247
+ init_shim2();
112248
+ var TREE_DEPTH = HASH_BIT_LENGTH;
112249
+ function bitAt(index, position) {
112250
+ return Number(index >> BigInt(position) & 1n);
112251
+ }
112252
+ var CACHED_ZERO = (() => {
112253
+ const arr = new Array(TREE_DEPTH + 1);
112254
+ let z = new Uint8Array(HASH_BYTE_LENGTH);
112255
+ for (let h = 0; h <= TREE_DEPTH; h++) {
112256
+ z = blockHash(z, z);
112257
+ arr[h] = z;
112591
112258
  }
112592
- /** Root hash. Throws if tree has not been finalized. */
112593
- get rootHash() {
112594
- if (this.#rootHash === null)
112595
- throw new RangeError("SMT not finalized");
112596
- return this.#rootHash;
112597
- }
112598
- // -----------------------------------------------------------------------
112599
- // Build phase
112600
- // -----------------------------------------------------------------------
112601
- /**
112602
- * Add leaf indexes to the tree.
112603
- * May be called multiple times before finalization. Duplicate indexes throw.
112604
- */
112605
- add(indexes) {
112606
- this.#checkNotFinalized();
112607
- for (const index of indexes) {
112608
- if (index < 0n || index >= _OptimizedSMT.OUTER_BIT) {
112609
- throw new RangeError("Index out of range");
112610
- }
112611
- const leaf = new LeafNode(index, HASH_BIT_LENGTH);
112612
- if (this.#root === null) {
112613
- this.#root = leaf;
112259
+ return arr;
112260
+ })();
112261
+ function subtreeHash(leaves, height) {
112262
+ if (leaves.length === 0)
112263
+ return CACHED_ZERO[height];
112264
+ if (height === 0)
112265
+ return leaves[0].leaf;
112266
+ const bit = TREE_DEPTH - height;
112267
+ const left = [];
112268
+ const right = [];
112269
+ for (const e2 of leaves)
112270
+ (bitAt(e2.index, bit) === 0 ? left : right).push(e2);
112271
+ return blockHash(subtreeHash(left, height - 1), subtreeHash(right, height - 1));
112272
+ }
112273
+ function zeroHashRoot(leaves) {
112274
+ return subtreeHash(leaves, TREE_DEPTH);
112275
+ }
112276
+ function generateZeroHashProof(leaves, targetIndex) {
112277
+ let collapsed = 0n;
112278
+ const hashes2 = [];
112279
+ for (let height = 1; height <= TREE_DEPTH; height++) {
112280
+ const bit = TREE_DEPTH - height;
112281
+ const siblingLeaves = [];
112282
+ for (const e2 of leaves) {
112283
+ if (e2.index === targetIndex)
112614
112284
  continue;
112615
- }
112616
- let replaceNode = (node2) => {
112617
- this.#root = node2;
112618
- };
112619
- let node = this.#root;
112620
- let commonIndex = 0n;
112621
- let commonDepth = 0;
112622
- let done = false;
112623
- while (!done) {
112624
- const bit = BITS[commonDepth];
112625
- const indexBit = index & bit;
112626
- const isLeft = indexBit === 0n;
112627
- if (commonDepth === node.depth) {
112628
- if (node instanceof ParentNode) {
112629
- const parent = node;
112630
- if (isLeft) {
112631
- node = parent.left;
112632
- replaceNode = (n2) => {
112633
- parent.left = n2;
112634
- };
112635
- } else {
112636
- node = parent.right;
112637
- replaceNode = (n2) => {
112638
- parent.right = n2;
112639
- };
112640
- }
112641
- } else {
112642
- throw new RangeError("Duplicate index");
112643
- }
112644
- } else if ((node.index & bit) === indexBit) {
112645
- commonIndex |= indexBit;
112646
- commonDepth++;
112647
- } else {
112648
- replaceNode(new ParentNode(commonIndex, commonDepth, isLeft ? leaf : node, isLeft ? node : leaf));
112649
- done = true;
112285
+ let sharesLowerPath = true;
112286
+ for (let lower = 0; lower < bit; lower++) {
112287
+ if (bitAt(e2.index, lower) !== bitAt(targetIndex, lower)) {
112288
+ sharesLowerPath = false;
112289
+ break;
112650
112290
  }
112651
112291
  }
112292
+ if (sharesLowerPath && bitAt(e2.index, bit) !== bitAt(targetIndex, bit))
112293
+ siblingLeaves.push(e2);
112652
112294
  }
112653
- }
112654
- /**
112655
- * Set the hash for a leaf at the given index.
112656
- * The index must have been previously added via {@link add}.
112657
- * Each leaf's hash can only be set once (until {@link reset}).
112658
- */
112659
- setHash(index, hash32) {
112660
- this.#checkNotFinalized();
112661
- validateHash(hash32);
112662
- let node = this.#root;
112663
- if (node === null)
112664
- throw new RangeError("Empty SMT");
112665
- while (node instanceof ParentNode) {
112666
- node = (index & BITS[node.depth]) === 0n ? node.left : node.right;
112667
- }
112668
- if (node.index !== index)
112669
- throw new RangeError("Index not found");
112670
- node.hash = hash32;
112671
- }
112672
- // -----------------------------------------------------------------------
112673
- // Finalize phase
112674
- // -----------------------------------------------------------------------
112675
- /**
112676
- * Compute root hash and generate all proofs in a single recursive pass.
112677
- * Must be called after all hashes are set.
112678
- */
112679
- finalize() {
112680
- if (this.#root === null) {
112681
- this.#rootHash = NULL_HASH;
112682
- return;
112295
+ if (siblingLeaves.length === 0) {
112296
+ collapsed |= 1n << BigInt(bit);
112297
+ } else {
112298
+ hashes2.push(subtreeHash(siblingLeaves, height - 1));
112683
112299
  }
112684
- const result = this.#finalizeStep(this.#root, 0n, 0);
112685
- this.#rootHash = result.hash;
112686
- result.saveProofs([]);
112687
- }
112688
- /** Retrieve the proof for an index. Only valid after {@link finalize}. */
112689
- proof(index) {
112690
- const p2 = this.#proofs.get(index);
112691
- if (p2 === void 0)
112692
- throw new RangeError("Proof not found");
112693
- return p2;
112694
112300
  }
112695
- /** Clear hashes and proofs, keeping the tree structure for reuse. */
112696
- reset() {
112697
- this.#root?.reset();
112698
- this.#rootHash = null;
112699
- this.#proofs.clear();
112700
- }
112701
- /**
112702
- * Check if the SMT has not been finalized yet.
112703
- * @throws {Error} If the SMT has already been finalized.
112704
- */
112705
- #checkNotFinalized() {
112706
- if (this.#rootHash !== null)
112707
- throw new Error("SMT already finalized");
112708
- }
112709
- /**
112710
- * Perform a single step of finalization on the given node.
112711
- * @param {Node} node The node to finalize.
112712
- * @param {bigint} parentConverge The convergence value from the parent node.
112713
- * @param {number} depth The current depth in the tree.
112714
- * @returns {FinalizeStepResult} The result of the finalization step.
112715
- */
112716
- #finalizeStep(node, parentConverge, depth) {
112717
- const converge = parentConverge | BITS[HASH_BIT_LENGTH - depth];
112718
- let hash32;
112719
- let saveProofs;
112720
- if (node instanceof ParentNode) {
112721
- const childDepth = node.depth + 1;
112722
- const leftResult = this.#finalizeStep(node.left, converge, childDepth);
112723
- const rightResult = this.#finalizeStep(node.right, converge, childDepth);
112724
- hash32 = blockHash(leftResult.hash, rightResult.hash);
112725
- saveProofs = (hashes2) => {
112726
- const leftHashes = hashes2;
112727
- const rightHashes = hashes2.slice();
112728
- leftHashes.unshift(rightResult.hash);
112729
- rightHashes.unshift(leftResult.hash);
112730
- leftResult.saveProofs(leftHashes);
112731
- rightResult.saveProofs(rightHashes);
112732
- };
112301
+ return { collapsed, hashes: hashes2 };
112302
+ }
112303
+ function verifyZeroHash(collapsed, hashes2, index, candidate, root) {
112304
+ let acc = candidate;
112305
+ let hashPtr = 0;
112306
+ for (let n2 = 0; n2 < TREE_DEPTH; n2++) {
112307
+ const i42 = TREE_DEPTH - 1 - n2;
112308
+ let sibling;
112309
+ if ((collapsed >> BigInt(i42) & 1n) === 1n) {
112310
+ sibling = CACHED_ZERO[n2];
112733
112311
  } else {
112734
- if (node.hash === null) {
112735
- if (!this.#allowNonInclusion)
112736
- throw new RangeError("Hash missing");
112737
- node.hash = NULL_HASH;
112738
- }
112739
- hash32 = node.hash;
112740
- saveProofs = (hashes2) => {
112741
- this.#proofs.set(node.index, new SMTProof(converge, hashes2));
112742
- };
112743
- }
112744
- if (node.depth !== depth) {
112745
- const leftPad = [];
112746
- const rightPad = [];
112747
- for (let i42 = node.depth - 1; i42 >= depth; i42--) {
112748
- if ((node.index & BITS[i42]) === 0n) {
112749
- rightPad.push(i42);
112750
- } else {
112751
- leftPad.unshift(i42);
112752
- }
112753
- }
112754
- hash32 = blockHash(new Uint8Array(leftPad), hash32, new Uint8Array(rightPad));
112312
+ if (hashPtr >= hashes2.length)
112313
+ return false;
112314
+ sibling = hashes2[hashPtr++];
112755
112315
  }
112756
- return { hash: hash32, saveProofs };
112316
+ acc = bitAt(index, i42) === 1 ? blockHash(sibling, acc) : blockHash(acc, sibling);
112757
112317
  }
112758
- };
112318
+ return hashPtr === hashes2.length && hashesEqual(acc, root);
112319
+ }
112759
112320
  init_shim2();
112760
112321
  var encoder = new TextEncoder();
112761
112322
  function didToIndex(did) {
@@ -112768,49 +112329,51 @@ a=end-of-candidates
112768
112329
  return blockHash(blockHash(nonce));
112769
112330
  }
112770
112331
  init_shim2();
112771
- function serializeProof(proof, rootHash, options2) {
112332
+ function serializeProof(rootHash, proof, options2) {
112772
112333
  const result = {
112773
- id: hashToHex(rootHash),
112774
- collapsed: bigIntToHex(proof.converge, false),
112775
- hashes: proof.hashes.map((h) => hashToHex(h))
112334
+ id: hashToBase64Url(rootHash),
112335
+ collapsed: hashToBase64Url(bigIntToHash(proof.collapsed)),
112336
+ hashes: proof.hashes.map((h) => hashToBase64Url(h))
112776
112337
  };
112777
112338
  if (options2?.nonce)
112778
- result.nonce = hashToHex(options2.nonce);
112339
+ result.nonce = hashToBase64Url(options2.nonce);
112779
112340
  if (options2?.updateId)
112780
- result.updateId = hashToHex(options2.updateId);
112341
+ result.updateId = hashToBase64Url(options2.updateId);
112781
112342
  return result;
112782
112343
  }
112783
112344
  function deserializeProof(serialized) {
112784
- const converge = hexToBigInt(serialized.collapsed, false);
112785
- const hashes2 = serialized.hashes.map((h) => hexToHash(h));
112786
112345
  const result = {
112787
- proof: new SMTProof(converge, hashes2),
112788
- rootHash: hexToHash(serialized.id)
112346
+ rootHash: base64UrlToHash(serialized.id),
112347
+ collapsed: hashToBigInt(base64UrlToHash(serialized.collapsed)),
112348
+ hashes: serialized.hashes.map((h) => base64UrlToHash(h))
112789
112349
  };
112790
112350
  if (serialized.nonce)
112791
- result.nonce = hexToHash(serialized.nonce);
112351
+ result.nonce = base64UrlToHash(serialized.nonce);
112792
112352
  if (serialized.updateId)
112793
- result.updateId = hexToHash(serialized.updateId);
112353
+ result.updateId = base64UrlToHash(serialized.updateId);
112794
112354
  return result;
112795
112355
  }
112796
112356
  function verifySerializedProof(serialized, index, candidateHash) {
112797
- const { proof, rootHash } = deserializeProof(serialized);
112798
- return proof.isValid(index, candidateHash, rootHash);
112357
+ const { rootHash, collapsed, hashes: hashes2 } = deserializeProof(serialized);
112358
+ return verifyZeroHash(collapsed, hashes2, index, candidateHash, rootHash);
112799
112359
  }
112800
112360
  init_shim2();
112801
112361
  var BTCR2MerkleTree = class {
112802
- #smt;
112803
112362
  #entries = /* @__PURE__ */ new Map();
112804
112363
  #indexByDid = /* @__PURE__ */ new Map();
112805
- constructor(allowNonInclusion = true) {
112806
- this.#smt = new OptimizedSMT(allowNonInclusion);
112364
+ #leaves = null;
112365
+ #root = null;
112366
+ /**
112367
+ * @param _allowNonInclusion Retained for API compatibility; non-inclusion
112368
+ * leaves are always supported (an entry without `signedUpdate`).
112369
+ */
112370
+ constructor(_allowNonInclusion = true) {
112807
112371
  }
112808
112372
  /**
112809
112373
  * Add entries to the tree. May be called multiple times before
112810
112374
  * {@link finalize}. Duplicate DIDs (same index) throw.
112811
112375
  */
112812
112376
  addEntries(entries) {
112813
- const indexes = [];
112814
112377
  for (const entry of entries) {
112815
112378
  const index = didToIndex(entry.did);
112816
112379
  if (this.#entries.has(index)) {
@@ -112818,24 +112381,28 @@ a=end-of-candidates
112818
112381
  }
112819
112382
  this.#entries.set(index, entry);
112820
112383
  this.#indexByDid.set(entry.did, index);
112821
- indexes.push(index);
112822
112384
  }
112823
- this.#smt.add(indexes);
112385
+ this.#leaves = null;
112386
+ this.#root = null;
112824
112387
  }
112825
112388
  /**
112826
- * Compute leaf hashes and finalize the tree.
112389
+ * Compute leaf hashes and the zero-hash root.
112827
112390
  * After this call, {@link rootHash} and {@link proof} become available.
112828
112391
  */
112829
112392
  finalize() {
112393
+ const leaves = [];
112830
112394
  for (const [index, entry] of this.#entries) {
112831
- const leafHash = entry.signedUpdate !== void 0 ? inclusionLeafHash(entry.nonce, entry.signedUpdate) : nonInclusionLeafHash(entry.nonce);
112832
- this.#smt.setHash(index, leafHash);
112395
+ const leaf = entry.signedUpdate !== void 0 ? inclusionLeafHash(entry.nonce, entry.signedUpdate) : nonInclusionLeafHash(entry.nonce);
112396
+ leaves.push({ index, leaf });
112833
112397
  }
112834
- this.#smt.finalize();
112398
+ this.#leaves = leaves;
112399
+ this.#root = zeroHashRoot(leaves);
112835
112400
  }
112836
112401
  /** Root hash of the finalized tree. Throws if not finalized. */
112837
112402
  get rootHash() {
112838
- return this.#smt.rootHash;
112403
+ if (this.#root === null)
112404
+ throw new Error("Tree not finalized: call finalize() first");
112405
+ return this.#root;
112839
112406
  }
112840
112407
  /**
112841
112408
  * Get the did:btcr2 serialized proof for a DID.
@@ -112845,14 +112412,18 @@ a=end-of-candidates
112845
112412
  const index = this.#indexByDid.get(did);
112846
112413
  if (index === void 0)
112847
112414
  throw new RangeError(`DID not in tree: ${did}`);
112415
+ if (this.#leaves === null || this.#root === null) {
112416
+ throw new Error("Tree not finalized: call finalize() first");
112417
+ }
112848
112418
  const entry = this.#entries.get(index);
112849
- const smtProof = this.#smt.proof(index);
112419
+ const proof = generateZeroHashProof(this.#leaves, index);
112850
112420
  const updateId = entry.signedUpdate !== void 0 ? blockHash(entry.signedUpdate) : void 0;
112851
- return serializeProof(smtProof, this.#smt.rootHash, { nonce: entry.nonce, updateId });
112421
+ return serializeProof(this.#root, proof, { nonce: entry.nonce, updateId });
112852
112422
  }
112853
- /** Clear hashes and proofs, keeping tree structure. Entries are preserved. */
112423
+ /** Clear computed leaves and root, keeping entries. */
112854
112424
  reset() {
112855
- this.#smt.reset();
112425
+ this.#leaves = null;
112426
+ this.#root = null;
112856
112427
  }
112857
112428
  };
112858
112429
  var CAS_STRATEGY = {
@@ -112885,12 +112456,12 @@ a=end-of-candidates
112885
112456
  const smtProof = body.smtProof;
112886
112457
  if (!smtProof?.updateId || !smtProof?.nonce) return { matches: false };
112887
112458
  const canonicalBytes = new TextEncoder().encode(canonicalize2(submittedUpdate));
112888
- const expectedUpdateId = hashToHex(blockHash(canonicalBytes));
112459
+ const expectedUpdateId = hashToBase64Url(blockHash(canonicalBytes));
112889
112460
  if (smtProof.updateId !== expectedUpdateId) {
112890
112461
  return { matches: false, smtProof };
112891
112462
  }
112892
112463
  const index = didToIndex(participantDid);
112893
- const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
112464
+ const candidateHash = blockHash(blockHash(base64UrlToHash(smtProof.nonce)), base64UrlToHash(smtProof.updateId));
112894
112465
  return {
112895
112466
  matches: verifySerializedProof(smtProof, index, candidateHash),
112896
112467
  smtProof
@@ -117166,8 +116737,8 @@ a=end-of-candidates
117166
116737
  let iv = Uint8Array.from(randomBytes2(16));
117167
116738
  let plaintext = utf8Encoder.encode(text);
117168
116739
  let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);
117169
- let ctb64 = base642.encode(new Uint8Array(ciphertext));
117170
- let ivb64 = base642.encode(new Uint8Array(iv.buffer));
116740
+ let ctb64 = base64.encode(new Uint8Array(ciphertext));
116741
+ let ivb64 = base64.encode(new Uint8Array(iv.buffer));
117171
116742
  return `${ctb64}?iv=${ivb64}`;
117172
116743
  }
117173
116744
  function decrypt2(secretKey, pubkey, data) {
@@ -117175,8 +116746,8 @@ a=end-of-candidates
117175
116746
  let [ctb64, ivb64] = data.split("?iv=");
117176
116747
  let key = secp256k1.getSharedSecret(privkey, hexToBytes2("02" + pubkey));
117177
116748
  let normalizedKey = getNormalizedX(key);
117178
- let iv = base642.decode(ivb64);
117179
- let ciphertext = base642.decode(ctb64);
116749
+ let iv = base64.decode(ivb64);
116750
+ let ciphertext = base64.decode(ctb64);
117180
116751
  let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext);
117181
116752
  return utf8Decoder.decode(plaintext);
117182
116753
  }
@@ -117496,7 +117067,7 @@ a=end-of-candidates
117496
117067
  throw new Error("unknown encryption version");
117497
117068
  let data;
117498
117069
  try {
117499
- data = base642.decode(payload);
117070
+ data = base64.decode(payload);
117500
117071
  } catch (error) {
117501
117072
  throw new Error("invalid base64: " + error.message);
117502
117073
  }
@@ -117517,7 +117088,7 @@ a=end-of-candidates
117517
117088
  const padded = pad(plaintext);
117518
117089
  const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
117519
117090
  const mac = hmacAad(hmac_key, ciphertext, nonce);
117520
- return base642.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
117091
+ return base64.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
117521
117092
  }
117522
117093
  function decrypt22(payload, conversationKey) {
117523
117094
  const { nonce, ciphertext, mac } = decodePayload(payload);
@@ -118792,7 +118363,7 @@ a=end-of-candidates
118792
118363
  }
118793
118364
  const signedEvent = await sign(event);
118794
118365
  const authorizationScheme = includeAuthorizationScheme ? _authorizationScheme : "";
118795
- return authorizationScheme + base642.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
118366
+ return authorizationScheme + base64.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
118796
118367
  }
118797
118368
  async function validateToken(token, url, method) {
118798
118369
  const event = await unpackEventFromToken(token).catch((error) => {
@@ -118808,7 +118379,7 @@ a=end-of-candidates
118808
118379
  throw new Error("Missing token");
118809
118380
  }
118810
118381
  token = token.replace(_authorizationScheme, "");
118811
- const eventB64 = utf8Decoder.decode(base642.decode(token));
118382
+ const eventB64 = utf8Decoder.decode(base64.decode(token));
118812
118383
  if (!eventB64 || eventB64.length === 0 || !eventB64.startsWith("{")) {
118813
118384
  throw new Error("Invalid token");
118814
118385
  }
@@ -118958,6 +118529,9 @@ a=end-of-candidates
118958
118529
  }
118959
118530
  var DEFAULT_BROADCAST_LOOKBACK_MS = 5 * 60 * 1e3;
118960
118531
  init_shim2();
118532
+ init_utils();
118533
+ init_shim2();
118534
+ init_shim2();
118961
118535
  init_shim2();
118962
118536
  init_shim2();
118963
118537
  init_shim2();
@@ -119080,7 +118654,7 @@ a=end-of-candidates
119080
118654
  tx.finalize();
119081
118655
  return tx.hex;
119082
118656
  }
119083
- var Beacon = class {
118657
+ var SinglePartyBeacon = class {
119084
118658
  /**
119085
118659
  * The Beacon service configuration parsed from the DID Document.
119086
118660
  */
@@ -119215,7 +118789,7 @@ a=end-of-candidates
119215
118789
  }
119216
118790
  };
119217
118791
  init_shim2();
119218
- var CASBeacon = class extends Beacon {
118792
+ var CASBeacon = class extends SinglePartyBeacon {
119219
118793
  /**
119220
118794
  * Creates an instance of CASBeacon.
119221
118795
  * @param {BeaconService} service The service of the Beacon.
@@ -119275,7 +118849,7 @@ a=end-of-candidates
119275
118849
  * Creates a CAS Announcement mapping the DID to the update hash, broadcasts the hash of the
119276
118850
  * announcement via OP_RETURN, and optionally publishes the announcement off-chain via the
119277
118851
  * supplied `casPublish` callback. UTXO selection, PSBT construction, fee estimation, signing,
119278
- * and broadcast are delegated to {@link Beacon.buildSignAndBroadcast}.
118852
+ * and broadcast are delegated to {@link SinglePartyBeacon.buildSignAndBroadcast}.
119279
118853
  *
119280
118854
  * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
119281
118855
  * @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
@@ -119299,7 +118873,7 @@ a=end-of-candidates
119299
118873
  };
119300
118874
  init_shim2();
119301
118875
  init_shim2();
119302
- var SingletonBeacon = class extends Beacon {
118876
+ var SingletonBeacon = class extends SinglePartyBeacon {
119303
118877
  /**
119304
118878
  * Creates an instance of SingletonBeacon.
119305
118879
  * @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
@@ -119336,7 +118910,7 @@ a=end-of-candidates
119336
118910
  *
119337
118911
  * The signal bytes embedded in OP_RETURN are the SHA-256 canonical hash of the signed update.
119338
118912
  * UTXO selection, PSBT construction, fee estimation, signing, and broadcast are delegated to
119339
- * {@link Beacon.buildSignAndBroadcast}.
118913
+ * {@link SinglePartyBeacon.buildSignAndBroadcast}.
119340
118914
  *
119341
118915
  * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
119342
118916
  * @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
@@ -119353,7 +118927,7 @@ a=end-of-candidates
119353
118927
  };
119354
118928
  init_shim2();
119355
118929
  init_utils();
119356
- var SMTBeacon = class extends Beacon {
118930
+ var SMTBeacon = class extends SinglePartyBeacon {
119357
118931
  /**
119358
118932
  * Creates an instance of SMTBeacon.
119359
118933
  * @param {BeaconService} service The Beacon service.
@@ -119388,9 +118962,6 @@ a=end-of-candidates
119388
118962
  });
119389
118963
  continue;
119390
118964
  }
119391
- if (!smtProof.updateId) {
119392
- continue;
119393
- }
119394
118965
  if (!smtProof.nonce) {
119395
118966
  throw new SMTBeaconError(
119396
118967
  "SMT proof missing required nonce field.",
@@ -119399,7 +118970,8 @@ a=end-of-candidates
119399
118970
  );
119400
118971
  }
119401
118972
  const index = didToIndex(did);
119402
- const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
118973
+ const nonceHash2 = base64UrlToHash(smtProof.nonce);
118974
+ const candidateHash = smtProof.updateId ? blockHash(blockHash(nonceHash2), base64UrlToHash(smtProof.updateId)) : blockHash(blockHash(nonceHash2));
119403
118975
  const valid = verifySerializedProof(smtProof, index, candidateHash);
119404
118976
  if (!valid) {
119405
118977
  throw new SMTBeaconError(
@@ -119408,11 +118980,15 @@ a=end-of-candidates
119408
118980
  { smtProof, did }
119409
118981
  );
119410
118982
  }
119411
- const signedUpdate = sidecar.updateMap.get(smtProof.updateId);
118983
+ if (!smtProof.updateId) {
118984
+ continue;
118985
+ }
118986
+ const updateHashHex = hashToHex(base64UrlToHash(smtProof.updateId));
118987
+ const signedUpdate = sidecar.updateMap.get(updateHashHex);
119412
118988
  if (!signedUpdate) {
119413
118989
  needs.push({
119414
118990
  kind: "NeedSignedUpdate",
119415
- updateHash: smtProof.updateId,
118991
+ updateHash: updateHashHex,
119416
118992
  beaconServiceId: this.service.id
119417
118993
  });
119418
118994
  continue;
@@ -119427,7 +119003,7 @@ a=end-of-candidates
119427
119003
  * Builds a single-entry Sparse Merkle Tree from the signed update, then broadcasts the tree's
119428
119004
  * root hash via OP_RETURN. For multi-party aggregation, use the {@link AggregationService}
119429
119005
  * subsystem directly instead of this method. UTXO selection, PSBT construction, fee estimation,
119430
- * signing, and broadcast are delegated to {@link Beacon.buildSignAndBroadcast}.
119006
+ * signing, and broadcast are delegated to {@link SinglePartyBeacon.buildSignAndBroadcast}.
119431
119007
  *
119432
119008
  * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
119433
119009
  * @param {Signer} signer Signer that produces the ECDSA signature for the Bitcoin transaction.
@@ -119451,7 +119027,7 @@ a=end-of-candidates
119451
119027
  /**
119452
119028
  * Establish a Beacon instance based on the provided service and optional sidecar data.
119453
119029
  * @param {BeaconService} service The beacon service configuration.
119454
- * @returns {Beacon} The established Beacon instance.
119030
+ * @returns {SinglePartyBeacon} The established Beacon instance.
119455
119031
  */
119456
119032
  static establish(service) {
119457
119033
  switch (service.type) {
@@ -135168,7 +134744,7 @@ a=end-of-candidates
135168
134744
  const smtMap = /* @__PURE__ */ new Map();
135169
134745
  if (sidecar.smtProofs?.length)
135170
134746
  for (const proof of sidecar.smtProofs) {
135171
- smtMap.set(proof.id, proof);
134747
+ smtMap.set(encode(decode(proof.id, "base64urlnopad"), "hex"), proof);
135172
134748
  }
135173
134749
  return { updateMap, casMap, smtMap };
135174
134750
  }
@@ -135456,11 +135032,12 @@ a=end-of-candidates
135456
135032
  case "NeedSMTProof": {
135457
135033
  const smtNeed = need;
135458
135034
  const proof = data;
135459
- if (proof.id !== smtNeed.smtRootHash) {
135035
+ const proofIdHex = encode(decode(proof.id, "base64urlnopad"), "hex");
135036
+ if (proofIdHex !== smtNeed.smtRootHash) {
135460
135037
  throw new ResolveError(
135461
- `SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proof.id}`,
135038
+ `SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proofIdHex}`,
135462
135039
  INVALID_DID_UPDATE,
135463
- { expected: smtNeed.smtRootHash, actual: proof.id }
135040
+ { expected: smtNeed.smtRootHash, actual: proofIdHex }
135464
135041
  );
135465
135042
  }
135466
135043
  this.#sidecarData.smtMap.set(smtNeed.smtRootHash, proof);
@@ -136097,7 +135674,7 @@ a=end-of-candidates
136097
135674
  res.push(2 ** i5);
136098
135675
  return res;
136099
135676
  })();
136100
- function convertRadix23(data, from14, to, padding3) {
135677
+ function convertRadix23(data, from14, to, padding2) {
136101
135678
  aArr3(data);
136102
135679
  if (from14 <= 0 || from14 > 32)
136103
135680
  throw new Error(`convertRadix2: wrong from=${from14}`);
@@ -136127,11 +135704,11 @@ a=end-of-candidates
136127
135704
  carry &= pow4 - 1;
136128
135705
  }
136129
135706
  carry = carry << to - pos & mask;
136130
- if (!padding3 && pos >= from14)
135707
+ if (!padding2 && pos >= from14)
136131
135708
  throw new Error("Excess padding");
136132
- if (!padding3 && carry > 0)
135709
+ if (!padding2 && carry > 0)
136133
135710
  throw new Error(`Non-zero padding: ${carry}`);
136134
- if (padding3 && pos > 0)
135711
+ if (padding2 && pos > 0)
136135
135712
  res.push(carry >>> 0);
136136
135713
  return res;
136137
135714
  }
@@ -146728,7 +146305,7 @@ a=end-of-candidates
146728
146305
 
146729
146306
  // ../../node_modules/.pnpm/multiformats@13.1.0/node_modules/multiformats/dist/src/bases/base64.js
146730
146307
  init_shim();
146731
- var base646 = rfc46485({
146308
+ var base642 = rfc46485({
146732
146309
  prefix: "m",
146733
146310
  name: "base64",
146734
146311
  alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
@@ -158712,7 +158289,7 @@ a=end-of-candidates
158712
158289
  };
158713
158290
 
158714
158291
  // ../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base64.js
158715
- var base647 = rfc46486({
158292
+ var base646 = rfc46486({
158716
158293
  prefix: "m",
158717
158294
  name: "base64",
158718
158295
  alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",