@did-btcr2/method 0.14.6 → 0.15.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.
@@ -1 +1 @@
1
- {"version":3,"file":"did-btcr2.d.ts","sourceRoot":"","sources":["../../src/did-btcr2.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAIL,SAAS,EAEV,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAU,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAM7E;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,YAAW,SAAS;IACxC,uFAAuF;IACvF,OAAc,UAAU,EAAE,MAAM,CAAW;IAE3C;;;;;;;;;;;;;;;;;OAiBG;WACiB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IA0BzE;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACiB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAwC5H;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;WACiB,MAAM,CAAC,MAAM,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,WAAW,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;QACxB,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,GAAG,OAAO,CAAC,GAAG,CAAC;IAuDhB;;;;;;;;;;;OAWG;WACW,gBA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;;;;;;OAWG;WACW,gBAAgB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;QACxD,WAAW,EAAE,WAAW,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,qBAAqB;CA0B1B"}
@@ -1,21 +1,21 @@
1
- import { BitcoinNetworkNames, UnixTimestamp } from '@did-btcr2/common';
1
+ import { BitcoinCoreRpcClient } from '@did-btcr2/bitcoin';
2
+ import { UnixTimestamp } from '@did-btcr2/common';
2
3
  import { DidResolutionOptions as IDidResolutionOptions } from '@web5/dids';
3
- import { BitcoinRpc } from '@did-btcr2/bitcoin';
4
4
  import { SidecarData } from '../types/crud.js';
5
5
  import { DidDocument } from '../utils/did-document.js';
6
6
  /**
7
7
  * Options for resolving a DID Document
8
8
  * @param {?number} versionId The versionId for resolving the DID Document
9
9
  * @param {?UnixTimestamp} versionTime The versionTime for resolving the DID Document
10
- * @param {?BitcoinRpc} rpc BitcoinRpc client connection
10
+ * @param {?BitcoinCoreRpcClient} rpc BitcoinCoreRpcClient client connection
11
11
  * @param {?SidecarData} sidecarData The sidecar data for resolving the DID Document
12
12
  */
13
13
  export interface DidResolutionOptions extends IDidResolutionOptions {
14
14
  versionId?: number;
15
15
  versionTime?: UnixTimestamp;
16
16
  sidecarData?: SidecarData;
17
- network?: BitcoinNetworkNames;
18
- rpc?: BitcoinRpc;
17
+ network?: string;
18
+ rpc?: BitcoinCoreRpcClient;
19
19
  }
20
20
  export interface Btc1RootCapability {
21
21
  '@context': string;
@@ -1 +1 @@
1
- {"version":3,"file":"crud.d.ts","sourceRoot":"","sources":["../../../src/interfaces/crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,oBAAoB,IAAI,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,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,qBAAqB;IACjE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,oBAAoB,CAAC;CAC5B;AACD,MAAM,WAAW,kBAAkB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AACD,MAAM,WAAW,oBAAoB;IACnC,uBAAuB,EAAE,WAAW,CAAC;IACrC,uBAAuB,EAAE,MAAM,GAAG,CAAC,CAAC;IACpC,gBAAgB,EAAE,MAAM,GAAG,CAAC,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-btcr2/method",
3
- "version": "0.14.6",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "Javascript/TypeScript reference implementation of did:btcr2 method, a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the DID document. Core package of the did-btcr2-js monorepo.",
6
6
  "main": "./dist/cjs/index.js",
@@ -64,6 +64,7 @@
64
64
  "bitcoin"
65
65
  ],
66
66
  "dependencies": {
67
+ "@bitcoinerlab/secp256k1": "^1.2.0",
67
68
  "@helia/strings": "^4.0.2",
68
69
  "@noble/curves": "^1.8.1",
69
70
  "@noble/hashes": "^1.5.0",
@@ -75,7 +76,6 @@
75
76
  "@web5/common": "^1.1.0",
76
77
  "@web5/crypto": "^1.0.6",
77
78
  "@web5/dids": "^1.2.0",
78
- "bitcoin-core": "^5.0.0",
79
79
  "bitcoinjs-lib": "7.0.0-rc.0",
80
80
  "canonicalize": "^2.1.0",
81
81
  "dotenv": "^16.5.0",
@@ -83,10 +83,10 @@
83
83
  "multiformats": "^13.3.1",
84
84
  "nostr-tools": "^2.15.0",
85
85
  "tiny-secp256k1": "^2.2.3",
86
- "@did-btcr2/keypair": "0.5.1",
87
- "@did-btcr2/bitcoin": "0.1.2",
86
+ "@did-btcr2/bitcoin": "0.2.0",
88
87
  "@did-btcr2/common": "2.1.0",
89
- "@did-btcr2/cryptosuite": "3.1.0"
88
+ "@did-btcr2/cryptosuite": "3.1.0",
89
+ "@did-btcr2/keypair": "0.5.1"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@eslint/js": "^9.22.0",
@@ -1,4 +1,4 @@
1
- import { AddressUtxo, Bitcoin, RawTransactionRest, RawTransactionV2, TxOut, Vout } from '@did-btcr2/bitcoin';
1
+ import { AddressUtxo, BitcoinNetworkConnection, RawTransactionRest, RawTransactionV2, TxOut, Vout } from '@did-btcr2/bitcoin';
2
2
  import { DidUpdatePayload, INVALID_SIDECAR_DATA, LATE_PUBLISHING_ERROR, SingletonBeaconError } from '@did-btcr2/common';
3
3
  import { opcodes, Psbt, script } from 'bitcoinjs-lib';
4
4
  import { base58btc } from 'multiformats/bases/base58';
@@ -8,7 +8,7 @@ import { BeaconSidecarData, Metadata, SignalsMetadata, SingletonSidecar } from '
8
8
  import { Appendix } from '../../utils/appendix.js';
9
9
  import { KeyManager, Signer } from '../key-manager/index.js';
10
10
 
11
- const bitcoin = new Bitcoin();
11
+ const bitcoin = new BitcoinNetworkConnection();
12
12
 
13
13
  /**
14
14
  * Implements {@link https://dcdpr.github.io/did-btcr2/#singleton-beacon | 5.1 Singleton Beacon}.
@@ -1,7 +1,7 @@
1
1
  import {
2
- Bitcoin,
3
- BitcoinRest,
4
- BitcoinRpc,
2
+ BitcoinCoreRpcClient,
3
+ BitcoinNetworkConnection,
4
+ BitcoinRestClient,
5
5
  BlockV3,
6
6
  GENESIS_TX_ID,
7
7
  getNetwork,
@@ -40,13 +40,13 @@ import { DidDocument } from '../../utils/did-document.js';
40
40
  import { BeaconFactory } from '../beacon/factory.js';
41
41
 
42
42
  export type FindNextSignalsRestParams = {
43
- connection: BitcoinRest;
43
+ connection: BitcoinRestClient;
44
44
  beaconSignals: Array<BeaconSignal>;
45
45
  block: BlockV3;
46
46
  beacons: Array<BeaconServiceAddress>;
47
47
  }
48
48
  export type BeaconSignals = Array<BeaconSignal>;
49
- export type BitcoinClient = BitcoinRpc | BitcoinRest;
49
+ export type BitcoinClient = BitcoinCoreRpcClient | BitcoinRestClient;
50
50
 
51
51
  export type NetworkVersion = {
52
52
  version?: string;
@@ -95,7 +95,7 @@ export interface TargetBlockheightParams {
95
95
  targetTime?: UnixTimestamp;
96
96
  }
97
97
 
98
- const bitcoin = new Bitcoin();
98
+ const bitcoin = new BitcoinNetworkConnection();
99
99
 
100
100
  /**
101
101
  * Implements {@link https://dcdpr.github.io/did-btcr2/#read | 4.2 Read}.
@@ -331,7 +331,7 @@ export class Resolve {
331
331
  resolutionsOptions: DidResolutionOptions;
332
332
  }): Promise<DidDocument> {
333
333
  // Set the network from the options or default to mainnet
334
- const network = resolutionsOptions.network ?? BitcoinNetworkNames.bitcoin;
334
+ const network = resolutionsOptions.network!;
335
335
 
336
336
  // 1. If resolutionOptions.versionId is not null, set targetVersionId to resolutionOptions.versionId.
337
337
  const targetVersionId = resolutionsOptions.versionId;
@@ -341,7 +341,7 @@ export class Resolve {
341
341
  const targetTime = resolutionsOptions.versionTime ?? new Date().toUnix();
342
342
 
343
343
  // 4. Set signalsMetadata to resolutionOptions.sidecarData.signalsMetadata.
344
- const signalsMetadata = (resolutionsOptions.sidecarData as SidecarData).signalsMetadata;
344
+ const signalsMetadata = (resolutionsOptions.sidecarData as SidecarData)?.signalsMetadata ?? {};
345
345
 
346
346
  // 5. Set currentVersionId to 1
347
347
  const currentVersionId = 1;
@@ -399,7 +399,7 @@ export class Resolve {
399
399
  * @param {boolean} params.btc1UpdateHashHistory An array of SHA256 hashes of BTCR2 Updates ordered by version that are
400
400
  * applied to the DID document in order to construct the contemporaryDIDDocument.
401
401
  * @param {SignalsMetadata} params.signalsMetadata See {@link SignalsMetadata} for details.
402
- * @param {BitcoinNetworkNames} params.network The bitcoin network to connect to (mainnet, signet, testnet, regtest).
402
+ * @param {string} params.network The bitcoin network to connect to (mainnet, signet, testnet, regtest).
403
403
  * @returns {Promise<DidDocument>} The resolved DID Document object with a validated single, canonical history.
404
404
  */
405
405
  protected static async traverseBlockchainHistory({
@@ -421,7 +421,7 @@ export class Resolve {
421
421
  didDocumentHistory: DidDocument[];
422
422
  btc1UpdateHashHistory: string[];
423
423
  signalsMetadata: SignalsMetadata;
424
- network: BitcoinNetworkNames;
424
+ network: string;
425
425
  }): Promise<DidDocument> {
426
426
  // 1. Set contemporaryHash to the SHA256 hash of the contemporaryDidDocument
427
427
  let contemporaryHash = await JSON.canonicalization.process(contemporaryDidDocument, 'base58');
@@ -552,15 +552,17 @@ export class Resolve {
552
552
  *
553
553
  * @public
554
554
  * @param {FindNextSignals} params The parameters for the findNextSignals operation.
555
- * @param {number} params.blockheight The blockheight to start looking for beacon signals.
556
- * @param {Array<BeaconService>} params.target The target blockheight at which to stop finding signals.
555
+ * @param {number} params.contemporaryBlockHeight The blockheight to start looking for beacon signals.
557
556
  * @param {Array<BeaconService>} params.beacons The beacons to look for in the block.
557
+ * @param {Array<BeaconService>} params.network The bitcoin network to connect to (mainnet, signet, testnet, regtest).
558
+ * @param {UnixTimestamp} params.targetTime The timestamp used to target specific historical states of a DID document.
559
+ * Only Beacon Signals included in the Bitcoin blockchain before the targetTime are processed.
558
560
  * @returns {Promise<Array<BeaconSignal>>} An array of BeaconSignal objects with blockHeight and signals.
559
561
  */
560
- public static async findNextSignals({ contemporaryBlockHeight, targetTime, beacons }: {
562
+ public static async findNextSignals({ contemporaryBlockHeight, targetTime, network, beacons }: {
561
563
  contemporaryBlockHeight: number;
562
564
  beacons: Array<BeaconServiceAddress>;
563
- network: BitcoinNetworkNames;
565
+ network: string;
564
566
  targetTime: UnixTimestamp;
565
567
  }): Promise<Array<BeaconSignal>> {
566
568
  let height = contemporaryBlockHeight;
@@ -568,11 +570,23 @@ export class Resolve {
568
570
  // Create an default beaconSignal and beaconSignals array
569
571
  let beaconSignals: BeaconSignals = [];
570
572
 
571
- if (bitcoin.network.rest) {
572
- return await this.findSignalsRest({ beacons });
573
+ // Get the bitcoin network connection
574
+ bitcoin.setActiveNetwork(network);
575
+
576
+ // Opt into REST connection if available
577
+ if(bitcoin.network.rest) {
578
+ return await this.findSignalsRest(beacons);
579
+ }
580
+
581
+ // If no rest and no rpc connection is available, throw an error
582
+ if (!bitcoin.network.rpc) {
583
+ throw new ResolveError(
584
+ `No Bitcoin connection available, cannot find next signals`,
585
+ 'NO_BITCOIN_CONNECTION'
586
+ );
573
587
  }
574
588
 
575
- // Use connection to get the block data at the blockhash
589
+ // Opt into rpc connection to get the block data at the blockhash
576
590
  let block = await bitcoin.network.rpc.getBlock({ height }) as BlockV3;
577
591
 
578
592
  Logger.info(`Searching for signals, please wait ...`);
@@ -666,15 +680,10 @@ export class Resolve {
666
680
 
667
681
  /**
668
682
  * Helper method for the {@link findNextSignals | Find Next Signals} algorithm.
669
- *
670
- * @param params See {@link FindNextSignalsRestParams} for details.
671
- * @param {BitcoinClient} params.connection The bitcoin connection to use.
672
- * @param {Array<BeaconSignal>} params.beaconSignals The beacon signals to process.
673
- * @param {BlockV3} params.block The block to process.
674
- * @param {Array<BeaconService>} params.beacons The beacons to process.
683
+ * @param {Array<BeaconService>} beacons The beacons to process.
675
684
  * @returns {Promise<Array<BeaconSignal>>} The beacon signals found in the block.
676
685
  */
677
- public static async findSignalsRest({ beacons }: { beacons: Array<BeaconService>; }): Promise<Array<BeaconSignal>> {
686
+ public static async findSignalsRest(beacons: Array<BeaconService>): Promise<Array<BeaconSignal>> {
678
687
  // Empty array of beaconSignals
679
688
  const beaconSignals = new Array<BeaconSignal>();
680
689
 
package/src/did-btcr2.ts CHANGED
@@ -118,6 +118,9 @@ export class DidBtcr2 implements DidMethod {
118
118
  // 2. Set identifierComponents to a map of idType, version, network, and genesisBytes.
119
119
  const identifierComponents = Identifier.decode(identifier);
120
120
 
121
+ // Set the network based on the decoded identifier
122
+ resolutionsOptions.network ??= identifierComponents.network;
123
+
121
124
  // 3. Set initialDocument to the result of running the algorithm in Resolve Initial Document passing in the
122
125
  // identifier, identifierComponents and resolutionOptions.
123
126
  const initialDocument = await Resolve.initialDocument({ identifier, identifierComponents, resolutionsOptions });
@@ -1,6 +1,6 @@
1
- import { BitcoinNetworkNames, UnixTimestamp } from '@did-btcr2/common';
1
+ import { BitcoinCoreRpcClient } from '@did-btcr2/bitcoin';
2
+ import { UnixTimestamp } from '@did-btcr2/common';
2
3
  import { DidResolutionOptions as IDidResolutionOptions } from '@web5/dids';
3
- import { BitcoinRpc } from '@did-btcr2/bitcoin';
4
4
  import { SidecarData } from '../types/crud.js';
5
5
  import { DidDocument } from '../utils/did-document.js';
6
6
 
@@ -8,15 +8,15 @@ import { DidDocument } from '../utils/did-document.js';
8
8
  * Options for resolving a DID Document
9
9
  * @param {?number} versionId The versionId for resolving the DID Document
10
10
  * @param {?UnixTimestamp} versionTime The versionTime for resolving the DID Document
11
- * @param {?BitcoinRpc} rpc BitcoinRpc client connection
11
+ * @param {?BitcoinCoreRpcClient} rpc BitcoinCoreRpcClient client connection
12
12
  * @param {?SidecarData} sidecarData The sidecar data for resolving the DID Document
13
13
  */
14
14
  export interface DidResolutionOptions extends IDidResolutionOptions {
15
15
  versionId?: number
16
16
  versionTime?: UnixTimestamp;
17
17
  sidecarData?: SidecarData;
18
- network?: BitcoinNetworkNames;
19
- rpc?: BitcoinRpc;
18
+ network?: string;
19
+ rpc?: BitcoinCoreRpcClient;
20
20
  }
21
21
  export interface Btc1RootCapability {
22
22
  '@context': string;