@did-btcr2/method 0.18.1 → 0.20.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 +4917 -6487
- package/dist/browser.mjs +4917 -6487
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +3 -3
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +1 -9
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/coordinator.js +14 -14
- package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/participant.js +4 -3
- package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/cjs/core/beacon/beacon.js +25 -0
- package/dist/cjs/core/beacon/beacon.js.map +1 -0
- package/dist/cjs/core/beacon/cas-beacon.js +39 -0
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -0
- package/dist/cjs/core/beacon/error.js +4 -4
- package/dist/cjs/core/beacon/error.js.map +1 -1
- package/dist/cjs/core/beacon/factory.js +10 -11
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/interfaces.js +2 -0
- package/dist/cjs/core/beacon/interfaces.js.map +1 -0
- package/dist/cjs/core/beacon/signal-discovery.js +183 -0
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
- package/dist/cjs/core/beacon/singleton.js +75 -178
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +39 -0
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -0
- package/dist/cjs/core/beacon/utils.js +71 -114
- package/dist/cjs/core/beacon/utils.js.map +1 -1
- package/dist/cjs/core/identifier.js +18 -21
- package/dist/cjs/core/identifier.js.map +1 -1
- package/dist/cjs/core/interfaces.js +2 -0
- package/dist/cjs/core/interfaces.js.map +1 -0
- package/dist/cjs/core/resolve.js +321 -0
- package/dist/cjs/core/resolve.js.map +1 -0
- package/dist/cjs/{utils → core}/types.js.map +1 -1
- package/dist/cjs/core/update.js +113 -0
- package/dist/cjs/core/update.js.map +1 -0
- package/dist/cjs/did-btcr2.js +168 -129
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +17 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/appendix.js +16 -33
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +5 -0
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +62 -72
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/cjs/utils/general.js +1 -1
- package/dist/cjs/utils/general.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/index.js +3 -3
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +1 -9
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/coordinator.js +14 -14
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/participant.js +4 -3
- package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +25 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -0
- package/dist/esm/core/beacon/cas-beacon.js +39 -0
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -0
- package/dist/esm/core/beacon/error.js +4 -4
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +10 -11
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/interfaces.js +2 -0
- package/dist/esm/core/beacon/interfaces.js.map +1 -0
- package/dist/esm/core/beacon/signal-discovery.js +183 -0
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
- package/dist/esm/core/beacon/singleton.js +75 -178
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +39 -0
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -0
- package/dist/esm/core/beacon/utils.js +71 -114
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/identifier.js +18 -21
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/interfaces.js +2 -0
- package/dist/esm/core/interfaces.js.map +1 -0
- package/dist/esm/core/resolve.js +321 -0
- package/dist/esm/core/resolve.js.map +1 -0
- package/dist/esm/{utils → core}/types.js.map +1 -1
- package/dist/esm/core/update.js +113 -0
- package/dist/esm/core/update.js.map +1 -0
- package/dist/esm/did-btcr2.js +168 -129
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +17 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +16 -33
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +5 -0
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +62 -72
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/esm/utils/general.js +1 -1
- package/dist/esm/utils/general.js.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +0 -7
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +13 -5
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +17 -29
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +44 -0
- package/dist/types/core/beacon/beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/cas-beacon.d.ts +36 -0
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/error.d.ts +2 -2
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +4 -5
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/interfaces.d.ts +59 -0
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -0
- package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
- package/dist/types/core/beacon/singleton.d.ts +20 -76
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +36 -0
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/utils.d.ts +19 -97
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +87 -0
- package/dist/types/core/interfaces.d.ts.map +1 -0
- package/dist/types/core/resolve.d.ts +89 -0
- package/dist/types/core/resolve.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +84 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/core/update.d.ts +51 -0
- package/dist/types/core/update.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +70 -89
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +17 -16
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +5 -10
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +6 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +46 -42
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/core/beacon/aggregation/cohort/index.ts +3 -3
- package/src/core/beacon/aggregation/cohort/messages/base.ts +1 -12
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -2
- package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -2
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +43 -21
- package/src/core/beacon/aggregation/coordinator.ts +41 -29
- package/src/core/beacon/aggregation/participant.ts +4 -3
- package/src/core/beacon/aggregation/session/index.ts +1 -1
- package/src/core/beacon/beacon.ts +58 -0
- package/src/core/beacon/cas-beacon.ts +53 -0
- package/src/core/beacon/error.ts +5 -6
- package/src/core/beacon/factory.ts +12 -16
- package/src/core/beacon/interfaces.ts +67 -0
- package/src/core/beacon/signal-discovery.ts +237 -0
- package/src/core/beacon/singleton.ts +107 -197
- package/src/core/beacon/smt-beacon.ts +53 -0
- package/src/core/beacon/utils.ts +95 -182
- package/src/core/identifier.ts +21 -24
- package/src/core/interfaces.ts +93 -0
- package/src/core/resolve.ts +463 -0
- package/src/core/types.ts +95 -0
- package/src/core/update.ts +154 -0
- package/src/did-btcr2.ts +255 -159
- package/src/index.ts +19 -22
- package/src/utils/appendix.ts +26 -44
- package/src/utils/did-document-builder.ts +6 -1
- package/src/utils/did-document.ts +105 -113
- package/src/utils/general.ts +1 -1
- package/dist/cjs/core/beacon/cid-aggregate.js +0 -116
- package/dist/cjs/core/beacon/cid-aggregate.js.map +0 -1
- package/dist/cjs/core/beacon/smt-aggregate.js +0 -126
- package/dist/cjs/core/beacon/smt-aggregate.js.map +0 -1
- package/dist/cjs/core/crud/deactivate.js +0 -14
- package/dist/cjs/core/crud/deactivate.js.map +0 -1
- package/dist/cjs/core/crud/read.js +0 -679
- package/dist/cjs/core/crud/read.js.map +0 -1
- package/dist/cjs/core/crud/update.js +0 -194
- package/dist/cjs/core/crud/update.js.map +0 -1
- package/dist/cjs/interfaces/beacon.js +0 -41
- package/dist/cjs/interfaces/beacon.js.map +0 -1
- package/dist/cjs/interfaces/crud.js +0 -2
- package/dist/cjs/interfaces/crud.js.map +0 -1
- package/dist/esm/core/beacon/cid-aggregate.js +0 -116
- package/dist/esm/core/beacon/cid-aggregate.js.map +0 -1
- package/dist/esm/core/beacon/smt-aggregate.js +0 -126
- package/dist/esm/core/beacon/smt-aggregate.js.map +0 -1
- package/dist/esm/core/crud/deactivate.js +0 -14
- package/dist/esm/core/crud/deactivate.js.map +0 -1
- package/dist/esm/core/crud/read.js +0 -679
- package/dist/esm/core/crud/read.js.map +0 -1
- package/dist/esm/core/crud/update.js +0 -194
- package/dist/esm/core/crud/update.js.map +0 -1
- package/dist/esm/interfaces/beacon.js +0 -41
- package/dist/esm/interfaces/beacon.js.map +0 -1
- package/dist/esm/interfaces/crud.js +0 -2
- package/dist/esm/interfaces/crud.js.map +0 -1
- package/dist/types/core/beacon/cid-aggregate.d.ts +0 -102
- package/dist/types/core/beacon/cid-aggregate.d.ts.map +0 -1
- package/dist/types/core/beacon/smt-aggregate.d.ts +0 -111
- package/dist/types/core/beacon/smt-aggregate.d.ts.map +0 -1
- package/dist/types/core/crud/deactivate.d.ts +0 -13
- package/dist/types/core/crud/deactivate.d.ts.map +0 -1
- package/dist/types/core/crud/read.d.ts +0 -334
- package/dist/types/core/crud/read.d.ts.map +0 -1
- package/dist/types/core/crud/update.d.ts +0 -93
- package/dist/types/core/crud/update.d.ts.map +0 -1
- package/dist/types/interfaces/beacon.d.ts +0 -116
- package/dist/types/interfaces/beacon.d.ts.map +0 -1
- package/dist/types/interfaces/crud.d.ts +0 -32
- package/dist/types/interfaces/crud.d.ts.map +0 -1
- package/dist/types/utils/types.d.ts +0 -38
- package/dist/types/utils/types.d.ts.map +0 -1
- package/src/canonicalize.d.ts +0 -6
- package/src/core/beacon/cid-aggregate.ts +0 -153
- package/src/core/beacon/smt-aggregate.ts +0 -135
- package/src/core/crud/deactivate.ts +0 -13
- package/src/core/crud/read.ts +0 -948
- package/src/core/crud/update.ts +0 -292
- package/src/interfaces/beacon.ts +0 -137
- package/src/interfaces/crud.ts +0 -33
- package/src/utils/types.ts +0 -41
- /package/dist/cjs/{utils → core}/types.js +0 -0
- /package/dist/esm/{utils → core}/types.js +0 -0
|
@@ -1,253 +1,163 @@
|
|
|
1
|
-
import { AddressUtxo, BitcoinNetworkConnection
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { AddressUtxo, BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
|
|
2
|
+
import { INVALID_SIDECAR_DATA, KeyBytes, MISSING_UPDATE_DATA } from '@did-btcr2/common';
|
|
3
|
+
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
4
|
+
import { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
5
|
+
import { Signer } from '@did-btcr2/kms';
|
|
5
6
|
import { opcodes, Psbt, script } from 'bitcoinjs-lib';
|
|
6
7
|
import { base58btc } from 'multiformats/bases/base58';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
const bitcoin = new BitcoinNetworkConnection();
|
|
8
|
+
import { canonicalization } from '../../did-btcr2.js';
|
|
9
|
+
import { SidecarData } from '../types.js';
|
|
10
|
+
import { Beacon } from './beacon.js';
|
|
11
|
+
import { SingletonBeaconError } from './error.js';
|
|
12
|
+
import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
16
|
-
*
|
|
17
|
-
* A Singleton Beacon enables a single entity to independently post a DID Update Payload in a Beacon Signal. Its is a
|
|
18
|
-
* Beacon that can be used to publish a single DID Update Payload targeting a single DID document. The serviceEndpoint
|
|
19
|
-
* for this Beacon Type is a Bitcoin address represented as a URI following the BIP21 scheme. It is recommended that
|
|
20
|
-
* this Bitcoin address be under the sole control of the DID controller. How the Bitcoin address and the cryptographic
|
|
21
|
-
* material that controls it are generated is left to the implementation.
|
|
22
|
-
*
|
|
15
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#singleton-beacon | Singleton Beacon}.
|
|
23
16
|
* @class SingletonBeacon
|
|
24
17
|
* @type {SingletonBeacon}
|
|
25
|
-
* @extends {
|
|
18
|
+
* @extends {AggregateBeacon}
|
|
26
19
|
*/
|
|
27
20
|
export class SingletonBeacon extends Beacon {
|
|
28
21
|
|
|
29
22
|
/**
|
|
30
23
|
* Creates an instance of SingletonBeacon.
|
|
31
|
-
* @param {BeaconService} service The
|
|
32
|
-
* @param {?BeaconSidecarData} [sidecar] Optional sidecar data.
|
|
33
|
-
*/
|
|
34
|
-
constructor(service: BeaconService, sidecar?: BeaconSidecarData<SingletonSidecar>) {
|
|
35
|
-
super({ ...service, type: 'SingletonBeacon' }, sidecar);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get the Beacon service.
|
|
40
|
-
* @readonly
|
|
41
|
-
* @type {BeaconService} The Beacon service.
|
|
42
|
-
*/
|
|
43
|
-
get service(): BeaconService {
|
|
44
|
-
return {
|
|
45
|
-
type : this.type,
|
|
46
|
-
id : this.id,
|
|
47
|
-
serviceEndpoint : this.serviceEndpoint
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/#establish-singleton-beacon | 5.1.1 Establish Singleton Beacon}.
|
|
53
|
-
*
|
|
54
|
-
* Static, convenience method for establishing a Beacon object.
|
|
55
|
-
*
|
|
56
|
-
* A Singleton Beacon is a Beacon that can be used to publish a single DID Update Payload targeting a single DID
|
|
57
|
-
* document. The serviceEndpoint for this Beacon Type is a Bitcoin address represented as a URI following the BIP21
|
|
58
|
-
* scheme. It is RECOMMENDED that this Bitcoin address be under the sole control of the DID controller. How the
|
|
59
|
-
* Bitcoin address and the cryptographic material that controls it are generated is left to the implementation.
|
|
60
|
-
* The Establish Singleton Beacon algorithm takes in a Bitcoin address and a serviceId and returns a Singleton Beacon service.
|
|
61
|
-
* It returns a SignletonBeacon object with the given id, type, and serviceEndpoint.
|
|
24
|
+
* @param {BeaconService} service The BeaconService object representing the funded beacon to announce the update to.
|
|
62
25
|
*
|
|
63
|
-
* @param {string} service The Beacon service.
|
|
64
|
-
* @param {BeaconSidecarData<SingletonSidecar>} sidecar The sidecar data.
|
|
65
|
-
* @returns {SingletonBeacon} The Singleton Beacon.
|
|
66
26
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
27
|
+
constructor(service: BeaconService) {
|
|
28
|
+
super({ ...service, type: 'SingletonBeacon' });
|
|
69
29
|
}
|
|
70
30
|
|
|
71
31
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
* @throws {MethodError} if the signal is invalid.
|
|
32
|
+
* Processes an array of Beacon Signals associated with a Singleton Beacon Service.
|
|
33
|
+
* @returns {Promise<SignedBTCR2Update | undefined>} The DID Update payload announced by the Beacon Signal.
|
|
34
|
+
* @throws {SingletonBeaconError} if the signalTx is invalid or the signalSidecarData is invalid.
|
|
76
35
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// 1. Initialize a txOut variable to the 0th transaction output of the tx.
|
|
99
|
-
const output = signal.vout.filter((vout) => ((vout as Vout)['scriptpubkey_asm'] as string || (vout as TxOut)['scriptPubKey'].asm as string).includes('OP_RETURN'))?.[0];
|
|
100
|
-
if(!output) {
|
|
101
|
-
throw new SingletonBeaconError('No OP_RETURN output found in transaction outputs.', 'NO_OP_RETURN', { signal });
|
|
102
|
-
}
|
|
103
|
-
const outputMap = new Map(Object.entries(output));
|
|
104
|
-
|
|
105
|
-
// 2. Set didUpdatePayload to null.
|
|
106
|
-
let didUpdatePayload: DidUpdatePayload | undefined = undefined;
|
|
107
|
-
|
|
108
|
-
// 3. Check txout is of the format [OP_RETURN, OP_PUSH32, <32bytes>], if not, then return didUpdatePayload.
|
|
109
|
-
// The Bitcoin transaction is not a Beacon Signal.
|
|
110
|
-
const UPDATE_PAYLOAD_HASH = (outputMap.get('scriptpubkey_asm') ?? outputMap.get('scriptPubKey').asm).split(' ').last() as string;
|
|
111
|
-
if(!UPDATE_PAYLOAD_HASH) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
// 4. Set hashBytes to the 32 bytes in the txout.
|
|
115
|
-
const hashBytes = JSON.canonicalization.encode(Buffer.fromHex(UPDATE_PAYLOAD_HASH), 'base58');
|
|
116
|
-
|
|
117
|
-
// Convert signalsMetadata to a Map for easier access
|
|
118
|
-
const signalsMetadataMap = new Map<string, Metadata>(Object.entries(signalsMetadata));
|
|
119
|
-
|
|
120
|
-
// 5. If signalsMetadata:
|
|
121
|
-
if (signalsMetadata) {
|
|
122
|
-
// 5.1 Set didUpdatePayload to signalsMetadata.updatePayload
|
|
123
|
-
didUpdatePayload = signalsMetadataMap.get(signal.txid)?.didUpdate;
|
|
124
|
-
|
|
125
|
-
if(!didUpdatePayload) {
|
|
126
|
-
throw new SingletonBeaconError('Update Payload not found in signal metadata.', 'PROCESS_SIGNAL_ERROR');
|
|
36
|
+
async processSignals(
|
|
37
|
+
signals: Array<BeaconSignal>,
|
|
38
|
+
sidecar: SidecarData
|
|
39
|
+
): Promise<Array<[SignedBTCR2Update, BlockMetadata]>> {
|
|
40
|
+
// Initialize an empty array to hold the BTCR2 signed updates
|
|
41
|
+
const updates = new Array<[SignedBTCR2Update, BlockMetadata]>();
|
|
42
|
+
|
|
43
|
+
// Loop through each signal in signals
|
|
44
|
+
for(const signal of signals) {
|
|
45
|
+
// Grab the beacon signal bytes hash from the signal
|
|
46
|
+
const updateHash = signal.signalBytes;
|
|
47
|
+
|
|
48
|
+
// Use the updateHash as the sidecar data lookup key to retrieve the btcr2 update
|
|
49
|
+
const signedUpdate = sidecar.updateMap.get(updateHash);
|
|
50
|
+
|
|
51
|
+
// If no btcr2 update is found in sidecar data maps, throw missingUpdateData error.
|
|
52
|
+
if(!signedUpdate) {
|
|
53
|
+
throw new SingletonBeaconError(
|
|
54
|
+
`BTCR2 Signed Update not found for update hash ${updateHash}.`,
|
|
55
|
+
MISSING_UPDATE_DATA, signal
|
|
56
|
+
);
|
|
127
57
|
}
|
|
128
58
|
|
|
129
|
-
//
|
|
130
|
-
const
|
|
59
|
+
// Canonicalize, hash and encode to base58 the signed update object found in sidecar or CAS
|
|
60
|
+
const encodedUpdate = canonicalization.process(signedUpdate, { encoding: 'base58' });
|
|
131
61
|
|
|
132
|
-
//
|
|
133
|
-
|
|
62
|
+
// Encode the signal bytes hex string to base58
|
|
63
|
+
const signalBytes = base58btc.encode(Buffer.from(updateHash, 'hex'));
|
|
64
|
+
|
|
65
|
+
// Check for mismatch between found sidecar/cas update hash and onchain beacon signal hash
|
|
66
|
+
if (encodedUpdate !== signalBytes) {
|
|
67
|
+
// If mismatch, throw invalidSidecarData error.
|
|
134
68
|
throw new SingletonBeaconError(
|
|
135
|
-
`Hash mismatch:
|
|
136
|
-
INVALID_SIDECAR_DATA,
|
|
137
|
-
{ UPDATE_PAYLOAD_HASH, didUpdatePayload }
|
|
69
|
+
`Hash mismatch: sidecar update ${encodedUpdate} !== signal bytes ${signalBytes}.`,
|
|
70
|
+
INVALID_SIDECAR_DATA, { encodedUpdate, signalBytes }
|
|
138
71
|
);
|
|
139
72
|
}
|
|
140
|
-
// 7. Return didUpdatePayload.
|
|
141
|
-
return didUpdatePayload;
|
|
142
|
-
}
|
|
143
73
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const didUpdatePayloadString = await Appendix.fetchFromCas(base58btc.decode(hashBytes));
|
|
147
|
-
if(!didUpdatePayloadString || !JSON.parse(didUpdatePayloadString)) {
|
|
148
|
-
throw new SingletonBeaconError('Update payload not found in addressable storage.', INVALID_SIDECAR_DATA);
|
|
74
|
+
// Push signedUpdate to updates array
|
|
75
|
+
updates.push([signedUpdate, signal.blockMetadata]);
|
|
149
76
|
}
|
|
150
|
-
didUpdatePayload = JSON.parse(didUpdatePayloadString) as DidUpdatePayload;
|
|
151
77
|
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
throw new SingletonBeaconError('Update payload hash does not match transaction hash.', LATE_PUBLISHING_ERROR);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 7. Return didUpdatePayload.
|
|
158
|
-
return didUpdatePayload;
|
|
78
|
+
// Return the array of signed updates
|
|
79
|
+
return updates;
|
|
159
80
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
81
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* identified in the service and contains a transaction output of the format [OP_RETURN, OP_PUSH32, <hashBytes>],
|
|
169
|
-
* where hashBytes is the SHA256 hash of the canonical didUpdatePayload. The Bitcoin transaction is then signed and
|
|
170
|
-
* broadcast to the Bitcoin network, thereby publicly announcing a DID update in a Beacon Signal. It returns a
|
|
171
|
-
* signalMetadata object mapping the Bitcoin transaction identifier of the Beacon Signal to the necessary data needed
|
|
172
|
-
* to verify the signal announces a specific DID Update Payload.
|
|
173
|
-
*
|
|
174
|
-
* TODO: Design and implement a way to construct, sign and send via RPC
|
|
175
|
-
*
|
|
176
|
-
* @param {DidUpdatePayload} didUpdatePayload The verificationMethod object to be used for signing.
|
|
177
|
-
* @returns {SignedRawTx} Successful output of a bitcoin transaction.
|
|
82
|
+
* Broadcasts a SingletonBeacon signal to the Bitcoin network.
|
|
83
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
84
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
85
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
86
|
+
* @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
|
|
178
87
|
* @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
|
|
179
88
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
89
|
+
async broadcastSignal(
|
|
90
|
+
signedUpdate: SignedBTCR2Update,
|
|
91
|
+
secretKey: KeyBytes,
|
|
92
|
+
bitcoin: BitcoinNetworkConnection
|
|
93
|
+
): Promise<SignedBTCR2Update> {
|
|
94
|
+
// Convert the serviceEndpoint to a bitcoin address by removing the 'bitcoin:' prefix
|
|
183
95
|
const bitcoinAddress = this.service.serviceEndpoint.replace('bitcoin:', '');
|
|
184
96
|
|
|
185
|
-
//
|
|
186
|
-
// let inputs: Array<CreateRawTxInputs> = [];
|
|
187
|
-
|
|
97
|
+
// Query the Bitcoin network for UTXOs associated with the bitcoinAddress
|
|
188
98
|
const utxos = await bitcoin.network.rest.address.getUtxos(bitcoinAddress);
|
|
99
|
+
|
|
100
|
+
// If no utxos are found, throw an error indicating the address is unfunded.
|
|
189
101
|
if(!utxos.length) {
|
|
190
|
-
|
|
191
|
-
|
|
102
|
+
throw new SingletonBeaconError(
|
|
103
|
+
'No UTXOs found, please fund address!',
|
|
104
|
+
'UNFUNDED_BEACON_ADDRESS', { bitcoinAddress }
|
|
105
|
+
);
|
|
192
106
|
}
|
|
193
107
|
|
|
194
|
-
|
|
108
|
+
// Sort utxos by block height and take the most recent one
|
|
109
|
+
const utxo: AddressUtxo | undefined = utxos.sort(
|
|
110
|
+
(a, b) => b.status.block_height - a.status.block_height
|
|
111
|
+
).shift();
|
|
112
|
+
|
|
113
|
+
// If no utxos are found, throw an error.
|
|
195
114
|
if(!utxo) {
|
|
196
115
|
throw new SingletonBeaconError(
|
|
197
116
|
'Beacon bitcoin address unfunded or utxos unconfirmed.',
|
|
198
|
-
'UNFUNDED_BEACON_ADDRESS', { bitcoinAddress }
|
|
117
|
+
'UNFUNDED_BEACON_ADDRESS', { bitcoinAddress }
|
|
118
|
+
);
|
|
199
119
|
}
|
|
200
120
|
|
|
201
|
-
//
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
const {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
.addInput(input)
|
|
121
|
+
// Get the previous tx to the utxo being spent
|
|
122
|
+
const prevTx = await bitcoin.network.rest.transaction.getHex(utxo.txid);
|
|
123
|
+
|
|
124
|
+
// Canonicalize and hash the signed update for OP_RETURN output
|
|
125
|
+
const updateHash = canonicalization.canonicalhash(signedUpdate);
|
|
126
|
+
|
|
127
|
+
// Construct a spend transaction
|
|
128
|
+
const spendTx = new Psbt({ network: bitcoin.network.data })
|
|
129
|
+
// Spend tx contains the utxo as its input
|
|
130
|
+
.addInput({
|
|
131
|
+
hash : utxo.txid,
|
|
132
|
+
index : utxo.vout,
|
|
133
|
+
nonWitnessUtxo : Buffer.from(prevTx, 'hex')
|
|
134
|
+
})
|
|
135
|
+
// Add a change output minus a fee of 500 sats
|
|
136
|
+
// TODO: calculate fee based on transaction vsize and current fee rates
|
|
218
137
|
.addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) })
|
|
219
|
-
|
|
138
|
+
// Add an OP_RETURN output containing the update hash
|
|
139
|
+
.addOutput({ script: script.compile([opcodes.OP_RETURN, updateHash]), value: 0n });
|
|
220
140
|
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
const components = Identifier.decode(this.service.id);
|
|
224
|
-
const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
|
|
225
|
-
const keyPair = Kms.getKey(keyUri as string);
|
|
141
|
+
// Construct a Schnorr key pair from the secret key
|
|
142
|
+
const keyPair = SchnorrKeyPair.fromSecret(secretKey);
|
|
226
143
|
if (!keyPair) {
|
|
227
|
-
throw new
|
|
144
|
+
throw new SingletonBeaconError('Key pair not found.', 'KEY_PAIR_NOT_FOUND', { secretKey });
|
|
228
145
|
}
|
|
229
146
|
|
|
147
|
+
// Construct a signer object from the key pair and bitcoin network
|
|
230
148
|
const signer = new Signer({ keyPair, network: bitcoin.network.name });
|
|
231
149
|
|
|
232
|
-
//
|
|
150
|
+
// Sign 0th input, finalize extract to hex in prep for broadcast
|
|
233
151
|
const signedTx = spendTx.signInput(0, signer)
|
|
234
152
|
.finalizeAllInputs()
|
|
235
153
|
.extractTransaction()
|
|
236
154
|
.toHex();
|
|
237
|
-
if(!spendTx) {
|
|
238
|
-
throw new SingletonBeaconError('Failed to sign raw transaction.', 'RAW_TX_SIGN_FAILED', { spendTx });
|
|
239
|
-
}
|
|
240
155
|
|
|
241
|
-
//
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
throw new SingletonBeaconError('Failed to send raw transaction.', 'SEND_FAILED', { spentTx });
|
|
245
|
-
}
|
|
156
|
+
// Broadcast spendTx to the Bitcoin network.
|
|
157
|
+
const txid = await bitcoin.network.rest.transaction.send(signedTx);
|
|
158
|
+
console.info(`Broadcasted Singleton Beacon signal with txid ${txid}`);
|
|
246
159
|
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
// 11. Set signalMetadata.updatePayload to didUpdatePayload.
|
|
250
|
-
// 12. Return the object {<signalId>: { updatePayload: DidUpdatePayload; proofs?: any; }}.
|
|
251
|
-
return { [spentTx]: { didUpdate: didUpdatePayload } };
|
|
160
|
+
// Return the signed update
|
|
161
|
+
return signedUpdate;
|
|
252
162
|
}
|
|
253
163
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
|
|
2
|
+
import { KeyBytes } from '@did-btcr2/common';
|
|
3
|
+
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
4
|
+
import { SidecarData } from '../types.js';
|
|
5
|
+
import { Beacon } from './beacon.js';
|
|
6
|
+
import { SMTBeaconError } from './error.js';
|
|
7
|
+
import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#smt-beacon | SMTBeacon}.
|
|
11
|
+
* @class SMTBeacon
|
|
12
|
+
* @type {SMTBeacon}
|
|
13
|
+
* @extends {Beacon}
|
|
14
|
+
*/
|
|
15
|
+
export class SMTBeacon extends Beacon {
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of SMTBeacon.
|
|
18
|
+
* @param {BeaconService} service The Beacon service.
|
|
19
|
+
*/
|
|
20
|
+
constructor(service: BeaconService) {
|
|
21
|
+
super({ ...service, type: 'SMTBeacon' });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
|
|
26
|
+
* @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
|
|
27
|
+
* @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
|
|
28
|
+
* @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
|
|
29
|
+
* @throws {SMTBeaconError} if processing fails.
|
|
30
|
+
*/
|
|
31
|
+
processSignals(
|
|
32
|
+
signals: Array<BeaconSignal>,
|
|
33
|
+
sidecar: SidecarData
|
|
34
|
+
): Promise<Array<[SignedBTCR2Update, BlockMetadata]>> {
|
|
35
|
+
throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signals, sidecar});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Broadcast CAS Beacon signal to the Bitcoin network.
|
|
40
|
+
* @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
|
|
41
|
+
* @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
|
|
42
|
+
* @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
|
|
43
|
+
* @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
|
|
44
|
+
* @throws {SMTBeaconError} if broadcasting fails.
|
|
45
|
+
*/
|
|
46
|
+
async broadcastSignal(
|
|
47
|
+
signedUpdate: SignedBTCR2Update,
|
|
48
|
+
secretKey: KeyBytes,
|
|
49
|
+
bitcoin: BitcoinNetworkConnection
|
|
50
|
+
): Promise<SignedBTCR2Update> {
|
|
51
|
+
throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signedUpdate, secretKey, bitcoin});
|
|
52
|
+
}
|
|
53
|
+
}
|