@did-btcr2/api 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.mjs CHANGED
@@ -1972,17 +1972,17 @@ var require_utils = __commonJS({
1972
1972
  init_shim();
1973
1973
  Object.defineProperty(exports, "__esModule", { value: true });
1974
1974
  exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
1975
- exports.isBytes = isBytes13;
1975
+ exports.isBytes = isBytes12;
1976
1976
  exports.anumber = anumber4;
1977
- exports.abytes = abytes6;
1977
+ exports.abytes = abytes5;
1978
1978
  exports.ahash = ahash3;
1979
- exports.aexists = aexists4;
1980
- exports.aoutput = aoutput4;
1979
+ exports.aexists = aexists3;
1980
+ exports.aoutput = aoutput3;
1981
1981
  exports.u8 = u82;
1982
1982
  exports.u32 = u323;
1983
- exports.clean = clean4;
1984
- exports.createView = createView10;
1985
- exports.rotr = rotr7;
1983
+ exports.clean = clean3;
1984
+ exports.createView = createView9;
1985
+ exports.rotr = rotr6;
1986
1986
  exports.rotl = rotl4;
1987
1987
  exports.byteSwap = byteSwap;
1988
1988
  exports.byteSwap32 = byteSwap32;
@@ -2000,15 +2000,15 @@ var require_utils = __commonJS({
2000
2000
  exports.createXOFer = createXOFer;
2001
2001
  exports.randomBytes = randomBytes7;
2002
2002
  var crypto_1 = require_crypto();
2003
- function isBytes13(a3) {
2003
+ function isBytes12(a3) {
2004
2004
  return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
2005
2005
  }
2006
2006
  function anumber4(n3) {
2007
2007
  if (!Number.isSafeInteger(n3) || n3 < 0)
2008
2008
  throw new Error("positive integer expected, got " + n3);
2009
2009
  }
2010
- function abytes6(b3, ...lengths) {
2011
- if (!isBytes13(b3))
2010
+ function abytes5(b3, ...lengths) {
2011
+ if (!isBytes12(b3))
2012
2012
  throw new Error("Uint8Array expected");
2013
2013
  if (lengths.length > 0 && !lengths.includes(b3.length))
2014
2014
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b3.length);
@@ -2019,14 +2019,14 @@ var require_utils = __commonJS({
2019
2019
  anumber4(h2.outputLen);
2020
2020
  anumber4(h2.blockLen);
2021
2021
  }
2022
- function aexists4(instance3, checkFinished = true) {
2022
+ function aexists3(instance3, checkFinished = true) {
2023
2023
  if (instance3.destroyed)
2024
2024
  throw new Error("Hash instance has been destroyed");
2025
2025
  if (checkFinished && instance3.finished)
2026
2026
  throw new Error("Hash#digest() has already been called");
2027
2027
  }
2028
- function aoutput4(out, instance3) {
2029
- abytes6(out);
2028
+ function aoutput3(out, instance3) {
2029
+ abytes5(out);
2030
2030
  const min = instance3.outputLen;
2031
2031
  if (out.length < min) {
2032
2032
  throw new Error("digestInto() expects output buffer of length at least " + min);
@@ -2038,15 +2038,15 @@ var require_utils = __commonJS({
2038
2038
  function u323(arr) {
2039
2039
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
2040
2040
  }
2041
- function clean4(...arrays) {
2041
+ function clean3(...arrays) {
2042
2042
  for (let i5 = 0; i5 < arrays.length; i5++) {
2043
2043
  arrays[i5].fill(0);
2044
2044
  }
2045
2045
  }
2046
- function createView10(arr) {
2046
+ function createView9(arr) {
2047
2047
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
2048
2048
  }
2049
- function rotr7(word2, shift) {
2049
+ function rotr6(word2, shift) {
2050
2050
  return word2 << 32 - shift | word2 >>> shift;
2051
2051
  }
2052
2052
  function rotl4(word2, shift) {
@@ -2071,7 +2071,7 @@ var require_utils = __commonJS({
2071
2071
  ))();
2072
2072
  var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i5) => i5.toString(16).padStart(2, "0"));
2073
2073
  function bytesToHex6(bytes6) {
2074
- abytes6(bytes6);
2074
+ abytes5(bytes6);
2075
2075
  if (hasHexBuiltin3)
2076
2076
  return bytes6.toHex();
2077
2077
  let hex3 = "";
@@ -2136,20 +2136,20 @@ var require_utils = __commonJS({
2136
2136
  function toBytes8(data) {
2137
2137
  if (typeof data === "string")
2138
2138
  data = utf8ToBytes11(data);
2139
- abytes6(data);
2139
+ abytes5(data);
2140
2140
  return data;
2141
2141
  }
2142
2142
  function kdfInputToBytes2(data) {
2143
2143
  if (typeof data === "string")
2144
2144
  data = utf8ToBytes11(data);
2145
- abytes6(data);
2145
+ abytes5(data);
2146
2146
  return data;
2147
2147
  }
2148
2148
  function concatBytes11(...arrays) {
2149
2149
  let sum = 0;
2150
2150
  for (let i5 = 0; i5 < arrays.length; i5++) {
2151
2151
  const a3 = arrays[i5];
2152
- abytes6(a3);
2152
+ abytes5(a3);
2153
2153
  sum += a3.length;
2154
2154
  }
2155
2155
  const res = new Uint8Array(sum);
@@ -2216,8 +2216,8 @@ var require_md = __commonJS({
2216
2216
  Object.defineProperty(exports, "__esModule", { value: true });
2217
2217
  exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
2218
2218
  exports.setBigUint64 = setBigUint648;
2219
- exports.Chi = Chi7;
2220
- exports.Maj = Maj7;
2219
+ exports.Chi = Chi6;
2220
+ exports.Maj = Maj6;
2221
2221
  var utils_ts_1 = require_utils();
2222
2222
  function setBigUint648(view, byteOffset, value3, isLE7) {
2223
2223
  if (typeof view.setBigUint64 === "function")
@@ -2231,13 +2231,13 @@ var require_md = __commonJS({
2231
2231
  view.setUint32(byteOffset + h2, wh, isLE7);
2232
2232
  view.setUint32(byteOffset + l2, wl, isLE7);
2233
2233
  }
2234
- function Chi7(a3, b3, c2) {
2234
+ function Chi6(a3, b3, c2) {
2235
2235
  return a3 & b3 ^ ~a3 & c2;
2236
2236
  }
2237
- function Maj7(a3, b3, c2) {
2237
+ function Maj6(a3, b3, c2) {
2238
2238
  return a3 & b3 ^ a3 & c2 ^ b3 & c2;
2239
2239
  }
2240
- var HashMD4 = class extends utils_ts_1.Hash {
2240
+ var HashMD3 = class extends utils_ts_1.Hash {
2241
2241
  constructor(blockLen, outputLen, padOffset, isLE7) {
2242
2242
  super();
2243
2243
  this.finished = false;
@@ -2327,7 +2327,7 @@ var require_md = __commonJS({
2327
2327
  return this._cloneInto();
2328
2328
  }
2329
2329
  };
2330
- exports.HashMD = HashMD4;
2330
+ exports.HashMD = HashMD3;
2331
2331
  exports.SHA256_IV = Uint32Array.from([
2332
2332
  1779033703,
2333
2333
  3144134277,
@@ -2494,7 +2494,7 @@ var require_sha2 = __commonJS({
2494
2494
  var _md_ts_1 = require_md();
2495
2495
  var u642 = require_u64();
2496
2496
  var utils_ts_1 = require_utils();
2497
- var SHA256_K7 = /* @__PURE__ */ Uint32Array.from([
2497
+ var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
2498
2498
  1116352408,
2499
2499
  1899447441,
2500
2500
  3049323471,
@@ -2560,7 +2560,7 @@ var require_sha2 = __commonJS({
2560
2560
  3204031479,
2561
2561
  3329325298
2562
2562
  ]);
2563
- var SHA256_W7 = /* @__PURE__ */ new Uint32Array(64);
2563
+ var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
2564
2564
  var SHA2566 = class extends _md_ts_1.HashMD {
2565
2565
  constructor(outputLen = 32) {
2566
2566
  super(64, outputLen, 8, false);
@@ -2590,18 +2590,18 @@ var require_sha2 = __commonJS({
2590
2590
  }
2591
2591
  process(view, offset) {
2592
2592
  for (let i5 = 0; i5 < 16; i5++, offset += 4)
2593
- SHA256_W7[i5] = view.getUint32(offset, false);
2593
+ SHA256_W6[i5] = view.getUint32(offset, false);
2594
2594
  for (let i5 = 16; i5 < 64; i5++) {
2595
- const W15 = SHA256_W7[i5 - 15];
2596
- const W2 = SHA256_W7[i5 - 2];
2595
+ const W15 = SHA256_W6[i5 - 15];
2596
+ const W2 = SHA256_W6[i5 - 2];
2597
2597
  const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
2598
2598
  const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
2599
- SHA256_W7[i5] = s1 + SHA256_W7[i5 - 7] + s0 + SHA256_W7[i5 - 16] | 0;
2599
+ SHA256_W6[i5] = s1 + SHA256_W6[i5 - 7] + s0 + SHA256_W6[i5 - 16] | 0;
2600
2600
  }
2601
2601
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
2602
2602
  for (let i5 = 0; i5 < 64; i5++) {
2603
2603
  const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
2604
- const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K7[i5] + SHA256_W7[i5] | 0;
2604
+ const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i5] + SHA256_W6[i5] | 0;
2605
2605
  const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
2606
2606
  const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
2607
2607
  H = G2;
@@ -2624,7 +2624,7 @@ var require_sha2 = __commonJS({
2624
2624
  this.set(A, B, C2, D, E, F, G2, H);
2625
2625
  }
2626
2626
  roundClean() {
2627
- (0, utils_ts_1.clean)(SHA256_W7);
2627
+ (0, utils_ts_1.clean)(SHA256_W6);
2628
2628
  }
2629
2629
  destroy() {
2630
2630
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
@@ -40358,9 +40358,9 @@ var BIP340DataIntegrityProof = class {
40358
40358
  }
40359
40359
  /**
40360
40360
  * Add a proof to a document.
40361
- * @param {BTCR2UnsignedUpdate} unsignedDocument The document to add the proof to.
40361
+ * @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
40362
40362
  * @param {DataIntegrityConfig} config The configuration for generating the proof.
40363
- * @returns {BTCR2SignedUpdate} A document with a proof added.
40363
+ * @returns {SignedBTCR2Update} A document with a proof added.
40364
40364
  */
40365
40365
  addProof(unsignedDocument, config) {
40366
40366
  const proof = this.cryptosuite.createProof(unsignedDocument, config);
@@ -40475,7 +40475,7 @@ var BIP340Cryptosuite = class {
40475
40475
  }
40476
40476
  /**
40477
40477
  * Verify a proof for a secure document.
40478
- * @param {BTCR2SignedUpdate} secureDocument The secure document to verify.
40478
+ * @param {SignedBTCR2Update} secureDocument The secure document to verify.
40479
40479
  * @returns {VerificationResult} The result of the verification.
40480
40480
  */
40481
40481
  verifyProof(secureDocument) {
@@ -40490,7 +40490,7 @@ var BIP340Cryptosuite = class {
40490
40490
  }
40491
40491
  /**
40492
40492
  * Transform a document into canonical form.
40493
- * @param {BTCR2UnsignedUpdate | BTCR2SignedUpdate} document The document to transform.
40493
+ * @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
40494
40494
  * @param {DataIntegrityConfig} config The config to use when transforming the document.
40495
40495
  * @returns {string} The canonicalized document.
40496
40496
  * @throws {MethodError} if the document cannot be transformed.
@@ -40596,16 +40596,16 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey2 {
40596
40596
  #multibase;
40597
40597
  /**
40598
40598
  * Instantiates an instance of Secp256k1SecretKey.
40599
- * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
40599
+ * @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
40600
40600
  * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
40601
40601
  */
40602
40602
  constructor(entropy) {
40603
- const isBytes13 = entropy instanceof Uint8Array;
40603
+ const isBytes12 = entropy instanceof Uint8Array;
40604
40604
  const isSecret = typeof entropy === "bigint";
40605
- if (!isBytes13 && !isSecret) {
40605
+ if (!isBytes12 && !isSecret) {
40606
40606
  throw new SecretKeyError("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
40607
40607
  }
40608
- if (isBytes13 && entropy.length === 32) {
40608
+ if (isBytes12 && entropy.length === 32) {
40609
40609
  this.#bytes = entropy;
40610
40610
  this.#seed = _Secp256k1SecretKey2.toSecret(entropy);
40611
40611
  }
@@ -40790,15 +40790,23 @@ var Secp256k1SecretKey = class _Secp256k1SecretKey2 {
40790
40790
  }
40791
40791
  return new Uint8Array(bytes6);
40792
40792
  }
40793
+ /**
40794
+ * Creates a new Secp256k1SecretKey object from random bytes.
40795
+ * @param {KeyBytes} bytes The secret key bytes
40796
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
40797
+ */
40798
+ static fromBytes(bytes6) {
40799
+ return new _Secp256k1SecretKey2(bytes6);
40800
+ }
40793
40801
  /**
40794
40802
  * Creates a new Secp256k1SecretKey object from a bigint secret.
40795
- * @param {bigint} entropy The secret bigint
40803
+ * @param {bigint} bint The secret bigint
40796
40804
  * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
40797
40805
  */
40798
- static fromEntropy(entropy) {
40799
- const hexsecret = entropy.toString(16).padStart(64, "0");
40800
- const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
40801
- return new _Secp256k1SecretKey2(privateKeyBytes);
40806
+ static fromBigInt(bint) {
40807
+ const hexsecret = bint.toString(16).padStart(64, "0");
40808
+ const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
40809
+ return new _Secp256k1SecretKey2(bytes6);
40802
40810
  }
40803
40811
  /**
40804
40812
  * Generates random secret key bytes.
@@ -41115,12 +41123,18 @@ var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey2 {
41115
41123
 
41116
41124
  // ../keypair/dist/esm/pair.js
41117
41125
  var SchnorrKeyPair = class _SchnorrKeyPair2 {
41118
- /** @type {Secp256k1SecretKey} The secret key object */
41126
+ /**
41127
+ * The secret key objec
41128
+ */
41119
41129
  #secretKey;
41120
41130
  #publicKey;
41121
- /** @type {string} The public key in multibase format */
41131
+ /**
41132
+ * The public key in multibase forma
41133
+ */
41122
41134
  #publicKeyMultibase;
41123
- /** @type {string} The secret key in multibase format */
41135
+ /**
41136
+ * The secret key in multibase forma
41137
+ */
41124
41138
  #secretKeyMultibase;
41125
41139
  /**
41126
41140
  * Creates an instance of Keys. Must provide a at least a secret key.
@@ -41258,11 +41272,11 @@ var SchnorrKeyPair = class _SchnorrKeyPair2 {
41258
41272
  }
41259
41273
  /**
41260
41274
  * Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
41261
- * @param {bigint} entropy The entropy in bigint form
41275
+ * @param {bigint} bint The entropy in bigint form
41262
41276
  * @returns {SchnorrKeyPair} A new SchnorrKeyPair object
41263
41277
  */
41264
- static fromEntropy(entropy) {
41265
- const secretKey = Secp256k1SecretKey.fromEntropy(entropy);
41278
+ static fromBigInt(bint) {
41279
+ const secretKey = Secp256k1SecretKey.fromBigInt(bint);
41266
41280
  const publicKey2 = secretKey.computePublicKey();
41267
41281
  return new _SchnorrKeyPair2({ secretKey, publicKey: publicKey2 });
41268
41282
  }
@@ -43372,29 +43386,27 @@ var SchnorrMultikey = class _SchnorrMultikey2 {
43372
43386
  * @param {MultikeyParams} params The parameters to create the multikey
43373
43387
  * @param {string} params.id The id of the multikey (required)
43374
43388
  * @param {string} params.controller The controller of the multikey (required)
43375
- * @param {Keys} params.keys The Keys of the multikey (optional, required if no publicKey)
43376
- * @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
43377
- * @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
43389
+ * @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
43378
43390
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
43379
43391
  */
43380
- constructor({ id, controller, keys }) {
43381
- if (!keys) {
43382
- throw new MultikeyError('Argument missing: "keys" required', "CONSTRUCTOR_ERROR");
43392
+ constructor({ id, controller, keyPair }) {
43393
+ if (!keyPair) {
43394
+ throw new MultikeyError('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
43383
43395
  }
43384
- if (!keys.publicKey) {
43385
- throw new MultikeyError('Argument missing: "keys" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
43396
+ if (!keyPair.publicKey) {
43397
+ throw new MultikeyError('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
43386
43398
  }
43387
43399
  this.id = id;
43388
43400
  this.controller = controller;
43389
- this.#keyPair = keys;
43401
+ this.#keyPair = keyPair;
43390
43402
  }
43391
43403
  /**
43392
43404
  * @readonly
43393
43405
  * Get the SchnorrKeyPair.
43394
43406
  */
43395
43407
  get keyPair() {
43396
- const keys = this.#keyPair;
43397
- return keys;
43408
+ const keyPair = this.#keyPair;
43409
+ return keyPair;
43398
43410
  }
43399
43411
  /**
43400
43412
  * @readonly
@@ -43501,9 +43513,10 @@ var SchnorrMultikey = class _SchnorrMultikey2 {
43501
43513
  throw new MultikeyError('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR, { verificationMethod });
43502
43514
  }
43503
43515
  const decoded = this.publicKey.decode();
43504
- const publicKey2 = decoded.slice(2, decoded.length);
43505
- const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKey2) });
43506
- return new _SchnorrMultikey2({ id, controller, keys });
43516
+ const pk = decoded.slice(2, decoded.length);
43517
+ const publicKey2 = new CompressedSecp256k1PublicKey(pk);
43518
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
43519
+ return new _SchnorrMultikey2({ id, controller, keyPair });
43507
43520
  }
43508
43521
  /**
43509
43522
  * @readonly
@@ -43537,22 +43550,21 @@ var SchnorrMultikey = class _SchnorrMultikey2 {
43537
43550
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
43538
43551
  * @returns {SchnorrMultikey} A new Multikey instance
43539
43552
  */
43540
- static create({ id, controller, keys }) {
43541
- return new _SchnorrMultikey2({ id, controller, keys });
43553
+ static create({ id, controller, keyPair }) {
43554
+ return new _SchnorrMultikey2({ id, controller, keyPair });
43542
43555
  }
43543
43556
  /**
43544
43557
  * Creates a `Multikey` instance from a private key
43545
- * @param {FromPublicKey} params The parameters to create the multikey
43546
43558
  * @param {string} params.id The id of the multikey
43547
43559
  * @param {string} params.controller The controller of the multikey
43548
43560
  * @param {KeyBytes} params.entropy The private key bytes for the multikey
43549
43561
  * @returns {SchnorrMultikey} The new multikey instance
43550
43562
  */
43551
- static fromPrivateKey({ id, controller, entropy }) {
43552
- const secretKey = new Secp256k1SecretKey(entropy);
43563
+ static fromSecretKey(id, controller, secretKeyb) {
43564
+ const secretKey = new Secp256k1SecretKey(secretKeyb);
43553
43565
  const publicKey2 = secretKey.computePublicKey();
43554
- const keys = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
43555
- return new _SchnorrMultikey2({ id, controller, keys });
43566
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
43567
+ return new _SchnorrMultikey2({ id, controller, keyPair });
43556
43568
  }
43557
43569
  /**
43558
43570
  * Creates a `Multikey` instance from a public key
@@ -43563,24 +43575,29 @@ var SchnorrMultikey = class _SchnorrMultikey2 {
43563
43575
  * @returns {Multikey} The new multikey instance
43564
43576
  */
43565
43577
  static fromPublicKey({ id, controller, publicKeyBytes }) {
43566
- const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKeyBytes) });
43567
- return new _SchnorrMultikey2({ id, controller, keys });
43578
+ const publicKey2 = new CompressedSecp256k1PublicKey(publicKeyBytes);
43579
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
43580
+ return new _SchnorrMultikey2({ id, controller, keyPair });
43568
43581
  }
43569
43582
  /**
43570
43583
  * Creates a `Multikey` instance from a public key multibase.
43571
- * @param {string} id The id of the multikey.
43572
- * @param {string} controller The controller of the multikey.
43573
- * @param {string} publicKeyMultibase The public key multibase of the multikey.
43584
+ * @param {DidVerificationMethod} vm The verification method containing the public key multibase.
43585
+ * @param {string} vm.id The id of the multikey.
43586
+ * @param {string} vm.controller The controller of the multikey.
43587
+ * @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
43574
43588
  * @returns {Multikey} The new multikey instance.
43575
43589
  */
43576
- static fromPublicKeyMultibase(id, controller, publicKeyMultibase) {
43590
+ static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
43591
+ if (!publicKeyMultibase) {
43592
+ throw new MultikeyError("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
43593
+ }
43577
43594
  const publicKeyMultibaseBytes = base58btc.decode(publicKeyMultibase);
43578
43595
  if (publicKeyMultibaseBytes.length !== 35) {
43579
43596
  throw new MultikeyError(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR, { publicKeyMultibase });
43580
43597
  }
43581
43598
  const publicKey2 = publicKeyMultibaseBytes.slice(2);
43582
- const keys = new SchnorrKeyPair({ publicKey: publicKey2 });
43583
- return new _SchnorrMultikey2({ id, controller, keys });
43599
+ const keyPair = new SchnorrKeyPair({ publicKey: publicKey2 });
43600
+ return new _SchnorrMultikey2({ id, controller, keyPair });
43584
43601
  }
43585
43602
  };
43586
43603
 
@@ -45549,17 +45566,17 @@ var require_utils8 = __commonJS2({
45549
45566
  init_shim2();
45550
45567
  Object.defineProperty(exports, "__esModule", { value: true });
45551
45568
  exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.Hash = exports.nextTick = exports.swap32IfBE = exports.byteSwapIfBE = exports.swap8IfBE = exports.isLE = void 0;
45552
- exports.isBytes = isBytes13;
45569
+ exports.isBytes = isBytes12;
45553
45570
  exports.anumber = anumber4;
45554
- exports.abytes = abytes6;
45571
+ exports.abytes = abytes5;
45555
45572
  exports.ahash = ahash22;
45556
- exports.aexists = aexists4;
45557
- exports.aoutput = aoutput4;
45573
+ exports.aexists = aexists3;
45574
+ exports.aoutput = aoutput3;
45558
45575
  exports.u8 = u82;
45559
45576
  exports.u32 = u323;
45560
- exports.clean = clean4;
45561
- exports.createView = createView10;
45562
- exports.rotr = rotr7;
45577
+ exports.clean = clean3;
45578
+ exports.createView = createView9;
45579
+ exports.rotr = rotr6;
45563
45580
  exports.rotl = rotl4;
45564
45581
  exports.byteSwap = byteSwap;
45565
45582
  exports.byteSwap32 = byteSwap32;
@@ -45572,20 +45589,20 @@ var require_utils8 = __commonJS2({
45572
45589
  exports.kdfInputToBytes = kdfInputToBytes2;
45573
45590
  exports.concatBytes = concatBytes11;
45574
45591
  exports.checkOpts = checkOpts4;
45575
- exports.createHasher = createHasher3;
45592
+ exports.createHasher = createHasher22;
45576
45593
  exports.createOptHasher = createOptHasher;
45577
45594
  exports.createXOFer = createXOFer;
45578
45595
  exports.randomBytes = randomBytes10;
45579
45596
  var crypto_1 = require_crypto2();
45580
- function isBytes13(a3) {
45597
+ function isBytes12(a3) {
45581
45598
  return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
45582
45599
  }
45583
45600
  function anumber4(n3) {
45584
45601
  if (!Number.isSafeInteger(n3) || n3 < 0)
45585
45602
  throw new Error("positive integer expected, got " + n3);
45586
45603
  }
45587
- function abytes6(b22, ...lengths) {
45588
- if (!isBytes13(b22))
45604
+ function abytes5(b22, ...lengths) {
45605
+ if (!isBytes12(b22))
45589
45606
  throw new Error("Uint8Array expected");
45590
45607
  if (lengths.length > 0 && !lengths.includes(b22.length))
45591
45608
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b22.length);
@@ -45596,14 +45613,14 @@ var require_utils8 = __commonJS2({
45596
45613
  anumber4(h2.outputLen);
45597
45614
  anumber4(h2.blockLen);
45598
45615
  }
45599
- function aexists4(instance3, checkFinished = true) {
45616
+ function aexists3(instance3, checkFinished = true) {
45600
45617
  if (instance3.destroyed)
45601
45618
  throw new Error("Hash instance has been destroyed");
45602
45619
  if (checkFinished && instance3.finished)
45603
45620
  throw new Error("Hash#digest() has already been called");
45604
45621
  }
45605
- function aoutput4(out, instance3) {
45606
- abytes6(out);
45622
+ function aoutput3(out, instance3) {
45623
+ abytes5(out);
45607
45624
  const min = instance3.outputLen;
45608
45625
  if (out.length < min) {
45609
45626
  throw new Error("digestInto() expects output buffer of length at least " + min);
@@ -45615,15 +45632,15 @@ var require_utils8 = __commonJS2({
45615
45632
  function u323(arr) {
45616
45633
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
45617
45634
  }
45618
- function clean4(...arrays) {
45635
+ function clean3(...arrays) {
45619
45636
  for (let i42 = 0; i42 < arrays.length; i42++) {
45620
45637
  arrays[i42].fill(0);
45621
45638
  }
45622
45639
  }
45623
- function createView10(arr) {
45640
+ function createView9(arr) {
45624
45641
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
45625
45642
  }
45626
- function rotr7(word2, shift) {
45643
+ function rotr6(word2, shift) {
45627
45644
  return word2 << 32 - shift | word2 >>> shift;
45628
45645
  }
45629
45646
  function rotl4(word2, shift) {
@@ -45648,7 +45665,7 @@ var require_utils8 = __commonJS2({
45648
45665
  ))();
45649
45666
  var hexes5 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i42) => i42.toString(16).padStart(2, "0"));
45650
45667
  function bytesToHex6(bytes6) {
45651
- abytes6(bytes6);
45668
+ abytes5(bytes6);
45652
45669
  if (hasHexBuiltin3)
45653
45670
  return bytes6.toHex();
45654
45671
  let hex3 = "";
@@ -45713,20 +45730,20 @@ var require_utils8 = __commonJS2({
45713
45730
  function toBytes8(data) {
45714
45731
  if (typeof data === "string")
45715
45732
  data = utf8ToBytes11(data);
45716
- abytes6(data);
45733
+ abytes5(data);
45717
45734
  return data;
45718
45735
  }
45719
45736
  function kdfInputToBytes2(data) {
45720
45737
  if (typeof data === "string")
45721
45738
  data = utf8ToBytes11(data);
45722
- abytes6(data);
45739
+ abytes5(data);
45723
45740
  return data;
45724
45741
  }
45725
45742
  function concatBytes11(...arrays) {
45726
45743
  let sum = 0;
45727
45744
  for (let i42 = 0; i42 < arrays.length; i42++) {
45728
45745
  const a3 = arrays[i42];
45729
- abytes6(a3);
45746
+ abytes5(a3);
45730
45747
  sum += a3.length;
45731
45748
  }
45732
45749
  const res = new Uint8Array(sum);
@@ -45746,7 +45763,7 @@ var require_utils8 = __commonJS2({
45746
45763
  var Hash7 = class {
45747
45764
  };
45748
45765
  exports.Hash = Hash7;
45749
- function createHasher3(hashCons) {
45766
+ function createHasher22(hashCons) {
45750
45767
  const hashC = (msg) => hashCons().update(toBytes8(msg)).digest();
45751
45768
  const tmp = hashCons();
45752
45769
  hashC.outputLen = tmp.outputLen;
@@ -45770,7 +45787,7 @@ var require_utils8 = __commonJS2({
45770
45787
  hashC.create = (opts) => hashCons(opts);
45771
45788
  return hashC;
45772
45789
  }
45773
- exports.wrapConstructor = createHasher3;
45790
+ exports.wrapConstructor = createHasher22;
45774
45791
  exports.wrapConstructorWithOpts = createOptHasher;
45775
45792
  exports.wrapXOFConstructorWithOpts = createXOFer;
45776
45793
  function randomBytes10(bytesLength = 32) {
@@ -45791,8 +45808,8 @@ var require_md2 = __commonJS2({
45791
45808
  Object.defineProperty(exports, "__esModule", { value: true });
45792
45809
  exports.SHA512_IV = exports.SHA384_IV = exports.SHA224_IV = exports.SHA256_IV = exports.HashMD = void 0;
45793
45810
  exports.setBigUint64 = setBigUint648;
45794
- exports.Chi = Chi7;
45795
- exports.Maj = Maj7;
45811
+ exports.Chi = Chi6;
45812
+ exports.Maj = Maj6;
45796
45813
  var utils_ts_1 = require_utils8();
45797
45814
  function setBigUint648(view, byteOffset, value3, isLE7) {
45798
45815
  if (typeof view.setBigUint64 === "function")
@@ -45806,13 +45823,13 @@ var require_md2 = __commonJS2({
45806
45823
  view.setUint32(byteOffset + h2, wh, isLE7);
45807
45824
  view.setUint32(byteOffset + l2, wl, isLE7);
45808
45825
  }
45809
- function Chi7(a3, b22, c2) {
45826
+ function Chi6(a3, b22, c2) {
45810
45827
  return a3 & b22 ^ ~a3 & c2;
45811
45828
  }
45812
- function Maj7(a3, b22, c2) {
45829
+ function Maj6(a3, b22, c2) {
45813
45830
  return a3 & b22 ^ a3 & c2 ^ b22 & c2;
45814
45831
  }
45815
- var HashMD4 = class extends utils_ts_1.Hash {
45832
+ var HashMD3 = class extends utils_ts_1.Hash {
45816
45833
  constructor(blockLen, outputLen, padOffset, isLE7) {
45817
45834
  super();
45818
45835
  this.finished = false;
@@ -45902,7 +45919,7 @@ var require_md2 = __commonJS2({
45902
45919
  return this._cloneInto();
45903
45920
  }
45904
45921
  };
45905
- exports.HashMD = HashMD4;
45922
+ exports.HashMD = HashMD3;
45906
45923
  exports.SHA256_IV = Uint32Array.from([
45907
45924
  1779033703,
45908
45925
  3144134277,
@@ -46065,7 +46082,7 @@ var require_sha22 = __commonJS2({
46065
46082
  var _md_ts_1 = require_md2();
46066
46083
  var u642 = require_u642();
46067
46084
  var utils_ts_1 = require_utils8();
46068
- var SHA256_K7 = /* @__PURE__ */ Uint32Array.from([
46085
+ var SHA256_K6 = /* @__PURE__ */ Uint32Array.from([
46069
46086
  1116352408,
46070
46087
  1899447441,
46071
46088
  3049323471,
@@ -46131,7 +46148,7 @@ var require_sha22 = __commonJS2({
46131
46148
  3204031479,
46132
46149
  3329325298
46133
46150
  ]);
46134
- var SHA256_W7 = /* @__PURE__ */ new Uint32Array(64);
46151
+ var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
46135
46152
  var SHA2566 = class extends _md_ts_1.HashMD {
46136
46153
  constructor(outputLen = 32) {
46137
46154
  super(64, outputLen, 8, false);
@@ -46161,18 +46178,18 @@ var require_sha22 = __commonJS2({
46161
46178
  }
46162
46179
  process(view, offset) {
46163
46180
  for (let i42 = 0; i42 < 16; i42++, offset += 4)
46164
- SHA256_W7[i42] = view.getUint32(offset, false);
46181
+ SHA256_W6[i42] = view.getUint32(offset, false);
46165
46182
  for (let i42 = 16; i42 < 64; i42++) {
46166
- const W15 = SHA256_W7[i42 - 15];
46167
- const W2 = SHA256_W7[i42 - 2];
46183
+ const W15 = SHA256_W6[i42 - 15];
46184
+ const W2 = SHA256_W6[i42 - 2];
46168
46185
  const s0 = (0, utils_ts_1.rotr)(W15, 7) ^ (0, utils_ts_1.rotr)(W15, 18) ^ W15 >>> 3;
46169
46186
  const s1 = (0, utils_ts_1.rotr)(W2, 17) ^ (0, utils_ts_1.rotr)(W2, 19) ^ W2 >>> 10;
46170
- SHA256_W7[i42] = s1 + SHA256_W7[i42 - 7] + s0 + SHA256_W7[i42 - 16] | 0;
46187
+ SHA256_W6[i42] = s1 + SHA256_W6[i42 - 7] + s0 + SHA256_W6[i42 - 16] | 0;
46171
46188
  }
46172
46189
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
46173
46190
  for (let i42 = 0; i42 < 64; i42++) {
46174
46191
  const sigma1 = (0, utils_ts_1.rotr)(E, 6) ^ (0, utils_ts_1.rotr)(E, 11) ^ (0, utils_ts_1.rotr)(E, 25);
46175
- const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K7[i42] + SHA256_W7[i42] | 0;
46192
+ const T1 = H + sigma1 + (0, _md_ts_1.Chi)(E, F, G2) + SHA256_K6[i42] + SHA256_W6[i42] | 0;
46176
46193
  const sigma0 = (0, utils_ts_1.rotr)(A, 2) ^ (0, utils_ts_1.rotr)(A, 13) ^ (0, utils_ts_1.rotr)(A, 22);
46177
46194
  const T2 = sigma0 + (0, _md_ts_1.Maj)(A, B, C2) | 0;
46178
46195
  H = G2;
@@ -46195,7 +46212,7 @@ var require_sha22 = __commonJS2({
46195
46212
  this.set(A, B, C2, D, E, F, G2, H);
46196
46213
  }
46197
46214
  roundClean() {
46198
- (0, utils_ts_1.clean)(SHA256_W7);
46215
+ (0, utils_ts_1.clean)(SHA256_W6);
46199
46216
  }
46200
46217
  destroy() {
46201
46218
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
@@ -48828,7 +48845,7 @@ var require_hash_to_curve2 = __commonJS2({
48828
48845
  exports.expand_message_xof = expand_message_xof;
48829
48846
  exports.hash_to_field = hash_to_field;
48830
48847
  exports.isogenyMap = isogenyMap;
48831
- exports.createHasher = createHasher3;
48848
+ exports.createHasher = createHasher22;
48832
48849
  var utils_ts_1 = require_utils22();
48833
48850
  var modular_ts_1 = require_modular2();
48834
48851
  var os2ip = utils_ts_1.bytesToNumberBE;
@@ -48943,7 +48960,7 @@ var require_hash_to_curve2 = __commonJS2({
48943
48960
  };
48944
48961
  }
48945
48962
  exports._DST_scalar = (0, utils_ts_1.utf8ToBytes)("HashToScalar-");
48946
- function createHasher3(Point7, mapToCurve, defaults2) {
48963
+ function createHasher22(Point7, mapToCurve, defaults2) {
48947
48964
  if (typeof mapToCurve !== "function")
48948
48965
  throw new Error("mapToCurve() must be defined");
48949
48966
  function map3(num22) {
@@ -90505,7 +90522,7 @@ function checksum(len, fn) {
90505
90522
  }
90506
90523
  var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
90507
90524
  var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
90508
- var createBase58check = (sha25611) => /* @__PURE__ */ chain(checksum(4, (data) => sha25611(sha25611(data))), base58);
90525
+ var createBase58check = (sha25610) => /* @__PURE__ */ chain(checksum(4, (data) => sha25610(sha25610(data))), base58);
90509
90526
  var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
90510
90527
  var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
90511
90528
  function bech32Polymod(pre) {
@@ -91029,7 +91046,7 @@ var _Writer = class {
91029
91046
  this.buffers.push(new Uint8Array([b22]));
91030
91047
  this.pos++;
91031
91048
  }
91032
- finish(clean4 = true) {
91049
+ finish(clean3 = true) {
91033
91050
  if (this.finished)
91034
91051
  throw this.err("buffer: finished");
91035
91052
  if (this.bitPos)
@@ -91047,7 +91064,7 @@ var _Writer = class {
91047
91064
  buf2.set(ptr.ptr.encode(pos), ptr.pos);
91048
91065
  pos += ptr.buffer.length;
91049
91066
  }
91050
- if (clean4) {
91067
+ if (clean3) {
91051
91068
  this.buffers = [];
91052
91069
  for (const p3 of this.ptrs)
91053
91070
  p3.buffer.fill(0);
@@ -99941,11 +99958,6 @@ var ResolveError = class extends DidMethodError2 {
99941
99958
  super(message2, { type, name: "ResolveError", data });
99942
99959
  }
99943
99960
  };
99944
- var KeyManagerError = class extends DidMethodError2 {
99945
- constructor(message2, type = "KeyManagerError", data) {
99946
- super(message2, { type, name: type, data });
99947
- }
99948
- };
99949
99961
  var DidDocumentError = class extends DidMethodError2 {
99950
99962
  constructor(message2, type = "DidDocumentError", data) {
99951
99963
  super(message2, { type, name: type, data });
@@ -99981,11 +99993,6 @@ var MultikeyError2 = class extends DidMethodError2 {
99981
99993
  super(message2, { type, name: type, data });
99982
99994
  }
99983
99995
  };
99984
- var SingletonBeaconError = class extends DidMethodError2 {
99985
- constructor(message2, type = "SingletonBeaconError", data) {
99986
- super(message2, { type, name: type, data });
99987
- }
99988
- };
99989
99996
  var CanonicalizationError2 = class extends DidMethodError2 {
99990
99997
  constructor(message2, type = "CanonicalizationError", data) {
99991
99998
  super(message2, { type, name: type, data });
@@ -101784,6 +101791,26 @@ var StringUtils2 = class {
101784
101791
  return value3.replace(regex3, replacement);
101785
101792
  }
101786
101793
  };
101794
+ var BeaconError = class extends MethodError2 {
101795
+ constructor(message2, type = "BeaconError", data) {
101796
+ super(message2, type, data);
101797
+ }
101798
+ };
101799
+ var SingletonBeaconError = class extends MethodError2 {
101800
+ constructor(message2, type = "SingletonBeaconError", data) {
101801
+ super(message2, type, data);
101802
+ }
101803
+ };
101804
+ var CASBeaconError = class extends MethodError2 {
101805
+ constructor(message2, type = "CASBeaconError", data) {
101806
+ super(message2, type, data);
101807
+ }
101808
+ };
101809
+ var SMTBeaconError = class extends MethodError2 {
101810
+ constructor(message2, type = "SMTBeaconError", data) {
101811
+ super(message2, type, data);
101812
+ }
101813
+ };
101787
101814
  init_shim2();
101788
101815
  init_shim2();
101789
101816
  init_shim2();
@@ -101827,16 +101854,16 @@ var Secp256k1SecretKey2 = class _Secp256k1SecretKey {
101827
101854
  #multibase;
101828
101855
  /**
101829
101856
  * Instantiates an instance of Secp256k1SecretKey.
101830
- * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
101857
+ * @param {Bytes | bigint} entropy bytes (Uint8Array) or secret (bigint)
101831
101858
  * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
101832
101859
  */
101833
101860
  constructor(entropy) {
101834
- const isBytes13 = entropy instanceof Uint8Array;
101861
+ const isBytes12 = entropy instanceof Uint8Array;
101835
101862
  const isSecret = typeof entropy === "bigint";
101836
- if (!isBytes13 && !isSecret) {
101863
+ if (!isBytes12 && !isSecret) {
101837
101864
  throw new SecretKeyError2("Invalid entropy: must be a valid byte array (32) or bigint", "CONSTRUCTOR_ERROR");
101838
101865
  }
101839
- if (isBytes13 && entropy.length === 32) {
101866
+ if (isBytes12 && entropy.length === 32) {
101840
101867
  this.#bytes = entropy;
101841
101868
  this.#seed = _Secp256k1SecretKey.toSecret(entropy);
101842
101869
  }
@@ -102021,15 +102048,23 @@ var Secp256k1SecretKey2 = class _Secp256k1SecretKey {
102021
102048
  }
102022
102049
  return new Uint8Array(bytes6);
102023
102050
  }
102051
+ /**
102052
+ * Creates a new Secp256k1SecretKey object from random bytes.
102053
+ * @param {KeyBytes} bytes The secret key bytes
102054
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
102055
+ */
102056
+ static fromBytes(bytes6) {
102057
+ return new _Secp256k1SecretKey(bytes6);
102058
+ }
102024
102059
  /**
102025
102060
  * Creates a new Secp256k1SecretKey object from a bigint secret.
102026
- * @param {bigint} entropy The secret bigint
102061
+ * @param {bigint} bint The secret bigint
102027
102062
  * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
102028
102063
  */
102029
- static fromEntropy(entropy) {
102030
- const hexsecret = entropy.toString(16).padStart(64, "0");
102031
- const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
102032
- return new _Secp256k1SecretKey(privateKeyBytes);
102064
+ static fromBigInt(bint) {
102065
+ const hexsecret = bint.toString(16).padStart(64, "0");
102066
+ const bytes6 = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
102067
+ return new _Secp256k1SecretKey(bytes6);
102033
102068
  }
102034
102069
  /**
102035
102070
  * Generates random secret key bytes.
@@ -102342,12 +102377,18 @@ var CompressedSecp256k1PublicKey2 = class _CompressedSecp256k1PublicKey {
102342
102377
  }
102343
102378
  };
102344
102379
  var SchnorrKeyPair2 = class _SchnorrKeyPair {
102345
- /** @type {Secp256k1SecretKey} The secret key object */
102380
+ /**
102381
+ * The secret key objec
102382
+ */
102346
102383
  #secretKey;
102347
102384
  #publicKey;
102348
- /** @type {string} The public key in multibase format */
102385
+ /**
102386
+ * The public key in multibase forma
102387
+ */
102349
102388
  #publicKeyMultibase;
102350
- /** @type {string} The secret key in multibase format */
102389
+ /**
102390
+ * The secret key in multibase forma
102391
+ */
102351
102392
  #secretKeyMultibase;
102352
102393
  /**
102353
102394
  * Creates an instance of Keys. Must provide a at least a secret key.
@@ -102485,11 +102526,11 @@ var SchnorrKeyPair2 = class _SchnorrKeyPair {
102485
102526
  }
102486
102527
  /**
102487
102528
  * Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
102488
- * @param {bigint} entropy The entropy in bigint form
102529
+ * @param {bigint} bint The entropy in bigint form
102489
102530
  * @returns {SchnorrKeyPair} A new SchnorrKeyPair object
102490
102531
  */
102491
- static fromEntropy(entropy) {
102492
- const secretKey = Secp256k1SecretKey2.fromEntropy(entropy);
102532
+ static fromBigInt(bint) {
102533
+ const secretKey = Secp256k1SecretKey2.fromBigInt(bint);
102493
102534
  const publicKey2 = secretKey.computePublicKey();
102494
102535
  return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
102495
102536
  }
@@ -108901,75 +108942,44 @@ async function pbkdf2Async(hash4, password, salt, opts) {
108901
108942
  return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
108902
108943
  }
108903
108944
  init_shim2();
108904
- init_shim2();
108905
- var AggregateBeacon = class {
108945
+ var Beacon = class {
108906
108946
  /**
108907
- * The Beacon service object parsed from the DID Document.
108947
+ * The Beacon service configuration parsed from the DID Document.
108908
108948
  */
108909
108949
  service;
108910
- /**
108911
- * The array of Beacon Signals associated with this Beacon service.
108912
- */
108913
- signals;
108914
- /**
108915
- * The sidecar data associated with this Beacon service.
108916
- * TODO: Make this more specific to Beacon type.
108917
- */
108918
- sidecar;
108919
- /**
108920
- * The Bitcoin network connection associated with this Beacon service.
108921
- */
108922
- bitcoin;
108923
- constructor(service, signals, sidecar, bitcoin32) {
108950
+ constructor(service) {
108924
108951
  this.service = service;
108925
- this.signals = signals;
108926
- this.sidecar = sidecar;
108927
- this.bitcoin = bitcoin32;
108928
108952
  }
108929
108953
  };
108930
- var CASBeacon = class _CASBeacon extends AggregateBeacon {
108954
+ init_shim2();
108955
+ var CASBeacon = class extends Beacon {
108931
108956
  /**
108932
108957
  * Creates an instance of CASBeacon.
108933
108958
  * @param {BeaconService} service The service of the Beacon.
108934
- * @param {?BeaconSidecarData} [sidecar] The sidecar data of the Beacon.
108935
- */
108936
- constructor(service, signals, sidecar, bitcoin32) {
108937
- super({ ...service, type: "CASBeacon" }, signals, sidecar, bitcoin32);
108938
- }
108939
- /**
108940
- * Establish a CASBeacon instance based on the provided service and sidecar data.
108941
- * @param {BeaconService} service - The beacon service configuration.
108942
- * @param {SidecarData} sidecar - The sidecar data.
108943
- * @returns {CASBeacon} The established CASBeacon instance.
108944
- */
108945
- static establish(service, signals, sidecar) {
108946
- return new _CASBeacon(service, signals, sidecar);
108947
- }
108948
- /**
108949
- * TODO: Figure out if this is necessary or not.
108950
- * @param {HexString} updateHash The hash of the update to generate the signal for.
108951
- * @returns {BeaconSignal} The generated signal.
108952
- * @throws {MethodError} if the signal is invalid.
108953
108959
  */
108954
- generateSignal(updateHash) {
108955
- throw new Error("Method not implemented." + updateHash);
108960
+ constructor(service) {
108961
+ super({ ...service, type: "CASBeacon" });
108956
108962
  }
108957
108963
  /**
108958
108964
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
108959
- * @returns {Promise<BTCR2SignedUpdate | undefined>} The processed signed update or undefined.
108960
- * @throws {MethodError} if the signal processing fails.
108965
+ * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
108966
+ * @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
108967
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
108968
+ * @throws {CASBeaconError} if processing fails.
108961
108969
  */
108962
- processSignals() {
108963
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`);
108970
+ processSignals(signals, sidecar) {
108971
+ throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
108964
108972
  }
108965
108973
  /**
108966
- * TODO: Finish implementation
108967
- * @param {HexString} updateHash The hash of the update to broadcast.
108968
- * @returns {Promise<{ spentTx: string; signedUpdate: BTCR2SignedUpdate }>} The result of the broadcast.
108969
- * @throws {MethodError} if the broadcast fails.
108974
+ * Broadcast CAS Beacon signal to the Bitcoin network.
108975
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
108976
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
108977
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
108978
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
108979
+ * @throws {CASBeaconError} if broadcasting fails.
108970
108980
  */
108971
- async broadcastSignal(updateHash) {
108972
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
108981
+ async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
108982
+ throw new CASBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin32 });
108973
108983
  }
108974
108984
  };
108975
108985
  init_shim2();
@@ -108979,609 +108989,6 @@ init_shim2();
108979
108989
  init_shim2();
108980
108990
  init_shim2();
108981
108991
  init_shim2();
108982
- init_shim2();
108983
- function isBytes6(a3) {
108984
- return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
108985
- }
108986
- function abytes3(value3, length7, title = "") {
108987
- const bytes6 = isBytes6(value3);
108988
- const len = value3?.length;
108989
- const needsLen = length7 !== void 0;
108990
- if (!bytes6 || needsLen && len !== length7) {
108991
- const prefix = title && `"${title}" `;
108992
- const ofLen = needsLen ? ` of length ${length7}` : "";
108993
- const got = bytes6 ? `length=${len}` : `type=${typeof value3}`;
108994
- throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
108995
- }
108996
- return value3;
108997
- }
108998
- function aexists22(instance3, checkFinished = true) {
108999
- if (instance3.destroyed)
109000
- throw new Error("Hash instance has been destroyed");
109001
- if (checkFinished && instance3.finished)
109002
- throw new Error("Hash#digest() has already been called");
109003
- }
109004
- function aoutput22(out, instance3) {
109005
- abytes3(out, void 0, "digestInto() output");
109006
- const min = instance3.outputLen;
109007
- if (out.length < min) {
109008
- throw new Error('"digestInto() output" expected to be of length >=' + min);
109009
- }
109010
- }
109011
- function clean22(...arrays) {
109012
- for (let i42 = 0; i42 < arrays.length; i42++) {
109013
- arrays[i42].fill(0);
109014
- }
109015
- }
109016
- function createView6(arr) {
109017
- return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
109018
- }
109019
- function rotr4(word2, shift) {
109020
- return word2 << 32 - shift | word2 >>> shift;
109021
- }
109022
- function createHasher22(hashCons, info = {}) {
109023
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
109024
- const tmp = hashCons(void 0);
109025
- hashC.outputLen = tmp.outputLen;
109026
- hashC.blockLen = tmp.blockLen;
109027
- hashC.create = (opts) => hashCons(opts);
109028
- Object.assign(hashC, info);
109029
- return Object.freeze(hashC);
109030
- }
109031
- var oidNist = (suffix) => ({
109032
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
109033
- });
109034
- function Chi4(a3, b22, c2) {
109035
- return a3 & b22 ^ ~a3 & c2;
109036
- }
109037
- function Maj4(a3, b22, c2) {
109038
- return a3 & b22 ^ a3 & c2 ^ b22 & c2;
109039
- }
109040
- var HashMD22 = class {
109041
- blockLen;
109042
- outputLen;
109043
- padOffset;
109044
- isLE;
109045
- // For partial updates less than block size
109046
- buffer;
109047
- view;
109048
- finished = false;
109049
- length = 0;
109050
- pos = 0;
109051
- destroyed = false;
109052
- constructor(blockLen, outputLen, padOffset, isLE7) {
109053
- this.blockLen = blockLen;
109054
- this.outputLen = outputLen;
109055
- this.padOffset = padOffset;
109056
- this.isLE = isLE7;
109057
- this.buffer = new Uint8Array(blockLen);
109058
- this.view = createView6(this.buffer);
109059
- }
109060
- update(data) {
109061
- aexists22(this);
109062
- abytes3(data);
109063
- const { view, buffer: buffer2, blockLen } = this;
109064
- const len = data.length;
109065
- for (let pos = 0; pos < len; ) {
109066
- const take2 = Math.min(blockLen - this.pos, len - pos);
109067
- if (take2 === blockLen) {
109068
- const dataView2 = createView6(data);
109069
- for (; blockLen <= len - pos; pos += blockLen)
109070
- this.process(dataView2, pos);
109071
- continue;
109072
- }
109073
- buffer2.set(data.subarray(pos, pos + take2), this.pos);
109074
- this.pos += take2;
109075
- pos += take2;
109076
- if (this.pos === blockLen) {
109077
- this.process(view, 0);
109078
- this.pos = 0;
109079
- }
109080
- }
109081
- this.length += data.length;
109082
- this.roundClean();
109083
- return this;
109084
- }
109085
- digestInto(out) {
109086
- aexists22(this);
109087
- aoutput22(out, this);
109088
- this.finished = true;
109089
- const { buffer: buffer2, view, blockLen, isLE: isLE7 } = this;
109090
- let { pos } = this;
109091
- buffer2[pos++] = 128;
109092
- clean22(this.buffer.subarray(pos));
109093
- if (this.padOffset > blockLen - pos) {
109094
- this.process(view, 0);
109095
- pos = 0;
109096
- }
109097
- for (let i42 = pos; i42 < blockLen; i42++)
109098
- buffer2[i42] = 0;
109099
- view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE7);
109100
- this.process(view, 0);
109101
- const oview = createView6(out);
109102
- const len = this.outputLen;
109103
- if (len % 4)
109104
- throw new Error("_sha2: outputLen must be aligned to 32bit");
109105
- const outLen = len / 4;
109106
- const state = this.get();
109107
- if (outLen > state.length)
109108
- throw new Error("_sha2: outputLen bigger than state");
109109
- for (let i42 = 0; i42 < outLen; i42++)
109110
- oview.setUint32(4 * i42, state[i42], isLE7);
109111
- }
109112
- digest() {
109113
- const { buffer: buffer2, outputLen } = this;
109114
- this.digestInto(buffer2);
109115
- const res = buffer2.slice(0, outputLen);
109116
- this.destroy();
109117
- return res;
109118
- }
109119
- _cloneInto(to) {
109120
- to ||= new this.constructor();
109121
- to.set(...this.get());
109122
- const { blockLen, buffer: buffer2, length: length7, finished, destroyed, pos } = this;
109123
- to.destroyed = destroyed;
109124
- to.finished = finished;
109125
- to.length = length7;
109126
- to.pos = pos;
109127
- if (length7 % blockLen)
109128
- to.buffer.set(buffer2);
109129
- return to;
109130
- }
109131
- clone() {
109132
- return this._cloneInto();
109133
- }
109134
- };
109135
- var SHA256_IV22 = /* @__PURE__ */ Uint32Array.from([
109136
- 1779033703,
109137
- 3144134277,
109138
- 1013904242,
109139
- 2773480762,
109140
- 1359893119,
109141
- 2600822924,
109142
- 528734635,
109143
- 1541459225
109144
- ]);
109145
- var SHA256_K4 = /* @__PURE__ */ Uint32Array.from([
109146
- 1116352408,
109147
- 1899447441,
109148
- 3049323471,
109149
- 3921009573,
109150
- 961987163,
109151
- 1508970993,
109152
- 2453635748,
109153
- 2870763221,
109154
- 3624381080,
109155
- 310598401,
109156
- 607225278,
109157
- 1426881987,
109158
- 1925078388,
109159
- 2162078206,
109160
- 2614888103,
109161
- 3248222580,
109162
- 3835390401,
109163
- 4022224774,
109164
- 264347078,
109165
- 604807628,
109166
- 770255983,
109167
- 1249150122,
109168
- 1555081692,
109169
- 1996064986,
109170
- 2554220882,
109171
- 2821834349,
109172
- 2952996808,
109173
- 3210313671,
109174
- 3336571891,
109175
- 3584528711,
109176
- 113926993,
109177
- 338241895,
109178
- 666307205,
109179
- 773529912,
109180
- 1294757372,
109181
- 1396182291,
109182
- 1695183700,
109183
- 1986661051,
109184
- 2177026350,
109185
- 2456956037,
109186
- 2730485921,
109187
- 2820302411,
109188
- 3259730800,
109189
- 3345764771,
109190
- 3516065817,
109191
- 3600352804,
109192
- 4094571909,
109193
- 275423344,
109194
- 430227734,
109195
- 506948616,
109196
- 659060556,
109197
- 883997877,
109198
- 958139571,
109199
- 1322822218,
109200
- 1537002063,
109201
- 1747873779,
109202
- 1955562222,
109203
- 2024104815,
109204
- 2227730452,
109205
- 2361852424,
109206
- 2428436474,
109207
- 2756734187,
109208
- 3204031479,
109209
- 3329325298
109210
- ]);
109211
- var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
109212
- var SHA2_32B = class extends HashMD22 {
109213
- constructor(outputLen) {
109214
- super(64, outputLen, 8, false);
109215
- }
109216
- get() {
109217
- const { A, B, C: C2, D, E, F, G: G2, H } = this;
109218
- return [A, B, C2, D, E, F, G2, H];
109219
- }
109220
- // prettier-ignore
109221
- set(A, B, C2, D, E, F, G2, H) {
109222
- this.A = A | 0;
109223
- this.B = B | 0;
109224
- this.C = C2 | 0;
109225
- this.D = D | 0;
109226
- this.E = E | 0;
109227
- this.F = F | 0;
109228
- this.G = G2 | 0;
109229
- this.H = H | 0;
109230
- }
109231
- process(view, offset) {
109232
- for (let i42 = 0; i42 < 16; i42++, offset += 4)
109233
- SHA256_W4[i42] = view.getUint32(offset, false);
109234
- for (let i42 = 16; i42 < 64; i42++) {
109235
- const W15 = SHA256_W4[i42 - 15];
109236
- const W2 = SHA256_W4[i42 - 2];
109237
- const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
109238
- const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
109239
- SHA256_W4[i42] = s1 + SHA256_W4[i42 - 7] + s0 + SHA256_W4[i42 - 16] | 0;
109240
- }
109241
- let { A, B, C: C2, D, E, F, G: G2, H } = this;
109242
- for (let i42 = 0; i42 < 64; i42++) {
109243
- const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
109244
- const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i42] + SHA256_W4[i42] | 0;
109245
- const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
109246
- const T2 = sigma0 + Maj4(A, B, C2) | 0;
109247
- H = G2;
109248
- G2 = F;
109249
- F = E;
109250
- E = D + T1 | 0;
109251
- D = C2;
109252
- C2 = B;
109253
- B = A;
109254
- A = T1 + T2 | 0;
109255
- }
109256
- A = A + this.A | 0;
109257
- B = B + this.B | 0;
109258
- C2 = C2 + this.C | 0;
109259
- D = D + this.D | 0;
109260
- E = E + this.E | 0;
109261
- F = F + this.F | 0;
109262
- G2 = G2 + this.G | 0;
109263
- H = H + this.H | 0;
109264
- this.set(A, B, C2, D, E, F, G2, H);
109265
- }
109266
- roundClean() {
109267
- clean22(SHA256_W4);
109268
- }
109269
- destroy() {
109270
- this.set(0, 0, 0, 0, 0, 0, 0, 0);
109271
- clean22(this.buffer);
109272
- }
109273
- };
109274
- var _SHA256 = class extends SHA2_32B {
109275
- // We cannot use array here since array allows indexing by variable
109276
- // which means optimizer/compiler cannot use registers.
109277
- A = SHA256_IV22[0] | 0;
109278
- B = SHA256_IV22[1] | 0;
109279
- C = SHA256_IV22[2] | 0;
109280
- D = SHA256_IV22[3] | 0;
109281
- E = SHA256_IV22[4] | 0;
109282
- F = SHA256_IV22[5] | 0;
109283
- G = SHA256_IV22[6] | 0;
109284
- H = SHA256_IV22[7] | 0;
109285
- constructor() {
109286
- super(32);
109287
- }
109288
- };
109289
- var sha2565 = /* @__PURE__ */ createHasher22(
109290
- () => new _SHA256(),
109291
- /* @__PURE__ */ oidNist(1)
109292
- );
109293
- init_shim2();
109294
- var MemoryStore = class {
109295
- /**
109296
- * A private field that contains the Map used as the key-value store.
109297
- */
109298
- store = /* @__PURE__ */ new Map();
109299
- /**
109300
- * Clears all entries in the key-value store.
109301
- *
109302
- * @returns {void} returns once the operation is complete.
109303
- */
109304
- clear() {
109305
- this.store.clear();
109306
- }
109307
- /**
109308
- * This operation is no-op for `MemoryStore`.
109309
- */
109310
- close() {
109311
- }
109312
- /**
109313
- * Deletes an entry from the key-value store by its key.
109314
- *
109315
- * @param {K} id - The key of the entry to delete.
109316
- * @returns {boolean} a boolean indicating whether the entry was successfully deleted.
109317
- */
109318
- delete(id) {
109319
- return this.store.delete(id);
109320
- }
109321
- /**
109322
- * Retrieves the value of an entry by its key.
109323
- *
109324
- * @param {K} id - The key of the entry to retrieve.
109325
- * @returns {V | undefined} the value of the entry, or `undefined` if the entry does not exist.
109326
- */
109327
- get(id) {
109328
- return this.store.get(id);
109329
- }
109330
- /**
109331
- * Checks for the presence of an entry by key.
109332
- *
109333
- * @param {K} id - The key to check for the existence of.
109334
- * @returns {boolean} a boolean indicating whether an element with the specified key exists or not.
109335
- */
109336
- has(id) {
109337
- return this.store.has(id);
109338
- }
109339
- /**
109340
- * Retrieves all values in the key-value store.
109341
-
109342
- * @returns {Array<V>} an array of all values in the store.
109343
- */
109344
- list() {
109345
- return Array.from(this.store.values());
109346
- }
109347
- /**
109348
- * Retrieves all entries in the key-value store.
109349
- *
109350
- * @returns {Array<[K, V]>} an array of key-value pairs in the store.
109351
- */
109352
- entries() {
109353
- return Array.from(this.store.entries());
109354
- }
109355
- /**
109356
- * Sets the value of an entry in the key-value store.
109357
- *
109358
- * @param {K} id - The key of the entry to set.
109359
- * @param {V} key - The new value for the entry.
109360
- * @returns {void} once operation is complete.
109361
- */
109362
- set(id, key) {
109363
- this.store.set(id, key);
109364
- }
109365
- };
109366
- var Kms = class _Kms {
109367
- /**
109368
- * Singleton instance of the Kms.
109369
- * @private
109370
- * @type {KeyManager}
109371
- */
109372
- static #instance;
109373
- /**
109374
- * The `store` is a private variable in `KeyManager`. It is a `KeyValueStore` instance used for
109375
- * storing and managing cryptographic keys. It allows the `KeyManager` class to save,
109376
- * retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
109377
- * This variable can be configured to use different storage backends, like in-memory storage or
109378
- * persistent storage, providing flexibility in key management according to the application's
109379
- * requirements.
109380
- * @private
109381
- * @type {KeyValueStore<KeyIdentifier, KeyBytes>} The key store for managing cryptographic keys.
109382
- */
109383
- #store;
109384
- /**
109385
- * The `#activeKeyId` property is a string that points to the currently active key.
109386
- * It is used to identify the key that will be used for signing and verifying operations.
109387
- * This property is optional and can be set to a specific key ID when initializing the
109388
- * `KeyManager` instance. If not set, the key manager will use the default key id.
109389
- * @private
109390
- * @type {KeyIdentifier}
109391
- */
109392
- #activeKeyId;
109393
- /**
109394
- * Creates an instance of KeyManager.
109395
- * @param {KeyValueStore<KeyIdentifier, KeyBytes>} store An optional property to specify a custom
109396
- * `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
109397
- * instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
109398
- * managed during cryptographic operations.
109399
- */
109400
- constructor(store52) {
109401
- this.#store = store52 ?? new MemoryStore();
109402
- }
109403
- /**
109404
- * Gets the ID of the active key.
109405
- * @returns {KeyIdentifier | undefined} The ID of the active key.
109406
- */
109407
- get activeKeyId() {
109408
- return this.#activeKeyId;
109409
- }
109410
- /**
109411
- * Gets the key pair associated with the given ID or the active key if no ID is provided.
109412
- * @param {KeyIdentifier} [id] The ID of the key to get.
109413
- * @returns {KeyBytes} A promise resolving to the key pair.
109414
- * @throws {KeyManagerError} If the key is not found or no active key is set.
109415
- */
109416
- #getKeyOrThrow(id) {
109417
- const keyId2 = id ?? this.#activeKeyId;
109418
- if (!keyId2) {
109419
- throw new KeyManagerError("No active key set", "ACTIVE_KEY_URI_NOT_SET");
109420
- }
109421
- const _secretKey = this.#store.get(keyId2);
109422
- if (!_secretKey) {
109423
- throw new KeyManagerError(`Key not found: ${keyId2}`, "KEY_NOT_FOUND");
109424
- }
109425
- const kp = new SchnorrKeyPair2({ secretKey: _secretKey });
109426
- return kp;
109427
- }
109428
- /**
109429
- * Checks if a key with the given ID exists in the key store.
109430
- * @param {KeyIdentifier} id The ID of the key to check.
109431
- * @returns {boolean} A promise resolving to a boolean indicating if the key exists.
109432
- */
109433
- #exists(id) {
109434
- const key = this.#store.get(id);
109435
- return !!key;
109436
- }
109437
- /**
109438
- * Removes a key from the key store.
109439
- * @param {KeyIdentifier} id The key identifier of the key to remove.
109440
- * @param {{ force?: boolean }} options The options for removing the key.
109441
- * @param {boolean} [options.force] Whether to force the removal of the key.
109442
- * @returns {void} A promise that resolves when the key is removed.
109443
- * @throws {KeyManagerError} If attempting to remove the active key without force.
109444
- */
109445
- removeKey(id, options2 = {}) {
109446
- if (this.#activeKeyId === id && !options2.force) {
109447
- throw new KeyManagerError('Cannot remove active key (use "force": true or switch active key)', "ACTIVE_KEY_DELETE");
109448
- }
109449
- if (!this.#exists(id)) {
109450
- throw new KeyManagerError(`Key not found: ${id}`, "KEY_NOT_FOUND");
109451
- }
109452
- this.#store.delete(id);
109453
- if (this.#activeKeyId === id) {
109454
- this.#activeKeyId = void 0;
109455
- }
109456
- }
109457
- /**
109458
- * Lists all key identifiers in the key store.
109459
- * @returns {Promise<KeyIdentifier[]>} A promise that resolves to an array of key identifiers.
109460
- */
109461
- listKeys() {
109462
- return this.#store.entries().flatMap(([k, _]) => [k]);
109463
- }
109464
- /**
109465
- * Sets the active key to the key associated with the given ID.
109466
- * @param {KeyIdentifier} id The ID of the key to set as active.
109467
- * @returns {Promise<void>} A promise that resolves when the active key is set.
109468
- * @throws {KeyManagerError} If the key is not found.
109469
- */
109470
- setActiveKey(id) {
109471
- this.#getKeyOrThrow(id);
109472
- this.#activeKeyId = id;
109473
- }
109474
- /**
109475
- * Gets the public key associated with the given ID or the active key if no ID is provided.
109476
- * @param {KeyIdentifier} [id] The ID of the key to get the public key for.
109477
- * @returns {Promise<KeyBytes>} A promise resolving to the public key bytes.
109478
- */
109479
- getPublicKey(id) {
109480
- const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
109481
- return publicKey2.compressed;
109482
- }
109483
- /**
109484
- * Signs the given data using the key associated with the key ID.
109485
- * @param {Bytes} data The data to sign.
109486
- * @param {KeyIdentifier} [id] The ID of the key to sign the data with.
109487
- * @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
109488
- */
109489
- sign(data, id) {
109490
- const { secretKey } = this.#getKeyOrThrow(id);
109491
- if (!secretKey) {
109492
- throw new KeyManagerError(`Key ID ${id} is not a signer`, "KEY_NOT_SIGNER");
109493
- }
109494
- return secretKey.sign(data);
109495
- }
109496
- /**
109497
- * Verifies a signature using the key associated with the key ID.
109498
- * @param {KeyIdentifier} id The ID of the key to verify the signature with.
109499
- * @param {SignatureBytes} signature The signature to verify.
109500
- * @param {Hex} data The data to verify the signature with.
109501
- * @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
109502
- */
109503
- verify(signature22, data, id) {
109504
- const { publicKey: publicKey2 } = this.#getKeyOrThrow(id);
109505
- return publicKey2.verify(signature22, data);
109506
- }
109507
- /**
109508
- * Imports a key pair into the key store.
109509
- * @param {SchnorrKeyPair} keyPair The key pair to import.
109510
- * @param {{ id?: KeyIdentifier; setActive?: boolean }} options The options for importing the key pair.
109511
- * @param {KeyIdentifier} [options.id] The ID of the key to import (optional).
109512
- * @param {boolean} [options.setActive] Whether to set the key as active (optional, default: true).
109513
- * @returns {Promise<KeyIdentifier>} A promise resolving to the ID of the imported key.
109514
- */
109515
- importKey(keyPair, options2 = {}) {
109516
- if (!keyPair.publicKey) {
109517
- keyPair.publicKey = keyPair.secretKey.computePublicKey();
109518
- }
109519
- const id = options2.id ?? keyPair.publicKey.hex;
109520
- if (this.#exists(id)) {
109521
- throw new KeyManagerError(`Key already exists: ${id}`, "KEY_FOUND");
109522
- }
109523
- this.#store.set(id, keyPair.secretKey.bytes);
109524
- const setActive = options2.setActive ?? true;
109525
- if (setActive) {
109526
- this.#activeKeyId = id;
109527
- }
109528
- return id;
109529
- }
109530
- /**
109531
- * Computes the hash of the given data.
109532
- * @param {Uint8Array} data The data to hash.
109533
- * @returns {HashBytes} The hash of the data.
109534
- */
109535
- digest(data) {
109536
- return sha2565(data);
109537
- }
109538
- /**
109539
- * Generates a new key pair and stores it in the key store.
109540
- * @returns {KeyIdentifier} The key identifier of the generated key.
109541
- */
109542
- generateKey() {
109543
- const kp = SchnorrKeyPair2.generate();
109544
- const id = kp.publicKey.hex;
109545
- this.#store.set(id, kp.secretKey.bytes);
109546
- this.#activeKeyId = id;
109547
- return id;
109548
- }
109549
- /**
109550
- * Initializes a singleton KeyManager instance.
109551
- * @param {SchnorrKeyPair} keyPair The secret key to import.
109552
- * @param {string} id The ID to set as the active key.
109553
- * @returns {void}
109554
- */
109555
- static initialize(keyPair, id) {
109556
- if (_Kms.#instance) {
109557
- console.warn("WARNING: Kms global instance is already initialized.");
109558
- return _Kms.#instance;
109559
- }
109560
- if (!keyPair) {
109561
- console.warn("WARNING: secretKey not provided, generating new SchnorrKeyPair ...");
109562
- }
109563
- keyPair ??= SchnorrKeyPair2.generate();
109564
- _Kms.#instance = new _Kms();
109565
- _Kms.#instance.importKey(keyPair, { setActive: true, id });
109566
- _Kms.#instance.#activeKeyId = id;
109567
- console.info(`Kms initialized with Active Key ID: ${_Kms.#instance.#activeKeyId}`);
109568
- return _Kms.#instance;
109569
- }
109570
- /**
109571
- * Retrieves a keypair from the key store using the provided key ID.
109572
- * @public
109573
- * @param {KeyIdentifier} id The ID of the keypair to retrieve.
109574
- * @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
109575
- */
109576
- static getKey(id) {
109577
- if (!_Kms.#instance) {
109578
- throw new KeyManagerError("Kms instance not initialized", "KMS_NOT_INITIALIZED");
109579
- }
109580
- id ??= _Kms.#instance.activeKeyId;
109581
- return _Kms.#instance.#getKeyOrThrow(id);
109582
- }
109583
- };
109584
- init_shim2();
109585
108992
  var Signer = class {
109586
108993
  /**
109587
108994
  * The key pair used for signing.
@@ -109615,7 +109022,7 @@ var Signer = class {
109615
109022
  * @param {Bytes} hash The hash to sign.
109616
109023
  * @returns {SignatureBytes} The signature of the hash.
109617
109024
  */
109618
- signEcdsa(hash4) {
109025
+ sign(hash4) {
109619
109026
  return this.keyPair.secretKey.sign(hash4, { scheme: "ecdsa" });
109620
109027
  }
109621
109028
  /**
@@ -109623,7 +109030,7 @@ var Signer = class {
109623
109030
  * @param {Bytes} hash The hash to sign.
109624
109031
  * @returns {SignatureBytes} The Schnorr signature of the hash.
109625
109032
  */
109626
- sign(hash4) {
109033
+ signSchnorr(hash4) {
109627
109034
  return this.keyPair.secretKey.sign(hash4);
109628
109035
  }
109629
109036
  };
@@ -112293,11 +111700,11 @@ init_shim2();
112293
111700
  init_shim2();
112294
111701
  init_shim2();
112295
111702
  init_shim2();
112296
- function isBytes7(a3) {
111703
+ function isBytes6(a3) {
112297
111704
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
112298
111705
  }
112299
111706
  function bytes4(b22, ...lengths) {
112300
- if (!isBytes7(b22))
111707
+ if (!isBytes6(b22))
112301
111708
  throw new Error("Uint8Array expected");
112302
111709
  if (lengths.length > 0 && !lengths.includes(b22.length))
112303
111710
  throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b22.length}`);
@@ -112318,8 +111725,8 @@ function output4(out, instance3) {
112318
111725
  init_shim2();
112319
111726
  init_shim2();
112320
111727
  var crypto5 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
112321
- var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
112322
- var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
111728
+ var createView6 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
111729
+ var rotr4 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
112323
111730
  var isLE4 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
112324
111731
  function utf8ToBytes6(str) {
112325
111732
  if (typeof str !== "string")
@@ -112365,9 +111772,9 @@ function setBigUint645(view, byteOffset, value3, isLE7) {
112365
111772
  view.setUint32(byteOffset + h2, wh, isLE7);
112366
111773
  view.setUint32(byteOffset + l2, wl, isLE7);
112367
111774
  }
112368
- var Chi5 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
112369
- var Maj5 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
112370
- var HashMD3 = class extends Hash4 {
111775
+ var Chi4 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
111776
+ var Maj4 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
111777
+ var HashMD22 = class extends Hash4 {
112371
111778
  constructor(blockLen, outputLen, padOffset, isLE7) {
112372
111779
  super();
112373
111780
  this.blockLen = blockLen;
@@ -112379,7 +111786,7 @@ var HashMD3 = class extends Hash4 {
112379
111786
  this.pos = 0;
112380
111787
  this.destroyed = false;
112381
111788
  this.buffer = new Uint8Array(blockLen);
112382
- this.view = createView7(this.buffer);
111789
+ this.view = createView6(this.buffer);
112383
111790
  }
112384
111791
  update(data) {
112385
111792
  exists4(this);
@@ -112389,7 +111796,7 @@ var HashMD3 = class extends Hash4 {
112389
111796
  for (let pos = 0; pos < len; ) {
112390
111797
  const take2 = Math.min(blockLen - this.pos, len - pos);
112391
111798
  if (take2 === blockLen) {
112392
- const dataView2 = createView7(data);
111799
+ const dataView2 = createView6(data);
112393
111800
  for (; blockLen <= len - pos; pos += blockLen)
112394
111801
  this.process(dataView2, pos);
112395
111802
  continue;
@@ -112422,7 +111829,7 @@ var HashMD3 = class extends Hash4 {
112422
111829
  buffer2[i42] = 0;
112423
111830
  setBigUint645(view, blockLen - 8, BigInt(this.length * 8), isLE7);
112424
111831
  this.process(view, 0);
112425
- const oview = createView7(out);
111832
+ const oview = createView6(out);
112426
111833
  const len = this.outputLen;
112427
111834
  if (len % 4)
112428
111835
  throw new Error("_sha2: outputLen should be aligned to 32bit");
@@ -112453,7 +111860,7 @@ var HashMD3 = class extends Hash4 {
112453
111860
  return to;
112454
111861
  }
112455
111862
  };
112456
- var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
111863
+ var SHA256_K4 = /* @__PURE__ */ new Uint32Array([
112457
111864
  1116352408,
112458
111865
  1899447441,
112459
111866
  3049323471,
@@ -112519,7 +111926,7 @@ var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
112519
111926
  3204031479,
112520
111927
  3329325298
112521
111928
  ]);
112522
- var SHA256_IV3 = /* @__PURE__ */ new Uint32Array([
111929
+ var SHA256_IV22 = /* @__PURE__ */ new Uint32Array([
112523
111930
  1779033703,
112524
111931
  3144134277,
112525
111932
  1013904242,
@@ -112529,18 +111936,18 @@ var SHA256_IV3 = /* @__PURE__ */ new Uint32Array([
112529
111936
  528734635,
112530
111937
  1541459225
112531
111938
  ]);
112532
- var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
112533
- var SHA2564 = class extends HashMD3 {
111939
+ var SHA256_W4 = /* @__PURE__ */ new Uint32Array(64);
111940
+ var SHA2564 = class extends HashMD22 {
112534
111941
  constructor() {
112535
111942
  super(64, 32, 8, false);
112536
- this.A = SHA256_IV3[0] | 0;
112537
- this.B = SHA256_IV3[1] | 0;
112538
- this.C = SHA256_IV3[2] | 0;
112539
- this.D = SHA256_IV3[3] | 0;
112540
- this.E = SHA256_IV3[4] | 0;
112541
- this.F = SHA256_IV3[5] | 0;
112542
- this.G = SHA256_IV3[6] | 0;
112543
- this.H = SHA256_IV3[7] | 0;
111943
+ this.A = SHA256_IV22[0] | 0;
111944
+ this.B = SHA256_IV22[1] | 0;
111945
+ this.C = SHA256_IV22[2] | 0;
111946
+ this.D = SHA256_IV22[3] | 0;
111947
+ this.E = SHA256_IV22[4] | 0;
111948
+ this.F = SHA256_IV22[5] | 0;
111949
+ this.G = SHA256_IV22[6] | 0;
111950
+ this.H = SHA256_IV22[7] | 0;
112544
111951
  }
112545
111952
  get() {
112546
111953
  const { A, B, C: C2, D, E, F, G: G2, H } = this;
@@ -112559,20 +111966,20 @@ var SHA2564 = class extends HashMD3 {
112559
111966
  }
112560
111967
  process(view, offset) {
112561
111968
  for (let i42 = 0; i42 < 16; i42++, offset += 4)
112562
- SHA256_W5[i42] = view.getUint32(offset, false);
111969
+ SHA256_W4[i42] = view.getUint32(offset, false);
112563
111970
  for (let i42 = 16; i42 < 64; i42++) {
112564
- const W15 = SHA256_W5[i42 - 15];
112565
- const W2 = SHA256_W5[i42 - 2];
112566
- const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
112567
- const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
112568
- SHA256_W5[i42] = s1 + SHA256_W5[i42 - 7] + s0 + SHA256_W5[i42 - 16] | 0;
111971
+ const W15 = SHA256_W4[i42 - 15];
111972
+ const W2 = SHA256_W4[i42 - 2];
111973
+ const s0 = rotr4(W15, 7) ^ rotr4(W15, 18) ^ W15 >>> 3;
111974
+ const s1 = rotr4(W2, 17) ^ rotr4(W2, 19) ^ W2 >>> 10;
111975
+ SHA256_W4[i42] = s1 + SHA256_W4[i42 - 7] + s0 + SHA256_W4[i42 - 16] | 0;
112569
111976
  }
112570
111977
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
112571
111978
  for (let i42 = 0; i42 < 64; i42++) {
112572
- const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
112573
- const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i42] + SHA256_W5[i42] | 0;
112574
- const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
112575
- const T2 = sigma0 + Maj5(A, B, C2) | 0;
111979
+ const sigma1 = rotr4(E, 6) ^ rotr4(E, 11) ^ rotr4(E, 25);
111980
+ const T1 = H + sigma1 + Chi4(E, F, G2) + SHA256_K4[i42] + SHA256_W4[i42] | 0;
111981
+ const sigma0 = rotr4(A, 2) ^ rotr4(A, 13) ^ rotr4(A, 22);
111982
+ const T2 = sigma0 + Maj4(A, B, C2) | 0;
112576
111983
  H = G2;
112577
111984
  G2 = F;
112578
111985
  F = E;
@@ -112593,14 +112000,14 @@ var SHA2564 = class extends HashMD3 {
112593
112000
  this.set(A, B, C2, D, E, F, G2, H);
112594
112001
  }
112595
112002
  roundClean() {
112596
- SHA256_W5.fill(0);
112003
+ SHA256_W4.fill(0);
112597
112004
  }
112598
112005
  destroy() {
112599
112006
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
112600
112007
  this.buffer.fill(0);
112601
112008
  }
112602
112009
  };
112603
- var sha2566 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
112010
+ var sha2565 = /* @__PURE__ */ wrapConstructor3(() => new SHA2564());
112604
112011
  var __awaiter3 = function(thisArg, _arguments, P3, generator) {
112605
112012
  function adopt(value3) {
112606
112013
  return value3 instanceof P3 ? value3 : new P3(function(resolve) {
@@ -112650,7 +112057,7 @@ var Sha256 = class {
112650
112057
  */
112651
112058
  static digest(_a3) {
112652
112059
  return __awaiter3(this, arguments, void 0, function* ({ data }) {
112653
- const hash4 = sha2566(data);
112060
+ const hash4 = sha2565(data);
112654
112061
  return hash4;
112655
112062
  });
112656
112063
  }
@@ -112732,11 +112139,11 @@ function number6(n3) {
112732
112139
  if (!Number.isSafeInteger(n3) || n3 < 0)
112733
112140
  throw new Error(`Wrong positive integer: ${n3}`);
112734
112141
  }
112735
- function isBytes8(a3) {
112142
+ function isBytes7(a3) {
112736
112143
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
112737
112144
  }
112738
112145
  function bytes5(b22, ...lengths) {
112739
- if (!isBytes8(b22))
112146
+ if (!isBytes7(b22))
112740
112147
  throw new Error("Expected Uint8Array");
112741
112148
  if (lengths.length > 0 && !lengths.includes(b22.length))
112742
112149
  throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b22.length}`);
@@ -112763,11 +112170,11 @@ function output5(out, instance3) {
112763
112170
  init_shim2();
112764
112171
  init_shim2();
112765
112172
  var crypto6 = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : void 0;
112766
- function isBytes9(a3) {
112173
+ function isBytes8(a3) {
112767
112174
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
112768
112175
  }
112769
- var createView8 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
112770
- var rotr6 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
112176
+ var createView7 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
112177
+ var rotr5 = (word2, shift) => word2 << 32 - shift | word2 >>> shift;
112771
112178
  var isLE5 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
112772
112179
  if (!isLE5)
112773
112180
  throw new Error("Non little-endian hardware is not supported");
@@ -112779,7 +112186,7 @@ function utf8ToBytes7(str) {
112779
112186
  function toBytes6(data) {
112780
112187
  if (typeof data === "string")
112781
112188
  data = utf8ToBytes7(data);
112782
- if (!isBytes9(data))
112189
+ if (!isBytes8(data))
112783
112190
  throw new Error(`expected Uint8Array, got ${typeof data}`);
112784
112191
  return data;
112785
112192
  }
@@ -112787,7 +112194,7 @@ function concatBytes8(...arrays) {
112787
112194
  let sum = 0;
112788
112195
  for (let i42 = 0; i42 < arrays.length; i42++) {
112789
112196
  const a3 = arrays[i42];
112790
- if (!isBytes9(a3))
112197
+ if (!isBytes8(a3))
112791
112198
  throw new Error("Uint8Array expected");
112792
112199
  sum += a3.length;
112793
112200
  }
@@ -112844,7 +112251,7 @@ var SHA23 = class extends Hash5 {
112844
112251
  this.pos = 0;
112845
112252
  this.destroyed = false;
112846
112253
  this.buffer = new Uint8Array(blockLen);
112847
- this.view = createView8(this.buffer);
112254
+ this.view = createView7(this.buffer);
112848
112255
  }
112849
112256
  update(data) {
112850
112257
  exists5(this);
@@ -112854,7 +112261,7 @@ var SHA23 = class extends Hash5 {
112854
112261
  for (let pos = 0; pos < len; ) {
112855
112262
  const take2 = Math.min(blockLen - this.pos, len - pos);
112856
112263
  if (take2 === blockLen) {
112857
- const dataView2 = createView8(data);
112264
+ const dataView2 = createView7(data);
112858
112265
  for (; blockLen <= len - pos; pos += blockLen)
112859
112266
  this.process(dataView2, pos);
112860
112267
  continue;
@@ -112887,7 +112294,7 @@ var SHA23 = class extends Hash5 {
112887
112294
  buffer2[i42] = 0;
112888
112295
  setBigUint646(view, blockLen - 8, BigInt(this.length * 8), isLE7);
112889
112296
  this.process(view, 0);
112890
- const oview = createView8(out);
112297
+ const oview = createView7(out);
112891
112298
  const len = this.outputLen;
112892
112299
  if (len % 4)
112893
112300
  throw new Error("_sha2: outputLen should be aligned to 32bit");
@@ -112918,9 +112325,9 @@ var SHA23 = class extends Hash5 {
112918
112325
  return to;
112919
112326
  }
112920
112327
  };
112921
- var Chi6 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
112922
- var Maj6 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
112923
- var SHA256_K6 = /* @__PURE__ */ new Uint32Array([
112328
+ var Chi5 = (a3, b22, c2) => a3 & b22 ^ ~a3 & c2;
112329
+ var Maj5 = (a3, b22, c2) => a3 & b22 ^ a3 & c2 ^ b22 & c2;
112330
+ var SHA256_K5 = /* @__PURE__ */ new Uint32Array([
112924
112331
  1116352408,
112925
112332
  1899447441,
112926
112333
  3049323471,
@@ -112996,7 +112403,7 @@ var IV3 = /* @__PURE__ */ new Uint32Array([
112996
112403
  528734635,
112997
112404
  1541459225
112998
112405
  ]);
112999
- var SHA256_W6 = /* @__PURE__ */ new Uint32Array(64);
112406
+ var SHA256_W5 = /* @__PURE__ */ new Uint32Array(64);
113000
112407
  var SHA2565 = class extends SHA23 {
113001
112408
  constructor() {
113002
112409
  super(64, 32, 8, false);
@@ -113026,20 +112433,20 @@ var SHA2565 = class extends SHA23 {
113026
112433
  }
113027
112434
  process(view, offset) {
113028
112435
  for (let i42 = 0; i42 < 16; i42++, offset += 4)
113029
- SHA256_W6[i42] = view.getUint32(offset, false);
112436
+ SHA256_W5[i42] = view.getUint32(offset, false);
113030
112437
  for (let i42 = 16; i42 < 64; i42++) {
113031
- const W15 = SHA256_W6[i42 - 15];
113032
- const W2 = SHA256_W6[i42 - 2];
113033
- const s0 = rotr6(W15, 7) ^ rotr6(W15, 18) ^ W15 >>> 3;
113034
- const s1 = rotr6(W2, 17) ^ rotr6(W2, 19) ^ W2 >>> 10;
113035
- SHA256_W6[i42] = s1 + SHA256_W6[i42 - 7] + s0 + SHA256_W6[i42 - 16] | 0;
112438
+ const W15 = SHA256_W5[i42 - 15];
112439
+ const W2 = SHA256_W5[i42 - 2];
112440
+ const s0 = rotr5(W15, 7) ^ rotr5(W15, 18) ^ W15 >>> 3;
112441
+ const s1 = rotr5(W2, 17) ^ rotr5(W2, 19) ^ W2 >>> 10;
112442
+ SHA256_W5[i42] = s1 + SHA256_W5[i42 - 7] + s0 + SHA256_W5[i42 - 16] | 0;
113036
112443
  }
113037
112444
  let { A, B, C: C2, D, E, F, G: G2, H } = this;
113038
112445
  for (let i42 = 0; i42 < 64; i42++) {
113039
- const sigma1 = rotr6(E, 6) ^ rotr6(E, 11) ^ rotr6(E, 25);
113040
- const T1 = H + sigma1 + Chi6(E, F, G2) + SHA256_K6[i42] + SHA256_W6[i42] | 0;
113041
- const sigma0 = rotr6(A, 2) ^ rotr6(A, 13) ^ rotr6(A, 22);
113042
- const T2 = sigma0 + Maj6(A, B, C2) | 0;
112446
+ const sigma1 = rotr5(E, 6) ^ rotr5(E, 11) ^ rotr5(E, 25);
112447
+ const T1 = H + sigma1 + Chi5(E, F, G2) + SHA256_K5[i42] + SHA256_W5[i42] | 0;
112448
+ const sigma0 = rotr5(A, 2) ^ rotr5(A, 13) ^ rotr5(A, 22);
112449
+ const T2 = sigma0 + Maj5(A, B, C2) | 0;
113043
112450
  H = G2;
113044
112451
  G2 = F;
113045
112452
  F = E;
@@ -113060,14 +112467,14 @@ var SHA2565 = class extends SHA23 {
113060
112467
  this.set(A, B, C2, D, E, F, G2, H);
113061
112468
  }
113062
112469
  roundClean() {
113063
- SHA256_W6.fill(0);
112470
+ SHA256_W5.fill(0);
113064
112471
  }
113065
112472
  destroy() {
113066
112473
  this.set(0, 0, 0, 0, 0, 0, 0, 0);
113067
112474
  this.buffer.fill(0);
113068
112475
  }
113069
112476
  };
113070
- var sha2567 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
112477
+ var sha2566 = /* @__PURE__ */ wrapConstructor4(() => new SHA2565());
113071
112478
  init_shim2();
113072
112479
  var utils_exports4 = {};
113073
112480
  __export2(utils_exports4, {
@@ -113084,7 +112491,7 @@ __export2(utils_exports4, {
113084
112491
  equalBytes: () => equalBytes7,
113085
112492
  hexToBytes: () => hexToBytes4,
113086
112493
  hexToNumber: () => hexToNumber3,
113087
- isBytes: () => isBytes10,
112494
+ isBytes: () => isBytes9,
113088
112495
  numberToBytesBE: () => numberToBytesBE4,
113089
112496
  numberToBytesLE: () => numberToBytesLE3,
113090
112497
  numberToHexUnpadded: () => numberToHexUnpadded3,
@@ -113096,12 +112503,12 @@ init_shim2();
113096
112503
  var _0n11 = BigInt(0);
113097
112504
  var _1n11 = BigInt(1);
113098
112505
  var _2n8 = BigInt(2);
113099
- function isBytes10(a3) {
112506
+ function isBytes9(a3) {
113100
112507
  return a3 instanceof Uint8Array || a3 != null && typeof a3 === "object" && a3.constructor.name === "Uint8Array";
113101
112508
  }
113102
112509
  var hexes4 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i42) => i42.toString(16).padStart(2, "0"));
113103
112510
  function bytesToHex4(bytes6) {
113104
- if (!isBytes10(bytes6))
112511
+ if (!isBytes9(bytes6))
113105
112512
  throw new Error("Uint8Array expected");
113106
112513
  let hex3 = "";
113107
112514
  for (let i42 = 0; i42 < bytes6.length; i42++) {
@@ -113151,7 +112558,7 @@ function bytesToNumberBE4(bytes6) {
113151
112558
  return hexToNumber3(bytesToHex4(bytes6));
113152
112559
  }
113153
112560
  function bytesToNumberLE3(bytes6) {
113154
- if (!isBytes10(bytes6))
112561
+ if (!isBytes9(bytes6))
113155
112562
  throw new Error("Uint8Array expected");
113156
112563
  return hexToNumber3(bytesToHex4(Uint8Array.from(bytes6).reverse()));
113157
112564
  }
@@ -113172,7 +112579,7 @@ function ensureBytes3(title, hex3, expectedLength) {
113172
112579
  } catch (e2) {
113173
112580
  throw new Error(`${title} must be valid hex string, got "${hex3}". Cause: ${e2}`);
113174
112581
  }
113175
- } else if (isBytes10(hex3)) {
112582
+ } else if (isBytes9(hex3)) {
113176
112583
  res = Uint8Array.from(hex3);
113177
112584
  } else {
113178
112585
  throw new Error(`${title} must be hex string or Uint8Array`);
@@ -113186,7 +112593,7 @@ function concatBytes9(...arrays) {
113186
112593
  let sum = 0;
113187
112594
  for (let i42 = 0; i42 < arrays.length; i42++) {
113188
112595
  const a3 = arrays[i42];
113189
- if (!isBytes10(a3))
112596
+ if (!isBytes9(a3))
113190
112597
  throw new Error("Uint8Array expected");
113191
112598
  sum += a3.length;
113192
112599
  }
@@ -113280,7 +112687,7 @@ var validatorFns2 = {
113280
112687
  function: (val) => typeof val === "function",
113281
112688
  boolean: (val) => typeof val === "boolean",
113282
112689
  string: (val) => typeof val === "string",
113283
- stringOrUint8Array: (val) => typeof val === "string" || isBytes10(val),
112690
+ stringOrUint8Array: (val) => typeof val === "string" || isBytes9(val),
113284
112691
  isSafeInteger: (val) => Number.isSafeInteger(val),
113285
112692
  array: (val) => Array.isArray(val),
113286
112693
  field: (val, object22) => object22.Fp.isValid(val),
@@ -113743,7 +113150,7 @@ var DER3 = {
113743
113150
  toSig(hex3) {
113744
113151
  const { Err: E } = DER3;
113745
113152
  const data = typeof hex3 === "string" ? h2b2(hex3) : hex3;
113746
- if (!isBytes10(data))
113153
+ if (!isBytes9(data))
113747
113154
  throw new Error("ui8a expected");
113748
113155
  let l2 = data.length;
113749
113156
  if (l2 < 2 || data[0] != 48)
@@ -113807,7 +113214,7 @@ function weierstrassPoints2(opts) {
113807
113214
  function normPrivateKeyToScalar(key) {
113808
113215
  const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n: n3 } = CURVE22;
113809
113216
  if (lengths && typeof key !== "bigint") {
113810
- if (isBytes10(key))
113217
+ if (isBytes9(key))
113811
113218
  key = bytesToHex4(key);
113812
113219
  if (typeof key !== "string" || !lengths.includes(key.length))
113813
113220
  throw new Error("Invalid key");
@@ -114342,7 +113749,7 @@ function weierstrass3(curveDef) {
114342
113749
  return Point7.fromPrivateKey(privateKey).toRawBytes(isCompressed);
114343
113750
  }
114344
113751
  function isProbPub(item) {
114345
- const arr = isBytes10(item);
113752
+ const arr = isBytes9(item);
114346
113753
  const str = typeof item === "string";
114347
113754
  const len = (arr || str) && item.length;
114348
113755
  if (arr)
@@ -114437,7 +113844,7 @@ function weierstrass3(curveDef) {
114437
113844
  let _sig = void 0;
114438
113845
  let P3;
114439
113846
  try {
114440
- if (typeof sg === "string" || isBytes10(sg)) {
113847
+ if (typeof sg === "string" || isBytes9(sg)) {
114441
113848
  try {
114442
113849
  _sig = Signature.fromDER(sg);
114443
113850
  } catch (derError) {
@@ -114634,7 +114041,7 @@ var secp256k13 = createCurve3({
114634
114041
  return { k1neg, k1, k2neg, k2 };
114635
114042
  }
114636
114043
  }
114637
- }, sha2567);
114044
+ }, sha2566);
114638
114045
  var _0n15 = BigInt(0);
114639
114046
  var Point5 = secp256k13.ProjectivePoint;
114640
114047
  init_shim2();
@@ -115311,7 +114718,7 @@ var Secp256k1 = class _Secp256k1 {
115311
114718
  static sign(_a3) {
115312
114719
  return __awaiter6(this, arguments, void 0, function* ({ data, key }) {
115313
114720
  const privateKeyBytes = yield _Secp256k1.privateKeyToBytes({ privateKey: key });
115314
- const digest2 = sha2566(data);
114721
+ const digest2 = sha2565(data);
115315
114722
  const signatureObject = secp256k13.sign(digest2, privateKeyBytes);
115316
114723
  const signature22 = signatureObject.toCompactRawBytes();
115317
114724
  return signature22;
@@ -115423,7 +114830,7 @@ var Secp256k1 = class _Secp256k1 {
115423
114830
  static verify(_a3) {
115424
114831
  return __awaiter6(this, arguments, void 0, function* ({ key, signature: signature22, data }) {
115425
114832
  const publicKeyBytes = yield _Secp256k1.publicKeyToBytes({ publicKey: key });
115426
- const digest2 = sha2566(data);
114833
+ const digest2 = sha2565(data);
115427
114834
  const isValid2 = secp256k13.verify(signature22, digest2, publicKeyBytes, { lowS: false });
115428
114835
  return isValid2;
115429
114836
  });
@@ -115491,7 +114898,7 @@ var p256 = createCurve3({
115491
114898
  Gy: BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),
115492
114899
  h: BigInt(1),
115493
114900
  lowS: false
115494
- }, sha2567);
114901
+ }, sha2566);
115495
114902
  var secp256r1 = p256;
115496
114903
  var __awaiter7 = function(thisArg, _arguments, P3, generator) {
115497
114904
  function adopt(value3) {
@@ -116032,7 +115439,7 @@ var Secp256r1 = class _Secp256r1 {
116032
115439
  static sign(_a3) {
116033
115440
  return __awaiter7(this, arguments, void 0, function* ({ data, key }) {
116034
115441
  const privateKeyBytes = yield _Secp256r1.privateKeyToBytes({ privateKey: key });
116035
- const digest2 = sha2566(data);
115442
+ const digest2 = sha2565(data);
116036
115443
  const signatureObject = secp256r1.sign(digest2, privateKeyBytes);
116037
115444
  const signature22 = signatureObject.toCompactRawBytes();
116038
115445
  return signature22;
@@ -116144,7 +115551,7 @@ var Secp256r1 = class _Secp256r1 {
116144
115551
  static verify(_a3) {
116145
115552
  return __awaiter7(this, arguments, void 0, function* ({ key, signature: signature22, data }) {
116146
115553
  const publicKeyBytes = yield _Secp256r1.publicKeyToBytes({ publicKey: key });
116147
- const digest2 = sha2566(data);
115554
+ const digest2 = sha2565(data);
116148
115555
  const isValid2 = secp256r1.verify(signature22, digest2, publicKeyBytes, { lowS: false });
116149
115556
  return isValid2;
116150
115557
  });
@@ -123163,7 +122570,7 @@ var sha = (name10) => (
123163
122570
  */
123164
122571
  async (data) => new Uint8Array(await crypto.subtle.digest(name10, data))
123165
122572
  );
123166
- var sha2568 = from5({
122573
+ var sha2567 = from5({
123167
122574
  name: "sha2-256",
123168
122575
  code: 18,
123169
122576
  encode: sha("SHA-256")
@@ -123211,7 +122618,7 @@ var Multihash = class _Multihash {
123211
122618
  let multihash;
123212
122619
  switch (hashAlgorithmInMultihashCode) {
123213
122620
  case 18:
123214
- let hasher = yield sha2568.digest(content);
122621
+ let hasher = yield sha2567.digest(content);
123215
122622
  multihash = hasher.bytes;
123216
122623
  break;
123217
122624
  default:
@@ -123230,7 +122637,7 @@ var Multihash = class _Multihash {
123230
122637
  let hash4;
123231
122638
  switch (hashAlgorithmInMultihashCode) {
123232
122639
  case 18:
123233
- hash4 = yield sha2568.encode(content);
122640
+ hash4 = yield sha2567.encode(content);
123234
122641
  break;
123235
122642
  default:
123236
122643
  throw new IonError(ErrorCode_default.MultihashUnsupportedHashAlgorithm, `Hash algorithm defined in multihash code ${hashAlgorithmInMultihashCode} is not supported.`);
@@ -123641,12 +123048,12 @@ var err = (m2 = "") => {
123641
123048
  };
123642
123049
  var isBig = (n3) => typeof n3 === "bigint";
123643
123050
  var isStr = (s2) => typeof s2 === "string";
123644
- var isBytes11 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
123645
- var abytes4 = (a3, l2) => !isBytes11(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
123051
+ var isBytes10 = (a3) => a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
123052
+ var abytes3 = (a3, l2) => !isBytes10(a3) || typeof l2 === "number" && l2 > 0 && a3.length !== l2 ? err("Uint8Array expected") : a3;
123646
123053
  var u8n3 = (len) => new Uint8Array(len);
123647
123054
  var u8fr3 = (buf2) => Uint8Array.from(buf2);
123648
123055
  var padh = (n3, pad2) => n3.toString(16).padStart(pad2, "0");
123649
- var bytesToHex5 = (b22) => Array.from(abytes4(b22)).map((e2) => padh(e2, 2)).join("");
123056
+ var bytesToHex5 = (b22) => Array.from(abytes3(b22)).map((e2) => padh(e2, 2)).join("");
123650
123057
  var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
123651
123058
  var _ch = (ch) => {
123652
123059
  if (ch >= C._0 && ch <= C._9)
@@ -123675,9 +123082,9 @@ var hexToBytes5 = (hex3) => {
123675
123082
  }
123676
123083
  return array22;
123677
123084
  };
123678
- var toU8 = (a3, len) => abytes4(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes4(a3)), len);
123085
+ var toU8 = (a3, len) => abytes3(isStr(a3) ? hexToBytes5(a3) : u8fr3(abytes3(a3)), len);
123679
123086
  var concatBytes10 = (...arrs) => {
123680
- const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes4(a3).length, 0));
123087
+ const r2 = u8n3(arrs.reduce((sum, a3) => sum + abytes3(a3).length, 0));
123681
123088
  let pad2 = 0;
123682
123089
  arrs.forEach((a3) => {
123683
123090
  r2.set(a3, pad2);
@@ -123734,7 +123141,7 @@ var Point6 = class _Point {
123734
123141
  }
123735
123142
  /** Convert Uint8Array or hex string to Point. */
123736
123143
  static fromBytes(bytes6) {
123737
- abytes4(bytes6);
123144
+ abytes3(bytes6);
123738
123145
  let p3 = void 0;
123739
123146
  const head = bytes6[0];
123740
123147
  const tail = bytes6.subarray(1);
@@ -125834,7 +125241,7 @@ function decode37(data) {
125834
125241
  }
125835
125242
  var sha2_browser_exports = {};
125836
125243
  __export2(sha2_browser_exports, {
125837
- sha256: () => sha2569,
125244
+ sha256: () => sha2568,
125838
125245
  sha512: () => sha5124
125839
125246
  });
125840
125247
  init_shim2();
@@ -125888,7 +125295,7 @@ function createDigest(digest2, code8, truncate) {
125888
125295
  function sha2(name10) {
125889
125296
  return async (data) => new Uint8Array(await crypto.subtle.digest(name10, data));
125890
125297
  }
125891
- var sha2569 = from6({
125298
+ var sha2568 = from6({
125892
125299
  name: "sha2-256",
125893
125300
  code: 18,
125894
125301
  encode: sha2("SHA-256")
@@ -126157,7 +125564,7 @@ var DefaultStrings = class {
126157
125564
  }
126158
125565
  async add(string4, options2 = {}) {
126159
125566
  const buf2 = fromString2(string4);
126160
- const hash4 = await (options2.hasher ?? sha2569).digest(buf2);
125567
+ const hash4 = await (options2.hasher ?? sha2568).digest(buf2);
126161
125568
  const codec2 = options2.codec ?? raw_exports;
126162
125569
  const cid = CID2.createV1(codec2.code, hash4);
126163
125570
  await this.components.blockstore.put(cid, buf2, options2);
@@ -130052,7 +129459,7 @@ var Key = class _Key {
130052
129459
  * @param {string | Uint8Array} s
130053
129460
  * @param {boolean} [clean]
130054
129461
  */
130055
- constructor(s2, clean4) {
129462
+ constructor(s2, clean3) {
130056
129463
  if (typeof s2 === "string") {
130057
129464
  this._buf = fromString2(s2);
130058
129465
  } else if (s2 instanceof Uint8Array) {
@@ -130060,10 +129467,10 @@ var Key = class _Key {
130060
129467
  } else {
130061
129468
  throw new Error("Invalid key, should be String of Uint8Array");
130062
129469
  }
130063
- if (clean4 == null) {
130064
- clean4 = true;
129470
+ if (clean3 == null) {
129471
+ clean3 = true;
130065
129472
  }
130066
- if (clean4) {
129473
+ if (clean3) {
130067
129474
  this.clean();
130068
129475
  }
130069
129476
  if (this._buf.byteLength === 0 || this._buf[0] !== pathSep) {
@@ -133481,7 +132888,7 @@ function getCodec(initialCodecs = [], loadCodec) {
133481
132888
  init_shim2();
133482
132889
  function getHasher(initialHashers = [], loadHasher) {
133483
132890
  const hashers = {
133484
- [sha2569.code]: sha2569,
132891
+ [sha2568.code]: sha2568,
133485
132892
  [sha5124.code]: sha5124,
133486
132893
  [identity2.code]: identity2
133487
132894
  };
@@ -137813,7 +137220,7 @@ function rsaKeySize(jwk) {
137813
137220
  init_shim2();
137814
137221
  var PRIVATE_KEY_BYTE_LENGTH2 = 32;
137815
137222
  function hashAndSign4(key, msg, options2) {
137816
- const p3 = sha2569.digest(msg instanceof Uint8Array ? msg : msg.subarray());
137223
+ const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
137817
137224
  if (isPromise3(p3)) {
137818
137225
  return p3.then(({ digest: digest2 }) => {
137819
137226
  options2?.signal?.throwIfAborted();
@@ -137832,7 +137239,7 @@ function hashAndSign4(key, msg, options2) {
137832
137239
  }
137833
137240
  }
137834
137241
  function hashAndVerify4(key, sig, msg, options2) {
137835
- const p3 = sha2569.digest(msg instanceof Uint8Array ? msg : msg.subarray());
137242
+ const p3 = sha2568.digest(msg instanceof Uint8Array ? msg : msg.subarray());
137836
137243
  if (isPromise3(p3)) {
137837
137244
  return p3.then(({ digest: digest2 }) => {
137838
137245
  options2?.signal?.throwIfAborted();
@@ -140039,7 +139446,7 @@ function isIdentityMultihash(multihash) {
140039
139446
  return multihash.code === identity2.code;
140040
139447
  }
140041
139448
  function isSha256Multihash(multihash) {
140042
- return multihash.code === sha2569.code;
139449
+ return multihash.code === sha2568.code;
140043
139450
  }
140044
139451
  function mapIterable(iter, map3) {
140045
139452
  const iterator = {
@@ -140861,7 +140268,7 @@ var WantList = class extends TypedEventEmitter {
140861
140268
  const cidVersion = values[0];
140862
140269
  const multicodec2 = values[1];
140863
140270
  const hashAlg = values[2];
140864
- const hasher = hashAlg === sha2569.code ? sha2569 : await this.hashLoader?.getHasher(hashAlg);
140271
+ const hasher = hashAlg === sha2568.code ? sha2568 : await this.hashLoader?.getHasher(hashAlg);
140865
140272
  if (hasher == null) {
140866
140273
  this.log.error("unknown hash algorithm", hashAlg);
140867
140274
  continue;
@@ -154725,7 +154132,7 @@ function DsInfoName(name10) {
154725
154132
  }
154726
154133
  async function keyId(key) {
154727
154134
  const pb = privateKeyToProtobuf(key);
154728
- const hash4 = await sha2569.digest(pb);
154135
+ const hash4 = await sha2568.digest(pb);
154729
154136
  return base58btc2.encode(hash4.bytes).substring(1);
154730
154137
  }
154731
154138
  var Keychain = class {
@@ -155050,7 +154457,7 @@ init_shim2();
155050
154457
  init_shim2();
155051
154458
  init_shim2();
155052
154459
  init_shim2();
155053
- function isBytes12(a3) {
154460
+ function isBytes11(a3) {
155054
154461
  return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
155055
154462
  }
155056
154463
  function abool2(b22) {
@@ -155061,20 +154468,20 @@ function anumber3(n3) {
155061
154468
  if (!Number.isSafeInteger(n3) || n3 < 0)
155062
154469
  throw new Error("positive integer expected, got " + n3);
155063
154470
  }
155064
- function abytes5(b22, ...lengths) {
155065
- if (!isBytes12(b22))
154471
+ function abytes4(b22, ...lengths) {
154472
+ if (!isBytes11(b22))
155066
154473
  throw new Error("Uint8Array expected");
155067
154474
  if (lengths.length > 0 && !lengths.includes(b22.length))
155068
154475
  throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b22.length);
155069
154476
  }
155070
- function aexists3(instance3, checkFinished = true) {
154477
+ function aexists22(instance3, checkFinished = true) {
155071
154478
  if (instance3.destroyed)
155072
154479
  throw new Error("Hash instance has been destroyed");
155073
154480
  if (checkFinished && instance3.finished)
155074
154481
  throw new Error("Hash#digest() has already been called");
155075
154482
  }
155076
- function aoutput3(out, instance3) {
155077
- abytes5(out);
154483
+ function aoutput22(out, instance3) {
154484
+ abytes4(out);
155078
154485
  const min = instance3.outputLen;
155079
154486
  if (out.length < min) {
155080
154487
  throw new Error("digestInto() expects output buffer of length at least " + min);
@@ -155083,12 +154490,12 @@ function aoutput3(out, instance3) {
155083
154490
  function u322(arr) {
155084
154491
  return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
155085
154492
  }
155086
- function clean3(...arrays) {
154493
+ function clean22(...arrays) {
155087
154494
  for (let i42 = 0; i42 < arrays.length; i42++) {
155088
154495
  arrays[i42].fill(0);
155089
154496
  }
155090
154497
  }
155091
- function createView9(arr) {
154498
+ function createView8(arr) {
155092
154499
  return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
155093
154500
  }
155094
154501
  var isLE6 = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
@@ -155100,7 +154507,7 @@ function utf8ToBytes10(str) {
155100
154507
  function toBytes7(data) {
155101
154508
  if (typeof data === "string")
155102
154509
  data = utf8ToBytes10(data);
155103
- else if (isBytes12(data))
154510
+ else if (isBytes11(data))
155104
154511
  data = copyBytes2(data);
155105
154512
  else
155106
154513
  throw new Error("Uint8Array expected, got " + typeof data);
@@ -155122,7 +154529,7 @@ function equalBytes8(a3, b22) {
155122
154529
  }
155123
154530
  var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
155124
154531
  function wrappedCipher(key, ...args) {
155125
- abytes5(key);
154532
+ abytes4(key);
155126
154533
  if (!isLE6)
155127
154534
  throw new Error("Non little-endian hardware is not yet supported");
155128
154535
  if (params.nonceLength !== void 0) {
@@ -155130,20 +154537,20 @@ var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
155130
154537
  if (!nonce)
155131
154538
  throw new Error("nonce / iv required");
155132
154539
  if (params.varSizeNonce)
155133
- abytes5(nonce);
154540
+ abytes4(nonce);
155134
154541
  else
155135
- abytes5(nonce, params.nonceLength);
154542
+ abytes4(nonce, params.nonceLength);
155136
154543
  }
155137
154544
  const tagl = params.tagLength;
155138
154545
  if (tagl && args[1] !== void 0) {
155139
- abytes5(args[1]);
154546
+ abytes4(args[1]);
155140
154547
  }
155141
154548
  const cipher = constructor(key, ...args);
155142
154549
  const checkOutput = (fnLength, output6) => {
155143
154550
  if (output6 !== void 0) {
155144
154551
  if (fnLength !== 2)
155145
154552
  throw new Error("cipher output not supported");
155146
- abytes5(output6);
154553
+ abytes4(output6);
155147
154554
  }
155148
154555
  };
155149
154556
  let called = false;
@@ -155152,12 +154559,12 @@ var wrapCipher2 = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
155152
154559
  if (called)
155153
154560
  throw new Error("cannot encrypt() twice with same key + nonce");
155154
154561
  called = true;
155155
- abytes5(data);
154562
+ abytes4(data);
155156
154563
  checkOutput(cipher.encrypt.length, output6);
155157
154564
  return cipher.encrypt(data, output6);
155158
154565
  },
155159
154566
  decrypt(data, output6) {
155160
- abytes5(data);
154567
+ abytes4(data);
155161
154568
  if (tagl && data.length < tagl)
155162
154569
  throw new Error("invalid ciphertext length: smaller than tagLength=" + tagl);
155163
154570
  checkOutput(cipher.decrypt.length, output6);
@@ -155193,7 +154600,7 @@ function setBigUint647(view, byteOffset, value3, isLE7) {
155193
154600
  function u64Lengths(dataLength, aadLength, isLE7) {
155194
154601
  abool2(isLE7);
155195
154602
  const num22 = new Uint8Array(16);
155196
- const view = createView9(num22);
154603
+ const view = createView8(num22);
155197
154604
  setBigUint647(view, 0, BigInt(aadLength), isLE7);
155198
154605
  setBigUint647(view, 8, BigInt(dataLength), isLE7);
155199
154606
  return num22;
@@ -155258,13 +154665,13 @@ function createCipher2(core, opts) {
155258
154665
  abool2(counterRight);
155259
154666
  abool2(allowShortKeys);
155260
154667
  return (key, nonce, data, output6, counter = 0) => {
155261
- abytes5(key);
155262
- abytes5(nonce);
155263
- abytes5(data);
154668
+ abytes4(key);
154669
+ abytes4(nonce);
154670
+ abytes4(data);
155264
154671
  const len = data.length;
155265
154672
  if (output6 === void 0)
155266
154673
  output6 = new Uint8Array(len);
155267
- abytes5(output6);
154674
+ abytes4(output6);
155268
154675
  anumber3(counter);
155269
154676
  if (counter < 0 || counter >= MAX_COUNTER2)
155270
154677
  throw new Error("arx: counter overflow");
@@ -155306,7 +154713,7 @@ function createCipher2(core, opts) {
155306
154713
  }
155307
154714
  const n32 = u322(nonce);
155308
154715
  runCipher2(core, sigma2, k32, n32, data, output6, counter, rounds);
155309
- clean3(...toClean);
154716
+ clean22(...toClean);
155310
154717
  return output6;
155311
154718
  };
155312
154719
  }
@@ -155323,7 +154730,7 @@ var Poly13052 = class {
155323
154730
  this.pos = 0;
155324
154731
  this.finished = false;
155325
154732
  key = toBytes7(key);
155326
- abytes5(key, 32);
154733
+ abytes4(key, 32);
155327
154734
  const t0 = u8to162(key, 0);
155328
154735
  const t1 = u8to162(key, 2);
155329
154736
  const t2 = u8to162(key, 4);
@@ -155499,12 +154906,12 @@ var Poly13052 = class {
155499
154906
  f2 = (h2[i42] + pad2[i42] | 0) + (f2 >>> 16) | 0;
155500
154907
  h2[i42] = f2 & 65535;
155501
154908
  }
155502
- clean3(g);
154909
+ clean22(g);
155503
154910
  }
155504
154911
  update(data) {
155505
- aexists3(this);
154912
+ aexists22(this);
155506
154913
  data = toBytes7(data);
155507
- abytes5(data);
154914
+ abytes4(data);
155508
154915
  const { buffer: buffer2, blockLen } = this;
155509
154916
  const len = data.length;
155510
154917
  for (let pos = 0; pos < len; ) {
@@ -155525,11 +154932,11 @@ var Poly13052 = class {
155525
154932
  return this;
155526
154933
  }
155527
154934
  destroy() {
155528
- clean3(this.h, this.r, this.buffer, this.pad);
154935
+ clean22(this.h, this.r, this.buffer, this.pad);
155529
154936
  }
155530
154937
  digestInto(out) {
155531
- aexists3(this);
155532
- aoutput3(out, this);
154938
+ aexists22(this);
154939
+ aoutput22(out, this);
155533
154940
  this.finished = true;
155534
154941
  const { buffer: buffer2, h: h2 } = this;
155535
154942
  let { pos } = this;
@@ -155757,7 +155164,7 @@ function computeTag3(fn, key, nonce, data, AAD) {
155757
155164
  const num22 = u64Lengths(data.length, AAD ? AAD.length : 0, true);
155758
155165
  h2.update(num22);
155759
155166
  const res = h2.digest();
155760
- clean3(authKey, num22);
155167
+ clean22(authKey, num22);
155761
155168
  return res;
155762
155169
  }
155763
155170
  var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
@@ -155771,7 +155178,7 @@ var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
155771
155178
  xorStream(key, nonce, oPlain, oPlain, 1);
155772
155179
  const tag = computeTag3(xorStream, key, nonce, oPlain, AAD);
155773
155180
  output6.set(tag, plength);
155774
- clean3(tag);
155181
+ clean22(tag);
155775
155182
  return output6;
155776
155183
  },
155777
155184
  decrypt(ciphertext, output6) {
@@ -155783,7 +155190,7 @@ var _poly1305_aead2 = (xorStream) => (key, nonce, AAD) => {
155783
155190
  throw new Error("invalid tag");
155784
155191
  output6.set(ciphertext.subarray(0, -tagLength));
155785
155192
  xorStream(key, nonce, output6, output6, 1);
155786
- clean3(tag);
155193
+ clean22(tag);
155787
155194
  return output6;
155788
155195
  }
155789
155196
  };
@@ -162304,7 +161711,7 @@ function removePrivateAddressesMapper(peer) {
162304
161711
  };
162305
161712
  }
162306
161713
  async function convertBuffer(buf2, options2) {
162307
- const multihash = await sha2569.digest(buf2);
161714
+ const multihash = await sha2568.digest(buf2);
162308
161715
  options2?.signal?.throwIfAborted();
162309
161716
  return multihash.digest;
162310
161717
  }
@@ -181450,7 +180857,7 @@ var RoutingTableRefresh = class {
181450
180857
  const keyPrefix2 = generated_prefix_list_browser_default[targetPrefix];
181451
180858
  const keyBuffer = new ArrayBuffer(34);
181452
180859
  const keyView = new DataView(keyBuffer, 0, keyBuffer.byteLength);
181453
- keyView.setUint8(0, sha2569.code);
180860
+ keyView.setUint8(0, sha2568.code);
181454
180861
  keyView.setUint8(1, 32);
181455
180862
  keyView.setUint32(2, keyPrefix2, false);
181456
180863
  return new Uint8Array(keyView.buffer, keyView.byteOffset, keyView.byteLength);
@@ -187874,7 +187281,7 @@ var md2 = create6(id_md2);
187874
187281
  var md4 = create6(id_md5);
187875
187282
  var sha13 = create6(id_sha1);
187876
187283
  var sha2243 = create6(id_sha224);
187877
- var sha25610 = create6(id_sha256);
187284
+ var sha2569 = create6(id_sha256);
187878
187285
  var sha3842 = create6(id_sha384);
187879
187286
  var sha5126 = create6(id_sha512);
187880
187287
  var sha512_2242 = create6(id_sha512_224);
@@ -191841,7 +191248,7 @@ function ma2Fingerprint(ma) {
191841
191248
  function fingerprint2Ma(fingerprint) {
191842
191249
  const output6 = fingerprint.split(":").map((str) => parseInt(str, 16));
191843
191250
  const encoded = Uint8Array.from(output6);
191844
- const digest2 = create3(sha2569.code, encoded);
191251
+ const digest2 = create3(sha2568.code, encoded);
191845
191252
  return multiaddr(`/certhash/${base64url4.encode(digest2.bytes)}`);
191846
191253
  }
191847
191254
  function toSupportedHashFunction(code8) {
@@ -191918,7 +191325,7 @@ var PREFIX = fromString2("libp2p-webrtc-noise:");
191918
191325
  function generateNoisePrologue(localFingerprint, remoteAddr, role) {
191919
191326
  const localFpString = localFingerprint.trim().toLowerCase().replaceAll(":", "");
191920
191327
  const localFpArray = fromString2(localFpString, "hex");
191921
- const local = create3(sha2569.code, localFpArray);
191328
+ const local = create3(sha2568.code, localFpArray);
191922
191329
  const remote = multibaseDecoder.decode(certhash(remoteAddr));
191923
191330
  const byteLength = PREFIX.byteLength + local.bytes.byteLength + remote.byteLength;
191924
191331
  if (role === "server") {
@@ -192241,7 +191648,7 @@ var WebRTCDirectTransport = class {
192241
191648
  }, renewTime);
192242
191649
  return {
192243
191650
  pem: cert.toString("pem"),
192244
- certhash: base64url4.encode((await sha2569.digest(new Uint8Array(cert.rawData))).bytes)
191651
+ certhash: base64url4.encode((await sha2568.digest(new Uint8Array(cert.rawData))).bytes)
192245
191652
  };
192246
191653
  }
192247
191654
  async loadCertificate(dsKey, keyPair) {
@@ -192951,13 +192358,12 @@ var Appendix = class _Appendix {
192951
192358
  * ```
192952
192359
  */
192953
192360
  static deriveRootCapability(identifier) {
192954
- const rootCapability = {};
192955
- rootCapability["@context"] = W3C_ZCAP_V12;
192956
- const encodedIdentifier = encodeURIComponent(identifier);
192957
- rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
192958
- rootCapability.controller = identifier;
192959
- rootCapability.invocationTarget = identifier;
192960
- return rootCapability;
192361
+ return {
192362
+ "@context": "https://w3id.org/zcap/v1",
192363
+ id: `urn:zcap:root:${encodeURIComponent(identifier)}`,
192364
+ controller: identifier,
192365
+ invocationTarget: identifier
192366
+ };
192961
192367
  }
192962
192368
  /**
192963
192369
  * Implements {@link https://dcdpr.github.io/did-btcr2/#dereference-root-capability-identifier | 9.4.2 Dereference Root Capability Identifier}.
@@ -193055,7 +192461,6 @@ var BeaconUtils = class {
193055
192461
  if (!Appendix.isDidService(obj)) return false;
193056
192462
  if (!["SingletonBeacon", "CASBeacon", "SMTBeacon"].includes(obj.type)) return false;
193057
192463
  if ([obj.serviceEndpoint].flat().some((ep) => typeof ep === "string" && !ep.startsWith("bitcoin:"))) return false;
193058
- if (obj.casType && typeof obj.casType !== "string") return false;
193059
192464
  return true;
193060
192465
  }
193061
192466
  /**
@@ -193080,8 +192485,11 @@ var BeaconUtils = class {
193080
192485
  (addrType) => this.createBeaconService(did, addrType, beaconType)
193081
192486
  );
193082
192487
  } catch (error) {
193083
- console.error(error);
193084
- import_process2.default.exit(1);
192488
+ throw new BeaconError(
192489
+ "Failed to create beacon services: " + error.message,
192490
+ "BEACON_SERVICE_ERROR",
192491
+ { did, beaconType }
192492
+ );
193085
192493
  }
193086
192494
  }
193087
192495
  /**
@@ -193101,8 +192509,11 @@ var BeaconUtils = class {
193101
192509
  const serviceEndpoint = `bitcoin:${payments_exports2[addressType]({ pubkey, network }).address}`;
193102
192510
  return { id, type: beaconType, serviceEndpoint };
193103
192511
  } catch (error) {
193104
- console.error(error);
193105
- import_process2.default.exit(1);
192512
+ throw new BeaconError(
192513
+ "Failed to create beacon service: " + error.message,
192514
+ "BEACON_SERVICE_ERROR",
192515
+ { did, beaconType }
192516
+ );
193106
192517
  }
193107
192518
  }
193108
192519
  /**
@@ -193137,8 +192548,11 @@ var BeaconUtils = class {
193137
192548
  }
193138
192549
  ];
193139
192550
  } catch (error) {
193140
- console.error(error);
193141
- import_process2.default.exit(1);
192551
+ throw new BeaconError(
192552
+ "Failed to create beacon services: " + error.message,
192553
+ "BEACON_SERVICE_ERROR",
192554
+ { id, publicKey: publicKey2, network, beaconType }
192555
+ );
193142
192556
  }
193143
192557
  }
193144
192558
  /**
@@ -193184,9 +192598,9 @@ var BIP340DataIntegrityProof2 = class {
193184
192598
  }
193185
192599
  /**
193186
192600
  * Add a proof to a document.
193187
- * @param {BTCR2UnsignedUpdate} unsignedDocument The document to add the proof to.
192601
+ * @param {UnsignedBTCR2Update} unsignedDocument The document to add the proof to.
193188
192602
  * @param {DataIntegrityConfig} config The configuration for generating the proof.
193189
- * @returns {BTCR2SignedUpdate} A document with a proof added.
192603
+ * @returns {SignedBTCR2Update} A document with a proof added.
193190
192604
  */
193191
192605
  addProof(unsignedDocument, config) {
193192
192606
  const proof = this.cryptosuite.createProof(unsignedDocument, config);
@@ -193299,7 +192713,7 @@ var BIP340Cryptosuite2 = class {
193299
192713
  }
193300
192714
  /**
193301
192715
  * Verify a proof for a secure document.
193302
- * @param {BTCR2SignedUpdate} secureDocument The secure document to verify.
192716
+ * @param {SignedBTCR2Update} secureDocument The secure document to verify.
193303
192717
  * @returns {VerificationResult} The result of the verification.
193304
192718
  */
193305
192719
  verifyProof(secureDocument) {
@@ -193314,7 +192728,7 @@ var BIP340Cryptosuite2 = class {
193314
192728
  }
193315
192729
  /**
193316
192730
  * Transform a document into canonical form.
193317
- * @param {BTCR2UnsignedUpdate | BTCR2SignedUpdate} document The document to transform.
192731
+ * @param {UnsignedBTCR2Update | SignedBTCR2Update} document The document to transform.
193318
192732
  * @param {DataIntegrityConfig} config The config to use when transforming the document.
193319
192733
  * @returns {string} The canonicalized document.
193320
192734
  * @throws {MethodError} if the document cannot be transformed.
@@ -193413,29 +192827,27 @@ var SchnorrMultikey2 = class _SchnorrMultikey {
193413
192827
  * @param {MultikeyParams} params The parameters to create the multikey
193414
192828
  * @param {string} params.id The id of the multikey (required)
193415
192829
  * @param {string} params.controller The controller of the multikey (required)
193416
- * @param {Keys} params.keys The Keys of the multikey (optional, required if no publicKey)
193417
- * @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
193418
- * @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
192830
+ * @param {SchnorrKeyPair} params.keyPair The key pair of the multikey (optional, required if no publicKey)
193419
192831
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
193420
192832
  */
193421
- constructor({ id, controller, keys }) {
193422
- if (!keys) {
193423
- throw new MultikeyError2('Argument missing: "keys" required', "CONSTRUCTOR_ERROR");
192833
+ constructor({ id, controller, keyPair }) {
192834
+ if (!keyPair) {
192835
+ throw new MultikeyError2('Argument missing: "keyPair" required', "CONSTRUCTOR_ERROR");
193424
192836
  }
193425
- if (!keys.publicKey) {
193426
- throw new MultikeyError2('Argument missing: "keys" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
192837
+ if (!keyPair.publicKey) {
192838
+ throw new MultikeyError2('Argument missing: "keyPair" must contain a "publicKey"', "CONSTRUCTOR_ERROR");
193427
192839
  }
193428
192840
  this.id = id;
193429
192841
  this.controller = controller;
193430
- this.#keyPair = keys;
192842
+ this.#keyPair = keyPair;
193431
192843
  }
193432
192844
  /**
193433
192845
  * @readonly
193434
192846
  * Get the SchnorrKeyPair.
193435
192847
  */
193436
192848
  get keyPair() {
193437
- const keys = this.#keyPair;
193438
- return keys;
192849
+ const keyPair = this.#keyPair;
192850
+ return keyPair;
193439
192851
  }
193440
192852
  /**
193441
192853
  * @readonly
@@ -193542,9 +192954,10 @@ var SchnorrMultikey2 = class _SchnorrMultikey {
193542
192954
  throw new MultikeyError2('Invalid "type" in verificationMethod', VERIFICATION_METHOD_ERROR2, { verificationMethod });
193543
192955
  }
193544
192956
  const decoded = this.publicKey.decode();
193545
- const publicKey2 = decoded.slice(2, decoded.length);
193546
- const keys = new SchnorrKeyPair2({ publicKey: new CompressedSecp256k1PublicKey2(publicKey2) });
193547
- return new _SchnorrMultikey({ id, controller, keys });
192957
+ const pk = decoded.slice(2, decoded.length);
192958
+ const publicKey2 = new CompressedSecp256k1PublicKey2(pk);
192959
+ const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
192960
+ return new _SchnorrMultikey({ id, controller, keyPair });
193548
192961
  }
193549
192962
  /**
193550
192963
  * @readonly
@@ -193578,22 +192991,21 @@ var SchnorrMultikey2 = class _SchnorrMultikey {
193578
192991
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
193579
192992
  * @returns {SchnorrMultikey} A new Multikey instance
193580
192993
  */
193581
- static create({ id, controller, keys }) {
193582
- return new _SchnorrMultikey({ id, controller, keys });
192994
+ static create({ id, controller, keyPair }) {
192995
+ return new _SchnorrMultikey({ id, controller, keyPair });
193583
192996
  }
193584
192997
  /**
193585
192998
  * Creates a `Multikey` instance from a private key
193586
- * @param {FromPublicKey} params The parameters to create the multikey
193587
192999
  * @param {string} params.id The id of the multikey
193588
193000
  * @param {string} params.controller The controller of the multikey
193589
193001
  * @param {KeyBytes} params.entropy The private key bytes for the multikey
193590
193002
  * @returns {SchnorrMultikey} The new multikey instance
193591
193003
  */
193592
- static fromPrivateKey({ id, controller, entropy }) {
193593
- const secretKey = new Secp256k1SecretKey2(entropy);
193004
+ static fromSecretKey(id, controller, secretKeyb) {
193005
+ const secretKey = new Secp256k1SecretKey2(secretKeyb);
193594
193006
  const publicKey2 = secretKey.computePublicKey();
193595
- const keys = new SchnorrKeyPair2({ publicKey: publicKey2, secretKey });
193596
- return new _SchnorrMultikey({ id, controller, keys });
193007
+ const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2, secretKey });
193008
+ return new _SchnorrMultikey({ id, controller, keyPair });
193597
193009
  }
193598
193010
  /**
193599
193011
  * Creates a `Multikey` instance from a public key
@@ -193604,24 +193016,29 @@ var SchnorrMultikey2 = class _SchnorrMultikey {
193604
193016
  * @returns {Multikey} The new multikey instance
193605
193017
  */
193606
193018
  static fromPublicKey({ id, controller, publicKeyBytes }) {
193607
- const keys = new SchnorrKeyPair2({ publicKey: new CompressedSecp256k1PublicKey2(publicKeyBytes) });
193608
- return new _SchnorrMultikey({ id, controller, keys });
193019
+ const publicKey2 = new CompressedSecp256k1PublicKey2(publicKeyBytes);
193020
+ const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
193021
+ return new _SchnorrMultikey({ id, controller, keyPair });
193609
193022
  }
193610
193023
  /**
193611
193024
  * Creates a `Multikey` instance from a public key multibase.
193612
- * @param {string} id The id of the multikey.
193613
- * @param {string} controller The controller of the multikey.
193614
- * @param {string} publicKeyMultibase The public key multibase of the multikey.
193025
+ * @param {DidVerificationMethod} vm The verification method containing the public key multibase.
193026
+ * @param {string} vm.id The id of the multikey.
193027
+ * @param {string} vm.controller The controller of the multikey.
193028
+ * @param {string} vm.publicKeyMultibase The public key multibase of the multikey.
193615
193029
  * @returns {Multikey} The new multikey instance.
193616
193030
  */
193617
- static fromPublicKeyMultibase(id, controller, publicKeyMultibase) {
193031
+ static fromVerificationMethod({ id, controller, publicKeyMultibase }) {
193032
+ if (!publicKeyMultibase) {
193033
+ throw new MultikeyError2("Invalid publicKeyMultibase: cannot be undefined", VERIFICATION_METHOD_ERROR2, { publicKeyMultibase });
193034
+ }
193618
193035
  const publicKeyMultibaseBytes = base58btc2.decode(publicKeyMultibase);
193619
193036
  if (publicKeyMultibaseBytes.length !== 35) {
193620
193037
  throw new MultikeyError2(`Invalid publicKeyMultibase length: ${publicKeyMultibaseBytes.length}`, VERIFICATION_METHOD_ERROR2, { publicKeyMultibase });
193621
193038
  }
193622
193039
  const publicKey2 = publicKeyMultibaseBytes.slice(2);
193623
- const keys = new SchnorrKeyPair2({ publicKey: publicKey2 });
193624
- return new _SchnorrMultikey({ id, controller, keys });
193040
+ const keyPair = new SchnorrKeyPair2({ publicKey: publicKey2 });
193041
+ return new _SchnorrMultikey({ id, controller, keyPair });
193625
193042
  }
193626
193043
  };
193627
193044
  init_shim2();
@@ -193791,6 +193208,7 @@ var DidDocument2 = class _DidDocument {
193791
193208
  * @returns {boolean} True if the id is valid.
193792
193209
  */
193793
193210
  static isValidId(id) {
193211
+ if (typeof id !== "string") return false;
193794
193212
  try {
193795
193213
  Identifier.decode(id);
193796
193214
  return true;
@@ -193840,18 +193258,14 @@ var DidDocument2 = class _DidDocument {
193840
193258
  "capabilityInvocation",
193841
193259
  "capabilityDelegation"
193842
193260
  ];
193843
- const verificationRelationships = Object.keys(didDocument);
193844
- const availableVerificationRelationships = possibleVerificationRelationships.filter(
193845
- (key) => verificationRelationships.includes(key)
193846
- );
193847
- return availableVerificationRelationships.every((key) => (
193848
- // Check if the key exists in the DID Document
193849
- didDocument[key] && // Check if the key is an array
193850
- Array.isArray(didDocument[key]) && // Check that every value in the array is a string or DidVerificationMethod
193851
- didDocument[key].every(
193261
+ const keys = Object.keys(didDocument);
193262
+ const availableKeys = possibleVerificationRelationships.filter((key) => keys.includes(key));
193263
+ return availableKeys.every((key) => {
193264
+ const value3 = didDocument[key];
193265
+ return value3 && Array.isArray(value3) && value3.every(
193852
193266
  (entry) => typeof entry === "string" || Appendix.isDidVerificationMethod(entry)
193853
- )
193854
- ));
193267
+ );
193268
+ });
193855
193269
  }
193856
193270
  /**
193857
193271
  * Validate the DID Document
@@ -193972,13 +193386,192 @@ var GenesisDocument = class _GenesisDocument extends DidDocument2 {
193972
193386
  return new _GenesisDocument(object22);
193973
193387
  }
193974
193388
  };
193389
+ init_shim2();
193390
+ var BeaconSignalDiscovery = class {
193391
+ /**
193392
+ * Retrieves the beacon signals for the given array of BeaconService objects
193393
+ * using an esplora/electrs REST API connection via a bitcoin I/O driver.
193394
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
193395
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
193396
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
193397
+ */
193398
+ static async indexer(beaconServices, bitcoin32) {
193399
+ const beaconServiceSignals = /* @__PURE__ */ new Map();
193400
+ const currentBlockCount = await bitcoin32.network.rest.block.count();
193401
+ for (const beaconService of beaconServices) {
193402
+ beaconServiceSignals.set(beaconService, []);
193403
+ const beaconSignals = await bitcoin32.network.rest.address.getTxs(
193404
+ beaconService.serviceEndpoint
193405
+ );
193406
+ if (!beaconSignals || !beaconSignals.length) {
193407
+ continue;
193408
+ }
193409
+ for (const beaconSignal of beaconSignals) {
193410
+ const signalVout = beaconSignal.vout.slice(-1)[0];
193411
+ if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
193412
+ continue;
193413
+ }
193414
+ const outputMap = new Map(Object.entries(signalVout));
193415
+ const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
193416
+ if (!signalVoutScriptPubkey) {
193417
+ continue;
193418
+ }
193419
+ const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
193420
+ if (!updateHash) {
193421
+ continue;
193422
+ }
193423
+ const confirmations = currentBlockCount - beaconSignal.status.block_height + 1;
193424
+ beaconServiceSignals.get(beaconService)?.push({
193425
+ tx: beaconSignal,
193426
+ signalBytes: updateHash,
193427
+ blockMetadata: {
193428
+ confirmations,
193429
+ height: beaconSignal.status.block_height,
193430
+ time: beaconSignal.status.block_time
193431
+ }
193432
+ });
193433
+ }
193434
+ }
193435
+ return beaconServiceSignals;
193436
+ }
193437
+ /**
193438
+ * Traverse the full blockchain from genesis to chain top looking for beacon signals.
193439
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
193440
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
193441
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
193442
+ */
193443
+ static async fullnode(beaconServices, bitcoin32) {
193444
+ const beaconServiceSignals = /* @__PURE__ */ new Map();
193445
+ for (const beaconService of beaconServices) {
193446
+ beaconServiceSignals.set(beaconService, []);
193447
+ }
193448
+ const rpc = bitcoin32.network.rpc;
193449
+ if (!rpc) {
193450
+ throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin32);
193451
+ }
193452
+ const targetHeight = await rpc.getBlockCount();
193453
+ const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
193454
+ let height = 0;
193455
+ let block = await bitcoin32.network.rpc.getBlock({ height });
193456
+ console.info(`Searching for beacon signals, please wait ...`);
193457
+ while (block.height <= targetHeight) {
193458
+ for (const tx of block.tx) {
193459
+ if (tx.txid === GENESIS_TX_ID) {
193460
+ continue;
193461
+ }
193462
+ for (const vin of tx.vin) {
193463
+ if (vin.coinbase) {
193464
+ continue;
193465
+ }
193466
+ if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
193467
+ continue;
193468
+ }
193469
+ if (!vin.txid) {
193470
+ continue;
193471
+ }
193472
+ if (vin.vout === void 0) {
193473
+ continue;
193474
+ }
193475
+ const prevout = await rpc.getRawTransaction(vin.txid, 2);
193476
+ if (!prevout.vout[vin.vout]) {
193477
+ continue;
193478
+ }
193479
+ const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
193480
+ if (!scriptPubKey.address) {
193481
+ continue;
193482
+ }
193483
+ const beaconService = beaconServicesMap.get(scriptPubKey.address);
193484
+ if (!beaconService) {
193485
+ continue;
193486
+ }
193487
+ const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
193488
+ if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
193489
+ continue;
193490
+ }
193491
+ console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
193492
+ const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
193493
+ if (!updateHash) {
193494
+ continue;
193495
+ }
193496
+ beaconServiceSignals.get(beaconService)?.push({
193497
+ tx,
193498
+ signalBytes: updateHash,
193499
+ blockMetadata: {
193500
+ height: block.height,
193501
+ time: block.time,
193502
+ confirmations: block.confirmations
193503
+ }
193504
+ });
193505
+ }
193506
+ ;
193507
+ }
193508
+ height += 1;
193509
+ if (height > targetHeight) {
193510
+ console.info(`Chain tip reached ${height}, breaking ...`);
193511
+ break;
193512
+ }
193513
+ block = await rpc.getBlock({ height });
193514
+ }
193515
+ return beaconServiceSignals;
193516
+ }
193517
+ };
193975
193518
  var Resolve = class {
193519
+ /**
193520
+ * 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}.
193521
+ * @param {DidComponents} didComponents The decoded components of the did.
193522
+ * @returns {DidDocument} The resolved DID Document object.
193523
+ */
193524
+ static deterministic(didComponents) {
193525
+ const did = Identifier.encode(didComponents);
193526
+ const { genesisBytes } = didComponents;
193527
+ const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey2(genesisBytes);
193528
+ const service = BeaconUtils.generateBeaconServices({
193529
+ id: did,
193530
+ publicKey: genesisBytes,
193531
+ network: getNetwork2(didComponents.network),
193532
+ beaconType: "SingletonBeacon"
193533
+ });
193534
+ return new DidDocument2({
193535
+ id: did,
193536
+ controller: [did],
193537
+ verificationMethod: [{
193538
+ id: `${did}#initialKey`,
193539
+ type: "Multikey",
193540
+ controller: did,
193541
+ publicKeyMultibase: publicKeyMultibase.encoded
193542
+ }],
193543
+ service
193544
+ });
193545
+ }
193546
+ /**
193547
+ * 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}.
193548
+ * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
193549
+ * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
193550
+ * @returns {Promise<DidDocument>} The resolved DID Document object
193551
+ * @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
193552
+ */
193553
+ static async external(didComponents, genesisDocument) {
193554
+ const hashBytes = canonicalization22.process(genesisDocument, { encoding: "hex" });
193555
+ const genesisBytes = bytesToHex2(didComponents.genesisBytes);
193556
+ if (genesisBytes !== hashBytes) {
193557
+ throw new ResolveError(
193558
+ `Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
193559
+ INVALID_DID_DOCUMENT2,
193560
+ { genesisBytes, hashBytes }
193561
+ );
193562
+ }
193563
+ const did = Identifier.encode(didComponents);
193564
+ const currentDocument = JSON.parse(
193565
+ JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
193566
+ );
193567
+ return new DidDocument2(currentDocument);
193568
+ }
193976
193569
  /**
193977
193570
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
193978
193571
  * @param {Sidecar} sidecar The sidecar data to process.
193979
- * @returns {SidecarData} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
193572
+ * @returns {ProcessedSidecar} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
193980
193573
  */
193981
- static processSidecarData(sidecar = {}) {
193574
+ static sidecarData(sidecar = {}) {
193982
193575
  const updateMap = /* @__PURE__ */ new Map();
193983
193576
  if (sidecar.updates?.length)
193984
193577
  for (const update of sidecar.updates) {
@@ -194003,9 +193596,9 @@ var Resolve = class {
194003
193596
  * @param {DidComponents} didComponents The decoded components of the did.
194004
193597
  * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
194005
193598
  * @returns {Promise<DidDocument>} The resolved DID Document object.
194006
- * @throws {DidError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
193599
+ * @throws {ResolveError} if the DID hrp is invalid, no sidecarData passed and hrp = "x".
194007
193600
  */
194008
- static async establishCurrentDocument(didComponents, genesisDocument) {
193601
+ static async currentDocument(didComponents, genesisDocument) {
194009
193602
  const { hrp, genesisBytes } = didComponents;
194010
193603
  if (hrp === IdentifierHrp2.x) {
194011
193604
  if (!genesisDocument)
@@ -194028,84 +193621,33 @@ var Resolve = class {
194028
193621
  }
194029
193622
  throw new ResolveError(`Unsupported DID hrp ${hrp}`, INVALID_DID2, { hrp });
194030
193623
  }
194031
- /**
194032
- * 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}.
194033
- * @param {DidComponents} didComponents The decoded components of the did.
194034
- * @returns {DidDocument} The resolved DID Document object.
194035
- */
194036
- static deterministic(didComponents) {
194037
- const did = Identifier.encode(didComponents);
194038
- const { genesisBytes } = didComponents;
194039
- const { multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey2(genesisBytes);
194040
- const service = BeaconUtils.generateBeaconServices({
194041
- id: did,
194042
- publicKey: genesisBytes,
194043
- network: getNetwork2(didComponents.network),
194044
- beaconType: "SingletonBeacon"
194045
- });
194046
- return new DidDocument2({
194047
- id: did,
194048
- controller: [did],
194049
- verificationMethod: [{
194050
- id: `${did}#initialKey`,
194051
- type: "Multikey",
194052
- controller: did,
194053
- publicKeyMultibase: publicKeyMultibase.encoded
194054
- }],
194055
- service
194056
- });
194057
- }
194058
- /**
194059
- * 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}.
194060
- * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
194061
- * @param {GenesisDocument} genesisDocument The genesis document for resolving the DID Document.
194062
- * @returns {Promise<DidDocument>} The resolved DID Document object
194063
- * @throws {MethodError} InvalidDidDocument if not conformant to DID Core v1.1
194064
- */
194065
- static async external(didComponents, genesisDocument) {
194066
- const hashBytes = canonicalization22.process(genesisDocument, { encoding: "hex" });
194067
- const genesisBytes = bytesToHex2(didComponents.genesisBytes);
194068
- if (genesisBytes !== hashBytes) {
194069
- throw new MethodError2(
194070
- `Initial document mismatch: genesisBytes ${genesisBytes} !== hashBytes ${hashBytes}`,
194071
- INVALID_DID_DOCUMENT2,
194072
- { genesisBytes, hashBytes }
194073
- );
194074
- }
194075
- const did = Identifier.encode(didComponents);
194076
- const currentDocument = JSON.parse(
194077
- JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did)
194078
- );
194079
- return new DidDocument2(currentDocument);
194080
- }
194081
193624
  /**
194082
193625
  * Finds uses the beacon services in the currentDocument to scan for onchain Beacon Signals (transactions) containing
194083
193626
  * Signal Bytes (last output in OP_RETURN transaction).
194084
193627
  * @param {Array<BeaconService>} beaconServices The array of BeaconService objects to search for signals.
194085
193628
  * @param {SidecarData} sidecarData The sidecar data containing maps of updates, CAS announcements, and SMT proofs.
194086
193629
  * @param {BitcoinNetworkConnection} bitcoin The bitcoin network connection used to fetch beacon signals
194087
- * @param {boolean} [fullBlockchainTraversal=false] Whether to perform a full blockchain traversal or use an indexer
194088
- * @returns {Promise<Array<[BTCR2SignedUpdate, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
193630
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The array of BTCR2 Signed Updates announced by the Beacon Signals.
194089
193631
  */
194090
- static async processBeaconSignals(beaconServices, sidecarData, bitcoin32, fullBlockchainTraversal) {
194091
- const beaconServicesSignals = !fullBlockchainTraversal ? await this.queryBlockchainIndexer(beaconServices, bitcoin32) : await this.traverseFullBlockchain(beaconServices, bitcoin32);
194092
- const unsortedUpdates = new Array();
194093
- for (const [service, signals] of beaconServicesSignals) {
194094
- const beacon = BeaconFactory.establish(service, signals, sidecarData);
194095
- const processed = await beacon.processSignals();
194096
- unsortedUpdates.push(...processed);
194097
- }
194098
- return unsortedUpdates;
193632
+ static async beaconSignals(beaconServices, sidecarData, bitcoin32) {
193633
+ const beaconServicesSignals = bitcoin32.network.rest ? await BeaconSignalDiscovery.indexer(beaconServices, bitcoin32) : await BeaconSignalDiscovery.fullnode(beaconServices, bitcoin32);
193634
+ const promises = Array.from(beaconServicesSignals.entries()).map(
193635
+ async ([service, signals]) => {
193636
+ if (!signals.length) return [];
193637
+ return BeaconFactory.establish(service).processSignals(signals, sidecarData);
193638
+ }
193639
+ );
193640
+ return (await Promise.all(promises)).flat();
194099
193641
  }
194100
193642
  /**
194101
193643
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
194102
193644
  * @param {DidDocument} currentDocument The current DID Document to apply the updates to.
194103
- * @param {Array<[BTCR2SignedUpdate, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
193645
+ * @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
194104
193646
  * @param {string} [versionTime] The optional version time to limit updates to.
194105
193647
  * @param {string} [versionId] The optional version id to limit updates to.
194106
193648
  * @returns {Promise<DidResolutionResponse>} The updated DID Document, number of confirmations, and version id.
194107
193649
  */
194108
- static async processUpdatesArray(currentDocument, unsortedUpdates, versionTime, versionId) {
193650
+ static async updates(currentDocument, unsortedUpdates, versionTime, versionId) {
194109
193651
  let currentVersionId = 1;
194110
193652
  const updateHashHistory = [];
194111
193653
  const updates = unsortedUpdates.sort(
@@ -194128,7 +193670,7 @@ var Resolve = class {
194128
193670
  }
194129
193671
  if (update.targetVersionId <= currentVersionId) {
194130
193672
  updateHashHistory.push(currentDocumentHash);
194131
- this.confirmDuplicateUpdate(update, updateHashHistory);
193673
+ this.confirmDuplicate(update, updateHashHistory);
194132
193674
  } else if (update.targetVersionId === currentVersionId + 1) {
194133
193675
  const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
194134
193676
  if (sourceHash !== currentDocumentHash) {
@@ -194138,7 +193680,7 @@ var Resolve = class {
194138
193680
  { sourceHash, currentDocumentHash }
194139
193681
  );
194140
193682
  }
194141
- response2.currentDocument = await this.applyDidUpdate(response2.currentDocument, update);
193683
+ response2.currentDocument = await this.applyUpdate(response2.currentDocument, update);
194142
193684
  const unsignedUpdate = JSONUtils2.deleteKeys(update, ["proof"]);
194143
193685
  updateHashHistory.push(canonicalization22.process(unsignedUpdate, { encoding: "base58" }));
194144
193686
  } else if (update.targetVersionId > currentVersionId + 1) {
@@ -194162,138 +193704,13 @@ var Resolve = class {
194162
193704
  }
194163
193705
  return response2;
194164
193706
  }
194165
- /**
194166
- * Retrieves the beacon signals for the given array of BeaconService objects
194167
- * using a esplora/electrs REST API connection via a bitcoin I/O driver.
194168
- * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
194169
- * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
194170
- * @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects
194171
- */
194172
- static async queryBlockchainIndexer(beaconServices, bitcoin32) {
194173
- const beaconServiceSignals = /* @__PURE__ */ new Map();
194174
- for (const beaconService of beaconServices) {
194175
- beaconServiceSignals.set(beaconService, []);
194176
- const beaconSignals = await bitcoin32.network.rest.address.getTxs(
194177
- beaconService.serviceEndpoint
194178
- );
194179
- if (!beaconSignals || !beaconSignals.length) {
194180
- continue;
194181
- }
194182
- for (const beaconSignal of beaconSignals) {
194183
- const signalVout = beaconSignal.vout.slice(-1)[0];
194184
- if (!signalVout || !signalVout.scriptpubkey_asm.includes("OP_RETURN")) {
194185
- continue;
194186
- }
194187
- const outputMap = new Map(Object.entries(signalVout));
194188
- const signalVoutScriptPubkey = outputMap.get("scriptpubkey_asm");
194189
- if (!signalVoutScriptPubkey) {
194190
- continue;
194191
- }
194192
- const updateHash = signalVoutScriptPubkey.split(" ").slice(-1)[0];
194193
- if (!updateHash) {
194194
- continue;
194195
- }
194196
- const confirmations = await bitcoin32.network.rest.block.count() - beaconSignal.status.block_height + 1;
194197
- beaconServiceSignals.get(beaconService)?.push({
194198
- tx: beaconSignal,
194199
- signalBytes: updateHash,
194200
- blockMetadata: {
194201
- confirmations,
194202
- height: beaconSignal.status.block_height,
194203
- time: beaconSignal.status.block_time
194204
- }
194205
- });
194206
- }
194207
- }
194208
- return beaconServiceSignals;
194209
- }
194210
- /**
194211
- * Traverse the full blockchain from genesis to chain top looking for beacon signals.
194212
- * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
194213
- * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
194214
- * @returns {Promise<Array<BeaconSignal>>} Promise resolving to an array of BeaconSignal objects.
194215
- */
194216
- static async traverseFullBlockchain(beaconServices, bitcoin32) {
194217
- const beaconServiceSignals = /* @__PURE__ */ new Map();
194218
- for (const beaconService of beaconServices) {
194219
- beaconServiceSignals.set(beaconService, []);
194220
- }
194221
- const rpc = bitcoin32.network.rpc;
194222
- if (!rpc) {
194223
- throw new ResolveError("RPC connection is not available", "RPC_CONNECTION_ERROR", bitcoin32);
194224
- }
194225
- const targetHeight = await rpc.getBlockCount();
194226
- let height = 0;
194227
- let block = await bitcoin32.network.rpc.getBlock({ height });
194228
- console.info(`Searching for beacon signals, please wait ...`);
194229
- while (block.height <= targetHeight) {
194230
- for (const tx of block.tx) {
194231
- if (tx.txid === GENESIS_TX_ID) {
194232
- continue;
194233
- }
194234
- for (const vin of tx.vin) {
194235
- if (vin.coinbase) {
194236
- continue;
194237
- }
194238
- if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
194239
- continue;
194240
- }
194241
- if (!vin.txid) {
194242
- continue;
194243
- }
194244
- if (vin.vout === void 0) {
194245
- continue;
194246
- }
194247
- const prevout = await rpc.getRawTransaction(vin.txid, 2);
194248
- if (!prevout.vout[vin.vout]) {
194249
- continue;
194250
- }
194251
- const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
194252
- if (!scriptPubKey.address) {
194253
- continue;
194254
- }
194255
- const beaconService = BeaconUtils.getBeaconServicesMap(beaconServices).get(scriptPubKey.address);
194256
- if (!beaconService) {
194257
- continue;
194258
- }
194259
- const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
194260
- if (!txVoutScriptPubkeyAsm.includes("OP_RETURN")) {
194261
- continue;
194262
- }
194263
- console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
194264
- const updateHash = txVoutScriptPubkeyAsm.split(" ").slice(-1)[0];
194265
- if (!updateHash) {
194266
- continue;
194267
- }
194268
- beaconServiceSignals.get(beaconService)?.push({
194269
- tx,
194270
- signalBytes: updateHash,
194271
- blockMetadata: {
194272
- height: block.height,
194273
- time: block.time,
194274
- confirmations: block.confirmations
194275
- }
194276
- });
194277
- }
194278
- ;
194279
- }
194280
- height += 1;
194281
- const tip = await rpc.getBlockCount();
194282
- if (height > tip) {
194283
- console.info(`Chain tip reached ${height}, breaking ...`);
194284
- break;
194285
- }
194286
- block = await rpc.getBlock({ height });
194287
- }
194288
- return beaconServiceSignals;
194289
- }
194290
193707
  /**
194291
193708
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
194292
193709
  * This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
194293
- * @param {BTCR2SignedUpdate} update The BTCR2 Signed Update to confirm as a duplicate.
193710
+ * @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
194294
193711
  * @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
194295
193712
  */
194296
- static confirmDuplicateUpdate(update, updateHashHistory) {
193713
+ static confirmDuplicate(update, updateHashHistory) {
194297
193714
  const unsignedUpdate = JSONUtils2.deleteKeys(update, ["proof"]);
194298
193715
  const unsignedUpdateHash = canonicalization22.process(unsignedUpdate);
194299
193716
  const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
@@ -194308,11 +193725,11 @@ var Resolve = class {
194308
193725
  /**
194309
193726
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
194310
193727
  * @param {DidDocument} currentDocument The current DID Document to apply the update to.
194311
- * @param {BTCR2SignedUpdate} update The BTCR2 Signed Update to apply.
193728
+ * @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
194312
193729
  * @returns {Promise<DidDocument>} The updated DID Document after applying the update.
194313
193730
  * @throws {ResolveError} If the update is invalid or cannot be applied.
194314
193731
  */
194315
- static async applyDidUpdate(currentDocument, update) {
193732
+ static async applyUpdate(currentDocument, update) {
194316
193733
  const capabilityId = update.proof?.capability;
194317
193734
  if (!capabilityId) {
194318
193735
  throw new ResolveError("No root capability found in update", INVALID_DID_UPDATE2, update);
@@ -194331,18 +193748,13 @@ var Resolve = class {
194331
193748
  throw new ResolveError("No verificationMethod found in update", INVALID_DID_UPDATE2, update);
194332
193749
  }
194333
193750
  const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
194334
- const [vmController, vmId] = vm.id.split("#");
194335
- const multikey = SchnorrMultikey2.fromPublicKeyMultibase(
194336
- `#${vmId}`,
194337
- vmController,
194338
- vm.publicKeyMultibase
194339
- );
193751
+ const multikey = SchnorrMultikey2.fromVerificationMethod(vm);
194340
193752
  const cryptosuite = new BIP340Cryptosuite2(multikey);
194341
193753
  const canonicalUpdate = canonicalization22.canonicalize(update);
194342
193754
  const diProof = new BIP340DataIntegrityProof2(cryptosuite);
194343
193755
  const verificationResult = diProof.verifyProof(canonicalUpdate, "capabilityInvocation");
194344
193756
  if (!verificationResult.verified) {
194345
- throw new MethodError2(
193757
+ throw new ResolveError(
194346
193758
  "Invalid update: proof not verified",
194347
193759
  INVALID_DID_UPDATE2,
194348
193760
  verificationResult
@@ -194353,7 +193765,7 @@ var Resolve = class {
194353
193765
  const currentDocumentHash = canonicalization22.process(currentDocument, { encoding: "base58" });
194354
193766
  const updateTargetHash = update.targetHash.startsWith("z") ? update.targetHash : `z${update.targetHash}`;
194355
193767
  if (updateTargetHash !== currentDocumentHash) {
194356
- throw new MethodError2(
193768
+ throw new ResolveError(
194357
193769
  `Invalid update: updateTargetHash !== currentDocumentHash`,
194358
193770
  INVALID_DID_UPDATE2,
194359
193771
  { updateTargetHash, currentDocumentHash }
@@ -194365,103 +193777,55 @@ var Resolve = class {
194365
193777
  init_shim2();
194366
193778
  var Update = class {
194367
193779
  /**
194368
- * Implements {@link https://dcdpr.github.io/did-btcr2/#construct-did-update-payload | 4.3.1 Construct DID Update Payload}.
194369
- *
194370
- * The Construct DID Update Payload algorithm applies the documentPatch to the sourceDocument and verifies the
194371
- * resulting targetDocument is a conformant DID document. It takes in a Identifier, sourceDocument,
194372
- * sourceVersionId, and documentPatch objects. It returns an unsigned DID Update Payload.
193780
+ * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
193781
+ * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
194373
193782
  *
194374
- * @param {ConstructPayloadParams} params See {@link ConstructPayloadParams} for more details.
194375
- * @param {string} params.identifier The did-btcr2 identifier to use for verification.
194376
- * @param {DidDocument} params.sourceDocument The source document to be updated.
194377
- * @param {string} params.sourceVersionId The versionId of the source document.
194378
- * @param {DidDocumentPatch} params.patch The JSON patch to be applied to the source document.
194379
- * @returns {Promise<BTCR2SignedUpdate>} The constructed BTCR2SignedUpdate object.
194380
- * @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
193783
+ * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
193784
+ * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
193785
+ * @param {number} sourceVersionId The version ID of the source document.
193786
+ * @returns {Promise<SignedBTCR2Update>} The constructed SignedBTCR2Update object.
193787
+ * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
194381
193788
  */
194382
- static async construct({
194383
- identifier,
194384
- sourceDocument,
194385
- sourceVersionId,
194386
- patch
194387
- }) {
194388
- if (sourceDocument.id !== identifier) {
194389
- throw new UpdateError(
194390
- "Identifier mismatch: sourceDocument.id !== identifier",
194391
- INVALID_DID_UPDATE2,
194392
- { sourceDocument, identifier }
194393
- );
194394
- }
193789
+ static async construct(sourceDocument, patches, sourceVersionId) {
194395
193790
  const unsignedUpdate = {
194396
- // 3. Set BTCR2SignedUpdate.@context to the following list
194397
193791
  "@context": [
194398
193792
  "https://w3id.org/security/v2",
194399
193793
  "https://w3id.org/zcap/v1",
194400
193794
  "https://w3id.org/json-ld-patch/v1",
194401
193795
  "https://btcr2.dev/context/v1"
194402
193796
  ],
194403
- // 4. Set BTCR2SignedUpdate.patch to documentPatch.
194404
- patch,
193797
+ patch: patches,
194405
193798
  targetHash: "",
194406
- targetVersionId: 0,
194407
- sourceHash: ""
194408
- };
194409
- const targetDocument = JSONPatch.apply(sourceDocument, patch);
194410
- DidDocument2.validate(targetDocument);
194411
- unsignedUpdate.sourceHash = canonicalization22.process(sourceDocument, { encoding: "base58" }).slice(1);
194412
- unsignedUpdate.targetHash = canonicalization22.process(targetDocument, { encoding: "base58" }).slice(1);
194413
- unsignedUpdate.targetVersionId = sourceVersionId + 1;
193799
+ targetVersionId: sourceVersionId + 1,
193800
+ sourceHash: canonicalization22.process(sourceDocument, { encoding: "base58" })
193801
+ };
193802
+ const targetDocument = JSONPatch.apply(sourceDocument, patches);
193803
+ try {
193804
+ DidDocument2.isValid(targetDocument);
193805
+ } catch (error) {
193806
+ throw new UpdateError(
193807
+ "Error validating targetDocument: " + (error instanceof Error ? error.message : String(error)),
193808
+ INVALID_DID_UPDATE2,
193809
+ targetDocument
193810
+ );
193811
+ }
193812
+ unsignedUpdate.targetHash = canonicalization22.process(targetDocument, { encoding: "base58" });
194414
193813
  return unsignedUpdate;
194415
193814
  }
194416
193815
  /**
194417
- * {@link https://dcdpr.github.io/did-btcr2/#invoke-did-update-payload | 4.3.2 Invoke DID Update Payload}.
194418
- *
194419
- * The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned BTCR2SignedUpdate, and a
194420
- * verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
194421
- * the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
194422
- * specifications. It returns the invoked DID Update Payload.
193816
+ * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
193817
+ * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
194423
193818
  *
194424
- * @param {InvokePayloadParams} params Required params for calling the invokePayload method
194425
- * @param {string} params.identifier The did-btcr2 identifier to derive the root capability from
194426
- * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The updatePayload object to be signed
194427
- * @param {DidVerificationMethod} params.verificationMethod The verificationMethod object to be used for signing
194428
- * @returns {BTCR2SignedUpdate} Did update payload secured with a proof => BTCR2SignedUpdate
194429
- * @throws {MethodError} if the privateKeyBytes are invalid
193819
+ * @param {string} did The did-btcr2 identifier to derive the root capability from
193820
+ * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
193821
+ * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
193822
+ * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
193823
+ * @throws {UpdateError} if the privateKeyBytes are invalid
194430
193824
  */
194431
- static async invoke({
194432
- identifier,
194433
- unsignedUpdate,
194434
- verificationMethod
194435
- }) {
194436
- const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
194437
- if (!publicKeyMultibase) {
194438
- throw new MethodError2(
194439
- "Invalid publicKeyMultibase: cannot be undefined",
194440
- INVALID_PUBLIC_KEY_TYPE2,
194441
- verificationMethod
194442
- );
194443
- }
194444
- const id = fullId.slice(fullId.indexOf("#"));
194445
- const components = Identifier.decode(id);
194446
- const keyUri = new CompressedSecp256k1PublicKey2(components.genesisBytes).hex;
194447
- const keys = secretKeyMultibase ? new SchnorrKeyPair2({ secretKey: Secp256k1SecretKey2.decode(secretKeyMultibase) }) : Kms.getKey(keyUri);
194448
- if (!keys) {
194449
- throw new MethodError2(
194450
- "No privateKey found in kms or vm",
194451
- NOT_FOUND2,
194452
- verificationMethod
194453
- );
194454
- }
194455
- const multikey = SchnorrMultikey2.create({ id, controller, keys });
194456
- if (!multikey) {
194457
- throw new MethodError2(
194458
- "Failed to create multikey from verification method",
194459
- "MULTKEY_CREATE_FAILED",
194460
- verificationMethod
194461
- );
194462
- }
194463
- const rootCapability = Appendix.deriveRootCapability(identifier);
194464
- const cryptosuite = "bip340-jcs-2025";
193825
+ static async sign(did, unsignedUpdate, verificationMethod, secretKey) {
193826
+ const controller = verificationMethod.controller;
193827
+ const id = verificationMethod.id.slice(verificationMethod.id.indexOf("#"));
193828
+ const multikey = SchnorrMultikey2.fromSecretKey(id, controller, secretKey);
194465
193829
  const config = {
194466
193830
  "@context": [
194467
193831
  "https://w3id.org/security/v2",
@@ -194469,62 +193833,37 @@ var Update = class {
194469
193833
  "https://w3id.org/json-ld-patch/v1",
194470
193834
  "https://btcr2.dev/context/v1"
194471
193835
  ],
194472
- cryptosuite,
193836
+ cryptosuite: "bip340-jcs-2025",
194473
193837
  type: "DataIntegrityProof",
194474
- verificationMethod: fullId,
193838
+ verificationMethod: verificationMethod.id,
194475
193839
  proofPurpose: "capabilityInvocation",
194476
- capability: rootCapability.id,
193840
+ capability: `urn:zcap:root:${encodeURIComponent(did)}`,
194477
193841
  capabilityAction: "Write"
194478
193842
  };
194479
193843
  const diproof = multikey.toCryptosuite().toDataIntegrityProof();
194480
- return await diproof.addProof(unsignedUpdate, config);
193844
+ return diproof.addProof(unsignedUpdate, config);
194481
193845
  }
194482
193846
  /**
194483
- * Implements {@link https://dcdpr.github.io/did-btcr2/#announce-did-update | 4.3.3 Announce DID Update}.
194484
- *
194485
- * The Announce DID Update algorithm retrieves beaconServices from the sourceDocument and calls the Broadcast DID
194486
- * Update algorithm corresponding to the type of the Beacon. It takes in a Identifier, sourceDocument, an array of
194487
- * beaconIds, and a BTCR2SignedUpdate. It returns an array of signalsMetadata, containing the necessary
194488
- * data to validate the Beacon Signal against the BTCR2SignedUpdate.
194489
- *
194490
- * @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
194491
- * @param {DidDocument} params.sourceDocument The did-btcr2 did document to derive the root capability from
194492
- * @param {string[]} params.beaconIds The BTCR2SignedUpdate object to be signed
194493
- * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The verificationMethod object to be used for signing
194494
- * @returns {BTCR2SignedUpdate} The BTCR2SignedUpdate object containing data to validate the Beacon Signal
194495
- * @throws {MethodError} if the beaconService type is invalid
193847
+ * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
193848
+ * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
193849
+ * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
193850
+ * @param {SignedBTCR2Update} update The signed update object to be announced.
193851
+ * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
193852
+ * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
193853
+ * @throws {UpdateError} if the beaconService type is invalid
194496
193854
  */
194497
- static async announce({
194498
- sourceDocument,
194499
- beaconIds,
194500
- signedUpdate
194501
- }) {
194502
- const beaconServices = [];
194503
- let sidecarData;
194504
- for (const beaconId of beaconIds) {
194505
- const beaconService = sourceDocument.service.find((s2) => s2.id === beaconId);
194506
- if (!beaconService) {
194507
- throw new MethodError2("Not found: sourceDocument does not contain beaconId", INVALID_DID_DOCUMENT2, { beaconId });
194508
- }
194509
- beaconServices.push(beaconService);
194510
- }
194511
- for (const beaconService of beaconServices) {
194512
- console.log("TODO: refactor this code", signedUpdate, beaconService);
194513
- }
194514
- if (!sidecarData) {
194515
- throw new MethodError2(
194516
- "Invalid beacon: no sidecarData found",
194517
- INVALID_DID_DOCUMENT2,
194518
- { beaconServices }
194519
- );
194520
- }
194521
- return sidecarData;
193855
+ static async announce(beaconService, update, secretKey, bitcoin32) {
193856
+ const beacon = BeaconFactory.establish(beaconService);
193857
+ const result = await beacon.broadcastSignal(update, secretKey, bitcoin32);
193858
+ return result;
194522
193859
  }
194523
193860
  };
194524
193861
  var canonicalization22 = new Canonicalization2();
194525
193862
  initEccLib2(tinysecp32);
194526
193863
  var DidBtcr2 = class {
194527
- /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
193864
+ /**
193865
+ * Name of the DID method, as defined in the DID BTCR2 specification
193866
+ */
194528
193867
  static methodName = "btcr2";
194529
193868
  /**
194530
193869
  * Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
@@ -194549,7 +193888,7 @@ var DidBtcr2 = class {
194549
193888
  return Identifier.encode({ idType, genesisBytes, version: version3, network });
194550
193889
  }
194551
193890
  /**
194552
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Resolve}.
193891
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
194553
193892
  * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
194554
193893
  * See {@link Resolve | Resolve (class)} for class implementation.
194555
193894
  *
@@ -194558,14 +193897,10 @@ var DidBtcr2 = class {
194558
193897
  * blockchain by Authorized Beacon Signals. The Initial DID Document is either
194559
193898
  * deterministically created from the DID or provided by Sidecar Data.
194560
193899
  *
194561
- * @param {string} did a valid did:btcr2 identifier to be resolved
194562
- * @param {ResolutionOptions} resolutionOptions see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | ResolutionOptions}
194563
- * @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
194564
- * @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
194565
- * @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
193900
+ * @param {string} did The did:btcr2 identifier to be resolved.
193901
+ * @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
194566
193902
  * @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
194567
- * @throws {Error} if the resolution fails for any reason
194568
- * @throws {DidError} InvalidDid if the identifier is invalid
193903
+ * @throws {ResolveError} If the resolution process fails at any step.
194569
193904
  * @example
194570
193905
  * ```ts
194571
193906
  * const resolution = await DidBtcr2.resolve(
@@ -194587,8 +193922,9 @@ var DidBtcr2 = class {
194587
193922
  didDocument: null
194588
193923
  };
194589
193924
  const didComponents = Identifier.decode(did);
194590
- const sidecarData = Resolve.processSidecarData(resolutionOptions.sidecar);
194591
- if (!resolutionOptions.drivers.bitcoin) {
193925
+ const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
193926
+ if (!resolutionOptions?.drivers?.bitcoin) {
193927
+ resolutionOptions.drivers = resolutionOptions.drivers || {};
194592
193928
  resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection2();
194593
193929
  resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
194594
193930
  }
@@ -194601,20 +193937,21 @@ var DidBtcr2 = class {
194601
193937
  { resolutionOptions }
194602
193938
  );
194603
193939
  }
194604
- const currentDocument = await Resolve.establishCurrentDocument(didComponents, genesisDocument);
193940
+ const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
194605
193941
  const beaconServices = currentDocument.service.filter(BeaconUtils.isBeaconService).map(BeaconUtils.parseBeaconServiceEndpoint);
194606
- const unsortedUpdates = await Resolve.processBeaconSignals(
193942
+ console.log("beaconServices", beaconServices);
193943
+ const unsortedUpdates = await Resolve.beaconSignals(
194607
193944
  beaconServices,
194608
193945
  sidecarData,
194609
- resolutionOptions.drivers.bitcoin,
194610
- resolutionOptions.fullBlockchainTraversal
193946
+ resolutionOptions.drivers.bitcoin
194611
193947
  );
193948
+ console.log("unsortedUpdates", unsortedUpdates);
194612
193949
  if (!unsortedUpdates.length) {
194613
193950
  didResolutionResult.didDocument = currentDocument;
194614
193951
  didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
194615
193952
  return didResolutionResult;
194616
193953
  }
194617
- const result = await Resolve.processUpdatesArray(
193954
+ const result = await Resolve.updates(
194618
193955
  currentDocument,
194619
193956
  unsortedUpdates,
194620
193957
  resolutionOptions.versionTime,
@@ -194638,68 +193975,90 @@ var DidBtcr2 = class {
194638
193975
  }
194639
193976
  }
194640
193977
  /**
194641
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
194642
- * See {@link Update} for implementation details.
194643
- *
194644
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
194645
- * verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
194646
- * invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
194647
- * cryptosuite with a proofPurpose of capabilityInvocation.
194648
- *
194649
- * The Update algorithm takes as inputs a Identifier, sourceDocument, sourceVersionId, documentPatch, a
194650
- * verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
194651
- * documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
194652
- * The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
194653
- * verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
194654
- * identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
194655
- * Types SingletonBeacon, CASBeacon, and SMTBeacon.
194656
- *
194657
- * @param {UpdateParams} params Required parameters for the update operation.
194658
- * @param {string} params.identifier The btcr2 identifier to be updated.
194659
- * @param {DidDocument} params.sourceDocument The DID document being updated.
194660
- * @param {string} params.sourceVersionId The versionId of the source document.
194661
- * @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
194662
- * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
194663
- * @param {string[]} params.beaconIds The beacon IDs to announce the update
194664
- * @returns {Promise<void>} Promise resolving to void
194665
- * @throws {MethodError} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
194666
- */
194667
- static async update(params) {
194668
- const {
194669
- identifier,
194670
- sourceDocument,
194671
- sourceVersionId,
194672
- patch,
194673
- verificationMethodId: methodId,
194674
- beaconIds
194675
- } = params;
194676
- const unsignedUpdate = await Update.construct({
194677
- identifier,
194678
- sourceDocument,
194679
- sourceVersionId,
194680
- patch
194681
- });
194682
- const verificationMethod = this.getSigningMethod(sourceDocument, methodId);
193978
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
193979
+ * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
193980
+ * See {@link Update | Update (class)} for class implementation.
193981
+ *
193982
+ * BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
193983
+ * published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
193984
+ * invalidate the DID document.
193985
+ * @param params An object containing the parameters for the update operation.
193986
+ * @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
193987
+ * @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
193988
+ * @param {string} params.sourceVersionId The version ID before applying the update.
193989
+ * @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
193990
+ * @param {string} params.beaconId The beacon ID associated with the update.
193991
+ * @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
193992
+ * @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
193993
+ * @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
193994
+ * @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
193995
+ * header is not `zQ3s`
193996
+ */
193997
+ static async update({
193998
+ sourceDocument,
193999
+ patches,
194000
+ sourceVersionId,
194001
+ verificationMethodId,
194002
+ beaconId,
194003
+ signingMaterial,
194004
+ bitcoin: bitcoin32
194005
+ }) {
194006
+ if (!signingMaterial) {
194007
+ throw new UpdateError(
194008
+ "Missing signing material for update",
194009
+ INVALID_DID_UPDATE2,
194010
+ { signingMaterial }
194011
+ );
194012
+ }
194013
+ const secretKey = typeof signingMaterial === "string" ? import_buffer2.Buffer.from(signingMaterial, "hex") : signingMaterial;
194014
+ if (!sourceDocument.capabilityInvocation?.some((vr) => vr === verificationMethodId)) {
194015
+ throw new UpdateError(
194016
+ "Invalid verificationMethodId: not authorized for capabilityInvocation",
194017
+ INVALID_DID_DOCUMENT2,
194018
+ sourceDocument
194019
+ );
194020
+ }
194021
+ const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
194683
194022
  if (!verificationMethod) {
194684
- throw new MethodError2("Verification method not found in did document", INVALID_DID_DOCUMENT2, sourceDocument);
194023
+ throw new UpdateError(
194024
+ "Invalid verificationMethod: not found in source document",
194025
+ INVALID_DID_DOCUMENT2,
194026
+ { sourceDocument, verificationMethodId }
194027
+ );
194685
194028
  }
194686
194029
  if (verificationMethod.type !== "Multikey") {
194687
- throw new MethodError2('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT2, verificationMethod);
194030
+ throw new UpdateError(
194031
+ 'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
194032
+ INVALID_DID_DOCUMENT2,
194033
+ verificationMethod
194034
+ );
194688
194035
  }
194689
- const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
194690
- if (mbasePrefix !== "zQ3s") {
194691
- throw new MethodError2(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT2, verificationMethod);
194036
+ if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== "zQ3s") {
194037
+ throw new UpdateError(
194038
+ 'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
194039
+ INVALID_DID_DOCUMENT2,
194040
+ verificationMethod
194041
+ );
194692
194042
  }
194693
- const signedUpdate = await Update.invoke({ identifier, verificationMethod, unsignedUpdate });
194694
- const signalsMetadata = await Update.announce({ sourceDocument, beaconIds, signedUpdate });
194695
- return signalsMetadata;
194043
+ const update = await Update.construct(sourceDocument, patches, sourceVersionId);
194044
+ const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
194045
+ const beaconService = sourceDocument.service.filter((service) => service.id === beaconId).filter((service) => !!service).shift();
194046
+ if (!beaconService) {
194047
+ throw new UpdateError(
194048
+ "No beacon service found for provided beaconId",
194049
+ INVALID_DID_UPDATE2,
194050
+ { sourceDocument, beaconId }
194051
+ );
194052
+ }
194053
+ bitcoin32 ??= new BitcoinNetworkConnection2();
194054
+ return signed;
194696
194055
  }
194697
194056
  /**
194698
194057
  * Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
194699
194058
  * for signing messages and credentials. If given, the `methodId` parameter is used to select the
194700
194059
  * verification method. If not given, the Identity Key's verification method with an ID fragment
194701
194060
  * of '#initialKey' is used.
194702
- * @param {DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
194061
+ * @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
194703
194062
  * @param {string} [methodId] Optional verification method ID to be used for signing.
194704
194063
  * @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
194705
194064
  * @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
@@ -194722,43 +194081,25 @@ var DidBtcr2 = class {
194722
194081
  return verificationMethod;
194723
194082
  }
194724
194083
  };
194725
- var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
194084
+ var SingletonBeacon = class extends Beacon {
194726
194085
  /**
194727
194086
  * Creates an instance of SingletonBeacon.
194728
- * @param {BeaconService} service The Beacon service.
194729
- * @param {?BeaconSidecarData} sidecar The SingletonBeacon sidecar data.
194730
- */
194731
- constructor(service, signals, sidecar, bitcoin32) {
194732
- super({ ...service, type: "SingletonBeacon" }, signals, sidecar, bitcoin32);
194733
- }
194734
- /**
194735
- * Static, convenience method for establishing a CASBeacon object.
194736
- * @param {string} service The Beacon service.
194737
- * @param {SidecarData} sidecar The sidecar data.
194738
- * @returns {SingletonBeacon} The Singleton Beacon.
194739
- */
194740
- static establish(service, signals, sidecar) {
194741
- return new _SingletonBeacon(service, signals, sidecar);
194742
- }
194743
- /**
194744
- * Generates a Beacon Signal for a Singleton Beacon Service.
194745
- * @param {HexString} updateHash The update hash to be included in the Beacon Signal.
194746
- * @returns {BeaconSignal} The generated signal.
194747
- * @throws {MethodError} if the signal is invalid.
194087
+ * @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
194088
+ *
194748
194089
  */
194749
- generateSignal(updateHash) {
194750
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
194090
+ constructor(service) {
194091
+ super({ ...service, type: "SingletonBeacon" });
194751
194092
  }
194752
194093
  /**
194753
194094
  * Processes an array of Beacon Signals associated with a Singleton Beacon Service.
194754
- * @returns {Promise<BTCR2SignedUpdate | undefined>} The DID Update payload announced by the Beacon Signal.
194095
+ * @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
194755
194096
  * @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
194756
194097
  */
194757
- async processSignals() {
194098
+ async processSignals(signals, sidecar) {
194758
194099
  const updates = new Array();
194759
- for (const signal of this.signals || []) {
194100
+ for (const signal of signals) {
194760
194101
  const updateHash = signal.signalBytes;
194761
- const signedUpdate = this.sidecar.updateMap.get(updateHash);
194102
+ const signedUpdate = sidecar.updateMap.get(updateHash);
194762
194103
  if (!signedUpdate) {
194763
194104
  throw new SingletonBeaconError(
194764
194105
  `BTCR2 Signed Update not found for update hash ${updateHash}.`,
@@ -194780,19 +194121,26 @@ var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
194780
194121
  return updates;
194781
194122
  }
194782
194123
  /**
194783
- * Broadcasts a SingletonBeacon signal.
194784
- * TODO: Design and implement a way to construct, sign and send via RPC
194785
- *
194786
- * @returns {SignedRawTx} Successful output of a bitcoin transaction.
194124
+ * Broadcasts a SingletonBeacon signal to the Bitcoin network.
194125
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
194126
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
194127
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
194128
+ * @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
194787
194129
  * @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
194788
194130
  */
194789
- async broadcastSignal(updateHash) {
194131
+ async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
194790
194132
  const bitcoinAddress = this.service.serviceEndpoint.replace("bitcoin:", "");
194791
- const utxos = await this.bitcoin.network.rest.address.getUtxos(bitcoinAddress);
194133
+ const utxos = await bitcoin32.network.rest.address.getUtxos(bitcoinAddress);
194792
194134
  if (!utxos.length) {
194793
- throw new SingletonBeaconError("No UTXOs found, please fund address!", "UNFUNDED_BEACON_ADDRESS", { bitcoinAddress });
194135
+ throw new SingletonBeaconError(
194136
+ "No UTXOs found, please fund address!",
194137
+ "UNFUNDED_BEACON_ADDRESS",
194138
+ { bitcoinAddress }
194139
+ );
194794
194140
  }
194795
- const utxo = utxos.sort((a3, b22) => b22.status.block_height - a3.status.block_height)[0];
194141
+ const utxo = utxos.sort(
194142
+ (a3, b22) => b22.status.block_height - a3.status.block_height
194143
+ ).shift();
194796
194144
  if (!utxo) {
194797
194145
  throw new SingletonBeaconError(
194798
194146
  "Beacon bitcoin address unfunded or utxos unconfirmed.",
@@ -194800,99 +194148,69 @@ var SingletonBeacon = class _SingletonBeacon extends AggregateBeacon {
194800
194148
  { bitcoinAddress }
194801
194149
  );
194802
194150
  }
194803
- const udpateHashBytes = import_buffer2.Buffer.from(updateHash, "hex");
194804
- if (udpateHashBytes.length !== 32) {
194805
- throw new SingletonBeaconError("Hash must be 32 bytes");
194806
- }
194807
- const { txid, vout } = utxo;
194808
- const prevTx = await this.bitcoin.network.rest.transaction.getHex(txid);
194809
- const input = {
194810
- hash: txid,
194811
- index: vout,
194151
+ const prevTx = await bitcoin32.network.rest.transaction.getHex(utxo.txid);
194152
+ const updateHash = canonicalization22.canonicalhash(signedUpdate);
194153
+ const spendTx = new Psbt22({ network: bitcoin32.network.data }).addInput({
194154
+ hash: utxo.txid,
194155
+ index: utxo.vout,
194812
194156
  nonWitnessUtxo: import_buffer2.Buffer.from(prevTx, "hex")
194813
- };
194814
- const spendTx = new Psbt22({ network: this.bitcoin.network.data }).addInput(input).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports2.compile([OPS9.OP_RETURN, udpateHashBytes]), value: 0n });
194815
- const components = Identifier.decode(this.service.id);
194816
- const keyUri = new CompressedSecp256k1PublicKey2(components.genesisBytes).hex;
194817
- const keyPair = Kms.getKey(keyUri);
194157
+ }).addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) }).addOutput({ script: script_exports2.compile([OPS9.OP_RETURN, updateHash]), value: 0n });
194158
+ const keyPair = SchnorrKeyPair2.fromSecret(secretKey);
194818
194159
  if (!keyPair) {
194819
- throw new Error("Key pair not found.");
194160
+ throw new SingletonBeaconError("Key pair not found.", "KEY_PAIR_NOT_FOUND", { secretKey });
194820
194161
  }
194821
- const signer = new Signer({ keyPair, network: this.bitcoin.network.name });
194162
+ const signer = new Signer({ keyPair, network: bitcoin32.network.name });
194822
194163
  const signedTx = spendTx.signInput(0, signer).finalizeAllInputs().extractTransaction().toHex();
194823
- if (!spendTx) {
194824
- throw new SingletonBeaconError("Failed to sign raw transaction.", "RAW_TX_SIGN_FAILED", { spendTx });
194825
- }
194826
- const spentTx = await this.bitcoin.network.rest.transaction.send(signedTx);
194827
- if (!spentTx) {
194828
- throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
194829
- }
194830
- return spentTx;
194164
+ const txid = await bitcoin32.network.rest.transaction.send(signedTx);
194165
+ console.info(`Broadcasted Singleton Beacon signal with txid ${txid}`);
194166
+ return signedUpdate;
194831
194167
  }
194832
194168
  };
194833
194169
  init_shim2();
194834
- var SMTBeacon = class _SMTBeacon extends AggregateBeacon {
194170
+ var SMTBeacon = class extends Beacon {
194835
194171
  /**
194836
- * Creates an instance of SingletonBeacon.
194172
+ * Creates an instance of SMTBeacon.
194837
194173
  * @param {BeaconService} service The Beacon service.
194838
- * @param {Array<BeaconSignal>} signals The SingletonBeacon sidecar data.
194839
- * @param {SidecarData} sidecar The sidecar data.
194840
- */
194841
- constructor(service, signals, sidecar, bitcoin32) {
194842
- super({ ...service, type: "SMTBeacon" }, signals, sidecar, bitcoin32);
194843
- }
194844
- /**
194845
- * Static, convenience method for establishing a SMTBeacon object.
194846
- * @param {string} service The Beacon service.
194847
- * @param {SidecarData} sidecar The sidecar data.
194848
- * @returns {SingletonBeacon} The Singleton Beacon.
194849
194174
  */
194850
- static establish(service, signals, sidecar) {
194851
- return new _SMTBeacon(service, signals, sidecar);
194175
+ constructor(service) {
194176
+ super({ ...service, type: "SMTBeacon" });
194852
194177
  }
194853
194178
  /**
194854
- * TODO: Figure out if this is necessary or not.
194855
- * @param {HexString} updateHash The hash of the BTCR2 update to generate the signal for.
194856
- * @returns {BeaconSignal} The generated signal.
194857
- * @throws {MethodError} if the signal is invalid.
194179
+ * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
194180
+ * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
194181
+ * @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
194182
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
194183
+ * @throws {SMTBeaconError} if processing fails.
194858
194184
  */
194859
- generateSignal(updateHash) {
194860
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
194185
+ processSignals(signals, sidecar) {
194186
+ throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
194861
194187
  }
194862
194188
  /**
194863
- * Process SMTBeacon signals.
194864
- * @returns {Promise<Array<BTCR2SignedUpdate>>} The processed signed update or undefined.
194865
- * @throws {MethodError} if the signal processing fails.
194189
+ * Broadcast CAS Beacon signal to the Bitcoin network.
194190
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
194191
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
194192
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
194193
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
194194
+ * @throws {SMTBeaconError} if broadcasting fails.
194866
194195
  */
194867
- async processSignals() {
194868
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`);
194869
- }
194870
- /**
194871
- * Broadcast a SMTBeacon signal.
194872
- * @param {HexString} updateHash The hash of the BTCR2 update to broadcast.
194873
- * @returns {Promise<SignalsMetadata>} The result of the broadcast.
194874
- * @throws {MethodError} if the broadcast fails.
194875
- */
194876
- async broadcastSignal(updateHash) {
194877
- throw new MethodError2("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { updateHash });
194196
+ async broadcastSignal(signedUpdate, secretKey, bitcoin32) {
194197
+ throw new SMTBeaconError("Method not implemented.", `METHOD_NOT_IMPLEMENTED`, { signedUpdate, secretKey, bitcoin: bitcoin32 });
194878
194198
  }
194879
194199
  };
194880
194200
  var BeaconFactory = class {
194881
194201
  /**
194882
194202
  * Establish a Beacon instance based on the provided service and optional sidecar data.
194883
- * @param {BeaconService} service - The beacon service configuration.
194884
- * @param {Array<BeaconSignal>} signals - The array of beacon signals.
194885
- * @param {SidecarData} sidecar - The sidecar data associated with the beacon.
194203
+ * @param {BeaconService} service The beacon service configuration.
194886
194204
  * @returns {Beacon} The established Beacon instance.
194887
194205
  */
194888
- static establish(service, signals, sidecar) {
194206
+ static establish(service) {
194889
194207
  switch (service.type) {
194890
194208
  case "SingletonBeacon":
194891
- return new SingletonBeacon(service, signals, sidecar);
194209
+ return new SingletonBeacon(service);
194892
194210
  case "CASBeacon":
194893
- return new CASBeacon(service, signals, sidecar);
194211
+ return new CASBeacon(service);
194894
194212
  case "SMTBeacon":
194895
- return new SMTBeacon(service, signals, sidecar);
194213
+ return new SMTBeacon(service);
194896
194214
  default:
194897
194215
  throw new MethodError2("Invalid Beacon Type", "INVALID_BEACON_ERROR", service);
194898
194216
  }
@@ -194901,6 +194219,7 @@ var BeaconFactory = class {
194901
194219
  init_shim2();
194902
194220
  init_shim2();
194903
194221
  init_shim2();
194222
+ init_shim2();
194904
194223
  var DidDocumentBuilder = class {
194905
194224
  document = {};
194906
194225
  constructor(initialDocument) {
@@ -197106,22 +196425,23 @@ var DidApi = class {
197106
196425
  * This delegates to MethodUpdate (which follows the cryptosuite rules internally).
197107
196426
  */
197108
196427
  async update({
197109
- identifier,
197110
196428
  sourceDocument,
196429
+ patches,
197111
196430
  sourceVersionId,
197112
- patch,
197113
196431
  verificationMethodId,
197114
- beaconIds
196432
+ beaconId,
196433
+ signingMaterial,
196434
+ bitcoin: bitcoin4
197115
196435
  }) {
197116
- const result = await DidBtcr2.update({
197117
- identifier,
196436
+ return await DidBtcr2.update({
197118
196437
  sourceDocument,
196438
+ patches,
197119
196439
  sourceVersionId,
197120
- patch,
197121
196440
  verificationMethodId,
197122
- beaconIds
196441
+ beaconId,
196442
+ signingMaterial,
196443
+ bitcoin: bitcoin4
197123
196444
  });
197124
- return result;
197125
196445
  }
197126
196446
  /** Deactivate convenience: applies the standard `deactivated: true` patch. */
197127
196447
  async deactivate() {
@@ -197341,9 +196661,6 @@ fast-json-patch/module/duplex.mjs:
197341
196661
  @scure/bip39/esm/index.js:
197342
196662
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
197343
196663
 
197344
- @noble/hashes/utils.js:
197345
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
197346
-
197347
196664
  @noble/hashes/esm/utils.js:
197348
196665
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
197349
196666