@did-btcr2/method 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/browser.js +314 -312
  2. package/dist/browser.mjs +314 -312
  3. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +4 -4
  4. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +1 -1
  5. package/dist/cjs/core/beacon/cid-aggregate.js +2 -2
  6. package/dist/cjs/core/beacon/singleton.js +2 -2
  7. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  8. package/dist/cjs/core/crud/deactivate.js +4 -4
  9. package/dist/cjs/core/crud/deactivate.js.map +1 -1
  10. package/dist/cjs/core/crud/read.js +20 -20
  11. package/dist/cjs/core/crud/read.js.map +1 -1
  12. package/dist/cjs/core/crud/update.js +2 -2
  13. package/dist/cjs/core/crud/update.js.map +1 -1
  14. package/dist/cjs/core/key-manager/index.js +5 -5
  15. package/dist/cjs/core/key-manager/index.js.map +1 -1
  16. package/dist/cjs/did-btcr2.js +8 -20
  17. package/dist/cjs/did-btcr2.js.map +1 -1
  18. package/dist/cjs/index.js +0 -1
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/cjs/utils/appendix.js +4 -4
  21. package/dist/cjs/utils/appendix.js.map +1 -1
  22. package/dist/cjs/utils/did-document-builder.js +1 -1
  23. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  24. package/dist/cjs/utils/did-document.js +62 -14
  25. package/dist/cjs/utils/did-document.js.map +1 -1
  26. package/dist/cjs/utils/identifier.js +5 -5
  27. package/dist/cjs/utils/identifier.js.map +1 -1
  28. package/dist/esm/core/beacon/aggregation/protocol/nostr.js +4 -4
  29. package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +1 -1
  30. package/dist/esm/core/beacon/cid-aggregate.js +2 -2
  31. package/dist/esm/core/beacon/singleton.js +2 -2
  32. package/dist/esm/core/beacon/singleton.js.map +1 -1
  33. package/dist/esm/core/crud/deactivate.js +4 -4
  34. package/dist/esm/core/crud/deactivate.js.map +1 -1
  35. package/dist/esm/core/crud/read.js +20 -20
  36. package/dist/esm/core/crud/read.js.map +1 -1
  37. package/dist/esm/core/crud/update.js +2 -2
  38. package/dist/esm/core/crud/update.js.map +1 -1
  39. package/dist/esm/core/key-manager/index.js +5 -5
  40. package/dist/esm/core/key-manager/index.js.map +1 -1
  41. package/dist/esm/did-btcr2.js +8 -20
  42. package/dist/esm/did-btcr2.js.map +1 -1
  43. package/dist/esm/index.js +0 -1
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/utils/appendix.js +4 -4
  46. package/dist/esm/utils/appendix.js.map +1 -1
  47. package/dist/esm/utils/did-document-builder.js +1 -1
  48. package/dist/esm/utils/did-document-builder.js.map +1 -1
  49. package/dist/esm/utils/did-document.js +62 -14
  50. package/dist/esm/utils/did-document.js.map +1 -1
  51. package/dist/esm/utils/identifier.js +5 -5
  52. package/dist/esm/utils/identifier.js.map +1 -1
  53. package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +1 -1
  54. package/dist/types/core/beacon/cid-aggregate.d.ts +2 -2
  55. package/dist/types/core/crud/deactivate.d.ts +4 -4
  56. package/dist/types/core/crud/deactivate.d.ts.map +1 -1
  57. package/dist/types/core/crud/read.d.ts +4 -4
  58. package/dist/types/core/crud/read.d.ts.map +1 -1
  59. package/dist/types/core/crud/update.d.ts +10 -0
  60. package/dist/types/core/crud/update.d.ts.map +1 -1
  61. package/dist/types/core/key-manager/index.d.ts +6 -6
  62. package/dist/types/core/key-manager/index.d.ts.map +1 -1
  63. package/dist/types/core/key-manager/interface.d.ts +3 -3
  64. package/dist/types/core/key-manager/interface.d.ts.map +1 -1
  65. package/dist/types/did-btcr2.d.ts +15 -5
  66. package/dist/types/did-btcr2.d.ts.map +1 -1
  67. package/dist/types/index.d.ts +0 -1
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/interfaces/crud.d.ts +1 -4
  70. package/dist/types/interfaces/crud.d.ts.map +1 -1
  71. package/dist/types/types/crud.d.ts +5 -5
  72. package/dist/types/types/crud.d.ts.map +1 -1
  73. package/dist/types/utils/appendix.d.ts +7 -7
  74. package/dist/types/utils/appendix.d.ts.map +1 -1
  75. package/dist/types/utils/did-document-builder.d.ts +1 -1
  76. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  77. package/dist/types/utils/did-document.d.ts +26 -11
  78. package/dist/types/utils/did-document.d.ts.map +1 -1
  79. package/dist/types/utils/identifier.d.ts +2 -2
  80. package/dist/types/utils/identifier.d.ts.map +1 -1
  81. package/package.json +7 -6
  82. package/src/core/beacon/aggregation/protocol/nostr.ts +4 -4
  83. package/src/core/beacon/cid-aggregate.ts +2 -2
  84. package/src/core/beacon/singleton.ts +2 -2
  85. package/src/core/crud/deactivate.ts +4 -4
  86. package/src/core/crud/read.ts +21 -21
  87. package/src/core/crud/update.ts +14 -2
  88. package/src/core/key-manager/index.ts +7 -7
  89. package/src/core/key-manager/interface.ts +3 -3
  90. package/src/did-btcr2.ts +24 -25
  91. package/src/index.ts +0 -1
  92. package/src/interfaces/crud.ts +1 -4
  93. package/src/types/crud.ts +5 -5
  94. package/src/utils/appendix.ts +9 -9
  95. package/src/utils/did-document-builder.ts +1 -1
  96. package/src/utils/did-document.ts +73 -17
  97. package/src/utils/identifier.ts +5 -5
  98. package/dist/cjs/core/crud/create.js +0 -102
  99. package/dist/cjs/core/crud/create.js.map +0 -1
  100. package/dist/esm/core/crud/create.js +0 -102
  101. package/dist/esm/core/crud/create.js.map +0 -1
  102. package/dist/types/core/crud/create.d.ts +0 -92
  103. package/dist/types/core/crud/create.d.ts.map +0 -1
  104. package/src/core/crud/create.ts +0 -160
package/dist/browser.js CHANGED
@@ -7362,7 +7362,7 @@ var BTCR2 = (() => {
7362
7362
  return false;
7363
7363
  }
7364
7364
  }
7365
- function isPoint3(p3) {
7365
+ function isPoint4(p3) {
7366
7366
  return _isPoint(p3, false);
7367
7367
  }
7368
7368
  function isPointCompressed(p3) {
@@ -7389,7 +7389,7 @@ var BTCR2 = (() => {
7389
7389
  });
7390
7390
  }
7391
7391
  function xOnlyPointFromPoint(p3) {
7392
- if (!isPoint3(p3)) {
7392
+ if (!isPoint4(p3)) {
7393
7393
  throw new Error(THROW_BAD_POINT);
7394
7394
  }
7395
7395
  return p3.slice(1, 33);
@@ -7409,13 +7409,13 @@ var BTCR2 = (() => {
7409
7409
  return xOnlyPointFromPoint(pointFromScalar2(d2));
7410
7410
  }
7411
7411
  function pointCompress(p3, compressed) {
7412
- if (!isPoint3(p3)) {
7412
+ if (!isPoint4(p3)) {
7413
7413
  throw new Error(THROW_BAD_POINT);
7414
7414
  }
7415
7415
  return fromHex2(p3).toRawBytes(assumeCompression(compressed, p3));
7416
7416
  }
7417
7417
  function pointMultiply(a3, tweak, compressed) {
7418
- if (!isPoint3(a3)) {
7418
+ if (!isPoint4(a3)) {
7419
7419
  throw new Error(THROW_BAD_POINT);
7420
7420
  }
7421
7421
  if (!isTweak(tweak)) {
@@ -7426,7 +7426,7 @@ var BTCR2 = (() => {
7426
7426
  );
7427
7427
  }
7428
7428
  function pointAdd2(a3, b2, compressed) {
7429
- if (!isPoint3(a3) || !isPoint3(b2)) {
7429
+ if (!isPoint4(a3) || !isPoint4(b2)) {
7430
7430
  throw new Error(THROW_BAD_POINT);
7431
7431
  }
7432
7432
  return throwToNull(() => {
@@ -7440,7 +7440,7 @@ var BTCR2 = (() => {
7440
7440
  });
7441
7441
  }
7442
7442
  function pointAddScalar(p3, tweak, compressed) {
7443
- if (!isPoint3(p3)) {
7443
+ if (!isPoint4(p3)) {
7444
7444
  throw new Error(THROW_BAD_POINT);
7445
7445
  }
7446
7446
  if (!isTweak(tweak)) {
@@ -7534,7 +7534,7 @@ var BTCR2 = (() => {
7534
7534
  return Q.toRawBytes(assumeCompression(compressed));
7535
7535
  }
7536
7536
  function verify(h2, Q, signature2, strict) {
7537
- if (!isPoint3(Q)) {
7537
+ if (!isPoint4(Q)) {
7538
7538
  throw new Error(THROW_BAD_POINT);
7539
7539
  }
7540
7540
  if (!isSignature(signature2)) {
@@ -7557,7 +7557,7 @@ var BTCR2 = (() => {
7557
7557
  }
7558
7558
  return secp256k13.schnorr.verify(signature2, h2, Q);
7559
7559
  }
7560
- exports.isPoint = isPoint3;
7560
+ exports.isPoint = isPoint4;
7561
7561
  exports.isPointCompressed = isPointCompressed;
7562
7562
  exports.isPrivate = isPrivate3;
7563
7563
  exports.isXOnlyPoint = isXOnlyPoint;
@@ -30638,7 +30638,7 @@ var BTCR2 = (() => {
30638
30638
  EDDSA.prototype.decodeInt = function decodeInt(bytes3) {
30639
30639
  return utils3.intFromLE(bytes3);
30640
30640
  };
30641
- EDDSA.prototype.isPoint = function isPoint3(val) {
30641
+ EDDSA.prototype.isPoint = function isPoint4(val) {
30642
30642
  return val instanceof this.pointClass;
30643
30643
  };
30644
30644
  }
@@ -32250,13 +32250,13 @@ var BTCR2 = (() => {
32250
32250
  ).optional()
32251
32251
  );
32252
32252
  });
32253
- var PublicKey4 = asn1.define("SubjectPublicKeyInfo", function() {
32253
+ var PublicKey3 = asn1.define("SubjectPublicKeyInfo", function() {
32254
32254
  this.seq().obj(
32255
32255
  this.key("algorithm").use(AlgorithmIdentifier2),
32256
32256
  this.key("subjectPublicKey").bitstr()
32257
32257
  );
32258
32258
  });
32259
- exports.PublicKey = PublicKey4;
32259
+ exports.PublicKey = PublicKey3;
32260
32260
  var PrivateKeyInfo2 = asn1.define("PrivateKeyInfo", function() {
32261
32261
  this.seq().obj(
32262
32262
  this.key("version")["int"](),
@@ -45004,11 +45004,11 @@ var BTCR2 = (() => {
45004
45004
  };
45005
45005
  metadataRegistry.registerProvider(provider);
45006
45006
  return provider;
45007
- function GetOrCreateMetadataMap(O, P3, Create2) {
45007
+ function GetOrCreateMetadataMap(O, P3, Create) {
45008
45008
  var targetMetadata = metadata2.get(O);
45009
45009
  var createdTargetMetadata = false;
45010
45010
  if (IsUndefined(targetMetadata)) {
45011
- if (!Create2)
45011
+ if (!Create)
45012
45012
  return void 0;
45013
45013
  targetMetadata = new _Map();
45014
45014
  metadata2.set(O, targetMetadata);
@@ -45016,7 +45016,7 @@ var BTCR2 = (() => {
45016
45016
  }
45017
45017
  var metadataMap = targetMetadata.get(P3);
45018
45018
  if (IsUndefined(metadataMap)) {
45019
- if (!Create2)
45019
+ if (!Create)
45020
45020
  return void 0;
45021
45021
  metadataMap = new _Map();
45022
45022
  targetMetadata.set(P3, metadataMap);
@@ -45143,12 +45143,12 @@ var BTCR2 = (() => {
45143
45143
  };
45144
45144
  return provider;
45145
45145
  }
45146
- function GetMetadataProvider(O, P3, Create2) {
45146
+ function GetMetadataProvider(O, P3, Create) {
45147
45147
  var registeredProvider = metadataRegistry.getProvider(O, P3);
45148
45148
  if (!IsUndefined(registeredProvider)) {
45149
45149
  return registeredProvider;
45150
45150
  }
45151
- if (Create2) {
45151
+ if (Create) {
45152
45152
  if (metadataRegistry.setProvider(O, P3, metadataProvider)) {
45153
45153
  return metadataProvider;
45154
45154
  }
@@ -45987,17 +45987,17 @@ var BTCR2 = (() => {
45987
45987
  __export(index_exports, {
45988
45988
  Appendix: () => Appendix,
45989
45989
  BECH32M_CHARS: () => BECH32M_CHARS,
45990
- BTC1_DID_REGEX: () => BTC1_DID_REGEX,
45991
45990
  Beacon: () => Beacon,
45992
45991
  BeaconFactory: () => BeaconFactory,
45993
45992
  BeaconUtils: () => BeaconUtils,
45994
- Btc1Deactivate: () => Btc1Deactivate,
45995
- Btc1DidDocumentBuilder: () => Btc1DidDocumentBuilder,
45996
45993
  CIDAggregateBeacon: () => CIDAggregateBeacon,
45997
- Create: () => Create,
45994
+ DID_REGEX: () => DID_REGEX,
45995
+ Deactivate: () => Deactivate,
45998
45996
  DidBtcr2: () => DidBtcr2,
45999
45997
  DidDocument: () => DidDocument2,
45998
+ DidDocumentBuilder: () => DidDocumentBuilder,
46000
45999
  DidVerificationMethod: () => DidVerificationMethod,
46000
+ Document: () => Document,
46001
46001
  GeneralUtils: () => GeneralUtils,
46002
46002
  Identifier: () => Identifier,
46003
46003
  IntermediateDidDocument: () => IntermediateDidDocument,
@@ -48457,8 +48457,8 @@ var BTCR2 = (() => {
48457
48457
  *
48458
48458
  * The Broadcast CIDAggregate Beacon Signal algorithm involving two roles: a set of cohort participants and a Beacon
48459
48459
  * coordinator. The Beacon coordinator collects individual DID Update Payload Content Identifiers (CIDs) for specific
48460
- * did:btc1s and aggregates them into a DID Update Bundle, which is then published to a Content Addressable Storage
48461
- * (CAS). The CID for the DID Update Bundle is included in a Partially Signed Bitcoin Transaction (PSBT) transaction
48460
+ * did:btcr2 idntifiers and aggregates them into a DID Update Bundle, which is then published to a Content Addressable
48461
+ * Storage (CAS). The CID for the DID Update Bundle is included in a Partially Signed Bitcoin Transaction (PSBT) transaction
48462
48462
  * output spent from the Beacon’s n-of-n address. Each of the n cohort participants in the Beacon MUST sign the
48463
48463
  * transaction before it can be broadcast to the network. It is RECOMMENDED that cohort participants keep a copy of
48464
48464
  * the DID Update Bundle and separately pin it to the CAS.
@@ -48713,21 +48713,21 @@ var BTCR2 = (() => {
48713
48713
  var TXIN_WITNESS_COINBASE = "0000000000000000000000000000000000000000000000000000000000000000";
48714
48714
  var GENESIS_TX_ID = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
48715
48715
  var DEFAULT_BITCOIN_NETWORK_CONFIG = {
48716
- mainnet: {
48716
+ bitcoin: {
48717
48717
  rpc: void 0,
48718
- rest: { host: "https://mempool.space/api" }
48718
+ rest: { host: "https://mempool.holdings/api" }
48719
48719
  },
48720
48720
  testnet3: {
48721
48721
  rpc: void 0,
48722
- rest: { host: "https://mempool.space/testnet/api" }
48722
+ rest: { host: "https://mempool.holdings/testnet/api" }
48723
48723
  },
48724
48724
  testnet4: {
48725
48725
  rpc: void 0,
48726
- rest: { host: "https://mempool.space/testnet4/api" }
48726
+ rest: { host: "https://mempool.holdings/testnet4/api" }
48727
48727
  },
48728
48728
  signet: {
48729
48729
  rpc: void 0,
48730
- rest: { host: "https://mempool.space/signet/api" }
48730
+ rest: { host: "https://mempool.holdings/signet/api" }
48731
48731
  },
48732
48732
  mutinynet: {
48733
48733
  rpc: void 0,
@@ -48863,7 +48863,7 @@ var BTCR2 = (() => {
48863
48863
  allowDefaultWallet;
48864
48864
  constructor(options2 = {
48865
48865
  headers: {},
48866
- host: "localhost",
48866
+ host: "http://localhost",
48867
48867
  logger: console,
48868
48868
  password: "",
48869
48869
  timeout: 3e4,
@@ -48932,8 +48932,8 @@ var BTCR2 = (() => {
48932
48932
  u.password = "";
48933
48933
  this.url = u.toString().replace(/\/+$/, "");
48934
48934
  }
48935
- } catch {
48936
- console.error("Invalid URL in Bitcoin RPC config");
48935
+ } catch (error) {
48936
+ console.error(`Invalid URL in Bitcoin RPC config: ${this.url}`, error);
48937
48937
  }
48938
48938
  }
48939
48939
  }
@@ -57649,7 +57649,7 @@ var BTCR2 = (() => {
57649
57649
  // ../bitcoin/dist/esm/bitcoin.js
57650
57650
  var BitcoinNetworkConnection = class {
57651
57651
  network;
57652
- mainnet;
57652
+ bitcoin;
57653
57653
  testnet3;
57654
57654
  testnet4;
57655
57655
  signet;
@@ -57670,7 +57670,7 @@ var BTCR2 = (() => {
57670
57670
  throw new MethodError("Parsing failed: malformed BITCOIN_NETWORK_CONFIG", "MISSING_MALFORMED_BITCOIN_NETWORK_CONFIG", { BITCOIN_NETWORK_CONFIG });
57671
57671
  }
57672
57672
  const networkConfigs = JSON.parse(BITCOIN_NETWORK_CONFIG);
57673
- const networks2 = ["mainnet", "testnet3", "testnet4", "signet", "mutinynet", "regtest"];
57673
+ const networks2 = ["bitcoin", "testnet3", "testnet4", "signet", "mutinynet", "regtest"];
57674
57674
  for (const network of networks2) {
57675
57675
  const networkConfig = configs?.[network] ?? networkConfigs[network];
57676
57676
  if (networkConfig) {
@@ -57694,7 +57694,7 @@ var BTCR2 = (() => {
57694
57694
  }
57695
57695
  /**
57696
57696
  * Get the Bitcoin network configuration for a specific network.
57697
- * @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'mainnet', 'testnet3', 'signet', 'regtest').
57697
+ * @param {keyof AvailableNetworks} network - The Bitcoin network (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
57698
57698
  * @returns {Bitcoin} The Bitcoin object.
57699
57699
  */
57700
57700
  getNetworkConnection(network) {
@@ -57706,7 +57706,7 @@ var BTCR2 = (() => {
57706
57706
  }
57707
57707
  /**
57708
57708
  * Sets the active Bitcoin network.
57709
- * @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'mainnet', 'testnet3', 'signet', 'regtest').
57709
+ * @param {keyof AvailableNetworks} active - The Bitcoin network to set as active (e.g., 'bitcoin', 'testnet3', 'signet', 'regtest').
57710
57710
  * @throws {MethodError} If no configuration is found for the specified network.
57711
57711
  */
57712
57712
  setActiveNetwork(active) {
@@ -57740,7 +57740,7 @@ var BTCR2 = (() => {
57740
57740
 
57741
57741
  // ../bitcoin/dist/esm/taproot.js
57742
57742
  init_shim();
57743
- var tinysecp2 = __toESM(require_dist2(), 1);
57743
+ var tinysecp3 = __toESM(require_dist2(), 1);
57744
57744
 
57745
57745
  // ../keypair/dist/esm/index.js
57746
57746
  init_shim();
@@ -57750,12 +57750,13 @@ var BTCR2 = (() => {
57750
57750
 
57751
57751
  // ../keypair/dist/esm/public.js
57752
57752
  init_shim();
57753
+ var tinysecp2 = __toESM(require_dist2(), 1);
57753
57754
 
57754
57755
  // ../keypair/dist/esm/secret.js
57755
57756
  init_shim();
57756
57757
  var import_crypto3 = __toESM(require_crypto_browserify(), 1);
57757
57758
  var tinysecp = __toESM(require_dist2(), 1);
57758
- var SecretKey = class _SecretKey {
57759
+ var Secp256k1SecretKey = class _Secp256k1SecretKey {
57759
57760
  /** @type {KeyBytes} The entropy for the secret key as a byte array */
57760
57761
  _bytes;
57761
57762
  /** @type {bigint} The entropy for the secret key as a bigint */
@@ -57763,7 +57764,7 @@ var BTCR2 = (() => {
57763
57764
  /** @type {string} The secret key as a secretKeyMultibase */
57764
57765
  _multibase;
57765
57766
  /**
57766
- * Instantiates an instance of SecretKey.
57767
+ * Instantiates an instance of Secp256k1SecretKey.
57767
57768
  * @param {Entropy} entropy bytes (Uint8Array) or secret (bigint)
57768
57769
  * @throws {SecretKeyError} If entropy is not provided, not a valid 32-byte secret key or not a valid bigint seed
57769
57770
  */
@@ -57775,10 +57776,10 @@ var BTCR2 = (() => {
57775
57776
  }
57776
57777
  if (isBytes9 && entropy.length === 32) {
57777
57778
  this._bytes = entropy;
57778
- this._seed = _SecretKey.toSecret(entropy);
57779
+ this._seed = _Secp256k1SecretKey.toSecret(entropy);
57779
57780
  }
57780
57781
  if (isSecret && !(entropy < 1n || entropy >= CURVE.n)) {
57781
- this._bytes = _SecretKey.toBytes(entropy);
57782
+ this._bytes = _Secp256k1SecretKey.toBytes(entropy);
57782
57783
  this._seed = entropy;
57783
57784
  }
57784
57785
  if (!this._bytes || this._bytes.length !== 32) {
@@ -57835,7 +57836,7 @@ var BTCR2 = (() => {
57835
57836
  }
57836
57837
  /**
57837
57838
  * Checks if this secret key is equal to another.
57838
- * @param {SecretKey} other The other secret key
57839
+ * @param {Secp256k1SecretKey} other The other secret key
57839
57840
  * @returns {boolean} True if the private keys are equal, false otherwise
57840
57841
  */
57841
57842
  equals(other) {
@@ -57843,7 +57844,7 @@ var BTCR2 = (() => {
57843
57844
  }
57844
57845
  /**
57845
57846
  * Computes the public key from the secret key bytes.
57846
- * @returns {KeyBytes} The computed public key
57847
+ * @returns {CompressedSecp256k1PublicKey} The computed public key
57847
57848
  */
57848
57849
  computePublicKey() {
57849
57850
  const publicKeyBytes = tinysecp.pointFromScalar(this.bytes, true);
@@ -57853,7 +57854,7 @@ var BTCR2 = (() => {
57853
57854
  if (publicKeyBytes.length !== 33) {
57854
57855
  throw new SecretKeyError("Invalid compute: public key not compressed format", "COMPUTE_PUBLIC_KEY_ERROR");
57855
57856
  }
57856
- return publicKeyBytes;
57857
+ return new CompressedSecp256k1PublicKey(publicKeyBytes);
57857
57858
  }
57858
57859
  /**
57859
57860
  * Converts the secret key to a JSON object.
@@ -57875,10 +57876,10 @@ var BTCR2 = (() => {
57875
57876
  }
57876
57877
  /**
57877
57878
  * Checks if the public key is a valid secp256k1 point.
57878
- * @param {PublicKey} pk The public key to validate
57879
57879
  * @returns {boolean} True if the public key is valid, false otherwise
57880
57880
  */
57881
- isValidPair(pk) {
57881
+ hasValidPublicKey() {
57882
+ const pk = this.computePublicKey();
57882
57883
  if (!tinysecp.isPoint(pk.compressed)) {
57883
57884
  return false;
57884
57885
  }
@@ -57902,21 +57903,21 @@ var BTCR2 = (() => {
57902
57903
  return decoded;
57903
57904
  }
57904
57905
  /**
57905
- * Creates a SecretKey object from a JSON object.
57906
+ * Creates a Secp256k1SecretKey object from a JSON object.
57906
57907
  * @param {SecretKeyObject} json The JSON object containing the secret key bytes
57907
- * @returns {SecretKey} A new SecretKey object
57908
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
57908
57909
  */
57909
57910
  static fromJSON(json) {
57910
- return new _SecretKey(new Uint8Array(json.bytes));
57911
+ return new _Secp256k1SecretKey(new Uint8Array(json.bytes));
57911
57912
  }
57912
57913
  /**
57913
- * Converts a SecretKey or KeyBytes to a Pair.
57914
- * @param {KeyBytes} bytes
57914
+ * Converts a Secp256k1SecretKey or KeyBytes to a SchnorrKeyPair.
57915
+ * @param {KeyBytes} bytes The secret key bytes
57915
57916
  * @returns {SchnorrKeyPair} The SchnorrKeyPair object containing the public and private keys
57916
57917
  * @throws {SecretKeyError} If the secret key is not valid
57917
57918
  */
57918
57919
  static toKeyPair(bytes3) {
57919
- const secretKey = new _SecretKey(bytes3);
57920
+ const secretKey = new _Secp256k1SecretKey(bytes3);
57920
57921
  const publicKey2 = secretKey.computePublicKey();
57921
57922
  return new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
57922
57923
  }
@@ -57941,14 +57942,14 @@ var BTCR2 = (() => {
57941
57942
  return new Uint8Array(bytes3);
57942
57943
  }
57943
57944
  /**
57944
- * Creates a new SecretKey object from a bigint secret.
57945
- * @param {bigint} secret The secret bigint
57946
- * @returns {SecretKey} A new SecretKey object
57945
+ * Creates a new Secp256k1SecretKey object from a bigint secret.
57946
+ * @param {bigint} entropy The secret bigint
57947
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
57947
57948
  */
57948
- static fromSecret(secret) {
57949
- const hexsecret = secret.toString(16).padStart(64, "0");
57949
+ static fromEntropy(entropy) {
57950
+ const hexsecret = entropy.toString(16).padStart(64, "0");
57950
57951
  const privateKeyBytes = new Uint8Array(hexsecret.match(/.{2}/g).map((byte) => parseInt(byte, 16)));
57951
- return new _SecretKey(privateKeyBytes);
57952
+ return new _Secp256k1SecretKey(privateKeyBytes);
57952
57953
  }
57953
57954
  /**
57954
57955
  * Generates random secret key bytes.
@@ -57959,35 +57960,35 @@ var BTCR2 = (() => {
57959
57960
  return (0, import_crypto3.getRandomValues)(byteArray);
57960
57961
  }
57961
57962
  /**
57962
- * Creates a new SecretKey from random secret key bytes.
57963
- * @returns {SecretKey} A new SecretKey object
57963
+ * Creates a new Secp256k1SecretKey from random secret key bytes.
57964
+ * @returns {Secp256k1SecretKey} A new Secp256k1SecretKey object
57964
57965
  */
57965
57966
  static generate() {
57966
57967
  const randomBytes7 = this.random();
57967
- return new _SecretKey(randomBytes7);
57968
+ return new _Secp256k1SecretKey(randomBytes7);
57968
57969
  }
57969
57970
  /**
57970
57971
  * Generates a public key from the given secret key bytes.
57971
57972
  * @param {KeyBytes} bytes The secret key bytes
57972
- * @returns {KeyBytes} The computed public key bytes
57973
+ * @returns {CompressedSecp256k1PublicKey} The computed public key bytes
57973
57974
  */
57974
57975
  static getPublicKey(bytes3) {
57975
- return new _SecretKey(bytes3).computePublicKey();
57976
+ return new _Secp256k1SecretKey(bytes3).computePublicKey();
57976
57977
  }
57977
57978
  };
57978
57979
 
57979
57980
  // ../keypair/dist/esm/public.js
57980
- var PublicKey = class _PublicKey {
57981
+ var CompressedSecp256k1PublicKey = class _CompressedSecp256k1PublicKey {
57981
57982
  /** @type {KeyBytes} The public key bytes */
57982
57983
  _bytes;
57983
57984
  /** @type {MultibaseObject} The public key as a MultibaseObject */
57984
57985
  _multibase = {
57985
57986
  prefix: BIP340_PUBLIC_KEY_MULTIBASE_PREFIX,
57986
57987
  key: [],
57987
- address: ""
57988
+ encoded: ""
57988
57989
  };
57989
57990
  /**
57990
- * Creates a PublicKey instance.
57991
+ * Creates a CompressedSecp256k1PublicKey instance.
57991
57992
  * @param {KeyBytes} bytes The public key byte array.
57992
57993
  * @throws {PublicKeyError} if the byte length is not 32 (x-only) or 33 (compressed)
57993
57994
  */
@@ -57995,8 +57996,11 @@ var BTCR2 = (() => {
57995
57996
  if (bytes3.length !== 33) {
57996
57997
  throw new PublicKeyError("Invalid argument: byte length must be 33 (compressed)", "CONSTRUCTOR_ERROR", { bytes: bytes3 });
57997
57998
  }
57999
+ if (!tinysecp2.isPoint(bytes3)) {
58000
+ throw new PublicKeyError("Invalid argument: bytes are not a valid secp256k1 compressed point", "CONSTRUCTOR_ERROR", { bytes: bytes3 });
58001
+ }
57998
58002
  this._bytes = bytes3;
57999
- this._multibase.address = this.encode();
58003
+ this._multibase.encoded = this.encode();
58000
58004
  this._multibase.key = [...this._multibase.prefix, ...this.compressed];
58001
58005
  }
58002
58006
  /**
@@ -58016,13 +58020,30 @@ var BTCR2 = (() => {
58016
58020
  return uncompressed;
58017
58021
  }
58018
58022
  /**
58019
- * Get the parity byte of the public key.
58020
- * @returns {number} The parity byte of the public key.
58023
+ * X-only (32-byte) view of the public key per BIP-340.
58024
+ */
58025
+ get xOnly() {
58026
+ return this._bytes.slice(1);
58027
+ }
58028
+ /**
58029
+ * Parity of the SEC compressed public key.
58030
+ * @returns {0x02 | 0x03} The parity byte (0x02 if even, 0x03 if odd).
58031
+ * @throws {PublicKeyError} If the parity byte is not 0x02 or 0x03.
58021
58032
  */
58022
58033
  get parity() {
58023
- const parity = this.compressed[0];
58034
+ const parity = this._bytes[0];
58035
+ if (![2, 3].includes(parity)) {
58036
+ throw new PublicKeyError("Invalid state: parity byte must be 2 or 3", "PARITY_ERROR", { parity });
58037
+ }
58024
58038
  return parity;
58025
58039
  }
58040
+ /**
58041
+ * Whether the SEC compressed public key has even Y.
58042
+ * @returns {boolean} True if the public key has even Y.
58043
+ */
58044
+ get isEven() {
58045
+ return this._bytes[0] === 2;
58046
+ }
58026
58047
  /**
58027
58048
  * Get the x-coordinate of the public key.
58028
58049
  * @returns {Uint8Array} The 32-byte x-coordinate of the public key.
@@ -58065,6 +58086,13 @@ var BTCR2 = (() => {
58065
58086
  y: this.y
58066
58087
  };
58067
58088
  }
58089
+ /**
58090
+ * Returns the BIP-340 (x-only) representation of this key.
58091
+ * @returns {KeyBytes} The BIP-340 (x-only) representation of the public key.
58092
+ */
58093
+ bip340() {
58094
+ return this.xOnly;
58095
+ }
58068
58096
  /**
58069
58097
  * Returns the point of the public key.
58070
58098
  * @param {Hex} pk The public key in hex (Uint8Array or string) format.
@@ -58073,11 +58101,11 @@ var BTCR2 = (() => {
58073
58101
  */
58074
58102
  static point(pk) {
58075
58103
  if (typeof pk === "string" && /^[0-9a-fA-F]+$/.test(pk)) {
58076
- const publicKey2 = new _PublicKey(import_buffer.Buffer.fromHex(pk));
58104
+ const publicKey2 = new _CompressedSecp256k1PublicKey(import_buffer.Buffer.fromHex(pk));
58077
58105
  return publicKey2.point;
58078
58106
  }
58079
58107
  if (pk instanceof Uint8Array || ArrayBuffer.isView(pk)) {
58080
- const publicKey2 = new _PublicKey(pk);
58108
+ const publicKey2 = new _CompressedSecp256k1PublicKey(pk);
58081
58109
  return publicKey2.point;
58082
58110
  }
58083
58111
  throw new PublicKeyError("Invalid publicKey: must be a hex string or byte array", "POINT_ERROR", { publicKey: pk });
@@ -58087,7 +58115,7 @@ var BTCR2 = (() => {
58087
58115
  * @returns {KeyBytes} The decoded public key: prefix and public key bytes
58088
58116
  */
58089
58117
  decode() {
58090
- const decoded = base58btc.decode(this.multibase.address);
58118
+ const decoded = base58btc.decode(this.multibase.encoded);
58091
58119
  if (decoded.length !== 35) {
58092
58120
  throw new PublicKeyError("Invalid argument: must be 35 byte publicKeyMultibase", "DECODE_MULTIBASE_ERROR");
58093
58121
  }
@@ -58113,15 +58141,15 @@ var BTCR2 = (() => {
58113
58141
  }
58114
58142
  /**
58115
58143
  * Compares this public key to another public key.
58116
- * @param {PublicKey} other The other public key to compare
58144
+ * @param {CompressedSecp256k1PublicKey} other The other public key to compare
58117
58145
  * @returns {boolean} True if the public keys are equal, false otherwise.
58118
58146
  */
58119
58147
  equals(other) {
58120
58148
  return this.hex === other.hex;
58121
58149
  }
58122
58150
  /**
58123
- * JSON representation of a PublicKey object.
58124
- * @returns {PublicKeyObject} The PublicKey as a JSON object.
58151
+ * JSON representation of a CompressedSecp256k1PublicKey object.
58152
+ * @returns {PublicKeyObject} The CompressedSecp256k1PublicKey as a JSON object.
58125
58153
  */
58126
58154
  json() {
58127
58155
  return {
@@ -58135,26 +58163,26 @@ var BTCR2 = (() => {
58135
58163
  };
58136
58164
  }
58137
58165
  /**
58138
- * Creates a PublicKey object from a JSON representation.
58139
- * @param {PublicKeyObject} json The JSON object to initialize the PublicKey.
58140
- * @returns {PublicKey} The initialized PublicKey object.
58166
+ * Creates a CompressedSecp256k1PublicKey object from a JSON representation.
58167
+ * @param {PublicKeyObject} json The JSON object to initialize the CompressedSecp256k1PublicKey.
58168
+ * @returns {CompressedSecp256k1PublicKey} The initialized CompressedSecp256k1PublicKey object.
58141
58169
  */
58142
58170
  static fromJSON(json) {
58143
58171
  json.x.unshift(json.parity);
58144
- return new _PublicKey(json.x.toUint8Array());
58172
+ return new _CompressedSecp256k1PublicKey(json.x.toUint8Array());
58145
58173
  }
58146
58174
  /**
58147
- * Computes the deterministic public key for a given private key.
58148
- * @param {PrivateKey | KeyBytes} sk The PrivateKey object or the private key bytes
58149
- * @returns {PublicKey} A new PublicKey object
58175
+ * Computes the deterministic public key for a given secret key.
58176
+ * @param {Secp256k1SecretKey | KeyBytes} sk The Secp256k1SecretKey object or the secret key bytes
58177
+ * @returns {CompressedSecp256k1PublicKey} A new CompressedSecp256k1PublicKey object
58150
58178
  */
58151
58179
  static fromSecretKey(sk) {
58152
- const bytes3 = sk instanceof SecretKey ? sk.bytes : sk;
58180
+ const bytes3 = sk instanceof Secp256k1SecretKey ? sk.bytes : sk;
58153
58181
  if (bytes3.length !== 32) {
58154
- throw new PublicKeyError("Invalid arg: must be 32 byte private key", "FROM_PRIVATE_KEY_ERROR");
58182
+ throw new PublicKeyError("Invalid arg: must be 32 byte secret key", "FROM_SECRET_KEY_ERROR");
58155
58183
  }
58156
- const privateKey = sk instanceof SecretKey ? sk : new SecretKey(sk);
58157
- return new _PublicKey(privateKey.computePublicKey());
58184
+ const secret = sk instanceof Secp256k1SecretKey ? sk : new Secp256k1SecretKey(sk);
58185
+ return secret.computePublicKey();
58158
58186
  }
58159
58187
  /**
58160
58188
  * Computes modular exponentiation: (base^exp) % mod.
@@ -58202,23 +58230,11 @@ var BTCR2 = (() => {
58202
58230
  const yBytes = import_buffer.Buffer.fromHex(y.toString(16).padStart(64, "0"));
58203
58231
  return new Uint8Array(import_buffer.Buffer.concat([import_buffer.Buffer.from([4]), import_buffer.Buffer.from(this.x), yBytes]));
58204
58232
  }
58205
- /**
58206
- * Static version of liftX method.
58207
- * @param {KeyBytes} x The 32-byte x-coordinate to lift.
58208
- * @returns {Uint8Array} The 65-byte uncompressed public key (0x04, x, y).
58209
- */
58210
- static xOnly(x) {
58211
- if (x.length !== 32) {
58212
- throw new PublicKeyError("Invalid argument: x-coordinate length must be 32 bytes", "LIFT_X_ERROR");
58213
- }
58214
- const publicKey2 = new _PublicKey(x);
58215
- return publicKey2.x;
58216
- }
58217
58233
  };
58218
58234
 
58219
58235
  // ../keypair/dist/esm/pair.js
58220
58236
  var SchnorrKeyPair = class _SchnorrKeyPair {
58221
- /** @type {SecretKey} The secret key object */
58237
+ /** @type {Secp256k1SecretKey} The secret key object */
58222
58238
  _secretKey;
58223
58239
  _publicKey;
58224
58240
  /** @type {string} The public key in multibase format */
@@ -58227,31 +58243,35 @@ var BTCR2 = (() => {
58227
58243
  _secretKeyMultibase;
58228
58244
  /**
58229
58245
  * Creates an instance of Keys. Must provide a at least a secret key.
58230
- * Can optionally provide both a private and public key, but must be a valid pair.
58231
- * @param {SecretKey} secretKey The secret key object
58246
+ * Can optionally provide both a secret and public key, but must be a valid pair.
58247
+ * @param {SchnorrKeyPairParams} params The parameters to initialize the Keys object.
58248
+ * @param {CompressedSecp256k1PublicKey | KeyBytes} params.publicKey The public key object or bytes
58249
+ * @param {Secp256k1SecretKey | KeyBytes} [params.secret] The secret key object or bytes
58250
+ * @throws {KeyPairError} If neither a public key or secret key is provided.
58251
+ * @throws {KeyPairError} If the public key is not a valid pair with the secret key.
58232
58252
  */
58233
- constructor({ secretKey, publicKey: publicKey2 } = {}) {
58234
- if (!publicKey2 && !secretKey) {
58253
+ constructor(params = {}) {
58254
+ if (!params.publicKey && !params.secretKey) {
58235
58255
  throw new KeyPairError("Argument missing: must at least provide a publicKey", "CONSTRUCTOR_ERROR");
58236
58256
  }
58237
- if (secretKey instanceof Uint8Array) {
58238
- this._secretKey = new SecretKey(secretKey);
58239
- } else if (secretKey instanceof SecretKey) {
58240
- this._secretKey = secretKey;
58257
+ if (params.secretKey instanceof Uint8Array) {
58258
+ this._secretKey = new Secp256k1SecretKey(params.secretKey);
58259
+ } else if (params.secretKey instanceof Secp256k1SecretKey) {
58260
+ this._secretKey = params.secretKey;
58241
58261
  }
58242
- if (publicKey2 instanceof PublicKey) {
58243
- this._publicKey = publicKey2;
58244
- } else if (publicKey2 instanceof Uint8Array) {
58245
- this._publicKey = new PublicKey(publicKey2);
58262
+ if (params.publicKey instanceof CompressedSecp256k1PublicKey) {
58263
+ this._publicKey = params.publicKey;
58264
+ } else if (params.publicKey instanceof Uint8Array) {
58265
+ this._publicKey = new CompressedSecp256k1PublicKey(params.publicKey);
58246
58266
  } else {
58247
- this._publicKey = new PublicKey(this._secretKey.computePublicKey());
58267
+ this._publicKey = this._secretKey.computePublicKey();
58248
58268
  }
58249
- this._publicKeyMultibase = this._publicKey.multibase.address;
58269
+ this._publicKeyMultibase = this._publicKey.multibase.encoded;
58250
58270
  this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : "";
58251
58271
  }
58252
58272
  /**
58253
- * Get the SecretKey.
58254
- * @returns {SecretKey} The SecretKey object
58273
+ * Get the Secp256k1SecretKey.
58274
+ * @returns {Secp256k1SecretKey} The Secp256k1SecretKey object
58255
58275
  * @throws {KeyPairError} If the secret key is not available
58256
58276
  */
58257
58277
  get secretKey() {
@@ -58261,33 +58281,38 @@ var BTCR2 = (() => {
58261
58281
  if (!this._secretKey.isValid()) {
58262
58282
  throw new KeyPairError("Secret key is not valid", "SECRET_KEY_ERROR");
58263
58283
  }
58264
- const secretKey = this._secretKey;
58265
- return secretKey;
58284
+ const secret = this._secretKey;
58285
+ return secret;
58266
58286
  }
58267
58287
  /**
58268
- * Set the PublicKey.
58269
- * @param {PublicKey} publicKey The PublicKey object
58288
+ * Set the CompressedSecp256k1PublicKey.
58289
+ * @param {CompressedSecp256k1PublicKey} publicKey The CompressedSecp256k1PublicKey object
58270
58290
  * @throws {KeyPairError} If the public key is not a valid pair with the secret key.
58271
58291
  */
58272
58292
  set publicKey(publicKey2) {
58273
- if (this.secretKey && !this.secretKey.isValidPair(publicKey2)) {
58274
- throw new KeyPairError("Public key is not a valid pair with the secret key", "PUBLIC_KEY_ERROR");
58293
+ if (this.secretKey) {
58294
+ if (!this.secretKey.hasValidPublicKey()) {
58295
+ throw new KeyPairError("Secret key is not valid", "SECRET_KEY_ERROR");
58296
+ }
58297
+ const cPk = this.secretKey.computePublicKey();
58298
+ if (!publicKey2.equals(cPk))
58299
+ throw new KeyPairError("Public key is not a valid pair with the secret key", "PUBLIC_KEY_ERROR");
58275
58300
  }
58276
58301
  this._publicKey = publicKey2;
58277
- this._publicKeyMultibase = publicKey2.multibase.address;
58302
+ this._publicKeyMultibase = publicKey2.multibase.encoded;
58278
58303
  this._secretKeyMultibase = this._secretKey ? this._secretKey.multibase : "";
58279
58304
  }
58280
58305
  /**
58281
- * Get the PublicKey.
58282
- * @returns {PublicKey} The PublicKey object
58306
+ * Get the CompressedSecp256k1PublicKey.
58307
+ * @returns {CompressedSecp256k1PublicKey} The CompressedSecp256k1PublicKey object
58283
58308
  */
58284
58309
  get publicKey() {
58285
58310
  const publicKey2 = this._publicKey;
58286
58311
  return publicKey2;
58287
58312
  }
58288
58313
  /**
58289
- * Get the Keys as a raw key pair.
58290
- * @returns {RawKeyPair} The Keys as a raw key pair
58314
+ * Get the raw bytes of each key in the SchnorrKeyPair.
58315
+ * @returns {RawSchnorrKeyPair} JSON object with the SchnorrKeyPair raw bytes.
58291
58316
  */
58292
58317
  get raw() {
58293
58318
  return {
@@ -58297,7 +58322,7 @@ var BTCR2 = (() => {
58297
58322
  }
58298
58323
  /**
58299
58324
  * Get the Keys in multibase format.
58300
- * @returns {MultibaseKeys} The SecretKey in multibase format
58325
+ * @returns {MultibaseKeys} The Secp256k1SecretKey in multibase format
58301
58326
  */
58302
58327
  get multibase() {
58303
58328
  return {
@@ -58321,37 +58346,40 @@ var BTCR2 = (() => {
58321
58346
  * @returns {SchnorrKeyPair} The initialized Keys object.
58322
58347
  */
58323
58348
  static fromJSON(keys) {
58324
- const secretKey = SecretKey.fromJSON(keys.secretKey);
58325
- const publicKey2 = PublicKey.fromJSON(keys.publicKey);
58326
- return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
58349
+ return new _SchnorrKeyPair({
58350
+ secretKey: Secp256k1SecretKey.fromJSON(keys.secretKey),
58351
+ publicKey: CompressedSecp256k1PublicKey.fromJSON(keys.publicKey)
58352
+ });
58327
58353
  }
58328
58354
  /**
58329
- * Static method creates a new SchnorrKeyPair from a SecretKey object or secret key bytes.
58330
- * @param {SecretKey | KeyBytes} data The secret key bytes
58355
+ * Static method creates a new SchnorrKeyPair from a Secp256k1SecretKey object or secret key bytes.
58356
+ * @param {Secp256k1SecretKey | KeyBytes} data The secret key bytes
58331
58357
  * @returns {SchnorrKeyPair} A new SchnorrKeyPair object
58332
58358
  */
58333
58359
  static fromPrivateKey(data) {
58334
- const bytes3 = data instanceof SecretKey ? data.bytes : data;
58360
+ const bytes3 = data instanceof Secp256k1SecretKey ? data.bytes : data;
58335
58361
  if (bytes3.length !== 32) {
58336
58362
  throw new KeyPairError("Invalid arg: must be 32 byte secret key", "FROM_PRIVATE_KEY_ERROR");
58337
58363
  }
58338
- const secretKey = data instanceof Uint8Array ? new SecretKey(data) : data;
58339
- const publicKey2 = secretKey.computePublicKey();
58340
- return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
58364
+ const secret = data instanceof Uint8Array ? new Secp256k1SecretKey(data) : data;
58365
+ return new _SchnorrKeyPair({
58366
+ secretKey: data instanceof Uint8Array ? new Secp256k1SecretKey(data) : data,
58367
+ publicKey: secret.computePublicKey()
58368
+ });
58341
58369
  }
58342
58370
  /**
58343
- * Static method creates a new Keys (SecretKey/PublicKey) bigint secret.
58344
- * @param {bigint} secret The secret key secret
58345
- * @returns {Keys} A new Keys object
58371
+ * Static method creates a new Keys (Secp256k1SecretKey/CompressedSecp256k1PublicKey) from bigint entropy.
58372
+ * @param {bigint} entropy The entropy in bigint form
58373
+ * @returns {SchnorrKeyPair} A new SchnorrKeyPair object
58346
58374
  */
58347
- static fromSecret(secret) {
58348
- const secretKey = SecretKey.fromSecret(secret);
58375
+ static fromEntropy(entropy) {
58376
+ const secretKey = Secp256k1SecretKey.fromEntropy(entropy);
58349
58377
  const publicKey2 = secretKey.computePublicKey();
58350
58378
  return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
58351
58379
  }
58352
58380
  /**
58353
58381
  * Converts key bytes to a hex string.
58354
- * @param {KeyBytes} keyBytes The key bytes (private or public).
58382
+ * @param {KeyBytes} keyBytes The key bytes (secret or public).
58355
58383
  * @returns {Hex} The key bytes as a hex string.
58356
58384
  */
58357
58385
  static toHex(keyBytes) {
@@ -58359,18 +58387,18 @@ var BTCR2 = (() => {
58359
58387
  }
58360
58388
  /**
58361
58389
  * Compares two Keys objects for equality.
58362
- * @param {SchnorrKeyPair} keys The main keys.
58363
- * @param {SchnorrKeyPair} otherKeys The other keys to compare.
58390
+ * @param {SchnorrKeyPair} kp The main keys.
58391
+ * @param {SchnorrKeyPair} otherKp The other keys to compare.
58364
58392
  * @returns {boolean} True if the public key and secret key are equal, false otherwise.
58365
58393
  */
58366
- static equals(keys, otherKeys) {
58367
- const pk = keys.publicKey;
58368
- const otherPk = otherKeys.publicKey;
58394
+ static equals(kp, otherKp) {
58395
+ const pk = kp.publicKey;
58396
+ const otherPk = otherKp.publicKey;
58369
58397
  if (pk && otherPk) {
58370
58398
  return pk.hex === otherPk.hex;
58371
58399
  }
58372
- const sk = keys.secretKey;
58373
- const otherSk = otherKeys.secretKey;
58400
+ const sk = kp.secretKey;
58401
+ const otherSk = otherKp.secretKey;
58374
58402
  if (sk && otherSk) {
58375
58403
  return sk.hex === otherSk.hex;
58376
58404
  }
@@ -58378,16 +58406,19 @@ var BTCR2 = (() => {
58378
58406
  }
58379
58407
  /**
58380
58408
  * Static method to generate a new random SchnorrKeyPair instance.
58381
- * @returns {SchnorrKeyPair} A new SecretKey object.
58409
+ * @returns {SchnorrKeyPair} A new Secp256k1SecretKey object.
58382
58410
  */
58383
58411
  static generate() {
58384
- const skBytes = SecretKey.random();
58385
- const secretKey = new SecretKey(skBytes);
58412
+ const sk = Secp256k1SecretKey.random();
58413
+ const secretKey = new Secp256k1SecretKey(sk);
58386
58414
  const publicKey2 = secretKey.computePublicKey();
58387
58415
  return new _SchnorrKeyPair({ secretKey, publicKey: publicKey2 });
58388
58416
  }
58389
58417
  };
58390
58418
 
58419
+ // ../keypair/dist/esm/types.js
58420
+ init_shim();
58421
+
58391
58422
  // src/utils/appendix.ts
58392
58423
  init_shim();
58393
58424
 
@@ -65708,7 +65739,7 @@ var BTCR2 = (() => {
65708
65739
  return n3 === _0n6 ? n3 : assertInRange(n3, CURVE_ORDER);
65709
65740
  }
65710
65741
  const pointPrecomputes2 = /* @__PURE__ */ new Map();
65711
- function isPoint3(other) {
65742
+ function isPoint4(other) {
65712
65743
  if (!(other instanceof Point4))
65713
65744
  throw new Error("ExtendedPoint expected");
65714
65745
  }
@@ -65773,7 +65804,7 @@ var BTCR2 = (() => {
65773
65804
  }
65774
65805
  // Compare one point to another.
65775
65806
  equals(other) {
65776
- isPoint3(other);
65807
+ isPoint4(other);
65777
65808
  const { ex: X1, ey: Y1, ez: Z1 } = this;
65778
65809
  const { ex: X2, ey: Y2, ez: Z2 } = other;
65779
65810
  const X1Z2 = modP(X1 * Z2);
@@ -65813,7 +65844,7 @@ var BTCR2 = (() => {
65813
65844
  // https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
65814
65845
  // Cost: 9M + 1*a + 1*d + 7add.
65815
65846
  add(other) {
65816
- isPoint3(other);
65847
+ isPoint4(other);
65817
65848
  const { a: a3, d: d2 } = CURVE2;
65818
65849
  const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
65819
65850
  const { ex: X2, ey: Y2, ez: Z2, et: T2 } = other;
@@ -86869,10 +86900,10 @@ var BTCR2 = (() => {
86869
86900
  return enumeration(__KeyTypeValues);
86870
86901
  };
86871
86902
  })(KeyType || (KeyType = {}));
86872
- var PublicKey2;
86873
- (function(PublicKey4) {
86903
+ var PublicKey;
86904
+ (function(PublicKey3) {
86874
86905
  let _codec;
86875
- PublicKey4.codec = () => {
86906
+ PublicKey3.codec = () => {
86876
86907
  if (_codec == null) {
86877
86908
  _codec = message((obj, w, opts = {}) => {
86878
86909
  if (opts.lengthDelimited !== false) {
@@ -86914,13 +86945,13 @@ var BTCR2 = (() => {
86914
86945
  }
86915
86946
  return _codec;
86916
86947
  };
86917
- PublicKey4.encode = (obj) => {
86918
- return encodeMessage(obj, PublicKey4.codec());
86948
+ PublicKey3.encode = (obj) => {
86949
+ return encodeMessage(obj, PublicKey3.codec());
86919
86950
  };
86920
- PublicKey4.decode = (buf2, opts) => {
86921
- return decodeMessage(buf2, PublicKey4.codec(), opts);
86951
+ PublicKey3.decode = (buf2, opts) => {
86952
+ return decodeMessage(buf2, PublicKey3.codec(), opts);
86922
86953
  };
86923
- })(PublicKey2 || (PublicKey2 = {}));
86954
+ })(PublicKey || (PublicKey = {}));
86924
86955
  var PrivateKey;
86925
86956
  (function(PrivateKey3) {
86926
86957
  let _codec;
@@ -87171,7 +87202,7 @@ var BTCR2 = (() => {
87171
87202
  function pkixMessageToRSAPublicKey(message2, bytes3, digest2) {
87172
87203
  const jwk = pkixMessageToJwk(message2);
87173
87204
  if (digest2 == null) {
87174
- const hash2 = sha2562(PublicKey2.encode({
87205
+ const hash2 = sha2562(PublicKey.encode({
87175
87206
  Type: KeyType.RSA,
87176
87207
  Data: bytes3
87177
87208
  }));
@@ -87184,7 +87215,7 @@ var BTCR2 = (() => {
87184
87215
  throw new InvalidParametersError("Key size is too large");
87185
87216
  }
87186
87217
  const keys = jwkToJWKKeyPair(jwk);
87187
- const hash2 = sha2562(PublicKey2.encode({
87218
+ const hash2 = sha2562(PublicKey.encode({
87188
87219
  Type: KeyType.RSA,
87189
87220
  Data: jwkToPkix(keys.publicKey)
87190
87221
  }));
@@ -87196,7 +87227,7 @@ var BTCR2 = (() => {
87196
87227
  throw new InvalidParametersError("Key size is too large");
87197
87228
  }
87198
87229
  const keys = await generateRSAKey(bits);
87199
- const hash2 = sha2562(PublicKey2.encode({
87230
+ const hash2 = sha2562(PublicKey.encode({
87200
87231
  Type: KeyType.RSA,
87201
87232
  Data: jwkToPkix(keys.publicKey)
87202
87233
  }));
@@ -88687,7 +88718,7 @@ var BTCR2 = (() => {
88687
88718
  throw new UnsupportedKeyTypeError();
88688
88719
  }
88689
88720
  function publicKeyFromProtobuf(buf2, digest2) {
88690
- const { Type: Type2, Data } = PublicKey2.decode(buf2);
88721
+ const { Type: Type2, Data } = PublicKey.decode(buf2);
88691
88722
  const data = Data ?? new Uint8Array();
88692
88723
  switch (Type2) {
88693
88724
  case KeyType.RSA:
@@ -88703,7 +88734,7 @@ var BTCR2 = (() => {
88703
88734
  }
88704
88735
  }
88705
88736
  function publicKeyFromMultihash(digest2) {
88706
- const { Type: Type2, Data } = PublicKey2.decode(digest2.digest);
88737
+ const { Type: Type2, Data } = PublicKey.decode(digest2.digest);
88707
88738
  const data = Data ?? new Uint8Array();
88708
88739
  switch (Type2) {
88709
88740
  case KeyType.Ed25519:
@@ -88717,7 +88748,7 @@ var BTCR2 = (() => {
88717
88748
  }
88718
88749
  }
88719
88750
  function publicKeyToProtobuf(key) {
88720
- return PublicKey2.encode({
88751
+ return PublicKey.encode({
88721
88752
  Type: KeyType[key.type],
88722
88753
  Data: key.raw
88723
88754
  });
@@ -142602,7 +142633,7 @@ ${values.join("\n")}` : `${blockName} :`;
142602
142633
  }
142603
142634
  }
142604
142635
  };
142605
- var PublicKey3 = class _PublicKey extends PemData {
142636
+ var PublicKey2 = class _PublicKey extends PemData {
142606
142637
  static async create(data, crypto6 = cryptoProvider.get()) {
142607
142638
  if (data instanceof _PublicKey) {
142608
142639
  return data;
@@ -142718,7 +142749,7 @@ ${values.join("\n")}` : `${blockName} :`;
142718
142749
  if ("name" in param && "serialNumber" in param) {
142719
142750
  return new _AuthorityKeyIdentifierExtension(param, critical);
142720
142751
  }
142721
- const key = await PublicKey3.create(param, crypto6);
142752
+ const key = await PublicKey2.create(param, crypto6);
142722
142753
  const id = await key.getKeyIdentifier(crypto6);
142723
142754
  return new _AuthorityKeyIdentifierExtension(import_pvtsutils6.Convert.ToHex(id), critical);
142724
142755
  }
@@ -142858,7 +142889,7 @@ ${values.join("\n")}` : `${blockName} :`;
142858
142889
  KeyUsagesExtension.NAME = "Key Usages";
142859
142890
  var SubjectKeyIdentifierExtension = class _SubjectKeyIdentifierExtension extends Extension2 {
142860
142891
  static async create(publicKey2, critical = false, crypto6 = cryptoProvider.get()) {
142861
- const key = await PublicKey3.create(publicKey2, crypto6);
142892
+ const key = await PublicKey2.create(publicKey2, crypto6);
142862
142893
  const id = await key.getKeyIdentifier(crypto6);
142863
142894
  return new _SubjectKeyIdentifierExtension(import_pvtsutils6.Convert.ToHex(id), critical);
142864
142895
  }
@@ -143500,7 +143531,7 @@ ${values.join("\n")}` : `${blockName} :`;
143500
143531
  }
143501
143532
  get publicKey() {
143502
143533
  if (!__classPrivateFieldGet(this, _Pkcs10CertificateRequest_publicKey, "f")) {
143503
- __classPrivateFieldSet(this, _Pkcs10CertificateRequest_publicKey, new PublicKey3(this.asn.certificationRequestInfo.subjectPKInfo), "f");
143534
+ __classPrivateFieldSet(this, _Pkcs10CertificateRequest_publicKey, new PublicKey2(this.asn.certificationRequestInfo.subjectPKInfo), "f");
143504
143535
  }
143505
143536
  return __classPrivateFieldGet(this, _Pkcs10CertificateRequest_publicKey, "f");
143506
143537
  }
@@ -143622,7 +143653,7 @@ ${values.join("\n")}` : `${blockName} :`;
143622
143653
  var X509Certificate = class extends PemData {
143623
143654
  get publicKey() {
143624
143655
  if (!__classPrivateFieldGet(this, _X509Certificate_publicKey, "f")) {
143625
- __classPrivateFieldSet(this, _X509Certificate_publicKey, new PublicKey3(this.asn.tbsCertificate.subjectPublicKeyInfo), "f");
143656
+ __classPrivateFieldSet(this, _X509Certificate_publicKey, new PublicKey2(this.asn.tbsCertificate.subjectPublicKeyInfo), "f");
143626
143657
  }
143627
143658
  return __classPrivateFieldGet(this, _X509Certificate_publicKey, "f");
143628
143659
  }
@@ -143762,11 +143793,11 @@ ${values.join("\n")}` : `${blockName} :`;
143762
143793
  } else if ("publicKey" in paramsKey) {
143763
143794
  keyAlgorithm = { ...paramsKey.publicKey.algorithm, ...this.signatureAlgorithm };
143764
143795
  publicKey2 = await paramsKey.publicKey.export(keyAlgorithm, ["verify"], crypto6);
143765
- } else if (paramsKey instanceof PublicKey3) {
143796
+ } else if (paramsKey instanceof PublicKey2) {
143766
143797
  keyAlgorithm = { ...paramsKey.algorithm, ...this.signatureAlgorithm };
143767
143798
  publicKey2 = await paramsKey.export(keyAlgorithm, ["verify"], crypto6);
143768
143799
  } else if (import_pvtsutils6.BufferSourceConverter.isBufferSource(paramsKey)) {
143769
- const key = new PublicKey3(paramsKey);
143800
+ const key = new PublicKey2(paramsKey);
143770
143801
  keyAlgorithm = { ...key.algorithm, ...this.signatureAlgorithm };
143771
143802
  publicKey2 = await key.export(keyAlgorithm, ["verify"], crypto6);
143772
143803
  } else {
@@ -143895,7 +143926,7 @@ ${values.join("\n")}` : `${blockName} :`;
143895
143926
  static async create(params, crypto6 = cryptoProvider.get()) {
143896
143927
  var _a3;
143897
143928
  let spki;
143898
- if (params.publicKey instanceof PublicKey3) {
143929
+ if (params.publicKey instanceof PublicKey2) {
143899
143930
  spki = params.publicKey.rawData;
143900
143931
  } else if ("publicKey" in params.publicKey) {
143901
143932
  spki = params.publicKey.publicKey.rawData;
@@ -145202,7 +145233,7 @@ a=end-of-candidates
145202
145233
  return verificationMethods;
145203
145234
  }
145204
145235
  /**
145205
- * Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-didbtc1-identifier | 9.4.1 Derive Root Capability from did:btcr2 Identifier}.
145236
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-didbtcr2-identifier | 9.4.1 Derive Root Capability from did:btcr2 Identifier }.
145206
145237
  *
145207
145238
  * The Derive Root Capability algorithm deterministically generates a ZCAP-LD root capability from a given did:btcr2
145208
145239
  * identifier. Each root capability is unique to the identifier. This root capability is defined and understood by the
@@ -145210,7 +145241,7 @@ a=end-of-candidates
145210
145241
  * document. It takes in a did:btcr2 identifier and returns a rootCapability object. It returns the root capability.
145211
145242
  *
145212
145243
  * @param {string} identifier The did-btcr2 identifier to derive the root capability from
145213
- * @returns {Btc1RootCapability} The root capability object
145244
+ * @returns {RootCapability} The root capability object
145214
145245
  * @example Root capability for updating the DID document for
145215
145246
  * did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u
145216
145247
  * ```
@@ -145238,7 +145269,7 @@ a=end-of-candidates
145238
145269
  * capability object.
145239
145270
  *
145240
145271
  * @param {string} capabilityId The root capability identifier to dereference.
145241
- * @returns {Btc1RootCapability} The root capability object.
145272
+ * @returns {RootCapability} The root capability object.
145242
145273
  * @example a didUpdatePayload with an invoked ZCAP-LD capability containing a patch defining how the DID document
145243
145274
  * for did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u SHOULD be mutated.
145244
145275
  * ```
@@ -145264,7 +145295,7 @@ a=end-of-candidates
145264
145295
  * "cryptosuite": "schnorr-secp256k1-jcs-2025",
145265
145296
  * "verificationMethod": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u#initialKey",
145266
145297
  * "invocationTarget": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
145267
- * "capability": "urn:zcap:root:did%3Abtc1%3Ak1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
145298
+ * "capability": "urn:zcap:root:did%3Abtcr2%3Ak1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
145268
145299
  * "capabilityAction": "Write",
145269
145300
  * "proofPurpose": "assertionMethod",
145270
145301
  * "proofValue": "z381yXYmxU8NudZ4HXY56DfMN6zfD8syvWcRXzT9xD9uYoQToo8QsXD7ahM3gXTzuay5WJbqTswt2BKaGWYn2hHhVFKJLXaDz"
@@ -145595,8 +145626,8 @@ a=end-of-candidates
145595
145626
  * @param {string} params.id The id of the multikey (required)
145596
145627
  * @param {string} params.controller The controller of the multikey (required)
145597
145628
  * @param {Keys} params.keys The Keys of the multikey (optional, required if no publicKey)
145598
- * @param {PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
145599
- * @param {SecretKey} params.keys.privateKey The private key of the multikey (optional)
145629
+ * @param {CompressedSecp256k1PublicKey} params.keys.publicKey The public key of the multikey (optional, required if no privateKey)
145630
+ * @param {Secp256k1SecretKey} params.keys.privateKey The private key of the multikey (optional)
145600
145631
  * @throws {MultikeyError} if neither a publicKey nor a privateKey is provided
145601
145632
  */
145602
145633
  constructor({ id, controller, keys }) {
@@ -145615,7 +145646,7 @@ a=end-of-candidates
145615
145646
  const keys = this._keys;
145616
145647
  return keys;
145617
145648
  }
145618
- /** @type {PublicKey} @readonly Get the Multikey PublicKey. */
145649
+ /** @type {CompressedSecp256k1PublicKey} @readonly Get the Multikey CompressedSecp256k1PublicKey. */
145619
145650
  get publicKey() {
145620
145651
  const publicKey2 = this._keys.publicKey;
145621
145652
  return publicKey2;
@@ -145691,7 +145722,7 @@ a=end-of-candidates
145691
145722
  id: this.id,
145692
145723
  type: _SchnorrMultikey.type,
145693
145724
  controller: this.controller,
145694
- publicKeyMultibase: this.publicKey.multibase.address
145725
+ publicKeyMultibase: this.publicKey.multibase.encoded
145695
145726
  };
145696
145727
  }
145697
145728
  /**
@@ -145719,10 +145750,10 @@ a=end-of-candidates
145719
145750
  }
145720
145751
  const decoded = this.publicKey.decode();
145721
145752
  const publicKey2 = decoded.slice(2, decoded.length);
145722
- const keys = new SchnorrKeyPair({ publicKey: new PublicKey(publicKey2) });
145753
+ const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKey2) });
145723
145754
  return new _SchnorrMultikey({ id, controller, keys });
145724
145755
  }
145725
- /** @type {boolean} @readonly Get signing ability of the Multikey (i.e. is there a valid SecretKey). */
145756
+ /** @type {boolean} @readonly Get signing ability of the Multikey (i.e. is there a valid Secp256k1SecretKey). */
145726
145757
  get signer() {
145727
145758
  return !!this.keys.secretKey;
145728
145759
  }
@@ -145763,7 +145794,7 @@ a=end-of-candidates
145763
145794
  * @returns {SchnorrMultikey} The new multikey instance
145764
145795
  */
145765
145796
  static fromPrivateKey({ id, controller, entropy }) {
145766
- const secretKey = new SecretKey(entropy);
145797
+ const secretKey = new Secp256k1SecretKey(entropy);
145767
145798
  const publicKey2 = secretKey.computePublicKey();
145768
145799
  const keys = new SchnorrKeyPair({ publicKey: publicKey2, secretKey });
145769
145800
  return new _SchnorrMultikey({ id, controller, keys });
@@ -145777,7 +145808,7 @@ a=end-of-candidates
145777
145808
  * @returns {Multikey} The new multikey instance
145778
145809
  */
145779
145810
  static fromPublicKey({ id, controller, publicKeyBytes }) {
145780
- const keys = new SchnorrKeyPair({ publicKey: new PublicKey(publicKeyBytes) });
145811
+ const keys = new SchnorrKeyPair({ publicKey: new CompressedSecp256k1PublicKey(publicKeyBytes) });
145781
145812
  return new _SchnorrMultikey({ id, controller, keys });
145782
145813
  }
145783
145814
  /**
@@ -145868,9 +145899,9 @@ a=end-of-candidates
145868
145899
  throw new Error("Method not implemented." + txHex + keyUri);
145869
145900
  }
145870
145901
  /**
145871
- * Gets the key pair from the key store and returns a PublicKey.
145902
+ * Gets the key pair from the key store and returns a CompressedSecp256k1PublicKey.
145872
145903
  * @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
145873
- * @returns {Promise<PublicKey>} The public key associated with the key URI.
145904
+ * @returns {Promise<CompressedSecp256k1PublicKey>} The public key associated with the key URI.
145874
145905
  */
145875
145906
  async getPublicKey(keyUri) {
145876
145907
  const key = await this.getKey(keyUri);
@@ -145987,11 +146018,11 @@ a=end-of-candidates
145987
146018
  }
145988
146019
  /**
145989
146020
  * Computes a multibase-compliant URI from a key.
145990
- * @param key A SchnorrKeyPair, PublicKey, or multibase string
146021
+ * @param key A SchnorrKeyPair, CompressedSecp256k1PublicKey, or multibase string
145991
146022
  * @returns {string} A multibase URI (e.g. 'urn:mb:zQ3s...')
145992
146023
  */
145993
146024
  static toMultibaseUri(data) {
145994
- const multibase = data instanceof SchnorrKeyPair ? data.publicKey.multibase : data instanceof PublicKey ? data.multibase : data;
146025
+ const multibase = data instanceof SchnorrKeyPair ? data.publicKey.multibase : data instanceof CompressedSecp256k1PublicKey ? data.multibase : data;
145995
146026
  return `${MULTIBASE_URI_PREFIX}${multibase}`;
145996
146027
  }
145997
146028
  /**
@@ -146134,7 +146165,7 @@ a=end-of-candidates
146134
146165
  const hashBytes = JSON.canonicalization.encode(import_buffer.Buffer.fromHex(UPDATE_PAYLOAD_HASH), "base58");
146135
146166
  const signalsMetadataMap = new Map(Object.entries(signalsMetadata));
146136
146167
  if (signalsMetadata) {
146137
- didUpdatePayload = signalsMetadataMap.get(signal.txid)?.btc1Update;
146168
+ didUpdatePayload = signalsMetadataMap.get(signal.txid)?.didUpdate;
146138
146169
  if (!didUpdatePayload) {
146139
146170
  throw new SingletonBeaconError("Update Payload not found in signal metadata.", "PROCESS_SIGNAL_ERROR");
146140
146171
  }
@@ -146213,7 +146244,7 @@ a=end-of-candidates
146213
146244
  if (!spentTx) {
146214
146245
  throw new SingletonBeaconError("Failed to send raw transaction.", "SEND_FAILED", { spentTx });
146215
146246
  }
146216
- return { [spentTx]: { btc1Update: didUpdatePayload } };
146247
+ return { [spentTx]: { didUpdate: didUpdatePayload } };
146217
146248
  }
146218
146249
  };
146219
146250
 
@@ -146352,7 +146383,14 @@ a=end-of-candidates
146352
146383
  }
146353
146384
  };
146354
146385
 
146355
- // src/core/crud/create.ts
146386
+ // src/core/crud/deactivate.ts
146387
+ init_shim();
146388
+
146389
+ // src/did-btcr2.ts
146390
+ init_shim();
146391
+ var tinysecp4 = __toESM(require_dist2(), 1);
146392
+
146393
+ // src/core/crud/read.ts
146356
146394
  init_shim();
146357
146395
 
146358
146396
  // src/utils/beacons.ts
@@ -146932,7 +146970,7 @@ a=end-of-candidates
146932
146970
  // src/utils/identifier.ts
146933
146971
  var Identifier = class {
146934
146972
  /**
146935
- * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtc1-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
146973
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
146936
146974
  *
146937
146975
  * A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
146938
146976
  * - the specification version;
@@ -146963,7 +147001,7 @@ a=end-of-candidates
146963
147001
  }
146964
147002
  if (idType === "KEY") {
146965
147003
  try {
146966
- new PublicKey(genesisBytes);
147004
+ new CompressedSecp256k1PublicKey(genesisBytes);
146967
147005
  } catch {
146968
147006
  throw new MethodError(
146969
147007
  'Expected "genesisBytes" to be a valid compressed secp256k1 public key',
@@ -146996,7 +147034,7 @@ a=end-of-candidates
146996
147034
  return `did:btcr2:${bech32m3.encodeFromBytes(hrp, dataBytes)}`;
146997
147035
  }
146998
147036
  /**
146999
- * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtc1-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
147037
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
147000
147038
  * @param {string} identifier The BTCR2 DID to be parsed
147001
147039
  * @returns {DidComponents} The parsed identifier components. See {@link DidComponents} for details.
147002
147040
  * @throws {DidError} if an error occurs while parsing the identifier
@@ -147065,7 +147103,7 @@ a=end-of-candidates
147065
147103
  const genesisBytes = dataBytes.slice(byteIndex + 1);
147066
147104
  if (idType === "KEY") {
147067
147105
  try {
147068
- new PublicKey(genesisBytes);
147106
+ new CompressedSecp256k1PublicKey(genesisBytes);
147069
147107
  } catch {
147070
147108
  throw new MethodError(`Invalid genesisBytes: ${genesisBytes}`, INVALID_DID, { identifier });
147071
147109
  }
@@ -147090,7 +147128,7 @@ a=end-of-candidates
147090
147128
 
147091
147129
  // src/utils/did-document.ts
147092
147130
  var BECH32M_CHARS = "";
147093
- var BTC1_DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
147131
+ var DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
147094
147132
  var DidVerificationMethod = class {
147095
147133
  id;
147096
147134
  type;
@@ -147120,6 +147158,7 @@ a=end-of-candidates
147120
147158
  capabilityDelegation;
147121
147159
  service;
147122
147160
  constructor(document2) {
147161
+ console.log("Constructing DidDocument with document:", document2);
147123
147162
  const idType = document2.id.includes("k1") ? IdentifierTypes.KEY : IdentifierTypes.EXTERNAL;
147124
147163
  const isIntermediate = document2.id === ID_PLACEHOLDER_VALUE;
147125
147164
  const { id, controller, verificationMethod: vm, service } = document2;
@@ -147359,6 +147398,7 @@ a=end-of-candidates
147359
147398
  if (!_DidDocument.isValidVerificationRelationships(this)) {
147360
147399
  throw new DidDocumentError("Invalid IntermediateDidDocument assertionMethod", INVALID_DID_DOCUMENT, this);
147361
147400
  }
147401
+ return true;
147362
147402
  }
147363
147403
  /**
147364
147404
  * Convert the DidDocument to an IntermediateDidDocument.
@@ -147373,19 +147413,7 @@ a=end-of-candidates
147373
147413
  };
147374
147414
  var IntermediateDidDocument = class _IntermediateDidDocument extends DidDocument2 {
147375
147415
  constructor(document2) {
147376
- const intermediateDocument = JSON.cloneReplace(document2, BTC1_DID_REGEX, ID_PLACEHOLDER_VALUE);
147377
- super(intermediateDocument);
147378
- }
147379
- /**
147380
- * Create a minimal IntermediateDidDocument with a placeholder ID.
147381
- * @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
147382
- * @param {VerificationRelationships} relationships The public key in multibase format.
147383
- * @param {Array<BeaconService>} service The service to be included in the document.
147384
- * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
147385
- */
147386
- static create(verificationMethod, relationships, service) {
147387
- const id = ID_PLACEHOLDER_VALUE;
147388
- return new _IntermediateDidDocument({ id, ...relationships, verificationMethod, service });
147416
+ super(document2);
147389
147417
  }
147390
147418
  /**
147391
147419
  * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
@@ -147398,92 +147426,72 @@ a=end-of-candidates
147398
147426
  return new DidDocument2(parseThis);
147399
147427
  }
147400
147428
  /**
147401
- * Create a DidDocument from a JSON object.
147402
- * @param {JSONObject} object The JSON object to convert.
147403
- * @returns {DidDocument} The created DidDocument.
147429
+ * Create an IntermediateDidDocument from a DidDocument by replacing the DID with a placeholder value.
147430
+ * @param {DidDocument} didDocument The DidDocument to convert.
147431
+ * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
147404
147432
  */
147405
- static from(object2) {
147406
- return new _IntermediateDidDocument(object2).toDidDocument(object2.id);
147433
+ static fromDidDocument(didDocument) {
147434
+ const intermediateDocument = JSON.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE);
147435
+ return new _IntermediateDidDocument(intermediateDocument);
147407
147436
  }
147408
- };
147409
-
147410
- // src/core/crud/create.ts
147411
- var Create = class {
147412
147437
  /**
147413
- * Implements {@link https://dcdpr.github.io/did-btcr2/#deterministic-key-based-creation | 4.1.1 Deterministic Key-Based Creation}.
147414
- *
147415
- * For deterministic key-based creation, the did:btcr2 identifier encodes a secp256k1 public key. The key is then used
147416
- * to deterministically generate the initial DID document.
147417
- *
147418
- * @param {CreateKeyParams} params See {@link CreateKeyParams} for details.
147419
- * @param {number} params.version did-btcr2 identifier version.
147420
- * @param {string} params.network did-btcr2 bitcoin network.
147421
- * @param {KeyBytes} params.pubKeyBytes public key bytes for id creation.
147422
- * @returns {CreateResponse} A response object of type {@link CreateResponse}.
147423
- * @throws {DidError} if the public key is missing or invalid.
147438
+ * Create a minimal IntermediateDidDocument with a placeholder ID.
147439
+ * @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
147440
+ * @param {VerificationRelationships} relationships The public key in multibase format.
147441
+ * @param {Array<BeaconService>} service The service to be included in the document.
147442
+ * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
147424
147443
  */
147425
- static deterministic({ pubKeyBytes, options: options2 }) {
147426
- const { version: version3 = 1, network = "bitcoin" } = options2;
147427
- const idType = IdentifierTypes.KEY;
147428
- const identifier = Identifier.encode({ version: version3, network, idType, genesisBytes: pubKeyBytes });
147429
- const { compressed: publicKey2, multibase: publicKeyMultibase } = new PublicKey(pubKeyBytes);
147430
- const service = BeaconUtils.generateBeaconServices({
147431
- identifier,
147432
- publicKey: publicKey2,
147444
+ static create(verificationMethod, relationships, service) {
147445
+ const id = ID_PLACEHOLDER_VALUE;
147446
+ return new _IntermediateDidDocument({ id, ...relationships, verificationMethod, service });
147447
+ }
147448
+ /**
147449
+ * Create a minimal IntermediateDidDocument from a public key.
147450
+ * @param {KeyBytes} publicKey The public key in bytes format.
147451
+ * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
147452
+ */
147453
+ static fromPublicKey(publicKey2, network) {
147454
+ const pk = new CompressedSecp256k1PublicKey(publicKey2);
147455
+ const id = ID_PLACEHOLDER_VALUE;
147456
+ const service = BeaconUtils.generateBeaconService({
147457
+ id: `${id}#key-0`,
147458
+ publicKey: pk.compressed,
147433
147459
  network: getNetwork(network),
147460
+ addressType: "p2pkh",
147434
147461
  type: "SingletonBeacon"
147435
147462
  });
147436
- const initialDocument = new DidDocument2({
147437
- id: identifier,
147438
- controller: [identifier],
147439
- verificationMethod: [{
147440
- id: `${identifier}#initialKey`,
147463
+ const relationships = {
147464
+ authentication: [`${id}#key-0`],
147465
+ assertionMethod: [`${id}#key-0`],
147466
+ capabilityInvocation: [`${id}#key-0`],
147467
+ capabilityDelegation: [`${id}#key-0`]
147468
+ };
147469
+ const verificationMethod = [
147470
+ {
147471
+ id: `${id}#key-0`,
147441
147472
  type: "Multikey",
147442
- controller: identifier,
147443
- publicKeyMultibase: publicKeyMultibase.address
147444
- }],
147445
- service
147446
- });
147447
- return { did: identifier, initialDocument };
147473
+ controller: id,
147474
+ publicKeyMultibase: pk.multibase.encoded
147475
+ }
147476
+ ];
147477
+ return _IntermediateDidDocument.create(verificationMethod, relationships, [service]);
147448
147478
  }
147449
147479
  /**
147450
- * Implements {@link https://dcdpr.github.io/did-btcr2/#external-initial-document-creation | 4.1.2 External Initial Document Creation}.
147451
- *
147452
- * Creates a did:btcr2 identifier from some initiating arbitrary DID document. This allows for more complex
147453
- * initial DID documents, including the ability to include Service Endpoints and Beacons that support aggregation.
147454
- * Inputs include `intermediateDocument`, optional version and network returning initialDidDocument. The
147455
- * intermediateDocument should be a valid DID document except all places where the DID document requires the use of
147456
- * the identifier (e.g. the id field). These fields should use placeholder value
147457
- * `did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. The intermediateDocument should include at
147458
- * least one verificationMethod and service of the type SingletonBeacon.
147459
- *
147460
- * @param {CreateExternalParams} params See {@link CreateExternalParams} for details.
147461
- * @param {number} params.version Identifier version.
147462
- * @param {string} params.network Identifier network name.
147463
- * @param {string} params.documentBytes Intermediate DID Document bytes.
147464
- * @returns {CreateResponse} A Promise resolving to {@link CreateResponses}.
147465
- * @throws {DidError} if the verificationMethod or service objects are missing required properties
147480
+ * Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
147481
+ * @param {JSONObject} object The JSON object to convert.
147482
+ * @returns {DidDocument} The created DidDocument.
147466
147483
  */
147467
- static async external({ intermediateDocument, options: options2 }) {
147468
- const idType = IdentifierTypes.EXTERNAL;
147469
- const { version: version3 = 1, network = "bitcoin" } = options2;
147470
- intermediateDocument.validateIntermediate();
147471
- const genesisBytes = await JSON.canonicalization.canonicalhash(intermediateDocument);
147472
- const did = Identifier.encode({ idType, genesisBytes, version: version3, network });
147473
- const initialDocument = intermediateDocument.toDidDocument(did);
147474
- return { did, initialDocument };
147484
+ static fromJSON(object2) {
147485
+ return new _IntermediateDidDocument(object2);
147486
+ }
147487
+ };
147488
+ var Document = class {
147489
+ static isValid(didDocument) {
147490
+ return new DidDocument2(didDocument).validateIntermediate();
147475
147491
  }
147476
147492
  };
147477
-
147478
- // src/core/crud/deactivate.ts
147479
- init_shim();
147480
-
147481
- // src/did-btcr2.ts
147482
- init_shim();
147483
- var tinysecp3 = __toESM(require_dist2(), 1);
147484
147493
 
147485
147494
  // src/core/crud/read.ts
147486
- init_shim();
147487
147495
  var bitcoin4 = new BitcoinNetworkConnection();
147488
147496
  var Resolve = class {
147489
147497
  /**
@@ -147500,7 +147508,7 @@ a=end-of-candidates
147500
147508
  */
147501
147509
  static deterministic({ identifier, identifierComponents }) {
147502
147510
  const { network, genesisBytes } = identifierComponents;
147503
- const { compressed: publicKey2, multibase: publicKeyMultibase } = new PublicKey(genesisBytes);
147511
+ const { compressed: publicKey2, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
147504
147512
  const service = BeaconUtils.generateBeaconServices({
147505
147513
  identifier,
147506
147514
  publicKey: publicKey2,
@@ -147514,7 +147522,7 @@ a=end-of-candidates
147514
147522
  id: `${identifier}#initialKey`,
147515
147523
  type: "Multikey",
147516
147524
  controller: identifier,
147517
- publicKeyMultibase: publicKeyMultibase.address
147525
+ publicKeyMultibase: publicKeyMultibase.encoded
147518
147526
  }],
147519
147527
  service
147520
147528
  });
@@ -147650,7 +147658,7 @@ a=end-of-candidates
147650
147658
  targetVersionId,
147651
147659
  targetTime,
147652
147660
  didDocumentHistory: new Array(),
147653
- btc1UpdateHashHistory: new Array(),
147661
+ updateHashHistory: new Array(),
147654
147662
  signalsMetadata,
147655
147663
  network
147656
147664
  });
@@ -147682,7 +147690,7 @@ a=end-of-candidates
147682
147690
  * @param {UnixTimestamp} params.targetTime The timestamp used to target specific historical states of a DID document.
147683
147691
  * Only Beacon Signals included in the Bitcoin blockchain before the targetTime are processed.
147684
147692
  * @param {boolean} params.didDocumentHistory An array of DID documents ordered ascensing by version (1...N).
147685
- * @param {boolean} params.btc1UpdateHashHistory An array of SHA256 hashes of BTCR2 Updates ordered by version that are
147693
+ * @param {boolean} params.updateHashHistory An array of SHA256 hashes of BTCR2 Updates ordered by version that are
147686
147694
  * applied to the DID document in order to construct the contemporaryDIDDocument.
147687
147695
  * @param {SignalsMetadata} params.signalsMetadata See {@link SignalsMetadata} for details.
147688
147696
  * @param {string} params.network The bitcoin network to connect to (mainnet, signet, testnet, regtest).
@@ -147695,7 +147703,7 @@ a=end-of-candidates
147695
147703
  targetVersionId,
147696
147704
  targetTime,
147697
147705
  didDocumentHistory,
147698
- btc1UpdateHashHistory,
147706
+ updateHashHistory,
147699
147707
  signalsMetadata,
147700
147708
  network
147701
147709
  }) {
@@ -147718,8 +147726,8 @@ a=end-of-candidates
147718
147726
  for (let update of orderedUpdates) {
147719
147727
  const updateTargetVersionId = update.targetVersionId;
147720
147728
  if (updateTargetVersionId <= currentVersionId) {
147721
- btc1UpdateHashHistory.push(contemporaryHash);
147722
- await this.confirmDuplicateUpdate({ update, updateHashHistory: btc1UpdateHashHistory });
147729
+ updateHashHistory.push(contemporaryHash);
147730
+ await this.confirmDuplicateUpdate({ update, updateHashHistory });
147723
147731
  } else if (updateTargetVersionId === currentVersionId + 1) {
147724
147732
  const sourceHash = update.sourceHash.startsWith("z") ? update.sourceHash : `z${update.sourceHash}`;
147725
147733
  if (sourceHash !== contemporaryHash) {
@@ -147735,7 +147743,7 @@ a=end-of-candidates
147735
147743
  const unsecuredUpdate = update;
147736
147744
  delete unsecuredUpdate.proof;
147737
147745
  const updateHash = await JSON.canonicalization.process(update, "base58");
147738
- btc1UpdateHashHistory.push(updateHash);
147746
+ updateHashHistory.push(updateHash);
147739
147747
  contemporaryHash = await JSON.canonicalization.process(contemporaryDidDocument, "base58");
147740
147748
  } else if (update.targetVersionId > currentVersionId + 1) {
147741
147749
  throw new ResolveError(
@@ -147921,12 +147929,12 @@ a=end-of-candidates
147921
147929
  const sidecar = { signalsMetadata };
147922
147930
  const service = { id, type, serviceEndpoint: `bitcoin:${address}` };
147923
147931
  const beacon = BeaconFactory.establish(service, sidecar);
147924
- const btc1Update = await beacon.processSignal(signalTx, signalsMetadata) ?? null;
147925
- if (!btc1Update) {
147926
- throw new MethodError("No btc1Update for beacon", "PROCESS_BEACON_SIGNALS_ERROR", { tx, signalsMetadata });
147932
+ const didUpdate = await beacon.processSignal(signalTx, signalsMetadata) ?? null;
147933
+ if (!didUpdate) {
147934
+ throw new MethodError("No didUpdate for beacon", "PROCESS_BEACON_SIGNALS_ERROR", { tx, signalsMetadata });
147927
147935
  }
147928
- updates.push(btc1Update);
147929
- return btc1Update;
147936
+ updates.push(didUpdate);
147937
+ return didUpdate;
147930
147938
  }
147931
147939
  /**
147932
147940
  * Implements {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.2.4 Confirm Duplicate Update}.
@@ -147941,7 +147949,7 @@ a=end-of-candidates
147941
147949
  * @param {DidUpdatePayload} params.update The DID Update Payload to confirm.
147942
147950
  * @param {Array<string>} params.updateHashHistory The history of hashes for previously applied updates.
147943
147951
  * @returns {Promise<void>} A promise that resolves if the update is a duplicate, otherwise throws an error.
147944
- * @throws {DidBtc1Error} if the update hash does not match the historical hash.
147952
+ * @throws {ResolveError} if the update hash does not match the historical hash.
147945
147953
  */
147946
147954
  static async confirmDuplicateUpdate({ update, updateHashHistory }) {
147947
147955
  const unsecuredUpdate = update;
@@ -148089,7 +148097,7 @@ a=end-of-candidates
148089
148097
  id,
148090
148098
  controller,
148091
148099
  keys: new SchnorrKeyPair({
148092
- secretKey: SecretKey.decode(secretKeyMultibase)
148100
+ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase)
148093
148101
  })
148094
148102
  });
148095
148103
  if (!multikey) {
@@ -148158,7 +148166,7 @@ a=end-of-candidates
148158
148166
  };
148159
148167
 
148160
148168
  // src/did-btcr2.ts
148161
- initEccLib(tinysecp3);
148169
+ initEccLib(tinysecp4);
148162
148170
  var DidBtcr2 = class {
148163
148171
  /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
148164
148172
  static methodName = "btcr2";
@@ -148182,15 +148190,9 @@ a=end-of-candidates
148182
148190
  */
148183
148191
  static async create(params) {
148184
148192
  const { idType, options: options2 = {} } = params;
148185
- if (idType === IdentifierTypes.KEY) {
148186
- const { pubKeyBytes } = params;
148187
- return Create.deterministic({ pubKeyBytes, options: options2 });
148188
- }
148189
- if (idType === IdentifierTypes.EXTERNAL) {
148190
- const { intermediateDocument } = params;
148191
- return await Create.external({ intermediateDocument, options: options2 });
148192
- }
148193
- throw new MethodError('Invalid idType: expected "KEY" or "EXTERNAL"', INVALID_DID, params);
148193
+ const { version: version3 = 1, network = "bitcoin" } = options2;
148194
+ const genesisBytes = params.genesisBytes;
148195
+ return Identifier.encode({ idType, genesisBytes, version: version3, network });
148194
148196
  }
148195
148197
  /**
148196
148198
  * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Read}.
@@ -148263,7 +148265,7 @@ a=end-of-candidates
148263
148265
  * @param {string} params.identifier The btcr2 identifier to be updated.
148264
148266
  * @param {DidDocument} params.sourceDocument The DID document being updated.
148265
148267
  * @param {string} params.sourceVersionId The versionId of the source document.
148266
- * @param {Btc1DocumentPatch} params.documentPatch The JSON patch to be applied to the source document.
148268
+ * @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
148267
148269
  * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
148268
148270
  * @param {string[]} params.beaconIds The beacon IDs to announce the update
148269
148271
  * @returns {Promise<void>} Promise resolving to void
@@ -148331,7 +148333,7 @@ a=end-of-candidates
148331
148333
  };
148332
148334
 
148333
148335
  // src/core/crud/deactivate.ts
148334
- var Btc1Deactivate = class extends DidBtcr2 {
148336
+ var Deactivate = class extends DidBtcr2 {
148335
148337
  };
148336
148338
 
148337
148339
  // src/core/key-manager/interface.ts
@@ -148348,7 +148350,7 @@ a=end-of-candidates
148348
148350
 
148349
148351
  // src/utils/did-document-builder.ts
148350
148352
  init_shim();
148351
- var Btc1DidDocumentBuilder = class {
148353
+ var DidDocumentBuilder = class {
148352
148354
  document = {};
148353
148355
  constructor(initialDocument) {
148354
148356
  if (!initialDocument.id) {