@did-btcr2/method 0.14.6 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +5346 -2734
- package/dist/browser.mjs +5346 -2734
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +4 -4
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/cid-aggregate.js +2 -2
- package/dist/cjs/core/beacon/singleton.js +4 -4
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/crud/create.js +4 -4
- package/dist/cjs/core/crud/create.js.map +1 -1
- package/dist/cjs/core/crud/deactivate.js +4 -4
- package/dist/cjs/core/crud/deactivate.js.map +1 -1
- package/dist/cjs/core/crud/read.js +42 -38
- package/dist/cjs/core/crud/read.js.map +1 -1
- package/dist/cjs/core/crud/update.js +2 -2
- package/dist/cjs/core/crud/update.js.map +1 -1
- package/dist/cjs/core/key-manager/index.js +5 -5
- package/dist/cjs/core/key-manager/index.js.map +1 -1
- package/dist/cjs/did-btcr2.js +3 -1
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/utils/appendix.js +4 -4
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +1 -1
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +2 -2
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/cjs/utils/identifier.js +5 -5
- package/dist/cjs/utils/identifier.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js +4 -4
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +1 -1
- package/dist/esm/core/beacon/cid-aggregate.js +2 -2
- package/dist/esm/core/beacon/singleton.js +4 -4
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/crud/create.js +4 -4
- package/dist/esm/core/crud/create.js.map +1 -1
- package/dist/esm/core/crud/deactivate.js +4 -4
- package/dist/esm/core/crud/deactivate.js.map +1 -1
- package/dist/esm/core/crud/read.js +42 -38
- package/dist/esm/core/crud/read.js.map +1 -1
- package/dist/esm/core/crud/update.js +2 -2
- package/dist/esm/core/crud/update.js.map +1 -1
- package/dist/esm/core/key-manager/index.js +5 -5
- package/dist/esm/core/key-manager/index.js.map +1 -1
- package/dist/esm/did-btcr2.js +3 -1
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/appendix.js +4 -4
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +1 -1
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +2 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/esm/utils/identifier.js +5 -5
- package/dist/esm/utils/identifier.js.map +1 -1
- package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +1 -1
- package/dist/types/core/beacon/cid-aggregate.d.ts +2 -2
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/crud/deactivate.d.ts +4 -4
- package/dist/types/core/crud/deactivate.d.ts.map +1 -1
- package/dist/types/core/crud/read.d.ts +17 -22
- package/dist/types/core/crud/read.d.ts.map +1 -1
- package/dist/types/core/key-manager/index.d.ts +6 -6
- package/dist/types/core/key-manager/index.d.ts.map +1 -1
- package/dist/types/core/key-manager/interface.d.ts +3 -3
- package/dist/types/core/key-manager/interface.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +1 -1
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/interfaces/crud.d.ts +3 -6
- package/dist/types/interfaces/crud.d.ts.map +1 -1
- package/dist/types/types/crud.d.ts +5 -5
- package/dist/types/types/crud.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +7 -7
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +1 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +1 -1
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/dist/types/utils/identifier.d.ts +2 -2
- package/dist/types/utils/identifier.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/core/beacon/aggregation/protocol/nostr.ts +4 -4
- package/src/core/beacon/cid-aggregate.ts +2 -2
- package/src/core/beacon/singleton.ts +4 -4
- package/src/core/crud/create.ts +4 -4
- package/src/core/crud/deactivate.ts +4 -4
- package/src/core/crud/read.ts +54 -45
- package/src/core/crud/update.ts +2 -2
- package/src/core/key-manager/index.ts +7 -7
- package/src/core/key-manager/interface.ts +3 -3
- package/src/did-btcr2.ts +4 -1
- package/src/interfaces/crud.ts +3 -6
- package/src/types/crud.ts +5 -5
- package/src/utils/appendix.ts +9 -9
- package/src/utils/did-document-builder.ts +1 -1
- package/src/utils/did-document.ts +2 -2
- package/src/utils/identifier.ts +5 -5
- package/dist/browser.js.map +0 -7
- package/dist/browser.mjs.map +0 -7
package/src/core/crud/read.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
BitcoinCoreRpcClient,
|
|
3
|
+
BitcoinNetworkConnection,
|
|
4
|
+
BitcoinRestClient,
|
|
5
5
|
BlockV3,
|
|
6
6
|
GENESIS_TX_ID,
|
|
7
7
|
getNetwork,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
UnixTimestamp
|
|
25
25
|
} from '@did-btcr2/common';
|
|
26
26
|
import { Cryptosuite, DataIntegrityProof, SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
27
|
-
import {
|
|
27
|
+
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
28
28
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
29
29
|
import { DidBtcr2 } from '../../did-btcr2.js';
|
|
30
30
|
import { DidResolutionOptions } from '../../interfaces/crud.js';
|
|
@@ -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:
|
|
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 =
|
|
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
|
|
98
|
+
const bitcoin = new BitcoinNetworkConnection();
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#read | 4.2 Read}.
|
|
@@ -136,8 +136,8 @@ export class Resolve {
|
|
|
136
136
|
// Deconstruct the components
|
|
137
137
|
const { network, genesisBytes } = identifierComponents;
|
|
138
138
|
|
|
139
|
-
// Construct a new
|
|
140
|
-
const { compressed: publicKey, multibase: publicKeyMultibase } = new
|
|
139
|
+
// Construct a new CompressedSecp256k1PublicKey and deconstruct the publicKey and publicKeyMultibase
|
|
140
|
+
const { compressed: publicKey, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(genesisBytes);
|
|
141
141
|
|
|
142
142
|
// Generate the service field for the DID Document
|
|
143
143
|
const service = BeaconUtils.generateBeaconServices({
|
|
@@ -154,7 +154,7 @@ export class Resolve {
|
|
|
154
154
|
id : `${identifier}#initialKey`,
|
|
155
155
|
type : 'Multikey',
|
|
156
156
|
controller : identifier,
|
|
157
|
-
publicKeyMultibase : publicKeyMultibase.
|
|
157
|
+
publicKeyMultibase : publicKeyMultibase.encoded
|
|
158
158
|
}],
|
|
159
159
|
service
|
|
160
160
|
});
|
|
@@ -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
|
|
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)
|
|
344
|
+
const signalsMetadata = (resolutionsOptions.sidecarData as SidecarData)?.signalsMetadata ?? {};
|
|
345
345
|
|
|
346
346
|
// 5. Set currentVersionId to 1
|
|
347
347
|
const currentVersionId = 1;
|
|
@@ -353,7 +353,7 @@ export class Resolve {
|
|
|
353
353
|
|
|
354
354
|
// 10. Set targetDocument to the result of calling the Traverse Bitcoin Blockchain History algorithm
|
|
355
355
|
// passing in contemporaryDIDDocument, contemporaryBlockheight, currentVersionId, targetVersionId,
|
|
356
|
-
// targetTime, didDocumentHistory,
|
|
356
|
+
// targetTime, didDocumentHistory, updateHashHistory, signalsMetadata, and network.
|
|
357
357
|
const targetDocument = this.traverseBlockchainHistory({
|
|
358
358
|
contemporaryDidDocument : initialDocument,
|
|
359
359
|
contemporaryBlockHeight : 0,
|
|
@@ -361,7 +361,7 @@ export class Resolve {
|
|
|
361
361
|
targetVersionId,
|
|
362
362
|
targetTime,
|
|
363
363
|
didDocumentHistory : new Array(),
|
|
364
|
-
|
|
364
|
+
updateHashHistory : new Array(),
|
|
365
365
|
signalsMetadata,
|
|
366
366
|
network
|
|
367
367
|
});
|
|
@@ -396,10 +396,10 @@ export class Resolve {
|
|
|
396
396
|
* @param {UnixTimestamp} params.targetTime The timestamp used to target specific historical states of a DID document.
|
|
397
397
|
* Only Beacon Signals included in the Bitcoin blockchain before the targetTime are processed.
|
|
398
398
|
* @param {boolean} params.didDocumentHistory An array of DID documents ordered ascensing by version (1...N).
|
|
399
|
-
* @param {boolean} params.
|
|
399
|
+
* @param {boolean} params.updateHashHistory 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 {
|
|
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({
|
|
@@ -409,7 +409,7 @@ export class Resolve {
|
|
|
409
409
|
targetVersionId,
|
|
410
410
|
targetTime,
|
|
411
411
|
didDocumentHistory,
|
|
412
|
-
|
|
412
|
+
updateHashHistory,
|
|
413
413
|
signalsMetadata,
|
|
414
414
|
network
|
|
415
415
|
}: {
|
|
@@ -419,9 +419,9 @@ export class Resolve {
|
|
|
419
419
|
targetVersionId?: number;
|
|
420
420
|
targetTime: number;
|
|
421
421
|
didDocumentHistory: DidDocument[];
|
|
422
|
-
|
|
422
|
+
updateHashHistory: string[];
|
|
423
423
|
signalsMetadata: SignalsMetadata;
|
|
424
|
-
network:
|
|
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');
|
|
@@ -463,8 +463,8 @@ export class Resolve {
|
|
|
463
463
|
// 10.1. If update.targetVersionId is less than or equal to currentVersionId, run Algorithm Confirm Duplicate
|
|
464
464
|
// Update passing in update, documentHistory, and contemporaryHash.
|
|
465
465
|
if (updateTargetVersionId <= currentVersionId) {
|
|
466
|
-
|
|
467
|
-
await this.confirmDuplicateUpdate({ update, updateHashHistory:
|
|
466
|
+
updateHashHistory.push(contemporaryHash);
|
|
467
|
+
await this.confirmDuplicateUpdate({ update, updateHashHistory: updateHashHistory });
|
|
468
468
|
|
|
469
469
|
// 10.2. If update.targetVersionId equals currentVersionId + 1:
|
|
470
470
|
} else if (updateTargetVersionId === currentVersionId + 1) {
|
|
@@ -498,8 +498,8 @@ export class Resolve {
|
|
|
498
498
|
// 10.2.7 Set updateHash to the result of passing unsecuredUpdate into the JSON Canonicalization and Hash algorithm.
|
|
499
499
|
const updateHash = await JSON.canonicalization.process(update, 'base58');
|
|
500
500
|
|
|
501
|
-
// 10.2.8. Push updateHash onto
|
|
502
|
-
|
|
501
|
+
// 10.2.8. Push updateHash onto updateHashHistory.
|
|
502
|
+
updateHashHistory.push(updateHash as string);
|
|
503
503
|
|
|
504
504
|
// 10.2.9. Set contemporaryHash to result of passing contemporaryDIDDocument into the JSON Canonicalization and Hash algorithm.
|
|
505
505
|
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.
|
|
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:
|
|
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
|
-
|
|
572
|
-
|
|
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);
|
|
573
579
|
}
|
|
574
580
|
|
|
575
|
-
//
|
|
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
|
+
);
|
|
587
|
+
}
|
|
588
|
+
|
|
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(
|
|
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
|
|
|
@@ -787,19 +796,19 @@ export class Resolve {
|
|
|
787
796
|
// Establish a Beacon instance using the service and sidecar
|
|
788
797
|
const beacon = BeaconFactory.establish(service, sidecar);
|
|
789
798
|
|
|
790
|
-
// 2.5 Set
|
|
791
|
-
const
|
|
799
|
+
// 2.5 Set didUpdate to null.
|
|
800
|
+
const didUpdate = await beacon.processSignal(signalTx, signalsMetadata) ?? null;
|
|
792
801
|
|
|
793
802
|
// If the updates is null, throw an error
|
|
794
|
-
if (!
|
|
795
|
-
throw new MethodError('No
|
|
803
|
+
if (!didUpdate) {
|
|
804
|
+
throw new MethodError('No didUpdate for beacon', 'PROCESS_BEACON_SIGNALS_ERROR', { tx, signalsMetadata });
|
|
796
805
|
}
|
|
797
806
|
|
|
798
|
-
// 2.9 If
|
|
799
|
-
updates.push(
|
|
807
|
+
// 2.9 If didUpdate is not null, push didUpdate to updates.
|
|
808
|
+
updates.push(didUpdate);
|
|
800
809
|
|
|
801
810
|
// 3. Return updates.
|
|
802
|
-
return
|
|
811
|
+
return didUpdate;
|
|
803
812
|
}
|
|
804
813
|
|
|
805
814
|
/**
|
|
@@ -815,7 +824,7 @@ export class Resolve {
|
|
|
815
824
|
* @param {DidUpdatePayload} params.update The DID Update Payload to confirm.
|
|
816
825
|
* @param {Array<string>} params.updateHashHistory The history of hashes for previously applied updates.
|
|
817
826
|
* @returns {Promise<void>} A promise that resolves if the update is a duplicate, otherwise throws an error.
|
|
818
|
-
* @throws {
|
|
827
|
+
* @throws {ResolveError} if the update hash does not match the historical hash.
|
|
819
828
|
*/
|
|
820
829
|
public static async confirmDuplicateUpdate({ update, updateHashHistory }: {
|
|
821
830
|
update: DidUpdatePayload;
|
package/src/core/crud/update.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
ProofOptions
|
|
13
13
|
} from '@did-btcr2/common';
|
|
14
14
|
import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
15
|
-
import { SchnorrKeyPair,
|
|
15
|
+
import { SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
|
|
16
16
|
import type { DidService } from '@web5/dids';
|
|
17
17
|
import { BeaconService } from '../../interfaces/ibeacon.js';
|
|
18
18
|
import { SignalsMetadata } from '../../types/crud.js';
|
|
@@ -158,7 +158,7 @@ export class Update {
|
|
|
158
158
|
id,
|
|
159
159
|
controller,
|
|
160
160
|
keys : new SchnorrKeyPair({
|
|
161
|
-
secretKey :
|
|
161
|
+
secretKey : Secp256k1SecretKey.decode(secretKeyMultibase)
|
|
162
162
|
})
|
|
163
163
|
});
|
|
164
164
|
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
SignatureBytes
|
|
11
11
|
} from '@did-btcr2/common';
|
|
12
12
|
import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
13
|
-
import {
|
|
13
|
+
import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
14
14
|
import { sha256 } from '@noble/hashes/sha2';
|
|
15
15
|
import { KeyValueStore, MemoryStore } from '@web5/common';
|
|
16
16
|
import { KeyIdentifier } from '@web5/crypto';
|
|
@@ -104,11 +104,11 @@ export class KeyManager implements IKeyManager, CryptoSigner, BitcoinSigner {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* Gets the key pair from the key store and returns a
|
|
107
|
+
* Gets the key pair from the key store and returns a CompressedSecp256k1PublicKey.
|
|
108
108
|
* @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
|
|
109
|
-
* @returns {Promise<
|
|
109
|
+
* @returns {Promise<CompressedSecp256k1PublicKey>} The public key associated with the key URI.
|
|
110
110
|
*/
|
|
111
|
-
public async getPublicKey(keyUri?: KeyIdentifier): Promise<
|
|
111
|
+
public async getPublicKey(keyUri?: KeyIdentifier): Promise<CompressedSecp256k1PublicKey> {
|
|
112
112
|
// Use the active key URI if not provided
|
|
113
113
|
const key = await this.getKey(keyUri);
|
|
114
114
|
|
|
@@ -264,13 +264,13 @@ export class KeyManager implements IKeyManager, CryptoSigner, BitcoinSigner {
|
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
266
|
* Computes a multibase-compliant URI from a key.
|
|
267
|
-
* @param key A SchnorrKeyPair,
|
|
267
|
+
* @param key A SchnorrKeyPair, CompressedSecp256k1PublicKey, or multibase string
|
|
268
268
|
* @returns {string} A multibase URI (e.g. 'urn:mb:zQ3s...')
|
|
269
269
|
*/
|
|
270
|
-
public static toMultibaseUri(data: SchnorrKeyPair |
|
|
270
|
+
public static toMultibaseUri(data: SchnorrKeyPair | CompressedSecp256k1PublicKey | Multibase<'zQ3s'>): string {
|
|
271
271
|
const multibase = data instanceof SchnorrKeyPair
|
|
272
272
|
? data.publicKey.multibase
|
|
273
|
-
: data instanceof
|
|
273
|
+
: data instanceof CompressedSecp256k1PublicKey
|
|
274
274
|
? data.multibase
|
|
275
275
|
: data;
|
|
276
276
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HashBytes, Hex, SignatureBytes } from '@did-btcr2/common';
|
|
2
2
|
import { Multikey, SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
3
|
-
import { SchnorrKeyPair,
|
|
3
|
+
import { SchnorrKeyPair, CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
4
4
|
import { KeyValueStore } from '@web5/common';
|
|
5
5
|
|
|
6
6
|
export type KeyManagerOptions = {
|
|
@@ -77,9 +77,9 @@ export interface IKeyManager {
|
|
|
77
77
|
/**
|
|
78
78
|
* Gets the public key of a key pair.
|
|
79
79
|
* @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
|
|
80
|
-
* @returns {Promise<
|
|
80
|
+
* @returns {Promise<CompressedSecp256k1PublicKey>} The public key of the key pair.
|
|
81
81
|
*/
|
|
82
|
-
getPublicKey(keyUri: KeyIdentifier): Promise<
|
|
82
|
+
getPublicKey(keyUri: KeyIdentifier): Promise<CompressedSecp256k1PublicKey>;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Imports a key pair into the key store.
|
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 });
|
|
@@ -173,7 +176,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
173
176
|
* @param {string} params.identifier The btcr2 identifier to be updated.
|
|
174
177
|
* @param {DidDocument} params.sourceDocument The DID document being updated.
|
|
175
178
|
* @param {string} params.sourceVersionId The versionId of the source document.
|
|
176
|
-
* @param {
|
|
179
|
+
* @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
|
|
177
180
|
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update
|
|
178
181
|
* @param {string[]} params.beaconIds The beacon IDs to announce the update
|
|
179
182
|
* @returns {Promise<void>} Promise resolving to void
|
package/src/interfaces/crud.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnixTimestamp } from '@did-btcr2/common';
|
|
2
2
|
import { DidResolutionOptions as IDidResolutionOptions } from '@web5/dids';
|
|
3
|
-
import { BitcoinRpc } from '@did-btcr2/bitcoin';
|
|
4
3
|
import { SidecarData } from '../types/crud.js';
|
|
5
4
|
import { DidDocument } from '../utils/did-document.js';
|
|
6
5
|
|
|
@@ -8,17 +7,15 @@ import { DidDocument } from '../utils/did-document.js';
|
|
|
8
7
|
* Options for resolving a DID Document
|
|
9
8
|
* @param {?number} versionId The versionId for resolving the DID Document
|
|
10
9
|
* @param {?UnixTimestamp} versionTime The versionTime for resolving the DID Document
|
|
11
|
-
* @param {?BitcoinRpc} rpc BitcoinRpc client connection
|
|
12
10
|
* @param {?SidecarData} sidecarData The sidecar data for resolving the DID Document
|
|
13
11
|
*/
|
|
14
12
|
export interface DidResolutionOptions extends IDidResolutionOptions {
|
|
15
13
|
versionId?: number
|
|
16
14
|
versionTime?: UnixTimestamp;
|
|
17
15
|
sidecarData?: SidecarData;
|
|
18
|
-
network?:
|
|
19
|
-
rpc?: BitcoinRpc;
|
|
16
|
+
network?: string;
|
|
20
17
|
}
|
|
21
|
-
export interface
|
|
18
|
+
export interface RootCapability {
|
|
22
19
|
'@context': string;
|
|
23
20
|
id: string;
|
|
24
21
|
controller: string;
|
package/src/types/crud.ts
CHANGED
|
@@ -8,23 +8,23 @@ export type FindNextSignals = {
|
|
|
8
8
|
beacons: BeaconService[]
|
|
9
9
|
};
|
|
10
10
|
export type Metadata = {
|
|
11
|
-
|
|
11
|
+
didUpdate: DidUpdatePayload;
|
|
12
12
|
proofs?: string;
|
|
13
13
|
};
|
|
14
14
|
export type SignalSidecarData = Metadata;
|
|
15
|
-
export interface
|
|
15
|
+
export interface Sidecar {
|
|
16
16
|
did: string;
|
|
17
17
|
}
|
|
18
18
|
export type SignalsMetadata = { [signalId: string]: Metadata; };
|
|
19
|
-
export interface SingletonSidecar extends
|
|
19
|
+
export interface SingletonSidecar extends Sidecar {
|
|
20
20
|
signalsMetadata: SignalsMetadata;
|
|
21
21
|
}
|
|
22
|
-
export interface CIDAggregateSidecar extends
|
|
22
|
+
export interface CIDAggregateSidecar extends Sidecar {
|
|
23
23
|
initialDocument: DidDocument;
|
|
24
24
|
signalsMetadata: SignalsMetadata;
|
|
25
25
|
cidUpdates: Array<string>;
|
|
26
26
|
}
|
|
27
|
-
export interface SMTAggregateSidecar extends
|
|
27
|
+
export interface SMTAggregateSidecar extends Sidecar {
|
|
28
28
|
initialDocument: DidDocument;
|
|
29
29
|
signalsMetadata: SignalsMetadata;
|
|
30
30
|
smtProof: ProofBytes;
|
package/src/utils/appendix.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { createHelia } from 'helia';
|
|
11
11
|
import { CID } from 'multiformats';
|
|
12
12
|
import { create as createDigest } from 'multiformats/hashes/digest';
|
|
13
|
-
import {
|
|
13
|
+
import { RootCapability } from '../interfaces/crud.js';
|
|
14
14
|
import { DidVerificationMethod } from './did-document.js';
|
|
15
15
|
|
|
16
16
|
export interface DidComponents {
|
|
@@ -97,7 +97,7 @@ export class Appendix {
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-
|
|
100
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-didbtcr2-identifier | 9.4.1 Derive Root Capability from did:btcr2 Identifier }.
|
|
101
101
|
*
|
|
102
102
|
* The Derive Root Capability algorithm deterministically generates a ZCAP-LD root capability from a given did:btcr2
|
|
103
103
|
* identifier. Each root capability is unique to the identifier. This root capability is defined and understood by the
|
|
@@ -105,7 +105,7 @@ export class Appendix {
|
|
|
105
105
|
* document. It takes in a did:btcr2 identifier and returns a rootCapability object. It returns the root capability.
|
|
106
106
|
*
|
|
107
107
|
* @param {string} identifier The did-btcr2 identifier to derive the root capability from
|
|
108
|
-
* @returns {
|
|
108
|
+
* @returns {RootCapability} The root capability object
|
|
109
109
|
* @example Root capability for updating the DID document for
|
|
110
110
|
* did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u
|
|
111
111
|
* ```
|
|
@@ -117,9 +117,9 @@ export class Appendix {
|
|
|
117
117
|
* }
|
|
118
118
|
* ```
|
|
119
119
|
*/
|
|
120
|
-
public static deriveRootCapability(identifier: string):
|
|
120
|
+
public static deriveRootCapability(identifier: string): RootCapability {
|
|
121
121
|
// 1. Define rootCapability as an empty object.
|
|
122
|
-
const rootCapability = {} as
|
|
122
|
+
const rootCapability = {} as RootCapability;
|
|
123
123
|
|
|
124
124
|
// 2. Set rootCapability.@context to ‘https://w3id.org/zcap/v1’.
|
|
125
125
|
rootCapability['@context'] = W3C_ZCAP_V1;
|
|
@@ -148,7 +148,7 @@ export class Appendix {
|
|
|
148
148
|
* capability object.
|
|
149
149
|
*
|
|
150
150
|
* @param {string} capabilityId The root capability identifier to dereference.
|
|
151
|
-
* @returns {
|
|
151
|
+
* @returns {RootCapability} The root capability object.
|
|
152
152
|
* @example a didUpdatePayload with an invoked ZCAP-LD capability containing a patch defining how the DID document
|
|
153
153
|
* for did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u SHOULD be mutated.
|
|
154
154
|
* ```
|
|
@@ -174,16 +174,16 @@ export class Appendix {
|
|
|
174
174
|
* "cryptosuite": "schnorr-secp256k1-jcs-2025",
|
|
175
175
|
* "verificationMethod": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u#initialKey",
|
|
176
176
|
* "invocationTarget": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
177
|
-
* "capability": "urn:zcap:root:did%
|
|
177
|
+
* "capability": "urn:zcap:root:did%3Abtcr2%3Ak1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
178
178
|
* "capabilityAction": "Write",
|
|
179
179
|
* "proofPurpose": "assertionMethod",
|
|
180
180
|
* "proofValue": "z381yXYmxU8NudZ4HXY56DfMN6zfD8syvWcRXzT9xD9uYoQToo8QsXD7ahM3gXTzuay5WJbqTswt2BKaGWYn2hHhVFKJLXaDz"
|
|
181
181
|
* }
|
|
182
182
|
* }
|
|
183
183
|
*/
|
|
184
|
-
public static derefernceRootCapabilityIdentifier(capabilityId: string):
|
|
184
|
+
public static derefernceRootCapabilityIdentifier(capabilityId: string): RootCapability {
|
|
185
185
|
// 1. Set rootCapability to an empty object.
|
|
186
|
-
const rootCapability = {} as
|
|
186
|
+
const rootCapability = {} as RootCapability;
|
|
187
187
|
|
|
188
188
|
// 2. Set components to the result of capabilityId.split(":").
|
|
189
189
|
const [urn, zcap, root, did] = capabilityId.split(':') ?? [];
|
|
@@ -2,7 +2,7 @@ import { DidDocumentError, INVALID_DID_DOCUMENT } from '@did-btcr2/common';
|
|
|
2
2
|
import { BeaconService } from '../interfaces/ibeacon.js';
|
|
3
3
|
import { DidDocument, DidVerificationMethod } from './did-document.js';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class DidDocumentBuilder {
|
|
6
6
|
private document: Partial<DidDocument> = {};
|
|
7
7
|
|
|
8
8
|
constructor(initialDocument: Partial<DidDocument>) {
|
|
@@ -14,7 +14,7 @@ import { BeaconUtils } from './beacons.js';
|
|
|
14
14
|
import { Identifier } from './identifier.js';
|
|
15
15
|
|
|
16
16
|
export const BECH32M_CHARS = '';
|
|
17
|
-
export const
|
|
17
|
+
export const DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
|
|
18
18
|
|
|
19
19
|
export type ExternalData = {
|
|
20
20
|
id: string,
|
|
@@ -432,7 +432,7 @@ export class DidDocument implements IDidDocument {
|
|
|
432
432
|
*/
|
|
433
433
|
export class IntermediateDidDocument extends DidDocument {
|
|
434
434
|
constructor(document: IDidDocument) {
|
|
435
|
-
const intermediateDocument = JSON.cloneReplace(document,
|
|
435
|
+
const intermediateDocument = JSON.cloneReplace(document, DID_REGEX, ID_PLACEHOLDER_VALUE) as IDidDocument;
|
|
436
436
|
super(intermediateDocument);
|
|
437
437
|
}
|
|
438
438
|
|
package/src/utils/identifier.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BitcoinNetworkNames, MethodError, IdentifierTypes, Bytes, INVALID_DID, METHOD_NOT_SUPPORTED } from '@did-btcr2/common';
|
|
2
|
-
import {
|
|
2
|
+
import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
3
|
import { bech32m } from '@scure/base';
|
|
4
4
|
import { DidComponents } from './appendix.js';
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ import { DidComponents } from './appendix.js';
|
|
|
16
16
|
*/
|
|
17
17
|
export class Identifier {
|
|
18
18
|
/**
|
|
19
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#
|
|
19
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-encoding | 3.2 did:btcr2 Identifier Encoding}.
|
|
20
20
|
*
|
|
21
21
|
* A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
|
|
22
22
|
* - the specification version;
|
|
@@ -61,7 +61,7 @@ export class Identifier {
|
|
|
61
61
|
// 5. If idType is “key” and genesisBytes is not a valid compressed secp256k1 public key, raise invalidDid error.
|
|
62
62
|
if (idType === 'KEY') {
|
|
63
63
|
try {
|
|
64
|
-
new
|
|
64
|
+
new CompressedSecp256k1PublicKey(genesisBytes);
|
|
65
65
|
} catch {
|
|
66
66
|
throw new MethodError(
|
|
67
67
|
'Expected "genesisBytes" to be a valid compressed secp256k1 public key',
|
|
@@ -125,7 +125,7 @@ export class Identifier {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#
|
|
128
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#didbtcr2-identifier-decoding | 3.3 did:btcr2 Identifier Decoding}.
|
|
129
129
|
* @param {string} identifier The BTCR2 DID to be parsed
|
|
130
130
|
* @returns {DidComponents} The parsed identifier components. See {@link DidComponents} for details.
|
|
131
131
|
* @throws {DidError} if an error occurs while parsing the identifier
|
|
@@ -248,7 +248,7 @@ export class Identifier {
|
|
|
248
248
|
// 19. If idType is “key” and genesisBytes is not a valid compressed secp256k1 public key, raise invalidDid error.
|
|
249
249
|
if (idType === 'KEY') {
|
|
250
250
|
try {
|
|
251
|
-
new
|
|
251
|
+
new CompressedSecp256k1PublicKey(genesisBytes);
|
|
252
252
|
} catch {
|
|
253
253
|
throw new MethodError(`Invalid genesisBytes: ${genesisBytes}`, INVALID_DID, { identifier });
|
|
254
254
|
}
|