@did-btcr2/method 0.20.0 → 0.23.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/README.md +223 -1
- package/dist/browser.js +2566 -3507
- package/dist/browser.mjs +2566 -3507
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +15 -3
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +6 -6
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -1
- package/dist/cjs/core/beacon/singleton.js +18 -20
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/identifier.js +11 -13
- package/dist/cjs/core/identifier.js.map +1 -1
- package/dist/cjs/core/resolve.js +52 -49
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +3 -4
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +36 -35
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +0 -6
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +44 -26
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +15 -3
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +1 -1
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +6 -6
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
- package/dist/esm/core/beacon/singleton.js +18 -20
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +1 -1
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +11 -13
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolve.js +52 -49
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +3 -4
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +36 -35
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +0 -6
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +44 -26
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +3 -3
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +5 -5
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton.d.ts +4 -4
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +17 -21
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +2 -2
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +10 -7
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +2 -2
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +12 -8
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +0 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +14 -9
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/core/beacon/aggregation/cohort/index.ts +13 -2
- package/src/core/beacon/aggregation/cohort/messages/base.ts +7 -2
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -12
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +5 -8
- package/src/core/beacon/aggregation/session/index.ts +15 -3
- package/src/core/beacon/beacon.ts +3 -3
- package/src/core/beacon/cas-beacon.ts +3 -3
- package/src/core/beacon/signal-discovery.ts +9 -9
- package/src/core/beacon/singleton.ts +21 -23
- package/src/core/beacon/smt-beacon.ts +3 -3
- package/src/core/identifier.ts +31 -28
- package/src/core/interfaces.ts +2 -2
- package/src/core/resolve.ts +73 -62
- package/src/core/update.ts +5 -5
- package/src/did-btcr2.ts +47 -43
- package/src/utils/did-document-builder.ts +0 -7
- package/src/utils/did-document.ts +54 -31
|
@@ -188,7 +188,7 @@ export class BeaconCohortSigningSession implements SigningSession {
|
|
|
188
188
|
`Missing ${missing} nonce contributions. ` +
|
|
189
189
|
`Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. ` +
|
|
190
190
|
`Current status: ${this.status}`,
|
|
191
|
-
'NONCE_CONTRIBUTION_ERROR', this.
|
|
191
|
+
'NONCE_CONTRIBUTION_ERROR', this.toJSON()
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
const sortedPubkeys = musig2.sortKeys(this.cohort.cohortKeys);
|
|
@@ -267,8 +267,20 @@ export class BeaconCohortSigningSession implements SigningSession {
|
|
|
267
267
|
* Converts the signing session instance to a JSON object representation.
|
|
268
268
|
* @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
|
|
269
269
|
*/
|
|
270
|
-
public
|
|
271
|
-
return
|
|
270
|
+
public toJSON(): Partial<BeaconCohortSigningSession> {
|
|
271
|
+
return {
|
|
272
|
+
id : this.id,
|
|
273
|
+
cohort : this.cohort,
|
|
274
|
+
pendingTx : this.pendingTx,
|
|
275
|
+
nonceContributions : this.nonceContributions,
|
|
276
|
+
aggregatedNonce : this.aggregatedNonce,
|
|
277
|
+
partialSignatures : this.partialSignatures,
|
|
278
|
+
signature : this.signature,
|
|
279
|
+
status : this.status,
|
|
280
|
+
processedRequests : this.processedRequests,
|
|
281
|
+
nonceSecrets : this.nonceSecrets,
|
|
282
|
+
musig2Session : this.musig2Session
|
|
283
|
+
};
|
|
272
284
|
}
|
|
273
285
|
|
|
274
286
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyBytes } from '@did-btcr2/common';
|
|
2
|
-
import {
|
|
2
|
+
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
3
3
|
import { SignedBTCR2Update } from '../../../../cryptosuite/dist/types/data-integrity-proof/interface.js';
|
|
4
4
|
import { SidecarData } from '../types.js';
|
|
5
5
|
import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
|
|
@@ -47,12 +47,12 @@ export abstract class Beacon {
|
|
|
47
47
|
* Used during the update path.
|
|
48
48
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
49
49
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
51
51
|
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
52
52
|
*/
|
|
53
53
|
abstract broadcastSignal(
|
|
54
54
|
signedUpdate: SignedBTCR2Update,
|
|
55
55
|
secretKey: KeyBytes,
|
|
56
|
-
bitcoin:
|
|
56
|
+
bitcoin: BitcoinConnection
|
|
57
57
|
): Promise<SignedBTCR2Update>;
|
|
58
58
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
2
|
import { KeyBytes } from '@did-btcr2/common';
|
|
3
3
|
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
4
4
|
import { SidecarData } from '../types.js';
|
|
@@ -39,14 +39,14 @@ export class CASBeacon extends Beacon {
|
|
|
39
39
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
40
40
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
41
41
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
43
43
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
44
44
|
* @throws {CASBeaconError} if broadcasting fails.
|
|
45
45
|
*/
|
|
46
46
|
async broadcastSignal(
|
|
47
47
|
signedUpdate: SignedBTCR2Update,
|
|
48
48
|
secretKey: KeyBytes,
|
|
49
|
-
bitcoin:
|
|
49
|
+
bitcoin: BitcoinConnection
|
|
50
50
|
): Promise<SignedBTCR2Update> {
|
|
51
51
|
throw new CASBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signedUpdate, secretKey, bitcoin});
|
|
52
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
BitcoinConnection,
|
|
3
3
|
BlockV3,
|
|
4
4
|
GENESIS_TX_ID,
|
|
5
5
|
RawTransactionV2,
|
|
@@ -21,23 +21,23 @@ export class BeaconSignalDiscovery {
|
|
|
21
21
|
* Retrieves the beacon signals for the given array of BeaconService objects
|
|
22
22
|
* using an esplora/electrs REST API connection via a bitcoin I/O driver.
|
|
23
23
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
|
|
24
|
-
* @param {
|
|
24
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for REST calls
|
|
25
25
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
|
|
26
26
|
*/
|
|
27
27
|
static async indexer(
|
|
28
28
|
beaconServices: Array<BeaconService>,
|
|
29
|
-
bitcoin:
|
|
29
|
+
bitcoin: BitcoinConnection
|
|
30
30
|
): Promise<Map<BeaconService, Array<BeaconSignal>>> {
|
|
31
31
|
const beaconServiceSignals = new Map<BeaconService, Array<BeaconSignal>>();
|
|
32
32
|
|
|
33
33
|
// Fetch the current block count once before the loop
|
|
34
|
-
const currentBlockCount = await bitcoin.
|
|
34
|
+
const currentBlockCount = await bitcoin.rest.block.count();
|
|
35
35
|
|
|
36
36
|
// Iterate over each beacon
|
|
37
37
|
for (const beaconService of beaconServices) {
|
|
38
38
|
beaconServiceSignals.set(beaconService, []);
|
|
39
39
|
// Get the transactions for the beacon address via REST
|
|
40
|
-
const beaconSignals = await bitcoin.
|
|
40
|
+
const beaconSignals = await bitcoin.rest.address.getTxs(
|
|
41
41
|
beaconService.serviceEndpoint as string
|
|
42
42
|
);
|
|
43
43
|
|
|
@@ -104,12 +104,12 @@ export class BeaconSignalDiscovery {
|
|
|
104
104
|
/**
|
|
105
105
|
* Traverse the full blockchain from genesis to chain top looking for beacon signals.
|
|
106
106
|
* @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
|
|
107
|
-
* @param {
|
|
107
|
+
* @param {BitcoinConnection} bitcoin Bitcoin network connection to use for RPC calls.
|
|
108
108
|
* @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
|
|
109
109
|
*/
|
|
110
110
|
static async fullnode(
|
|
111
111
|
beaconServices: Array<BeaconService>,
|
|
112
|
-
bitcoin:
|
|
112
|
+
bitcoin: BitcoinConnection
|
|
113
113
|
): Promise<Map<BeaconService, Array<BeaconSignal>>> {
|
|
114
114
|
const beaconServiceSignals = new Map<BeaconService, Array<BeaconSignal>>();
|
|
115
115
|
|
|
@@ -118,7 +118,7 @@ export class BeaconSignalDiscovery {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// Get the RPC connection from the bitcoin network
|
|
121
|
-
const rpc = bitcoin.
|
|
121
|
+
const rpc = bitcoin.rpc;
|
|
122
122
|
|
|
123
123
|
// Ensure that the RPC connection is available
|
|
124
124
|
if(!rpc) {
|
|
@@ -135,7 +135,7 @@ export class BeaconSignalDiscovery {
|
|
|
135
135
|
let height = 0;
|
|
136
136
|
|
|
137
137
|
// Opt into rpc connection to get the block data at the blockhash
|
|
138
|
-
let block = await bitcoin.
|
|
138
|
+
let block = await bitcoin.rpc!.getBlock({ height }) as BlockV3;
|
|
139
139
|
|
|
140
140
|
console.info(`Searching for beacon signals, please wait ...`);
|
|
141
141
|
while (block.height <= targetHeight) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { AddressUtxo,
|
|
2
|
-
import { INVALID_SIDECAR_DATA, KeyBytes, MISSING_UPDATE_DATA } from '@did-btcr2/common';
|
|
1
|
+
import { AddressUtxo, BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
|
+
import { Canonicalization, INVALID_SIDECAR_DATA, KeyBytes, MISSING_UPDATE_DATA } from '@did-btcr2/common';
|
|
3
3
|
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
4
4
|
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
5
|
-
import { Signer } from '@did-btcr2/kms';
|
|
6
5
|
import { opcodes, Psbt, script } from 'bitcoinjs-lib';
|
|
7
6
|
import { base58btc } from 'multiformats/bases/base58';
|
|
8
|
-
import { canonicalization } from '../../did-btcr2.js';
|
|
9
7
|
import { SidecarData } from '../types.js';
|
|
10
8
|
import { Beacon } from './beacon.js';
|
|
11
9
|
import { SingletonBeaconError } from './error.js';
|
|
@@ -15,7 +13,7 @@ import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
|
|
|
15
13
|
* Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#singleton-beacon | Singleton Beacon}.
|
|
16
14
|
* @class SingletonBeacon
|
|
17
15
|
* @type {SingletonBeacon}
|
|
18
|
-
* @extends {
|
|
16
|
+
* @extends {Beacon}
|
|
19
17
|
*/
|
|
20
18
|
export class SingletonBeacon extends Beacon {
|
|
21
19
|
|
|
@@ -56,10 +54,10 @@ export class SingletonBeacon extends Beacon {
|
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
// Canonicalize, hash and encode to
|
|
60
|
-
const encodedUpdate =
|
|
57
|
+
// Canonicalize, hash and encode to base58btc the signed update object found in sidecar or CAS
|
|
58
|
+
const encodedUpdate = Canonicalization.process(signedUpdate, { encoding: 'base58btc' });
|
|
61
59
|
|
|
62
|
-
// Encode the signal bytes hex string to
|
|
60
|
+
// Encode the signal bytes hex string to base58btc
|
|
63
61
|
const signalBytes = base58btc.encode(Buffer.from(updateHash, 'hex'));
|
|
64
62
|
|
|
65
63
|
// Check for mismatch between found sidecar/cas update hash and onchain beacon signal hash
|
|
@@ -82,20 +80,20 @@ export class SingletonBeacon extends Beacon {
|
|
|
82
80
|
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
83
81
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
84
82
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
85
|
-
* @param {
|
|
83
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
86
84
|
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
87
85
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
88
86
|
*/
|
|
89
87
|
async broadcastSignal(
|
|
90
88
|
signedUpdate: SignedBTCR2Update,
|
|
91
89
|
secretKey: KeyBytes,
|
|
92
|
-
bitcoin:
|
|
90
|
+
bitcoin: BitcoinConnection
|
|
93
91
|
): Promise<SignedBTCR2Update> {
|
|
94
92
|
// Convert the serviceEndpoint to a bitcoin address by removing the 'bitcoin:' prefix
|
|
95
93
|
const bitcoinAddress = this.service.serviceEndpoint.replace('bitcoin:', '');
|
|
96
94
|
|
|
97
95
|
// Query the Bitcoin network for UTXOs associated with the bitcoinAddress
|
|
98
|
-
const utxos = await bitcoin.
|
|
96
|
+
const utxos = await bitcoin.rest.address.getUtxos(bitcoinAddress);
|
|
99
97
|
|
|
100
98
|
// If no utxos are found, throw an error indicating the address is unfunded.
|
|
101
99
|
if(!utxos.length) {
|
|
@@ -119,13 +117,13 @@ export class SingletonBeacon extends Beacon {
|
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
// Get the previous tx to the utxo being spent
|
|
122
|
-
const prevTx = await bitcoin.
|
|
120
|
+
const prevTx = await bitcoin.rest.transaction.getHex(utxo.txid);
|
|
123
121
|
|
|
124
122
|
// Canonicalize and hash the signed update for OP_RETURN output
|
|
125
|
-
const updateHash =
|
|
123
|
+
const updateHash = Canonicalization.andHash(signedUpdate);
|
|
126
124
|
|
|
127
125
|
// Construct a spend transaction
|
|
128
|
-
const spendTx = new Psbt({ network: bitcoin.
|
|
126
|
+
const spendTx = new Psbt({ network: bitcoin.data })
|
|
129
127
|
// Spend tx contains the utxo as its input
|
|
130
128
|
.addInput({
|
|
131
129
|
hash : utxo.txid,
|
|
@@ -138,14 +136,12 @@ export class SingletonBeacon extends Beacon {
|
|
|
138
136
|
// Add an OP_RETURN output containing the update hash
|
|
139
137
|
.addOutput({ script: script.compile([opcodes.OP_RETURN, updateHash]), value: 0n });
|
|
140
138
|
|
|
141
|
-
// Construct a
|
|
139
|
+
// Construct a key pair and PSBT signer from the secret key
|
|
142
140
|
const keyPair = SchnorrKeyPair.fromSecret(secretKey);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// Construct a signer object from the key pair and bitcoin network
|
|
148
|
-
const signer = new Signer({ keyPair, network: bitcoin.network.name });
|
|
141
|
+
const signer = {
|
|
142
|
+
publicKey : keyPair.publicKey.compressed,
|
|
143
|
+
sign : (hash: Uint8Array) => keyPair.secretKey.sign(hash, { scheme: 'ecdsa' }),
|
|
144
|
+
};
|
|
149
145
|
|
|
150
146
|
// Sign 0th input, finalize extract to hex in prep for broadcast
|
|
151
147
|
const signedTx = spendTx.signInput(0, signer)
|
|
@@ -154,8 +150,10 @@ export class SingletonBeacon extends Beacon {
|
|
|
154
150
|
.toHex();
|
|
155
151
|
|
|
156
152
|
// Broadcast spendTx to the Bitcoin network.
|
|
157
|
-
const txid = await bitcoin.
|
|
158
|
-
|
|
153
|
+
const txid = await bitcoin.rest.transaction.send(signedTx);
|
|
154
|
+
|
|
155
|
+
// Log the txid of the broadcasted transaction
|
|
156
|
+
console.info(`Singleton Beacon Signal Broadcasted with txid: ${txid}`);
|
|
159
157
|
|
|
160
158
|
// Return the signed update
|
|
161
159
|
return signedUpdate;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
2
|
import { KeyBytes } from '@did-btcr2/common';
|
|
3
3
|
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
4
4
|
import { SidecarData } from '../types.js';
|
|
@@ -39,14 +39,14 @@ export class SMTBeacon extends Beacon {
|
|
|
39
39
|
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
40
40
|
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
41
41
|
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {BitcoinConnection} bitcoin The Bitcoin network connection.
|
|
43
43
|
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
44
44
|
* @throws {SMTBeaconError} if broadcasting fails.
|
|
45
45
|
*/
|
|
46
46
|
async broadcastSignal(
|
|
47
47
|
signedUpdate: SignedBTCR2Update,
|
|
48
48
|
secretKey: KeyBytes,
|
|
49
|
-
bitcoin:
|
|
49
|
+
bitcoin: BitcoinConnection
|
|
50
50
|
): Promise<SignedBTCR2Update> {
|
|
51
51
|
throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signedUpdate, secretKey, bitcoin});
|
|
52
52
|
}
|
package/src/core/identifier.ts
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import { BitcoinNetworkNames, Bytes, IdentifierError, IdentifierTypes, INVALID_DID, METHOD_NOT_SUPPORTED } from '@did-btcr2/common';
|
|
1
|
+
import { BitcoinNetworkNames, Bytes, DocumentBytes, IdentifierError, IdentifierTypes, INVALID_DID, KeyBytes, METHOD_NOT_SUPPORTED, SchnorrKeyPairObject } from '@did-btcr2/common';
|
|
2
2
|
import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
3
|
import { bech32m } from '@scure/base';
|
|
4
|
+
import { DidCreateOptions } from '../did-btcr2.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Components of a did:btcr2 identifier.
|
|
7
8
|
* @interface DidComponents
|
|
9
|
+
* @extends {IdentifierComponents}
|
|
8
10
|
* @property {string} hrp The human-readable part of the Bech32m encoding.
|
|
11
|
+
*/
|
|
12
|
+
export interface DidComponents extends IdentifierComponents {
|
|
13
|
+
hrp: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Components of a did:btcr2 identifier.
|
|
18
|
+
* @interface IdentifierComponents
|
|
9
19
|
* @property {string} idType Identifier type (key or external).
|
|
10
20
|
* @property {number} version Identifier version.
|
|
11
|
-
* @property {string
|
|
21
|
+
* @property {string} network Bitcoin network name or number.
|
|
12
22
|
* @property {Bytes} genesisBytes Public key or an intermediate document bytes.
|
|
13
23
|
*/
|
|
14
|
-
export interface
|
|
15
|
-
hrp: string;
|
|
24
|
+
export interface IdentifierComponents {
|
|
16
25
|
idType: string;
|
|
17
26
|
version: number;
|
|
18
27
|
network: string;
|
|
19
28
|
genesisBytes: Bytes;
|
|
20
|
-
}
|
|
21
|
-
|
|
29
|
+
}
|
|
22
30
|
/**
|
|
23
31
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#syntax | 3 Syntax}.
|
|
24
32
|
* A did:btcr2 DID consists of a did:btcr2 prefix, followed by an id-bech32 value, which is a Bech32m encoding of:
|
|
@@ -41,20 +49,15 @@ export class Identifier {
|
|
|
41
49
|
* - a key-value representing a secp256k1 public key; or
|
|
42
50
|
* - a hash-value representing the hash of an initiating external DID document.
|
|
43
51
|
*
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {string} params.network Bitcoin network name.
|
|
47
|
-
* @param {number} params.version Identifier version.
|
|
48
|
-
* @param {KeyBytes | DocumentBytes} params.genesisBytes Public key or an intermediate document bytes.
|
|
52
|
+
* @param {KeyBytes | DocumentBytes} genesisBytes The genesis bytes (public key or document bytes).
|
|
53
|
+
* @param {DidCreateOptions} options The DID creation options.
|
|
49
54
|
* @returns {string} The new did:btcr2 identifier.
|
|
50
55
|
*/
|
|
51
|
-
static encode(
|
|
52
|
-
|
|
53
|
-
version
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}): string {
|
|
57
|
-
// 1. If idType is not a valid value per above, raise invalidDid error.
|
|
56
|
+
static encode(genesisBytes: KeyBytes | DocumentBytes, options: DidCreateOptions): string {
|
|
57
|
+
// Deconstruct the options
|
|
58
|
+
const { idType, version = 1, network } = options;
|
|
59
|
+
|
|
60
|
+
// If idType is not a valid value per above, raise invalidDid error.
|
|
58
61
|
if (!(idType in IdentifierTypes)) {
|
|
59
62
|
throw new IdentifierError('Expected "idType" to be "KEY" or "EXTERNAL"', INVALID_DID, {idType});
|
|
60
63
|
}
|
|
@@ -275,16 +278,16 @@ export class Identifier {
|
|
|
275
278
|
* Generates a new did:btcr2 identifier based on a newly generated key pair.
|
|
276
279
|
* @returns {string} The new did:btcr2 identifier.
|
|
277
280
|
*/
|
|
278
|
-
static generate(): {
|
|
279
|
-
const
|
|
280
|
-
const did = this.encode(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return {
|
|
281
|
+
static generate(): { keyPair: SchnorrKeyPairObject; did: string } {
|
|
282
|
+
const keyPair = SchnorrKeyPair.generate();
|
|
283
|
+
const did = this.encode(keyPair.publicKey.compressed,
|
|
284
|
+
{
|
|
285
|
+
idType : 'KEY',
|
|
286
|
+
version : 1,
|
|
287
|
+
network : 'regtest'
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
return { keyPair: keyPair.toJSON(), did };
|
|
288
291
|
}
|
|
289
292
|
|
|
290
293
|
/**
|
package/src/core/interfaces.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
2
|
import { DidResolutionOptions } from '@web5/dids';
|
|
3
3
|
import { Sidecar } from './types.js';
|
|
4
4
|
|
|
@@ -44,7 +44,7 @@ export interface ResolutionOptions extends ResolutionOptionsCore {
|
|
|
44
44
|
* Drivers for interacting with external systems, such as the Bitcoin network.
|
|
45
45
|
*/
|
|
46
46
|
drivers?: {
|
|
47
|
-
bitcoin?:
|
|
47
|
+
bitcoin?: BitcoinConnection;
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
|