@did-btcr2/method 0.24.1 → 0.25.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.
Files changed (72) hide show
  1. package/dist/browser.js +697 -554
  2. package/dist/browser.mjs +697 -554
  3. package/dist/cjs/core/beacon/beacon.js.map +1 -1
  4. package/dist/cjs/core/beacon/cas-beacon.js +119 -7
  5. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  6. package/dist/cjs/core/beacon/factory.js +1 -1
  7. package/dist/cjs/core/beacon/factory.js.map +1 -1
  8. package/dist/cjs/core/beacon/{singleton.js → singleton-beacon.js} +18 -26
  9. package/dist/cjs/core/beacon/singleton-beacon.js.map +1 -0
  10. package/dist/cjs/core/beacon/smt-beacon.js +1 -1
  11. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  12. package/dist/{esm/core/resolve.js → cjs/core/resolver.js} +241 -93
  13. package/dist/cjs/core/resolver.js.map +1 -0
  14. package/dist/cjs/core/update.js +5 -5
  15. package/dist/cjs/core/update.js.map +1 -1
  16. package/dist/cjs/did-btcr2.js +34 -92
  17. package/dist/cjs/did-btcr2.js.map +1 -1
  18. package/dist/cjs/index.js +2 -2
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/esm/core/beacon/beacon.js.map +1 -1
  21. package/dist/esm/core/beacon/cas-beacon.js +119 -7
  22. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  23. package/dist/esm/core/beacon/factory.js +1 -1
  24. package/dist/esm/core/beacon/factory.js.map +1 -1
  25. package/dist/esm/core/beacon/{singleton.js → singleton-beacon.js} +18 -26
  26. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -0
  27. package/dist/esm/core/beacon/smt-beacon.js +1 -1
  28. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  29. package/dist/{cjs/core/resolve.js → esm/core/resolver.js} +241 -93
  30. package/dist/esm/core/resolver.js.map +1 -0
  31. package/dist/esm/core/update.js +5 -5
  32. package/dist/esm/core/update.js.map +1 -1
  33. package/dist/esm/did-btcr2.js +34 -92
  34. package/dist/esm/did-btcr2.js.map +1 -1
  35. package/dist/esm/index.js +2 -2
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/types/core/beacon/beacon.d.ts +9 -4
  38. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  39. package/dist/types/core/beacon/cas-beacon.d.ts +26 -7
  40. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  41. package/dist/types/core/beacon/{singleton.d.ts → singleton-beacon.d.ts} +7 -5
  42. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -0
  43. package/dist/types/core/beacon/smt-beacon.d.ts +4 -3
  44. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  45. package/dist/types/core/interfaces.d.ts +5 -15
  46. package/dist/types/core/interfaces.d.ts.map +1 -1
  47. package/dist/types/core/resolver.d.ts +167 -0
  48. package/dist/types/core/resolver.d.ts.map +1 -0
  49. package/dist/types/core/update.d.ts +3 -3
  50. package/dist/types/core/update.d.ts.map +1 -1
  51. package/dist/types/did-btcr2.d.ts +16 -16
  52. package/dist/types/did-btcr2.d.ts.map +1 -1
  53. package/dist/types/index.d.ts +2 -2
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/package.json +4 -4
  56. package/src/core/beacon/beacon.ts +9 -5
  57. package/src/core/beacon/cas-beacon.ts +156 -10
  58. package/src/core/beacon/factory.ts +1 -1
  59. package/src/core/beacon/{singleton.ts → singleton-beacon.ts} +19 -35
  60. package/src/core/beacon/smt-beacon.ts +4 -3
  61. package/src/core/interfaces.ts +5 -16
  62. package/src/core/{resolve.ts → resolver.ts} +355 -130
  63. package/src/core/update.ts +7 -7
  64. package/src/did-btcr2.ts +37 -128
  65. package/src/index.ts +2 -2
  66. package/dist/cjs/core/beacon/singleton.js.map +0 -1
  67. package/dist/cjs/core/resolve.js.map +0 -1
  68. package/dist/esm/core/beacon/singleton.js.map +0 -1
  69. package/dist/esm/core/resolve.js.map +0 -1
  70. package/dist/types/core/beacon/singleton.d.ts.map +0 -1
  71. package/dist/types/core/resolve.d.ts +0 -93
  72. package/dist/types/core/resolve.d.ts.map +0 -1
package/dist/browser.js CHANGED
@@ -1868,7 +1868,7 @@ var BTCR2 = (() => {
1868
1868
  } else {
1869
1869
  ENCODING_CONST = 734539939;
1870
1870
  }
1871
- function encode43(prefix, words, LIMIT) {
1871
+ function encode44(prefix, words, LIMIT) {
1872
1872
  LIMIT = LIMIT || 90;
1873
1873
  if (prefix.length + 7 + words.length > LIMIT)
1874
1874
  throw new TypeError("Exceeds length limit");
@@ -1937,7 +1937,7 @@ var BTCR2 = (() => {
1937
1937
  if (typeof res === "object")
1938
1938
  return res;
1939
1939
  }
1940
- function decode47(str, LIMIT) {
1940
+ function decode48(str, LIMIT) {
1941
1941
  const res = __decode(str, LIMIT);
1942
1942
  if (typeof res === "object")
1943
1943
  return res;
@@ -1945,8 +1945,8 @@ var BTCR2 = (() => {
1945
1945
  }
1946
1946
  return {
1947
1947
  decodeUnsafe,
1948
- decode: decode47,
1949
- encode: encode43,
1948
+ decode: decode48,
1949
+ encode: encode44,
1950
1950
  toWords,
1951
1951
  fromWordsUnsafe,
1952
1952
  fromWords
@@ -20068,7 +20068,7 @@ var BTCR2 = (() => {
20068
20068
  return res;
20069
20069
  }
20070
20070
  utils2.toHex = toHex3;
20071
- utils2.encode = function encode43(arr, enc) {
20071
+ utils2.encode = function encode44(arr, enc) {
20072
20072
  if (enc === "hex")
20073
20073
  return toHex3(arr);
20074
20074
  else
@@ -20442,7 +20442,7 @@ var BTCR2 = (() => {
20442
20442
  return [this.getY().isEven() ? 2 : 3].concat(x);
20443
20443
  return [4].concat(x, this.getY().toArray("be", len));
20444
20444
  };
20445
- BasePoint.prototype.encode = function encode43(enc, compact) {
20445
+ BasePoint.prototype.encode = function encode44(enc, compact) {
20446
20446
  return utils2.encode(this._encode(compact), enc);
20447
20447
  };
20448
20448
  BasePoint.prototype.precompute = function precompute(power) {
@@ -25075,7 +25075,7 @@ var BTCR2 = (() => {
25075
25075
  this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
25076
25076
  return this.decoders[enc];
25077
25077
  };
25078
- Entity.prototype.decode = function decode47(data, enc, options2) {
25078
+ Entity.prototype.decode = function decode48(data, enc, options2) {
25079
25079
  return this._getDecoder(enc).decode(data, options2);
25080
25080
  };
25081
25081
  Entity.prototype._getEncoder = function _getEncoder(enc) {
@@ -25084,7 +25084,7 @@ var BTCR2 = (() => {
25084
25084
  this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
25085
25085
  return this.encoders[enc];
25086
25086
  };
25087
- Entity.prototype.encode = function encode43(data, enc, reporter) {
25087
+ Entity.prototype.encode = function encode44(data, enc, reporter) {
25088
25088
  return this._getEncoder(enc).encode(data, reporter);
25089
25089
  };
25090
25090
  }
@@ -25548,7 +25548,7 @@ var BTCR2 = (() => {
25548
25548
  state.contains = item;
25549
25549
  return this;
25550
25550
  };
25551
- Node.prototype._decode = function decode47(input, options2) {
25551
+ Node.prototype._decode = function decode48(input, options2) {
25552
25552
  var state = this._baseState;
25553
25553
  if (state.parent === null)
25554
25554
  return input.wrapResult(state.children[0]._decode(input, options2));
@@ -25704,7 +25704,7 @@ var BTCR2 = (() => {
25704
25704
  Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
25705
25705
  return new EncoderBuffer(data, this.reporter);
25706
25706
  };
25707
- Node.prototype._encode = function encode43(data, reporter, parent) {
25707
+ Node.prototype._encode = function encode44(data, reporter, parent) {
25708
25708
  var state = this._baseState;
25709
25709
  if (state["default"] !== null && state["default"] === data)
25710
25710
  return;
@@ -25715,7 +25715,7 @@ var BTCR2 = (() => {
25715
25715
  return;
25716
25716
  return result;
25717
25717
  };
25718
- Node.prototype._encodeValue = function encode43(data, reporter, parent) {
25718
+ Node.prototype._encodeValue = function encode44(data, reporter, parent) {
25719
25719
  var state = this._baseState;
25720
25720
  if (state.parent === null)
25721
25721
  return state.children[0]._encode(data, reporter || new Reporter());
@@ -25923,7 +25923,7 @@ var BTCR2 = (() => {
25923
25923
  this.tree._init(entity.body);
25924
25924
  }
25925
25925
  module.exports = DERDecoder;
25926
- DERDecoder.prototype.decode = function decode47(data, options2) {
25926
+ DERDecoder.prototype.decode = function decode48(data, options2) {
25927
25927
  if (!(data instanceof base5.DecoderBuffer))
25928
25928
  data = new base5.DecoderBuffer(data, options2);
25929
25929
  return this.tree._decode(data, options2);
@@ -26183,7 +26183,7 @@ var BTCR2 = (() => {
26183
26183
  }
26184
26184
  inherits(PEMDecoder, DERDecoder);
26185
26185
  module.exports = PEMDecoder;
26186
- PEMDecoder.prototype.decode = function decode47(data, options2) {
26186
+ PEMDecoder.prototype.decode = function decode48(data, options2) {
26187
26187
  var lines = data.toString().split(/[\r\n]+/g);
26188
26188
  var label = options2.label.toUpperCase();
26189
26189
  var re = /^-----(BEGIN|END) ([^-]+)-----$/;
@@ -26243,7 +26243,7 @@ var BTCR2 = (() => {
26243
26243
  this.tree._init(entity.body);
26244
26244
  }
26245
26245
  module.exports = DEREncoder;
26246
- DEREncoder.prototype.encode = function encode43(data, reporter) {
26246
+ DEREncoder.prototype.encode = function encode44(data, reporter) {
26247
26247
  return this.tree._encode(data, reporter).join();
26248
26248
  };
26249
26249
  function DERNode(parent) {
@@ -26470,7 +26470,7 @@ var BTCR2 = (() => {
26470
26470
  }
26471
26471
  inherits(PEMEncoder, DEREncoder);
26472
26472
  module.exports = PEMEncoder;
26473
- PEMEncoder.prototype.encode = function encode43(data, options2) {
26473
+ PEMEncoder.prototype.encode = function encode44(data, options2) {
26474
26474
  var buf2 = DEREncoder.prototype.encode.call(this, data);
26475
26475
  var p2 = buf2.toString("base64");
26476
26476
  var out = ["-----BEGIN " + options2.label + "-----"];
@@ -36545,7 +36545,7 @@ var BTCR2 = (() => {
36545
36545
  }
36546
36546
  return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
36547
36547
  };
36548
- var decode47 = function decode48(input) {
36548
+ var decode48 = function decode49(input) {
36549
36549
  var output6 = [];
36550
36550
  var inputLength = input.length;
36551
36551
  var i4 = 0;
@@ -36598,7 +36598,7 @@ var BTCR2 = (() => {
36598
36598
  }
36599
36599
  return String.fromCodePoint.apply(String, output6);
36600
36600
  };
36601
- var encode43 = function encode44(input) {
36601
+ var encode44 = function encode45(input) {
36602
36602
  var output6 = [];
36603
36603
  input = ucs2decode(input);
36604
36604
  var inputLength = input.length;
@@ -36719,12 +36719,12 @@ var BTCR2 = (() => {
36719
36719
  };
36720
36720
  var toUnicode = function toUnicode2(input) {
36721
36721
  return mapDomain(input, function(string4) {
36722
- return regexPunycode.test(string4) ? decode47(string4.slice(4).toLowerCase()) : string4;
36722
+ return regexPunycode.test(string4) ? decode48(string4.slice(4).toLowerCase()) : string4;
36723
36723
  });
36724
36724
  };
36725
36725
  var toASCII = function toASCII2(input) {
36726
36726
  return mapDomain(input, function(string4) {
36727
- return regexNonASCII.test(string4) ? "xn--" + encode43(string4) : string4;
36727
+ return regexNonASCII.test(string4) ? "xn--" + encode44(string4) : string4;
36728
36728
  });
36729
36729
  };
36730
36730
  var punycode = {
@@ -36745,8 +36745,8 @@ var BTCR2 = (() => {
36745
36745
  "decode": ucs2decode,
36746
36746
  "encode": ucs2encode
36747
36747
  },
36748
- "decode": decode47,
36749
- "encode": encode43,
36748
+ "decode": decode48,
36749
+ "encode": encode44,
36750
36750
  "toASCII": toASCII,
36751
36751
  "toUnicode": toUnicode
36752
36752
  };
@@ -44614,7 +44614,7 @@ var BTCR2 = (() => {
44614
44614
  Identifier: () => Identifier,
44615
44615
  MESSAGE_PREFIX: () => MESSAGE_PREFIX,
44616
44616
  NostrAdapter: () => NostrAdapter,
44617
- Resolve: () => Resolve,
44617
+ Resolver: () => Resolver,
44618
44618
  SIGNING_SESSION_STATUS: () => SIGNING_SESSION_STATUS,
44619
44619
  SMTBeacon: () => SMTBeacon,
44620
44620
  SMTBeaconError: () => SMTBeaconError,
@@ -47439,9 +47439,9 @@ var BTCR2 = (() => {
47439
47439
  function chain(...args) {
47440
47440
  const id = (a2) => a2;
47441
47441
  const wrap2 = (a2, b) => (c2) => a2(b(c2));
47442
- const encode43 = args.map((x) => x.encode).reduceRight(wrap2, id);
47443
- const decode47 = args.map((x) => x.decode).reduce(wrap2, id);
47444
- return { encode: encode43, decode: decode47 };
47442
+ const encode44 = args.map((x) => x.encode).reduceRight(wrap2, id);
47443
+ const decode48 = args.map((x) => x.decode).reduce(wrap2, id);
47444
+ return { encode: encode44, decode: decode48 };
47445
47445
  }
47446
47446
  // @__NO_SIDE_EFFECTS__
47447
47447
  function alphabet(letters) {
@@ -47694,7 +47694,7 @@ var BTCR2 = (() => {
47694
47694
  const fromWords = _words.decode;
47695
47695
  const toWords = _words.encode;
47696
47696
  const fromWordsUnsafe = unsafeWrapper(fromWords);
47697
- function encode43(prefix, words, limit2 = 90) {
47697
+ function encode44(prefix, words, limit2 = 90) {
47698
47698
  astr("bech32.encode prefix", prefix);
47699
47699
  if (isBytes2(words))
47700
47700
  words = Array.from(words);
@@ -47709,7 +47709,7 @@ var BTCR2 = (() => {
47709
47709
  const sum = bechChecksum(lowered, words, ENCODING_CONST);
47710
47710
  return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
47711
47711
  }
47712
- function decode47(str, limit2 = 90) {
47712
+ function decode48(str, limit2 = 90) {
47713
47713
  astr("bech32.decode input", str);
47714
47714
  const slen = str.length;
47715
47715
  if (slen < 8 || limit2 !== false && slen > limit2)
@@ -47730,17 +47730,17 @@ var BTCR2 = (() => {
47730
47730
  throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
47731
47731
  return { prefix, words };
47732
47732
  }
47733
- const decodeUnsafe = unsafeWrapper(decode47);
47733
+ const decodeUnsafe = unsafeWrapper(decode48);
47734
47734
  function decodeToBytes(str) {
47735
- const { prefix, words } = decode47(str, false);
47735
+ const { prefix, words } = decode48(str, false);
47736
47736
  return { prefix, words, bytes: fromWords(words) };
47737
47737
  }
47738
47738
  function encodeFromBytes(prefix, bytes6) {
47739
- return encode43(prefix, toWords(bytes6));
47739
+ return encode44(prefix, toWords(bytes6));
47740
47740
  }
47741
47741
  return {
47742
- encode: encode43,
47743
- decode: decode47,
47742
+ encode: encode44,
47743
+ decode: decode48,
47744
47744
  encodeFromBytes,
47745
47745
  decodeToBytes,
47746
47746
  decodeUnsafe,
@@ -50736,7 +50736,7 @@ var BTCR2 = (() => {
50736
50736
  const o2 = { network };
50737
50737
  let chunks = [];
50738
50738
  let decoded = false;
50739
- function decode47(output6) {
50739
+ function decode48(output6) {
50740
50740
  if (decoded) return;
50741
50741
  decoded = true;
50742
50742
  chunks = decompile(output6);
@@ -50759,7 +50759,7 @@ var BTCR2 = (() => {
50759
50759
  });
50760
50760
  prop(o2, "m", () => {
50761
50761
  if (!o2.output) return;
50762
- decode47(o2.output);
50762
+ decode48(o2.output);
50763
50763
  return o2.m;
50764
50764
  });
50765
50765
  prop(o2, "n", () => {
@@ -50768,7 +50768,7 @@ var BTCR2 = (() => {
50768
50768
  });
50769
50769
  prop(o2, "pubkeys", () => {
50770
50770
  if (!a2.output) return;
50771
- decode47(a2.output);
50771
+ decode48(a2.output);
50772
50772
  return o2.pubkeys;
50773
50773
  });
50774
50774
  prop(o2, "signatures", () => {
@@ -50789,7 +50789,7 @@ var BTCR2 = (() => {
50789
50789
  });
50790
50790
  if (opts.validate) {
50791
50791
  if (a2.output) {
50792
- decode47(a2.output);
50792
+ decode48(a2.output);
50793
50793
  parse(number(), chunks[0], { message: "Output is invalid" });
50794
50794
  parse(number(), chunks[chunks.length - 2], {
50795
50795
  message: "Output is invalid"
@@ -51550,7 +51550,7 @@ var BTCR2 = (() => {
51550
51550
  const LEADER = ALPHABET2.charAt(0);
51551
51551
  const FACTOR = Math.log(BASE) / Math.log(256);
51552
51552
  const iFACTOR = Math.log(256) / Math.log(BASE);
51553
- function encode43(source) {
51553
+ function encode44(source) {
51554
51554
  if (source instanceof Uint8Array) {
51555
51555
  } else if (ArrayBuffer.isView(source)) {
51556
51556
  source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
@@ -51645,7 +51645,7 @@ var BTCR2 = (() => {
51645
51645
  }
51646
51646
  return vch;
51647
51647
  }
51648
- function decode47(string4) {
51648
+ function decode48(string4) {
51649
51649
  const buffer2 = decodeUnsafe(string4);
51650
51650
  if (buffer2) {
51651
51651
  return buffer2;
@@ -51653,9 +51653,9 @@ var BTCR2 = (() => {
51653
51653
  throw new Error("Non-base" + BASE + " character");
51654
51654
  }
51655
51655
  return {
51656
- encode: encode43,
51656
+ encode: encode44,
51657
51657
  decodeUnsafe,
51658
- decode: decode47
51658
+ decode: decode48
51659
51659
  };
51660
51660
  }
51661
51661
  var esm_default = base;
@@ -51666,7 +51666,7 @@ var BTCR2 = (() => {
51666
51666
 
51667
51667
  // ../../node_modules/.pnpm/bs58check@4.0.0/node_modules/bs58check/src/esm/base.js
51668
51668
  function base_default(checksumFn) {
51669
- function encode43(payload) {
51669
+ function encode44(payload) {
51670
51670
  var payloadU8 = Uint8Array.from(payload);
51671
51671
  var checksum2 = checksumFn(payloadU8);
51672
51672
  var length7 = payloadU8.length + 4;
@@ -51689,7 +51689,7 @@ var BTCR2 = (() => {
51689
51689
  return;
51690
51690
  return decodeRaw(buffer2);
51691
51691
  }
51692
- function decode47(str) {
51692
+ function decode48(str) {
51693
51693
  var buffer2 = esm_default2.decode(str);
51694
51694
  var payload = decodeRaw(buffer2);
51695
51695
  if (payload == null)
@@ -51697,8 +51697,8 @@ var BTCR2 = (() => {
51697
51697
  return payload;
51698
51698
  }
51699
51699
  return {
51700
- encode: encode43,
51701
- decode: decode47,
51700
+ encode: encode44,
51701
+ decode: decode48,
51702
51702
  decodeUnsafe
51703
51703
  };
51704
51704
  }
@@ -54314,7 +54314,7 @@ var BTCR2 = (() => {
54314
54314
  var range2 = (n2) => [...Array(n2).keys()];
54315
54315
  var isValidDERKey = (pubkey) => pubkey.length === 33 && [2, 3].includes(pubkey[0]) || pubkey.length === 65 && 4 === pubkey[0];
54316
54316
  function makeConverter(TYPE_BYTE, isValidPubkey = isValidDERKey) {
54317
- function decode47(keyVal) {
54317
+ function decode48(keyVal) {
54318
54318
  if (keyVal.key[0] !== TYPE_BYTE) {
54319
54319
  throw new Error(
54320
54320
  "Decode Error: could not decode bip32Derivation with key 0x" + toHex(keyVal.key)
@@ -54344,7 +54344,7 @@ var BTCR2 = (() => {
54344
54344
  }
54345
54345
  return data;
54346
54346
  }
54347
- function encode43(data) {
54347
+ function encode44(data) {
54348
54348
  const head = Uint8Array.from([TYPE_BYTE]);
54349
54349
  const key = concat([head, data.pubkey]);
54350
54350
  const splitPath = data.path.split("/");
@@ -54374,8 +54374,8 @@ var BTCR2 = (() => {
54374
54374
  return array2.filter((v) => compare(v.pubkey, item.pubkey) === 0).length === 0;
54375
54375
  }
54376
54376
  return {
54377
- decode: decode47,
54378
- encode: encode43,
54377
+ decode: decode48,
54378
+ encode: encode44,
54379
54379
  check: check15,
54380
54380
  expected: expected14,
54381
54381
  canAddToArray: canAddToArray5
@@ -54403,7 +54403,7 @@ var BTCR2 = (() => {
54403
54403
  // ../../node_modules/.pnpm/bip174@3.0.0-rc.1/node_modules/bip174/src/esm/lib/converter/shared/redeemScript.js
54404
54404
  init_shim();
54405
54405
  function makeConverter2(TYPE_BYTE) {
54406
- function decode47(keyVal) {
54406
+ function decode48(keyVal) {
54407
54407
  if (keyVal.key[0] !== TYPE_BYTE) {
54408
54408
  throw new Error(
54409
54409
  "Decode Error: could not decode redeemScript with key 0x" + toHex(keyVal.key)
@@ -54411,7 +54411,7 @@ var BTCR2 = (() => {
54411
54411
  }
54412
54412
  return keyVal.value;
54413
54413
  }
54414
- function encode43(data) {
54414
+ function encode44(data) {
54415
54415
  const key = Uint8Array.from([TYPE_BYTE]);
54416
54416
  return {
54417
54417
  key,
@@ -54426,8 +54426,8 @@ var BTCR2 = (() => {
54426
54426
  return !!currentData && !!newData && currentData.redeemScript === void 0;
54427
54427
  }
54428
54428
  return {
54429
- decode: decode47,
54430
- encode: encode43,
54429
+ decode: decode48,
54430
+ encode: encode44,
54431
54431
  check: check15,
54432
54432
  expected: expected14,
54433
54433
  canAdd: canAdd10
@@ -54439,7 +54439,7 @@ var BTCR2 = (() => {
54439
54439
  var isValidBIP340Key = (pubkey) => pubkey.length === 32;
54440
54440
  function makeConverter3(TYPE_BYTE) {
54441
54441
  const parent = makeConverter(TYPE_BYTE, isValidBIP340Key);
54442
- function decode47(keyVal) {
54442
+ function decode48(keyVal) {
54443
54443
  const { numberValue: nHashes, bytes: nHashesLen } = decode5(
54444
54444
  keyVal.value
54445
54445
  );
@@ -54453,7 +54453,7 @@ var BTCR2 = (() => {
54453
54453
  }
54454
54454
  return { ...base5, leafHashes };
54455
54455
  }
54456
- function encode43(data) {
54456
+ function encode44(data) {
54457
54457
  const base5 = parent.encode(data);
54458
54458
  const nHashesLen = encodingLength2(data.leafHashes.length);
54459
54459
  const nHashesBuf = new Uint8Array(nHashesLen);
@@ -54468,8 +54468,8 @@ var BTCR2 = (() => {
54468
54468
  ) && parent.check(data);
54469
54469
  }
54470
54470
  return {
54471
- decode: decode47,
54472
- encode: encode43,
54471
+ decode: decode48,
54472
+ encode: encode44,
54473
54473
  check: check15,
54474
54474
  expected: expected14,
54475
54475
  canAddToArray: parent.canAddToArray
@@ -54479,7 +54479,7 @@ var BTCR2 = (() => {
54479
54479
  // ../../node_modules/.pnpm/bip174@3.0.0-rc.1/node_modules/bip174/src/esm/lib/converter/shared/tapInternalKey.js
54480
54480
  init_shim();
54481
54481
  function makeConverter4(TYPE_BYTE) {
54482
- function decode47(keyVal) {
54482
+ function decode48(keyVal) {
54483
54483
  if (keyVal.key[0] !== TYPE_BYTE || keyVal.key.length !== 1) {
54484
54484
  throw new Error(
54485
54485
  "Decode Error: could not decode tapInternalKey with key 0x" + toHex(keyVal.key)
@@ -54492,7 +54492,7 @@ var BTCR2 = (() => {
54492
54492
  }
54493
54493
  return keyVal.value;
54494
54494
  }
54495
- function encode43(value3) {
54495
+ function encode44(value3) {
54496
54496
  const key = Uint8Array.from([TYPE_BYTE]);
54497
54497
  return { key, value: value3 };
54498
54498
  }
@@ -54504,8 +54504,8 @@ var BTCR2 = (() => {
54504
54504
  return !!currentData && !!newData && currentData.tapInternalKey === void 0;
54505
54505
  }
54506
54506
  return {
54507
- decode: decode47,
54508
- encode: encode43,
54507
+ decode: decode48,
54508
+ encode: encode44,
54509
54509
  check: check15,
54510
54510
  expected: expected14,
54511
54511
  canAdd: canAdd10
@@ -54515,7 +54515,7 @@ var BTCR2 = (() => {
54515
54515
  // ../../node_modules/.pnpm/bip174@3.0.0-rc.1/node_modules/bip174/src/esm/lib/converter/shared/witnessScript.js
54516
54516
  init_shim();
54517
54517
  function makeConverter5(TYPE_BYTE) {
54518
- function decode47(keyVal) {
54518
+ function decode48(keyVal) {
54519
54519
  if (keyVal.key[0] !== TYPE_BYTE) {
54520
54520
  throw new Error(
54521
54521
  "Decode Error: could not decode witnessScript with key 0x" + toHex(keyVal.key)
@@ -54523,7 +54523,7 @@ var BTCR2 = (() => {
54523
54523
  }
54524
54524
  return keyVal.value;
54525
54525
  }
54526
- function encode43(data) {
54526
+ function encode44(data) {
54527
54527
  const key = Uint8Array.from([TYPE_BYTE]);
54528
54528
  return {
54529
54529
  key,
@@ -54538,8 +54538,8 @@ var BTCR2 = (() => {
54538
54538
  return !!currentData && !!newData && currentData.witnessScript === void 0;
54539
54539
  }
54540
54540
  return {
54541
- decode: decode47,
54542
- encode: encode43,
54541
+ decode: decode48,
54542
+ encode: encode44,
54543
54543
  check: check15,
54544
54544
  expected: expected14,
54545
54545
  canAdd: canAdd10
@@ -57316,7 +57316,7 @@ var BTCR2 = (() => {
57316
57316
  function hash(canonicalized) {
57317
57317
  return sha256(canonicalized);
57318
57318
  }
57319
- function encodeHash(hashBytes, encoding = "hex") {
57319
+ function encode20(hashBytes, encoding = "base64url") {
57320
57320
  const normalized = normalizeEncoding(encoding);
57321
57321
  switch (normalized) {
57322
57322
  case "hex":
@@ -57327,10 +57327,21 @@ var BTCR2 = (() => {
57327
57327
  return base64urlnopad.encode(hashBytes);
57328
57328
  }
57329
57329
  }
57330
+ function decode19(encoded, encoding = "base64url") {
57331
+ const normalized = normalizeEncoding(encoding);
57332
+ switch (normalized) {
57333
+ case "hex":
57334
+ return hex.decode(encoded);
57335
+ case "base58":
57336
+ return base58.decode(encoded);
57337
+ case "base64url":
57338
+ return base64urlnopad.decode(encoded);
57339
+ }
57340
+ }
57330
57341
  function canonicalHash(object2, options2) {
57331
57342
  const algorithm = normalizeAlgorithm(options2?.algorithm ?? "jcs");
57332
- const encoding = normalizeEncoding(options2?.encoding ?? "hex");
57333
- return encodeHash(hash(canonicalize2(object2, algorithm)), encoding);
57343
+ const encoding = normalizeEncoding(options2?.encoding ?? "base64url");
57344
+ return encode20(hash(canonicalize2(object2, algorithm)), encoding);
57334
57345
  }
57335
57346
 
57336
57347
  // ../common/dist/esm/json-patch.js
@@ -61688,9 +61699,9 @@ var BTCR2 = (() => {
61688
61699
  function chain2(...args) {
61689
61700
  const id = (a2) => a2;
61690
61701
  const wrap2 = (a2, b) => (c2) => a2(b(c2));
61691
- const encode43 = args.map((x) => x.encode).reduceRight(wrap2, id);
61692
- const decode47 = args.map((x) => x.decode).reduce(wrap2, id);
61693
- return { encode: encode43, decode: decode47 };
61702
+ const encode44 = args.map((x) => x.encode).reduceRight(wrap2, id);
61703
+ const decode48 = args.map((x) => x.decode).reduce(wrap2, id);
61704
+ return { encode: encode44, decode: decode48 };
61694
61705
  }
61695
61706
  // @__NO_SIDE_EFFECTS__
61696
61707
  function alphabet2(letters) {
@@ -65158,9 +65169,9 @@ var BTCR2 = (() => {
65158
65169
  }
65159
65170
  function chain3(...args) {
65160
65171
  const wrap2 = (a2, b) => (c2) => a2(b(c2));
65161
- const encode43 = Array.from(args).reverse().reduce((acc, i4) => acc ? wrap2(acc, i4.encode) : i4.encode, void 0);
65162
- const decode47 = args.reduce((acc, i4) => acc ? wrap2(acc, i4.decode) : i4.decode, void 0);
65163
- return { encode: encode43, decode: decode47 };
65172
+ const encode44 = Array.from(args).reverse().reduce((acc, i4) => acc ? wrap2(acc, i4.encode) : i4.encode, void 0);
65173
+ const decode48 = args.reduce((acc, i4) => acc ? wrap2(acc, i4.decode) : i4.decode, void 0);
65174
+ return { encode: encode44, decode: decode48 };
65164
65175
  }
65165
65176
  function alphabet3(alphabet6) {
65166
65177
  return {
@@ -65441,7 +65452,7 @@ var BTCR2 = (() => {
65441
65452
  const fromWords = _words.decode;
65442
65453
  const toWords = _words.encode;
65443
65454
  const fromWordsUnsafe = unsafeWrapper2(fromWords);
65444
- function encode43(prefix, words, limit2 = 90) {
65455
+ function encode44(prefix, words, limit2 = 90) {
65445
65456
  if (typeof prefix !== "string")
65446
65457
  throw new Error(`bech32.encode prefix should be string, not ${typeof prefix}`);
65447
65458
  if (!Array.isArray(words) || words.length && typeof words[0] !== "number")
@@ -65452,7 +65463,7 @@ var BTCR2 = (() => {
65452
65463
  prefix = prefix.toLowerCase();
65453
65464
  return `${prefix}1${BECH_ALPHABET2.encode(words)}${bechChecksum2(prefix, words, ENCODING_CONST)}`;
65454
65465
  }
65455
- function decode47(str, limit2 = 90) {
65466
+ function decode48(str, limit2 = 90) {
65456
65467
  if (typeof str !== "string")
65457
65468
  throw new Error(`bech32.decode input should be string, not ${typeof str}`);
65458
65469
  if (str.length < 8 || limit2 !== false && str.length > limit2)
@@ -65474,12 +65485,12 @@ var BTCR2 = (() => {
65474
65485
  throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
65475
65486
  return { prefix, words };
65476
65487
  }
65477
- const decodeUnsafe = unsafeWrapper2(decode47);
65488
+ const decodeUnsafe = unsafeWrapper2(decode48);
65478
65489
  function decodeToBytes(str) {
65479
- const { prefix, words } = decode47(str, false);
65490
+ const { prefix, words } = decode48(str, false);
65480
65491
  return { prefix, words, bytes: fromWords(words) };
65481
65492
  }
65482
- return { encode: encode43, decode: decode47, decodeToBytes, decodeUnsafe, fromWords, fromWordsUnsafe, toWords };
65493
+ return { encode: encode44, decode: decode48, decodeToBytes, decodeUnsafe, fromWords, fromWordsUnsafe, toWords };
65483
65494
  }
65484
65495
  var bech324 = genBech322("bech32");
65485
65496
  var bech32m4 = genBech322("bech32m");
@@ -67513,7 +67524,7 @@ var BTCR2 = (() => {
67513
67524
  BECH32_REGEX: () => BECH32_REGEX,
67514
67525
  Bech32MaxSize: () => Bech32MaxSize,
67515
67526
  NostrTypeGuard: () => NostrTypeGuard,
67516
- decode: () => decode19,
67527
+ decode: () => decode20,
67517
67528
  decodeNostrURI: () => decodeNostrURI,
67518
67529
  encodeBytes: () => encodeBytes,
67519
67530
  naddrEncode: () => naddrEncode,
@@ -67546,12 +67557,12 @@ var BTCR2 = (() => {
67546
67557
  try {
67547
67558
  if (nip19code.startsWith("nostr:"))
67548
67559
  nip19code = nip19code.substring(6);
67549
- return decode19(nip19code);
67560
+ return decode20(nip19code);
67550
67561
  } catch (_err) {
67551
67562
  return { type: "invalid", data: null };
67552
67563
  }
67553
67564
  }
67554
- function decode19(code8) {
67565
+ function decode20(code8) {
67555
67566
  let { prefix, words } = bech324.decode(code8, Bech32MaxSize);
67556
67567
  let data = new Uint8Array(bech324.fromWords(words));
67557
67568
  switch (prefix) {
@@ -68255,7 +68266,7 @@ var BTCR2 = (() => {
68255
68266
  return {
68256
68267
  uri: match[0],
68257
68268
  value: match[1],
68258
- decoded: decode19(match[1])
68269
+ decoded: decode20(match[1])
68259
68270
  };
68260
68271
  }
68261
68272
  var nip25_exports = {};
@@ -68320,7 +68331,7 @@ var BTCR2 = (() => {
68320
68331
  const end = m2 ? u + 60 + m2.index : max;
68321
68332
  try {
68322
68333
  let pointer;
68323
- let { data, type } = decode19(content.substring(u + 1, end));
68334
+ let { data, type } = decode20(content.substring(u + 1, end));
68324
68335
  switch (type) {
68325
68336
  case "npub":
68326
68337
  pointer = { pubkey: data };
@@ -71059,31 +71070,108 @@ var BTCR2 = (() => {
71059
71070
  }
71060
71071
  /**
71061
71072
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
71073
+ *
71074
+ * For each signal, the signalBytes contain the hex-encoded hash of a CAS Announcement.
71075
+ * The CAS Announcement maps DIDs to their base64url-encoded update hashes.
71076
+ * This method looks up the CAS Announcement from the sidecar, extracts the update
71077
+ * hash for the DID being resolved, and retrieves the corresponding signed update.
71078
+ *
71062
71079
  * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
71063
71080
  * @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
71064
- * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
71065
- * @throws {CASBeaconError} if processing fails.
71081
+ * @returns {BeaconProcessResult} Successfully resolved updates and any data needs.
71082
+ * @throws {CASBeaconError} if hash verification fails (validation errors only).
71066
71083
  */
71067
71084
  processSignals(signals, sidecar) {
71068
- throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
71085
+ const updates = new Array();
71086
+ const needs = new Array();
71087
+ const did = this.service.id.split("#")[0];
71088
+ for (const signal of signals) {
71089
+ const announcementHash = encode20(decode19(signal.signalBytes, "hex"));
71090
+ const casAnnouncement = sidecar.casMap.get(announcementHash);
71091
+ if (!casAnnouncement) {
71092
+ needs.push({
71093
+ kind: "NeedCASAnnouncement",
71094
+ announcementHash,
71095
+ beaconServiceId: this.service.id
71096
+ });
71097
+ continue;
71098
+ }
71099
+ const updateHash = casAnnouncement[did];
71100
+ if (!updateHash) {
71101
+ continue;
71102
+ }
71103
+ const signedUpdate = sidecar.updateMap.get(updateHash);
71104
+ if (!signedUpdate) {
71105
+ needs.push({
71106
+ kind: "NeedSignedUpdate",
71107
+ updateHash,
71108
+ beaconServiceId: this.service.id
71109
+ });
71110
+ continue;
71111
+ }
71112
+ updates.push([signedUpdate, signal.blockMetadata]);
71113
+ }
71114
+ return { updates, needs };
71069
71115
  }
71070
71116
  /**
71071
- * Broadcast CAS Beacon signal to the Bitcoin network.
71117
+ * Broadcasts a CAS Beacon signal to the Bitcoin network.
71118
+ *
71119
+ * Creates a CAS Announcement mapping the DID to the update hash, then broadcasts
71120
+ * the hash of the announcement via OP_RETURN. The CAS Announcement is distributed
71121
+ * to resolvers via sidecar data.
71122
+ *
71072
71123
  * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
71073
71124
  * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
71074
71125
  * @param {BitcoinConnection} bitcoin The Bitcoin network connection.
71075
- * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
71076
- * @throws {CASBeaconError} if broadcasting fails.
71126
+ * @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
71127
+ * @throws {CASBeaconError} if the bitcoin address is invalid or unfunded.
71077
71128
  */
71078
71129
  async broadcastSignal(signedUpdate, secretKey, bitcoin2) {
71079
- throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin2 });
71130
+ const did = this.service.id.split("#")[0];
71131
+ const updateHash = canonicalHash(signedUpdate);
71132
+ const casAnnouncement = { [did]: updateHash };
71133
+ const announcementHash = hash(canonicalize2(casAnnouncement));
71134
+ const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
71135
+ const utxos = await bitcoin2.rest.address.getUtxos(bitcoinAddress);
71136
+ if (!utxos.length) {
71137
+ throw new CASBeaconError(
71138
+ "No UTXOs found, please fund address!",
71139
+ "UNFUNDED_BEACON_ADDRESS",
71140
+ { bitcoinAddress }
71141
+ );
71142
+ }
71143
+ const utxo = utxos.sort(
71144
+ (a2, b) => b.status.block_height - a2.status.block_height
71145
+ ).shift();
71146
+ if (!utxo) {
71147
+ throw new CASBeaconError(
71148
+ "Beacon bitcoin address unfunded or utxos unconfirmed.",
71149
+ "UNFUNDED_BEACON_ADDRESS",
71150
+ { bitcoinAddress }
71151
+ );
71152
+ }
71153
+ const prevTx = await bitcoin2.rest.transaction.getHex(utxo.txid);
71154
+ const spendTx = new Psbt2({ network: bitcoin2.data }).addInput({
71155
+ hash: utxo.txid,
71156
+ index: utxo.vout,
71157
+ nonWitnessUtxo: import_buffer.Buffer.from(prevTx, "hex")
71158
+ }).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, announcementHash]), value: 0n });
71159
+ const keyPair = SchnorrKeyPair.fromSecret(secretKey);
71160
+ const signer = {
71161
+ publicKey: keyPair.publicKey.compressed,
71162
+ sign: (hash5) => keyPair.secretKey.sign(hash5, { scheme: "ecdsa" })
71163
+ };
71164
+ const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
71165
+ const txid = await bitcoin2.rest.transaction.send(signedTx);
71166
+ console.info(`CAS Beacon Signal Broadcasted with txid: ${txid}`);
71167
+ return signedUpdate;
71080
71168
  }
71081
71169
  };
71082
71170
 
71083
71171
  // src/core/beacon/factory.ts
71084
71172
  init_shim();
71085
71173
 
71086
- // src/core/beacon/singleton.ts
71174
+ // src/core/beacon/singleton-beacon.ts
71087
71175
  init_shim();
71088
71176
  var SingletonBeacon = class extends Beacon {
71089
71177
  /**
@@ -71095,33 +71183,27 @@ var BTCR2 = (() => {
71095
71183
  }
71096
71184
  /**
71097
71185
  * Processes an array of Beacon Signals associated with a Singleton Beacon Service.
71098
- * @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
71099
- * @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
71186
+ * @param {Array<BeaconSignal>} signals The beacon signals discovered on-chain.
71187
+ * @param {SidecarData} sidecar The processed sidecar data.
71188
+ * @returns {BeaconProcessResult} Successfully resolved updates and any data needs.
71100
71189
  */
71101
- async processSignals(signals, sidecar) {
71190
+ processSignals(signals, sidecar) {
71102
71191
  const updates = new Array();
71192
+ const needs = new Array();
71103
71193
  for (const signal of signals) {
71104
- const updateHash = signal.signalBytes;
71194
+ const updateHash = encode20(decode19(signal.signalBytes, "hex"));
71105
71195
  const signedUpdate = sidecar.updateMap.get(updateHash);
71106
71196
  if (!signedUpdate) {
71107
- throw new SingletonBeaconError(
71108
- `BTCR2 Signed Update not found for update hash ${updateHash}.`,
71109
- MISSING_UPDATE_DATA,
71110
- signal
71111
- );
71112
- }
71113
- const encodedUpdate = canonicalHash(signedUpdate, { encoding: "base64url" });
71114
- const signalBytes = base64urlnopad.encode(import_buffer.Buffer.from(updateHash, "hex"));
71115
- if (encodedUpdate !== signalBytes) {
71116
- throw new SingletonBeaconError(
71117
- `Hash mismatch: sidecar update ${encodedUpdate} !== signal bytes ${signalBytes}.`,
71118
- INVALID_SIDECAR_DATA,
71119
- { encodedUpdate, signalBytes }
71120
- );
71197
+ needs.push({
71198
+ kind: "NeedSignedUpdate",
71199
+ updateHash,
71200
+ beaconServiceId: this.service.id
71201
+ });
71202
+ continue;
71121
71203
  }
71122
71204
  updates.push([signedUpdate, signal.blockMetadata]);
71123
71205
  }
71124
- return updates;
71206
+ return { updates, needs };
71125
71207
  }
71126
71208
  /**
71127
71209
  * Broadcasts a SingletonBeacon signal to the Bitcoin network.
@@ -71184,7 +71266,7 @@ var BTCR2 = (() => {
71184
71266
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
71185
71267
  * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
71186
71268
  * @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
71187
- * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
71269
+ * @returns {BeaconProcessResult} The processed signals.
71188
71270
  * @throws {SMTBeaconError} if processing fails.
71189
71271
  */
71190
71272
  processSignals(signals, sidecar) {
@@ -71390,7 +71472,7 @@ var BTCR2 = (() => {
71390
71472
  var LEADER = ALPHABET2.charAt(0);
71391
71473
  var FACTOR = Math.log(BASE) / Math.log(256);
71392
71474
  var iFACTOR = Math.log(256) / Math.log(BASE);
71393
- function encode43(source) {
71475
+ function encode44(source) {
71394
71476
  if (source instanceof Uint8Array)
71395
71477
  ;
71396
71478
  else if (ArrayBuffer.isView(source)) {
@@ -71488,7 +71570,7 @@ var BTCR2 = (() => {
71488
71570
  }
71489
71571
  return vch;
71490
71572
  }
71491
- function decode47(string4) {
71573
+ function decode48(string4) {
71492
71574
  var buffer2 = decodeUnsafe(string4);
71493
71575
  if (buffer2) {
71494
71576
  return buffer2;
@@ -71496,9 +71578,9 @@ var BTCR2 = (() => {
71496
71578
  throw new Error(`Non-${name10} character`);
71497
71579
  }
71498
71580
  return {
71499
- encode: encode43,
71581
+ encode: encode44,
71500
71582
  decodeUnsafe,
71501
- decode: decode47
71583
+ decode: decode48
71502
71584
  };
71503
71585
  }
71504
71586
  var src = base2;
@@ -71598,19 +71680,19 @@ var BTCR2 = (() => {
71598
71680
  return this.decoder.decode(input);
71599
71681
  }
71600
71682
  };
71601
- function from({ name: name10, prefix, encode: encode43, decode: decode47 }) {
71602
- return new Codec(name10, prefix, encode43, decode47);
71683
+ function from({ name: name10, prefix, encode: encode44, decode: decode48 }) {
71684
+ return new Codec(name10, prefix, encode44, decode48);
71603
71685
  }
71604
71686
  function baseX({ name: name10, prefix, alphabet: alphabet6 }) {
71605
- const { encode: encode43, decode: decode47 } = base_x_default(alphabet6, name10);
71687
+ const { encode: encode44, decode: decode48 } = base_x_default(alphabet6, name10);
71606
71688
  return from({
71607
71689
  prefix,
71608
71690
  name: name10,
71609
- encode: encode43,
71610
- decode: (text) => coerce(decode47(text))
71691
+ encode: encode44,
71692
+ decode: (text) => coerce(decode48(text))
71611
71693
  });
71612
71694
  }
71613
- function decode20(string4, alphabetIdx, bitsPerChar, name10) {
71695
+ function decode21(string4, alphabetIdx, bitsPerChar, name10) {
71614
71696
  let end = string4.length;
71615
71697
  while (string4[end - 1] === "=") {
71616
71698
  --end;
@@ -71636,7 +71718,7 @@ var BTCR2 = (() => {
71636
71718
  }
71637
71719
  return out;
71638
71720
  }
71639
- function encode20(data, alphabet6, bitsPerChar) {
71721
+ function encode21(data, alphabet6, bitsPerChar) {
71640
71722
  const pad2 = alphabet6[alphabet6.length - 1] === "=";
71641
71723
  const mask = (1 << bitsPerChar) - 1;
71642
71724
  let out = "";
@@ -71673,10 +71755,10 @@ var BTCR2 = (() => {
71673
71755
  prefix,
71674
71756
  name: name10,
71675
71757
  encode(input) {
71676
- return encode20(input, alphabet6, bitsPerChar);
71758
+ return encode21(input, alphabet6, bitsPerChar);
71677
71759
  },
71678
71760
  decode(input) {
71679
- return decode20(input, alphabetIdx, bitsPerChar, name10);
71761
+ return decode21(input, alphabetIdx, bitsPerChar, name10);
71680
71762
  }
71681
71763
  });
71682
71764
  }
@@ -71778,7 +71860,7 @@ var BTCR2 = (() => {
71778
71860
  __export(digest_exports, {
71779
71861
  Digest: () => Digest,
71780
71862
  create: () => create,
71781
- decode: () => decode23,
71863
+ decode: () => decode24,
71782
71864
  equals: () => equals2,
71783
71865
  hasCode: () => hasCode
71784
71866
  });
@@ -71789,12 +71871,12 @@ var BTCR2 = (() => {
71789
71871
 
71790
71872
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/vendor/varint.js
71791
71873
  init_shim();
71792
- var encode_1 = encode21;
71874
+ var encode_1 = encode22;
71793
71875
  var MSB = 128;
71794
71876
  var REST = 127;
71795
71877
  var MSBALL = ~REST;
71796
71878
  var INT = Math.pow(2, 31);
71797
- function encode21(num3, out, offset) {
71879
+ function encode22(num3, out, offset) {
71798
71880
  out = out || [];
71799
71881
  offset = offset || 0;
71800
71882
  var oldOffset = offset;
@@ -71807,10 +71889,10 @@ var BTCR2 = (() => {
71807
71889
  num3 >>>= 7;
71808
71890
  }
71809
71891
  out[offset] = num3 | 0;
71810
- encode21.bytes = offset - oldOffset + 1;
71892
+ encode22.bytes = offset - oldOffset + 1;
71811
71893
  return out;
71812
71894
  }
71813
- var decode21 = read;
71895
+ var decode22 = read;
71814
71896
  var MSB$1 = 128;
71815
71897
  var REST$1 = 127;
71816
71898
  function read(buf2, offset) {
@@ -71841,14 +71923,14 @@ var BTCR2 = (() => {
71841
71923
  };
71842
71924
  var varint = {
71843
71925
  encode: encode_1,
71844
- decode: decode21,
71926
+ decode: decode22,
71845
71927
  encodingLength: length2
71846
71928
  };
71847
71929
  var _brrp_varint = varint;
71848
71930
  var varint_default = _brrp_varint;
71849
71931
 
71850
71932
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/varint.js
71851
- function decode22(data, offset = 0) {
71933
+ function decode23(data, offset = 0) {
71852
71934
  const code8 = varint_default.decode(data, offset);
71853
71935
  return [code8, varint_default.decode.bytes];
71854
71936
  }
@@ -71871,10 +71953,10 @@ var BTCR2 = (() => {
71871
71953
  bytes6.set(digest2, digestOffset);
71872
71954
  return new Digest(code8, size, digest2, bytes6);
71873
71955
  }
71874
- function decode23(multihash) {
71956
+ function decode24(multihash) {
71875
71957
  const bytes6 = coerce(multihash);
71876
- const [code8, sizeOffset] = decode22(bytes6);
71877
- const [size, digestOffset] = decode22(bytes6.subarray(sizeOffset));
71958
+ const [code8, sizeOffset] = decode23(bytes6);
71959
+ const [size, digestOffset] = decode23(bytes6.subarray(sizeOffset));
71878
71960
  const digest2 = bytes6.subarray(sizeOffset + digestOffset);
71879
71961
  if (digest2.byteLength !== size) {
71880
71962
  throw new Error("Incorrect length");
@@ -72044,7 +72126,7 @@ var BTCR2 = (() => {
72044
72126
  return new _CID(version3, code8, multihash, bytes6 ?? encodeCID(version3, code8, multihash.bytes));
72045
72127
  } else if (value3[cidSymbol] === true) {
72046
72128
  const { version: version3, multihash, code: code8 } = value3;
72047
- const digest2 = decode23(multihash);
72129
+ const digest2 = decode24(multihash);
72048
72130
  return _CID.create(version3, code8, digest2);
72049
72131
  } else {
72050
72132
  return null;
@@ -72141,7 +72223,7 @@ var BTCR2 = (() => {
72141
72223
  static inspectBytes(initialBytes) {
72142
72224
  let offset = 0;
72143
72225
  const next = () => {
72144
- const [i4, length7] = decode22(initialBytes.subarray(offset));
72226
+ const [i4, length7] = decode23(initialBytes.subarray(offset));
72145
72227
  offset += length7;
72146
72228
  return i4;
72147
72229
  };
@@ -72251,17 +72333,17 @@ var BTCR2 = (() => {
72251
72333
  var raw_exports = {};
72252
72334
  __export(raw_exports, {
72253
72335
  code: () => code,
72254
- decode: () => decode24,
72255
- encode: () => encode22,
72336
+ decode: () => decode25,
72337
+ encode: () => encode23,
72256
72338
  name: () => name
72257
72339
  });
72258
72340
  init_shim();
72259
72341
  var name = "raw";
72260
72342
  var code = 85;
72261
- function encode22(node) {
72343
+ function encode23(node) {
72262
72344
  return coerce(node);
72263
72345
  }
72264
- function decode24(data) {
72346
+ function decode25(data) {
72265
72347
  return coerce(data);
72266
72348
  }
72267
72349
 
@@ -72276,8 +72358,8 @@ var BTCR2 = (() => {
72276
72358
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/hashes/hasher.js
72277
72359
  init_shim();
72278
72360
  var DEFAULT_MIN_DIGEST_LENGTH = 20;
72279
- function from2({ name: name10, code: code8, encode: encode43, minDigestLength, maxDigestLength }) {
72280
- return new Hasher(name10, code8, encode43, minDigestLength, maxDigestLength);
72361
+ function from2({ name: name10, code: code8, encode: encode44, minDigestLength, maxDigestLength }) {
72362
+ return new Hasher(name10, code8, encode44, minDigestLength, maxDigestLength);
72281
72363
  }
72282
72364
  var Hasher = class {
72283
72365
  name;
@@ -72285,10 +72367,10 @@ var BTCR2 = (() => {
72285
72367
  encode;
72286
72368
  minDigestLength;
72287
72369
  maxDigestLength;
72288
- constructor(name10, code8, encode43, minDigestLength, maxDigestLength) {
72370
+ constructor(name10, code8, encode44, minDigestLength, maxDigestLength) {
72289
72371
  this.name = name10;
72290
72372
  this.code = code8;
72291
- this.encode = encode43;
72373
+ this.encode = encode44;
72292
72374
  this.minDigestLength = minDigestLength ?? DEFAULT_MIN_DIGEST_LENGTH;
72293
72375
  this.maxDigestLength = maxDigestLength;
72294
72376
  }
@@ -72410,13 +72492,13 @@ var BTCR2 = (() => {
72410
72492
  p2[codePoint] = i4;
72411
72493
  return p2;
72412
72494
  }, []);
72413
- function encode23(data) {
72495
+ function encode24(data) {
72414
72496
  return data.reduce((p2, c2) => {
72415
72497
  p2 += alphabetBytesToChars[c2];
72416
72498
  return p2;
72417
72499
  }, "");
72418
72500
  }
72419
- function decode25(str) {
72501
+ function decode26(str) {
72420
72502
  const byts = [];
72421
72503
  for (const char of str) {
72422
72504
  const codePoint = char.codePointAt(0);
@@ -72434,8 +72516,8 @@ var BTCR2 = (() => {
72434
72516
  var base256emoji = from({
72435
72517
  prefix: "\u{1F680}",
72436
72518
  name: "base256emoji",
72437
- encode: encode23,
72438
- decode: decode25
72519
+ encode: encode24,
72520
+ decode: decode26
72439
72521
  });
72440
72522
 
72441
72523
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base64.js
@@ -72502,8 +72584,8 @@ var BTCR2 = (() => {
72502
72584
  var json_exports = {};
72503
72585
  __export(json_exports, {
72504
72586
  code: () => code2,
72505
- decode: () => decode26,
72506
- encode: () => encode24,
72587
+ decode: () => decode27,
72588
+ encode: () => encode25,
72507
72589
  name: () => name2
72508
72590
  });
72509
72591
  init_shim();
@@ -72511,10 +72593,10 @@ var BTCR2 = (() => {
72511
72593
  var textDecoder = new TextDecoder();
72512
72594
  var name2 = "json";
72513
72595
  var code2 = 512;
72514
- function encode24(node) {
72596
+ function encode25(node) {
72515
72597
  return textEncoder.encode(JSON.stringify(node));
72516
72598
  }
72517
- function decode26(data) {
72599
+ function decode27(data) {
72518
72600
  return JSON.parse(textDecoder.decode(data));
72519
72601
  }
72520
72602
 
@@ -72526,7 +72608,7 @@ var BTCR2 = (() => {
72526
72608
  init_shim();
72527
72609
  var code3 = 0;
72528
72610
  var name3 = "identity";
72529
- var encode25 = coerce;
72611
+ var encode26 = coerce;
72530
72612
  function digest(input, options2) {
72531
72613
  if (options2?.truncate != null && options2.truncate !== input.byteLength) {
72532
72614
  if (options2.truncate < 0 || options2.truncate > input.byteLength) {
@@ -72534,9 +72616,9 @@ var BTCR2 = (() => {
72534
72616
  }
72535
72617
  input = input.subarray(0, options2.truncate);
72536
72618
  }
72537
- return create(code3, encode25(input));
72619
+ return create(code3, encode26(input));
72538
72620
  }
72539
- var identity2 = { code: code3, name: name3, encode: encode25, digest };
72621
+ var identity2 = { code: code3, name: name3, encode: encode26, digest };
72540
72622
 
72541
72623
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/index.js
72542
72624
  init_shim();
@@ -72570,17 +72652,17 @@ var BTCR2 = (() => {
72570
72652
  }
72571
72653
 
72572
72654
  // ../../node_modules/.pnpm/uint8arrays@5.1.0/node_modules/uint8arrays/dist/src/util/bases.js
72573
- function createCodec(name10, prefix, encode43, decode47) {
72655
+ function createCodec(name10, prefix, encode44, decode48) {
72574
72656
  return {
72575
72657
  name: name10,
72576
72658
  prefix,
72577
72659
  encoder: {
72578
72660
  name: name10,
72579
72661
  prefix,
72580
- encode: encode43
72662
+ encode: encode44
72581
72663
  },
72582
72664
  decoder: {
72583
- decode: decode47
72665
+ decode: decode48
72584
72666
  }
72585
72667
  };
72586
72668
  }
@@ -72872,7 +72954,7 @@ var BTCR2 = (() => {
72872
72954
  var LEADER = ALPHABET2.charAt(0);
72873
72955
  var FACTOR = Math.log(BASE) / Math.log(256);
72874
72956
  var iFACTOR = Math.log(256) / Math.log(BASE);
72875
- function encode43(source) {
72957
+ function encode44(source) {
72876
72958
  if (source instanceof Uint8Array)
72877
72959
  ;
72878
72960
  else if (ArrayBuffer.isView(source)) {
@@ -72970,7 +73052,7 @@ var BTCR2 = (() => {
72970
73052
  }
72971
73053
  return vch;
72972
73054
  }
72973
- function decode47(string4) {
73055
+ function decode48(string4) {
72974
73056
  var buffer2 = decodeUnsafe(string4);
72975
73057
  if (buffer2) {
72976
73058
  return buffer2;
@@ -72978,9 +73060,9 @@ var BTCR2 = (() => {
72978
73060
  throw new Error(`Non-${name10} character`);
72979
73061
  }
72980
73062
  return {
72981
- encode: encode43,
73063
+ encode: encode44,
72982
73064
  decodeUnsafe,
72983
- decode: decode47
73065
+ decode: decode48
72984
73066
  };
72985
73067
  }
72986
73068
  var src2 = base3;
@@ -73079,19 +73161,19 @@ var BTCR2 = (() => {
73079
73161
  return this.decoder.decode(input);
73080
73162
  }
73081
73163
  };
73082
- function from3({ name: name10, prefix, encode: encode43, decode: decode47 }) {
73083
- return new Codec2(name10, prefix, encode43, decode47);
73164
+ function from3({ name: name10, prefix, encode: encode44, decode: decode48 }) {
73165
+ return new Codec2(name10, prefix, encode44, decode48);
73084
73166
  }
73085
73167
  function baseX2({ name: name10, prefix, alphabet: alphabet6 }) {
73086
- const { encode: encode43, decode: decode47 } = base_x_default2(alphabet6, name10);
73168
+ const { encode: encode44, decode: decode48 } = base_x_default2(alphabet6, name10);
73087
73169
  return from3({
73088
73170
  prefix,
73089
73171
  name: name10,
73090
- encode: encode43,
73091
- decode: (text) => coerce2(decode47(text))
73172
+ encode: encode44,
73173
+ decode: (text) => coerce2(decode48(text))
73092
73174
  });
73093
73175
  }
73094
- function decode27(string4, alphabet6, bitsPerChar, name10) {
73176
+ function decode28(string4, alphabet6, bitsPerChar, name10) {
73095
73177
  const codes = {};
73096
73178
  for (let i4 = 0; i4 < alphabet6.length; ++i4) {
73097
73179
  codes[alphabet6[i4]] = i4;
@@ -73121,7 +73203,7 @@ var BTCR2 = (() => {
73121
73203
  }
73122
73204
  return out;
73123
73205
  }
73124
- function encode26(data, alphabet6, bitsPerChar) {
73206
+ function encode27(data, alphabet6, bitsPerChar) {
73125
73207
  const pad2 = alphabet6[alphabet6.length - 1] === "=";
73126
73208
  const mask = (1 << bitsPerChar) - 1;
73127
73209
  let out = "";
@@ -73150,10 +73232,10 @@ var BTCR2 = (() => {
73150
73232
  prefix,
73151
73233
  name: name10,
73152
73234
  encode(input) {
73153
- return encode26(input, alphabet6, bitsPerChar);
73235
+ return encode27(input, alphabet6, bitsPerChar);
73154
73236
  },
73155
73237
  decode(input) {
73156
- return decode27(input, alphabet6, bitsPerChar, name10);
73238
+ return decode28(input, alphabet6, bitsPerChar, name10);
73157
73239
  }
73158
73240
  });
73159
73241
  }
@@ -73728,7 +73810,7 @@ var BTCR2 = (() => {
73728
73810
  // ../../node_modules/.pnpm/multiformats@13.1.0/node_modules/multiformats/dist/src/varint.js
73729
73811
  var varint_exports2 = {};
73730
73812
  __export(varint_exports2, {
73731
- decode: () => decode29,
73813
+ decode: () => decode30,
73732
73814
  encodeTo: () => encodeTo2,
73733
73815
  encodingLength: () => encodingLength4
73734
73816
  });
@@ -73736,12 +73818,12 @@ var BTCR2 = (() => {
73736
73818
 
73737
73819
  // ../../node_modules/.pnpm/multiformats@13.1.0/node_modules/multiformats/dist/src/vendor/varint.js
73738
73820
  init_shim();
73739
- var encode_12 = encode27;
73821
+ var encode_12 = encode28;
73740
73822
  var MSB2 = 128;
73741
73823
  var REST2 = 127;
73742
73824
  var MSBALL2 = ~REST2;
73743
73825
  var INT2 = Math.pow(2, 31);
73744
- function encode27(num3, out, offset) {
73826
+ function encode28(num3, out, offset) {
73745
73827
  out = out || [];
73746
73828
  offset = offset || 0;
73747
73829
  var oldOffset = offset;
@@ -73754,10 +73836,10 @@ var BTCR2 = (() => {
73754
73836
  num3 >>>= 7;
73755
73837
  }
73756
73838
  out[offset] = num3 | 0;
73757
- encode27.bytes = offset - oldOffset + 1;
73839
+ encode28.bytes = offset - oldOffset + 1;
73758
73840
  return out;
73759
73841
  }
73760
- var decode28 = read2;
73842
+ var decode29 = read2;
73761
73843
  var MSB$12 = 128;
73762
73844
  var REST$12 = 127;
73763
73845
  function read2(buf2, offset) {
@@ -73788,14 +73870,14 @@ var BTCR2 = (() => {
73788
73870
  };
73789
73871
  var varint2 = {
73790
73872
  encode: encode_12,
73791
- decode: decode28,
73873
+ decode: decode29,
73792
73874
  encodingLength: length3
73793
73875
  };
73794
73876
  var _brrp_varint2 = varint2;
73795
73877
  var varint_default2 = _brrp_varint2;
73796
73878
 
73797
73879
  // ../../node_modules/.pnpm/multiformats@13.1.0/node_modules/multiformats/dist/src/varint.js
73798
- function decode29(data, offset = 0) {
73880
+ function decode30(data, offset = 0) {
73799
73881
  const code8 = varint_default2.decode(data, offset);
73800
73882
  return [code8, varint_default2.decode.bytes];
73801
73883
  }
@@ -73818,10 +73900,10 @@ var BTCR2 = (() => {
73818
73900
  bytes6.set(digest2, digestOffset);
73819
73901
  return new Digest2(code8, size, digest2, bytes6);
73820
73902
  }
73821
- function decode30(multihash) {
73903
+ function decode31(multihash) {
73822
73904
  const bytes6 = coerce2(multihash);
73823
- const [code8, sizeOffset] = decode29(bytes6);
73824
- const [size, digestOffset] = decode29(bytes6.subarray(sizeOffset));
73905
+ const [code8, sizeOffset] = decode30(bytes6);
73906
+ const [size, digestOffset] = decode30(bytes6.subarray(sizeOffset));
73825
73907
  const digest2 = bytes6.subarray(sizeOffset + digestOffset);
73826
73908
  if (digest2.byteLength !== size) {
73827
73909
  throw new Error("Incorrect length");
@@ -73988,7 +74070,7 @@ var BTCR2 = (() => {
73988
74070
  return new _CID(version3, code8, multihash, bytes6 ?? encodeCID2(version3, code8, multihash.bytes));
73989
74071
  } else if (value3[cidSymbol2] === true) {
73990
74072
  const { version: version3, multihash, code: code8 } = value3;
73991
- const digest2 = decode30(multihash);
74073
+ const digest2 = decode31(multihash);
73992
74074
  return _CID.create(version3, code8, digest2);
73993
74075
  } else {
73994
74076
  return null;
@@ -74085,7 +74167,7 @@ var BTCR2 = (() => {
74085
74167
  static inspectBytes(initialBytes) {
74086
74168
  let offset = 0;
74087
74169
  const next = () => {
74088
- const [i4, length7] = decode29(initialBytes.subarray(offset));
74170
+ const [i4, length7] = decode30(initialBytes.subarray(offset));
74089
74171
  offset += length7;
74090
74172
  return i4;
74091
74173
  };
@@ -81537,72 +81619,72 @@ var BTCR2 = (() => {
81537
81619
  }
81538
81620
 
81539
81621
  // ../../node_modules/.pnpm/bencode@4.0.0/node_modules/bencode/lib/encode.js
81540
- function encode29(data, buffer2, offset) {
81622
+ function encode30(data, buffer2, offset) {
81541
81623
  const buffers = [];
81542
81624
  let result = null;
81543
- encode29._encode(buffers, data);
81625
+ encode30._encode(buffers, data);
81544
81626
  result = concat2(buffers);
81545
- encode29.bytes = result.length;
81627
+ encode30.bytes = result.length;
81546
81628
  if (ArrayBuffer.isView(buffer2)) {
81547
81629
  buffer2.set(result, offset);
81548
81630
  return buffer2;
81549
81631
  }
81550
81632
  return result;
81551
81633
  }
81552
- encode29.bytes = -1;
81553
- encode29._floatConversionDetected = false;
81554
- encode29._encode = function(buffers, data) {
81634
+ encode30.bytes = -1;
81635
+ encode30._floatConversionDetected = false;
81636
+ encode30._encode = function(buffers, data) {
81555
81637
  if (data == null) {
81556
81638
  return;
81557
81639
  }
81558
81640
  switch (getType(data)) {
81559
81641
  case "object":
81560
- encode29.dict(buffers, data);
81642
+ encode30.dict(buffers, data);
81561
81643
  break;
81562
81644
  case "map":
81563
- encode29.dictMap(buffers, data);
81645
+ encode30.dictMap(buffers, data);
81564
81646
  break;
81565
81647
  case "array":
81566
- encode29.list(buffers, data);
81648
+ encode30.list(buffers, data);
81567
81649
  break;
81568
81650
  case "set":
81569
- encode29.listSet(buffers, data);
81651
+ encode30.listSet(buffers, data);
81570
81652
  break;
81571
81653
  case "string":
81572
- encode29.string(buffers, data);
81654
+ encode30.string(buffers, data);
81573
81655
  break;
81574
81656
  case "number":
81575
- encode29.number(buffers, data);
81657
+ encode30.number(buffers, data);
81576
81658
  break;
81577
81659
  case "boolean":
81578
- encode29.number(buffers, data);
81660
+ encode30.number(buffers, data);
81579
81661
  break;
81580
81662
  case "arraybufferview":
81581
- encode29.buffer(buffers, new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
81663
+ encode30.buffer(buffers, new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
81582
81664
  break;
81583
81665
  case "arraybuffer":
81584
- encode29.buffer(buffers, new Uint8Array(data));
81666
+ encode30.buffer(buffers, new Uint8Array(data));
81585
81667
  break;
81586
81668
  }
81587
81669
  };
81588
81670
  var buffE = new Uint8Array([101]);
81589
81671
  var buffD = new Uint8Array([100]);
81590
81672
  var buffL = new Uint8Array([108]);
81591
- encode29.buffer = function(buffers, data) {
81673
+ encode30.buffer = function(buffers, data) {
81592
81674
  buffers.push(text2arr(data.length + ":"), data);
81593
81675
  };
81594
- encode29.string = function(buffers, data) {
81676
+ encode30.string = function(buffers, data) {
81595
81677
  buffers.push(text2arr(text2arr(data).byteLength + ":" + data));
81596
81678
  };
81597
- encode29.number = function(buffers, data) {
81679
+ encode30.number = function(buffers, data) {
81598
81680
  if (Number.isInteger(data)) return buffers.push(text2arr("i" + BigInt(data) + "e"));
81599
81681
  const maxLo = 2147483648;
81600
81682
  const hi = data / maxLo << 0;
81601
81683
  const lo = data % maxLo << 0;
81602
81684
  const val = hi * maxLo + lo;
81603
81685
  buffers.push(text2arr("i" + val + "e"));
81604
- if (val !== data && !encode29._floatConversionDetected) {
81605
- encode29._floatConversionDetected = true;
81686
+ if (val !== data && !encode30._floatConversionDetected) {
81687
+ encode30._floatConversionDetected = true;
81606
81688
  console.warn(
81607
81689
  'WARNING: Possible data corruption detected with value "' + data + '":',
81608
81690
  'Bencoding only defines support for integers, value was converted to "' + val + '"'
@@ -81610,7 +81692,7 @@ var BTCR2 = (() => {
81610
81692
  console.trace();
81611
81693
  }
81612
81694
  };
81613
- encode29.dict = function(buffers, data) {
81695
+ encode30.dict = function(buffers, data) {
81614
81696
  buffers.push(buffD);
81615
81697
  let j = 0;
81616
81698
  let k;
@@ -81619,40 +81701,40 @@ var BTCR2 = (() => {
81619
81701
  for (; j < kl; j++) {
81620
81702
  k = keys[j];
81621
81703
  if (data[k] == null) continue;
81622
- encode29.string(buffers, k);
81623
- encode29._encode(buffers, data[k]);
81704
+ encode30.string(buffers, k);
81705
+ encode30._encode(buffers, data[k]);
81624
81706
  }
81625
81707
  buffers.push(buffE);
81626
81708
  };
81627
- encode29.dictMap = function(buffers, data) {
81709
+ encode30.dictMap = function(buffers, data) {
81628
81710
  buffers.push(buffD);
81629
81711
  const keys = Array.from(data.keys()).sort();
81630
81712
  for (const key of keys) {
81631
81713
  if (data.get(key) == null) continue;
81632
- ArrayBuffer.isView(key) ? encode29._encode(buffers, key) : encode29.string(buffers, String(key));
81633
- encode29._encode(buffers, data.get(key));
81714
+ ArrayBuffer.isView(key) ? encode30._encode(buffers, key) : encode30.string(buffers, String(key));
81715
+ encode30._encode(buffers, data.get(key));
81634
81716
  }
81635
81717
  buffers.push(buffE);
81636
81718
  };
81637
- encode29.list = function(buffers, data) {
81719
+ encode30.list = function(buffers, data) {
81638
81720
  let i4 = 0;
81639
81721
  const c2 = data.length;
81640
81722
  buffers.push(buffL);
81641
81723
  for (; i4 < c2; i4++) {
81642
81724
  if (data[i4] == null) continue;
81643
- encode29._encode(buffers, data[i4]);
81725
+ encode30._encode(buffers, data[i4]);
81644
81726
  }
81645
81727
  buffers.push(buffE);
81646
81728
  };
81647
- encode29.listSet = function(buffers, data) {
81729
+ encode30.listSet = function(buffers, data) {
81648
81730
  buffers.push(buffL);
81649
81731
  for (const item of data) {
81650
81732
  if (item == null) continue;
81651
- encode29._encode(buffers, item);
81733
+ encode30._encode(buffers, item);
81652
81734
  }
81653
81735
  buffers.push(buffE);
81654
81736
  };
81655
- var encode_default = encode29;
81737
+ var encode_default = encode30;
81656
81738
 
81657
81739
  // ../../node_modules/.pnpm/bencode@4.0.0/node_modules/bencode/lib/decode.js
81658
81740
  init_shim();
@@ -81684,7 +81766,7 @@ var BTCR2 = (() => {
81684
81766
  }
81685
81767
  return sum * sign;
81686
81768
  }
81687
- function decode32(data, start2, end, encoding) {
81769
+ function decode33(data, start2, end, encoding) {
81688
81770
  if (data == null || data.length === 0) {
81689
81771
  return null;
81690
81772
  }
@@ -81696,32 +81778,32 @@ var BTCR2 = (() => {
81696
81778
  encoding = end;
81697
81779
  end = void 0;
81698
81780
  }
81699
- decode32.position = 0;
81700
- decode32.encoding = encoding || null;
81701
- decode32.data = !ArrayBuffer.isView(data) ? text2arr(data) : new Uint8Array(data.slice(start2, end));
81702
- decode32.bytes = decode32.data.length;
81703
- return decode32.next();
81704
- }
81705
- decode32.bytes = 0;
81706
- decode32.position = 0;
81707
- decode32.data = null;
81708
- decode32.encoding = null;
81709
- decode32.next = function() {
81710
- switch (decode32.data[decode32.position]) {
81781
+ decode33.position = 0;
81782
+ decode33.encoding = encoding || null;
81783
+ decode33.data = !ArrayBuffer.isView(data) ? text2arr(data) : new Uint8Array(data.slice(start2, end));
81784
+ decode33.bytes = decode33.data.length;
81785
+ return decode33.next();
81786
+ }
81787
+ decode33.bytes = 0;
81788
+ decode33.position = 0;
81789
+ decode33.data = null;
81790
+ decode33.encoding = null;
81791
+ decode33.next = function() {
81792
+ switch (decode33.data[decode33.position]) {
81711
81793
  case DICTIONARY_START:
81712
- return decode32.dictionary();
81794
+ return decode33.dictionary();
81713
81795
  case LIST_START:
81714
- return decode32.list();
81796
+ return decode33.list();
81715
81797
  case INTEGER_START:
81716
- return decode32.integer();
81798
+ return decode33.integer();
81717
81799
  default:
81718
- return decode32.buffer();
81800
+ return decode33.buffer();
81719
81801
  }
81720
81802
  };
81721
- decode32.find = function(chr) {
81722
- let i4 = decode32.position;
81723
- const c2 = decode32.data.length;
81724
- const d2 = decode32.data;
81803
+ decode33.find = function(chr) {
81804
+ let i4 = decode33.position;
81805
+ const c2 = decode33.data.length;
81806
+ const d2 = decode33.data;
81725
81807
  while (i4 < c2) {
81726
81808
  if (d2[i4] === chr) return i4;
81727
81809
  i4++;
@@ -81730,41 +81812,41 @@ var BTCR2 = (() => {
81730
81812
  'Invalid data: Missing delimiter "' + String.fromCharCode(chr) + '" [0x' + chr.toString(16) + "]"
81731
81813
  );
81732
81814
  };
81733
- decode32.dictionary = function() {
81734
- decode32.position++;
81815
+ decode33.dictionary = function() {
81816
+ decode33.position++;
81735
81817
  const dict = {};
81736
- while (decode32.data[decode32.position] !== END_OF_TYPE) {
81737
- const buffer2 = decode32.buffer();
81818
+ while (decode33.data[decode33.position] !== END_OF_TYPE) {
81819
+ const buffer2 = decode33.buffer();
81738
81820
  let key = arr2text(buffer2);
81739
81821
  if (key.includes("\uFFFD")) key = arr2hex(buffer2);
81740
- dict[key] = decode32.next();
81822
+ dict[key] = decode33.next();
81741
81823
  }
81742
- decode32.position++;
81824
+ decode33.position++;
81743
81825
  return dict;
81744
81826
  };
81745
- decode32.list = function() {
81746
- decode32.position++;
81827
+ decode33.list = function() {
81828
+ decode33.position++;
81747
81829
  const lst = [];
81748
- while (decode32.data[decode32.position] !== END_OF_TYPE) {
81749
- lst.push(decode32.next());
81830
+ while (decode33.data[decode33.position] !== END_OF_TYPE) {
81831
+ lst.push(decode33.next());
81750
81832
  }
81751
- decode32.position++;
81833
+ decode33.position++;
81752
81834
  return lst;
81753
81835
  };
81754
- decode32.integer = function() {
81755
- const end = decode32.find(END_OF_TYPE);
81756
- const number7 = getIntFromBuffer(decode32.data, decode32.position + 1, end);
81757
- decode32.position += end + 1 - decode32.position;
81836
+ decode33.integer = function() {
81837
+ const end = decode33.find(END_OF_TYPE);
81838
+ const number7 = getIntFromBuffer(decode33.data, decode33.position + 1, end);
81839
+ decode33.position += end + 1 - decode33.position;
81758
81840
  return number7;
81759
81841
  };
81760
- decode32.buffer = function() {
81761
- let sep = decode32.find(STRING_DELIM);
81762
- const length7 = getIntFromBuffer(decode32.data, decode32.position, sep);
81842
+ decode33.buffer = function() {
81843
+ let sep = decode33.find(STRING_DELIM);
81844
+ const length7 = getIntFromBuffer(decode33.data, decode33.position, sep);
81763
81845
  const end = ++sep + length7;
81764
- decode32.position = end;
81765
- return decode32.encoding ? arr2text(decode32.data.slice(sep, end)) : decode32.data.slice(sep, end);
81846
+ decode33.position = end;
81847
+ return decode33.encoding ? arr2text(decode33.data.slice(sep, end)) : decode33.data.slice(sep, end);
81766
81848
  };
81767
- var decode_default = decode32;
81849
+ var decode_default = decode33;
81768
81850
 
81769
81851
  // ../../node_modules/.pnpm/bencode@4.0.0/node_modules/bencode/lib/encoding-length.js
81770
81852
  init_shim();
@@ -81981,7 +82063,7 @@ var BTCR2 = (() => {
81981
82063
  function familyOf(string4) {
81982
82064
  return sizeOf(string4) === v4.size ? 1 : 2;
81983
82065
  }
81984
- function encode30(ip, buff, offset) {
82066
+ function encode31(ip, buff, offset) {
81985
82067
  offset = ~~offset;
81986
82068
  const size = sizeOf(ip);
81987
82069
  if (typeof buff === "function") {
@@ -81992,7 +82074,7 @@ var BTCR2 = (() => {
81992
82074
  }
81993
82075
  return v6.encode(ip, buff, offset);
81994
82076
  }
81995
- function decode33(buff, offset, length7) {
82077
+ function decode34(buff, offset, length7) {
81996
82078
  offset = ~~offset;
81997
82079
  length7 = length7 || buff.length - offset;
81998
82080
  if (length7 === v4.size) {
@@ -82434,7 +82516,7 @@ var BTCR2 = (() => {
82434
82516
  }
82435
82517
  return len;
82436
82518
  }
82437
- function encode31(str, buf2, offset) {
82519
+ function encode32(str, buf2, offset) {
82438
82520
  const strLen = str.length;
82439
82521
  if (offset === void 0 || offset === null) {
82440
82522
  offset = 0;
@@ -82477,11 +82559,11 @@ var BTCR2 = (() => {
82477
82559
  }
82478
82560
  }
82479
82561
  }
82480
- encode31.bytes = off - offset;
82562
+ encode32.bytes = off - offset;
82481
82563
  return buf2;
82482
82564
  }
82483
- encode31.bytes = 0;
82484
- function decode34(buf2, start2, end) {
82565
+ encode32.bytes = 0;
82566
+ function decode35(buf2, start2, end) {
82485
82567
  let result = "";
82486
82568
  if (start2 === void 0 || start2 === null) {
82487
82569
  start2 = 0;
@@ -82506,10 +82588,10 @@ var BTCR2 = (() => {
82506
82588
  }
82507
82589
  result += String.fromCharCode(num3);
82508
82590
  }
82509
- decode34.bytes = end - start2;
82591
+ decode35.bytes = end - start2;
82510
82592
  return result;
82511
82593
  }
82512
- decode34.bytes = 0;
82594
+ decode35.bytes = 0;
82513
82595
 
82514
82596
  // ../../node_modules/.pnpm/@dnsquery+dns-packet@6.1.1/node_modules/@dnsquery/dns-packet/buffer_utils.mjs
82515
82597
  var isU8Arr = (input) => input instanceof Uint8Array;
@@ -82523,14 +82605,14 @@ var BTCR2 = (() => {
82523
82605
  if (Array.isArray(input)) {
82524
82606
  return new Uint8Array(input);
82525
82607
  }
82526
- return encode31(input);
82608
+ return encode32(input);
82527
82609
  }
82528
82610
  function write(arr, str, start2) {
82529
82611
  if (typeof str !== "string") {
82530
82612
  throw new Error("unknown input type");
82531
82613
  }
82532
- encode31(str, arr, start2);
82533
- return encode31.bytes;
82614
+ encode32(str, arr, start2);
82615
+ return encode32.bytes;
82534
82616
  }
82535
82617
  var hexNum = {};
82536
82618
  var numHex = new Array(255);
@@ -82631,12 +82713,12 @@ var BTCR2 = (() => {
82631
82713
  var NOT_FLUSH_MASK = ~FLUSH_MASK;
82632
82714
  var QU_MASK = 1 << 15;
82633
82715
  var NOT_QU_MASK = ~QU_MASK;
82634
- function codec({ bytes: bytes6 = 0, encode: encode43, decode: decode47, encodingLength: encodingLength11 }) {
82635
- encode43.bytes = bytes6;
82636
- decode47.bytes = bytes6;
82716
+ function codec({ bytes: bytes6 = 0, encode: encode44, decode: decode48, encodingLength: encodingLength11 }) {
82717
+ encode44.bytes = bytes6;
82718
+ decode48.bytes = bytes6;
82637
82719
  return {
82638
- encode: encode43,
82639
- decode: decode47,
82720
+ encode: encode44,
82721
+ decode: decode48,
82640
82722
  encodingLength: encodingLength11 || (() => bytes6)
82641
82723
  };
82642
82724
  }
@@ -82681,7 +82763,7 @@ var BTCR2 = (() => {
82681
82763
  if (totalLength > 254) {
82682
82764
  throw new Error("Cannot decode name (name too long)");
82683
82765
  }
82684
- list.push(decode34(buf2, offset, offset + len));
82766
+ list.push(decode35(buf2, offset, offset + len));
82685
82767
  offset += len;
82686
82768
  consumedBytes += jumped ? 0 : len;
82687
82769
  } else if ((len & 192) === 192) {
@@ -82720,7 +82802,7 @@ var BTCR2 = (() => {
82720
82802
  decode(buf2, offset) {
82721
82803
  if (!offset) offset = 0;
82722
82804
  const len = buf2[offset];
82723
- const s2 = decode34(buf2, offset + 1, offset + 1 + len);
82805
+ const s2 = decode35(buf2, offset + 1, offset + 1 + len);
82724
82806
  string3.decode.bytes = len + 1;
82725
82807
  return s2;
82726
82808
  },
@@ -83054,7 +83136,7 @@ var BTCR2 = (() => {
83054
83136
  offset += 1;
83055
83137
  data.tag = string3.decode(buf2, offset);
83056
83138
  offset += string3.decode.bytes;
83057
- data.value = decode34(buf2, offset, oldOffset + len);
83139
+ data.value = decode35(buf2, offset, oldOffset + len);
83058
83140
  data.issuerCritical = !!(data.flags & rcaa.ISSUER_CRITICAL);
83059
83141
  rcaa.decode.bytes = len + 2;
83060
83142
  return data;
@@ -83152,7 +83234,7 @@ var BTCR2 = (() => {
83152
83234
  {
83153
83235
  const spl = option.sourcePrefixLength || 0;
83154
83236
  const fam = option.family || familyOf(option.ip, alloc2);
83155
- const ipBuf = encode30(option.ip, alloc2);
83237
+ const ipBuf = encode31(option.ip, alloc2);
83156
83238
  const ipLen = Math.ceil(spl / 8);
83157
83239
  writeUInt16BE(buf2, ipLen + 4, offset);
83158
83240
  offset += 2;
@@ -83224,7 +83306,7 @@ var BTCR2 = (() => {
83224
83306
  {
83225
83307
  const padded = new Uint8Array(option.family === 1 ? 4 : 16);
83226
83308
  copy(buf2, padded, 0, offset, offset + len - 4);
83227
- option.ip = decode33(padded);
83309
+ option.ip = decode34(padded);
83228
83310
  }
83229
83311
  break;
83230
83312
  // case 12: Padding. No decode makes sense.
@@ -83850,8 +83932,8 @@ var BTCR2 = (() => {
83850
83932
  offset = encodeList(result.authorities, answer, buf2, offset);
83851
83933
  offset = encodeList(result.additionals, answer, buf2, offset);
83852
83934
  packet.encode.bytes = offset - oldOffset;
83853
- if (allocing && encode32.bytes !== buf2.length) {
83854
- return buf2.slice(0, encode32.bytes);
83935
+ if (allocing && encode33.bytes !== buf2.length) {
83936
+ return buf2.slice(0, encode33.bytes);
83855
83937
  }
83856
83938
  return buf2;
83857
83939
  },
@@ -83928,11 +84010,11 @@ var BTCR2 = (() => {
83928
84010
  };
83929
84011
  response.encode.bytes = 0;
83930
84012
  response.decode.bytes = 0;
83931
- var encode32 = packet.encode;
83932
- var decode35 = packet.decode;
84013
+ var encode33 = packet.encode;
84014
+ var decode36 = packet.decode;
83933
84015
  var encodingLength8 = packet.encodingLength;
83934
84016
  function streamEncode(result) {
83935
- const buf2 = encode32(result);
84017
+ const buf2 = encode33(result);
83936
84018
  const combine3 = new Uint8Array(2 + buf2.byteLength);
83937
84019
  writeUInt16BE(combine3, buf2.byteLength);
83938
84020
  copy(buf2, combine3, 2, 0, buf2.length);
@@ -83945,8 +84027,8 @@ var BTCR2 = (() => {
83945
84027
  if (sbuf.byteLength < len + 2) {
83946
84028
  return null;
83947
84029
  }
83948
- const result = decode35(sbuf.slice(2));
83949
- streamDecode.bytes = decode35.bytes;
84030
+ const result = decode36(sbuf.slice(2));
84031
+ streamDecode.bytes = decode36.bytes;
83950
84032
  return result;
83951
84033
  }
83952
84034
  streamDecode.bytes = 0;
@@ -84745,7 +84827,7 @@ var BTCR2 = (() => {
84745
84827
  static createBep44PutMessage(_a3) {
84746
84828
  return __awaiter15(this, arguments, void 0, function* ({ dnsPacket, publicKeyBytes, signer }) {
84747
84829
  const sequenceNumber = Math.ceil(Date.now() / 1e3);
84748
- const encodedDnsPacket = encode32(dnsPacket);
84830
+ const encodedDnsPacket = encode33(dnsPacket);
84749
84831
  const bencodedData = bencode_default.encode({ seq: sequenceNumber, v: encodedDnsPacket }).subarray(1, -1);
84750
84832
  if (bencodedData.length > 1e3) {
84751
84833
  throw new DidError(DidErrorCode.InvalidDidDocumentLength, `DNS packet exceeds the 1000 byte maximum size: ${bencodedData.length} bytes`);
@@ -84870,7 +84952,7 @@ var BTCR2 = (() => {
84870
84952
  if (!isValid2) {
84871
84953
  throw new DidError(DidErrorCode.InvalidSignature, `Invalid signature for DHT BEP44 message`);
84872
84954
  }
84873
- return decode35(bep44Message.v);
84955
+ return decode36(bep44Message.v);
84874
84956
  });
84875
84957
  }
84876
84958
  /**
@@ -85144,8 +85226,8 @@ var BTCR2 = (() => {
85144
85226
  return this.decoder.decode(input);
85145
85227
  }
85146
85228
  };
85147
- var from5 = ({ name: name10, prefix, encode: encode43, decode: decode47 }) => new Codec3(name10, prefix, encode43, decode47);
85148
- var decode36 = (string4, alphabet6, bitsPerChar, name10) => {
85229
+ var from5 = ({ name: name10, prefix, encode: encode44, decode: decode48 }) => new Codec3(name10, prefix, encode44, decode48);
85230
+ var decode37 = (string4, alphabet6, bitsPerChar, name10) => {
85149
85231
  const codes = {};
85150
85232
  for (let i4 = 0; i4 < alphabet6.length; ++i4) {
85151
85233
  codes[alphabet6[i4]] = i4;
@@ -85175,7 +85257,7 @@ var BTCR2 = (() => {
85175
85257
  }
85176
85258
  return out;
85177
85259
  };
85178
- var encode33 = (data, alphabet6, bitsPerChar) => {
85260
+ var encode34 = (data, alphabet6, bitsPerChar) => {
85179
85261
  const pad2 = alphabet6[alphabet6.length - 1] === "=";
85180
85262
  const mask = (1 << bitsPerChar) - 1;
85181
85263
  let out = "";
@@ -85204,10 +85286,10 @@ var BTCR2 = (() => {
85204
85286
  prefix,
85205
85287
  name: name10,
85206
85288
  encode(input) {
85207
- return encode33(input, alphabet6, bitsPerChar);
85289
+ return encode34(input, alphabet6, bitsPerChar);
85208
85290
  },
85209
85291
  decode(input) {
85210
- return decode36(input, alphabet6, bitsPerChar, name10);
85292
+ return decode37(input, alphabet6, bitsPerChar, name10);
85211
85293
  }
85212
85294
  });
85213
85295
  };
@@ -85409,12 +85491,12 @@ var BTCR2 = (() => {
85409
85491
 
85410
85492
  // ../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/vendor/varint.js
85411
85493
  init_shim();
85412
- var encode_13 = encode34;
85494
+ var encode_13 = encode35;
85413
85495
  var MSB3 = 128;
85414
85496
  var REST3 = 127;
85415
85497
  var MSBALL3 = ~REST3;
85416
85498
  var INT3 = Math.pow(2, 31);
85417
- function encode34(num3, out, offset) {
85499
+ function encode35(num3, out, offset) {
85418
85500
  out = out || [];
85419
85501
  offset = offset || 0;
85420
85502
  var oldOffset = offset;
@@ -85427,10 +85509,10 @@ var BTCR2 = (() => {
85427
85509
  num3 >>>= 7;
85428
85510
  }
85429
85511
  out[offset] = num3 | 0;
85430
- encode34.bytes = offset - oldOffset + 1;
85512
+ encode35.bytes = offset - oldOffset + 1;
85431
85513
  return out;
85432
85514
  }
85433
- var decode37 = read3;
85515
+ var decode38 = read3;
85434
85516
  var MSB$13 = 128;
85435
85517
  var REST$13 = 127;
85436
85518
  function read3(buf2, offset) {
@@ -85461,14 +85543,14 @@ var BTCR2 = (() => {
85461
85543
  };
85462
85544
  var varint3 = {
85463
85545
  encode: encode_13,
85464
- decode: decode37,
85546
+ decode: decode38,
85465
85547
  encodingLength: length4
85466
85548
  };
85467
85549
  var _brrp_varint3 = varint3;
85468
85550
  var varint_default3 = _brrp_varint3;
85469
85551
 
85470
85552
  // ../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/varint.js
85471
- var decode38 = (data, offset = 0) => {
85553
+ var decode39 = (data, offset = 0) => {
85472
85554
  const code8 = varint_default3.decode(data, offset);
85473
85555
  return [code8, varint_default3.decode.bytes];
85474
85556
  };
@@ -85491,10 +85573,10 @@ var BTCR2 = (() => {
85491
85573
  bytes6.set(digest2, digestOffset);
85492
85574
  return new Digest3(code8, size, digest2, bytes6);
85493
85575
  };
85494
- var decode39 = (multihash) => {
85576
+ var decode40 = (multihash) => {
85495
85577
  const bytes6 = coerce3(multihash);
85496
- const [code8, sizeOffset] = decode38(bytes6);
85497
- const [size, digestOffset] = decode38(bytes6.subarray(sizeOffset));
85578
+ const [code8, sizeOffset] = decode39(bytes6);
85579
+ const [size, digestOffset] = decode39(bytes6.subarray(sizeOffset));
85498
85580
  const digest2 = bytes6.subarray(sizeOffset + digestOffset);
85499
85581
  if (digest2.byteLength !== size) {
85500
85582
  throw new Error("Incorrect length");
@@ -85523,7 +85605,7 @@ var BTCR2 = (() => {
85523
85605
 
85524
85606
  // ../../node_modules/.pnpm/multiformats@12.1.3/node_modules/multiformats/src/hashes/hasher.js
85525
85607
  init_shim();
85526
- var from6 = ({ name: name10, code: code8, encode: encode43 }) => new Hasher2(name10, code8, encode43);
85608
+ var from6 = ({ name: name10, code: code8, encode: encode44 }) => new Hasher2(name10, code8, encode44);
85527
85609
  var Hasher2 = class {
85528
85610
  /**
85529
85611
  *
@@ -85531,10 +85613,10 @@ var BTCR2 = (() => {
85531
85613
  * @param {Code} code
85532
85614
  * @param {(input: Uint8Array) => Await<Uint8Array>} encode
85533
85615
  */
85534
- constructor(name10, code8, encode43) {
85616
+ constructor(name10, code8, encode44) {
85535
85617
  this.name = name10;
85536
85618
  this.code = code8;
85537
- this.encode = encode43;
85619
+ this.encode = encode44;
85538
85620
  }
85539
85621
  /**
85540
85622
  * @param {Uint8Array} input
@@ -85675,7 +85757,7 @@ var BTCR2 = (() => {
85675
85757
  let multihash;
85676
85758
  const multihashBytes = Encoder4.decodeAsBytes(encodedMultihash, inputContextForErrorLogging);
85677
85759
  try {
85678
- multihash = decode39(multihashBytes);
85760
+ multihash = decode40(multihashBytes);
85679
85761
  } catch (_a3) {
85680
85762
  throw new IonError(ErrorCode_default.MultihashStringNotAMultihash, `Given ${inputContextForErrorLogging} string '${encodedMultihash}' is not a multihash after decoding.`);
85681
85763
  }
@@ -91236,7 +91318,7 @@ var BTCR2 = (() => {
91236
91318
  tokensToEncoded(buf, tokens, encoders, options2);
91237
91319
  return buf.toBytes(true);
91238
91320
  }
91239
- function encode35(data, options2) {
91321
+ function encode36(data, options2) {
91240
91322
  options2 = Object.assign({}, defaultEncodeOptions, options2);
91241
91323
  return encodeCustom(data, cborEncoders, options2);
91242
91324
  }
@@ -91375,7 +91457,7 @@ var BTCR2 = (() => {
91375
91457
  }
91376
91458
  return [decoded, data.subarray(tokeniser.pos())];
91377
91459
  }
91378
- function decode40(data, options2) {
91460
+ function decode41(data, options2) {
91379
91461
  const [decoded, remainder] = decodeFirst(data, options2);
91380
91462
  if (remainder.length > 0) {
91381
91463
  throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`);
@@ -91931,7 +92013,7 @@ var BTCR2 = (() => {
91931
92013
  depth,
91932
92014
  metadata: options2.metadata ?? {}
91933
92015
  };
91934
- await this.datastore.put(pinKey, encode35(pin), options2);
92016
+ await this.datastore.put(pinKey, encode36(pin), options2);
91935
92017
  }
91936
92018
  /**
91937
92019
  * Walk a DAG in an iterable fashion
@@ -91963,7 +92045,7 @@ var BTCR2 = (() => {
91963
92045
  pinnedBy: []
91964
92046
  };
91965
92047
  try {
91966
- pinnedBlock = decode40(await this.datastore.get(blockKey, options2));
92048
+ pinnedBlock = decode41(await this.datastore.get(blockKey, options2));
91967
92049
  } catch (err) {
91968
92050
  if (err.name !== "NotFoundError") {
91969
92051
  throw err;
@@ -91979,13 +92061,13 @@ var BTCR2 = (() => {
91979
92061
  return;
91980
92062
  }
91981
92063
  }
91982
- await this.datastore.put(blockKey, encode35(pinnedBlock), options2);
92064
+ await this.datastore.put(blockKey, encode36(pinnedBlock), options2);
91983
92065
  options2.onProgress?.(new CustomProgressEvent("helia:pin:add", cid));
91984
92066
  }
91985
92067
  async *rm(cid, options2 = {}) {
91986
92068
  const pinKey = toDSKey(cid);
91987
92069
  const buf2 = await this.datastore.get(pinKey, options2);
91988
- const pin = decode40(buf2);
92070
+ const pin = decode41(buf2);
91989
92071
  await this.datastore.delete(pinKey, options2);
91990
92072
  const queue = new Queue3({
91991
92073
  concurrency: DAG_WALK_QUEUE_CONCURRENCY
@@ -92010,7 +92092,7 @@ var BTCR2 = (() => {
92010
92092
  prefix: DATASTORE_PIN_PREFIX + (options2.cid != null ? `${options2.cid.toString(base36)}` : "")
92011
92093
  }, options2)) {
92012
92094
  const cid = CID.parse(key.toString().substring(5), base36);
92013
- const pin = decode40(value3);
92095
+ const pin = decode41(value3);
92014
92096
  yield {
92015
92097
  cid,
92016
92098
  ...pin
@@ -92024,14 +92106,14 @@ var BTCR2 = (() => {
92024
92106
  async get(cid, options2) {
92025
92107
  const pinKey = toDSKey(cid);
92026
92108
  const buf2 = await this.datastore.get(pinKey, options2);
92027
- return decode40(buf2);
92109
+ return decode41(buf2);
92028
92110
  }
92029
92111
  async setMetadata(cid, metadata, options2) {
92030
92112
  const pinKey = toDSKey(cid);
92031
92113
  const buf2 = await this.datastore.get(pinKey, options2);
92032
- const pin = decode40(buf2);
92114
+ const pin = decode41(buf2);
92033
92115
  pin.metadata = metadata ?? {};
92034
- await this.datastore.put(pinKey, encode35(pin), options2);
92116
+ await this.datastore.put(pinKey, encode36(pin), options2);
92035
92117
  }
92036
92118
  };
92037
92119
 
@@ -93302,9 +93384,9 @@ var BTCR2 = (() => {
93302
93384
  var src_exports = {};
93303
93385
  __export(src_exports, {
93304
93386
  code: () => code4,
93305
- decode: () => decode41,
93387
+ decode: () => decode42,
93306
93388
  decodeOptions: () => decodeOptions,
93307
- encode: () => encode36,
93389
+ encode: () => encode37,
93308
93390
  encodeOptions: () => encodeOptions,
93309
93391
  name: () => name5,
93310
93392
  toByteView: () => toByteView
@@ -93394,15 +93476,15 @@ var BTCR2 = (() => {
93394
93476
  };
93395
93477
  var name5 = "dag-cbor";
93396
93478
  var code4 = 113;
93397
- var encode36 = (node) => encode35(node, _encodeOptions);
93398
- var decode41 = (data) => decode40(toByteView(data), _decodeOptions);
93479
+ var encode37 = (node) => encode36(node, _encodeOptions);
93480
+ var decode42 = (data) => decode41(toByteView(data), _decodeOptions);
93399
93481
 
93400
93482
  // ../../node_modules/.pnpm/@ipld+dag-json@10.2.5/node_modules/@ipld/dag-json/src/index.js
93401
93483
  var src_exports2 = {};
93402
93484
  __export(src_exports2, {
93403
93485
  code: () => code5,
93404
- decode: () => decode43,
93405
- encode: () => encode38,
93486
+ decode: () => decode44,
93487
+ encode: () => encode39,
93406
93488
  format: () => format3,
93407
93489
  name: () => name6,
93408
93490
  parse: () => parse5,
@@ -93571,7 +93653,7 @@ var BTCR2 = (() => {
93571
93653
  throw new Error(`${encodeErrPrefix} unexpected duplicate map keys, this is not supported`);
93572
93654
  }
93573
93655
  var defaultEncodeOptions2 = { addBreakTokens: true, mapSorter: mapSorter2 };
93574
- function encode37(data, options2) {
93656
+ function encode38(data, options2) {
93575
93657
  options2 = Object.assign({}, defaultEncodeOptions2, options2);
93576
93658
  return encodeCustom(data, new JSONEncoder(), options2);
93577
93659
  }
@@ -93972,9 +94054,9 @@ var BTCR2 = (() => {
93972
94054
  }
93973
94055
  }
93974
94056
  };
93975
- function decode42(data, options2) {
94057
+ function decode43(data, options2) {
93976
94058
  options2 = Object.assign({ tokenizer: new Tokenizer(data, options2) }, options2);
93977
- return decode40(data, options2);
94059
+ return decode41(data, options2);
93978
94060
  }
93979
94061
 
93980
94062
  // ../../node_modules/.pnpm/@ipld+dag-json@10.2.5/node_modules/@ipld/dag-json/src/index.js
@@ -94142,15 +94224,15 @@ var BTCR2 = (() => {
94142
94224
  decodeOptions2.tags[42] = CID.parse;
94143
94225
  var name6 = "dag-json";
94144
94226
  var code5 = 297;
94145
- var encode38 = (node) => encode37(node, encodeOptions2);
94146
- var decode43 = (data) => {
94227
+ var encode39 = (node) => encode38(node, encodeOptions2);
94228
+ var decode44 = (data) => {
94147
94229
  const buf2 = toByteView2(data);
94148
94230
  const options2 = Object.assign(decodeOptions2, { tokenizer: new DagJsonTokenizer(buf2, decodeOptions2) });
94149
- return decode42(buf2, options2);
94231
+ return decode43(buf2, options2);
94150
94232
  };
94151
- var format3 = (node) => utf8Decoder3.decode(encode38(node));
94233
+ var format3 = (node) => utf8Decoder3.decode(encode39(node));
94152
94234
  var utf8Decoder3 = new TextDecoder();
94153
- var parse5 = (data) => decode43(utf8Encoder3.encode(data));
94235
+ var parse5 = (data) => decode44(utf8Encoder3.encode(data));
94154
94236
  var utf8Encoder3 = new TextEncoder();
94155
94237
 
94156
94238
  // ../../node_modules/.pnpm/@ipld+dag-pb@4.1.5/node_modules/@ipld/dag-pb/src/index.js
@@ -94159,8 +94241,8 @@ var BTCR2 = (() => {
94159
94241
  code: () => code6,
94160
94242
  createLink: () => createLink,
94161
94243
  createNode: () => createNode,
94162
- decode: () => decode44,
94163
- encode: () => encode39,
94244
+ decode: () => decode45,
94245
+ encode: () => encode40,
94164
94246
  name: () => name7,
94165
94247
  prepare: () => prepare,
94166
94248
  validate: () => validate3
@@ -94828,7 +94910,7 @@ var BTCR2 = (() => {
94828
94910
  // ../../node_modules/.pnpm/@ipld+dag-pb@4.1.5/node_modules/@ipld/dag-pb/src/index.js
94829
94911
  var name7 = "dag-pb";
94830
94912
  var code6 = 112;
94831
- function encode39(node) {
94913
+ function encode40(node) {
94832
94914
  validate3(node);
94833
94915
  const pbn = {};
94834
94916
  if (node.Links) {
@@ -94851,7 +94933,7 @@ var BTCR2 = (() => {
94851
94933
  }
94852
94934
  return encodeNode(pbn);
94853
94935
  }
94854
- function decode44(bytes6) {
94936
+ function decode45(bytes6) {
94855
94937
  const buf2 = toByteView3(bytes6);
94856
94938
  const pbn = decodeNode(buf2);
94857
94939
  const node = {};
@@ -97840,7 +97922,7 @@ var BTCR2 = (() => {
97840
97922
  }
97841
97923
  throw new RangeError("Could not decode varint");
97842
97924
  }
97843
- function encode40(value3, buf2, offset = 0) {
97925
+ function encode41(value3, buf2, offset = 0) {
97844
97926
  if (buf2 == null) {
97845
97927
  buf2 = allocUnsafe(encodingLength10(value3));
97846
97928
  }
@@ -97850,7 +97932,7 @@ var BTCR2 = (() => {
97850
97932
  return encodeUint8ArrayList(value3, buf2, offset);
97851
97933
  }
97852
97934
  }
97853
- function decode45(buf2, offset = 0) {
97935
+ function decode46(buf2, offset = 0) {
97854
97936
  if (buf2 instanceof Uint8Array) {
97855
97937
  return decodeUint8Array(buf2, offset);
97856
97938
  } else {
@@ -98912,12 +98994,12 @@ var BTCR2 = (() => {
98912
98994
  CODEC_TYPES2[CODEC_TYPES2["END_GROUP"] = 4] = "END_GROUP";
98913
98995
  CODEC_TYPES2[CODEC_TYPES2["BIT32"] = 5] = "BIT32";
98914
98996
  })(CODEC_TYPES || (CODEC_TYPES = {}));
98915
- function createCodec2(name10, type, encode43, decode47) {
98997
+ function createCodec2(name10, type, encode44, decode48) {
98916
98998
  return {
98917
98999
  name: name10,
98918
99000
  type,
98919
- encode: encode43,
98920
- decode: decode47
99001
+ encode: encode44,
99002
+ decode: decode48
98921
99003
  };
98922
99004
  }
98923
99005
 
@@ -98929,21 +99011,21 @@ var BTCR2 = (() => {
98929
99011
  }
98930
99012
  return v[val];
98931
99013
  }
98932
- const encode43 = function enumEncode(val, writer) {
99014
+ const encode44 = function enumEncode(val, writer) {
98933
99015
  const enumValue = findValue(val);
98934
99016
  writer.int32(enumValue);
98935
99017
  };
98936
- const decode47 = function enumDecode(reader) {
99018
+ const decode48 = function enumDecode(reader) {
98937
99019
  const val = reader.int32();
98938
99020
  return findValue(val);
98939
99021
  };
98940
- return createCodec2("enum", CODEC_TYPES.VARINT, encode43, decode47);
99022
+ return createCodec2("enum", CODEC_TYPES.VARINT, encode44, decode48);
98941
99023
  }
98942
99024
 
98943
99025
  // ../../node_modules/.pnpm/protons-runtime@5.6.0/node_modules/protons-runtime/dist/src/codecs/message.js
98944
99026
  init_shim();
98945
- function message(encode43, decode47) {
98946
- return createCodec2("message", CODEC_TYPES.LENGTH_DELIMITED, encode43, decode47);
99027
+ function message(encode44, decode48) {
99028
+ return createCodec2("message", CODEC_TYPES.LENGTH_DELIMITED, encode44, decode48);
98947
99029
  }
98948
99030
 
98949
99031
  // ../../node_modules/.pnpm/protons-runtime@5.6.0/node_modules/protons-runtime/dist/src/index.js
@@ -100445,12 +100527,12 @@ var BTCR2 = (() => {
100445
100527
  var defaultEncoder = (length7) => {
100446
100528
  const lengthLength = encodingLength10(length7);
100447
100529
  const lengthBuf = allocUnsafe(lengthLength);
100448
- encode40(length7, lengthBuf);
100530
+ encode41(length7, lengthBuf);
100449
100531
  defaultEncoder.bytes = lengthLength;
100450
100532
  return lengthBuf;
100451
100533
  };
100452
100534
  defaultEncoder.bytes = 0;
100453
- function encode41(source, options2) {
100535
+ function encode42(source, options2) {
100454
100536
  options2 = options2 ?? {};
100455
100537
  const encodeLength2 = options2.lengthEncoder ?? defaultEncoder;
100456
100538
  const maxDataLength = options2?.maxDataLength ?? MAX_DATA_LENGTH;
@@ -100481,7 +100563,7 @@ var BTCR2 = (() => {
100481
100563
  }
100482
100564
  }();
100483
100565
  }
100484
- encode41.single = (chunk, options2) => {
100566
+ encode42.single = (chunk, options2) => {
100485
100567
  options2 = options2 ?? {};
100486
100568
  const encodeLength2 = options2.lengthEncoder ?? defaultEncoder;
100487
100569
  const maxDataLength = options2?.maxDataLength ?? MAX_DATA_LENGTH;
@@ -100497,12 +100579,12 @@ var BTCR2 = (() => {
100497
100579
  ReadMode2[ReadMode2["DATA"] = 1] = "DATA";
100498
100580
  })(ReadMode || (ReadMode = {}));
100499
100581
  var defaultDecoder = (buf2) => {
100500
- const length7 = decode45(buf2);
100582
+ const length7 = decode46(buf2);
100501
100583
  defaultDecoder.bytes = encodingLength10(length7);
100502
100584
  return length7;
100503
100585
  };
100504
100586
  defaultDecoder.bytes = 0;
100505
- function decode46(source, options2) {
100587
+ function decode47(source, options2) {
100506
100588
  const buffer2 = new Uint8ArrayList();
100507
100589
  let mode = ReadMode.LENGTH;
100508
100590
  let dataLength = -1;
@@ -100571,7 +100653,7 @@ var BTCR2 = (() => {
100571
100653
  }
100572
100654
  }();
100573
100655
  }
100574
- decode46.fromReader = (reader, options2) => {
100656
+ decode47.fromReader = (reader, options2) => {
100575
100657
  let byteLength = 1;
100576
100658
  const varByteSource = async function* () {
100577
100659
  while (true) {
@@ -100596,7 +100678,7 @@ var BTCR2 = (() => {
100596
100678
  const onLength = (l2) => {
100597
100679
  byteLength = l2;
100598
100680
  };
100599
- return decode46(varByteSource, {
100681
+ return decode47(varByteSource, {
100600
100682
  ...options2 ?? {},
100601
100683
  onLength
100602
100684
  });
@@ -101369,7 +101451,7 @@ var BTCR2 = (() => {
101369
101451
  setMaxListeners(Infinity, signal);
101370
101452
  signal.addEventListener("abort", abortListener);
101371
101453
  await stream.closeWrite();
101372
- await pipe2(stream, (source) => decode46(source, {
101454
+ await pipe2(stream, (source) => decode47(source, {
101373
101455
  maxDataLength: this.maxIncomingMessageSize
101374
101456
  }), async (source) => {
101375
101457
  for await (const data of source) {
@@ -101454,7 +101536,7 @@ var BTCR2 = (() => {
101454
101536
  const stream = await this.libp2p.dialProtocol(peerId, BITSWAP_120, options3);
101455
101537
  await stream.closeRead();
101456
101538
  try {
101457
- await pipe2(splitMessage(message3, this.maxOutgoingMessageSize), (source) => encode41(source), stream);
101539
+ await pipe2(splitMessage(message3, this.maxOutgoingMessageSize), (source) => encode42(source), stream);
101458
101540
  await stream.close(options3);
101459
101541
  } catch (err) {
101460
101542
  options3?.onProgress?.(new CustomProgressEvent("bitswap:network:send-wantlist:error", { peer: peerId, error: err }));
@@ -101655,14 +101737,14 @@ var BTCR2 = (() => {
101655
101737
  function peerIdFromString(str, decoder2) {
101656
101738
  let multihash;
101657
101739
  if (str.charAt(0) === "1" || str.charAt(0) === "Q") {
101658
- multihash = decode23(base58btc.decode(`z${str}`));
101740
+ multihash = decode24(base58btc.decode(`z${str}`));
101659
101741
  } else if (str.startsWith("k51qzi5uqu5") || str.startsWith("kzwfwjn5ji4") || str.startsWith("k2k4r8") || str.startsWith("bafz")) {
101660
101742
  return peerIdFromCID(CID.parse(str));
101661
101743
  } else {
101662
101744
  if (decoder2 == null) {
101663
101745
  throw new InvalidParametersError('Please pass a multibase decoder for strings that do not start with "1" or "Q"');
101664
101746
  }
101665
- multihash = decode23(decoder2.decode(str));
101747
+ multihash = decode24(decoder2.decode(str));
101666
101748
  }
101667
101749
  return peerIdFromMultihash(multihash);
101668
101750
  }
@@ -101748,7 +101830,7 @@ var BTCR2 = (() => {
101748
101830
  return iterator;
101749
101831
  }
101750
101832
  function peerIdFromString2(str) {
101751
- const multihash = decode23(base58btc.decode(`z${str}`));
101833
+ const multihash = decode24(base58btc.decode(`z${str}`));
101752
101834
  return peerIdFromMultihash(multihash);
101753
101835
  }
101754
101836
 
@@ -101987,7 +102069,7 @@ var BTCR2 = (() => {
101987
102069
  }, 0));
101988
102070
  let offset = 0;
101989
102071
  for (const num3 of buf2) {
101990
- out = encode40(num3, out, offset);
102072
+ out = encode41(num3, out, offset);
101991
102073
  offset += encodingLength10(num3);
101992
102074
  }
101993
102075
  return out;
@@ -102357,7 +102439,7 @@ var BTCR2 = (() => {
102357
102439
  }
102358
102440
  const result = [];
102359
102441
  while (buf2.length > 0) {
102360
- const num3 = decode45(buf2);
102442
+ const num3 = decode46(buf2);
102361
102443
  result.push(num3);
102362
102444
  buf2 = buf2.slice(encodingLength10(num3));
102363
102445
  }
@@ -103581,7 +103663,7 @@ var BTCR2 = (() => {
103581
103663
  const components = [];
103582
103664
  let i4 = 0;
103583
103665
  while (i4 < bytes6.length) {
103584
- const code8 = decode45(bytes6, i4);
103666
+ const code8 = decode46(bytes6, i4);
103585
103667
  const codec2 = registry.getProtocol(code8);
103586
103668
  const codeLength = encodingLength10(code8);
103587
103669
  const size = sizeForAddr(codec2, bytes6, i4 + codeLength);
@@ -103719,7 +103801,7 @@ var BTCR2 = (() => {
103719
103801
  if (codec2.size > 0) {
103720
103802
  return codec2.size / 8;
103721
103803
  }
103722
- return decode45(bytes6, offset);
103804
+ return decode46(bytes6, offset);
103723
103805
  }
103724
103806
 
103725
103807
  // ../../node_modules/.pnpm/@multiformats+multiaddr@12.5.1/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js
@@ -105345,14 +105427,14 @@ var BTCR2 = (() => {
105345
105427
  ]);
105346
105428
  }
105347
105429
  function multihashFromIPNSRoutingKey(key) {
105348
- const digest2 = decode23(key.slice(IPNS_PREFIX.length));
105430
+ const digest2 = decode24(key.slice(IPNS_PREFIX.length));
105349
105431
  if (!isCodec(digest2, IDENTITY_CODEC2) && !isCodec(digest2, SHA2_256_CODEC)) {
105350
105432
  throw new InvalidMultihashError("Multihash in IPNS key was not identity or sha2-256");
105351
105433
  }
105352
105434
  return digest2;
105353
105435
  }
105354
105436
  function parseCborData(buf2) {
105355
- const data = decode40(buf2);
105437
+ const data = decode41(buf2);
105356
105438
  if (data.ValidityType === 0) {
105357
105439
  data.ValidityType = IpnsEntry.ValidityType.EOL;
105358
105440
  } else {
@@ -106286,7 +106368,7 @@ var BTCR2 = (() => {
106286
106368
  options2?.signal?.throwIfAborted();
106287
106369
  for (const [key, value3] of this.data.entries()) {
106288
106370
  yield {
106289
- cid: CID.createV1(code, decode23(base322.decode(key))),
106371
+ cid: CID.createV1(code, decode24(base322.decode(key))),
106290
106372
  block: value3
106291
106373
  };
106292
106374
  options2?.signal?.throwIfAborted();
@@ -106924,9 +107006,9 @@ var BTCR2 = (() => {
106924
107006
  };
106925
107007
  var formatSignaturePayload = (domain, payloadType, payload) => {
106926
107008
  const domainUint8Array = fromString2(domain);
106927
- const domainLength = encode40(domainUint8Array.byteLength);
106928
- const payloadTypeLength = encode40(payloadType.length);
106929
- const payloadLength = encode40(payload.length);
107009
+ const domainLength = encode41(domainUint8Array.byteLength);
107010
+ const payloadTypeLength = encode41(payloadType.length);
107011
+ const payloadLength = encode41(payload.length);
106930
107012
  return new Uint8ArrayList(domainLength, domainUint8Array, payloadTypeLength, payloadType, payloadLength, payload);
106931
107013
  };
106932
107014
 
@@ -107076,7 +107158,7 @@ var BTCR2 = (() => {
107076
107158
  */
107077
107159
  static createFromProtobuf = (buf2) => {
107078
107160
  const peerRecord = PeerRecord.decode(buf2);
107079
- const peerId = peerIdFromMultihash(decode23(peerRecord.peerId));
107161
+ const peerId = peerIdFromMultihash(decode24(peerRecord.peerId));
107080
107162
  const multiaddrs = (peerRecord.addresses ?? []).map((a2) => multiaddr(a2.multiaddr));
107081
107163
  const seqNumber = peerRecord.seq;
107082
107164
  return new _PeerRecord({ peerId, multiaddrs, seqNumber });
@@ -112061,8 +112143,8 @@ ${[...listenStats.errors.entries()].map(([addr, err]) => {
112061
112143
  if (opts.maxDataLength != null && opts.maxLengthLength == null) {
112062
112144
  opts.maxLengthLength = encodingLength10(opts.maxDataLength);
112063
112145
  }
112064
- const decodeLength = opts?.lengthDecoder ?? decode45;
112065
- const encodeLength2 = opts?.lengthEncoder ?? encode40;
112146
+ const decodeLength = opts?.lengthDecoder ?? decode46;
112147
+ const encodeLength2 = opts?.lengthEncoder ?? encode41;
112066
112148
  const W = {
112067
112149
  read: async (options2) => {
112068
112150
  let dataLength = -1;
@@ -112215,7 +112297,7 @@ ${[...listenStats.errors.entries()].map(([addr, err]) => {
112215
112297
  // length of PROTOCOL_ID plus newline
112216
112298
  fromString2(`${PROTOCOL_ID}
112217
112299
  `),
112218
- encode40(protocolString.length),
112300
+ encode41(protocolString.length),
112219
112301
  fromString2(protocolString),
112220
112302
  buf2
112221
112303
  ).subarray();
@@ -112385,7 +112467,7 @@ ${[...listenStats.errors.entries()].map(([addr, err]) => {
112385
112467
  return { stream: lp.unwrap(), protocol };
112386
112468
  }
112387
112469
  if (protocol === "ls") {
112388
- const protos = new Uint8ArrayList(...protocols2.map((p2) => encode41.single(fromString2(`${p2}
112470
+ const protos = new Uint8ArrayList(...protocols2.map((p2) => encode42.single(fromString2(`${p2}
112389
112471
  `))), fromString2("\n"));
112390
112472
  options2.log.trace('handle: respond with "%s" for %s', protocols2, protocol);
112391
112473
  await write3(lp, protos, options2);
@@ -118942,7 +119024,7 @@ ${values.join("\n")}` : `${blockName} :`;
118942
119024
  // encrypt data + prefix with message length
118943
119025
  network,
118944
119026
  // send to the remote peer
118945
- (source) => decode46(source, { lengthDecoder: uint16BEDecode }),
119027
+ (source) => decode47(source, { lengthDecoder: uint16BEDecode }),
118946
119028
  // read message length prefix
118947
119029
  decryptStream(handshake, this.metrics),
118948
119030
  // decrypt the incoming data
@@ -120860,7 +120942,7 @@ ${values.join("\n")}` : `${blockName} :`;
120860
120942
  };
120861
120943
  }
120862
120944
  try {
120863
- const digest2 = decode23(peer.id);
120945
+ const digest2 = decode24(peer.id);
120864
120946
  peerId = peerIdFromMultihash(digest2);
120865
120947
  } catch (err) {
120866
120948
  this.log.error("invalid PeerId - %e", err);
@@ -123033,7 +123115,7 @@ ${values.join("\n")}` : `${blockName} :`;
123033
123115
  });
123034
123116
  return;
123035
123117
  }
123036
- const remotePeerId = peerIdFromMultihash(decode23(request.peer.id));
123118
+ const remotePeerId = peerIdFromMultihash(decode24(request.peer.id));
123037
123119
  if (await this.connectionGater.denyInboundRelayedConnection?.(connection.remotePeer, remotePeerId) === true) {
123038
123120
  this.log.error("connection gater denied inbound relayed connection from %p", connection.remotePeer);
123039
123121
  await pbstr.write({ type: StopMessage.Type.STATUS, status: Status.PERMISSION_DENIED }, {
@@ -124723,7 +124805,7 @@ ${values.join("\n")}` : `${blockName} :`;
124723
124805
  return toString2(key.subarray(0, 4)) === "/pk/";
124724
124806
  }
124725
124807
  function fromPublicKeyKey(key) {
124726
- const multihash = decode23(key.subarray(4));
124808
+ const multihash = decode24(key.subarray(4));
124727
124809
  return peerIdFromMultihash(multihash);
124728
124810
  }
124729
124811
  function createPutRecord(key, value3) {
@@ -124762,7 +124844,7 @@ ${values.join("\n")}` : `${blockName} :`;
124762
124844
  throw new Error(`incorrectly formatted provider entry key in datastore: ${key.toString()}`);
124763
124845
  }
124764
124846
  return {
124765
- cid: CID.createV1(code, decode23(fromString2(cidStr, "base32"))),
124847
+ cid: CID.createV1(code, decode24(fromString2(cidStr, "base32"))),
124766
124848
  peerId: peerIdFromString(peerIdStr)
124767
124849
  };
124768
124850
  }
@@ -124778,7 +124860,7 @@ ${values.join("\n")}` : `${blockName} :`;
124778
124860
  return new Key(parts.join("/"));
124779
124861
  }
124780
124862
  function readProviderTime(buf2) {
124781
- return new Date(decode45(buf2));
124863
+ return new Date(decode46(buf2));
124782
124864
  }
124783
124865
  function timeOperationGenerator(fn, operationMetrics, type) {
124784
124866
  return async function* (...args) {
@@ -125053,7 +125135,7 @@ ${values.join("\n")}` : `${blockName} :`;
125053
125135
  if (peer.id == null) {
125054
125136
  throw new Error("Invalid peer in message");
125055
125137
  }
125056
- const multihash = decode23(peer.id);
125138
+ const multihash = decode24(peer.id);
125057
125139
  return {
125058
125140
  id: peerIdFromMultihash(multihash),
125059
125141
  multiaddrs: (peer.multiaddrs ?? []).map((a2) => multiaddr(a2))
@@ -125847,7 +125929,7 @@ ${values.join("\n")}` : `${blockName} :`;
125847
125929
  async getClosestPeersOffline(key, options2) {
125848
125930
  const output6 = [];
125849
125931
  try {
125850
- const multihash = decode23(key);
125932
+ const multihash = decode24(key);
125851
125933
  const targetPeerId = peerIdFromMultihash(multihash);
125852
125934
  const peer = await this.components.peerStore.get(targetPeerId, options2);
125853
125935
  output6.push({
@@ -125916,7 +125998,7 @@ ${values.join("\n")}` : `${blockName} :`;
125916
125998
  */
125917
125999
  async writeProviderEntry(cid, peerId, options2) {
125918
126000
  const key = toProviderKey(this.datastorePrefix, cid, peerId);
125919
- const buffer2 = encode40(options2?.time?.getTime() ?? Date.now());
126001
+ const buffer2 = encode41(options2?.time?.getTime() ?? Date.now());
125920
126002
  await this.datastore.put(key, buffer2, options2);
125921
126003
  }
125922
126004
  /**
@@ -143886,7 +143968,7 @@ ${values.join("\n")}` : `${blockName} :`;
143886
143968
  const randomData = randomBytes7(2);
143887
143969
  const randomUint16 = (randomData[1] << 8) + randomData[0];
143888
143970
  const key = this._makePeerId(this.routingTable.kb.localPeer.kadId, randomUint16, targetCommonPrefixLength);
143889
- const multihash = decode23(key);
143971
+ const multihash = decode24(key);
143890
143972
  return peerIdFromMultihash(multihash);
143891
143973
  }
143892
143974
  _makePeerId(localKadId, randomPrefix, targetCommonPrefixLength) {
@@ -143984,7 +144066,7 @@ ${values.join("\n")}` : `${blockName} :`;
143984
144066
  }
143985
144067
  this.log("%p asked us, %p to store provider record for for %c", peerId, this.peerId, cid);
143986
144068
  await Promise.all(msg.providers.map(async (pi) => {
143987
- const digest2 = decode23(pi.id);
144069
+ const digest2 = decode24(pi.id);
143988
144070
  const providerId = peerIdFromMultihash(digest2);
143989
144071
  const providerMultiaddrs = pi.multiaddrs.map((buf2) => multiaddr(buf2));
143990
144072
  if (!peerId.equals(providerId)) {
@@ -144987,13 +145069,13 @@ ${values.join("\n")}` : `${blockName} :`;
144987
145069
  write(msg, list) {
144988
145070
  const pool2 = this._pool;
144989
145071
  let offset = this._poolOffset;
144990
- encode40(msg.id << 3 | msg.type, pool2, offset);
145072
+ encode41(msg.id << 3 | msg.type, pool2, offset);
144991
145073
  offset += encodingLength10(msg.id << 3 | msg.type);
144992
145074
  if ((msg.type === MessageTypes.NEW_STREAM || msg.type === MessageTypes.MESSAGE_INITIATOR || msg.type === MessageTypes.MESSAGE_RECEIVER) && msg.data != null) {
144993
- encode40(msg.data.length, pool2, offset);
145075
+ encode41(msg.data.length, pool2, offset);
144994
145076
  offset += encodingLength10(msg.data.length);
144995
145077
  } else {
144996
- encode40(0, pool2, offset);
145078
+ encode41(0, pool2, offset);
144997
145079
  offset += encodingLength10(0);
144998
145080
  }
144999
145081
  const header2 = pool2.subarray(this._poolOffset, offset);
@@ -145010,7 +145092,7 @@ ${values.join("\n")}` : `${blockName} :`;
145010
145092
  }
145011
145093
  };
145012
145094
  var encoder2 = new Encoder5();
145013
- async function* encode42(source) {
145095
+ async function* encode43(source) {
145014
145096
  for await (const message2 of source) {
145015
145097
  const list = new Uint8ArrayList();
145016
145098
  encoder2.write(message2, list);
@@ -145143,7 +145225,7 @@ ${values.join("\n")}` : `${blockName} :`;
145143
145225
  }
145144
145226
  }
145145
145227
  });
145146
- this.source = pipe2(this._source, (source) => encode42(source));
145228
+ this.source = pipe2(this._source, (source) => encode43(source));
145147
145229
  this.closeController = new AbortController();
145148
145230
  this.rateLimiter = new RateLimiter({
145149
145231
  points: init.disconnectThreshold ?? DISCONNECT_THRESHOLD,
@@ -146067,7 +146149,7 @@ ${values.join("\n")}` : `${blockName} :`;
146067
146149
  };
146068
146150
  const self2 = this;
146069
146151
  Promise.resolve().then(async () => {
146070
- for await (const buf2 of decode46(this.incomingData)) {
146152
+ for await (const buf2 of decode47(this.incomingData)) {
146071
146153
  const message2 = self2.processIncomingProtobuf(buf2);
146072
146154
  if (message2 != null) {
146073
146155
  self2.sourcePush(new Uint8ArrayList(message2));
@@ -146129,7 +146211,7 @@ ${values.join("\n")}` : `${blockName} :`;
146129
146211
  const toSend = Math.min(data.byteLength, this.maxMessageSize);
146130
146212
  const buf2 = data.subarray(0, toSend);
146131
146213
  const messageBuf = Message3.encode({ message: buf2 });
146132
- const sendBuf = encode41.single(messageBuf);
146214
+ const sendBuf = encode42.single(messageBuf);
146133
146215
  this.log.trace("sending %d/%d bytes on channel", buf2.byteLength, bytesTotal);
146134
146216
  await this._sendMessage(sendBuf);
146135
146217
  data.consume(toSend);
@@ -146208,7 +146290,7 @@ ${values.join("\n")}` : `${blockName} :`;
146208
146290
  }
146209
146291
  this.log.trace("sending flag %s", flag.toString());
146210
146292
  const messageBuf = Message3.encode({ flag });
146211
- const prefixedBuf = encode41.single(messageBuf);
146293
+ const prefixedBuf = encode42.single(messageBuf);
146212
146294
  try {
146213
146295
  await this._sendMessage(prefixedBuf, false);
146214
146296
  return true;
@@ -156374,7 +156456,7 @@ a=end-of-candidates
156374
156456
  // src/core/interfaces.ts
156375
156457
  init_shim();
156376
156458
 
156377
- // src/core/resolve.ts
156459
+ // src/core/resolver.ts
156378
156460
  init_shim();
156379
156461
 
156380
156462
  // ../cryptosuite/dist/esm/index.js
@@ -157226,10 +157308,10 @@ a=end-of-candidates
157226
157308
  * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
157227
157309
  * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
157228
157310
  * @param {number} sourceVersionId The version ID of the source document.
157229
- * @returns {Promise<SignedBTCR2Update>} The constructed SignedBTCR2Update object.
157311
+ * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
157230
157312
  * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
157231
157313
  */
157232
- static async construct(sourceDocument, patches, sourceVersionId) {
157314
+ static construct(sourceDocument, patches, sourceVersionId) {
157233
157315
  const unsignedUpdate = {
157234
157316
  "@context": [
157235
157317
  "https://w3id.org/security/v2",
@@ -157240,7 +157322,7 @@ a=end-of-candidates
157240
157322
  patch: patches,
157241
157323
  targetHash: "",
157242
157324
  targetVersionId: sourceVersionId + 1,
157243
- sourceHash: canonicalHash(sourceDocument, { encoding: "base64url" })
157325
+ sourceHash: canonicalHash(sourceDocument)
157244
157326
  };
157245
157327
  const targetDocument = JSONPatch.apply(sourceDocument, patches);
157246
157328
  try {
@@ -157252,7 +157334,7 @@ a=end-of-candidates
157252
157334
  targetDocument
157253
157335
  );
157254
157336
  }
157255
- unsignedUpdate.targetHash = canonicalHash(targetDocument, { encoding: "base64url" });
157337
+ unsignedUpdate.targetHash = canonicalHash(targetDocument);
157256
157338
  return unsignedUpdate;
157257
157339
  }
157258
157340
  /**
@@ -157265,7 +157347,7 @@ a=end-of-candidates
157265
157347
  * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
157266
157348
  * @throws {UpdateError} if the privateKeyBytes are invalid
157267
157349
  */
157268
- static async sign(did, unsignedUpdate, verificationMethod, secretKey) {
157350
+ static sign(did, unsignedUpdate, verificationMethod, secretKey) {
157269
157351
  const controller = verificationMethod.controller;
157270
157352
  const id = verificationMethod.id.slice(verificationMethod.id.indexOf("#"));
157271
157353
  const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
@@ -157317,7 +157399,7 @@ a=end-of-candidates
157317
157399
  * @param {string} options.idType The type of identifier to create, either 'KEY' or 'EXTERNAL'. Defaults to 'KEY'.
157318
157400
  * @param {number} options.version The version number of the did:btcr2 specification to use for creating the identifier. Defaults to 1.
157319
157401
  * @param {string} options.network The Bitcoin network to use for the identifier, e.g. 'bitcoin', 'testnet', etc. Defaults to 'bitcoin'.
157320
- * @returns {Promise<Btcr2Identifier>} Promise resolving to a Btcr2Identifier string.
157402
+ * @returns {Promise<string>} Promise resolving to an identifier string.
157321
157403
  * @throws {MethodError} if any of the checks fail
157322
157404
  * @example
157323
157405
  * ```ts
@@ -157338,90 +157420,34 @@ a=end-of-candidates
157338
157420
  }
157339
157421
  /**
157340
157422
  * Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
157341
- * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
157342
- * See {@link Resolve | Resolve (class)} for class implementation.
157343
157423
  *
157344
- * Resolving a did:btcr2 identifier iteratively builds a DID document by applying
157345
- * BTCR2 Updates to an Initial DID Document that have been committed to the Bitcoin
157346
- * blockchain by Authorized Beacon Signals. The Initial DID Document is either
157347
- * deterministically created from the DID or provided by Sidecar Data.
157424
+ * Factory method that performs pure setup and returns a {@link Resolver} state machine.
157425
+ * The caller drives resolution by calling `resolver.resolve()` and `resolver.provide()`.
157426
+ * Analogous to Rust's `Document::read()`.
157348
157427
  *
157349
157428
  * @param {string} did The did:btcr2 identifier to be resolved.
157350
157429
  * @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
157351
- * @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
157352
- * @throws {ResolveError} If the resolution process fails at any step.
157430
+ * @returns {Resolver} A sans-I/O state machine the caller drives to completion.
157353
157431
  * @example
157354
157432
  * ```ts
157355
- * const resolution = await DidBtcr2.resolve(
157356
- * 'did:btcr2:k1qgpr45cheptyjekl3cex80xfnkwhxnlclecwwf92gvdjrszm2uwhzlcxu5xte'
157357
- * )
157433
+ * const resolver = DidBtcr2.resolve(did, { sidecar });
157434
+ * let state = resolver.resolve();
157435
+ * while (state.status === 'action-required') {
157436
+ * for (const need of state.needs) { ... provide data ... }
157437
+ * state = resolver.resolve();
157438
+ * }
157439
+ * const { didDocument, metadata } = state.result;
157358
157440
  * ```
157359
157441
  */
157360
- static async resolve(did, resolutionOptions = {}) {
157361
- try {
157362
- const versionId = resolutionOptions.versionId;
157363
- const didResolutionResult = {
157364
- "@context": "https://w3id.org/did-resolution/v1",
157365
- didResolutionMetadata: { contentType: "application/ld+json" },
157366
- didDocumentMetadata: {
157367
- versionId,
157368
- deactivated: false,
157369
- updated: void 0,
157370
- confirmations: void 0
157371
- },
157372
- didDocument: null
157373
- };
157374
- const didComponents = Identifier.decode(did);
157375
- const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
157376
- const genesisDocument = resolutionOptions.sidecar?.genesisDocument;
157377
- if (!genesisDocument) {
157378
- if (didComponents.hrp === IdentifierHrp.x)
157379
- throw new ResolveError(
157380
- "External resolution requires genesisDocument",
157381
- MISSING_UPDATE_DATA,
157382
- resolutionOptions
157383
- );
157384
- }
157385
- const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
157386
- const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
157387
- if (!resolutionOptions?.drivers?.bitcoin) {
157388
- throw new ResolveError(
157389
- "Bitcoin connection required for resolve. Pass a configured driver via resolutionOptions.drivers.bitcoin or use DidBtcr2Api which injects it automatically.",
157390
- MISSING_RESOLUTION_OPTIONS,
157391
- resolutionOptions
157392
- );
157393
- }
157394
- const bitcoin2 = resolutionOptions.drivers.bitcoin;
157395
- const unsortedUpdates = await Resolve.beaconSignals(
157396
- beaconServices,
157397
- sidecarData,
157398
- bitcoin2
157399
- );
157400
- if (!unsortedUpdates.length) {
157401
- didResolutionResult.didDocument = currentDocument;
157402
- didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
157403
- didResolutionResult.didDocumentMetadata.versionId = versionId ?? "1";
157404
- return didResolutionResult;
157405
- }
157406
- const result = await Resolve.updates(
157407
- currentDocument,
157408
- unsortedUpdates,
157409
- resolutionOptions.versionTime,
157410
- versionId
157411
- );
157412
- didResolutionResult.didDocument = result.didDocument;
157413
- didResolutionResult.didDocumentMetadata = result.metadata;
157414
- return didResolutionResult;
157415
- } catch (error) {
157416
- if (!(error instanceof ResolveError)) throw new Error(error.message ?? error, { cause: error });
157417
- return {
157418
- ...EMPTY_DID_RESOLUTION_RESULT,
157419
- didResolutionMetadata: {
157420
- error: error.type,
157421
- ...error.message && { errorMessage: error.message }
157422
- }
157423
- };
157424
- }
157442
+ static resolve(did, resolutionOptions = {}) {
157443
+ const didComponents = Identifier.decode(did);
157444
+ const sidecarData = Resolver.sidecarData(resolutionOptions.sidecar);
157445
+ const currentDocument = didComponents.hrp === IdentifierHrp.k ? Resolver.deterministic(didComponents) : null;
157446
+ return new Resolver(didComponents, sidecarData, currentDocument, {
157447
+ versionId: resolutionOptions.versionId,
157448
+ versionTime: resolutionOptions.versionTime,
157449
+ genesisDocument: resolutionOptions.sidecar?.genesisDocument
157450
+ });
157425
157451
  }
157426
157452
  /**
157427
157453
  * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
@@ -157489,8 +157515,8 @@ a=end-of-candidates
157489
157515
  verificationMethod
157490
157516
  );
157491
157517
  }
157492
- const update = await Update.construct(sourceDocument, patches, sourceVersionId);
157493
- const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
157518
+ const update = Update.construct(sourceDocument, patches, sourceVersionId);
157519
+ const signed = Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
157494
157520
  const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
157495
157521
  if (!beaconService) {
157496
157522
  throw new UpdateError(
@@ -157538,17 +157564,47 @@ a=end-of-candidates
157538
157564
  }
157539
157565
  };
157540
157566
 
157541
- // src/core/resolve.ts
157542
- var Resolve = class {
157567
+ // src/core/resolver.ts
157568
+ var Resolver = class _Resolver {
157569
+ // --- Immutable inputs ---
157570
+ #didComponents;
157571
+ #versionId;
157572
+ #versionTime;
157573
+ /**
157574
+ * The specific phase the Resolver is current in.
157575
+ */
157576
+ #phase;
157577
+ #sidecarData;
157578
+ #currentDocument;
157579
+ #providedGenesisDocument = null;
157580
+ #beaconServicesSignals = /* @__PURE__ */ new Map();
157581
+ #processedServices = /* @__PURE__ */ new Set();
157582
+ #requestCache = /* @__PURE__ */ new Set();
157583
+ #unsortedUpdates = [];
157584
+ #resolvedResponse = null;
157585
+ /**
157586
+ * @internal — Use {@link DidBtcr2.resolve} to create instances.
157587
+ */
157588
+ constructor(didComponents, sidecarData, currentDocument, options2) {
157589
+ this.#didComponents = didComponents;
157590
+ this.#sidecarData = sidecarData;
157591
+ this.#currentDocument = currentDocument;
157592
+ this.#versionId = options2?.versionId;
157593
+ this.#versionTime = options2?.versionTime;
157594
+ if (options2?.genesisDocument) {
157595
+ this.#providedGenesisDocument = options2.genesisDocument;
157596
+ }
157597
+ this.#phase = currentDocument ? "BeaconDiscovery" /* BeaconDiscovery */ : "GenesisDocument" /* GenesisDocument */;
157598
+ }
157543
157599
  /**
157544
157600
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-secp256k1-public-key | 7.2.d.1 if genesis bytes is a secp256k1 Public Key}.
157545
157601
  * @param {DidComponents} didComponents The decoded components of the did.
157546
157602
  * @returns {DidDocument} The resolved DID Document object.
157547
157603
  */
157548
157604
  static deterministic(didComponents) {
157549
- const { genesisBytes } = didComponents;
157605
+ const genesisBytes = didComponents.genesisBytes;
157550
157606
  const did = Identifier.encode(genesisBytes, didComponents);
157551
- const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
157607
+ const { multibase } = new CompressedSecp256k1PublicKey(genesisBytes);
157552
157608
  const service = BeaconUtils.generateBeaconServices({
157553
157609
  id: did,
157554
157610
  publicKey: genesisBytes,
@@ -157561,7 +157617,7 @@ a=end-of-candidates
157561
157617
  id: `${did}#initialKey`,
157562
157618
  type: "Multikey",
157563
157619
  controller: did,
157564
- publicKeyMultibase: publicKeyMultibase.encoded
157620
+ publicKeyMultibase: multibase.encoded
157565
157621
  }],
157566
157622
  service
157567
157623
  });
@@ -157569,22 +157625,21 @@ a=end-of-candidates
157569
157625
  /**
157570
157626
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-sha-256-hash | 7.2.d.2 if genesis_bytes is a SHA-256 Hash}.
157571
157627
  * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
157572
- * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
157573
- * @returns {Promise<DidDocument>} The resolved DID Document object
157628
+ * @param {object} genesisDocument The genesis document for resolving the DID Document.
157629
+ * @returns {DidDocument} The resolved DID Document object
157574
157630
  * @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
157575
157631
  */
157576
- static async external(didComponents, genesisDocument) {
157577
- const { genesisBytes } = didComponents;
157578
- const genesisHex = hex.encode(genesisBytes);
157579
- const hashBytes = canonicalHash(genesisDocument);
157580
- if (genesisHex !== hashBytes) {
157632
+ static external(didComponents, genesisDocument) {
157633
+ const genesisBytes = encode20(didComponents.genesisBytes);
157634
+ const genesisDocumentBytes = canonicalHash(genesisDocument);
157635
+ if (genesisBytes !== genesisDocumentBytes) {
157581
157636
  throw new ResolveError(
157582
- `Initial document mismatch: genesisBytes ${genesisHex} !== hashBytes ${hashBytes}`,
157637
+ `Initial document mismatch: genesisBytes !== genesisDocumentBytes`,
157583
157638
  INVALID_DID_DOCUMENT,
157584
- { genesisBytes, hashBytes }
157639
+ { genesisBytes, genesisDocumentBytes }
157585
157640
  );
157586
157641
  }
157587
- const did = Identifier.encode(genesisBytes, didComponents);
157642
+ const did = Identifier.encode(decode19(genesisBytes), didComponents);
157588
157643
  const currentDocument = JSON.parse(
157589
157644
  JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
157590
157645
  );
@@ -157593,18 +157648,18 @@ a=end-of-candidates
157593
157648
  /**
157594
157649
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
157595
157650
  * @param {Sidecar} sidecar The sidecar data to process.
157596
- * @returns {ProcessedSidecar} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
157651
+ * @returns {SidecarData} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
157597
157652
  */
157598
157653
  static sidecarData(sidecar = {}) {
157599
157654
  const updateMap = /* @__PURE__ */ new Map();
157600
157655
  if (sidecar.updates?.length)
157601
157656
  for (const update of sidecar.updates) {
157602
- updateMap.set(canonicalHash(update, { encoding: "hex" }), update);
157657
+ updateMap.set(canonicalHash(update), update);
157603
157658
  }
157604
157659
  const casMap = /* @__PURE__ */ new Map();
157605
157660
  if (sidecar.casUpdates?.length)
157606
157661
  for (const update of sidecar.casUpdates) {
157607
- casMap.set(canonicalHash(update, { encoding: "hex" }), update);
157662
+ casMap.set(canonicalHash(update), update);
157608
157663
  }
157609
157664
  const smtMap = /* @__PURE__ */ new Map();
157610
157665
  if (sidecar.smtProofs?.length)
@@ -157613,67 +157668,15 @@ a=end-of-candidates
157613
157668
  }
157614
157669
  return { updateMap, casMap, smtMap };
157615
157670
  }
157616
- /**
157617
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#establish-current-document | 7.2.d Establish current_document}.
157618
- * Resolution begins by creating an Initial Did Document called current_document (Current DID Document).
157619
- * The current_document is iteratively patched with BTCR2 Signed Updates announced by Authorized Beacon Signals.
157620
- * @param {DidComponents} didComponents The decoded components of the did.
157621
- * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
157622
- * @returns {Promise<DidDocument>} The resolved DID Document object.
157623
- * @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
157624
- */
157625
- static async currentDocument(didComponents, genesisDocument) {
157626
- const { hrp, genesisBytes } = didComponents;
157627
- if (hrp === IdentifierHrp.x) {
157628
- if (!genesisDocument)
157629
- throw new ResolveError(
157630
- "External resolution requires genesisDocument",
157631
- MISSING_UPDATE_DATA,
157632
- { didComponents }
157633
- );
157634
- return await this.external(didComponents, genesisDocument);
157635
- }
157636
- if (hrp === IdentifierHrp.k) {
157637
- if (!CompressedSecp256k1PublicKey.isValid(genesisBytes)) {
157638
- throw new ResolveError(
157639
- "Deterministic resolution requires valid secp256k1 public key",
157640
- INVALID_DID,
157641
- { genesisBytes }
157642
- );
157643
- }
157644
- return this.deterministic(didComponents);
157645
- }
157646
- throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID, { hrp });
157647
- }
157648
- /**
157649
- * Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
157650
- * Signal Bytes (last output in OP_RETURN transaction).
157651
- * @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
157652
- * @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
157653
- * @param {BitcoinConnection} bitcoin The bitcoin network connection used to fetch beacon signals
157654
- * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
157655
- */
157656
- static async beaconSignals(beaconServices, sidecarData, bitcoin2) {
157657
- const beaconServicesSignals = bitcoin2.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin2) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin2);
157658
- const promises = await Promise.all(
157659
- Array.from(beaconServicesSignals.entries()).map(
157660
- async ([service, signals]) => {
157661
- if (!signals.length) return [];
157662
- return BeaconFactory.establish(service).processSignals(signals, sidecarData);
157663
- }
157664
- )
157665
- );
157666
- return promises.flat();
157667
- }
157668
157671
  /**
157669
157672
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
157670
157673
  * @param {DidDocument} currentDocument The current DID Document to apply the updates to.
157671
157674
  * @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
157672
157675
  * @param {string} [versionTime] The optional version time to limit updates to.
157673
157676
  * @param {string} [versionId] The optional version id to limit updates to.
157674
- * @returns {Promise<DidResolutionResponse>} The updated DID Document, number of confirmations, and version id.
157677
+ * @returns {DidResolutionResponse} The updated DID Document, number of confirmations, and version id.
157675
157678
  */
157676
- static async updates(currentDocument, unsortedUpdates, versionTime, versionId) {
157679
+ static updates(currentDocument, unsortedUpdates, versionTime, versionId) {
157677
157680
  let currentVersionId = 1;
157678
157681
  const updateHashHistory = [];
157679
157682
  const updates = unsortedUpdates.sort(
@@ -157689,7 +157692,7 @@ a=end-of-candidates
157689
157692
  }
157690
157693
  };
157691
157694
  for (const [update, block] of updates) {
157692
- const currentDocumentHash = canonicalHash(response2.didDocument, { encoding: "base64url" });
157695
+ const currentDocumentHash = canonicalHash(response2.didDocument);
157693
157696
  const blocktime = DateUtils.blocktimeToTimestamp(block.time);
157694
157697
  response2.metadata.updated = DateUtils.toISOStringNonFractional(blocktime);
157695
157698
  response2.metadata.confirmations = block.confirmations;
@@ -157709,9 +157712,9 @@ a=end-of-candidates
157709
157712
  { sourceHash: update.sourceHash, currentDocumentHash }
157710
157713
  );
157711
157714
  }
157712
- response2.didDocument = await this.applyUpdate(response2.didDocument, update);
157715
+ response2.didDocument = this.applyUpdate(response2.didDocument, update);
157713
157716
  const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
157714
- updateHashHistory.push(canonicalHash(unsignedUpdate, { encoding: "base64url" }));
157717
+ updateHashHistory.push(canonicalHash(unsignedUpdate));
157715
157718
  } else if (update.targetVersionId > currentVersionId + 1) {
157716
157719
  throw new ResolveError(
157717
157720
  `Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1`,
@@ -157724,20 +157727,23 @@ a=end-of-candidates
157724
157727
  }
157725
157728
  currentVersionId++;
157726
157729
  response2.metadata.versionId = `${currentVersionId}`;
157727
- if (currentVersionId >= Number(versionId)) {
157730
+ const versionIdNumber = Number(versionId);
157731
+ if (!isNaN(versionIdNumber) && versionIdNumber <= currentVersionId) {
157728
157732
  return response2;
157729
157733
  }
157730
- if (currentDocument.deactivated) {
157731
- response2.metadata.deactivated = currentDocument.deactivated;
157734
+ if (response2.didDocument.deactivated) {
157735
+ response2.metadata.deactivated = response2.didDocument.deactivated;
157732
157736
  return response2;
157733
157737
  }
157734
157738
  }
157735
157739
  return response2;
157736
157740
  }
157741
+ // ─── Private static: update internals ──────────────────────────────
157737
157742
  /**
157738
157743
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
157739
157744
  * This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
157740
157745
  * @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
157746
+ * @param {string[]} updateHashHistory The accumulated hash history for comparison.
157741
157747
  * @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
157742
157748
  */
157743
157749
  static confirmDuplicate(update, updateHashHistory) {
@@ -157756,10 +157762,10 @@ a=end-of-candidates
157756
157762
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
157757
157763
  * @param {DidDocument} currentDocument The current DID Document to apply the update to.
157758
157764
  * @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
157759
- * @returns {Promise<DidDocument>} The updated DID Document after applying the update.
157765
+ * @returns {DidDocument} The updated DID Document after applying the update.
157760
157766
  * @throws {ResolveError} If the update is invalid or cannot be applied.
157761
157767
  */
157762
- static async applyUpdate(currentDocument, update) {
157768
+ static applyUpdate(currentDocument, update) {
157763
157769
  const capabilityId = update.proof?.capability;
157764
157770
  if (!capabilityId) {
157765
157771
  throw new ResolveError("No root capability found in update", INVALID_DID_UPDATE, update);
@@ -157792,7 +157798,7 @@ a=end-of-candidates
157792
157798
  }
157793
157799
  const updatedDocument = JSONPatch.apply(currentDocument, update.patch);
157794
157800
  DidDocument2.validate(updatedDocument);
157795
- const currentDocumentHash = canonicalHash(updatedDocument, { encoding: "base64url" });
157801
+ const currentDocumentHash = canonicalHash(updatedDocument);
157796
157802
  const updateTargetHash = update.targetHash;
157797
157803
  if (update.targetHash !== currentDocumentHash) {
157798
157804
  throw new ResolveError(
@@ -157803,6 +157809,143 @@ a=end-of-candidates
157803
157809
  }
157804
157810
  return updatedDocument;
157805
157811
  }
157812
+ // ─── Instance: state machine ───────────────────────────────────────
157813
+ /**
157814
+ * Advance the state machine. Returns either:
157815
+ * - `{ status: 'action-required', needs }` — caller must provide data via {@link provide}
157816
+ * - `{ status: 'resolved', result }` — resolution complete
157817
+ *
157818
+ * Analogous to Rust's `Resolver::resolve()`.
157819
+ */
157820
+ resolve() {
157821
+ while (true) {
157822
+ switch (this.#phase) {
157823
+ // Phase: GenesisDocument
157824
+ // Only entered for EXTERNAL (x HRP) identifiers when genesis doc was not in sidecar.
157825
+ case "GenesisDocument" /* GenesisDocument */: {
157826
+ if (this.#providedGenesisDocument) {
157827
+ this.#currentDocument = _Resolver.external(
157828
+ this.#didComponents,
157829
+ this.#providedGenesisDocument
157830
+ );
157831
+ this.#providedGenesisDocument = null;
157832
+ this.#phase = "BeaconDiscovery" /* BeaconDiscovery */;
157833
+ continue;
157834
+ }
157835
+ const genesisHash = encode20(this.#didComponents.genesisBytes);
157836
+ return {
157837
+ status: "action-required",
157838
+ needs: [{ kind: "NeedGenesisDocument", genesisHash }]
157839
+ };
157840
+ }
157841
+ // Phase: BeaconDiscovery
157842
+ // Extract beacon services, emit NeedBeaconSignals for addresses not yet queried.
157843
+ case "BeaconDiscovery" /* BeaconDiscovery */: {
157844
+ const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
157845
+ const newServices = beaconServices.filter((service) => {
157846
+ const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
157847
+ return !this.#requestCache.has(address);
157848
+ });
157849
+ if (newServices.length > 0) {
157850
+ for (const service of newServices) {
157851
+ const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
157852
+ this.#requestCache.add(address);
157853
+ }
157854
+ return {
157855
+ status: "action-required",
157856
+ needs: [{ kind: "NeedBeaconSignals", beaconServices: newServices }]
157857
+ };
157858
+ }
157859
+ this.#phase = "BeaconProcess" /* BeaconProcess */;
157860
+ continue;
157861
+ }
157862
+ // Phase: BeaconProcess
157863
+ // Process each beacon's signals. Collect updates and data needs.
157864
+ case "BeaconProcess" /* BeaconProcess */: {
157865
+ const allNeeds = [];
157866
+ for (const [service, signals] of this.#beaconServicesSignals) {
157867
+ if (this.#processedServices.has(service.id) || !signals.length) continue;
157868
+ const beacon = BeaconFactory.establish(service);
157869
+ const result = beacon.processSignals(signals, this.#sidecarData);
157870
+ if (result.needs.length > 0) {
157871
+ allNeeds.push(...result.needs);
157872
+ } else {
157873
+ this.#unsortedUpdates.push(...result.updates);
157874
+ this.#processedServices.add(service.id);
157875
+ }
157876
+ }
157877
+ if (allNeeds.length > 0) {
157878
+ return { status: "action-required", needs: allNeeds };
157879
+ }
157880
+ this.#phase = "ApplyUpdates" /* ApplyUpdates */;
157881
+ continue;
157882
+ }
157883
+ // Phase: ApplyUpdates
157884
+ // Apply collected updates, then check for new beacon services (multi-round).
157885
+ case "ApplyUpdates" /* ApplyUpdates */: {
157886
+ if (this.#unsortedUpdates.length > 0) {
157887
+ this.#resolvedResponse = _Resolver.updates(
157888
+ this.#currentDocument,
157889
+ this.#unsortedUpdates,
157890
+ this.#versionTime,
157891
+ this.#versionId
157892
+ );
157893
+ this.#currentDocument = this.#resolvedResponse.didDocument;
157894
+ this.#unsortedUpdates = [];
157895
+ const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
157896
+ const hasNewServices = beaconServices.some((service) => {
157897
+ const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
157898
+ return !this.#requestCache.has(address);
157899
+ });
157900
+ if (hasNewServices) {
157901
+ this.#phase = "BeaconDiscovery" /* BeaconDiscovery */;
157902
+ continue;
157903
+ }
157904
+ }
157905
+ this.#phase = "Complete" /* Complete */;
157906
+ continue;
157907
+ }
157908
+ // Phase: Complete
157909
+ case "Complete" /* Complete */: {
157910
+ return {
157911
+ status: "resolved",
157912
+ result: this.#resolvedResponse ?? {
157913
+ didDocument: this.#currentDocument,
157914
+ metadata: {
157915
+ versionId: this.#versionId ?? "1",
157916
+ deactivated: this.#currentDocument.deactivated || false
157917
+ }
157918
+ }
157919
+ };
157920
+ }
157921
+ }
157922
+ }
157923
+ }
157924
+ provide(need, data) {
157925
+ switch (need.kind) {
157926
+ case "NeedGenesisDocument": {
157927
+ this.#providedGenesisDocument = data;
157928
+ break;
157929
+ }
157930
+ case "NeedBeaconSignals": {
157931
+ const signals = data;
157932
+ for (const [service, serviceSignals] of signals) {
157933
+ this.#beaconServicesSignals.set(service, serviceSignals);
157934
+ }
157935
+ break;
157936
+ }
157937
+ case "NeedCASAnnouncement": {
157938
+ const announcement = data;
157939
+ this.#sidecarData.casMap.set(canonicalHash(announcement), announcement);
157940
+ break;
157941
+ }
157942
+ case "NeedSignedUpdate": {
157943
+ const update = data;
157944
+ this.#sidecarData.updateMap.set(canonicalHash(update), update);
157945
+ break;
157946
+ }
157947
+ }
157948
+ }
157806
157949
  };
157807
157950
 
157808
157951
  // src/core/types.ts