@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
package/src/did-btcr2.ts
CHANGED
|
@@ -1,154 +1,229 @@
|
|
|
1
|
+
import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
|
|
1
2
|
import {
|
|
3
|
+
Canonicalization,
|
|
2
4
|
DocumentBytes,
|
|
5
|
+
HexString,
|
|
6
|
+
IdentifierHrp,
|
|
3
7
|
INVALID_DID_DOCUMENT,
|
|
8
|
+
INVALID_DID_UPDATE,
|
|
4
9
|
KeyBytes,
|
|
5
10
|
METHOD_NOT_SUPPORTED,
|
|
6
11
|
MethodError,
|
|
12
|
+
MISSING_UPDATE_DATA,
|
|
7
13
|
PatchOperation,
|
|
8
|
-
|
|
14
|
+
ResolveError,
|
|
15
|
+
UpdateError
|
|
9
16
|
} from '@did-btcr2/common';
|
|
10
|
-
import
|
|
17
|
+
import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
11
18
|
import {
|
|
12
19
|
Did,
|
|
13
20
|
DidError,
|
|
14
21
|
DidErrorCode,
|
|
15
22
|
DidMethod,
|
|
23
|
+
DidResolutionResult,
|
|
16
24
|
EMPTY_DID_RESOLUTION_RESULT
|
|
17
25
|
} from '@web5/dids';
|
|
18
26
|
import { initEccLib } from 'bitcoinjs-lib';
|
|
19
27
|
import * as tinysecp from 'tiny-secp256k1';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { DidResolutionOptions } from './interfaces/crud.js';
|
|
23
|
-
import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
|
|
24
|
-
import { SignalsMetadata } from './utils/types.js';
|
|
28
|
+
import { BeaconService } from './core/beacon/interfaces.js';
|
|
29
|
+
import { BeaconUtils } from './core/beacon/utils.js';
|
|
25
30
|
import { Identifier } from './core/identifier.js';
|
|
31
|
+
import { ResolutionOptions } from './core/interfaces.js';
|
|
32
|
+
import { Resolve } from './core/resolve.js';
|
|
33
|
+
import { Update } from './core/update.js';
|
|
26
34
|
import { Appendix } from './utils/appendix.js';
|
|
35
|
+
import { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
|
|
36
|
+
|
|
37
|
+
// TODO: convert to API driver?
|
|
38
|
+
export const canonicalization = new Canonicalization();
|
|
27
39
|
|
|
28
40
|
export type Btcr2Identifier = string;
|
|
29
41
|
|
|
30
42
|
export interface DidCreateOptions {
|
|
43
|
+
/** Type of identifier to create (key or external) */
|
|
44
|
+
idType: 'KEY' | 'EXTERNAL';
|
|
31
45
|
/** DID BTCR2 Version Number */
|
|
32
46
|
version?: number;
|
|
33
47
|
/** Bitcoin Network */
|
|
34
48
|
network?: string;
|
|
35
49
|
}
|
|
36
50
|
|
|
51
|
+
// TODO: convert to API driver?
|
|
37
52
|
/** Initialize tiny secp256k1 */
|
|
38
53
|
initEccLib(tinysecp);
|
|
39
54
|
|
|
40
55
|
/**
|
|
41
56
|
* Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
|
|
42
|
-
* did:btcr2 is a censorship
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
57
|
+
* did:btcr2 is a censorship-resistant Decentralized Identifier (DID) method using
|
|
58
|
+
* the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the
|
|
59
|
+
* DID document. It supports zero-cost off-chain DID creation; aggregated updates
|
|
60
|
+
* for scalable on-chain update costs; long-term identifiers that can support
|
|
61
|
+
* frequent updates; private communication of the DID document; private DID resolution;
|
|
62
|
+
* and non-repudiation.
|
|
46
63
|
*
|
|
47
64
|
* @class DidBtcr2
|
|
48
65
|
* @type {DidBtcr2}
|
|
49
66
|
* @implements {DidMethod}
|
|
50
67
|
*/
|
|
51
68
|
export class DidBtcr2 implements DidMethod {
|
|
52
|
-
/** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
|
|
53
|
-
public static methodName: string = 'btcr2';
|
|
54
|
-
|
|
55
69
|
/**
|
|
56
|
-
*
|
|
57
|
-
* See {@link Create} for implementation details.
|
|
58
|
-
*
|
|
59
|
-
* A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic
|
|
60
|
-
* seed, or it can be created from an arbitrary genesis intermediate DID document representation. In both cases,
|
|
61
|
-
* DID creation can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the
|
|
62
|
-
* Bitcoin network to create their DID.
|
|
63
|
-
* @param {CreateParams} params See {@link CreateParams} for details.
|
|
64
|
-
* @param {IdType} params.idType Type of identifier to create (key or external).
|
|
65
|
-
* @param {KeyBytes} params.pubKeyBytes Public key byte array used to create a btcr2 "key" identifier.
|
|
66
|
-
* @param {IntermediateDocument} params.intermediateDocument DID Document used to create a btcr2 "external" identifier.
|
|
67
|
-
* @param {DidCreateOptions} params.options See {@link DidCreateOptions} for create options.
|
|
68
|
-
* @param {number} params.options.version Version number of the btcr2 method.
|
|
69
|
-
* @param {string} params.options.network Bitcoin network name (mainnet, testnet, signet, regtest).
|
|
70
|
-
* @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
|
|
71
|
-
* @throws {DidBtcr2Error} if any of the checks fail
|
|
70
|
+
* Name of the DID method, as defined in the DID BTCR2 specification
|
|
72
71
|
*/
|
|
73
|
-
|
|
74
|
-
idType: 'KEY' | 'EXTERNAL';
|
|
75
|
-
genesisBytes: KeyBytes | DocumentBytes;
|
|
76
|
-
options?: DidCreateOptions;
|
|
77
|
-
}): Promise<Btcr2Identifier> {
|
|
78
|
-
// Deconstruct the idType and options from the params
|
|
79
|
-
const { idType, options = {} } = params;
|
|
72
|
+
static methodName: string = 'btcr2';
|
|
80
73
|
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
|
|
76
|
+
* @param {KeyBytes | DocumentBytes} genesisBytes The bytes used to create the genesis document for a did:btcr2 identifier.
|
|
77
|
+
* This can be either the bytes of the genesis document itself or the bytes of a key that will be used to create the genesis document.
|
|
78
|
+
* @param {DidCreateOptions} options Options for creating the identifier, including the idType (key or external), version, and network.
|
|
79
|
+
* @param {string} options.idType The type of identifier to create, either 'KEY' or 'EXTERNAL'. Defaults to 'KEY'.
|
|
80
|
+
* @param {number} options.version The version number of the did:btcr2 specification to use for creating the identifier. Defaults to 1.
|
|
81
|
+
* @param {string} options.network The Bitcoin network to use for the identifier, e.g. 'bitcoin', 'testnet', etc. Defaults to 'bitcoin'.
|
|
82
|
+
* @returns {Promise<Btcr2Identifier>} Promise resolving to a Btcr2Identifier string.
|
|
83
|
+
* @throws {MethodError} if any of the checks fail
|
|
84
|
+
*/
|
|
85
|
+
static async create(
|
|
86
|
+
genesisBytes: KeyBytes | DocumentBytes,
|
|
87
|
+
options?: DidCreateOptions
|
|
88
|
+
): Promise<Btcr2Identifier> {
|
|
89
|
+
// Deconstruct the idType, version and network from the options, setting defaults if not given
|
|
90
|
+
const { idType, version = 1, network = 'bitcoin' } = options || {};
|
|
83
91
|
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
if(!idType) {
|
|
93
|
+
throw new MethodError(
|
|
94
|
+
'idType is required for creating a did:btcr2 identifier',
|
|
95
|
+
INVALID_DID_DOCUMENT, options
|
|
96
|
+
);
|
|
97
|
+
}
|
|
86
98
|
|
|
99
|
+
// Call identifier encoding algorithm
|
|
87
100
|
return Identifier.encode({ idType, genesisBytes, version, network });
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
/**
|
|
91
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2
|
|
92
|
-
* See {@link
|
|
104
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
|
|
105
|
+
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
106
|
+
* See {@link Resolve | Resolve (class)} for class implementation.
|
|
93
107
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* object. The resolver then attempts to resolve the DID document of the identifier at a specific Target Time. The
|
|
99
|
-
* Target Time is either provided in resolutionOptions or is set to the Resolution Time of the request.
|
|
108
|
+
* Resolving a did:btcr2 identifier iteratively builds a DID document by applying
|
|
109
|
+
* BTCR2 Updates to an Initial DID Document that have been committed to the Bitcoin
|
|
110
|
+
* blockchain by Authorized Beacon Signals. The Initial DID Document is either
|
|
111
|
+
* deterministically created from the DID or provided by Sidecar Data.
|
|
100
112
|
*
|
|
101
|
-
* @param {string}
|
|
102
|
-
* @param {
|
|
103
|
-
* @
|
|
104
|
-
* @
|
|
105
|
-
* @param {DidDocument} options.sidecarData data necessary for resolving a DID
|
|
106
|
-
* @param {string} options.network Bitcoin network name (mainnet, testnet, signet, regtest).
|
|
107
|
-
* @returns {DidResolutionResult} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
108
|
-
* @throws {Error} if the resolution fails for any reason
|
|
109
|
-
* @throws {DidError} InvalidDid if the identifier is invalid
|
|
113
|
+
* @param {string} did The did:btcr2 identifier to be resolved.
|
|
114
|
+
* @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
|
|
115
|
+
* @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
116
|
+
* @throws {ResolveError} If the resolution process fails at any step.
|
|
110
117
|
* @example
|
|
111
118
|
* ```ts
|
|
112
|
-
* const resolution = await DidBtcr2.resolve(
|
|
119
|
+
* const resolution = await DidBtcr2.resolve(
|
|
120
|
+
* 'did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh'
|
|
121
|
+
* )
|
|
113
122
|
* ```
|
|
114
123
|
*/
|
|
115
|
-
|
|
124
|
+
static async resolve(
|
|
125
|
+
did: string,
|
|
126
|
+
resolutionOptions: ResolutionOptions = { drivers: {} }
|
|
127
|
+
): Promise<DidResolutionResult> {
|
|
116
128
|
try {
|
|
117
|
-
// 1. Pass identifier to the did:btcr2 Identifier Decoding algorithm, retrieving idType, version, network, and genesisBytes.
|
|
118
|
-
// 2. Set identifierComponents to a map of idType, version, network, and genesisBytes.
|
|
119
|
-
const identifierComponents = Identifier.decode(identifier);
|
|
120
|
-
|
|
121
|
-
// Set the network based on the decoded identifier
|
|
122
|
-
resolutionsOptions.network ??= identifierComponents.network;
|
|
123
|
-
|
|
124
|
-
// 3. Set initialDocument to the result of running the algorithm in Resolve Initial Document passing in the
|
|
125
|
-
// identifier, identifierComponents and resolutionOptions.
|
|
126
|
-
const initialDocument = await Resolve.initialDocument({ identifier, identifierComponents, resolutionsOptions });
|
|
127
129
|
|
|
128
|
-
//
|
|
129
|
-
// initialDocument and resolutionOptions.
|
|
130
|
-
const targetDocument = await Resolve.targetDocument({ initialDocument, resolutionsOptions });
|
|
131
|
-
|
|
132
|
-
// 5. Return targetDocument.
|
|
130
|
+
// Initialize an empty DID Resolution Result
|
|
133
131
|
const didResolutionResult: DidResolutionResult = {
|
|
134
|
-
'@context' :
|
|
132
|
+
'@context' : 'https://w3id.org/did-resolution/v1',
|
|
135
133
|
didResolutionMetadata : { contentType: 'application/ld+json' },
|
|
136
|
-
didDocumentMetadata : {
|
|
137
|
-
|
|
134
|
+
didDocumentMetadata : {
|
|
135
|
+
deactivated : false,
|
|
136
|
+
updated : undefined,
|
|
137
|
+
versionId : resolutionOptions.versionId,
|
|
138
|
+
confirmations : undefined,
|
|
139
|
+
},
|
|
140
|
+
didDocument : null,
|
|
138
141
|
};
|
|
139
142
|
|
|
143
|
+
// Decode the did to be resolved
|
|
144
|
+
const didComponents = Identifier.decode(did);
|
|
145
|
+
|
|
146
|
+
// Process sidecar if provided
|
|
147
|
+
const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
|
|
148
|
+
|
|
149
|
+
// Check if bitcoin driver provided
|
|
150
|
+
if(!resolutionOptions?.drivers?.bitcoin) {
|
|
151
|
+
// If not, initialize default drivers
|
|
152
|
+
resolutionOptions.drivers = resolutionOptions.drivers || {};
|
|
153
|
+
// Set bitcoin driver to default BitcoinNetworkConnection
|
|
154
|
+
resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
|
|
155
|
+
// Set the network based on the decoded identifier
|
|
156
|
+
resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Parse the genesis document from the resolution options if provided
|
|
160
|
+
const genesisDocument = resolutionOptions.sidecar?.genesisDocument;
|
|
161
|
+
// Since genesisDocument is optional, check if it exists
|
|
162
|
+
if(!genesisDocument) {
|
|
163
|
+
// If no genesisDocument and x HRP, throw MISSING_UPDATE_DATA error
|
|
164
|
+
if(didComponents.hrp === IdentifierHrp.x)
|
|
165
|
+
throw new ResolveError(
|
|
166
|
+
'External resolution requires genesisDocument',
|
|
167
|
+
MISSING_UPDATE_DATA, { resolutionOptions }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Establish the current document
|
|
172
|
+
const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
|
|
173
|
+
|
|
174
|
+
// Extract all Beacon services from the current DID Document
|
|
175
|
+
const beaconServices = currentDocument.service
|
|
176
|
+
.filter(BeaconUtils.isBeaconService)
|
|
177
|
+
.map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
178
|
+
|
|
179
|
+
console.log('beaconServices', beaconServices);
|
|
180
|
+
|
|
181
|
+
// Process the Beacon Signals to get the required updates
|
|
182
|
+
const unsortedUpdates = await Resolve.beaconSignals(
|
|
183
|
+
beaconServices,
|
|
184
|
+
sidecarData,
|
|
185
|
+
resolutionOptions.drivers.bitcoin
|
|
186
|
+
);
|
|
187
|
+
console.log('unsortedUpdates', unsortedUpdates);
|
|
188
|
+
|
|
189
|
+
// If no updates found, return the current document
|
|
190
|
+
if(!unsortedUpdates.length) {
|
|
191
|
+
// Set the current document in the didResolutionResult
|
|
192
|
+
didResolutionResult.didDocument = currentDocument;
|
|
193
|
+
|
|
194
|
+
// Set the deactivated status in the didDocumentMetadata
|
|
195
|
+
didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
|
|
196
|
+
|
|
197
|
+
// Return the didResolutionResult early
|
|
198
|
+
return didResolutionResult;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Process the updates to apply updates to bring the current DID Document to its more current state
|
|
202
|
+
const result = await Resolve.updates(
|
|
203
|
+
currentDocument,
|
|
204
|
+
unsortedUpdates,
|
|
205
|
+
resolutionOptions.versionTime,
|
|
206
|
+
resolutionOptions.versionId
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// Set all of the required fields in the didResolutionResult
|
|
210
|
+
didResolutionResult.didDocument = result.currentDocument;
|
|
211
|
+
didResolutionResult.didDocumentMetadata.confirmations = result.confirmations;
|
|
212
|
+
didResolutionResult.didDocumentMetadata.versionId = result.versionId;
|
|
213
|
+
didResolutionResult.didDocumentMetadata.deactivated = !!result.currentDocument.deactivated;
|
|
214
|
+
|
|
140
215
|
// Return didResolutionResult;
|
|
141
216
|
return didResolutionResult;
|
|
142
217
|
} catch (error: any) {
|
|
143
218
|
console.error(error);
|
|
144
|
-
// Rethrow any unexpected errors that are not a `
|
|
145
|
-
if (!(error instanceof
|
|
219
|
+
// Rethrow any unexpected errors that are not a `ResolveError`.
|
|
220
|
+
if (!(error instanceof ResolveError)) throw new Error(error);
|
|
146
221
|
|
|
147
222
|
// Return a DID Resolution Result with the appropriate error code.
|
|
148
223
|
return {
|
|
149
224
|
...EMPTY_DID_RESOLUTION_RESULT,
|
|
150
225
|
didResolutionMetadata : {
|
|
151
|
-
error : error.
|
|
226
|
+
error : error.type,
|
|
152
227
|
...error.message && { errorMessage: error.message }
|
|
153
228
|
}
|
|
154
229
|
};
|
|
@@ -156,92 +231,118 @@ export class DidBtcr2 implements DidMethod {
|
|
|
156
231
|
}
|
|
157
232
|
|
|
158
233
|
/**
|
|
159
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#
|
|
160
|
-
* See {@link
|
|
234
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
|
|
235
|
+
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
236
|
+
* See {@link Update | Update (class)} for class implementation.
|
|
161
237
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* The
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* @param {string} params.identifier The btcr2 identifier to be updated.
|
|
177
|
-
* @param {DidDocument} params.sourceDocument The DID document being updated.
|
|
178
|
-
* @param {string} params.sourceVersionId The versionId of the source document.
|
|
179
|
-
* @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
|
|
180
|
-
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update
|
|
181
|
-
* @param {string[]} params.beaconIds The beacon IDs to announce the update
|
|
182
|
-
* @returns {Promise<void>} Promise resolving to void
|
|
183
|
-
* @throws {MethodError} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
|
|
238
|
+
* BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
|
|
239
|
+
* published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
|
|
240
|
+
* invalidate the DID document.
|
|
241
|
+
* @param params An object containing the parameters for the update operation.
|
|
242
|
+
* @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
|
|
243
|
+
* @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
244
|
+
* @param {string} params.sourceVersionId The version ID before applying the update.
|
|
245
|
+
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
246
|
+
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
247
|
+
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
248
|
+
* @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
249
|
+
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
250
|
+
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
251
|
+
* header is not `zQ3s`
|
|
184
252
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
253
|
+
static async update({
|
|
254
|
+
sourceDocument,
|
|
255
|
+
patches,
|
|
256
|
+
sourceVersionId,
|
|
257
|
+
verificationMethodId,
|
|
258
|
+
beaconId,
|
|
259
|
+
signingMaterial,
|
|
260
|
+
bitcoin,
|
|
261
|
+
}: {
|
|
262
|
+
sourceDocument: Btcr2DidDocument;
|
|
263
|
+
patches: PatchOperation[];
|
|
188
264
|
sourceVersionId: number;
|
|
189
|
-
patch: PatchOperation[];
|
|
190
265
|
verificationMethodId: string;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
266
|
+
beaconId: string;
|
|
267
|
+
signingMaterial?: KeyBytes | HexString;
|
|
268
|
+
bitcoin?: BitcoinNetworkConnection;
|
|
269
|
+
}): Promise<SignedBTCR2Update> {
|
|
270
|
+
// TODO: provide KMS as alternative
|
|
271
|
+
// If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
|
|
272
|
+
if (!signingMaterial) {
|
|
273
|
+
throw new UpdateError(
|
|
274
|
+
'Missing signing material for update',
|
|
275
|
+
INVALID_DID_UPDATE, {signingMaterial}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Convert signingMaterial to bytes if it's a hex string
|
|
280
|
+
const secretKey = typeof signingMaterial === 'string'
|
|
281
|
+
? Buffer.from(signingMaterial, 'hex')
|
|
282
|
+
: signingMaterial;
|
|
283
|
+
|
|
284
|
+
// Validate that the verificationMethodId is authorized for capabilityInvocation
|
|
285
|
+
if(!sourceDocument.capabilityInvocation?.some(vr => vr === verificationMethodId)) {
|
|
286
|
+
throw new UpdateError(
|
|
287
|
+
'Invalid verificationMethodId: not authorized for capabilityInvocation',
|
|
288
|
+
INVALID_DID_DOCUMENT, sourceDocument
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Get the verification method to be used for signing the update
|
|
293
|
+
const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
|
|
216
294
|
|
|
217
295
|
// Validate the verificationMethod exists in the sourceDocument
|
|
218
296
|
if (!verificationMethod) {
|
|
219
|
-
throw new
|
|
297
|
+
throw new UpdateError(
|
|
298
|
+
'Invalid verificationMethod: not found in source document',
|
|
299
|
+
INVALID_DID_DOCUMENT, {sourceDocument, verificationMethodId}
|
|
300
|
+
);
|
|
220
301
|
}
|
|
221
302
|
|
|
222
|
-
//
|
|
223
|
-
// 3.1 verificationMethod.type == Multikey
|
|
303
|
+
// Validate the verificationMethod is of type 'Multikey'
|
|
224
304
|
if (verificationMethod.type !== 'Multikey') {
|
|
225
|
-
throw new
|
|
305
|
+
throw new UpdateError(
|
|
306
|
+
'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
|
|
307
|
+
INVALID_DID_DOCUMENT, verificationMethod
|
|
308
|
+
);
|
|
226
309
|
}
|
|
227
310
|
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
311
|
+
// Validate the publicKeyMultibase prefix is 'zQ3s'
|
|
312
|
+
if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== 'zQ3s') {
|
|
313
|
+
throw new UpdateError(
|
|
314
|
+
'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
|
|
315
|
+
INVALID_DID_DOCUMENT, verificationMethod
|
|
316
|
+
);
|
|
232
317
|
}
|
|
233
318
|
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
|
|
319
|
+
// Construct an unsigned update following the BTCR2 Update construction algorithm
|
|
320
|
+
const update = await Update.construct(sourceDocument, patches, sourceVersionId);
|
|
321
|
+
|
|
322
|
+
// Sign the unsigned update using the specified verification method
|
|
323
|
+
const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
|
|
237
324
|
|
|
238
|
-
//
|
|
239
|
-
|
|
240
|
-
|
|
325
|
+
// Filter sourceDocument services to get beaconServices matching beaconIds
|
|
326
|
+
const beaconService = sourceDocument.service
|
|
327
|
+
.filter((service: BeaconService) => service.id === beaconId)
|
|
328
|
+
.filter((service: BeaconService): service is BeaconService => !!service)
|
|
329
|
+
.shift();
|
|
241
330
|
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
|
|
331
|
+
// If no matching beacon service found, throw an UpdateError with INVALID_DID_UPDATE.
|
|
332
|
+
if(!beaconService) {
|
|
333
|
+
throw new UpdateError(
|
|
334
|
+
'No beacon service found for provided beaconId',
|
|
335
|
+
INVALID_DID_UPDATE, {sourceDocument, beaconId}
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
// If no bitcoin network connection provided, initialize default
|
|
339
|
+
bitcoin ??= new BitcoinNetworkConnection();
|
|
340
|
+
|
|
341
|
+
// Announce the signed update to the blockchain using the specified beacon(s)
|
|
342
|
+
// await Update.announce(beaconService, signed, secretKey, bitcoin);
|
|
343
|
+
|
|
344
|
+
// Return signed update if announced successfully
|
|
345
|
+
return signed;
|
|
245
346
|
}
|
|
246
347
|
|
|
247
348
|
/**
|
|
@@ -249,17 +350,12 @@ export class DidBtcr2 implements DidMethod {
|
|
|
249
350
|
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
250
351
|
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
251
352
|
* of '#initialKey' is used.
|
|
252
|
-
*
|
|
253
|
-
* @param {
|
|
254
|
-
* @param {DidDocument} params.didDocument DID Document to get the verification method from.
|
|
255
|
-
* @param {string} params.methodId Optional ID of the verification method to use for signing.
|
|
353
|
+
* @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
|
|
354
|
+
* @param {string} [methodId] Optional verification method ID to be used for signing.
|
|
256
355
|
* @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
|
|
257
356
|
* @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
|
|
258
357
|
*/
|
|
259
|
-
|
|
260
|
-
didDocument: DidDocument;
|
|
261
|
-
methodId?: string;
|
|
262
|
-
}): DidVerificationMethod {
|
|
358
|
+
static getSigningMethod(didDocument: Btcr2DidDocument, methodId?: string): DidVerificationMethod {
|
|
263
359
|
// Set the default methodId to the first assertionMethod if not given
|
|
264
360
|
methodId ??= '#initialKey';
|
|
265
361
|
|
package/src/index.ts
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
|
+
export * from './core/beacon/aggregation/cohort/index.js';
|
|
2
|
+
export * from './core/beacon/aggregation/cohort/status.js';
|
|
3
|
+
|
|
4
|
+
export * from './core/beacon/aggregation/cohort/messages/base.js';
|
|
5
|
+
export * from './core/beacon/aggregation/cohort/messages/constants.js';
|
|
6
|
+
export * from './core/beacon/aggregation/cohort/messages/index.js';
|
|
7
|
+
export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
|
|
1
8
|
export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js';
|
|
2
9
|
export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js';
|
|
3
10
|
export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js';
|
|
4
11
|
export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in.js';
|
|
5
|
-
export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
|
|
6
|
-
|
|
7
12
|
export * from './core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js';
|
|
8
13
|
export * from './core/beacon/aggregation/cohort/messages/sign/authorization-request.js';
|
|
9
14
|
export * from './core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js';
|
|
10
15
|
export * from './core/beacon/aggregation/cohort/messages/sign/request-signature.js';
|
|
11
16
|
export * from './core/beacon/aggregation/cohort/messages/sign/signature-authorization.js';
|
|
12
17
|
|
|
13
|
-
export * from './core/beacon/aggregation/cohort/messages/base.js';
|
|
14
|
-
export * from './core/beacon/aggregation/cohort/messages/constants.js';
|
|
15
|
-
export * from './core/beacon/aggregation/cohort/messages/index.js';
|
|
16
|
-
|
|
17
|
-
export * from './core/beacon/aggregation/cohort/index.js';
|
|
18
|
-
export * from './core/beacon/aggregation/cohort/status.js';
|
|
19
|
-
|
|
20
18
|
export * from './core/beacon/aggregation/communication/adapter/did-comm.js';
|
|
21
19
|
export * from './core/beacon/aggregation/communication/adapter/nostr.js';
|
|
20
|
+
|
|
22
21
|
export * from './core/beacon/aggregation/communication/error.js';
|
|
23
22
|
export * from './core/beacon/aggregation/communication/factory.js';
|
|
24
23
|
export * from './core/beacon/aggregation/communication/service.js';
|
|
25
24
|
|
|
26
|
-
export * from './core/beacon/aggregation/session/index.js';
|
|
27
|
-
export * from './core/beacon/aggregation/session/status.js';
|
|
28
|
-
|
|
29
25
|
export * from './core/beacon/aggregation/coordinator.js';
|
|
30
26
|
export * from './core/beacon/aggregation/participant.js';
|
|
27
|
+
export * from './core/beacon/aggregation/session/index.js';
|
|
28
|
+
export * from './core/beacon/aggregation/session/status.js';
|
|
31
29
|
|
|
32
|
-
export * from './core/beacon/
|
|
30
|
+
export * from './core/beacon/beacon.js';
|
|
31
|
+
export * from './core/beacon/cas-beacon.js';
|
|
33
32
|
export * from './core/beacon/error.js';
|
|
34
33
|
export * from './core/beacon/factory.js';
|
|
34
|
+
export * from './core/beacon/interfaces.js';
|
|
35
|
+
export * from './core/beacon/signal-discovery.js';
|
|
35
36
|
export * from './core/beacon/singleton.js';
|
|
36
|
-
export * from './core/beacon/smt-
|
|
37
|
+
export * from './core/beacon/smt-beacon.js';
|
|
37
38
|
export * from './core/beacon/utils.js';
|
|
38
39
|
|
|
39
|
-
export * from './core/crud/deactivate.js';
|
|
40
|
-
export * from './core/crud/read.js';
|
|
41
|
-
export * from './core/crud/update.js';
|
|
42
|
-
|
|
43
40
|
export * from './core/identifier.js';
|
|
44
|
-
|
|
45
|
-
export * from './
|
|
46
|
-
export * from './
|
|
41
|
+
export * from './core/interfaces.js';
|
|
42
|
+
export * from './core/resolve.js';
|
|
43
|
+
export * from './core/types.js';
|
|
44
|
+
export * from './core/update.js';
|
|
47
45
|
|
|
48
46
|
export * from './utils/appendix.js';
|
|
49
47
|
export * from './utils/did-document-builder.js';
|
|
50
48
|
export * from './utils/did-document.js';
|
|
51
49
|
export * from './utils/general.js';
|
|
52
|
-
export * from './utils/types.js';
|
|
53
50
|
|
|
54
51
|
export * from './did-btcr2.js';
|