@did-btcr2/api 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.mjs CHANGED
@@ -222,7 +222,7 @@ var require_buffer = __commonJS({
222
222
  "../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js"(exports) {
223
223
  "use strict";
224
224
  init_shim();
225
- var base648 = require_base64_js();
225
+ var base647 = require_base64_js();
226
226
  var ieee754 = require_ieee754();
227
227
  var customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") : null;
228
228
  exports.Buffer = Buffer3;
@@ -923,9 +923,9 @@ var require_buffer = __commonJS({
923
923
  };
924
924
  function base64Slice(buf2, start2, end) {
925
925
  if (start2 === 0 && end === buf2.length) {
926
- return base648.fromByteArray(buf2);
926
+ return base647.fromByteArray(buf2);
927
927
  } else {
928
- return base648.fromByteArray(buf2.slice(start2, end));
928
+ return base647.fromByteArray(buf2.slice(start2, end));
929
929
  }
930
930
  }
931
931
  function utf8Slice2(buf2, start2, end) {
@@ -1560,7 +1560,7 @@ var require_buffer = __commonJS({
1560
1560
  return byteArray;
1561
1561
  }
1562
1562
  function base64ToBytes(str) {
1563
- return base648.toByteArray(base64clean(str));
1563
+ return base647.toByteArray(base64clean(str));
1564
1564
  }
1565
1565
  function blitBuffer(src6, dst, offset, length9) {
1566
1566
  for (var i5 = 0; i5 < length9; ++i5) {
@@ -58438,11 +58438,11 @@ function padNumber(inputNumber, fullLength) {
58438
58438
  return "";
58439
58439
  }
58440
58440
  const dif = fullLength - str.length;
58441
- const padding3 = new Array(dif);
58441
+ const padding2 = new Array(dif);
58442
58442
  for (let i42 = 0; i42 < dif; i42++) {
58443
- padding3[i42] = "0";
58443
+ padding2[i42] = "0";
58444
58444
  }
58445
- const paddingString = padding3.join("");
58445
+ const paddingString = padding2.join("");
58446
58446
  return paddingString.concat(str);
58447
58447
  }
58448
58448
  var log22;
@@ -105289,32 +105289,6 @@ function join(separator = "") {
105289
105289
  };
105290
105290
  }
105291
105291
  // @__NO_SIDE_EFFECTS__
105292
- function padding(bits, chr = "=") {
105293
- anumber2(bits);
105294
- astr("padding", chr);
105295
- return {
105296
- encode(data) {
105297
- astrArr("padding.encode", data);
105298
- while (data.length * bits % 8)
105299
- data.push(chr);
105300
- return data;
105301
- },
105302
- decode(input) {
105303
- astrArr("padding.decode", input);
105304
- let end = input.length;
105305
- if (end * bits % 8)
105306
- throw new Error("padding: invalid, string should have whole number of bytes");
105307
- for (; end > 0 && input[end - 1] === chr; end--) {
105308
- const last = end - 1;
105309
- const byte = last * bits;
105310
- if (byte % 8 === 0)
105311
- throw new Error("padding: invalid, string has too much padding");
105312
- }
105313
- return input.slice(0, end);
105314
- }
105315
- };
105316
- }
105317
- // @__NO_SIDE_EFFECTS__
105318
105292
  function normalize(fn) {
105319
105293
  afn(fn);
105320
105294
  return { encode: (from82) => from82, decode: (to) => fn(to) };
@@ -105375,7 +105349,7 @@ var powers = /* @__PURE__ */ (() => {
105375
105349
  res.push(2 ** i42);
105376
105350
  return res;
105377
105351
  })();
105378
- function convertRadix2(data, from82, to, padding3) {
105352
+ function convertRadix2(data, from82, to, padding2) {
105379
105353
  aArr(data);
105380
105354
  if (from82 <= 0 || from82 > 32)
105381
105355
  throw new Error(`convertRadix2: wrong from=${from82}`);
@@ -105405,11 +105379,11 @@ function convertRadix2(data, from82, to, padding3) {
105405
105379
  carry &= pow32 - 1;
105406
105380
  }
105407
105381
  carry = carry << to - pos & mask;
105408
- if (!padding3 && pos >= from82)
105382
+ if (!padding2 && pos >= from82)
105409
105383
  throw new Error("Excess padding");
105410
- if (!padding3 && carry > 0)
105384
+ if (!padding2 && carry > 0)
105411
105385
  throw new Error(`Non-zero padding: ${carry}`);
105412
- if (padding3 && pos > 0)
105386
+ if (padding2 && pos > 0)
105413
105387
  res.push(carry >>> 0);
105414
105388
  return res;
105415
105389
  }
@@ -105483,24 +105457,6 @@ function checksum(len, fn) {
105483
105457
  }
105484
105458
  };
105485
105459
  }
105486
- var hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
105487
- var decodeBase64Builtin = (s2, isUrl) => {
105488
- astr("base64", s2);
105489
- const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
105490
- const alphabet52 = isUrl ? "base64url" : "base64";
105491
- if (s2.length > 0 && !re.test(s2))
105492
- throw new Error("invalid base64");
105493
- return Uint8Array.fromBase64(s2, { alphabet: alphabet52, lastChunkHandling: "strict" });
105494
- };
105495
- var base64 = hasBase64Builtin ? {
105496
- encode(b) {
105497
- abytes2(b);
105498
- return b.toBase64();
105499
- },
105500
- decode(s2) {
105501
- return decodeBase64Builtin(s2, false);
105502
- }
105503
- } : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join(""));
105504
105460
  var base64urlnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ join(""));
105505
105461
  var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
105506
105462
  var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
@@ -109826,7 +109782,7 @@ function join2(separator = "") {
109826
109782
  };
109827
109783
  }
109828
109784
  // @__NO_SIDE_EFFECTS__
109829
- function padding2(bits, chr = "=") {
109785
+ function padding(bits, chr = "=") {
109830
109786
  anumber4(bits);
109831
109787
  astr2("padding", chr);
109832
109788
  return {
@@ -109907,7 +109863,7 @@ var powers2 = /* @__PURE__ */ (() => {
109907
109863
  res.push(2 ** i42);
109908
109864
  return res;
109909
109865
  })();
109910
- function convertRadix22(data, from82, to, padding3) {
109866
+ function convertRadix22(data, from82, to, padding2) {
109911
109867
  aArr2(data);
109912
109868
  if (from82 <= 0 || from82 > 32)
109913
109869
  throw new Error(`convertRadix2: wrong from=${from82}`);
@@ -109937,11 +109893,11 @@ function convertRadix22(data, from82, to, padding3) {
109937
109893
  carry &= pow32 - 1;
109938
109894
  }
109939
109895
  carry = carry << to - pos & mask;
109940
- if (!padding3 && pos >= from82)
109896
+ if (!padding2 && pos >= from82)
109941
109897
  throw new Error("Excess padding");
109942
- if (!padding3 && carry > 0)
109898
+ if (!padding2 && carry > 0)
109943
109899
  throw new Error(`Non-zero padding: ${carry}`);
109944
- if (padding3 && pos > 0)
109900
+ if (padding2 && pos > 0)
109945
109901
  res.push(carry >>> 0);
109946
109902
  return res;
109947
109903
  }
@@ -109989,8 +109945,8 @@ function unsafeWrapper2(fn) {
109989
109945
  }
109990
109946
  };
109991
109947
  }
109992
- var hasBase64Builtin2 = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
109993
- var decodeBase64Builtin2 = (s2, isUrl) => {
109948
+ var hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
109949
+ var decodeBase64Builtin = (s2, isUrl) => {
109994
109950
  astr2("base64", s2);
109995
109951
  const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
109996
109952
  const alphabet52 = isUrl ? "base64url" : "base64";
@@ -109998,15 +109954,15 @@ var decodeBase64Builtin2 = (s2, isUrl) => {
109998
109954
  throw new Error("invalid base64");
109999
109955
  return Uint8Array.fromBase64(s2, { alphabet: alphabet52, lastChunkHandling: "strict" });
110000
109956
  };
110001
- var base642 = hasBase64Builtin2 ? {
109957
+ var base64 = hasBase64Builtin ? {
110002
109958
  encode(b) {
110003
109959
  abytes4(b);
110004
109960
  return b.toBase64();
110005
109961
  },
110006
109962
  decode(s2) {
110007
- return decodeBase64Builtin2(s2, false);
109963
+ return decodeBase64Builtin(s2, false);
110008
109964
  }
110009
- } : /* @__PURE__ */ chain2(/* @__PURE__ */ radix22(6), /* @__PURE__ */ alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding2(6), /* @__PURE__ */ join2(""));
109965
+ } : /* @__PURE__ */ chain2(/* @__PURE__ */ radix22(6), /* @__PURE__ */ alphabet2("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join2(""));
110010
109966
  var genBase582 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain2(/* @__PURE__ */ radix3(58), /* @__PURE__ */ alphabet2(abc), /* @__PURE__ */ join2(""));
110011
109967
  var base582 = /* @__PURE__ */ genBase582("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
110012
109968
  var BECH_ALPHABET2 = /* @__PURE__ */ chain2(/* @__PURE__ */ alphabet2("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join2(""));
@@ -112232,123 +112188,23 @@ function hashToHex(hash32) {
112232
112188
  }
112233
112189
  return s2;
112234
112190
  }
112235
- function hexToHash(hex22) {
112236
- validateHex(hex22, true);
112237
- const hash32 = new Uint8Array(HASH_BYTE_LENGTH);
112238
- for (let i42 = 0; i42 < HASH_BYTE_LENGTH; i42++) {
112239
- hash32[i42] = Number.parseInt(hex22.substring(i42 * 2, i42 * 2 + 2), 16);
112240
- }
112241
- return hash32;
112242
- }
112243
- function bigIntToHex(value2, padded) {
112244
- const s2 = value2.toString(16);
112245
- return padded ? s2.padStart(HASH_HEX_LENGTH, "0") : s2;
112246
- }
112247
- function hexToBigInt(hex22, padded) {
112248
- validateHex(hex22, padded);
112249
- return BigInt(`0x${hex22}`);
112250
- }
112251
112191
  function hashesEqual(a2, b) {
112252
112192
  if (!isValidHash(a2) || !isValidHash(b))
112253
112193
  return false;
112254
112194
  return equalBytes(a2, b);
112255
112195
  }
112256
- function hashToBase64(hash32) {
112196
+ function hashToBase64Url(hash32) {
112257
112197
  validateHash(hash32);
112258
- return base64.encode(hash32);
112198
+ return base64urlnopad.encode(hash32);
112259
112199
  }
112260
- function base64ToHash(b64) {
112261
- const hash32 = base64.decode(b64);
112200
+ function base64UrlToHash(b64u) {
112201
+ const hash32 = base64urlnopad.decode(b64u);
112262
112202
  if (hash32.length !== HASH_BYTE_LENGTH) {
112263
- throw new RangeError(`Invalid base64 hash: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${hash32.length}`);
112203
+ throw new RangeError(`Invalid base64url hash: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${hash32.length}`);
112264
112204
  }
112265
112205
  return hash32;
112266
112206
  }
112267
- function bigIntToBase64(value2, padded) {
112268
- let bytes32 = bigIntToHash(value2);
112269
- if (!padded) {
112270
- const firstNonZero = bytes32.findIndex((b) => b !== 0);
112271
- bytes32 = firstNonZero === -1 ? new Uint8Array(1) : bytes32.slice(firstNonZero);
112272
- }
112273
- return base64.encode(bytes32);
112274
- }
112275
- function base64ToBigInt(b64, padded) {
112276
- const bytes32 = base64.decode(b64);
112277
- if (padded && bytes32.length !== HASH_BYTE_LENGTH) {
112278
- throw new RangeError(`Invalid padded base64 bigint: expected ${HASH_BYTE_LENGTH} decoded bytes, got ${bytes32.length}`);
112279
- }
112280
- if (bytes32.length > HASH_BYTE_LENGTH) {
112281
- throw new RangeError(`Value exceeds ${HASH_BYTE_LENGTH} bytes`);
112282
- }
112283
- let value2 = 0n;
112284
- for (const byte of bytes32) {
112285
- value2 = value2 << 8n | BigInt(byte);
112286
- }
112287
- return value2;
112288
- }
112289
- var HEX_RE = /^[0-9A-Fa-f]+$/;
112290
- function validateHex(s2, requireHashLength) {
112291
- const len = s2.length;
112292
- const minLen = requireHashLength ? HASH_HEX_LENGTH : 1;
112293
- if (len < minLen || len > HASH_HEX_LENGTH || !HEX_RE.test(s2)) {
112294
- throw new RangeError(`Invalid hex string: expected ${requireHashLength ? HASH_HEX_LENGTH : "1-" + HASH_HEX_LENGTH} hex characters, got ${len}`);
112295
- }
112296
- }
112297
112207
  init_shim2();
112298
- var BaseNode = class {
112299
- #index;
112300
- #depth;
112301
- constructor(index, depth) {
112302
- this.#index = index;
112303
- this.#depth = depth;
112304
- }
112305
- get index() {
112306
- return this.#index;
112307
- }
112308
- get depth() {
112309
- return this.#depth;
112310
- }
112311
- };
112312
- var LeafNode = class extends BaseNode {
112313
- #hash = null;
112314
- get hash() {
112315
- return this.#hash;
112316
- }
112317
- set hash(value2) {
112318
- if (this.#hash !== null) {
112319
- throw new RangeError("Leaf hash already set");
112320
- }
112321
- this.#hash = value2;
112322
- }
112323
- reset() {
112324
- this.#hash = null;
112325
- }
112326
- };
112327
- var ParentNode = class extends BaseNode {
112328
- #left;
112329
- #right;
112330
- constructor(index, depth, left, right) {
112331
- super(index, depth);
112332
- this.#left = left;
112333
- this.#right = right;
112334
- }
112335
- get left() {
112336
- return this.#left;
112337
- }
112338
- set left(node) {
112339
- this.#left = node;
112340
- }
112341
- get right() {
112342
- return this.#right;
112343
- }
112344
- set right(node) {
112345
- this.#right = node;
112346
- }
112347
- reset() {
112348
- this.#left.reset();
112349
- this.#right.reset();
112350
- }
112351
- };
112352
112208
  init_shim2();
112353
112209
  var ValidationState;
112354
112210
  (function(ValidationState2) {
@@ -112356,375 +112212,80 @@ var ValidationState;
112356
112212
  ValidationState2[ValidationState2["Valid"] = 1] = "Valid";
112357
112213
  ValidationState2[ValidationState2["Invalid"] = 2] = "Invalid";
112358
112214
  })(ValidationState || (ValidationState = {}));
112359
- var SMTProof = class _SMTProof {
112360
- #converge;
112361
- #hashes;
112362
- constructor(converge, hashes2) {
112363
- this.#converge = converge;
112364
- this.#hashes = hashes2;
112365
- }
112366
- /** Converge bitmap: bit `i` set means a sibling hash exists at depth `256 - i - 1`. */
112367
- get converge() {
112368
- return this.#converge;
112369
- }
112370
- /** Sibling hashes at converge points, ordered leaf-to-root. */
112371
- get hashes() {
112372
- return this.#hashes;
112373
- }
112374
- /**
112375
- * Verify this proof for a single leaf.
112376
- *
112377
- * @param index - Leaf index in the 256-bit key space.
112378
- * @param candidateHash - Expected leaf hash.
112379
- * @param rootHash - Expected root hash.
112380
- * @returns `true` if the proof is valid.
112381
- */
112382
- isValid(index, candidateHash, rootHash) {
112383
- return this.#validate(index, candidateHash, rootHash);
112384
- }
112385
- /**
112386
- * Batch-validate multiple proofs against the same root hash.
112387
- *
112388
- * Caches intermediate (partial) proofs so that subsequent candidates
112389
- * sharing an ancestor path can short-circuit once a cached match is found.
112390
- *
112391
- * @yields One {@link SMTProofResult} per candidate.
112392
- */
112393
- static *isValidBatch(candidates, rootHash) {
112394
- const cache42 = /* @__PURE__ */ new Map();
112395
- for (const candidate of candidates) {
112396
- const added = [];
112397
- const { index } = candidate;
112398
- const valid = candidate.proof.#validate(index | OUTER_BIT, candidate.hash, rootHash, (nodeIndex, partial) => {
112399
- const cached = cache42.get(nodeIndex);
112400
- if (cached === void 0) {
112401
- cache42.set(nodeIndex, partial);
112402
- added.push(nodeIndex);
112403
- return ValidationState.Pending;
112404
- }
112405
- 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]))) {
112406
- return ValidationState.Valid;
112407
- }
112408
- return ValidationState.Invalid;
112409
- });
112410
- if (!valid) {
112411
- for (const key of added)
112412
- cache42.delete(key);
112413
- }
112414
- yield { index, valid, additional: candidate.additional };
112415
- }
112416
- }
112417
- /**
112418
- * Export to JSON.
112419
- * @param base64 - Use base64 encoding instead of hex (default: `false`).
112420
- * @param compact - Omit whitespace (default: `true`).
112421
- */
112422
- toJSON(base6462 = false, compact = true) {
112423
- const convergeStr = base6462 ? bigIntToBase64(this.#converge, false) : bigIntToHex(this.#converge, false);
112424
- const hashStrs = this.#hashes.map((h) => base6462 ? hashToBase64(h) : hashToHex(h));
112425
- const obj = { converge: convergeStr, hashes: hashStrs };
112426
- return JSON.stringify(obj, null, compact ? 0 : 2);
112427
- }
112428
- /**
112429
- * Import from JSON.
112430
- * @param json - JSON string.
112431
- * @param base64 - Parse base64 instead of hex (default: `false`).
112432
- */
112433
- static fromJSON(json, base6462 = false) {
112434
- const raw = JSON.parse(json);
112435
- if (typeof raw?.converge !== "string" || !Array.isArray(raw.hashes)) {
112436
- throw new RangeError("Invalid SMTProof JSON: expected { converge, hashes }");
112437
- }
112438
- const converge = base6462 ? base64ToBigInt(raw.converge, false) : hexToBigInt(raw.converge, false);
112439
- const hashes2 = raw.hashes.map((h) => base6462 ? base64ToHash(h) : hexToHash(h));
112440
- return new _SMTProof(converge, hashes2);
112441
- }
112442
- /**
112443
- * Export to compact binary format.
112444
- *
112445
- * Layout: `[convergeZeroCount : 1] [truncatedConverge : 32-zc] [hashCount : 1] [hashes : N*32]`
112446
- */
112447
- toBinary() {
112448
- const convergeBin = bigIntToHash(this.#converge);
112449
- let zc = 0;
112450
- while (zc < HASH_BYTE_LENGTH && convergeBin[zc] === 0)
112451
- zc++;
112452
- const truncated = convergeBin.slice(zc);
112453
- const hashCount = this.#hashes.length;
112454
- const totalBytes = 1 + truncated.length + 1 + hashCount * HASH_BYTE_LENGTH;
112455
- const out = new Uint8Array(totalBytes);
112456
- let pos = 0;
112457
- out[pos++] = zc;
112458
- out.set(truncated, pos);
112459
- pos += truncated.length;
112460
- out[pos++] = hashCount;
112461
- for (const h of this.#hashes) {
112462
- out.set(h, pos);
112463
- pos += HASH_BYTE_LENGTH;
112464
- }
112465
- return out;
112466
- }
112467
- /**
112468
- * Import from compact binary format.
112469
- * Accepts any sync or async byte iterable (e.g. `Uint8Array`, `ReadableStream`).
112470
- */
112471
- static async fromBinary(source) {
112472
- const iter = Symbol.iterator in source ? source[Symbol.iterator]() : source[Symbol.asyncIterator]();
112473
- async function readBytes(n2) {
112474
- const buf2 = new Uint8Array(n2);
112475
- for (let i42 = 0; i42 < n2; i42++) {
112476
- const r2 = await iter.next();
112477
- if (r2.done)
112478
- throw new Error("Unexpected end of binary source");
112479
- buf2[i42] = r2.value;
112480
- }
112481
- return buf2;
112482
- }
112483
- const zc = (await readBytes(1))[0];
112484
- const convergeBin = new Uint8Array(HASH_BYTE_LENGTH);
112485
- convergeBin.set(await readBytes(HASH_BYTE_LENGTH - zc), zc);
112486
- const hashCount = (await readBytes(1))[0];
112487
- const hashes2 = new Array(hashCount);
112488
- for (let i42 = 0; i42 < hashCount; i42++) {
112489
- hashes2[i42] = await readBytes(HASH_BYTE_LENGTH);
112490
- }
112491
- return new _SMTProof(hashToBigInt(convergeBin), hashes2);
112492
- }
112493
- #validate(index, candidateHash, rootHash, onMerge) {
112494
- let nodeIndex = index;
112495
- let nodeHash = candidateHash;
112496
- let remaining = this.#converge;
112497
- const hashes2 = this.#hashes;
112498
- let hi = 0;
112499
- const leftPad = [];
112500
- const rightPad = [];
112501
- const finalizePadding = () => {
112502
- if (leftPad.length > 0 || rightPad.length > 0) {
112503
- nodeHash = blockHash(new Uint8Array(leftPad), nodeHash, new Uint8Array(rightPad));
112504
- leftPad.length = 0;
112505
- rightPad.length = 0;
112506
- }
112507
- };
112508
- let state = ValidationState.Pending;
112509
- for (let i42 = 0; state === ValidationState.Pending && i42 < HASH_BIT_LENGTH; i42++) {
112510
- const isLeft = (nodeIndex & 1n) === 0n;
112511
- nodeIndex >>= 1n;
112512
- const bit = BITS[i42];
112513
- if ((remaining & bit) !== 0n) {
112514
- remaining ^= bit;
112515
- finalizePadding();
112516
- if (hi >= hashes2.length) {
112517
- state = ValidationState.Invalid;
112518
- } else {
112519
- const peer = hashes2[hi++];
112520
- nodeHash = isLeft ? blockHash(nodeHash, peer) : blockHash(peer, nodeHash);
112521
- if (onMerge !== void 0) {
112522
- state = onMerge(nodeIndex, {
112523
- hash: nodeHash,
112524
- converge: remaining,
112525
- hashes: hashes2.slice(hi)
112526
- });
112527
- }
112528
- }
112529
- } else {
112530
- const depth = HASH_BIT_LENGTH - i42 - 1;
112531
- if (isLeft) {
112532
- rightPad.push(depth);
112533
- } else {
112534
- leftPad.unshift(depth);
112535
- }
112536
- }
112537
- }
112538
- finalizePadding();
112539
- if (state === ValidationState.Pending) {
112540
- state = hi === hashes2.length && hashesEqual(nodeHash, rootHash) ? ValidationState.Valid : ValidationState.Invalid;
112541
- }
112542
- return state === ValidationState.Valid;
112543
- }
112544
- };
112545
112215
  init_shim2();
112546
- var OptimizedSMT = class _OptimizedSMT {
112547
- /** `2^256` sentinel bit above the key space. Used by batch validation. */
112548
- static OUTER_BIT = OUTER_BIT;
112549
- /** Pre-computed MSB-first bit masks for tree traversal. */
112550
- static BITS = BITS;
112551
- #allowNonInclusion;
112552
- #root = null;
112553
- #rootHash = null;
112554
- #proofs = /* @__PURE__ */ new Map();
112555
- constructor(allowNonInclusion) {
112556
- this.#allowNonInclusion = allowNonInclusion;
112557
- }
112558
- get allowNonInclusion() {
112559
- return this.#allowNonInclusion;
112216
+ init_shim2();
112217
+ var TREE_DEPTH = HASH_BIT_LENGTH;
112218
+ function bitAt(index, position) {
112219
+ return Number(index >> BigInt(position) & 1n);
112220
+ }
112221
+ var CACHED_ZERO = (() => {
112222
+ const arr = new Array(TREE_DEPTH + 1);
112223
+ let z = new Uint8Array(HASH_BYTE_LENGTH);
112224
+ for (let h = 0; h <= TREE_DEPTH; h++) {
112225
+ z = blockHash(z, z);
112226
+ arr[h] = z;
112560
112227
  }
112561
- /** Root hash. Throws if tree has not been finalized. */
112562
- get rootHash() {
112563
- if (this.#rootHash === null)
112564
- throw new RangeError("SMT not finalized");
112565
- return this.#rootHash;
112566
- }
112567
- // -----------------------------------------------------------------------
112568
- // Build phase
112569
- // -----------------------------------------------------------------------
112570
- /**
112571
- * Add leaf indexes to the tree.
112572
- * May be called multiple times before finalization. Duplicate indexes throw.
112573
- */
112574
- add(indexes) {
112575
- this.#checkNotFinalized();
112576
- for (const index of indexes) {
112577
- if (index < 0n || index >= _OptimizedSMT.OUTER_BIT) {
112578
- throw new RangeError("Index out of range");
112579
- }
112580
- const leaf = new LeafNode(index, HASH_BIT_LENGTH);
112581
- if (this.#root === null) {
112582
- this.#root = leaf;
112228
+ return arr;
112229
+ })();
112230
+ function subtreeHash(leaves, height) {
112231
+ if (leaves.length === 0)
112232
+ return CACHED_ZERO[height];
112233
+ if (height === 0)
112234
+ return leaves[0].leaf;
112235
+ const bit = TREE_DEPTH - height;
112236
+ const left = [];
112237
+ const right = [];
112238
+ for (const e2 of leaves)
112239
+ (bitAt(e2.index, bit) === 0 ? left : right).push(e2);
112240
+ return blockHash(subtreeHash(left, height - 1), subtreeHash(right, height - 1));
112241
+ }
112242
+ function zeroHashRoot(leaves) {
112243
+ return subtreeHash(leaves, TREE_DEPTH);
112244
+ }
112245
+ function generateZeroHashProof(leaves, targetIndex) {
112246
+ let collapsed = 0n;
112247
+ const hashes2 = [];
112248
+ for (let height = 1; height <= TREE_DEPTH; height++) {
112249
+ const bit = TREE_DEPTH - height;
112250
+ const siblingLeaves = [];
112251
+ for (const e2 of leaves) {
112252
+ if (e2.index === targetIndex)
112583
112253
  continue;
112584
- }
112585
- let replaceNode = (node2) => {
112586
- this.#root = node2;
112587
- };
112588
- let node = this.#root;
112589
- let commonIndex = 0n;
112590
- let commonDepth = 0;
112591
- let done = false;
112592
- while (!done) {
112593
- const bit = BITS[commonDepth];
112594
- const indexBit = index & bit;
112595
- const isLeft = indexBit === 0n;
112596
- if (commonDepth === node.depth) {
112597
- if (node instanceof ParentNode) {
112598
- const parent = node;
112599
- if (isLeft) {
112600
- node = parent.left;
112601
- replaceNode = (n2) => {
112602
- parent.left = n2;
112603
- };
112604
- } else {
112605
- node = parent.right;
112606
- replaceNode = (n2) => {
112607
- parent.right = n2;
112608
- };
112609
- }
112610
- } else {
112611
- throw new RangeError("Duplicate index");
112612
- }
112613
- } else if ((node.index & bit) === indexBit) {
112614
- commonIndex |= indexBit;
112615
- commonDepth++;
112616
- } else {
112617
- replaceNode(new ParentNode(commonIndex, commonDepth, isLeft ? leaf : node, isLeft ? node : leaf));
112618
- done = true;
112254
+ let sharesLowerPath = true;
112255
+ for (let lower = 0; lower < bit; lower++) {
112256
+ if (bitAt(e2.index, lower) !== bitAt(targetIndex, lower)) {
112257
+ sharesLowerPath = false;
112258
+ break;
112619
112259
  }
112620
112260
  }
112261
+ if (sharesLowerPath && bitAt(e2.index, bit) !== bitAt(targetIndex, bit))
112262
+ siblingLeaves.push(e2);
112621
112263
  }
112622
- }
112623
- /**
112624
- * Set the hash for a leaf at the given index.
112625
- * The index must have been previously added via {@link add}.
112626
- * Each leaf's hash can only be set once (until {@link reset}).
112627
- */
112628
- setHash(index, hash32) {
112629
- this.#checkNotFinalized();
112630
- validateHash(hash32);
112631
- let node = this.#root;
112632
- if (node === null)
112633
- throw new RangeError("Empty SMT");
112634
- while (node instanceof ParentNode) {
112635
- node = (index & BITS[node.depth]) === 0n ? node.left : node.right;
112636
- }
112637
- if (node.index !== index)
112638
- throw new RangeError("Index not found");
112639
- node.hash = hash32;
112640
- }
112641
- // -----------------------------------------------------------------------
112642
- // Finalize phase
112643
- // -----------------------------------------------------------------------
112644
- /**
112645
- * Compute root hash and generate all proofs in a single recursive pass.
112646
- * Must be called after all hashes are set.
112647
- */
112648
- finalize() {
112649
- if (this.#root === null) {
112650
- this.#rootHash = NULL_HASH;
112651
- return;
112264
+ if (siblingLeaves.length === 0) {
112265
+ collapsed |= 1n << BigInt(bit);
112266
+ } else {
112267
+ hashes2.push(subtreeHash(siblingLeaves, height - 1));
112652
112268
  }
112653
- const result = this.#finalizeStep(this.#root, 0n, 0);
112654
- this.#rootHash = result.hash;
112655
- result.saveProofs([]);
112656
- }
112657
- /** Retrieve the proof for an index. Only valid after {@link finalize}. */
112658
- proof(index) {
112659
- const p2 = this.#proofs.get(index);
112660
- if (p2 === void 0)
112661
- throw new RangeError("Proof not found");
112662
- return p2;
112663
112269
  }
112664
- /** Clear hashes and proofs, keeping the tree structure for reuse. */
112665
- reset() {
112666
- this.#root?.reset();
112667
- this.#rootHash = null;
112668
- this.#proofs.clear();
112669
- }
112670
- /**
112671
- * Check if the SMT has not been finalized yet.
112672
- * @throws {Error} If the SMT has already been finalized.
112673
- */
112674
- #checkNotFinalized() {
112675
- if (this.#rootHash !== null)
112676
- throw new Error("SMT already finalized");
112677
- }
112678
- /**
112679
- * Perform a single step of finalization on the given node.
112680
- * @param {Node} node The node to finalize.
112681
- * @param {bigint} parentConverge The convergence value from the parent node.
112682
- * @param {number} depth The current depth in the tree.
112683
- * @returns {FinalizeStepResult} The result of the finalization step.
112684
- */
112685
- #finalizeStep(node, parentConverge, depth) {
112686
- const converge = parentConverge | BITS[HASH_BIT_LENGTH - depth];
112687
- let hash32;
112688
- let saveProofs;
112689
- if (node instanceof ParentNode) {
112690
- const childDepth = node.depth + 1;
112691
- const leftResult = this.#finalizeStep(node.left, converge, childDepth);
112692
- const rightResult = this.#finalizeStep(node.right, converge, childDepth);
112693
- hash32 = blockHash(leftResult.hash, rightResult.hash);
112694
- saveProofs = (hashes2) => {
112695
- const leftHashes = hashes2;
112696
- const rightHashes = hashes2.slice();
112697
- leftHashes.unshift(rightResult.hash);
112698
- rightHashes.unshift(leftResult.hash);
112699
- leftResult.saveProofs(leftHashes);
112700
- rightResult.saveProofs(rightHashes);
112701
- };
112270
+ return { collapsed, hashes: hashes2 };
112271
+ }
112272
+ function verifyZeroHash(collapsed, hashes2, index, candidate, root) {
112273
+ let acc = candidate;
112274
+ let hashPtr = 0;
112275
+ for (let n2 = 0; n2 < TREE_DEPTH; n2++) {
112276
+ const i42 = TREE_DEPTH - 1 - n2;
112277
+ let sibling;
112278
+ if ((collapsed >> BigInt(i42) & 1n) === 1n) {
112279
+ sibling = CACHED_ZERO[n2];
112702
112280
  } else {
112703
- if (node.hash === null) {
112704
- if (!this.#allowNonInclusion)
112705
- throw new RangeError("Hash missing");
112706
- node.hash = NULL_HASH;
112707
- }
112708
- hash32 = node.hash;
112709
- saveProofs = (hashes2) => {
112710
- this.#proofs.set(node.index, new SMTProof(converge, hashes2));
112711
- };
112712
- }
112713
- if (node.depth !== depth) {
112714
- const leftPad = [];
112715
- const rightPad = [];
112716
- for (let i42 = node.depth - 1; i42 >= depth; i42--) {
112717
- if ((node.index & BITS[i42]) === 0n) {
112718
- rightPad.push(i42);
112719
- } else {
112720
- leftPad.unshift(i42);
112721
- }
112722
- }
112723
- hash32 = blockHash(new Uint8Array(leftPad), hash32, new Uint8Array(rightPad));
112281
+ if (hashPtr >= hashes2.length)
112282
+ return false;
112283
+ sibling = hashes2[hashPtr++];
112724
112284
  }
112725
- return { hash: hash32, saveProofs };
112285
+ acc = bitAt(index, i42) === 1 ? blockHash(sibling, acc) : blockHash(acc, sibling);
112726
112286
  }
112727
- };
112287
+ return hashPtr === hashes2.length && hashesEqual(acc, root);
112288
+ }
112728
112289
  init_shim2();
112729
112290
  var encoder = new TextEncoder();
112730
112291
  function didToIndex(did) {
@@ -112737,49 +112298,51 @@ function nonInclusionLeafHash(nonce) {
112737
112298
  return blockHash(blockHash(nonce));
112738
112299
  }
112739
112300
  init_shim2();
112740
- function serializeProof(proof, rootHash, options2) {
112301
+ function serializeProof(rootHash, proof, options2) {
112741
112302
  const result = {
112742
- id: hashToHex(rootHash),
112743
- collapsed: bigIntToHex(proof.converge, false),
112744
- hashes: proof.hashes.map((h) => hashToHex(h))
112303
+ id: hashToBase64Url(rootHash),
112304
+ collapsed: hashToBase64Url(bigIntToHash(proof.collapsed)),
112305
+ hashes: proof.hashes.map((h) => hashToBase64Url(h))
112745
112306
  };
112746
112307
  if (options2?.nonce)
112747
- result.nonce = hashToHex(options2.nonce);
112308
+ result.nonce = hashToBase64Url(options2.nonce);
112748
112309
  if (options2?.updateId)
112749
- result.updateId = hashToHex(options2.updateId);
112310
+ result.updateId = hashToBase64Url(options2.updateId);
112750
112311
  return result;
112751
112312
  }
112752
112313
  function deserializeProof(serialized) {
112753
- const converge = hexToBigInt(serialized.collapsed, false);
112754
- const hashes2 = serialized.hashes.map((h) => hexToHash(h));
112755
112314
  const result = {
112756
- proof: new SMTProof(converge, hashes2),
112757
- rootHash: hexToHash(serialized.id)
112315
+ rootHash: base64UrlToHash(serialized.id),
112316
+ collapsed: hashToBigInt(base64UrlToHash(serialized.collapsed)),
112317
+ hashes: serialized.hashes.map((h) => base64UrlToHash(h))
112758
112318
  };
112759
112319
  if (serialized.nonce)
112760
- result.nonce = hexToHash(serialized.nonce);
112320
+ result.nonce = base64UrlToHash(serialized.nonce);
112761
112321
  if (serialized.updateId)
112762
- result.updateId = hexToHash(serialized.updateId);
112322
+ result.updateId = base64UrlToHash(serialized.updateId);
112763
112323
  return result;
112764
112324
  }
112765
112325
  function verifySerializedProof(serialized, index, candidateHash) {
112766
- const { proof, rootHash } = deserializeProof(serialized);
112767
- return proof.isValid(index, candidateHash, rootHash);
112326
+ const { rootHash, collapsed, hashes: hashes2 } = deserializeProof(serialized);
112327
+ return verifyZeroHash(collapsed, hashes2, index, candidateHash, rootHash);
112768
112328
  }
112769
112329
  init_shim2();
112770
112330
  var BTCR2MerkleTree = class {
112771
- #smt;
112772
112331
  #entries = /* @__PURE__ */ new Map();
112773
112332
  #indexByDid = /* @__PURE__ */ new Map();
112774
- constructor(allowNonInclusion = true) {
112775
- this.#smt = new OptimizedSMT(allowNonInclusion);
112333
+ #leaves = null;
112334
+ #root = null;
112335
+ /**
112336
+ * @param _allowNonInclusion Retained for API compatibility; non-inclusion
112337
+ * leaves are always supported (an entry without `signedUpdate`).
112338
+ */
112339
+ constructor(_allowNonInclusion = true) {
112776
112340
  }
112777
112341
  /**
112778
112342
  * Add entries to the tree. May be called multiple times before
112779
112343
  * {@link finalize}. Duplicate DIDs (same index) throw.
112780
112344
  */
112781
112345
  addEntries(entries) {
112782
- const indexes = [];
112783
112346
  for (const entry of entries) {
112784
112347
  const index = didToIndex(entry.did);
112785
112348
  if (this.#entries.has(index)) {
@@ -112787,24 +112350,28 @@ var BTCR2MerkleTree = class {
112787
112350
  }
112788
112351
  this.#entries.set(index, entry);
112789
112352
  this.#indexByDid.set(entry.did, index);
112790
- indexes.push(index);
112791
112353
  }
112792
- this.#smt.add(indexes);
112354
+ this.#leaves = null;
112355
+ this.#root = null;
112793
112356
  }
112794
112357
  /**
112795
- * Compute leaf hashes and finalize the tree.
112358
+ * Compute leaf hashes and the zero-hash root.
112796
112359
  * After this call, {@link rootHash} and {@link proof} become available.
112797
112360
  */
112798
112361
  finalize() {
112362
+ const leaves = [];
112799
112363
  for (const [index, entry] of this.#entries) {
112800
- const leafHash = entry.signedUpdate !== void 0 ? inclusionLeafHash(entry.nonce, entry.signedUpdate) : nonInclusionLeafHash(entry.nonce);
112801
- this.#smt.setHash(index, leafHash);
112364
+ const leaf = entry.signedUpdate !== void 0 ? inclusionLeafHash(entry.nonce, entry.signedUpdate) : nonInclusionLeafHash(entry.nonce);
112365
+ leaves.push({ index, leaf });
112802
112366
  }
112803
- this.#smt.finalize();
112367
+ this.#leaves = leaves;
112368
+ this.#root = zeroHashRoot(leaves);
112804
112369
  }
112805
112370
  /** Root hash of the finalized tree. Throws if not finalized. */
112806
112371
  get rootHash() {
112807
- return this.#smt.rootHash;
112372
+ if (this.#root === null)
112373
+ throw new Error("Tree not finalized: call finalize() first");
112374
+ return this.#root;
112808
112375
  }
112809
112376
  /**
112810
112377
  * Get the did:btcr2 serialized proof for a DID.
@@ -112814,14 +112381,18 @@ var BTCR2MerkleTree = class {
112814
112381
  const index = this.#indexByDid.get(did);
112815
112382
  if (index === void 0)
112816
112383
  throw new RangeError(`DID not in tree: ${did}`);
112384
+ if (this.#leaves === null || this.#root === null) {
112385
+ throw new Error("Tree not finalized: call finalize() first");
112386
+ }
112817
112387
  const entry = this.#entries.get(index);
112818
- const smtProof = this.#smt.proof(index);
112388
+ const proof = generateZeroHashProof(this.#leaves, index);
112819
112389
  const updateId = entry.signedUpdate !== void 0 ? blockHash(entry.signedUpdate) : void 0;
112820
- return serializeProof(smtProof, this.#smt.rootHash, { nonce: entry.nonce, updateId });
112390
+ return serializeProof(this.#root, proof, { nonce: entry.nonce, updateId });
112821
112391
  }
112822
- /** Clear hashes and proofs, keeping tree structure. Entries are preserved. */
112392
+ /** Clear computed leaves and root, keeping entries. */
112823
112393
  reset() {
112824
- this.#smt.reset();
112394
+ this.#leaves = null;
112395
+ this.#root = null;
112825
112396
  }
112826
112397
  };
112827
112398
  var CAS_STRATEGY = {
@@ -112854,12 +112425,12 @@ var SMT_STRATEGY = {
112854
112425
  const smtProof = body.smtProof;
112855
112426
  if (!smtProof?.updateId || !smtProof?.nonce) return { matches: false };
112856
112427
  const canonicalBytes = new TextEncoder().encode(canonicalize2(submittedUpdate));
112857
- const expectedUpdateId = hashToHex(blockHash(canonicalBytes));
112428
+ const expectedUpdateId = hashToBase64Url(blockHash(canonicalBytes));
112858
112429
  if (smtProof.updateId !== expectedUpdateId) {
112859
112430
  return { matches: false, smtProof };
112860
112431
  }
112861
112432
  const index = didToIndex(participantDid);
112862
- const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
112433
+ const candidateHash = blockHash(blockHash(base64UrlToHash(smtProof.nonce)), base64UrlToHash(smtProof.updateId));
112863
112434
  return {
112864
112435
  matches: verifySerializedProof(smtProof, index, candidateHash),
112865
112436
  smtProof
@@ -117135,8 +116706,8 @@ function encrypt2(secretKey, pubkey, text) {
117135
116706
  let iv = Uint8Array.from(randomBytes2(16));
117136
116707
  let plaintext = utf8Encoder.encode(text);
117137
116708
  let ciphertext = cbc(normalizedKey, iv).encrypt(plaintext);
117138
- let ctb64 = base642.encode(new Uint8Array(ciphertext));
117139
- let ivb64 = base642.encode(new Uint8Array(iv.buffer));
116709
+ let ctb64 = base64.encode(new Uint8Array(ciphertext));
116710
+ let ivb64 = base64.encode(new Uint8Array(iv.buffer));
117140
116711
  return `${ctb64}?iv=${ivb64}`;
117141
116712
  }
117142
116713
  function decrypt2(secretKey, pubkey, data) {
@@ -117144,8 +116715,8 @@ function decrypt2(secretKey, pubkey, data) {
117144
116715
  let [ctb64, ivb64] = data.split("?iv=");
117145
116716
  let key = secp256k1.getSharedSecret(privkey, hexToBytes2("02" + pubkey));
117146
116717
  let normalizedKey = getNormalizedX(key);
117147
- let iv = base642.decode(ivb64);
117148
- let ciphertext = base642.decode(ctb64);
116718
+ let iv = base64.decode(ivb64);
116719
+ let ciphertext = base64.decode(ctb64);
117149
116720
  let plaintext = cbc(normalizedKey, iv).decrypt(ciphertext);
117150
116721
  return utf8Decoder.decode(plaintext);
117151
116722
  }
@@ -117465,7 +117036,7 @@ function decodePayload(payload) {
117465
117036
  throw new Error("unknown encryption version");
117466
117037
  let data;
117467
117038
  try {
117468
- data = base642.decode(payload);
117039
+ data = base64.decode(payload);
117469
117040
  } catch (error) {
117470
117041
  throw new Error("invalid base64: " + error.message);
117471
117042
  }
@@ -117486,7 +117057,7 @@ function encrypt22(plaintext, conversationKey, nonce = randomBytes2(32)) {
117486
117057
  const padded = pad(plaintext);
117487
117058
  const ciphertext = chacha20(chacha_key, chacha_nonce, padded);
117488
117059
  const mac = hmacAad(hmac_key, ciphertext, nonce);
117489
- return base642.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
117060
+ return base64.encode(concatBytes2(new Uint8Array([2]), nonce, ciphertext, mac));
117490
117061
  }
117491
117062
  function decrypt22(payload, conversationKey) {
117492
117063
  const { nonce, ciphertext, mac } = decodePayload(payload);
@@ -118761,7 +118332,7 @@ async function getToken(loginUrl, httpMethod, sign, includeAuthorizationScheme =
118761
118332
  }
118762
118333
  const signedEvent = await sign(event);
118763
118334
  const authorizationScheme = includeAuthorizationScheme ? _authorizationScheme : "";
118764
- return authorizationScheme + base642.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
118335
+ return authorizationScheme + base64.encode(utf8Encoder.encode(JSON.stringify(signedEvent)));
118765
118336
  }
118766
118337
  async function validateToken(token, url, method) {
118767
118338
  const event = await unpackEventFromToken(token).catch((error) => {
@@ -118777,7 +118348,7 @@ async function unpackEventFromToken(token) {
118777
118348
  throw new Error("Missing token");
118778
118349
  }
118779
118350
  token = token.replace(_authorizationScheme, "");
118780
- const eventB64 = utf8Decoder.decode(base642.decode(token));
118351
+ const eventB64 = utf8Decoder.decode(base64.decode(token));
118781
118352
  if (!eventB64 || eventB64.length === 0 || !eventB64.startsWith("{")) {
118782
118353
  throw new Error("Invalid token");
118783
118354
  }
@@ -119357,9 +118928,6 @@ var SMTBeacon = class extends Beacon {
119357
118928
  });
119358
118929
  continue;
119359
118930
  }
119360
- if (!smtProof.updateId) {
119361
- continue;
119362
- }
119363
118931
  if (!smtProof.nonce) {
119364
118932
  throw new SMTBeaconError(
119365
118933
  "SMT proof missing required nonce field.",
@@ -119368,7 +118936,8 @@ var SMTBeacon = class extends Beacon {
119368
118936
  );
119369
118937
  }
119370
118938
  const index = didToIndex(did);
119371
- const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
118939
+ const nonceHash2 = base64UrlToHash(smtProof.nonce);
118940
+ const candidateHash = smtProof.updateId ? blockHash(blockHash(nonceHash2), base64UrlToHash(smtProof.updateId)) : blockHash(blockHash(nonceHash2));
119372
118941
  const valid = verifySerializedProof(smtProof, index, candidateHash);
119373
118942
  if (!valid) {
119374
118943
  throw new SMTBeaconError(
@@ -119377,11 +118946,15 @@ var SMTBeacon = class extends Beacon {
119377
118946
  { smtProof, did }
119378
118947
  );
119379
118948
  }
119380
- const signedUpdate = sidecar.updateMap.get(smtProof.updateId);
118949
+ if (!smtProof.updateId) {
118950
+ continue;
118951
+ }
118952
+ const updateHashHex = hashToHex(base64UrlToHash(smtProof.updateId));
118953
+ const signedUpdate = sidecar.updateMap.get(updateHashHex);
119381
118954
  if (!signedUpdate) {
119382
118955
  needs.push({
119383
118956
  kind: "NeedSignedUpdate",
119384
- updateHash: smtProof.updateId,
118957
+ updateHash: updateHashHex,
119385
118958
  beaconServiceId: this.service.id
119386
118959
  });
119387
118960
  continue;
@@ -135137,7 +134710,7 @@ var Resolver = class _Resolver {
135137
134710
  const smtMap = /* @__PURE__ */ new Map();
135138
134711
  if (sidecar.smtProofs?.length)
135139
134712
  for (const proof of sidecar.smtProofs) {
135140
- smtMap.set(proof.id, proof);
134713
+ smtMap.set(encode(decode(proof.id, "base64urlnopad"), "hex"), proof);
135141
134714
  }
135142
134715
  return { updateMap, casMap, smtMap };
135143
134716
  }
@@ -135425,11 +134998,12 @@ var Resolver = class _Resolver {
135425
134998
  case "NeedSMTProof": {
135426
134999
  const smtNeed = need;
135427
135000
  const proof = data;
135428
- if (proof.id !== smtNeed.smtRootHash) {
135001
+ const proofIdHex = encode(decode(proof.id, "base64urlnopad"), "hex");
135002
+ if (proofIdHex !== smtNeed.smtRootHash) {
135429
135003
  throw new ResolveError(
135430
- `SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proof.id}`,
135004
+ `SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proofIdHex}`,
135431
135005
  INVALID_DID_UPDATE,
135432
- { expected: smtNeed.smtRootHash, actual: proof.id }
135006
+ { expected: smtNeed.smtRootHash, actual: proofIdHex }
135433
135007
  );
135434
135008
  }
135435
135009
  this.#sidecarData.smtMap.set(smtNeed.smtRootHash, proof);
@@ -136066,7 +135640,7 @@ var powers3 = /* @__PURE__ */ (() => {
136066
135640
  res.push(2 ** i5);
136067
135641
  return res;
136068
135642
  })();
136069
- function convertRadix23(data, from14, to, padding3) {
135643
+ function convertRadix23(data, from14, to, padding2) {
136070
135644
  aArr3(data);
136071
135645
  if (from14 <= 0 || from14 > 32)
136072
135646
  throw new Error(`convertRadix2: wrong from=${from14}`);
@@ -136096,11 +135670,11 @@ function convertRadix23(data, from14, to, padding3) {
136096
135670
  carry &= pow4 - 1;
136097
135671
  }
136098
135672
  carry = carry << to - pos & mask;
136099
- if (!padding3 && pos >= from14)
135673
+ if (!padding2 && pos >= from14)
136100
135674
  throw new Error("Excess padding");
136101
- if (!padding3 && carry > 0)
135675
+ if (!padding2 && carry > 0)
136102
135676
  throw new Error(`Non-zero padding: ${carry}`);
136103
- if (padding3 && pos > 0)
135677
+ if (padding2 && pos > 0)
136104
135678
  res.push(carry >>> 0);
136105
135679
  return res;
136106
135680
  }
@@ -146697,7 +146271,7 @@ var base58flickr5 = baseX5({
146697
146271
 
146698
146272
  // ../../node_modules/.pnpm/multiformats@13.1.0/node_modules/multiformats/dist/src/bases/base64.js
146699
146273
  init_shim();
146700
- var base646 = rfc46485({
146274
+ var base642 = rfc46485({
146701
146275
  prefix: "m",
146702
146276
  name: "base64",
146703
146277
  alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
@@ -158681,7 +158255,7 @@ var rfc46486 = ({ name: name11, prefix: prefix2, bitsPerChar, alphabet: alphabet
158681
158255
  };
158682
158256
 
158683
158257
  // ../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/bases/base64.js
158684
- var base647 = rfc46486({
158258
+ var base646 = rfc46486({
158685
158259
  prefix: "m",
158686
158260
  name: "base64",
158687
158261
  alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",