@did-btcr2/method 0.19.0 → 0.20.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 (119) hide show
  1. package/dist/browser.js +715 -1445
  2. package/dist/browser.mjs +715 -1445
  3. package/dist/cjs/core/beacon/beacon.js +25 -0
  4. package/dist/cjs/core/beacon/beacon.js.map +1 -0
  5. package/dist/cjs/core/beacon/cas-beacon.js +20 -36
  6. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  7. package/dist/cjs/core/beacon/error.js +4 -4
  8. package/dist/cjs/core/beacon/error.js.map +1 -1
  9. package/dist/cjs/core/beacon/factory.js +5 -7
  10. package/dist/cjs/core/beacon/factory.js.map +1 -1
  11. package/dist/cjs/core/beacon/interfaces.js +1 -31
  12. package/dist/cjs/core/beacon/interfaces.js.map +1 -1
  13. package/dist/cjs/core/beacon/signal-discovery.js +183 -0
  14. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
  15. package/dist/cjs/core/beacon/singleton.js +54 -81
  16. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  17. package/dist/cjs/core/beacon/smt-beacon.js +22 -39
  18. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  19. package/dist/cjs/core/beacon/utils.js +4 -9
  20. package/dist/cjs/core/beacon/utils.js.map +1 -1
  21. package/dist/cjs/core/resolve.js +87 -277
  22. package/dist/cjs/core/resolve.js.map +1 -1
  23. package/dist/cjs/core/update.js +62 -153
  24. package/dist/cjs/core/update.js.map +1 -1
  25. package/dist/cjs/did-btcr2.js +80 -75
  26. package/dist/cjs/did-btcr2.js.map +1 -1
  27. package/dist/cjs/index.js +3 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/utils/appendix.js +6 -15
  30. package/dist/cjs/utils/appendix.js.map +1 -1
  31. package/dist/cjs/utils/did-document-builder.js +5 -0
  32. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  33. package/dist/cjs/utils/did-document.js +11 -14
  34. package/dist/cjs/utils/did-document.js.map +1 -1
  35. package/dist/esm/core/beacon/beacon.js +25 -0
  36. package/dist/esm/core/beacon/beacon.js.map +1 -0
  37. package/dist/esm/core/beacon/cas-beacon.js +20 -36
  38. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  39. package/dist/esm/core/beacon/error.js +4 -4
  40. package/dist/esm/core/beacon/error.js.map +1 -1
  41. package/dist/esm/core/beacon/factory.js +5 -7
  42. package/dist/esm/core/beacon/factory.js.map +1 -1
  43. package/dist/esm/core/beacon/interfaces.js +1 -31
  44. package/dist/esm/core/beacon/interfaces.js.map +1 -1
  45. package/dist/esm/core/beacon/signal-discovery.js +183 -0
  46. package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
  47. package/dist/esm/core/beacon/singleton.js +54 -81
  48. package/dist/esm/core/beacon/singleton.js.map +1 -1
  49. package/dist/esm/core/beacon/smt-beacon.js +22 -39
  50. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  51. package/dist/esm/core/beacon/utils.js +4 -9
  52. package/dist/esm/core/beacon/utils.js.map +1 -1
  53. package/dist/esm/core/resolve.js +87 -277
  54. package/dist/esm/core/resolve.js.map +1 -1
  55. package/dist/esm/core/update.js +62 -153
  56. package/dist/esm/core/update.js.map +1 -1
  57. package/dist/esm/did-btcr2.js +80 -75
  58. package/dist/esm/did-btcr2.js.map +1 -1
  59. package/dist/esm/index.js +3 -1
  60. package/dist/esm/index.js.map +1 -1
  61. package/dist/esm/utils/appendix.js +6 -15
  62. package/dist/esm/utils/appendix.js.map +1 -1
  63. package/dist/esm/utils/did-document-builder.js +5 -0
  64. package/dist/esm/utils/did-document-builder.js.map +1 -1
  65. package/dist/esm/utils/did-document.js +11 -14
  66. package/dist/esm/utils/did-document.js.map +1 -1
  67. package/dist/types/core/beacon/beacon.d.ts +44 -0
  68. package/dist/types/core/beacon/beacon.d.ts.map +1 -0
  69. package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
  70. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  71. package/dist/types/core/beacon/error.d.ts +2 -2
  72. package/dist/types/core/beacon/error.d.ts.map +1 -1
  73. package/dist/types/core/beacon/factory.d.ts +4 -6
  74. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  75. package/dist/types/core/beacon/interfaces.d.ts +7 -46
  76. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  77. package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
  78. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
  79. package/dist/types/core/beacon/singleton.d.ts +16 -29
  80. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  81. package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
  82. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  83. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  84. package/dist/types/core/interfaces.d.ts +1 -8
  85. package/dist/types/core/interfaces.d.ts.map +1 -1
  86. package/dist/types/core/resolve.d.ts +27 -43
  87. package/dist/types/core/resolve.d.ts.map +1 -1
  88. package/dist/types/core/types.d.ts +21 -8
  89. package/dist/types/core/types.d.ts.map +1 -1
  90. package/dist/types/core/update.d.ts +30 -73
  91. package/dist/types/core/update.d.ts.map +1 -1
  92. package/dist/types/did-btcr2.d.ts +37 -44
  93. package/dist/types/did-btcr2.d.ts.map +1 -1
  94. package/dist/types/index.d.ts +3 -1
  95. package/dist/types/index.d.ts.map +1 -1
  96. package/dist/types/utils/appendix.d.ts.map +1 -1
  97. package/dist/types/utils/did-document-builder.d.ts +5 -0
  98. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  99. package/dist/types/utils/did-document.d.ts +16 -14
  100. package/dist/types/utils/did-document.d.ts.map +1 -1
  101. package/package.json +4 -4
  102. package/src/core/beacon/beacon.ts +58 -0
  103. package/src/core/beacon/cas-beacon.ts +30 -44
  104. package/src/core/beacon/error.ts +5 -6
  105. package/src/core/beacon/factory.ts +7 -9
  106. package/src/core/beacon/interfaces.ts +7 -64
  107. package/src/core/beacon/signal-discovery.ts +237 -0
  108. package/src/core/beacon/singleton.ts +74 -94
  109. package/src/core/beacon/smt-beacon.ts +32 -49
  110. package/src/core/beacon/utils.ts +16 -13
  111. package/src/core/interfaces.ts +1 -9
  112. package/src/core/resolve.ts +116 -360
  113. package/src/core/types.ts +25 -8
  114. package/src/core/update.ts +90 -235
  115. package/src/did-btcr2.ts +131 -95
  116. package/src/index.ts +8 -1
  117. package/src/utils/appendix.ts +8 -22
  118. package/src/utils/did-document-builder.ts +5 -0
  119. package/src/utils/did-document.ts +41 -45
package/dist/browser.js CHANGED
@@ -1975,17 +1975,17 @@ var BTCR2 = (() => {
1975
1975
  init_shim();
1976
1976
  Object.defineProperty(exports, "__esModule", { value: true });
1977
1977
  exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
1978
- exports.isBytes = isBytes13;
1978
+ exports.isBytes = isBytes12;
1979
1979
  exports.anumber = anumber4;
1980
- exports.abytes = abytes6;
1980
+ exports.abytes = abytes5;
1981
1981
  exports.ahash = ahash2;
1982
- exports.aexists = aexists4;
1983
- exports.aoutput = aoutput4;
1982
+ exports.aexists = aexists3;
1983
+ exports.aoutput = aoutput3;
1984
1984
  exports.u8 = u82;
1985
1985
  exports.u32 = u323;
1986
- exports.clean = clean4;
1987
- exports.createView = createView10;
1988
- exports.rotr = rotr7;
1986
+ exports.clean = clean3;
1987
+ exports.createView = createView9;
1988
+ exports.rotr = rotr6;
1989
1989
  exports.rotl = rotl4;
1990
1990
  exports.byteSwap = byteSwap;
1991
1991
  exports.byteSwap32 = byteSwap32;
@@ -1998,20 +1998,20 @@ var BTCR2 = (() => {
1998
1998
  exports.kdfInputToBytes = kdfInputToBytes2;
1999
1999
  exports.concatBytes = concatBytes11;
2000
2000
  exports.checkOpts = checkOpts4;
2001
- exports.createHasher = createHasher3;
2001
+ exports.createHasher = createHasher2;
2002
2002
  exports.createOptHasher = createOptHasher;
2003
2003
  exports.createXOFer = createXOFer;
2004
2004
  exports.randomBytes = randomBytes10;
2005
2005
  var crypto_1 = require_crypto();
2006
- function isBytes13(a3) {
2006
+ function isBytes12(a3) {
2007
2007
  return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
2008
2008
  }
2009
2009
  function anumber4(n3) {
2010
2010
  if (!Number.isSafeInteger(n3) || n3 < 0)
2011
2011
  throw new Error("positive integer expected, got " + n3);
2012
2012
  }
2013
- function abytes6(b2, ...lengths) {
2014
- if (!isBytes13(b2))
2013
+ function abytes5(b2, ...lengths) {
2014
+ if (!isBytes12(b2))
2015
2015
  throw new Error("Uint8Array expected");
2016
2016
  if (lengths.length > 0 && !lengths.includes(b2.length))
2017
2017
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
@@ -2022,14 +2022,14 @@ var BTCR2 = (() => {
2022
2022
  anumber4(h2.outputLen);
2023
2023
  anumber4(h2.blockLen);
2024
2024
  }
2025
- function aexists4(instance3, checkFinished = true) {
2025
+ function aexists3(instance3, checkFinished = true) {
2026
2026
  if (instance3.destroyed)
2027
2027
  throw new Error("Hash instance has been destroyed");
2028
2028
  if (checkFinished && instance3.finished)
2029
2029
  throw new Error("Hash#digest() has already been called");
2030
2030
  }
2031
- function aoutput4(out, instance3) {
2032
- abytes6(out);
2031
+ function aoutput3(out, instance3) {
2032
+ abytes5(out);
2033
2033
  const min = instance3.outputLen;
2034
2034
  if (out.length < min) {
2035
2035
  throw new Error("digestInto() expects output buffer of length at least " + min);
@@ -2041,15 +2041,15 @@ var BTCR2 = (() => {
2041
2041
  function u323(arr) {
2042
2042
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
2043
2043
  }
2044
- function clean4(...arrays) {
2044
+ function clean3(...arrays) {
2045
2045
  for (let i4 = 0; i4 < arrays.length; i4++) {
2046
2046
  arrays[i4].fill(0);
2047
2047
  }
2048
2048
  }
2049
- function createView10(arr) {
2049
+ function createView9(arr) {
2050
2050
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2051
2051
  }
2052
- function rotr7(word2, shift) {
2052
+ function rotr6(word2, shift) {
2053
2053
  return word2 << 32 - shift | word2 >>> shift;
2054
2054
  }
2055
2055
  function rotl4(word2, shift) {
@@ -2074,7 +2074,7 @@ var BTCR2 = (() => {
2074
2074
  ))();
2075
2075
  var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
2076
2076
  function bytesToHex6(bytes6) {
2077
- abytes6(bytes6);
2077
+ abytes5(bytes6);
2078
2078
  if (hasHexBuiltin3)
2079
2079
  return bytes6.toHex();
2080
2080
  let hex3 = "";
@@ -2139,20 +2139,20 @@ var BTCR2 = (() => {
2139
2139
  function toBytes8(data) {
2140
2140
  if (typeof data === "string")
2141
2141
  data = utf8ToBytes11(data);
2142
- abytes6(data);
2142
+ abytes5(data);
2143
2143
  return data;
2144
2144
  }
2145
2145
  function kdfInputToBytes2(data) {
2146
2146
  if (typeof data === "string")
2147
2147
  data = utf8ToBytes11(data);
2148
- abytes6(data);
2148
+ abytes5(data);
2149
2149
  return data;
2150
2150
  }
2151
2151
  function concatBytes11(...arrays) {
2152
2152
  let sum = 0;
2153
2153
  for (let i4 = 0; i4 < arrays.length; i4++) {
2154
2154
  const a3 = arrays[i4];
2155
- abytes6(a3);
2155
+ abytes5(a3);
2156
2156
  sum += a3.length;
2157
2157
  }
2158
2158
  const res = new Uint8Array(sum);
@@ -2172,7 +2172,7 @@ var BTCR2 = (() => {
2172
2172
  var Hash7 = class {
2173
2173
  };
2174
2174
  exports.Hash = Hash7;
2175
- function createHasher3(hashCons) {
2175
+ function createHasher2(hashCons) {
2176
2176
  const hashC = (msg) => hashCons().update(toBytes8(msg)).digest();
2177
2177
  const tmp = hashCons();
2178
2178
  hashC.outputLen = tmp.outputLen;
@@ -2196,7 +2196,7 @@ var BTCR2 = (() => {
2196
2196
  hashC.create = (opts) => hashCons(opts);
2197
2197
  return hashC;
2198
2198
  }
2199
- exports.wrapConstructor = createHasher3;
2199
+ exports.wrapConstructor = createHasher2;
2200
2200
  exports.wrapConstructorWithOpts = createOptHasher;
2201
2201
  exports.wrapXOFConstructorWithOpts = createXOFer;
2202
2202
  function randomBytes10(bytesLength = 32) {
@@ -2219,8 +2219,8 @@ var BTCR2 = (() => {
2219
2219
  Object.defineProperty(exports, "__esModule", { value: true });
2220
2220
  exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
2221
2221
  exports.setBigUint64 = setBigUint648;
2222
- exports.Chi = Chi7;
2223
- exports.Maj = Maj7;
2222
+ exports.Chi = Chi6;
2223
+ exports.Maj = Maj6;
2224
2224
  var utils_ts_1 = require_utils();
2225
2225
  function setBigUint648(view, byteOffset, value3, isLE7) {
2226
2226
  if (typeof view.setBigUint64 === "function")
@@ -2234,13 +2234,13 @@ var BTCR2 = (() => {
2234
2234
  view.setUint32(byteOffset + h2, wh, isLE7);
2235
2235
  view.setUint32(byteOffset + l2, wl, isLE7);
2236
2236
  }
2237
- function Chi7(a3, b2, c2) {
2237
+ function Chi6(a3, b2, c2) {
2238
2238
  return a3 & b2 ^ ~a3 & c2;
2239
2239
  }
2240
- function Maj7(a3, b2, c2) {
2240
+ function Maj6(a3, b2, c2) {
2241
2241
  return a3 & b2 ^ a3 & c2 ^ b2 & c2;
2242
2242
  }
2243
- var HashMD4 = class extends utils_ts_1.Hash {
2243
+ var HashMD3 = class extends utils_ts_1.Hash {
2244
2244
  constructor(blockLen, outputLen, padOffset, isLE7) {
2245
2245
  super();
2246
2246
  this.finished = false;
@@ -2330,7 +2330,7 @@ var BTCR2 = (() => {
2330
2330
  return this._cloneInto();
2331
2331
  }
2332
2332
  };
2333
- exports.HashMD = HashMD4;
2333
+ exports.HashMD = HashMD3;
2334
2334
  exports.SHA256_IV = Uint32Array.from([
2335
2335
  1779033703,
2336
2336
  3144134277,
@@ -2497,7 +2497,7 @@ var BTCR2 = (() => {
2497
2497
  var _md_ts_1 = require_md();
2498
2498
  var u642 = require_u64();
2499
2499
  var utils_ts_1 = require_utils();
2500
- var SHA256_K7 = /* @__PURE__ */ Uint32Array.from([
2500
+ var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
2501
2501
  1116352408,
2502
2502
  1899447441,
2503
2503
  3049323471,
@@ -2563,7 +2563,7 @@ var BTCR2 = (() => {
2563
2563
  3204031479,
2564
2564
  3329325298
2565
2565
  ]);
2566
- var SHA256_W7 = /* @__PURE__ */ new Uint32Array(64);
2566
+ var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
2567
2567
  var SHA2566 = class extends _md_ts_1.HashMD {
2568
2568
  constructor(outputLen = 32) {
2569
2569
  super(64, outputLen, 8, false);
@@ -2593,18 +2593,18 @@ var BTCR2 = (() => {
2593
2593
  }
2594
2594
  process(view, offset) {
2595
2595
  for (let i4 = 0; i4 < 16; i4++, offset += 4)
2596
- SHA256_W7[i4] = view.getUint32(offset, false);
2596
+ SHA256_W6[i4] = view.getUint32(offset, false);
2597
2597
  for (let i4 = 16; i4 < 64; i4++) {
2598
- const W15 = SHA256_W7[i4 - 15];
2599
- const W2 = SHA256_W7[i4 - 2];
2598
+ const W15 = SHA256_W6[i4 - 15];
2599
+ const W2 = SHA256_W6[i4 - 2];
2600
2600
  const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
2601
2601
  const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
2602
- SHA256_W7[i4] = s1 + SHA256_W7[i4 - 7] + s0 + SHA256_W7[i4 - 16] | 0;
2602
+ SHA256_W6[i4] = s1 + SHA256_W6[i4 - 7] + s0 + SHA256_W6[i4 - 16] | 0;
2603
2603
  }
2604
2604
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
2605
2605
  for (let i4 = 0; i4 < 64; i4++) {
2606
2606
  const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
2607
- const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K7[i4] + SHA256_W7[i4] | 0;
2607
+ const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i4] + SHA256_W6[i4] | 0;
2608
2608
  const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
2609
2609
  const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
2610
2610
  H = G2;
@@ -2627,7 +2627,7 @@ var BTCR2 = (() => {
2627
2627
  this.set(A, B, C2, D, E, F, G2, H);
2628
2628
  }
2629
2629
  roundClean() {
2630
- (0, utils_ts_1.clean)(SHA256_W7);
2630
+ (0, utils_ts_1.clean)(SHA256_W6);
2631
2631
  }
2632
2632
  destroy() {
2633
2633
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
@@ -5274,7 +5274,7 @@ var BTCR2 = (() => {
5274
5274
  exports.expand_message_xof = expand_message_xof;
5275
5275
  exports.hash_to_field = hash_to_field;
5276
5276
  exports.isogenyMap = isogenyMap;
5277
- exports.createHasher = createHasher3;
5277
+ exports.createHasher = createHasher2;
5278
5278
  var utils_ts_1 = require_utils2();
5279
5279
  var modular_ts_1 = require_modular();
5280
5280
  var os2ip = utils_ts_1.bytesToNumberBE;
@@ -5389,7 +5389,7 @@ var BTCR2 = (() => {
5389
5389
  };
5390
5390
  }
5391
5391
  exports._DST_scalar = (0, utils_ts_1.utf8ToBytes)("HashToScalar-");
5392
- function createHasher3(Point7, mapToCurve, defaults2) {
5392
+ function createHasher2(Point7, mapToCurve, defaults2) {
5393
5393
  if (typeof mapToCurve !== "function")
5394
5394
  throw new Error("mapToCurve() must be defined");
5395
5395
  function map3(num2) {
@@ -44557,7 +44557,6 @@ var BTCR2 = (() => {
44557
44557
  // src/index.ts
44558
44558
  var index_exports = {};
44559
44559
  __export(index_exports, {
44560
- AggregateBeacon: () => AggregateBeacon,
44561
44560
  AggregateBeaconCohort: () => AggregateBeaconCohort,
44562
44561
  AggregateBeaconError: () => AggregateBeaconError,
44563
44562
  AggregateBeaconMessage: () => AggregateBeaconMessage,
@@ -44574,6 +44573,7 @@ var BTCR2 = (() => {
44574
44573
  BEACON_COHORT_SIGNATURE_AUTHORIZATION: () => BEACON_COHORT_SIGNATURE_AUTHORIZATION,
44575
44574
  BECH32M_CHARS: () => BECH32M_CHARS,
44576
44575
  BaseMessage: () => BaseMessage,
44576
+ Beacon: () => Beacon,
44577
44577
  BeaconCohortAdvertMessage: () => BeaconCohortAdvertMessage,
44578
44578
  BeaconCohortAggregatedNonceMessage: () => BeaconCohortAggregatedNonceMessage,
44579
44579
  BeaconCohortAuthorizationRequestMessage: () => BeaconCohortAuthorizationRequestMessage,
@@ -44591,9 +44591,10 @@ var BTCR2 = (() => {
44591
44591
  BeaconFactory: () => BeaconFactory,
44592
44592
  BeaconParticipant: () => BeaconParticipant,
44593
44593
  BeaconParticipantError: () => BeaconParticipantError,
44594
+ BeaconSignalDiscovery: () => BeaconSignalDiscovery,
44594
44595
  BeaconUtils: () => BeaconUtils,
44595
44596
  CASBeacon: () => CASBeacon,
44596
- CIDAggregateBeaconError: () => CIDAggregateBeaconError,
44597
+ CASBeaconError: () => CASBeaconError,
44597
44598
  COHORT_STATUS: () => COHORT_STATUS,
44598
44599
  CommunicationAdapterError: () => CommunicationAdapterError,
44599
44600
  CommunicationFactory: () => CommunicationFactory,
@@ -44615,10 +44616,10 @@ var BTCR2 = (() => {
44615
44616
  NostrAdapter: () => NostrAdapter,
44616
44617
  Resolve: () => Resolve,
44617
44618
  SIGNING_SESSION_STATUS: () => SIGNING_SESSION_STATUS,
44618
- SMTAggregateBeaconError: () => SMTAggregateBeaconError,
44619
44619
  SMTBeacon: () => SMTBeacon,
44620
+ SMTBeaconError: () => SMTBeaconError,
44620
44621
  SingletonBeacon: () => SingletonBeacon,
44621
- SingletonBeaconError: () => SingletonBeaconError2,
44622
+ SingletonBeaconError: () => SingletonBeaconError,
44622
44623
  Update: () => Update,
44623
44624
  bigEndianToInt: () => bigEndianToInt,
44624
44625
  canonicalization: () => canonicalization2,
@@ -47692,7 +47693,7 @@ var BTCR2 = (() => {
47692
47693
  };
47693
47694
  var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
47694
47695
  var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
47695
- var createBase58check = (sha25611) => /* @__PURE__ */ chain(checksum(4, (data) => sha25611(sha25611(data))), base58);
47696
+ var createBase58check = (sha25610) => /* @__PURE__ */ chain(checksum(4, (data) => sha25610(sha25610(data))), base58);
47696
47697
  var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
47697
47698
  var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
47698
47699
  function bech32Polymod(pre) {
@@ -48218,7 +48219,7 @@ var BTCR2 = (() => {
48218
48219
  this.buffers.push(new Uint8Array([b2]));
48219
48220
  this.pos++;
48220
48221
  }
48221
- finish(clean4 = true) {
48222
+ finish(clean3 = true) {
48222
48223
  if (this.finished)
48223
48224
  throw this.err("buffer: finished");
48224
48225
  if (this.bitPos)
@@ -48236,7 +48237,7 @@ var BTCR2 = (() => {
48236
48237
  buf2.set(ptr.ptr.encode(pos), ptr.pos);
48237
48238
  pos += ptr.buffer.length;
48238
48239
  }
48239
- if (clean4) {
48240
+ if (clean3) {
48240
48241
  this.buffers = [];
48241
48242
  for (const p3 of this.ptrs)
48242
48243
  p3.buffer.fill(0);
@@ -57651,11 +57652,6 @@ var BTCR2 = (() => {
57651
57652
  super(message2, { type, name: "ResolveError", data });
57652
57653
  }
57653
57654
  };
57654
- var KeyManagerError = class extends DidMethodError {
57655
- constructor(message2, type = "KeyManagerError", data) {
57656
- super(message2, { type, name: type, data });
57657
- }
57658
- };
57659
57655
  var DidDocumentError = class extends DidMethodError {
57660
57656
  constructor(message2, type = "DidDocumentError", data) {
57661
57657
  super(message2, { type, name: type, data });
@@ -57691,11 +57687,6 @@ var BTCR2 = (() => {
57691
57687
  super(message2, { type, name: type, data });
57692
57688
  }
57693
57689
  };
57694
- var SingletonBeaconError = class extends DidMethodError {
57695
- constructor(message2, type = "SingletonBeaconError", data) {
57696
- super(message2, { type, name: type, data });
57697
- }
57698
- };
57699
57690
  var CanonicalizationError = class extends DidMethodError {
57700
57691
  constructor(message2, type = "CanonicalizationError", data) {
57701
57692
  super(message2, { type, name: type, data });
@@ -59675,7 +59666,7 @@ var BTCR2 = (() => {
59675
59666
  super(message2, type, data);
59676
59667
  }
59677
59668
  };
59678
- var SingletonBeaconError2 = class extends MethodError {
59669
+ var SingletonBeaconError = class extends MethodError {
59679
59670
  constructor(message2, type = "SingletonBeaconError", data) {
59680
59671
  super(message2, type, data);
59681
59672
  }
@@ -59685,13 +59676,13 @@ var BTCR2 = (() => {
59685
59676
  super(message2, type, data);
59686
59677
  }
59687
59678
  };
59688
- var CIDAggregateBeaconError = class extends MethodError {
59689
- constructor(message2, type = "CIDAggregateBeaconError", data) {
59679
+ var CASBeaconError = class extends MethodError {
59680
+ constructor(message2, type = "CASBeaconError", data) {
59690
59681
  super(message2, type, data);
59691
59682
  }
59692
59683
  };
59693
- var SMTAggregateBeaconError = class extends MethodError {
59694
- constructor(message2, type = "SMTAggregateBeaconError", data) {
59684
+ var SMTBeaconError = class extends MethodError {
59685
+ constructor(message2, type = "SMTBeaconError", data) {
59695
59686
  super(message2, type, data);
59696
59687
  }
59697
59688
  };
@@ -60554,16 +60545,16 @@ var BTCR2 = (() => {
60554
60545
  #multibase;
60555
60546
  /**
60556
60547
  * Instantiates an instance of Secp256k1SecretKey.
60557
- * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
60548
+ * @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
60558
60549
  * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
60559
60550
  */
60560
60551
  constructor(entropy) {
60561
- const isBytes13 = entropy instanceof Uint8Array;
60552
+ const isBytes12 = entropy instanceof Uint8Array;
60562
60553
  const isSecret = typeof entropy === "bigint";
60563
- if (!isBytes13 && !isSecret) {
60554
+ if (!isBytes12 && !isSecret) {
60564
60555
  throw new SecretKeyError("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
60565
60556
  }
60566
- if (isBytes13 && entropy.length === 32) {
60557
+ if (isBytes12 && entropy.length === 32) {
60567
60558
  this.#bytes = entropy;
60568
60559
  this.#seed = _Secp256k1SecretKey.toSecret(entropy);
60569
60560
  }
@@ -60748,15 +60739,23 @@ var BTCR2 = (() => {
60748
60739
  }
60749
60740
  return new Uint8Array(bytes6);
60750
60741
  }
60742
+ /**
60743
+ * Creates a new Secp256k1SecretKey object from random bytes.
60744
+ * @param {KeyBytes} bytes The secret key bytes
60745
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
60746
+ */
60747
+ static fromBytes(bytes6) {
60748
+ return new _Secp256k1SecretKey(bytes6);
60749
+ }
60751
60750
  /**
60752
60751
  * Creates a new Secp256k1SecretKey object from a bigint secret.
60753
- * @param {bigint} entropy The secret bigint
60752
+ * @param {bigint} bint The secret bigint
60754
60753
  * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
60755
60754
  */
60756
- static fromEntropy(entropy) {
60757
- const hexsecret = entropy.toString(16).padStart(64, "0");
60758
- const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
60759
- return new _Secp256k1SecretKey(privateKeyBytes);
60755
+ static fromBigInt(bint) {
60756
+ const hexsecret = bint.toString(16).padStart(64, "0");
60757
+ const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
60758
+ return new _Secp256k1SecretKey(bytes6);
60760
60759
  }
60761
60760
  /**
60762
60761
  * Generates random secret key bytes.
@@ -61073,12 +61072,18 @@ var BTCR2 = (() => {
61073
61072
 
61074
61073
  // ../keypair/dist/esm/pair.js
61075
61074
  var SchnorrKeyPair = class _SchnorrKeyPair {
61076
- /** @type {Secp256k1SecretKey} The secret key object */
61075
+ /**
61076
+ * The secret key objec
61077
+ */
61077
61078
  #secretKey;
61078
61079
  #publicKey;
61079
- /** @type {string} The public key in multibase format */
61080
+ /**
61081
+ * The public key in multibase forma
61082
+ */
61080
61083
  #publicKeyMultibase;
61081
- /** @type {string} The secret key in multibase format */
61084
+ /**
61085
+ * The secret key in multibase forma
61086
+ */
61082
61087
  #secretKeyMultibase;
61083
61088
  /**
61084
61089
  * Creates an instance of Keys. Must provide a at least a secret key.
@@ -61216,11 +61221,11 @@ var BTCR2 = (() => {
61216
61221
  }
61217
61222
  /**
61218
61223
  * Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
61219
- * @param {bigint} entropy The entropy in bigint form
61224
+ * @param {bigint} bint The entropy in bigint form
61220
61225
  * @returns {SchnorrKeyPair} A new SchnorrKeyPair object
61221
61226
  */
61222
- static fromEntropy(entropy) {
61223
- const secretKey = Secp256k1SecretKey.fromEntropy(entropy);
61227
+ static fromBigInt(bint) {
61228
+ const secretKey = Secp256k1SecretKey.fromBigInt(bint);
61224
61229
  const publicKey2 = secretKey.computePublicKey();
61225
61230
  return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
61226
61231
  }
@@ -69887,81 +69892,48 @@ var BTCR2 = (() => {
69887
69892
  }
69888
69893
  };
69889
69894
 
69890
- // src/core/beacon/cas-beacon.ts
69895
+ // src/core/beacon/beacon.ts
69891
69896
  init_shim();
69892
-
69893
- // src/core/beacon/interfaces.ts
69894
- init_shim();
69895
- var AggregateBeacon = class {
69897
+ var Beacon = class {
69896
69898
  /**
69897
- * The Beacon service object parsed from the DID Document.
69899
+ * The Beacon service configuration parsed from the DID Document.
69898
69900
  */
69899
69901
  service;
69900
- /**
69901
- * The array of Beacon Signals associated with this Beacon service.
69902
- */
69903
- signals;
69904
- /**
69905
- * The sidecar data associated with this Beacon service.
69906
- * TODO: Make this more specific to Beacon type.
69907
- */
69908
- sidecar;
69909
- /**
69910
- * The Bitcoin network connection associated with this Beacon service.
69911
- */
69912
- bitcoin;
69913
- constructor(service, signals, sidecar, bitcoin3) {
69902
+ constructor(service) {
69914
69903
  this.service = service;
69915
- this.signals = signals;
69916
- this.sidecar = sidecar;
69917
- this.bitcoin = bitcoin3;
69918
69904
  }
69919
69905
  };
69920
69906
 
69921
69907
  // src/core/beacon/cas-beacon.ts
69922
- var CASBeacon = class _CASBeacon extends AggregateBeacon {
69908
+ init_shim();
69909
+ var CASBeacon = class extends Beacon {
69923
69910
  /**
69924
69911
  * Creates an instance of CASBeacon.
69925
69912
  * @param {BeaconService} service The service of the Beacon.
69926
- * @param {?BeaconSidecarData} [sidecar] The sidecar data of the Beacon.
69927
- */
69928
- constructor(service, signals, sidecar, bitcoin3) {
69929
- super({ ...service, type: "CASBeacon" }, signals, sidecar, bitcoin3);
69930
- }
69931
- /**
69932
- * Establish a CASBeacon instance based on the provided service and sidecar data.
69933
- * @param {BeaconService} service - The beacon service configuration.
69934
- * @param {SidecarData} sidecar - The sidecar data.
69935
- * @returns {CASBeacon} The established CASBeacon instance.
69936
- */
69937
- static establish(service, signals, sidecar) {
69938
- return new _CASBeacon(service, signals, sidecar);
69939
- }
69940
- /**
69941
- * TODO: Figure out if this is necessary or not.
69942
- * @param {HexString} updateHash The hash of the update to generate the signal for.
69943
- * @returns {BeaconSignal} The generated signal.
69944
- * @throws {MethodError} if the signal is invalid.
69945
69913
  */
69946
- generateSignal(updateHash) {
69947
- throw new Error("Method not implemented." + updateHash);
69914
+ constructor(service) {
69915
+ super({ ...service, type: "CASBeacon" });
69948
69916
  }
69949
69917
  /**
69950
69918
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
69951
- * @returns {Promise<BTCR2SignedUpdate | undefined>} The processed signed update or undefined.
69952
- * @throws {MethodError} if the signal processing fails.
69919
+ * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
69920
+ * @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
69921
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
69922
+ * @throws {CASBeaconError} if processing fails.
69953
69923
  */
69954
- processSignals() {
69955
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`);
69924
+ processSignals(signals, sidecar) {
69925
+ throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
69956
69926
  }
69957
69927
  /**
69958
- * TODO: Finish implementation
69959
- * @param {HexString} updateHash The hash of the update to broadcast.
69960
- * @returns {Promise<{ spentTx: string; signedUpdate: BTCR2SignedUpdate }>} The result of the broadcast.
69961
- * @throws {MethodError} if the broadcast fails.
69928
+ * Broadcast CAS Beacon signal to the Bitcoin network.
69929
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
69930
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
69931
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
69932
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
69933
+ * @throws {CASBeaconError} if broadcasting fails.
69962
69934
  */
69963
- async broadcastSignal(updateHash) {
69964
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
69935
+ async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
69936
+ throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin3 });
69965
69937
  }
69966
69938
  };
69967
69939
 
@@ -69980,623 +69952,8 @@ var BTCR2 = (() => {
69980
69952
  // ../kms/dist/esm/kms.js
69981
69953
  init_shim();
69982
69954
 
69983
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha2.js
69984
- init_shim();
69985
-
69986
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
69987
- init_shim();
69988
-
69989
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
69990
- init_shim();
69991
- function isBytes6(a3) {
69992
- return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
69993
- }
69994
- function abytes3(value3, length7, title = "") {
69995
- const bytes6 = isBytes6(value3);
69996
- const len = value3?.length;
69997
- const needsLen = length7 !== void 0;
69998
- if (!bytes6 || needsLen && len !== length7) {
69999
- const prefix = title && `"${title}" `;
70000
- const ofLen = needsLen ? ` of length ${length7}` : "";
70001
- const got = bytes6 ? `length=${len}` : `type=${typeof value3}`;
70002
- throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
70003
- }
70004
- return value3;
70005
- }
70006
- function aexists2(instance3, checkFinished = true) {
70007
- if (instance3.destroyed)
70008
- throw new Error("Hash instance has been destroyed");
70009
- if (checkFinished && instance3.finished)
70010
- throw new Error("Hash#digest() has already been called");
70011
- }
70012
- function aoutput2(out, instance3) {
70013
- abytes3(out, void 0, "digestInto() output");
70014
- const min = instance3.outputLen;
70015
- if (out.length < min) {
70016
- throw new Error('"digestInto() output" expected to be of length >=' + min);
70017
- }
70018
- }
70019
- function clean2(...arrays) {
70020
- for (let i4 = 0; i4 < arrays.length; i4++) {
70021
- arrays[i4].fill(0);
70022
- }
70023
- }
70024
- function createView6(arr) {
70025
- return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
70026
- }
70027
- function rotr4(word2, shift) {
70028
- return word2 << 32 - shift | word2 >>> shift;
70029
- }
70030
- function createHasher2(hashCons, info = {}) {
70031
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
70032
- const tmp = hashCons(void 0);
70033
- hashC.outputLen = tmp.outputLen;
70034
- hashC.blockLen = tmp.blockLen;
70035
- hashC.create = (opts) => hashCons(opts);
70036
- Object.assign(hashC, info);
70037
- return Object.freeze(hashC);
70038
- }
70039
- var oidNist = (suffix) => ({
70040
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
70041
- });
70042
-
70043
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_md.js
70044
- function Chi4(a3, b2, c2) {
70045
- return a3 & b2 ^ ~a3 & c2;
70046
- }
70047
- function Maj4(a3, b2, c2) {
70048
- return a3 & b2 ^ a3 & c2 ^ b2 & c2;
70049
- }
70050
- var HashMD2 = class {
70051
- blockLen;
70052
- outputLen;
70053
- padOffset;
70054
- isLE;
70055
- // For partial updates less than block size
70056
- buffer;
70057
- view;
70058
- finished = false;
70059
- length = 0;
70060
- pos = 0;
70061
- destroyed = false;
70062
- constructor(blockLen, outputLen, padOffset, isLE7) {
70063
- this.blockLen = blockLen;
70064
- this.outputLen = outputLen;
70065
- this.padOffset = padOffset;
70066
- this.isLE = isLE7;
70067
- this.buffer = new Uint8Array(blockLen);
70068
- this.view = createView6(this.buffer);
70069
- }
70070
- update(data) {
70071
- aexists2(this);
70072
- abytes3(data);
70073
- const { view, buffer: buffer2, blockLen } = this;
70074
- const len = data.length;
70075
- for (let pos = 0; pos < len; ) {
70076
- const take2 = Math.min(blockLen - this.pos, len - pos);
70077
- if (take2 === blockLen) {
70078
- const dataView2 = createView6(data);
70079
- for (; blockLen <= len - pos; pos += blockLen)
70080
- this.process(dataView2, pos);
70081
- continue;
70082
- }
70083
- buffer2.set(data.subarray(pos, pos + take2), this.pos);
70084
- this.pos += take2;
70085
- pos += take2;
70086
- if (this.pos === blockLen) {
70087
- this.process(view, 0);
70088
- this.pos = 0;
70089
- }
70090
- }
70091
- this.length += data.length;
70092
- this.roundClean();
70093
- return this;
70094
- }
70095
- digestInto(out) {
70096
- aexists2(this);
70097
- aoutput2(out, this);
70098
- this.finished = true;
70099
- const { buffer: buffer2, view, blockLen, isLE: isLE7 } = this;
70100
- let { pos } = this;
70101
- buffer2[pos++] = 128;
70102
- clean2(this.buffer.subarray(pos));
70103
- if (this.padOffset > blockLen - pos) {
70104
- this.process(view, 0);
70105
- pos = 0;
70106
- }
70107
- for (let i4 = pos; i4 < blockLen; i4++)
70108
- buffer2[i4] = 0;
70109
- view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE7);
70110
- this.process(view, 0);
70111
- const oview = createView6(out);
70112
- const len = this.outputLen;
70113
- if (len % 4)
70114
- throw new Error("_sha2: outputLen must be aligned to 32bit");
70115
- const outLen = len / 4;
70116
- const state = this.get();
70117
- if (outLen > state.length)
70118
- throw new Error("_sha2: outputLen bigger than state");
70119
- for (let i4 = 0; i4 < outLen; i4++)
70120
- oview.setUint32(4 * i4, state[i4], isLE7);
70121
- }
70122
- digest() {
70123
- const { buffer: buffer2, outputLen } = this;
70124
- this.digestInto(buffer2);
70125
- const res = buffer2.slice(0, outputLen);
70126
- this.destroy();
70127
- return res;
70128
- }
70129
- _cloneInto(to) {
70130
- to ||= new this.constructor();
70131
- to.set(...this.get());
70132
- const { blockLen, buffer: buffer2, length: length7, finished, destroyed, pos } = this;
70133
- to.destroyed = destroyed;
70134
- to.finished = finished;
70135
- to.length = length7;
70136
- to.pos = pos;
70137
- if (length7 % blockLen)
70138
- to.buffer.set(buffer2);
70139
- return to;
70140
- }
70141
- clone() {
70142
- return this._cloneInto();
70143
- }
70144
- };
70145
- var SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
70146
- 1779033703,
70147
- 3144134277,
70148
- 1013904242,
70149
- 2773480762,
70150
- 1359893119,
70151
- 2600822924,
70152
- 528734635,
70153
- 1541459225
70154
- ]);
70155
-
70156
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha2.js
70157
- var SHA256_K4 = /* @__PURE__ */ Uint32Array.from([
70158
- 1116352408,
70159
- 1899447441,
70160
- 3049323471,
70161
- 3921009573,
70162
- 961987163,
70163
- 1508970993,
70164
- 2453635748,
70165
- 2870763221,
70166
- 3624381080,
70167
- 310598401,
70168
- 607225278,
70169
- 1426881987,
70170
- 1925078388,
70171
- 2162078206,
70172
- 2614888103,
70173
- 3248222580,
70174
- 3835390401,
70175
- 4022224774,
70176
- 264347078,
70177
- 604807628,
70178
- 770255983,
70179
- 1249150122,
70180
- 1555081692,
70181
- 1996064986,
70182
- 2554220882,
70183
- 2821834349,
70184
- 2952996808,
70185
- 3210313671,
70186
- 3336571891,
70187
- 3584528711,
70188
- 113926993,
70189
- 338241895,
70190
- 666307205,
70191
- 773529912,
70192
- 1294757372,
70193
- 1396182291,
70194
- 1695183700,
70195
- 1986661051,
70196
- 2177026350,
70197
- 2456956037,
70198
- 2730485921,
70199
- 2820302411,
70200
- 3259730800,
70201
- 3345764771,
70202
- 3516065817,
70203
- 3600352804,
70204
- 4094571909,
70205
- 275423344,
70206
- 430227734,
70207
- 506948616,
70208
- 659060556,
70209
- 883997877,
70210
- 958139571,
70211
- 1322822218,
70212
- 1537002063,
70213
- 1747873779,
70214
- 1955562222,
70215
- 2024104815,
70216
- 2227730452,
70217
- 2361852424,
70218
- 2428436474,
70219
- 2756734187,
70220
- 3204031479,
70221
- 3329325298
70222
- ]);
70223
- var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
70224
- var SHA2_32B = class extends HashMD2 {
70225
- constructor(outputLen) {
70226
- super(64, outputLen, 8, false);
70227
- }
70228
- get() {
70229
- const { A, B, C: C2, D, E, F, G: G2, H } = this;
70230
- return [A, B, C2, D, E, F, G2, H];
70231
- }
70232
- // prettier-ignore
70233
- set(A, B, C2, D, E, F, G2, H) {
70234
- this.A = A | 0;
70235
- this.B = B | 0;
70236
- this.C = C2 | 0;
70237
- this.D = D | 0;
70238
- this.E = E | 0;
70239
- this.F = F | 0;
70240
- this.G = G2 | 0;
70241
- this.H = H | 0;
70242
- }
70243
- process(view, offset) {
70244
- for (let i4 = 0; i4 < 16; i4++, offset += 4)
70245
- SHA256_W4[i4] = view.getUint32(offset, false);
70246
- for (let i4 = 16; i4 < 64; i4++) {
70247
- const W15 = SHA256_W4[i4 - 15];
70248
- const W2 = SHA256_W4[i4 - 2];
70249
- const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
70250
- const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
70251
- SHA256_W4[i4] = s1 + SHA256_W4[i4 - 7] + s0 + SHA256_W4[i4 - 16] | 0;
70252
- }
70253
- let { A, B, C: C2, D, E, F, G: G2, H } = this;
70254
- for (let i4 = 0; i4 < 64; i4++) {
70255
- const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
70256
- const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i4] + SHA256_W4[i4] | 0;
70257
- const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
70258
- const T2 = sigma0 + Maj4(A, B, C2) | 0;
70259
- H = G2;
70260
- G2 = F;
70261
- F = E;
70262
- E = D + T1 | 0;
70263
- D = C2;
70264
- C2 = B;
70265
- B = A;
70266
- A = T1 + T2 | 0;
70267
- }
70268
- A = A + this.A | 0;
70269
- B = B + this.B | 0;
70270
- C2 = C2 + this.C | 0;
70271
- D = D + this.D | 0;
70272
- E = E + this.E | 0;
70273
- F = F + this.F | 0;
70274
- G2 = G2 + this.G | 0;
70275
- H = H + this.H | 0;
70276
- this.set(A, B, C2, D, E, F, G2, H);
70277
- }
70278
- roundClean() {
70279
- clean2(SHA256_W4);
70280
- }
70281
- destroy() {
70282
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
70283
- clean2(this.buffer);
70284
- }
70285
- };
70286
- var _SHA256 = class extends SHA2_32B {
70287
- // We cannot use array here since array allows indexing by variable
70288
- // which means optimizer/compiler cannot use registers.
70289
- A = SHA256_IV2[0] | 0;
70290
- B = SHA256_IV2[1] | 0;
70291
- C = SHA256_IV2[2] | 0;
70292
- D = SHA256_IV2[3] | 0;
70293
- E = SHA256_IV2[4] | 0;
70294
- F = SHA256_IV2[5] | 0;
70295
- G = SHA256_IV2[6] | 0;
70296
- H = SHA256_IV2[7] | 0;
70297
- constructor() {
70298
- super(32);
70299
- }
70300
- };
70301
- var sha2565 = /* @__PURE__ */ createHasher2(
70302
- () => new _SHA256(),
70303
- /* @__PURE__ */ oidNist(1)
70304
- );
70305
-
70306
69955
  // ../kms/dist/esm/store.js
70307
69956
  init_shim();
70308
- var MemoryStore = class {
70309
- /**
70310
- * A private field that contains the Map used as the key-value store.
70311
- */
70312
- store = /* @__PURE__ */ new Map();
70313
- /**
70314
- * Clears all entries in the key-value store.
70315
- *
70316
- * @returns {void} returns once the operation is complete.
70317
- */
70318
- clear() {
70319
- this.store.clear();
70320
- }
70321
- /**
70322
- * This operation is no-op for `MemoryStore`.
70323
- */
70324
- close() {
70325
- }
70326
- /**
70327
- * Deletes an entry from the key-value store by its key.
70328
- *
70329
- * @param {K} id - The key of the entry to delete.
70330
- * @returns {boolean} a boolean indicating whether the entry was successfully deleted.
70331
- */
70332
- delete(id) {
70333
- return this.store.delete(id);
70334
- }
70335
- /**
70336
- * Retrieves the value of an entry by its key.
70337
- *
70338
- * @param {K} id - The key of the entry to retrieve.
70339
- * @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
70340
- */
70341
- get(id) {
70342
- return this.store.get(id);
70343
- }
70344
- /**
70345
- * Checks for the presence of an entry by key.
70346
- *
70347
- * @param {K} id - The key to check for the existence of.
70348
- * @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
70349
- */
70350
- has(id) {
70351
- return this.store.has(id);
70352
- }
70353
- /**
70354
- * Retrieves all values in the key-value store.
70355
-
70356
- * @returns {Array<V>} an array of all values in the store.
70357
- */
70358
- list() {
70359
- return Array.from(this.store.values());
70360
- }
70361
- /**
70362
- * Retrieves all entries in the key-value store.
70363
- *
70364
- * @returns {Array<[K, V]>} an array of key-value pairs in the store.
70365
- */
70366
- entries() {
70367
- return Array.from(this.store.entries());
70368
- }
70369
- /**
70370
- * Sets the value of an entry in the key-value store.
70371
- *
70372
- * @param {K} id - The key of the entry to set.
70373
- * @param {V} key - The new value for the entry.
70374
- * @returns {void} once operation is complete.
70375
- */
70376
- set(id, key) {
70377
- this.store.set(id, key);
70378
- }
70379
- };
70380
-
70381
- // ../kms/dist/esm/kms.js
70382
- var Kms = class _Kms {
70383
- /**
70384
- * Singleton instance of the Kms.
70385
- * @private
70386
- * @type {KeyManager}
70387
- */
70388
- static #instance;
70389
- /**
70390
- * The `store` is a private variable in `KeyManager`. It is a `KeyValueStore` instance used for
70391
- * storing and managing cryptographic keys. It allows the `KeyManager` class to save,
70392
- * retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
70393
- * This variable can be configured to use different storage backends, like in-memory storage or
70394
- * persistent storage, providing flexibility in key management according to the application's
70395
- * requirements.
70396
- * @private
70397
- * @type {KeyValueStore<KeyIdentifier, KeyBytes>} The key store for managing cryptographic keys.
70398
- */
70399
- #store;
70400
- /**
70401
- * The `#activeKeyId` property is a string that points to the currently active key.
70402
- * It is used to identify the key that will be used for signing and verifying operations.
70403
- * This property is optional and can be set to a specific key ID when initializing the
70404
- * `KeyManager` instance. If not set, the key manager will use the default key id.
70405
- * @private
70406
- * @type {KeyIdentifier}
70407
- */
70408
- #activeKeyId;
70409
- /**
70410
- * Creates an instance of KeyManager.
70411
- * @param {KeyValueStore<KeyIdentifier, KeyBytes>} store An optional property to specify a custom
70412
- * `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
70413
- * instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
70414
- * managed during cryptographic operations.
70415
- */
70416
- constructor(store5) {
70417
- this.#store = store5 ?? new MemoryStore();
70418
- }
70419
- /**
70420
- * Gets the ID of the active key.
70421
- * @returns {KeyIdentifier | undefined} The ID of the active key.
70422
- */
70423
- get activeKeyId() {
70424
- return this.#activeKeyId;
70425
- }
70426
- /**
70427
- * Gets the key pair associated with the given ID or the active key if no ID is provided.
70428
- * @param {KeyIdentifier} [id] The ID of the key to get.
70429
- * @returns {KeyBytes} A promise resolving to the key pair.
70430
- * @throws {KeyManagerError} If the key is not found or no active key is set.
70431
- */
70432
- #getKeyOrThrow(id) {
70433
- const keyId2 = id ?? this.#activeKeyId;
70434
- if (!keyId2) {
70435
- throw new KeyManagerError("No active key set", "ACTIVE_KEY_URI_NOT_SET");
70436
- }
70437
- const _secretKey = this.#store.get(keyId2);
70438
- if (!_secretKey) {
70439
- throw new KeyManagerError(`Key not found: ${keyId2}`, "KEY_NOT_FOUND");
70440
- }
70441
- const kp = new SchnorrKeyPair({ secretKey: _secretKey });
70442
- return kp;
70443
- }
70444
- /**
70445
- * Checks if a key with the given ID exists in the key store.
70446
- * @param {KeyIdentifier} id The ID of the key to check.
70447
- * @returns {boolean} A promise resolving to a boolean indicating if the key exists.
70448
- */
70449
- #exists(id) {
70450
- const key = this.#store.get(id);
70451
- return !!key;
70452
- }
70453
- /**
70454
- * Removes a key from the key store.
70455
- * @param {KeyIdentifier} id The key identifier of the key to remove.
70456
- * @param {{ force?: boolean }} options The options for removing the key.
70457
- * @param {boolean} [options.force] Whether to force the removal of the key.
70458
- * @returns {void} A promise that resolves when the key is removed.
70459
- * @throws {KeyManagerError} If attempting to remove the active key without force.
70460
- */
70461
- removeKey(id, options2 = {}) {
70462
- if (this.#activeKeyId === id && !options2.force) {
70463
- throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', "ACTIVE_KEY_DELETE");
70464
- }
70465
- if (!this.#exists(id)) {
70466
- throw new KeyManagerError(`Key not found: ${id}`, "KEY_NOT_FOUND");
70467
- }
70468
- this.#store.delete(id);
70469
- if (this.#activeKeyId === id) {
70470
- this.#activeKeyId = void 0;
70471
- }
70472
- }
70473
- /**
70474
- * Lists all key identifiers in the key store.
70475
- * @returns {Promise<KeyIdentifier[]>} A promise that resolves to an array of key identifiers.
70476
- */
70477
- listKeys() {
70478
- return this.#store.entries().flatMap(([k, _]) => [k]);
70479
- }
70480
- /**
70481
- * Sets the active key to the key associated with the given ID.
70482
- * @param {KeyIdentifier} id The ID of the key to set as active.
70483
- * @returns {Promise<void>} A promise that resolves when the active key is set.
70484
- * @throws {KeyManagerError} If the key is not found.
70485
- */
70486
- setActiveKey(id) {
70487
- this.#getKeyOrThrow(id);
70488
- this.#activeKeyId = id;
70489
- }
70490
- /**
70491
- * Gets the public key associated with the given ID or the active key if no ID is provided.
70492
- * @param {KeyIdentifier} [id] The ID of the key to get the public key for.
70493
- * @returns {Promise<KeyBytes>} A promise resolving to the public key bytes.
70494
- */
70495
- getPublicKey(id) {
70496
- const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
70497
- return publicKey2.compressed;
70498
- }
70499
- /**
70500
- * Signs the given data using the key associated with the key ID.
70501
- * @param {Bytes} data The data to sign.
70502
- * @param {KeyIdentifier} [id] The ID of the key to sign the data with.
70503
- * @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
70504
- */
70505
- sign(data, id) {
70506
- const { secretKey } = this.#getKeyOrThrow(id);
70507
- if (!secretKey) {
70508
- throw new KeyManagerError(`Key ID ${id} is not a signer`, "KEY_NOT_SIGNER");
70509
- }
70510
- return secretKey.sign(data);
70511
- }
70512
- /**
70513
- * Verifies a signature using the key associated with the key ID.
70514
- * @param {KeyIdentifier} id The ID of the key to verify the signature with.
70515
- * @param {SignatureBytes} signature The signature to verify.
70516
- * @param {Hex} data The data to verify the signature with.
70517
- * @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
70518
- */
70519
- verify(signature2, data, id) {
70520
- const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
70521
- return publicKey2.verify(signature2, data);
70522
- }
70523
- /**
70524
- * Imports a key pair into the key store.
70525
- * @param {SchnorrKeyPair} keyPair The key pair to import.
70526
- * @param {{ id?: KeyIdentifier; setActive?: boolean }} options The options for importing the key pair.
70527
- * @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
70528
- * @param {boolean} [options.setActive] Whether to set the key as active (optional, default: true).
70529
- * @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
70530
- */
70531
- importKey(keyPair, options2 = {}) {
70532
- if (!keyPair.publicKey) {
70533
- keyPair.publicKey = keyPair.secretKey.computePublicKey();
70534
- }
70535
- const id = options2.id ?? keyPair.publicKey.hex;
70536
- if (this.#exists(id)) {
70537
- throw new KeyManagerError(`Key already exists: ${id}`, "KEY_FOUND");
70538
- }
70539
- this.#store.set(id, keyPair.secretKey.bytes);
70540
- const setActive = options2.setActive ?? true;
70541
- if (setActive) {
70542
- this.#activeKeyId = id;
70543
- }
70544
- return id;
70545
- }
70546
- /**
70547
- * Computes the hash of the given data.
70548
- * @param {Uint8Array} data The data to hash.
70549
- * @returns {HashBytes} The hash of the data.
70550
- */
70551
- digest(data) {
70552
- return sha2565(data);
70553
- }
70554
- /**
70555
- * Generates a new key pair and stores it in the key store.
70556
- * @returns {KeyIdentifier} The key identifier of the generated key.
70557
- */
70558
- generateKey() {
70559
- const kp = SchnorrKeyPair.generate();
70560
- const id = kp.publicKey.hex;
70561
- this.#store.set(id, kp.secretKey.bytes);
70562
- this.#activeKeyId = id;
70563
- return id;
70564
- }
70565
- /**
70566
- * Initializes a singleton KeyManager instance.
70567
- * @param {SchnorrKeyPair} keyPair The secret key to import.
70568
- * @param {string} id The ID to set as the active key.
70569
- * @returns {void}
70570
- */
70571
- static initialize(keyPair, id) {
70572
- if (_Kms.#instance) {
70573
- console.warn("WARNING: Kms global instance is already initialized.");
70574
- return _Kms.#instance;
70575
- }
70576
- if (!keyPair) {
70577
- console.warn("WARNING: secretKey not provided, generating new SchnorrKeyPair ...");
70578
- }
70579
- keyPair ??= SchnorrKeyPair.generate();
70580
- _Kms.#instance = new _Kms();
70581
- _Kms.#instance.importKey(keyPair, { setActive: true, id });
70582
- _Kms.#instance.#activeKeyId = id;
70583
- console.info(`Kms initialized with Active Key ID: ${_Kms.#instance.#activeKeyId}`);
70584
- return _Kms.#instance;
70585
- }
70586
- /**
70587
- * Retrieves a keypair from the key store using the provided key ID.
70588
- * @public
70589
- * @param {KeyIdentifier} id The ID of the keypair to retrieve.
70590
- * @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
70591
- */
70592
- static getKey(id) {
70593
- if (!_Kms.#instance) {
70594
- throw new KeyManagerError("Kms instance not initialized", "KMS_NOT_INITIALIZED");
70595
- }
70596
- id ??= _Kms.#instance.activeKeyId;
70597
- return _Kms.#instance.#getKeyOrThrow(id);
70598
- }
70599
- };
70600
69957
 
70601
69958
  // ../kms/dist/esm/signer.js
70602
69959
  init_shim();
@@ -70633,7 +69990,7 @@ var BTCR2 = (() => {
70633
69990
  * @param {Bytes} hash The hash to sign.
70634
69991
  * @returns {SignatureBytes} The signature of the hash.
70635
69992
  */
70636
- signEcdsa(hash4) {
69993
+ sign(hash4) {
70637
69994
  return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
70638
69995
  }
70639
69996
  /**
@@ -70641,7 +69998,7 @@ var BTCR2 = (() => {
70641
69998
  * @param {Bytes} hash The hash to sign.
70642
69999
  * @returns {SignatureBytes} The Schnorr signature of the hash.
70643
70000
  */
70644
- sign(hash4) {
70001
+ signSchnorr(hash4) {
70645
70002
  return this.keyPair.secretKey.sign(hash4);
70646
70003
  }
70647
70004
  };
@@ -73447,11 +72804,11 @@ var BTCR2 = (() => {
73447
72804
 
73448
72805
  // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/_assert.js
73449
72806
  init_shim();
73450
- function isBytes7(a3) {
72807
+ function isBytes6(a3) {
73451
72808
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
73452
72809
  }
73453
72810
  function bytes4(b2, ...lengths) {
73454
- if (!isBytes7(b2))
72811
+ if (!isBytes6(b2))
73455
72812
  throw new Error("Uint8Array expected");
73456
72813
  if (lengths.length > 0 && !lengths.includes(b2.length))
73457
72814
  throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b2.length}`);
@@ -73478,8 +72835,8 @@ var BTCR2 = (() => {
73478
72835
  var crypto5 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
73479
72836
 
73480
72837
  // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/utils.js
73481
- var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
73482
- var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
72838
+ var createView6 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
72839
+ var rotr4 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
73483
72840
  var isLE4 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
73484
72841
  function utf8ToBytes6(str) {
73485
72842
  if (typeof str !== "string")
@@ -73527,9 +72884,9 @@ var BTCR2 = (() => {
73527
72884
  view.setUint32(byteOffset + h2, wh, isLE7);
73528
72885
  view.setUint32(byteOffset + l2, wl, isLE7);
73529
72886
  }
73530
- var Chi5 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
73531
- var Maj5 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
73532
- var HashMD3 = class extends Hash4 {
72887
+ var Chi4 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
72888
+ var Maj4 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
72889
+ var HashMD2 = class extends Hash4 {
73533
72890
  constructor(blockLen, outputLen, padOffset, isLE7) {
73534
72891
  super();
73535
72892
  this.blockLen = blockLen;
@@ -73541,7 +72898,7 @@ var BTCR2 = (() => {
73541
72898
  this.pos = 0;
73542
72899
  this.destroyed = false;
73543
72900
  this.buffer = new Uint8Array(blockLen);
73544
- this.view = createView7(this.buffer);
72901
+ this.view = createView6(this.buffer);
73545
72902
  }
73546
72903
  update(data) {
73547
72904
  exists4(this);
@@ -73551,7 +72908,7 @@ var BTCR2 = (() => {
73551
72908
  for (let pos = 0; pos < len; ) {
73552
72909
  const take2 = Math.min(blockLen - this.pos, len - pos);
73553
72910
  if (take2 === blockLen) {
73554
- const dataView2 = createView7(data);
72911
+ const dataView2 = createView6(data);
73555
72912
  for (; blockLen <= len - pos; pos += blockLen)
73556
72913
  this.process(dataView2, pos);
73557
72914
  continue;
@@ -73584,7 +72941,7 @@ var BTCR2 = (() => {
73584
72941
  buffer2[i4] = 0;
73585
72942
  setBigUint645(view, blockLen - 8, BigInt(this.length * 8), isLE7);
73586
72943
  this.process(view, 0);
73587
- const oview = createView7(out);
72944
+ const oview = createView6(out);
73588
72945
  const len = this.outputLen;
73589
72946
  if (len % 4)
73590
72947
  throw new Error("_sha2: outputLen should be aligned to 32bit");
@@ -73617,7 +72974,7 @@ var BTCR2 = (() => {
73617
72974
  };
73618
72975
 
73619
72976
  // ../../node_modules/.pnpm/@noble+hashes@1.4.0/node_modules/@noble/hashes/esm/sha256.js
73620
- var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
72977
+ var SHA256_K4 = /* @__PURE__ */ new Uint32Array([
73621
72978
  1116352408,
73622
72979
  1899447441,
73623
72980
  3049323471,
@@ -73683,7 +73040,7 @@ var BTCR2 = (() => {
73683
73040
  3204031479,
73684
73041
  3329325298
73685
73042
  ]);
73686
- var SHA256_IV3 = /* @__PURE__ */ new Uint32Array([
73043
+ var SHA256_IV2 = /* @__PURE__ */ new Uint32Array([
73687
73044
  1779033703,
73688
73045
  3144134277,
73689
73046
  1013904242,
@@ -73693,18 +73050,18 @@ var BTCR2 = (() => {
73693
73050
  528734635,
73694
73051
  1541459225
73695
73052
  ]);
73696
- var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
73697
- var SHA2564 = class extends HashMD3 {
73053
+ var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
73054
+ var SHA2564 = class extends HashMD2 {
73698
73055
  constructor() {
73699
73056
  super(64, 32, 8, false);
73700
- this.A = SHA256_IV3[0] | 0;
73701
- this.B = SHA256_IV3[1] | 0;
73702
- this.C = SHA256_IV3[2] | 0;
73703
- this.D = SHA256_IV3[3] | 0;
73704
- this.E = SHA256_IV3[4] | 0;
73705
- this.F = SHA256_IV3[5] | 0;
73706
- this.G = SHA256_IV3[6] | 0;
73707
- this.H = SHA256_IV3[7] | 0;
73057
+ this.A = SHA256_IV2[0] | 0;
73058
+ this.B = SHA256_IV2[1] | 0;
73059
+ this.C = SHA256_IV2[2] | 0;
73060
+ this.D = SHA256_IV2[3] | 0;
73061
+ this.E = SHA256_IV2[4] | 0;
73062
+ this.F = SHA256_IV2[5] | 0;
73063
+ this.G = SHA256_IV2[6] | 0;
73064
+ this.H = SHA256_IV2[7] | 0;
73708
73065
  }
73709
73066
  get() {
73710
73067
  const { A, B, C: C2, D, E, F, G: G2, H } = this;
@@ -73723,20 +73080,20 @@ var BTCR2 = (() => {
73723
73080
  }
73724
73081
  process(view, offset) {
73725
73082
  for (let i4 = 0; i4 < 16; i4++, offset += 4)
73726
- SHA256_W5[i4] = view.getUint32(offset, false);
73083
+ SHA256_W4[i4] = view.getUint32(offset, false);
73727
73084
  for (let i4 = 16; i4 < 64; i4++) {
73728
- const W15 = SHA256_W5[i4 - 15];
73729
- const W2 = SHA256_W5[i4 - 2];
73730
- const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
73731
- const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
73732
- SHA256_W5[i4] = s1 + SHA256_W5[i4 - 7] + s0 + SHA256_W5[i4 - 16] | 0;
73085
+ const W15 = SHA256_W4[i4 - 15];
73086
+ const W2 = SHA256_W4[i4 - 2];
73087
+ const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
73088
+ const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
73089
+ SHA256_W4[i4] = s1 + SHA256_W4[i4 - 7] + s0 + SHA256_W4[i4 - 16] | 0;
73733
73090
  }
73734
73091
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
73735
73092
  for (let i4 = 0; i4 < 64; i4++) {
73736
- const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
73737
- const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i4] + SHA256_W5[i4] | 0;
73738
- const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
73739
- const T2 = sigma0 + Maj5(A, B, C2) | 0;
73093
+ const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
73094
+ const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i4] + SHA256_W4[i4] | 0;
73095
+ const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
73096
+ const T2 = sigma0 + Maj4(A, B, C2) | 0;
73740
73097
  H = G2;
73741
73098
  G2 = F;
73742
73099
  F = E;
@@ -73757,14 +73114,14 @@ var BTCR2 = (() => {
73757
73114
  this.set(A, B, C2, D, E, F, G2, H);
73758
73115
  }
73759
73116
  roundClean() {
73760
- SHA256_W5.fill(0);
73117
+ SHA256_W4.fill(0);
73761
73118
  }
73762
73119
  destroy() {
73763
73120
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
73764
73121
  this.buffer.fill(0);
73765
73122
  }
73766
73123
  };
73767
- var sha2566 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
73124
+ var sha2565 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
73768
73125
 
73769
73126
  // ../../node_modules/.pnpm/@web5+crypto@1.0.6/node_modules/@web5/crypto/dist/esm/primitives/sha256.js
73770
73127
  var __awaiter3 = function(thisArg, _arguments, P3, generator) {
@@ -73816,7 +73173,7 @@ var BTCR2 = (() => {
73816
73173
  */
73817
73174
  static digest(_a3) {
73818
73175
  return __awaiter3(this, arguments, void 0, function* ({ data }) {
73819
- const hash4 = sha2566(data);
73176
+ const hash4 = sha2565(data);
73820
73177
  return hash4;
73821
73178
  });
73822
73179
  }
@@ -73914,11 +73271,11 @@ var BTCR2 = (() => {
73914
73271
  if (!Number.isSafeInteger(n3) || n3 < 0)
73915
73272
  throw new Error(`Wrong positive integer: ${n3}`);
73916
73273
  }
73917
- function isBytes8(a3) {
73274
+ function isBytes7(a3) {
73918
73275
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
73919
73276
  }
73920
73277
  function bytes5(b2, ...lengths) {
73921
- if (!isBytes8(b2))
73278
+ if (!isBytes7(b2))
73922
73279
  throw new Error("Expected Uint8Array");
73923
73280
  if (lengths.length > 0 && !lengths.includes(b2.length))
73924
73281
  throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b2.length}`);
@@ -73951,11 +73308,11 @@ var BTCR2 = (() => {
73951
73308
  var crypto6 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
73952
73309
 
73953
73310
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/utils.js
73954
- function isBytes9(a3) {
73311
+ function isBytes8(a3) {
73955
73312
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
73956
73313
  }
73957
- var createView8 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
73958
- var rotr6 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
73314
+ var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
73315
+ var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
73959
73316
  var isLE5 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
73960
73317
  if (!isLE5)
73961
73318
  throw new Error("Non little-endian hardware is not supported");
@@ -73967,7 +73324,7 @@ var BTCR2 = (() => {
73967
73324
  function toBytes6(data) {
73968
73325
  if (typeof data === "string")
73969
73326
  data = utf8ToBytes7(data);
73970
- if (!isBytes9(data))
73327
+ if (!isBytes8(data))
73971
73328
  throw new Error(`expected Uint8Array, got ${typeof data}`);
73972
73329
  return data;
73973
73330
  }
@@ -73975,7 +73332,7 @@ var BTCR2 = (() => {
73975
73332
  let sum = 0;
73976
73333
  for (let i4 = 0; i4 < arrays.length; i4++) {
73977
73334
  const a3 = arrays[i4];
73978
- if (!isBytes9(a3))
73335
+ if (!isBytes8(a3))
73979
73336
  throw new Error("Uint8Array expected");
73980
73337
  sum += a3.length;
73981
73338
  }
@@ -74034,7 +73391,7 @@ var BTCR2 = (() => {
74034
73391
  this.pos = 0;
74035
73392
  this.destroyed = false;
74036
73393
  this.buffer = new Uint8Array(blockLen);
74037
- this.view = createView8(this.buffer);
73394
+ this.view = createView7(this.buffer);
74038
73395
  }
74039
73396
  update(data) {
74040
73397
  exists5(this);
@@ -74044,7 +73401,7 @@ var BTCR2 = (() => {
74044
73401
  for (let pos = 0; pos < len; ) {
74045
73402
  const take2 = Math.min(blockLen - this.pos, len - pos);
74046
73403
  if (take2 === blockLen) {
74047
- const dataView2 = createView8(data);
73404
+ const dataView2 = createView7(data);
74048
73405
  for (; blockLen <= len - pos; pos += blockLen)
74049
73406
  this.process(dataView2, pos);
74050
73407
  continue;
@@ -74077,7 +73434,7 @@ var BTCR2 = (() => {
74077
73434
  buffer2[i4] = 0;
74078
73435
  setBigUint646(view, blockLen - 8, BigInt(this.length * 8), isLE7);
74079
73436
  this.process(view, 0);
74080
- const oview = createView8(out);
73437
+ const oview = createView7(out);
74081
73438
  const len = this.outputLen;
74082
73439
  if (len % 4)
74083
73440
  throw new Error("_sha2: outputLen should be aligned to 32bit");
@@ -74110,9 +73467,9 @@ var BTCR2 = (() => {
74110
73467
  };
74111
73468
 
74112
73469
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/sha256.js
74113
- var Chi6 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
74114
- var Maj6 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
74115
- var SHA256_K6 = /* @__PURE__ */ new Uint32Array([
73470
+ var Chi5 = (a3, b2, c2) => a3 & b2 ^ ~a3 & c2;
73471
+ var Maj5 = (a3, b2, c2) => a3 & b2 ^ a3 & c2 ^ b2 & c2;
73472
+ var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
74116
73473
  1116352408,
74117
73474
  1899447441,
74118
73475
  3049323471,
@@ -74188,7 +73545,7 @@ var BTCR2 = (() => {
74188
73545
  528734635,
74189
73546
  1541459225
74190
73547
  ]);
74191
- var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
73548
+ var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
74192
73549
  var SHA2565 = class extends SHA23 {
74193
73550
  constructor() {
74194
73551
  super(64, 32, 8, false);
@@ -74218,20 +73575,20 @@ var BTCR2 = (() => {
74218
73575
  }
74219
73576
  process(view, offset) {
74220
73577
  for (let i4 = 0; i4 < 16; i4++, offset += 4)
74221
- SHA256_W6[i4] = view.getUint32(offset, false);
73578
+ SHA256_W5[i4] = view.getUint32(offset, false);
74222
73579
  for (let i4 = 16; i4 < 64; i4++) {
74223
- const W15 = SHA256_W6[i4 - 15];
74224
- const W2 = SHA256_W6[i4 - 2];
74225
- const s0 = rotr6(W15, 7) ^ rotr6(W15, 18) ^ W15 >>> 3;
74226
- const s1 = rotr6(W2, 17) ^ rotr6(W2, 19) ^ W2 >>> 10;
74227
- SHA256_W6[i4] = s1 + SHA256_W6[i4 - 7] + s0 + SHA256_W6[i4 - 16] | 0;
73580
+ const W15 = SHA256_W5[i4 - 15];
73581
+ const W2 = SHA256_W5[i4 - 2];
73582
+ const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
73583
+ const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
73584
+ SHA256_W5[i4] = s1 + SHA256_W5[i4 - 7] + s0 + SHA256_W5[i4 - 16] | 0;
74228
73585
  }
74229
73586
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
74230
73587
  for (let i4 = 0; i4 < 64; i4++) {
74231
- const sigma1 = rotr6(E, 6) ^ rotr6(E, 11) ^ rotr6(E, 25);
74232
- const T1 = H + sigma1 + Chi6(E, F, G2) + SHA256_K6[i4] + SHA256_W6[i4] | 0;
74233
- const sigma0 = rotr6(A, 2) ^ rotr6(A, 13) ^ rotr6(A, 22);
74234
- const T2 = sigma0 + Maj6(A, B, C2) | 0;
73588
+ const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
73589
+ const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i4] + SHA256_W5[i4] | 0;
73590
+ const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
73591
+ const T2 = sigma0 + Maj5(A, B, C2) | 0;
74235
73592
  H = G2;
74236
73593
  G2 = F;
74237
73594
  F = E;
@@ -74252,14 +73609,14 @@ var BTCR2 = (() => {
74252
73609
  this.set(A, B, C2, D, E, F, G2, H);
74253
73610
  }
74254
73611
  roundClean() {
74255
- SHA256_W6.fill(0);
73612
+ SHA256_W5.fill(0);
74256
73613
  }
74257
73614
  destroy() {
74258
73615
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
74259
73616
  this.buffer.fill(0);
74260
73617
  }
74261
73618
  };
74262
- var sha2567 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
73619
+ var sha2566 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
74263
73620
 
74264
73621
  // ../../node_modules/.pnpm/@noble+curves@1.3.0/node_modules/@noble/curves/esm/abstract/modular.js
74265
73622
  init_shim();
@@ -74280,7 +73637,7 @@ var BTCR2 = (() => {
74280
73637
  equalBytes: () => equalBytes7,
74281
73638
  hexToBytes: () => hexToBytes4,
74282
73639
  hexToNumber: () => hexToNumber3,
74283
- isBytes: () => isBytes10,
73640
+ isBytes: () => isBytes9,
74284
73641
  numberToBytesBE: () => numberToBytesBE4,
74285
73642
  numberToBytesLE: () => numberToBytesLE3,
74286
73643
  numberToHexUnpadded: () => numberToHexUnpadded3,
@@ -74292,12 +73649,12 @@ var BTCR2 = (() => {
74292
73649
  var _0n11 = BigInt(0);
74293
73650
  var _1n11 = BigInt(1);
74294
73651
  var _2n8 = BigInt(2);
74295
- function isBytes10(a3) {
73652
+ function isBytes9(a3) {
74296
73653
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
74297
73654
  }
74298
73655
  var hexes4 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
74299
73656
  function bytesToHex4(bytes6) {
74300
- if (!isBytes10(bytes6))
73657
+ if (!isBytes9(bytes6))
74301
73658
  throw new Error("Uint8Array expected");
74302
73659
  let hex3 = "";
74303
73660
  for (let i4 = 0; i4 < bytes6.length; i4++) {
@@ -74347,7 +73704,7 @@ var BTCR2 = (() => {
74347
73704
  return hexToNumber3(bytesToHex4(bytes6));
74348
73705
  }
74349
73706
  function bytesToNumberLE3(bytes6) {
74350
- if (!isBytes10(bytes6))
73707
+ if (!isBytes9(bytes6))
74351
73708
  throw new Error("Uint8Array expected");
74352
73709
  return hexToNumber3(bytesToHex4(Uint8Array.from(bytes6).reverse()));
74353
73710
  }
@@ -74368,7 +73725,7 @@ var BTCR2 = (() => {
74368
73725
  } catch (e2) {
74369
73726
  throw new Error(`${title} must be valid hex string, got "${hex3}". Cause: ${e2}`);
74370
73727
  }
74371
- } else if (isBytes10(hex3)) {
73728
+ } else if (isBytes9(hex3)) {
74372
73729
  res = Uint8Array.from(hex3);
74373
73730
  } else {
74374
73731
  throw new Error(`${title} must be hex string or Uint8Array`);
@@ -74382,7 +73739,7 @@ var BTCR2 = (() => {
74382
73739
  let sum = 0;
74383
73740
  for (let i4 = 0; i4 < arrays.length; i4++) {
74384
73741
  const a3 = arrays[i4];
74385
- if (!isBytes10(a3))
73742
+ if (!isBytes9(a3))
74386
73743
  throw new Error("Uint8Array expected");
74387
73744
  sum += a3.length;
74388
73745
  }
@@ -74476,7 +73833,7 @@ var BTCR2 = (() => {
74476
73833
  function: (val) => typeof val === "function",
74477
73834
  boolean: (val) => typeof val === "boolean",
74478
73835
  string: (val) => typeof val === "string",
74479
- stringOrUint8Array: (val) => typeof val === "string" || isBytes10(val),
73836
+ stringOrUint8Array: (val) => typeof val === "string" || isBytes9(val),
74480
73837
  isSafeInteger: (val) => Number.isSafeInteger(val),
74481
73838
  array: (val) => Array.isArray(val),
74482
73839
  field: (val, object2) => object2.Fp.isValid(val),
@@ -74947,7 +74304,7 @@ var BTCR2 = (() => {
74947
74304
  toSig(hex3) {
74948
74305
  const { Err: E } = DER3;
74949
74306
  const data = typeof hex3 === "string" ? h2b2(hex3) : hex3;
74950
- if (!isBytes10(data))
74307
+ if (!isBytes9(data))
74951
74308
  throw new Error("ui8a expected");
74952
74309
  let l2 = data.length;
74953
74310
  if (l2 < 2 || data[0] != 48)
@@ -75011,7 +74368,7 @@ var BTCR2 = (() => {
75011
74368
  function normPrivateKeyToScalar(key) {
75012
74369
  const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: n3 } = CURVE2;
75013
74370
  if (lengths && typeof key !== "bigint") {
75014
- if (isBytes10(key))
74371
+ if (isBytes9(key))
75015
74372
  key = bytesToHex4(key);
75016
74373
  if (typeof key !== "string" || !lengths.includes(key.length))
75017
74374
  throw new Error("Invalid key");
@@ -75546,7 +74903,7 @@ var BTCR2 = (() => {
75546
74903
  return Point7.fromPrivateKey(privateKey).toRawBytes(isCompressed);
75547
74904
  }
75548
74905
  function isProbPub(item) {
75549
- const arr = isBytes10(item);
74906
+ const arr = isBytes9(item);
75550
74907
  const str = typeof item === "string";
75551
74908
  const len = (arr || str) && item.length;
75552
74909
  if (arr)
@@ -75641,7 +74998,7 @@ var BTCR2 = (() => {
75641
74998
  let _sig = void 0;
75642
74999
  let P3;
75643
75000
  try {
75644
- if (typeof sg === "string" || isBytes10(sg)) {
75001
+ if (typeof sg === "string" || isBytes9(sg)) {
75645
75002
  try {
75646
75003
  _sig = Signature.fromDER(sg);
75647
75004
  } catch (derError) {
@@ -75846,7 +75203,7 @@ var BTCR2 = (() => {
75846
75203
  return { k1neg, k1, k2neg, k2 };
75847
75204
  }
75848
75205
  }
75849
- }, sha2567);
75206
+ }, sha2566);
75850
75207
  var _0n15 = BigInt(0);
75851
75208
  var Point5 = secp256k13.ProjectivePoint;
75852
75209
 
@@ -76531,7 +75888,7 @@ var BTCR2 = (() => {
76531
75888
  static sign(_a3) {
76532
75889
  return __awaiter6(this, arguments, void 0, function* ({ data, key }) {
76533
75890
  const privateKeyBytes = yield _Secp256k1.privateKeyToBytes({ privateKey: key });
76534
- const digest2 = sha2566(data);
75891
+ const digest2 = sha2565(data);
76535
75892
  const signatureObject = secp256k13.sign(digest2, privateKeyBytes);
76536
75893
  const signature2 = signatureObject.toCompactRawBytes();
76537
75894
  return signature2;
@@ -76643,7 +76000,7 @@ var BTCR2 = (() => {
76643
76000
  static verify(_a3) {
76644
76001
  return __awaiter6(this, arguments, void 0, function* ({ key, signature: signature2, data }) {
76645
76002
  const publicKeyBytes = yield _Secp256k1.publicKeyToBytes({ publicKey: key });
76646
- const digest2 = sha2566(data);
76003
+ const digest2 = sha2565(data);
76647
76004
  const isValid2 = secp256k13.verify(signature2, digest2, publicKeyBytes, { lowS: false });
76648
76005
  return isValid2;
76649
76006
  });
@@ -76715,7 +76072,7 @@ var BTCR2 = (() => {
76715
76072
  Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
76716
76073
  h: BigInt(1),
76717
76074
  lowS: false
76718
- }, sha2567);
76075
+ }, sha2566);
76719
76076
  var secp256r1 = p256;
76720
76077
 
76721
76078
  // ../../node_modules/.pnpm/@web5+crypto@1.0.6/node_modules/@web5/crypto/dist/esm/primitives/secp256r1.js
@@ -77258,7 +76615,7 @@ var BTCR2 = (() => {
77258
76615
  static sign(_a3) {
77259
76616
  return __awaiter7(this, arguments, void 0, function* ({ data, key }) {
77260
76617
  const privateKeyBytes = yield _Secp256r1.privateKeyToBytes({ privateKey: key });
77261
- const digest2 = sha2566(data);
76618
+ const digest2 = sha2565(data);
77262
76619
  const signatureObject = secp256r1.sign(digest2, privateKeyBytes);
77263
76620
  const signature2 = signatureObject.toCompactRawBytes();
77264
76621
  return signature2;
@@ -77370,7 +76727,7 @@ var BTCR2 = (() => {
77370
76727
  static verify(_a3) {
77371
76728
  return __awaiter7(this, arguments, void 0, function* ({ key, signature: signature2, data }) {
77372
76729
  const publicKeyBytes = yield _Secp256r1.publicKeyToBytes({ publicKey: key });
77373
- const digest2 = sha2566(data);
76730
+ const digest2 = sha2565(data);
77374
76731
  const isValid2 = secp256r1.verify(signature2, digest2, publicKeyBytes, { lowS: false });
77375
76732
  return isValid2;
77376
76733
  });
@@ -84553,7 +83910,7 @@ var BTCR2 = (() => {
84553
83910
  */
84554
83911
  async (data) => new Uint8Array(await crypto.subtle.digest(name10, data))
84555
83912
  );
84556
- var sha2568 = from5({
83913
+ var sha2567 = from5({
84557
83914
  name: "sha2-256",
84558
83915
  code: 18,
84559
83916
  encode: sha("SHA-256")
@@ -84603,7 +83960,7 @@ var BTCR2 = (() => {
84603
83960
  let multihash;
84604
83961
  switch (hashAlgorithmInMultihashCode) {
84605
83962
  case 18:
84606
- let hasher = yield sha2568.digest(content);
83963
+ let hasher = yield sha2567.digest(content);
84607
83964
  multihash = hasher.bytes;
84608
83965
  break;
84609
83966
  default:
@@ -84622,7 +83979,7 @@ var BTCR2 = (() => {
84622
83979
  let hash4;
84623
83980
  switch (hashAlgorithmInMultihashCode) {
84624
83981
  case 18:
84625
- hash4 = yield sha2568.encode(content);
83982
+ hash4 = yield sha2567.encode(content);
84626
83983
  break;
84627
83984
  default:
84628
83985
  throw new IonError(ErrorCode_default.MultihashUnsupportedHashAlgorithm, `Hash algorithm defined in multihash code ${hashAlgorithmInMultihashCode} is not supported.`);
@@ -85045,12 +84402,12 @@ var BTCR2 = (() => {
85045
84402
  };
85046
84403
  var isBig = (n3) => typeof n3 === "bigint";
85047
84404
  var isStr = (s2) => typeof s2 === "string";
85048
- var isBytes11 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
85049
- var abytes4 = (a3, l2) => !isBytes11(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
84405
+ var isBytes10 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
84406
+ var abytes3 = (a3, l2) => !isBytes10(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
85050
84407
  var u8n3 = (len) => new Uint8Array(len);
85051
84408
  var u8fr3 = (buf2) => Uint8Array.from(buf2);
85052
84409
  var padh = (n3, pad2) => n3.toString(16).padStart(pad2, "0");
85053
- var bytesToHex5 = (b2) => Array.from(abytes4(b2)).map((e2) => padh(e2, 2)).join("");
84410
+ var bytesToHex5 = (b2) => Array.from(abytes3(b2)).map((e2) => padh(e2, 2)).join("");
85054
84411
  var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
85055
84412
  var _ch = (ch) => {
85056
84413
  if (ch >= C._0 && ch <= C._9)
@@ -85079,10 +84436,10 @@ var BTCR2 = (() => {
85079
84436
  }
85080
84437
  return array2;
85081
84438
  };
85082
- var toU8 = (a3, len) => abytes4(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes4(a3)), len);
84439
+ var toU8 = (a3, len) => abytes3(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes3(a3)), len);
85083
84440
  var cr = () => globalThis?.crypto;
85084
84441
  var concatBytes10 = (...arrs) => {
85085
- const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes4(a3).length, 0));
84442
+ const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes3(a3).length, 0));
85086
84443
  let pad2 = 0;
85087
84444
  arrs.forEach((a3) => {
85088
84445
  r2.set(a3, pad2);
@@ -85143,7 +84500,7 @@ var BTCR2 = (() => {
85143
84500
  }
85144
84501
  /** Convert Uint8Array or hex string to Point. */
85145
84502
  static fromBytes(bytes6) {
85146
- abytes4(bytes6);
84503
+ abytes3(bytes6);
85147
84504
  let p3 = void 0;
85148
84505
  const head = bytes6[0];
85149
84506
  const tail = bytes6.subarray(1);
@@ -87322,7 +86679,7 @@ var BTCR2 = (() => {
87322
86679
  // ../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/hashes/sha2-browser.js
87323
86680
  var sha2_browser_exports = {};
87324
86681
  __export(sha2_browser_exports, {
87325
- sha256: () => sha2569,
86682
+ sha256: () => sha2568,
87326
86683
  sha512: () => sha5124
87327
86684
  });
87328
86685
  init_shim();
@@ -87380,7 +86737,7 @@ var BTCR2 = (() => {
87380
86737
  function sha2(name10) {
87381
86738
  return async (data) => new Uint8Array(await crypto.subtle.digest(name10, data));
87382
86739
  }
87383
- var sha2569 = from6({
86740
+ var sha2568 = from6({
87384
86741
  name: "sha2-256",
87385
86742
  code: 18,
87386
86743
  encode: sha2("SHA-256")
@@ -87697,7 +87054,7 @@ var BTCR2 = (() => {
87697
87054
  }
87698
87055
  async add(string4, options2 = {}) {
87699
87056
  const buf2 = fromString2(string4);
87700
- const hash4 = await (options2.hasher ?? sha2569).digest(buf2);
87057
+ const hash4 = await (options2.hasher ?? sha2568).digest(buf2);
87701
87058
  const codec2 = options2.codec ?? raw_exports;
87702
87059
  const cid = CID2.createV1(codec2.code, hash4);
87703
87060
  await this.components.blockstore.put(cid, buf2, options2);
@@ -91756,7 +91113,7 @@ var BTCR2 = (() => {
91756
91113
  * @param {string | Uint8Array} s
91757
91114
  * @param {boolean} [clean]
91758
91115
  */
91759
- constructor(s2, clean4) {
91116
+ constructor(s2, clean3) {
91760
91117
  if (typeof s2 === "string") {
91761
91118
  this._buf = fromString2(s2);
91762
91119
  } else if (s2 instanceof Uint8Array) {
@@ -91764,10 +91121,10 @@ var BTCR2 = (() => {
91764
91121
  } else {
91765
91122
  throw new Error("Invalid key, should be String of Uint8Array");
91766
91123
  }
91767
- if (clean4 == null) {
91768
- clean4 = true;
91124
+ if (clean3 == null) {
91125
+ clean3 = true;
91769
91126
  }
91770
- if (clean4) {
91127
+ if (clean3) {
91771
91128
  this.clean();
91772
91129
  }
91773
91130
  if (this._buf.byteLength === 0 || this._buf[0] !== pathSep) {
@@ -95279,7 +94636,7 @@ var BTCR2 = (() => {
95279
94636
  init_shim();
95280
94637
  function getHasher(initialHashers = [], loadHasher) {
95281
94638
  const hashers = {
95282
- [sha2569.code]: sha2569,
94639
+ [sha2568.code]: sha2568,
95283
94640
  [sha5124.code]: sha5124,
95284
94641
  [identity2.code]: identity2
95285
94642
  };
@@ -99753,7 +99110,7 @@ var BTCR2 = (() => {
99753
99110
  init_shim();
99754
99111
  var PRIVATE_KEY_BYTE_LENGTH2 = 32;
99755
99112
  function hashAndSign4(key, msg, options2) {
99756
- const p3 = sha2569.digest(msg instanceof Uint8Array ? msg : msg.subarray());
99113
+ const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
99757
99114
  if (isPromise3(p3)) {
99758
99115
  return p3.then(({ digest: digest2 }) => {
99759
99116
  options2?.signal?.throwIfAborted();
@@ -99772,7 +99129,7 @@ var BTCR2 = (() => {
99772
99129
  }
99773
99130
  }
99774
99131
  function hashAndVerify4(key, sig, msg, options2) {
99775
- const p3 = sha2569.digest(msg instanceof Uint8Array ? msg : msg.subarray());
99132
+ const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
99776
99133
  if (isPromise3(p3)) {
99777
99134
  return p3.then(({ digest: digest2 }) => {
99778
99135
  options2?.signal?.throwIfAborted();
@@ -102079,7 +101436,7 @@ var BTCR2 = (() => {
102079
101436
  return multihash.code === identity2.code;
102080
101437
  }
102081
101438
  function isSha256Multihash(multihash) {
102082
- return multihash.code === sha2569.code;
101439
+ return multihash.code === sha2568.code;
102083
101440
  }
102084
101441
 
102085
101442
  // ../../node_modules/.pnpm/@libp2p+peer-collections@6.0.35/node_modules/@libp2p/peer-collections/dist/src/util.js
@@ -102937,7 +102294,7 @@ var BTCR2 = (() => {
102937
102294
  const cidVersion = values[0];
102938
102295
  const multicodec2 = values[1];
102939
102296
  const hashAlg = values[2];
102940
- const hasher = hashAlg === sha2569.code ? sha2569 : await this.hashLoader?.getHasher(hashAlg);
102297
+ const hasher = hashAlg === sha2568.code ? sha2568 : await this.hashLoader?.getHasher(hashAlg);
102941
102298
  if (hasher == null) {
102942
102299
  this.log.error("unknown hash algorithm", hashAlg);
102943
102300
  continue;
@@ -117247,7 +116604,7 @@ ${values.join("\n")}` : `${blockName} :`;
117247
116604
  }
117248
116605
  async function keyId(key) {
117249
116606
  const pb = privateKeyToProtobuf(key);
117250
- const hash4 = await sha2569.digest(pb);
116607
+ const hash4 = await sha2568.digest(pb);
117251
116608
  return base58btc.encode(hash4.bytes).substring(1);
117252
116609
  }
117253
116610
  var Keychain = class {
@@ -117600,7 +116957,7 @@ ${values.join("\n")}` : `${blockName} :`;
117600
116957
 
117601
116958
  // ../../node_modules/.pnpm/@noble+ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js
117602
116959
  init_shim();
117603
- function isBytes12(a3) {
116960
+ function isBytes11(a3) {
117604
116961
  return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
117605
116962
  }
117606
116963
  function abool2(b2) {
@@ -117611,20 +116968,20 @@ ${values.join("\n")}` : `${blockName} :`;
117611
116968
  if (!Number.isSafeInteger(n3) || n3 < 0)
117612
116969
  throw new Error("positive integer expected, got " + n3);
117613
116970
  }
117614
- function abytes5(b2, ...lengths) {
117615
- if (!isBytes12(b2))
116971
+ function abytes4(b2, ...lengths) {
116972
+ if (!isBytes11(b2))
117616
116973
  throw new Error("Uint8Array expected");
117617
116974
  if (lengths.length > 0 && !lengths.includes(b2.length))
117618
116975
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
117619
116976
  }
117620
- function aexists3(instance3, checkFinished = true) {
116977
+ function aexists2(instance3, checkFinished = true) {
117621
116978
  if (instance3.destroyed)
117622
116979
  throw new Error("Hash instance has been destroyed");
117623
116980
  if (checkFinished && instance3.finished)
117624
116981
  throw new Error("Hash#digest() has already been called");
117625
116982
  }
117626
- function aoutput3(out, instance3) {
117627
- abytes5(out);
116983
+ function aoutput2(out, instance3) {
116984
+ abytes4(out);
117628
116985
  const min = instance3.outputLen;
117629
116986
  if (out.length < min) {
117630
116987
  throw new Error("digestInto() expects output buffer of length at least " + min);
@@ -117633,12 +116990,12 @@ ${values.join("\n")}` : `${blockName} :`;
117633
116990
  function u322(arr) {
117634
116991
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
117635
116992
  }
117636
- function clean3(...arrays) {
116993
+ function clean2(...arrays) {
117637
116994
  for (let i4 = 0; i4 < arrays.length; i4++) {
117638
116995
  arrays[i4].fill(0);
117639
116996
  }
117640
116997
  }
117641
- function createView9(arr) {
116998
+ function createView8(arr) {
117642
116999
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
117643
117000
  }
117644
117001
  var isLE6 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
@@ -117650,7 +117007,7 @@ ${values.join("\n")}` : `${blockName} :`;
117650
117007
  function toBytes7(data) {
117651
117008
  if (typeof data === "string")
117652
117009
  data = utf8ToBytes10(data);
117653
- else if (isBytes12(data))
117010
+ else if (isBytes11(data))
117654
117011
  data = copyBytes2(data);
117655
117012
  else
117656
117013
  throw new Error("Uint8Array expected, got " + typeof data);
@@ -117672,7 +117029,7 @@ ${values.join("\n")}` : `${blockName} :`;
117672
117029
  }
117673
117030
  var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
117674
117031
  function wrappedCipher(key, ...args) {
117675
- abytes5(key);
117032
+ abytes4(key);
117676
117033
  if (!isLE6)
117677
117034
  throw new Error("Non little-endian hardware is not yet supported");
117678
117035
  if (params.nonceLength !== void 0) {
@@ -117680,20 +117037,20 @@ ${values.join("\n")}` : `${blockName} :`;
117680
117037
  if (!nonce)
117681
117038
  throw new Error("nonce / iv required");
117682
117039
  if (params.varSizeNonce)
117683
- abytes5(nonce);
117040
+ abytes4(nonce);
117684
117041
  else
117685
- abytes5(nonce, params.nonceLength);
117042
+ abytes4(nonce, params.nonceLength);
117686
117043
  }
117687
117044
  const tagl = params.tagLength;
117688
117045
  if (tagl && args[1] !== void 0) {
117689
- abytes5(args[1]);
117046
+ abytes4(args[1]);
117690
117047
  }
117691
117048
  const cipher = constructor(key, ...args);
117692
117049
  const checkOutput = (fnLength, output6) => {
117693
117050
  if (output6 !== void 0) {
117694
117051
  if (fnLength !== 2)
117695
117052
  throw new Error("cipher output not supported");
117696
- abytes5(output6);
117053
+ abytes4(output6);
117697
117054
  }
117698
117055
  };
117699
117056
  let called = false;
@@ -117702,12 +117059,12 @@ ${values.join("\n")}` : `${blockName} :`;
117702
117059
  if (called)
117703
117060
  throw new Error("cannot encrypt() twice with same key + nonce");
117704
117061
  called = true;
117705
- abytes5(data);
117062
+ abytes4(data);
117706
117063
  checkOutput(cipher.encrypt.length, output6);
117707
117064
  return cipher.encrypt(data, output6);
117708
117065
  },
117709
117066
  decrypt(data, output6) {
117710
- abytes5(data);
117067
+ abytes4(data);
117711
117068
  if (tagl && data.length < tagl)
117712
117069
  throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
117713
117070
  checkOutput(cipher.decrypt.length, output6);
@@ -117743,7 +117100,7 @@ ${values.join("\n")}` : `${blockName} :`;
117743
117100
  function u64Lengths(dataLength, aadLength, isLE7) {
117744
117101
  abool2(isLE7);
117745
117102
  const num2 = new Uint8Array(16);
117746
- const view = createView9(num2);
117103
+ const view = createView8(num2);
117747
117104
  setBigUint647(view, 0, BigInt(aadLength), isLE7);
117748
117105
  setBigUint647(view, 8, BigInt(dataLength), isLE7);
117749
117106
  return num2;
@@ -117810,13 +117167,13 @@ ${values.join("\n")}` : `${blockName} :`;
117810
117167
  abool2(counterRight);
117811
117168
  abool2(allowShortKeys);
117812
117169
  return (key, nonce, data, output6, counter = 0) => {
117813
- abytes5(key);
117814
- abytes5(nonce);
117815
- abytes5(data);
117170
+ abytes4(key);
117171
+ abytes4(nonce);
117172
+ abytes4(data);
117816
117173
  const len = data.length;
117817
117174
  if (output6 === void 0)
117818
117175
  output6 = new Uint8Array(len);
117819
- abytes5(output6);
117176
+ abytes4(output6);
117820
117177
  anumber3(counter);
117821
117178
  if (counter < 0 || counter >= MAX_COUNTER2)
117822
117179
  throw new Error("arx: counter overflow");
@@ -117858,7 +117215,7 @@ ${values.join("\n")}` : `${blockName} :`;
117858
117215
  }
117859
117216
  const n32 = u322(nonce);
117860
117217
  runCipher2(core, sigma2, k32, n32, data, output6, counter, rounds);
117861
- clean3(...toClean);
117218
+ clean2(...toClean);
117862
117219
  return output6;
117863
117220
  };
117864
117221
  }
@@ -117877,7 +117234,7 @@ ${values.join("\n")}` : `${blockName} :`;
117877
117234
  this.pos = 0;
117878
117235
  this.finished = false;
117879
117236
  key = toBytes7(key);
117880
- abytes5(key, 32);
117237
+ abytes4(key, 32);
117881
117238
  const t0 = u8to162(key, 0);
117882
117239
  const t1 = u8to162(key, 2);
117883
117240
  const t2 = u8to162(key, 4);
@@ -118053,12 +117410,12 @@ ${values.join("\n")}` : `${blockName} :`;
118053
117410
  f2 = (h2[i4] + pad2[i4] | 0) + (f2 >>> 16) | 0;
118054
117411
  h2[i4] = f2 & 65535;
118055
117412
  }
118056
- clean3(g);
117413
+ clean2(g);
118057
117414
  }
118058
117415
  update(data) {
118059
- aexists3(this);
117416
+ aexists2(this);
118060
117417
  data = toBytes7(data);
118061
- abytes5(data);
117418
+ abytes4(data);
118062
117419
  const { buffer: buffer2, blockLen } = this;
118063
117420
  const len = data.length;
118064
117421
  for (let pos = 0; pos < len; ) {
@@ -118079,11 +117436,11 @@ ${values.join("\n")}` : `${blockName} :`;
118079
117436
  return this;
118080
117437
  }
118081
117438
  destroy() {
118082
- clean3(this.h, this.r, this.buffer, this.pad);
117439
+ clean2(this.h, this.r, this.buffer, this.pad);
118083
117440
  }
118084
117441
  digestInto(out) {
118085
- aexists3(this);
118086
- aoutput3(out, this);
117442
+ aexists2(this);
117443
+ aoutput2(out, this);
118087
117444
  this.finished = true;
118088
117445
  const { buffer: buffer2, h: h2 } = this;
118089
117446
  let { pos } = this;
@@ -118313,7 +117670,7 @@ ${values.join("\n")}` : `${blockName} :`;
118313
117670
  const num2 = u64Lengths(data.length, AAD ? AAD.length : 0, true);
118314
117671
  h2.update(num2);
118315
117672
  const res = h2.digest();
118316
- clean3(authKey, num2);
117673
+ clean2(authKey, num2);
118317
117674
  return res;
118318
117675
  }
118319
117676
  var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
@@ -118327,7 +117684,7 @@ ${values.join("\n")}` : `${blockName} :`;
118327
117684
  xorStream(key, nonce, oPlain, oPlain, 1);
118328
117685
  const tag = computeTag3(xorStream, key, nonce, oPlain, AAD);
118329
117686
  output6.set(tag, plength);
118330
- clean3(tag);
117687
+ clean2(tag);
118331
117688
  return output6;
118332
117689
  },
118333
117690
  decrypt(ciphertext, output6) {
@@ -118339,7 +117696,7 @@ ${values.join("\n")}` : `${blockName} :`;
118339
117696
  throw new Error("invalid tag");
118340
117697
  output6.set(ciphertext.subarray(0, -tagLength));
118341
117698
  xorStream(key, nonce, output6, output6, 1);
118342
- clean3(tag);
117699
+ clean2(tag);
118343
117700
  return output6;
118344
117701
  }
118345
117702
  };
@@ -125062,7 +124419,7 @@ ${values.join("\n")}` : `${blockName} :`;
125062
124419
  };
125063
124420
  }
125064
124421
  async function convertBuffer(buf2, options2) {
125065
- const multihash = await sha2569.digest(buf2);
124422
+ const multihash = await sha2568.digest(buf2);
125066
124423
  options2?.signal?.throwIfAborted();
125067
124424
  return multihash.digest;
125068
124425
  }
@@ -144260,7 +143617,7 @@ ${values.join("\n")}` : `${blockName} :`;
144260
143617
  const keyPrefix2 = generated_prefix_list_browser_default[targetPrefix];
144261
143618
  const keyBuffer = new ArrayBuffer(34);
144262
143619
  const keyView = new DataView(keyBuffer, 0, keyBuffer.byteLength);
144263
- keyView.setUint8(0, sha2569.code);
143620
+ keyView.setUint8(0, sha2568.code);
144264
143621
  keyView.setUint8(1, 32);
144265
143622
  keyView.setUint32(2, keyPrefix2, false);
144266
143623
  return new Uint8Array(keyView.buffer, keyView.byteOffset, keyView.byteLength);
@@ -151082,7 +150439,7 @@ ${values.join("\n")}` : `${blockName} :`;
151082
150439
  var md4 = create6(id_md5);
151083
150440
  var sha13 = create6(id_sha1);
151084
150441
  var sha2243 = create6(id_sha224);
151085
- var sha25610 = create6(id_sha256);
150442
+ var sha2569 = create6(id_sha256);
151086
150443
  var sha3842 = create6(id_sha384);
151087
150444
  var sha5126 = create6(id_sha512);
151088
150445
  var sha512_2242 = create6(id_sha512_224);
@@ -155201,7 +154558,7 @@ ${values.join("\n")}` : `${blockName} :`;
155201
154558
  function fingerprint2Ma(fingerprint) {
155202
154559
  const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
155203
154560
  const encoded = Uint8Array.from(output6);
155204
- const digest2 = create3(sha2569.code, encoded);
154561
+ const digest2 = create3(sha2568.code, encoded);
155205
154562
  return multiaddr(`/certhash/${base64url4.encode(digest2.bytes)}`);
155206
154563
  }
155207
154564
  function toSupportedHashFunction(code8) {
@@ -155280,7 +154637,7 @@ a=end-of-candidates
155280
154637
  function generateNoisePrologue(localFingerprint, remoteAddr, role) {
155281
154638
  const localFpString = localFingerprint.trim().toLowerCase().replaceAll(":", "");
155282
154639
  const localFpArray = fromString2(localFpString, "hex");
155283
- const local = create3(sha2569.code, localFpArray);
154640
+ const local = create3(sha2568.code, localFpArray);
155284
154641
  const remote = multibaseDecoder.decode(certhash(remoteAddr));
155285
154642
  const byteLength = PREFIX.byteLength + local.bytes.byteLength + remote.byteLength;
155286
154643
  if (role === "server") {
@@ -155611,7 +154968,7 @@ a=end-of-candidates
155611
154968
  }, renewTime);
155612
154969
  return {
155613
154970
  pem: cert.toString("pem"),
155614
- certhash: base64url4.encode((await sha2569.digest(new Uint8Array(cert.rawData))).bytes)
154971
+ certhash: base64url4.encode((await sha2568.digest(new Uint8Array(cert.rawData))).bytes)
155615
154972
  };
155616
154973
  }
155617
154974
  async loadCertificate(dsKey, keyPair) {
@@ -156373,13 +155730,12 @@ a=end-of-candidates
156373
155730
  * ```
156374
155731
  */
156375
155732
  static deriveRootCapability(identifier) {
156376
- const rootCapability = {};
156377
- rootCapability["@context"] = W3C_ZCAP_V1;
156378
- const encodedIdentifier = encodeURIComponent(identifier);
156379
- rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
156380
- rootCapability.controller = identifier;
156381
- rootCapability.invocationTarget = identifier;
156382
- return rootCapability;
155733
+ return {
155734
+ "@context": "https://w3id.org/zcap/v1",
155735
+ id: `urn:zcap:root:${encodeURIComponent(identifier)}`,
155736
+ controller: identifier,
155737
+ invocationTarget: identifier
155738
+ };
156383
155739
  }
156384
155740
  /**
156385
155741
  * Implements {@link https://dcdpr.github.io/did-btcr2/#dereference-root-capability-identifier | 9.4.2 Dereference Root Capability Identifier}.
@@ -156479,7 +155835,6 @@ a=end-of-candidates
156479
155835
  if (!Appendix.isDidService(obj)) return false;
156480
155836
  if (!["SingletonBeacon", "CASBeacon", "SMTBeacon"].includes(obj.type)) return false;
156481
155837
  if ([obj.serviceEndpoint].flat().some((ep) => typeof ep === "string" && !ep.startsWith("bitcoin:"))) return false;
156482
- if (obj.casType && typeof obj.casType !== "string") return false;
156483
155838
  return true;
156484
155839
  }
156485
155840
  /**
@@ -156504,8 +155859,11 @@ a=end-of-candidates
156504
155859
  (addrType) => this.createBeaconService(did, addrType, beaconType)
156505
155860
  );
156506
155861
  } catch (error) {
156507
- console.error(error);
156508
- import_process.default.exit(1);
155862
+ throw new BeaconError(
155863
+ "Failed to create beacon services: " + error.message,
155864
+ "BEACON_SERVICE_ERROR",
155865
+ { did, beaconType }
155866
+ );
156509
155867
  }
156510
155868
  }
156511
155869
  /**
@@ -156525,8 +155883,11 @@ a=end-of-candidates
156525
155883
  const serviceEndpoint = `bitcoin:${payments_exports[addressType]({ pubkey, network }).address}`;
156526
155884
  return { id, type: beaconType, serviceEndpoint };
156527
155885
  } catch (error) {
156528
- console.error(error);
156529
- import_process.default.exit(1);
155886
+ throw new BeaconError(
155887
+ "Failed to create beacon service: " + error.message,
155888
+ "BEACON_SERVICE_ERROR",
155889
+ { did, beaconType }
155890
+ );
156530
155891
  }
156531
155892
  }
156532
155893
  /**
@@ -156561,8 +155922,11 @@ a=end-of-candidates
156561
155922
  }
156562
155923
  ];
156563
155924
  } catch (error) {
156564
- console.error(error);
156565
- import_process.default.exit(1);
155925
+ throw new BeaconError(
155926
+ "Failed to create beacon services: " + error.message,
155927
+ "BEACON_SERVICE_ERROR",
155928
+ { id, publicKey: publicKey2, network, beaconType }
155929
+ );
156566
155930
  }
156567
155931
  }
156568
155932
  /**
@@ -156616,9 +155980,9 @@ a=end-of-candidates
156616
155980
  }
156617
155981
  /**
156618
155982
  * Add a proof to a document.
156619
- * @param {BTCR2UnsignedUpdate} unsignedDocument The document to add the proof to.
155983
+ * @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
156620
155984
  * @param {DataIntegrityConfig} config The configuration for generating the proof.
156621
- * @returns {BTCR2SignedUpdate} A document with a proof added.
155985
+ * @returns {SignedBTCR2Update} A document with a proof added.
156622
155986
  */
156623
155987
  addProof(unsignedDocument, config) {
156624
155988
  const proof = this.cryptosuite.createProof(unsignedDocument, config);
@@ -156733,7 +156097,7 @@ a=end-of-candidates
156733
156097
  }
156734
156098
  /**
156735
156099
  * Verify a proof for a secure document.
156736
- * @param {BTCR2SignedUpdate} secureDocument The secure document to verify.
156100
+ * @param {SignedBTCR2Update} secureDocument The secure document to verify.
156737
156101
  * @returns {VerificationResult} The result of the verification.
156738
156102
  */
156739
156103
  verifyProof(secureDocument) {
@@ -156748,7 +156112,7 @@ a=end-of-candidates
156748
156112
  }
156749
156113
  /**
156750
156114
  * Transform a document into canonical form.
156751
- * @param {BTCR2UnsignedUpdate | BTCR2SignedUpdate} document The document to transform.
156115
+ * @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
156752
156116
  * @param {DataIntegrityConfig} config The config to use when transforming the document.
156753
156117
  * @returns {string} The canonicalized document.
156754
156118
  * @throws {MethodError} if the document cannot be transformed.
@@ -156853,29 +156217,27 @@ a=end-of-candidates
156853
156217
  * @param {MultikeyParams} params The parameters to create the multikey
156854
156218
  * @param {string} params.id The id of the multikey (required)
156855
156219
  * @param {string} params.controller The controller of the multikey (required)
156856
- * @param {Keys} params.keys The Keys of the multikey (optional, required if no publicKey)
156857
- * @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
156858
- * @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
156220
+ * @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
156859
156221
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
156860
156222
  */
156861
- constructor({ id, controller, keys }) {
156862
- if (!keys) {
156863
- throw new MultikeyError('Argument missing: "keys" required', "CONSTRUCTOR_ERROR");
156223
+ constructor({ id, controller, keyPair }) {
156224
+ if (!keyPair) {
156225
+ throw new MultikeyError('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
156864
156226
  }
156865
- if (!keys.publicKey) {
156866
- throw new MultikeyError('Argument missing: "keys" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
156227
+ if (!keyPair.publicKey) {
156228
+ throw new MultikeyError('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
156867
156229
  }
156868
156230
  this.id = id;
156869
156231
  this.controller = controller;
156870
- this.#keyPair = keys;
156232
+ this.#keyPair = keyPair;
156871
156233
  }
156872
156234
  /**
156873
156235
  * @readonly
156874
156236
  * Get the SchnorrKeyPair.
156875
156237
  */
156876
156238
  get keyPair() {
156877
- const keys = this.#keyPair;
156878
- return keys;
156239
+ const keyPair = this.#keyPair;
156240
+ return keyPair;
156879
156241
  }
156880
156242
  /**
156881
156243
  * @readonly
@@ -156982,9 +156344,10 @@ a=end-of-candidates
156982
156344
  throw new MultikeyError('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR, { verificationMethod });
156983
156345
  }
156984
156346
  const decoded = this.publicKey.decode();
156985
- const publicKey2 = decoded.slice(2, decoded.length);
156986
- const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKey2) });
156987
- return new _SchnorrMultikey({ id, controller, keys });
156347
+ const pk = decoded.slice(2, decoded.length);
156348
+ const publicKey2 = new CompressedSecp256k1PublicKey(pk);
156349
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
156350
+ return new _SchnorrMultikey({ id, controller, keyPair });
156988
156351
  }
156989
156352
  /**
156990
156353
  * @readonly
@@ -157018,22 +156381,21 @@ a=end-of-candidates
157018
156381
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
157019
156382
  * @returns {SchnorrMultikey} A new Multikey instance
157020
156383
  */
157021
- static create({ id, controller, keys }) {
157022
- return new _SchnorrMultikey({ id, controller, keys });
156384
+ static create({ id, controller, keyPair }) {
156385
+ return new _SchnorrMultikey({ id, controller, keyPair });
157023
156386
  }
157024
156387
  /**
157025
156388
  * Creates a `Multikey` instance from a private key
157026
- * @param {FromPublicKey} params The parameters to create the multikey
157027
156389
  * @param {string} params.id The id of the multikey
157028
156390
  * @param {string} params.controller The controller of the multikey
157029
156391
  * @param {KeyBytes} params.entropy The private key bytes for the multikey
157030
156392
  * @returns {SchnorrMultikey} The new multikey instance
157031
156393
  */
157032
- static fromPrivateKey({ id, controller, entropy }) {
157033
- const secretKey = new Secp256k1SecretKey(entropy);
156394
+ static fromSecretKey(id, controller, secretKeyb) {
156395
+ const secretKey = new Secp256k1SecretKey(secretKeyb);
157034
156396
  const publicKey2 = secretKey.computePublicKey();
157035
- const keys = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
157036
- return new _SchnorrMultikey({ id, controller, keys });
156397
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
156398
+ return new _SchnorrMultikey({ id, controller, keyPair });
157037
156399
  }
157038
156400
  /**
157039
156401
  * Creates a `Multikey` instance from a public key
@@ -157044,24 +156406,29 @@ a=end-of-candidates
157044
156406
  * @returns {Multikey} The new multikey instance
157045
156407
  */
157046
156408
  static fromPublicKey({ id, controller, publicKeyBytes }) {
157047
- const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKeyBytes) });
157048
- return new _SchnorrMultikey({ id, controller, keys });
156409
+ const publicKey2 = new CompressedSecp256k1PublicKey(publicKeyBytes);
156410
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
156411
+ return new _SchnorrMultikey({ id, controller, keyPair });
157049
156412
  }
157050
156413
  /**
157051
156414
  * Creates a `Multikey` instance from a public key multibase.
157052
- * @param {string} id The id of the multikey.
157053
- * @param {string} controller The controller of the multikey.
157054
- * @param {string} publicKeyMultibase The public key multibase of the multikey.
156415
+ * @param {DidVerificationMethod} vm The verification method containing the public key multibase.
156416
+ * @param {string} vm.id The id of the multikey.
156417
+ * @param {string} vm.controller The controller of the multikey.
156418
+ * @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
157055
156419
  * @returns {Multikey} The new multikey instance.
157056
156420
  */
157057
- static fromPublicKeyMultibase(id, controller, publicKeyMultibase) {
156421
+ static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
156422
+ if (!publicKeyMultibase) {
156423
+ throw new MultikeyError("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
156424
+ }
157058
156425
  const publicKeyMultibaseBytes = base58btc.decode(publicKeyMultibase);
157059
156426
  if (publicKeyMultibaseBytes.length !== 35) {
157060
156427
  throw new MultikeyError(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
157061
156428
  }
157062
156429
  const publicKey2 = publicKeyMultibaseBytes.slice(2);
157063
- const keys = new SchnorrKeyPair({ publicKey: publicKey2 });
157064
- return new _SchnorrMultikey({ id, controller, keys });
156430
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
156431
+ return new _SchnorrMultikey({ id, controller, keyPair });
157065
156432
  }
157066
156433
  };
157067
156434
 
@@ -157236,6 +156603,7 @@ a=end-of-candidates
157236
156603
  * @returns {boolean} True if the id is valid.
157237
156604
  */
157238
156605
  static isValidId(id) {
156606
+ if (typeof id !== "string") return false;
157239
156607
  try {
157240
156608
  Identifier.decode(id);
157241
156609
  return true;
@@ -157285,18 +156653,14 @@ a=end-of-candidates
157285
156653
  "capabilityInvocation",
157286
156654
  "capabilityDelegation"
157287
156655
  ];
157288
- const verificationRelationships = Object.keys(didDocument);
157289
- const availableVerificationRelationships = possibleVerificationRelationships.filter(
157290
- (key) => verificationRelationships.includes(key)
157291
- );
157292
- return availableVerificationRelationships.every((key) => (
157293
- // Check if the key exists in the DID Document
157294
- didDocument[key] && // Check if the key is an array
157295
- Array.isArray(didDocument[key]) && // Check that every value in the array is a string or DidVerificationMethod
157296
- didDocument[key].every(
156656
+ const keys = Object.keys(didDocument);
156657
+ const availableKeys = possibleVerificationRelationships.filter((key) => keys.includes(key));
156658
+ return availableKeys.every((key) => {
156659
+ const value3 = didDocument[key];
156660
+ return value3 && Array.isArray(value3) && value3.every(
157297
156661
  (entry) => typeof entry === "string" || Appendix.isDidVerificationMethod(entry)
157298
- )
157299
- ));
156662
+ );
156663
+ });
157300
156664
  }
157301
156665
  /**
157302
156666
  * Validate the DID Document
@@ -157423,14 +156787,195 @@ a=end-of-candidates
157423
156787
  }
157424
156788
  };
157425
156789
 
156790
+ // src/core/beacon/signal-discovery.ts
156791
+ init_shim();
156792
+ var BeaconSignalDiscovery = class {
156793
+ /**
156794
+ * Retrieves the beacon signals for the given array of BeaconService objects
156795
+ * using an esplora/electrs REST API connection via a bitcoin I/O driver.
156796
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
156797
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
156798
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
156799
+ */
156800
+ static async indexer(beaconServices, bitcoin3) {
156801
+ const beaconServiceSignals = /* @__PURE__ */ new Map();
156802
+ const currentBlockCount = await bitcoin3.network.rest.block.count();
156803
+ for (const beaconService of beaconServices) {
156804
+ beaconServiceSignals.set(beaconService, []);
156805
+ const beaconSignals = await bitcoin3.network.rest.address.getTxs(
156806
+ beaconService.serviceEndpoint
156807
+ );
156808
+ if (!beaconSignals || !beaconSignals.length) {
156809
+ continue;
156810
+ }
156811
+ for (const beaconSignal of beaconSignals) {
156812
+ const signalVout = beaconSignal.vout.slice(-1)[0];
156813
+ if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
156814
+ continue;
156815
+ }
156816
+ const outputMap = new Map(Object.entries(signalVout));
156817
+ const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
156818
+ if (!signalVoutScriptPubkey) {
156819
+ continue;
156820
+ }
156821
+ const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
156822
+ if (!updateHash) {
156823
+ continue;
156824
+ }
156825
+ const confirmations = currentBlockCount - beaconSignal.status.block_height + 1;
156826
+ beaconServiceSignals.get(beaconService)?.push({
156827
+ tx: beaconSignal,
156828
+ signalBytes: updateHash,
156829
+ blockMetadata: {
156830
+ confirmations,
156831
+ height: beaconSignal.status.block_height,
156832
+ time: beaconSignal.status.block_time
156833
+ }
156834
+ });
156835
+ }
156836
+ }
156837
+ return beaconServiceSignals;
156838
+ }
156839
+ /**
156840
+ * Traverse the full blockchain from genesis to chain top looking for beacon signals.
156841
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
156842
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
156843
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
156844
+ */
156845
+ static async fullnode(beaconServices, bitcoin3) {
156846
+ const beaconServiceSignals = /* @__PURE__ */ new Map();
156847
+ for (const beaconService of beaconServices) {
156848
+ beaconServiceSignals.set(beaconService, []);
156849
+ }
156850
+ const rpc = bitcoin3.network.rpc;
156851
+ if (!rpc) {
156852
+ throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin3);
156853
+ }
156854
+ const targetHeight = await rpc.getBlockCount();
156855
+ const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
156856
+ let height = 0;
156857
+ let block = await bitcoin3.network.rpc.getBlock({ height });
156858
+ console.info(`Searching for beacon signals, please wait ...`);
156859
+ while (block.height <= targetHeight) {
156860
+ for (const tx of block.tx) {
156861
+ if (tx.txid === GENESIS_TX_ID) {
156862
+ continue;
156863
+ }
156864
+ for (const vin of tx.vin) {
156865
+ if (vin.coinbase) {
156866
+ continue;
156867
+ }
156868
+ if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
156869
+ continue;
156870
+ }
156871
+ if (!vin.txid) {
156872
+ continue;
156873
+ }
156874
+ if (vin.vout === void 0) {
156875
+ continue;
156876
+ }
156877
+ const prevout = await rpc.getRawTransaction(vin.txid, 2);
156878
+ if (!prevout.vout[vin.vout]) {
156879
+ continue;
156880
+ }
156881
+ const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
156882
+ if (!scriptPubKey.address) {
156883
+ continue;
156884
+ }
156885
+ const beaconService = beaconServicesMap.get(scriptPubKey.address);
156886
+ if (!beaconService) {
156887
+ continue;
156888
+ }
156889
+ const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
156890
+ if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
156891
+ continue;
156892
+ }
156893
+ console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
156894
+ const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
156895
+ if (!updateHash) {
156896
+ continue;
156897
+ }
156898
+ beaconServiceSignals.get(beaconService)?.push({
156899
+ tx,
156900
+ signalBytes: updateHash,
156901
+ blockMetadata: {
156902
+ height: block.height,
156903
+ time: block.time,
156904
+ confirmations: block.confirmations
156905
+ }
156906
+ });
156907
+ }
156908
+ ;
156909
+ }
156910
+ height += 1;
156911
+ if (height > targetHeight) {
156912
+ console.info(`Chain tip reached ${height}, breaking ...`);
156913
+ break;
156914
+ }
156915
+ block = await rpc.getBlock({ height });
156916
+ }
156917
+ return beaconServiceSignals;
156918
+ }
156919
+ };
156920
+
157426
156921
  // src/core/resolve.ts
157427
156922
  var Resolve = class {
156923
+ /**
156924
+ * 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}.
156925
+ * @param {DidComponents} didComponents The decoded components of the did.
156926
+ * @returns {DidDocument} The resolved DID Document object.
156927
+ */
156928
+ static deterministic(didComponents) {
156929
+ const did = Identifier.encode(didComponents);
156930
+ const { genesisBytes } = didComponents;
156931
+ const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
156932
+ const service = BeaconUtils.generateBeaconServices({
156933
+ id: did,
156934
+ publicKey: genesisBytes,
156935
+ network: getNetwork(didComponents.network),
156936
+ beaconType: "SingletonBeacon"
156937
+ });
156938
+ return new DidDocument2({
156939
+ id: did,
156940
+ controller: [did],
156941
+ verificationMethod: [{
156942
+ id: `${did}#initialKey`,
156943
+ type: "Multikey",
156944
+ controller: did,
156945
+ publicKeyMultibase: publicKeyMultibase.encoded
156946
+ }],
156947
+ service
156948
+ });
156949
+ }
156950
+ /**
156951
+ * 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}.
156952
+ * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
156953
+ * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
156954
+ * @returns {Promise<DidDocument>} The resolved DID Document object
156955
+ * @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
156956
+ */
156957
+ static async external(didComponents, genesisDocument) {
156958
+ const hashBytes = canonicalization2.process(genesisDocument, { encoding: "hex" });
156959
+ const genesisBytes = bytesToHex(didComponents.genesisBytes);
156960
+ if (genesisBytes !== hashBytes) {
156961
+ throw new ResolveError(
156962
+ `Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
156963
+ INVALID_DID_DOCUMENT,
156964
+ { genesisBytes, hashBytes }
156965
+ );
156966
+ }
156967
+ const did = Identifier.encode(didComponents);
156968
+ const currentDocument = JSON.parse(
156969
+ JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
156970
+ );
156971
+ return new DidDocument2(currentDocument);
156972
+ }
157428
156973
  /**
157429
156974
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
157430
156975
  * @param {Sidecar} sidecar The sidecar data to process.
157431
- * @returns {SidecarData} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
156976
+ * @returns {ProcessedSidecar} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
157432
156977
  */
157433
- static processSidecarData(sidecar = {}) {
156978
+ static sidecarData(sidecar = {}) {
157434
156979
  const updateMap = /* @__PURE__ */ new Map();
157435
156980
  if (sidecar.updates?.length)
157436
156981
  for (const update of sidecar.updates) {
@@ -157455,9 +157000,9 @@ a=end-of-candidates
157455
157000
  * @param {DidComponents} didComponents The decoded components of the did.
157456
157001
  * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
157457
157002
  * @returns {Promise<DidDocument>} The resolved DID Document object.
157458
- * @throws {DidError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
157003
+ * @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
157459
157004
  */
157460
- static async establishCurrentDocument(didComponents, genesisDocument) {
157005
+ static async currentDocument(didComponents, genesisDocument) {
157461
157006
  const { hrp, genesisBytes } = didComponents;
157462
157007
  if (hrp === IdentifierHrp.x) {
157463
157008
  if (!genesisDocument)
@@ -157480,84 +157025,33 @@ a=end-of-candidates
157480
157025
  }
157481
157026
  throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID, { hrp });
157482
157027
  }
157483
- /**
157484
- * 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}.
157485
- * @param {DidComponents} didComponents The decoded components of the did.
157486
- * @returns {DidDocument} The resolved DID Document object.
157487
- */
157488
- static deterministic(didComponents) {
157489
- const did = Identifier.encode(didComponents);
157490
- const { genesisBytes } = didComponents;
157491
- const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
157492
- const service = BeaconUtils.generateBeaconServices({
157493
- id: did,
157494
- publicKey: genesisBytes,
157495
- network: getNetwork(didComponents.network),
157496
- beaconType: "SingletonBeacon"
157497
- });
157498
- return new DidDocument2({
157499
- id: did,
157500
- controller: [did],
157501
- verificationMethod: [{
157502
- id: `${did}#initialKey`,
157503
- type: "Multikey",
157504
- controller: did,
157505
- publicKeyMultibase: publicKeyMultibase.encoded
157506
- }],
157507
- service
157508
- });
157509
- }
157510
- /**
157511
- * 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}.
157512
- * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
157513
- * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
157514
- * @returns {Promise<DidDocument>} The resolved DID Document object
157515
- * @throws {MethodError} InvalidDidDocument if not conformant to DID Core v1.1
157516
- */
157517
- static async external(didComponents, genesisDocument) {
157518
- const hashBytes = canonicalization2.process(genesisDocument, { encoding: "hex" });
157519
- const genesisBytes = bytesToHex(didComponents.genesisBytes);
157520
- if (genesisBytes !== hashBytes) {
157521
- throw new MethodError(
157522
- `Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
157523
- INVALID_DID_DOCUMENT,
157524
- { genesisBytes, hashBytes }
157525
- );
157526
- }
157527
- const did = Identifier.encode(didComponents);
157528
- const currentDocument = JSON.parse(
157529
- JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
157530
- );
157531
- return new DidDocument2(currentDocument);
157532
- }
157533
157028
  /**
157534
157029
  * Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
157535
157030
  * Signal Bytes (last output in OP_RETURN transaction).
157536
157031
  * @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
157537
157032
  * @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
157538
157033
  * @param {BitcoinNetworkConnection} bitcoin The bitcoin network connection used to fetch beacon signals
157539
- * @param {boolean} [fullBlockchainTraversal=false] Whether to perform a full blockchain traversal or use an indexer
157540
- * @returns {Promise<Array<[BTCR2SignedUpdate, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
157034
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
157541
157035
  */
157542
- static async processBeaconSignals(beaconServices, sidecarData, bitcoin3, fullBlockchainTraversal) {
157543
- const beaconServicesSignals = !fullBlockchainTraversal ? await this.queryBlockchainIndexer(beaconServices, bitcoin3) : await this.traverseFullBlockchain(beaconServices, bitcoin3);
157544
- const unsortedUpdates = new Array();
157545
- for (const [service, signals] of beaconServicesSignals) {
157546
- const beacon = BeaconFactory.establish(service, signals, sidecarData);
157547
- const processed = await beacon.processSignals();
157548
- unsortedUpdates.push(...processed);
157549
- }
157550
- return unsortedUpdates;
157036
+ static async beaconSignals(beaconServices, sidecarData, bitcoin3) {
157037
+ const beaconServicesSignals = bitcoin3.network.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin3) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin3);
157038
+ const promises = Array.from(beaconServicesSignals.entries()).map(
157039
+ async ([service, signals]) => {
157040
+ if (!signals.length) return [];
157041
+ return BeaconFactory.establish(service).processSignals(signals, sidecarData);
157042
+ }
157043
+ );
157044
+ return (await Promise.all(promises)).flat();
157551
157045
  }
157552
157046
  /**
157553
157047
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
157554
157048
  * @param {DidDocument} currentDocument The current DID Document to apply the updates to.
157555
- * @param {Array<[BTCR2SignedUpdate, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
157049
+ * @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
157556
157050
  * @param {string} [versionTime] The optional version time to limit updates to.
157557
157051
  * @param {string} [versionId] The optional version id to limit updates to.
157558
157052
  * @returns {Promise<DidResolutionResponse>} The updated DID Document, number of confirmations, and version id.
157559
157053
  */
157560
- static async processUpdatesArray(currentDocument, unsortedUpdates, versionTime, versionId) {
157054
+ static async updates(currentDocument, unsortedUpdates, versionTime, versionId) {
157561
157055
  let currentVersionId = 1;
157562
157056
  const updateHashHistory = [];
157563
157057
  const updates = unsortedUpdates.sort(
@@ -157580,7 +157074,7 @@ a=end-of-candidates
157580
157074
  }
157581
157075
  if (update.targetVersionId <= currentVersionId) {
157582
157076
  updateHashHistory.push(currentDocumentHash);
157583
- this.confirmDuplicateUpdate(update, updateHashHistory);
157077
+ this.confirmDuplicate(update, updateHashHistory);
157584
157078
  } else if (update.targetVersionId === currentVersionId + 1) {
157585
157079
  const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
157586
157080
  if (sourceHash !== currentDocumentHash) {
@@ -157590,7 +157084,7 @@ a=end-of-candidates
157590
157084
  { sourceHash, currentDocumentHash }
157591
157085
  );
157592
157086
  }
157593
- response2.currentDocument = await this.applyDidUpdate(response2.currentDocument, update);
157087
+ response2.currentDocument = await this.applyUpdate(response2.currentDocument, update);
157594
157088
  const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
157595
157089
  updateHashHistory.push(canonicalization2.process(unsignedUpdate, { encoding: "base58" }));
157596
157090
  } else if (update.targetVersionId > currentVersionId + 1) {
@@ -157614,138 +157108,13 @@ a=end-of-candidates
157614
157108
  }
157615
157109
  return response2;
157616
157110
  }
157617
- /**
157618
- * Retrieves the beacon signals for the given array of BeaconService objects
157619
- * using a esplora/electrs REST API connection via a bitcoin I/O driver.
157620
- * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
157621
- * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
157622
- * @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects
157623
- */
157624
- static async queryBlockchainIndexer(beaconServices, bitcoin3) {
157625
- const beaconServiceSignals = /* @__PURE__ */ new Map();
157626
- for (const beaconService of beaconServices) {
157627
- beaconServiceSignals.set(beaconService, []);
157628
- const beaconSignals = await bitcoin3.network.rest.address.getTxs(
157629
- beaconService.serviceEndpoint
157630
- );
157631
- if (!beaconSignals || !beaconSignals.length) {
157632
- continue;
157633
- }
157634
- for (const beaconSignal of beaconSignals) {
157635
- const signalVout = beaconSignal.vout.slice(-1)[0];
157636
- if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
157637
- continue;
157638
- }
157639
- const outputMap = new Map(Object.entries(signalVout));
157640
- const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
157641
- if (!signalVoutScriptPubkey) {
157642
- continue;
157643
- }
157644
- const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
157645
- if (!updateHash) {
157646
- continue;
157647
- }
157648
- const confirmations = await bitcoin3.network.rest.block.count() - beaconSignal.status.block_height + 1;
157649
- beaconServiceSignals.get(beaconService)?.push({
157650
- tx: beaconSignal,
157651
- signalBytes: updateHash,
157652
- blockMetadata: {
157653
- confirmations,
157654
- height: beaconSignal.status.block_height,
157655
- time: beaconSignal.status.block_time
157656
- }
157657
- });
157658
- }
157659
- }
157660
- return beaconServiceSignals;
157661
- }
157662
- /**
157663
- * Traverse the full blockchain from genesis to chain top looking for beacon signals.
157664
- * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
157665
- * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
157666
- * @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects.
157667
- */
157668
- static async traverseFullBlockchain(beaconServices, bitcoin3) {
157669
- const beaconServiceSignals = /* @__PURE__ */ new Map();
157670
- for (const beaconService of beaconServices) {
157671
- beaconServiceSignals.set(beaconService, []);
157672
- }
157673
- const rpc = bitcoin3.network.rpc;
157674
- if (!rpc) {
157675
- throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin3);
157676
- }
157677
- const targetHeight = await rpc.getBlockCount();
157678
- let height = 0;
157679
- let block = await bitcoin3.network.rpc.getBlock({ height });
157680
- console.info(`Searching for beacon signals, please wait ...`);
157681
- while (block.height <= targetHeight) {
157682
- for (const tx of block.tx) {
157683
- if (tx.txid === GENESIS_TX_ID) {
157684
- continue;
157685
- }
157686
- for (const vin of tx.vin) {
157687
- if (vin.coinbase) {
157688
- continue;
157689
- }
157690
- if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
157691
- continue;
157692
- }
157693
- if (!vin.txid) {
157694
- continue;
157695
- }
157696
- if (vin.vout === void 0) {
157697
- continue;
157698
- }
157699
- const prevout = await rpc.getRawTransaction(vin.txid, 2);
157700
- if (!prevout.vout[vin.vout]) {
157701
- continue;
157702
- }
157703
- const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
157704
- if (!scriptPubKey.address) {
157705
- continue;
157706
- }
157707
- const beaconService = BeaconUtils.getBeaconServicesMap(beaconServices).get(scriptPubKey.address);
157708
- if (!beaconService) {
157709
- continue;
157710
- }
157711
- const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
157712
- if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
157713
- continue;
157714
- }
157715
- console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
157716
- const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
157717
- if (!updateHash) {
157718
- continue;
157719
- }
157720
- beaconServiceSignals.get(beaconService)?.push({
157721
- tx,
157722
- signalBytes: updateHash,
157723
- blockMetadata: {
157724
- height: block.height,
157725
- time: block.time,
157726
- confirmations: block.confirmations
157727
- }
157728
- });
157729
- }
157730
- ;
157731
- }
157732
- height += 1;
157733
- const tip = await rpc.getBlockCount();
157734
- if (height > tip) {
157735
- console.info(`Chain tip reached ${height}, breaking ...`);
157736
- break;
157737
- }
157738
- block = await rpc.getBlock({ height });
157739
- }
157740
- return beaconServiceSignals;
157741
- }
157742
157111
  /**
157743
157112
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
157744
157113
  * This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
157745
- * @param {BTCR2SignedUpdate} update The BTCR2 Signed Update to confirm as a duplicate.
157114
+ * @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
157746
157115
  * @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
157747
157116
  */
157748
- static confirmDuplicateUpdate(update, updateHashHistory) {
157117
+ static confirmDuplicate(update, updateHashHistory) {
157749
157118
  const unsignedUpdate = JSONUtils.deleteKeys(update, ["proof"]);
157750
157119
  const unsignedUpdateHash = canonicalization2.process(unsignedUpdate);
157751
157120
  const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
@@ -157760,11 +157129,11 @@ a=end-of-candidates
157760
157129
  /**
157761
157130
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
157762
157131
  * @param {DidDocument} currentDocument The current DID Document to apply the update to.
157763
- * @param {BTCR2SignedUpdate} update The BTCR2 Signed Update to apply.
157132
+ * @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
157764
157133
  * @returns {Promise<DidDocument>} The updated DID Document after applying the update.
157765
157134
  * @throws {ResolveError} If the update is invalid or cannot be applied.
157766
157135
  */
157767
- static async applyDidUpdate(currentDocument, update) {
157136
+ static async applyUpdate(currentDocument, update) {
157768
157137
  const capabilityId = update.proof?.capability;
157769
157138
  if (!capabilityId) {
157770
157139
  throw new ResolveError("No root capability found in update", INVALID_DID_UPDATE, update);
@@ -157783,18 +157152,13 @@ a=end-of-candidates
157783
157152
  throw new ResolveError("No verificationMethod found in update", INVALID_DID_UPDATE, update);
157784
157153
  }
157785
157154
  const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
157786
- const [vmController, vmId] = vm.id.split("#");
157787
- const multikey = SchnorrMultikey.fromPublicKeyMultibase(
157788
- `#${vmId}`,
157789
- vmController,
157790
- vm.publicKeyMultibase
157791
- );
157155
+ const multikey = SchnorrMultikey.fromVerificationMethod(vm);
157792
157156
  const cryptosuite = new BIP340Cryptosuite(multikey);
157793
157157
  const canonicalUpdate = canonicalization2.canonicalize(update);
157794
157158
  const diProof = new BIP340DataIntegrityProof(cryptosuite);
157795
157159
  const verificationResult = diProof.verifyProof(canonicalUpdate, "capabilityInvocation");
157796
157160
  if (!verificationResult.verified) {
157797
- throw new MethodError(
157161
+ throw new ResolveError(
157798
157162
  "Invalid update: proof not verified",
157799
157163
  INVALID_DID_UPDATE,
157800
157164
  verificationResult
@@ -157805,7 +157169,7 @@ a=end-of-candidates
157805
157169
  const currentDocumentHash = canonicalization2.process(currentDocument, { encoding: "base58" });
157806
157170
  const updateTargetHash = update.targetHash.startsWith("z") ? update.targetHash : `z${update.targetHash}`;
157807
157171
  if (updateTargetHash !== currentDocumentHash) {
157808
- throw new MethodError(
157172
+ throw new ResolveError(
157809
157173
  `Invalid update: updateTargetHash !== currentDocumentHash`,
157810
157174
  INVALID_DID_UPDATE,
157811
157175
  { updateTargetHash, currentDocumentHash }
@@ -157819,103 +157183,55 @@ a=end-of-candidates
157819
157183
  init_shim();
157820
157184
  var Update = class {
157821
157185
  /**
157822
- * Implements {@link https://dcdpr.github.io/did-btcr2/#construct-did-update-payload | 4.3.1 Construct DID Update Payload}.
157823
- *
157824
- * The Construct DID Update Payload algorithm applies the documentPatch to the sourceDocument and verifies the
157825
- * resulting targetDocument is a conformant DID document. It takes in a Identifier, sourceDocument,
157826
- * sourceVersionId, and documentPatch objects. It returns an unsigned DID Update Payload.
157186
+ * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
157187
+ * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
157827
157188
  *
157828
- * @param {ConstructPayloadParams} params See {@link ConstructPayloadParams} for more details.
157829
- * @param {string} params.identifier The did-btcr2 identifier to use for verification.
157830
- * @param {DidDocument} params.sourceDocument The source document to be updated.
157831
- * @param {string} params.sourceVersionId The versionId of the source document.
157832
- * @param {DidDocumentPatch} params.patch The JSON patch to be applied to the source document.
157833
- * @returns {Promise<BTCR2SignedUpdate>} The constructed BTCR2SignedUpdate object.
157834
- * @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
157189
+ * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
157190
+ * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
157191
+ * @param {number} sourceVersionId The version ID of the source document.
157192
+ * @returns {Promise<SignedBTCR2Update>} The constructed SignedBTCR2Update object.
157193
+ * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
157835
157194
  */
157836
- static async construct({
157837
- identifier,
157838
- sourceDocument,
157839
- sourceVersionId,
157840
- patch
157841
- }) {
157842
- if (sourceDocument.id !== identifier) {
157843
- throw new UpdateError(
157844
- "Identifier mismatch: sourceDocument.id !== identifier",
157845
- INVALID_DID_UPDATE,
157846
- { sourceDocument, identifier }
157847
- );
157848
- }
157195
+ static async construct(sourceDocument, patches, sourceVersionId) {
157849
157196
  const unsignedUpdate = {
157850
- // 3. Set BTCR2SignedUpdate.@context to the following list
157851
157197
  "@context": [
157852
157198
  "https://w3id.org/security/v2",
157853
157199
  "https://w3id.org/zcap/v1",
157854
157200
  "https://w3id.org/json-ld-patch/v1",
157855
157201
  "https://btcr2.dev/context/v1"
157856
157202
  ],
157857
- // 4. Set BTCR2SignedUpdate.patch to documentPatch.
157858
- patch,
157203
+ patch: patches,
157859
157204
  targetHash: "",
157860
- targetVersionId: 0,
157861
- sourceHash: ""
157862
- };
157863
- const targetDocument = JSONPatch.apply(sourceDocument, patch);
157864
- DidDocument2.validate(targetDocument);
157865
- unsignedUpdate.sourceHash = canonicalization2.process(sourceDocument, { encoding: "base58" }).slice(1);
157866
- unsignedUpdate.targetHash = canonicalization2.process(targetDocument, { encoding: "base58" }).slice(1);
157867
- unsignedUpdate.targetVersionId = sourceVersionId + 1;
157205
+ targetVersionId: sourceVersionId + 1,
157206
+ sourceHash: canonicalization2.process(sourceDocument, { encoding: "base58" })
157207
+ };
157208
+ const targetDocument = JSONPatch.apply(sourceDocument, patches);
157209
+ try {
157210
+ DidDocument2.isValid(targetDocument);
157211
+ } catch (error) {
157212
+ throw new UpdateError(
157213
+ "Error validating targetDocument: " + (error instanceof Error ? error.message : String(error)),
157214
+ INVALID_DID_UPDATE,
157215
+ targetDocument
157216
+ );
157217
+ }
157218
+ unsignedUpdate.targetHash = canonicalization2.process(targetDocument, { encoding: "base58" });
157868
157219
  return unsignedUpdate;
157869
157220
  }
157870
157221
  /**
157871
- * {@link https://dcdpr.github.io/did-btcr2/#invoke-did-update-payload | 4.3.2 Invoke DID Update Payload}.
157872
- *
157873
- * The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned BTCR2SignedUpdate, and a
157874
- * verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
157875
- * the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
157876
- * specifications. It returns the invoked DID Update Payload.
157222
+ * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
157223
+ * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
157877
157224
  *
157878
- * @param {InvokePayloadParams} params Required params for calling the invokePayload method
157879
- * @param {string} params.identifier The did-btcr2 identifier to derive the root capability from
157880
- * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The updatePayload object to be signed
157881
- * @param {DidVerificationMethod} params.verificationMethod The verificationMethod object to be used for signing
157882
- * @returns {BTCR2SignedUpdate} Did update payload secured with a proof => BTCR2SignedUpdate
157883
- * @throws {MethodError} if the privateKeyBytes are invalid
157225
+ * @param {string} did The did-btcr2 identifier to derive the root capability from
157226
+ * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
157227
+ * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
157228
+ * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
157229
+ * @throws {UpdateError} if the privateKeyBytes are invalid
157884
157230
  */
157885
- static async invoke({
157886
- identifier,
157887
- unsignedUpdate,
157888
- verificationMethod
157889
- }) {
157890
- const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
157891
- if (!publicKeyMultibase) {
157892
- throw new MethodError(
157893
- "Invalid publicKeyMultibase: cannot be undefined",
157894
- INVALID_PUBLIC_KEY_TYPE,
157895
- verificationMethod
157896
- );
157897
- }
157898
- const id = fullId.slice(fullId.indexOf("#"));
157899
- const components = Identifier.decode(id);
157900
- const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
157901
- const keys = secretKeyMultibase ? new SchnorrKeyPair({ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase) }) : Kms.getKey(keyUri);
157902
- if (!keys) {
157903
- throw new MethodError(
157904
- "No privateKey found in kms or vm",
157905
- NOT_FOUND,
157906
- verificationMethod
157907
- );
157908
- }
157909
- const multikey = SchnorrMultikey.create({ id, controller, keys });
157910
- if (!multikey) {
157911
- throw new MethodError(
157912
- "Failed to create multikey from verification method",
157913
- "MULTKEY_CREATE_FAILED",
157914
- verificationMethod
157915
- );
157916
- }
157917
- const rootCapability = Appendix.deriveRootCapability(identifier);
157918
- const cryptosuite = "bip340-jcs-2025";
157231
+ static async sign(did, unsignedUpdate, verificationMethod, secretKey) {
157232
+ const controller = verificationMethod.controller;
157233
+ const id = verificationMethod.id.slice(verificationMethod.id.indexOf("#"));
157234
+ const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
157919
157235
  const config = {
157920
157236
  "@context": [
157921
157237
  "https://w3id.org/security/v2",
@@ -157923,56 +157239,29 @@ a=end-of-candidates
157923
157239
  "https://w3id.org/json-ld-patch/v1",
157924
157240
  "https://btcr2.dev/context/v1"
157925
157241
  ],
157926
- cryptosuite,
157242
+ cryptosuite: "bip340-jcs-2025",
157927
157243
  type: "DataIntegrityProof",
157928
- verificationMethod: fullId,
157244
+ verificationMethod: verificationMethod.id,
157929
157245
  proofPurpose: "capabilityInvocation",
157930
- capability: rootCapability.id,
157246
+ capability: `urn:zcap:root:${encodeURIComponent(did)}`,
157931
157247
  capabilityAction: "Write"
157932
157248
  };
157933
157249
  const diproof = multikey.toCryptosuite().toDataIntegrityProof();
157934
- return await diproof.addProof(unsignedUpdate, config);
157250
+ return diproof.addProof(unsignedUpdate, config);
157935
157251
  }
157936
157252
  /**
157937
- * Implements {@link https://dcdpr.github.io/did-btcr2/#announce-did-update | 4.3.3 Announce DID Update}.
157938
- *
157939
- * The Announce DID Update algorithm retrieves beaconServices from the sourceDocument and calls the Broadcast DID
157940
- * Update algorithm corresponding to the type of the Beacon. It takes in a Identifier, sourceDocument, an array of
157941
- * beaconIds, and a BTCR2SignedUpdate. It returns an array of signalsMetadata, containing the necessary
157942
- * data to validate the Beacon Signal against the BTCR2SignedUpdate.
157943
- *
157944
- * @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
157945
- * @param {DidDocument} params.sourceDocument The did-btcr2 did document to derive the root capability from
157946
- * @param {string[]} params.beaconIds The BTCR2SignedUpdate object to be signed
157947
- * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The verificationMethod object to be used for signing
157948
- * @returns {BTCR2SignedUpdate} The BTCR2SignedUpdate object containing data to validate the Beacon Signal
157949
- * @throws {MethodError} if the beaconService type is invalid
157253
+ * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
157254
+ * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
157255
+ * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
157256
+ * @param {SignedBTCR2Update} update The signed update object to be announced.
157257
+ * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
157258
+ * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
157259
+ * @throws {UpdateError} if the beaconService type is invalid
157950
157260
  */
157951
- static async announce({
157952
- sourceDocument,
157953
- beaconIds,
157954
- signedUpdate
157955
- }) {
157956
- const beaconServices = [];
157957
- let sidecarData;
157958
- for (const beaconId of beaconIds) {
157959
- const beaconService = sourceDocument.service.find((s2) => s2.id === beaconId);
157960
- if (!beaconService) {
157961
- throw new MethodError("Not found: sourceDocument does not contain beaconId", INVALID_DID_DOCUMENT, { beaconId });
157962
- }
157963
- beaconServices.push(beaconService);
157964
- }
157965
- for (const beaconService of beaconServices) {
157966
- console.log("TODO: refactor this code", signedUpdate, beaconService);
157967
- }
157968
- if (!sidecarData) {
157969
- throw new MethodError(
157970
- "Invalid beacon: no sidecarData found",
157971
- INVALID_DID_DOCUMENT,
157972
- { beaconServices }
157973
- );
157974
- }
157975
- return sidecarData;
157261
+ static async announce(beaconService, update, secretKey, bitcoin3) {
157262
+ const beacon = BeaconFactory.establish(beaconService);
157263
+ const result = await beacon.broadcastSignal(update, secretKey, bitcoin3);
157264
+ return result;
157976
157265
  }
157977
157266
  };
157978
157267
 
@@ -157980,7 +157269,9 @@ a=end-of-candidates
157980
157269
  var canonicalization2 = new Canonicalization();
157981
157270
  initEccLib(tinysecp3);
157982
157271
  var DidBtcr2 = class {
157983
- /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
157272
+ /**
157273
+ * Name of the DID method, as defined in the DID BTCR2 specification
157274
+ */
157984
157275
  static methodName = "btcr2";
157985
157276
  /**
157986
157277
  * Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
@@ -158005,7 +157296,7 @@ a=end-of-candidates
158005
157296
  return Identifier.encode({ idType, genesisBytes, version: version3, network });
158006
157297
  }
158007
157298
  /**
158008
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Resolve}.
157299
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
158009
157300
  * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
158010
157301
  * See {@link Resolve | Resolve (class)} for class implementation.
158011
157302
  *
@@ -158014,14 +157305,10 @@ a=end-of-candidates
158014
157305
  * blockchain by Authorized Beacon Signals. The Initial DID Document is either
158015
157306
  * deterministically created from the DID or provided by Sidecar Data.
158016
157307
  *
158017
- * @param {string} did a valid did:btcr2 identifier to be resolved
158018
- * @param {ResolutionOptions} resolutionOptions see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | ResolutionOptions}
158019
- * @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
158020
- * @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
158021
- * @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
157308
+ * @param {string} did The did:btcr2 identifier to be resolved.
157309
+ * @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
158022
157310
  * @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
158023
- * @throws {Error} if the resolution fails for any reason
158024
- * @throws {DidError} InvalidDid if the identifier is invalid
157311
+ * @throws {ResolveError} If the resolution process fails at any step.
158025
157312
  * @example
158026
157313
  * ```ts
158027
157314
  * const resolution = await DidBtcr2.resolve(
@@ -158043,8 +157330,9 @@ a=end-of-candidates
158043
157330
  didDocument: null
158044
157331
  };
158045
157332
  const didComponents = Identifier.decode(did);
158046
- const sidecarData = Resolve.processSidecarData(resolutionOptions.sidecar);
158047
- if (!resolutionOptions.drivers.bitcoin) {
157333
+ const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
157334
+ if (!resolutionOptions?.drivers?.bitcoin) {
157335
+ resolutionOptions.drivers = resolutionOptions.drivers || {};
158048
157336
  resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
158049
157337
  resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
158050
157338
  }
@@ -158057,20 +157345,21 @@ a=end-of-candidates
158057
157345
  { resolutionOptions }
158058
157346
  );
158059
157347
  }
158060
- const currentDocument = await Resolve.establishCurrentDocument(didComponents, genesisDocument);
157348
+ const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
158061
157349
  const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
158062
- const unsortedUpdates = await Resolve.processBeaconSignals(
157350
+ console.log("beaconServices", beaconServices);
157351
+ const unsortedUpdates = await Resolve.beaconSignals(
158063
157352
  beaconServices,
158064
157353
  sidecarData,
158065
- resolutionOptions.drivers.bitcoin,
158066
- resolutionOptions.fullBlockchainTraversal
157354
+ resolutionOptions.drivers.bitcoin
158067
157355
  );
157356
+ console.log("unsortedUpdates", unsortedUpdates);
158068
157357
  if (!unsortedUpdates.length) {
158069
157358
  didResolutionResult.didDocument = currentDocument;
158070
157359
  didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
158071
157360
  return didResolutionResult;
158072
157361
  }
158073
- const result = await Resolve.processUpdatesArray(
157362
+ const result = await Resolve.updates(
158074
157363
  currentDocument,
158075
157364
  unsortedUpdates,
158076
157365
  resolutionOptions.versionTime,
@@ -158094,68 +157383,90 @@ a=end-of-candidates
158094
157383
  }
158095
157384
  }
158096
157385
  /**
158097
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
158098
- * See {@link Update} for implementation details.
158099
- *
158100
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
158101
- * verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
158102
- * invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
158103
- * cryptosuite with a proofPurpose of capabilityInvocation.
158104
- *
158105
- * The Update algorithm takes as inputs a Identifier, sourceDocument, sourceVersionId, documentPatch, a
158106
- * verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
158107
- * documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
158108
- * The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
158109
- * verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
158110
- * identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
158111
- * Types SingletonBeacon, CASBeacon, and SMTBeacon.
158112
- *
158113
- * @param {UpdateParams} params Required parameters for the update operation.
158114
- * @param {string} params.identifier The btcr2 identifier to be updated.
158115
- * @param {DidDocument} params.sourceDocument The DID document being updated.
158116
- * @param {string} params.sourceVersionId The versionId of the source document.
158117
- * @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
158118
- * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
158119
- * @param {string[]} params.beaconIds The beacon IDs to announce the update
158120
- * @returns {Promise<void>} Promise resolving to void
158121
- * @throws {MethodError} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
158122
- */
158123
- static async update(params) {
158124
- const {
158125
- identifier,
158126
- sourceDocument,
158127
- sourceVersionId,
158128
- patch,
158129
- verificationMethodId: methodId,
158130
- beaconIds
158131
- } = params;
158132
- const unsignedUpdate = await Update.construct({
158133
- identifier,
158134
- sourceDocument,
158135
- sourceVersionId,
158136
- patch
158137
- });
158138
- const verificationMethod = this.getSigningMethod(sourceDocument, methodId);
157386
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
157387
+ * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
157388
+ * See {@link Update | Update (class)} for class implementation.
157389
+ *
157390
+ * BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
157391
+ * published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
157392
+ * invalidate the DID document.
157393
+ * @param params An object containing the parameters for the update operation.
157394
+ * @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
157395
+ * @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
157396
+ * @param {string} params.sourceVersionId The version ID before applying the update.
157397
+ * @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
157398
+ * @param {string} params.beaconId The beacon ID associated with the update.
157399
+ * @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
157400
+ * @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
157401
+ * @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
157402
+ * @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
157403
+ * header is not `zQ3s`
157404
+ */
157405
+ static async update({
157406
+ sourceDocument,
157407
+ patches,
157408
+ sourceVersionId,
157409
+ verificationMethodId,
157410
+ beaconId,
157411
+ signingMaterial,
157412
+ bitcoin: bitcoin3
157413
+ }) {
157414
+ if (!signingMaterial) {
157415
+ throw new UpdateError(
157416
+ "Missing signing material for update",
157417
+ INVALID_DID_UPDATE,
157418
+ { signingMaterial }
157419
+ );
157420
+ }
157421
+ const secretKey = typeof signingMaterial === "string" ? import_buffer.Buffer.from(signingMaterial, "hex") : signingMaterial;
157422
+ if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
157423
+ throw new UpdateError(
157424
+ "Invalid verificationMethodId: not authorized for capabilityInvocation",
157425
+ INVALID_DID_DOCUMENT,
157426
+ sourceDocument
157427
+ );
157428
+ }
157429
+ const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
158139
157430
  if (!verificationMethod) {
158140
- throw new MethodError("Verification method not found in did document", INVALID_DID_DOCUMENT, sourceDocument);
157431
+ throw new UpdateError(
157432
+ "Invalid verificationMethod: not found in source document",
157433
+ INVALID_DID_DOCUMENT,
157434
+ { sourceDocument, verificationMethodId }
157435
+ );
158141
157436
  }
158142
157437
  if (verificationMethod.type !== "Multikey") {
158143
- throw new MethodError('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT, verificationMethod);
157438
+ throw new UpdateError(
157439
+ 'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
157440
+ INVALID_DID_DOCUMENT,
157441
+ verificationMethod
157442
+ );
158144
157443
  }
158145
- const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
158146
- if (mbasePrefix !== "zQ3s") {
158147
- throw new MethodError(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT, verificationMethod);
157444
+ if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== "zQ3s") {
157445
+ throw new UpdateError(
157446
+ 'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
157447
+ INVALID_DID_DOCUMENT,
157448
+ verificationMethod
157449
+ );
158148
157450
  }
158149
- const signedUpdate = await Update.invoke({ identifier, verificationMethod, unsignedUpdate });
158150
- const signalsMetadata = await Update.announce({ sourceDocument, beaconIds, signedUpdate });
158151
- return signalsMetadata;
157451
+ const update = await Update.construct(sourceDocument, patches, sourceVersionId);
157452
+ const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
157453
+ const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
157454
+ if (!beaconService) {
157455
+ throw new UpdateError(
157456
+ "No beacon service found for provided beaconId",
157457
+ INVALID_DID_UPDATE,
157458
+ { sourceDocument, beaconId }
157459
+ );
157460
+ }
157461
+ bitcoin3 ??= new BitcoinNetworkConnection();
157462
+ return signed;
158152
157463
  }
158153
157464
  /**
158154
157465
  * Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
158155
157466
  * for signing messages and credentials. If given, the `methodId` parameter is used to select the
158156
157467
  * verification method. If not given, the Identity Key's verification method with an ID fragment
158157
157468
  * of '#initialKey' is used.
158158
- * @param {DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
157469
+ * @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
158159
157470
  * @param {string} [methodId] Optional verification method ID to be used for signing.
158160
157471
  * @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
158161
157472
  * @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
@@ -158180,43 +157491,25 @@ a=end-of-candidates
158180
157491
  };
158181
157492
 
158182
157493
  // src/core/beacon/singleton.ts
158183
- var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
157494
+ var SingletonBeacon = class extends Beacon {
158184
157495
  /**
158185
157496
  * Creates an instance of SingletonBeacon.
158186
- * @param {BeaconService} service The Beacon service.
158187
- * @param {?BeaconSidecarData} sidecar The SingletonBeacon sidecar data.
158188
- */
158189
- constructor(service, signals, sidecar, bitcoin3) {
158190
- super({ ...service, type: "SingletonBeacon" }, signals, sidecar, bitcoin3);
158191
- }
158192
- /**
158193
- * Static, convenience method for establishing a CASBeacon object.
158194
- * @param {string} service The Beacon service.
158195
- * @param {SidecarData} sidecar The sidecar data.
158196
- * @returns {SingletonBeacon} The Singleton Beacon.
158197
- */
158198
- static establish(service, signals, sidecar) {
158199
- return new _SingletonBeacon(service, signals, sidecar);
158200
- }
158201
- /**
158202
- * Generates a Beacon Signal for a Singleton Beacon Service.
158203
- * @param {HexString} updateHash The update hash to be included in the Beacon Signal.
158204
- * @returns {BeaconSignal} The generated signal.
158205
- * @throws {MethodError} if the signal is invalid.
157497
+ * @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
157498
+ *
158206
157499
  */
158207
- generateSignal(updateHash) {
158208
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
157500
+ constructor(service) {
157501
+ super({ ...service, type: "SingletonBeacon" });
158209
157502
  }
158210
157503
  /**
158211
157504
  * Processes an array of Beacon Signals associated with a Singleton Beacon Service.
158212
- * @returns {Promise<BTCR2SignedUpdate | undefined>} The DID Update payload announced by the Beacon Signal.
157505
+ * @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
158213
157506
  * @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
158214
157507
  */
158215
- async processSignals() {
157508
+ async processSignals(signals, sidecar) {
158216
157509
  const updates = new Array();
158217
- for (const signal of this.signals || []) {
157510
+ for (const signal of signals) {
158218
157511
  const updateHash = signal.signalBytes;
158219
- const signedUpdate = this.sidecar.updateMap.get(updateHash);
157512
+ const signedUpdate = sidecar.updateMap.get(updateHash);
158220
157513
  if (!signedUpdate) {
158221
157514
  throw new SingletonBeaconError(
158222
157515
  `BTCR2 Signed Update not found for update hash ${updateHash}.`,
@@ -158238,19 +157531,26 @@ a=end-of-candidates
158238
157531
  return updates;
158239
157532
  }
158240
157533
  /**
158241
- * Broadcasts a SingletonBeacon signal.
158242
- * TODO: Design and implement a way to construct, sign and send via RPC
158243
- *
158244
- * @returns {SignedRawTx} Successful output of a bitcoin transaction.
157534
+ * Broadcasts a SingletonBeacon signal to the Bitcoin network.
157535
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
157536
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
157537
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
157538
+ * @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
158245
157539
  * @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
158246
157540
  */
158247
- async broadcastSignal(updateHash) {
157541
+ async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
158248
157542
  const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
158249
- const utxos = await this.bitcoin.network.rest.address.getUtxos(bitcoinAddress);
157543
+ const utxos = await bitcoin3.network.rest.address.getUtxos(bitcoinAddress);
158250
157544
  if (!utxos.length) {
158251
- throw new SingletonBeaconError("No UTXOs found, please fund address!", "UNFUNDED_BEACON_ADDRESS", { bitcoinAddress });
157545
+ throw new SingletonBeaconError(
157546
+ "No UTXOs found, please fund address!",
157547
+ "UNFUNDED_BEACON_ADDRESS",
157548
+ { bitcoinAddress }
157549
+ );
158252
157550
  }
158253
- const utxo = utxos.sort((a3, b2) => b2.status.block_height - a3.status.block_height)[0];
157551
+ const utxo = utxos.sort(
157552
+ (a3, b2) => b2.status.block_height - a3.status.block_height
157553
+ ).shift();
158254
157554
  if (!utxo) {
158255
157555
  throw new SingletonBeaconError(
158256
157556
  "Beacon bitcoin address unfunded or utxos unconfirmed.",
@@ -158258,83 +157558,55 @@ a=end-of-candidates
158258
157558
  { bitcoinAddress }
158259
157559
  );
158260
157560
  }
158261
- const udpateHashBytes = import_buffer.Buffer.from(updateHash, "hex");
158262
- if (udpateHashBytes.length !== 32) {
158263
- throw new SingletonBeaconError("Hash must be 32 bytes");
158264
- }
158265
- const { txid, vout } = utxo;
158266
- const prevTx = await this.bitcoin.network.rest.transaction.getHex(txid);
158267
- const input = {
158268
- hash: txid,
158269
- index: vout,
157561
+ const prevTx = await bitcoin3.network.rest.transaction.getHex(utxo.txid);
157562
+ const updateHash = canonicalization2.canonicalhash(signedUpdate);
157563
+ const spendTx = new Psbt2({ network: bitcoin3.network.data }).addInput({
157564
+ hash: utxo.txid,
157565
+ index: utxo.vout,
158270
157566
  nonWitnessUtxo: import_buffer.Buffer.from(prevTx, "hex")
158271
- };
158272
- const spendTx = new Psbt2({ network: this.bitcoin.network.data }).addInput(input).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, udpateHashBytes]), value: 0n });
158273
- const components = Identifier.decode(this.service.id);
158274
- const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
158275
- const keyPair = Kms.getKey(keyUri);
157567
+ }).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports.compile([OPS.OP_RETURN, updateHash]), value: 0n });
157568
+ const keyPair = SchnorrKeyPair.fromSecret(secretKey);
158276
157569
  if (!keyPair) {
158277
- throw new Error("Key pair not found.");
157570
+ throw new SingletonBeaconError("Key pair not found.", "KEY_PAIR_NOT_FOUND", { secretKey });
158278
157571
  }
158279
- const signer = new Signer({ keyPair, network: this.bitcoin.network.name });
157572
+ const signer = new Signer({ keyPair, network: bitcoin3.network.name });
158280
157573
  const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
158281
- if (!spendTx) {
158282
- throw new SingletonBeaconError("Failed to sign raw transaction.", "RAW_TX_SIGN_FAILED", { spendTx });
158283
- }
158284
- const spentTx = await this.bitcoin.network.rest.transaction.send(signedTx);
158285
- if (!spentTx) {
158286
- throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
158287
- }
158288
- return spentTx;
157574
+ const txid = await bitcoin3.network.rest.transaction.send(signedTx);
157575
+ console.info(`Broadcasted Singleton Beacon signal with txid ${txid}`);
157576
+ return signedUpdate;
158289
157577
  }
158290
157578
  };
158291
157579
 
158292
157580
  // src/core/beacon/smt-beacon.ts
158293
157581
  init_shim();
158294
- var SMTBeacon = class _SMTBeacon extends AggregateBeacon {
157582
+ var SMTBeacon = class extends Beacon {
158295
157583
  /**
158296
- * Creates an instance of SingletonBeacon.
157584
+ * Creates an instance of SMTBeacon.
158297
157585
  * @param {BeaconService} service The Beacon service.
158298
- * @param {Array<BeaconSignal>} signals The SingletonBeacon sidecar data.
158299
- * @param {SidecarData} sidecar The sidecar data.
158300
157586
  */
158301
- constructor(service, signals, sidecar, bitcoin3) {
158302
- super({ ...service, type: "SMTBeacon" }, signals, sidecar, bitcoin3);
157587
+ constructor(service) {
157588
+ super({ ...service, type: "SMTBeacon" });
158303
157589
  }
158304
157590
  /**
158305
- * Static, convenience method for establishing a SMTBeacon object.
158306
- * @param {string} service The Beacon service.
158307
- * @param {SidecarData} sidecar The sidecar data.
158308
- * @returns {SingletonBeacon} The Singleton Beacon.
157591
+ * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
157592
+ * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
157593
+ * @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
157594
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
157595
+ * @throws {SMTBeaconError} if processing fails.
158309
157596
  */
158310
- static establish(service, signals, sidecar) {
158311
- return new _SMTBeacon(service, signals, sidecar);
157597
+ processSignals(signals, sidecar) {
157598
+ throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
158312
157599
  }
158313
157600
  /**
158314
- * TODO: Figure out if this is necessary or not.
158315
- * @param {HexString} updateHash The hash of the BTCR2 update to generate the signal for.
158316
- * @returns {BeaconSignal} The generated signal.
158317
- * @throws {MethodError} if the signal is invalid.
157601
+ * Broadcast CAS Beacon signal to the Bitcoin network.
157602
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
157603
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
157604
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
157605
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
157606
+ * @throws {SMTBeaconError} if broadcasting fails.
158318
157607
  */
158319
- generateSignal(updateHash) {
158320
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
158321
- }
158322
- /**
158323
- * Process SMTBeacon signals.
158324
- * @returns {Promise<Array<BTCR2SignedUpdate>>} The processed signed update or undefined.
158325
- * @throws {MethodError} if the signal processing fails.
158326
- */
158327
- async processSignals() {
158328
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`);
158329
- }
158330
- /**
158331
- * Broadcast a SMTBeacon signal.
158332
- * @param {HexString} updateHash The hash of the BTCR2 update to broadcast.
158333
- * @returns {Promise<SignalsMetadata>} The result of the broadcast.
158334
- * @throws {MethodError} if the broadcast fails.
158335
- */
158336
- async broadcastSignal(updateHash) {
158337
- throw new MethodError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
157608
+ async broadcastSignal(signedUpdate, secretKey, bitcoin3) {
157609
+ throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin3 });
158338
157610
  }
158339
157611
  };
158340
157612
 
@@ -158342,25 +157614,26 @@ a=end-of-candidates
158342
157614
  var BeaconFactory = class {
158343
157615
  /**
158344
157616
  * Establish a Beacon instance based on the provided service and optional sidecar data.
158345
- * @param {BeaconService} service - The beacon service configuration.
158346
- * @param {Array<BeaconSignal>} signals - The array of beacon signals.
158347
- * @param {SidecarData} sidecar - The sidecar data associated with the beacon.
157617
+ * @param {BeaconService} service The beacon service configuration.
158348
157618
  * @returns {Beacon} The established Beacon instance.
158349
157619
  */
158350
- static establish(service, signals, sidecar) {
157620
+ static establish(service) {
158351
157621
  switch (service.type) {
158352
157622
  case "SingletonBeacon":
158353
- return new SingletonBeacon(service, signals, sidecar);
157623
+ return new SingletonBeacon(service);
158354
157624
  case "CASBeacon":
158355
- return new CASBeacon(service, signals, sidecar);
157625
+ return new CASBeacon(service);
158356
157626
  case "SMTBeacon":
158357
- return new SMTBeacon(service, signals, sidecar);
157627
+ return new SMTBeacon(service);
158358
157628
  default:
158359
157629
  throw new MethodError("Invalid Beacon Type", "INVALID_BEACON_ERROR", service);
158360
157630
  }
158361
157631
  }
158362
157632
  };
158363
157633
 
157634
+ // src/core/beacon/interfaces.ts
157635
+ init_shim();
157636
+
158364
157637
  // src/core/interfaces.ts
158365
157638
  init_shim();
158366
157639
 
@@ -160819,9 +160092,6 @@ fast-json-patch/module/duplex.mjs:
160819
160092
  @scure/bip39/esm/index.js:
160820
160093
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
160821
160094
 
160822
- @noble/hashes/utils.js:
160823
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
160824
-
160825
160095
  @noble/hashes/esm/utils.js:
160826
160096
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
160827
160097