@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/utils/appendix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HashBytes
|
|
1
|
+
import { HashBytes } from '@did-btcr2/common';
|
|
2
2
|
import { strings } from '@helia/strings';
|
|
3
3
|
import {
|
|
4
4
|
DidDocument,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { createHelia } from 'helia';
|
|
12
12
|
import { CID } from 'multiformats';
|
|
13
13
|
import { create as createDigest } from 'multiformats/hashes/digest';
|
|
14
|
-
import { RootCapability } from '../interfaces
|
|
14
|
+
import { RootCapability } from '../core/interfaces.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#appendix | 9. Appendix} methods.
|
|
@@ -109,27 +109,13 @@ export class Appendix {
|
|
|
109
109
|
* }
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// 3. Set encodedIdentifier to result of calling algorithm encodeURIComponent(identifier).
|
|
120
|
-
const encodedIdentifier = encodeURIComponent(identifier);
|
|
121
|
-
|
|
122
|
-
// 4. Set rootCapability.id to urn:zcap:root:${encodedIdentifier}.
|
|
123
|
-
rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
|
|
124
|
-
|
|
125
|
-
// 5. Set rootCapability.controller to identifier.
|
|
126
|
-
rootCapability.controller = identifier;
|
|
127
|
-
|
|
128
|
-
// 6. Set rootCapability.invocationTarget to identifier.
|
|
129
|
-
rootCapability.invocationTarget = identifier;
|
|
130
|
-
|
|
131
|
-
// 7. Return rootCapability.
|
|
132
|
-
return rootCapability;
|
|
112
|
+
static deriveRootCapability(identifier: string): RootCapability {
|
|
113
|
+
return {
|
|
114
|
+
'@context' : 'https://w3id.org/zcap/v1',
|
|
115
|
+
id : `urn:zcap:root:${encodeURIComponent(identifier)}`,
|
|
116
|
+
controller : identifier,
|
|
117
|
+
invocationTarget : identifier,
|
|
118
|
+
};
|
|
133
119
|
}
|
|
134
120
|
|
|
135
121
|
|
|
@@ -173,7 +159,7 @@ export class Appendix {
|
|
|
173
159
|
* }
|
|
174
160
|
* }
|
|
175
161
|
*/
|
|
176
|
-
public static
|
|
162
|
+
public static dereferenceZcapId(capabilityId: string): RootCapability {
|
|
177
163
|
// 1. Set rootCapability to an empty object.
|
|
178
164
|
const rootCapability = {} as RootCapability;
|
|
179
165
|
|
|
@@ -221,28 +207,24 @@ export class Appendix {
|
|
|
221
207
|
}
|
|
222
208
|
|
|
223
209
|
/**
|
|
224
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* bytes to a IPFS v1 Content Identifier and attempts to retrieve the identified content from Content Addressable
|
|
228
|
-
* Storage (CAS). It returns the retrieved content or null.
|
|
229
|
-
*
|
|
230
|
-
* @param {HashBytes} hashBytes The SHA256 hash of the content to be fetched.
|
|
231
|
-
* @returns {string} The fetched content or null if not found.
|
|
210
|
+
* Implements CAS Lookup Step from {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-beacon-signals | 7.2.e Process Beacon Signals }.
|
|
211
|
+
* @param {HashBytes} hashBytes The hash bytes to look up in the CAS system.
|
|
212
|
+
* @returns {Promise<string | undefined>} The content fetched from the CAS system, or undefined if not found.
|
|
232
213
|
*/
|
|
233
|
-
|
|
234
|
-
//
|
|
214
|
+
static async fetchFromCas(hashBytes: HashBytes): Promise<string | undefined> {
|
|
215
|
+
// Construct CID from hash bytes
|
|
235
216
|
const cid = CID.create(1, 1, createDigest(1, hashBytes));
|
|
236
217
|
|
|
237
|
-
//
|
|
238
|
-
const helia =
|
|
218
|
+
// Connect to IPFS/Helia node
|
|
219
|
+
const helia = await createHelia();
|
|
220
|
+
const node = strings(helia);
|
|
239
221
|
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
const content = await helia.get(cid, {});
|
|
243
|
-
|
|
244
|
-
// 3. If content for cid cannot be found, set content to null.
|
|
245
|
-
// 4. Return content.
|
|
246
|
-
return content;
|
|
222
|
+
// Return the IPFS get result
|
|
223
|
+
return await node.get(cid, {});
|
|
247
224
|
}
|
|
248
|
-
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { DidDocumentError, INVALID_DID_DOCUMENT } from '@did-btcr2/common';
|
|
2
|
-
import { BeaconService } from '../
|
|
2
|
+
import { BeaconService } from '../core/beacon/interfaces.js';
|
|
3
3
|
import { DidDocument, DidVerificationMethod } from './did-document.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A builder class for constructing DID Documents.
|
|
7
|
+
* @type {DidDocumentBuilder}
|
|
8
|
+
* @class DidDocumentBuilder
|
|
9
|
+
*/
|
|
5
10
|
export class DidDocumentBuilder {
|
|
6
11
|
private document: Partial<DidDocument> = {};
|
|
7
12
|
|
|
@@ -2,19 +2,21 @@ import { getNetwork } from '@did-btcr2/bitcoin';
|
|
|
2
2
|
import {
|
|
3
3
|
BTCR2_DID_DOCUMENT_CONTEXT,
|
|
4
4
|
DidDocumentError,
|
|
5
|
-
ID_PLACEHOLDER_VALUE,
|
|
6
5
|
IdentifierTypes,
|
|
7
6
|
INVALID_DID_DOCUMENT,
|
|
8
7
|
JSONObject,
|
|
9
|
-
|
|
8
|
+
JSONUtils,
|
|
9
|
+
KeyBytes
|
|
10
10
|
} from '@did-btcr2/common';
|
|
11
11
|
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
12
|
-
import {
|
|
13
|
-
import { BeaconService } from '../
|
|
12
|
+
import { DidDocument as W3CDidDocument, DidVerificationMethod as W3CDidVerificationMethod } from '@web5/dids';
|
|
13
|
+
import { BeaconService } from '../core/beacon/interfaces.js';
|
|
14
14
|
import { BeaconUtils } from '../core/beacon/utils.js';
|
|
15
15
|
import { Identifier } from '../core/identifier.js';
|
|
16
16
|
import { Appendix } from './appendix.js';
|
|
17
|
+
import { payments } from 'bitcoinjs-lib';
|
|
17
18
|
|
|
19
|
+
export const ID_PLACEHOLDER_VALUE = 'did:btcr2:_';
|
|
18
20
|
export const BECH32M_CHARS = '';
|
|
19
21
|
export const DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
|
|
20
22
|
|
|
@@ -34,7 +36,10 @@ export type VerificationRelationships = {
|
|
|
34
36
|
capabilityDelegation?: Array<string | DidVerificationMethod>;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
/** Loose type for unvalidated DID document-like input objects. */
|
|
40
|
+
export type DidDocumentLike = Partial<Btcr2DidDocument>;
|
|
41
|
+
|
|
42
|
+
export interface Btcr2VerificationMethod extends W3CDidVerificationMethod {
|
|
38
43
|
id: string;
|
|
39
44
|
type: string;
|
|
40
45
|
controller: string;
|
|
@@ -48,14 +53,14 @@ export interface IDidVerificationMethod extends IIDidVerificationMethod {
|
|
|
48
53
|
* @type {DidVerificationMethod}
|
|
49
54
|
*
|
|
50
55
|
*/
|
|
51
|
-
export class DidVerificationMethod implements
|
|
56
|
+
export class DidVerificationMethod implements Btcr2VerificationMethod {
|
|
52
57
|
id: string;
|
|
53
58
|
type: string;
|
|
54
59
|
controller: string;
|
|
55
60
|
publicKeyMultibase: string;
|
|
56
61
|
secretKeyMultibase?: string | undefined;
|
|
57
62
|
|
|
58
|
-
constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }:
|
|
63
|
+
constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }: Btcr2VerificationMethod) {
|
|
59
64
|
this.id = id;
|
|
60
65
|
this.type = type;
|
|
61
66
|
this.controller = controller;
|
|
@@ -70,9 +75,9 @@ export class DidVerificationMethod implements IDidVerificationMethod {
|
|
|
70
75
|
|
|
71
76
|
/**
|
|
72
77
|
* BTCR2 DID Document Interface
|
|
73
|
-
* @interface
|
|
74
|
-
* @type {
|
|
75
|
-
* @extends {
|
|
78
|
+
* @interface Btcr2DidDocument
|
|
79
|
+
* @type {Btcr2DidDocument}
|
|
80
|
+
* @extends {W3CDidDocument}
|
|
76
81
|
* @property {string} id - The identifier of the DID Document.
|
|
77
82
|
* @property {Array<string>} [controller] - The controller of the DID Document.
|
|
78
83
|
* @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
|
|
@@ -83,7 +88,7 @@ export class DidVerificationMethod implements IDidVerificationMethod {
|
|
|
83
88
|
* @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
|
|
84
89
|
* @property {Array<BeaconService>} service - The services of the DID Document.
|
|
85
90
|
*/
|
|
86
|
-
export interface
|
|
91
|
+
export interface Btcr2DidDocument extends W3CDidDocument {
|
|
87
92
|
id: string;
|
|
88
93
|
controller?: Array<string>;
|
|
89
94
|
'@context'?: Array<string | JSONObject>;
|
|
@@ -99,7 +104,7 @@ export interface IDidDocument extends IIDidDocument {
|
|
|
99
104
|
* BTCR2 DID Document extends the DidDocument class adding helper methods and properties
|
|
100
105
|
* @class DidDocument
|
|
101
106
|
* @type {DidDocument}
|
|
102
|
-
* @implements {
|
|
107
|
+
* @implements {Btcr2DidDocument}
|
|
103
108
|
* @property {string} id - The identifier of the DID Document.
|
|
104
109
|
* @property {Array<string>} [controller] - The controller of the DID Document.
|
|
105
110
|
* @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
|
|
@@ -110,7 +115,7 @@ export interface IDidDocument extends IIDidDocument {
|
|
|
110
115
|
* @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
|
|
111
116
|
* @property {Array<BeaconService>} service - The services of the DID Document.
|
|
112
117
|
*/
|
|
113
|
-
export class DidDocument implements
|
|
118
|
+
export class DidDocument implements Btcr2DidDocument {
|
|
114
119
|
id: string;
|
|
115
120
|
controller?: Array<string>;
|
|
116
121
|
'@context'?: Array<string | JSONObject> = BTCR2_DID_DOCUMENT_CONTEXT;
|
|
@@ -120,18 +125,22 @@ export class DidDocument implements IDidDocument {
|
|
|
120
125
|
capabilityInvocation?: Array<string | DidVerificationMethod>;
|
|
121
126
|
capabilityDelegation?: Array<string | DidVerificationMethod>;
|
|
122
127
|
service: Array<BeaconService>;
|
|
128
|
+
deactivated?: boolean;
|
|
123
129
|
|
|
124
|
-
constructor(document:
|
|
130
|
+
constructor(document: Btcr2DidDocument) {
|
|
125
131
|
// Set the ID and ID type
|
|
126
|
-
const idType = document.id.includes('
|
|
132
|
+
const idType = document.id.includes('k')
|
|
127
133
|
? IdentifierTypes.KEY
|
|
128
134
|
: IdentifierTypes.EXTERNAL;
|
|
129
135
|
|
|
130
136
|
// Validate ID and parts for non-intermediate
|
|
131
|
-
const
|
|
137
|
+
const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
|
|
138
|
+
|
|
132
139
|
// Deconstruct the document parts for validation
|
|
133
140
|
const { id, controller, verificationMethod: vm, service } = document;
|
|
134
|
-
|
|
141
|
+
|
|
142
|
+
// If not genesis, validate core properties
|
|
143
|
+
if (!isGenesis) {
|
|
135
144
|
if (!DidDocument.isValidId(id)) {
|
|
136
145
|
throw new DidDocumentError(`Invalid id: ${id}`, INVALID_DID_DOCUMENT, document);
|
|
137
146
|
}
|
|
@@ -172,29 +181,19 @@ export class DidDocument implements IDidDocument {
|
|
|
172
181
|
// Sanitize the DID Document
|
|
173
182
|
DidDocument.sanitize(this);
|
|
174
183
|
// If the DID Document is not an intermediateDocument, validate it
|
|
175
|
-
if (!
|
|
184
|
+
if (!isGenesis) {
|
|
176
185
|
DidDocument.validate(this);
|
|
177
186
|
} else {
|
|
178
|
-
this.
|
|
187
|
+
this.validateGenesis();
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
/**
|
|
183
192
|
* Convert the DidDocument to a JSON object.
|
|
184
|
-
* @returns {
|
|
193
|
+
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
185
194
|
*/
|
|
186
|
-
public json():
|
|
187
|
-
return
|
|
188
|
-
id : this.id,
|
|
189
|
-
controller : this.controller,
|
|
190
|
-
'@context' : this['@context'],
|
|
191
|
-
verificationMethod : this.verificationMethod,
|
|
192
|
-
authentication : this.authentication,
|
|
193
|
-
assertionMethod : this.assertionMethod,
|
|
194
|
-
capabilityInvocation : this.capabilityInvocation,
|
|
195
|
-
capabilityDelegation : this.capabilityDelegation,
|
|
196
|
-
service : this.service
|
|
197
|
-
};
|
|
195
|
+
public json(): DidDocument {
|
|
196
|
+
return Object.fromEntries(Object.entries(this)) as DidDocument;
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
/**
|
|
@@ -222,7 +221,7 @@ export class DidDocument implements IDidDocument {
|
|
|
222
221
|
})
|
|
223
222
|
],
|
|
224
223
|
service
|
|
225
|
-
} as
|
|
224
|
+
} as Btcr2DidDocument;
|
|
226
225
|
return new DidDocument(document);
|
|
227
226
|
}
|
|
228
227
|
|
|
@@ -232,7 +231,7 @@ export class DidDocument implements IDidDocument {
|
|
|
232
231
|
* @returns {DidDocument} A new DidDocument.
|
|
233
232
|
*/
|
|
234
233
|
public static fromExternalIdentifier(data: ExternalData): DidDocument {
|
|
235
|
-
return new DidDocument(data as
|
|
234
|
+
return new DidDocument(data as Btcr2DidDocument);
|
|
236
235
|
}
|
|
237
236
|
|
|
238
237
|
|
|
@@ -255,7 +254,7 @@ export class DidDocument implements IDidDocument {
|
|
|
255
254
|
* @returns {boolean} True if the DID document is valid.
|
|
256
255
|
* @throws {DidDocumentError} If any validation check fails.
|
|
257
256
|
*/
|
|
258
|
-
public static isValid(didDocument:
|
|
257
|
+
public static isValid(didDocument: DidDocumentLike): boolean {
|
|
259
258
|
if (!this.isValidContext(didDocument?.['@context'])) {
|
|
260
259
|
throw new DidDocumentError('Invalid "@context"', INVALID_DID_DOCUMENT, didDocument);
|
|
261
260
|
}
|
|
@@ -280,7 +279,7 @@ export class DidDocument implements IDidDocument {
|
|
|
280
279
|
* @param {DidDocument['@context']} context The context to validate.
|
|
281
280
|
* @returns {boolean} True if the context is valid.
|
|
282
281
|
*/
|
|
283
|
-
private static isValidContext(context:
|
|
282
|
+
private static isValidContext(context: unknown): boolean {
|
|
284
283
|
if(!context) return false;
|
|
285
284
|
if(!Array.isArray(context)) return false;
|
|
286
285
|
if(!context.every(ctx => typeof ctx === 'string' && BTCR2_DID_DOCUMENT_CONTEXT.includes(ctx))) return false;
|
|
@@ -293,7 +292,8 @@ export class DidDocument implements IDidDocument {
|
|
|
293
292
|
* @param {string} id The id to validate.
|
|
294
293
|
* @returns {boolean} True if the id is valid.
|
|
295
294
|
*/
|
|
296
|
-
private static isValidId(id:
|
|
295
|
+
private static isValidId(id: unknown): boolean {
|
|
296
|
+
if (typeof id !== 'string') return false;
|
|
297
297
|
try {
|
|
298
298
|
Identifier.decode(id);
|
|
299
299
|
return true;
|
|
@@ -320,7 +320,7 @@ export class DidDocument implements IDidDocument {
|
|
|
320
320
|
* @param {DidVerificationMethod[]} verificationMethod The verification methods to validate.
|
|
321
321
|
* @returns {boolean} True if the verification methods are valid.
|
|
322
322
|
*/
|
|
323
|
-
private static isValidVerificationMethods(verificationMethod:
|
|
323
|
+
private static isValidVerificationMethods(verificationMethod: unknown): boolean {
|
|
324
324
|
return Array.isArray(verificationMethod) && verificationMethod.every(Appendix.isDidVerificationMethod);
|
|
325
325
|
}
|
|
326
326
|
|
|
@@ -330,7 +330,7 @@ export class DidDocument implements IDidDocument {
|
|
|
330
330
|
* @param {DidService[]} service The services to validate.
|
|
331
331
|
* @returns {boolean} True if the services are valid.
|
|
332
332
|
*/
|
|
333
|
-
private static isValidServices(service:
|
|
333
|
+
private static isValidServices(service: unknown): boolean {
|
|
334
334
|
return Array.isArray(service) && service.every(BeaconUtils.isBeaconService);
|
|
335
335
|
}
|
|
336
336
|
|
|
@@ -340,33 +340,25 @@ export class DidDocument implements IDidDocument {
|
|
|
340
340
|
* @param {DidDocument} didDocument The DID Document to validate.
|
|
341
341
|
* @returns {boolean} True if the verification relationships are valid.
|
|
342
342
|
*/
|
|
343
|
-
public static isValidVerificationRelationships(didDocument:
|
|
344
|
-
|
|
345
|
-
const possibleVerificationRelationships: (keyof DidDocument)[] = [
|
|
343
|
+
public static isValidVerificationRelationships(didDocument: DidDocumentLike): boolean {
|
|
344
|
+
const possibleVerificationRelationships = [
|
|
346
345
|
'authentication',
|
|
347
346
|
'assertionMethod',
|
|
348
347
|
'capabilityInvocation',
|
|
349
348
|
'capabilityDelegation'
|
|
350
|
-
];
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
didDocument[key] &&
|
|
364
|
-
// Check if the key is an array
|
|
365
|
-
Array.isArray(didDocument[key]) &&
|
|
366
|
-
// Check that every value in the array is a string or DidVerificationMethod
|
|
367
|
-
didDocument[key].every(
|
|
368
|
-
entry => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
|
|
369
|
-
));
|
|
349
|
+
] as const;
|
|
350
|
+
|
|
351
|
+
const keys = Object.keys(didDocument);
|
|
352
|
+
const availableKeys = possibleVerificationRelationships.filter(key => keys.includes(key));
|
|
353
|
+
|
|
354
|
+
return availableKeys.every((key) => {
|
|
355
|
+
const value = didDocument[key];
|
|
356
|
+
return value &&
|
|
357
|
+
Array.isArray(value) &&
|
|
358
|
+
value.every(
|
|
359
|
+
(entry) => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
|
|
360
|
+
);
|
|
361
|
+
});
|
|
370
362
|
}
|
|
371
363
|
|
|
372
364
|
/**
|
|
@@ -374,10 +366,10 @@ export class DidDocument implements IDidDocument {
|
|
|
374
366
|
* @returns {DidDocument} Validated DID Document.
|
|
375
367
|
* @throws {DidDocumentError} If the DID Document is invalid.
|
|
376
368
|
*/
|
|
377
|
-
public static validate(didDocument:
|
|
369
|
+
public static validate(didDocument: any): DidDocument {
|
|
378
370
|
// Validate the DID Document
|
|
379
371
|
if (didDocument.id === ID_PLACEHOLDER_VALUE) {
|
|
380
|
-
(didDocument as
|
|
372
|
+
(didDocument as GenesisDocument).validateGenesis();
|
|
381
373
|
} else {
|
|
382
374
|
DidDocument.isValid(didDocument);
|
|
383
375
|
}
|
|
@@ -386,111 +378,117 @@ export class DidDocument implements IDidDocument {
|
|
|
386
378
|
}
|
|
387
379
|
|
|
388
380
|
/**
|
|
389
|
-
* Validate the
|
|
390
|
-
* @returns {boolean} True if the
|
|
381
|
+
* Validate the GenesisDocument.
|
|
382
|
+
* @returns {boolean} True if the GenesisDocument is valid.
|
|
391
383
|
*/
|
|
392
|
-
public
|
|
384
|
+
public validateGenesis(): boolean {
|
|
393
385
|
// Validate the id
|
|
394
386
|
if(this.id !== ID_PLACEHOLDER_VALUE) {
|
|
395
|
-
throw new DidDocumentError('Invalid
|
|
387
|
+
throw new DidDocumentError('Invalid GenesisDocument ID', INVALID_DID_DOCUMENT, this);
|
|
396
388
|
}
|
|
397
389
|
// Validate the controller
|
|
398
390
|
if(!this.controller?.every(c => c === ID_PLACEHOLDER_VALUE)) {
|
|
399
|
-
throw new DidDocumentError('Invalid
|
|
391
|
+
throw new DidDocumentError('Invalid GenesisDocument controller', INVALID_DID_DOCUMENT, this);
|
|
400
392
|
}
|
|
401
393
|
// Validate the verificationMethod
|
|
402
394
|
if(!this.verificationMethod.every(vm => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
|
|
403
|
-
throw new DidDocumentError('Invalid
|
|
395
|
+
throw new DidDocumentError('Invalid GenesisDocument verificationMethod', INVALID_DID_DOCUMENT, this);
|
|
404
396
|
}
|
|
405
397
|
// Validate the service
|
|
406
398
|
if(!this.service.every(svc => svc.id.includes(ID_PLACEHOLDER_VALUE))) {
|
|
407
|
-
throw new DidDocumentError('Invalid
|
|
399
|
+
throw new DidDocumentError('Invalid GenesisDocument service', INVALID_DID_DOCUMENT, this);
|
|
408
400
|
}
|
|
409
401
|
if(!DidDocument.isValidVerificationRelationships(this)) {
|
|
410
402
|
// Return true if all validations pass
|
|
411
|
-
throw new DidDocumentError('Invalid
|
|
403
|
+
throw new DidDocumentError('Invalid GenesisDocument assertionMethod', INVALID_DID_DOCUMENT, this);
|
|
412
404
|
}
|
|
413
405
|
|
|
414
406
|
return true;
|
|
415
407
|
}
|
|
416
408
|
|
|
417
409
|
/**
|
|
418
|
-
* Convert the DidDocument to an
|
|
419
|
-
* @returns {
|
|
410
|
+
* Convert the DidDocument to an GenesisDocument.
|
|
411
|
+
* @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
|
|
420
412
|
*/
|
|
421
|
-
public toIntermediate():
|
|
413
|
+
public toIntermediate(): GenesisDocument {
|
|
422
414
|
if(this.id.includes('k1')) {
|
|
423
415
|
throw new DidDocumentError('Cannot convert a key identifier to an intermediate document', INVALID_DID_DOCUMENT, this);
|
|
424
416
|
}
|
|
425
|
-
return new
|
|
417
|
+
return new GenesisDocument(this);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export class Document {
|
|
422
|
+
public static isValid(didDocument: DidDocument | GenesisDocument): boolean {
|
|
423
|
+
return new DidDocument(didDocument).validateGenesis();
|
|
426
424
|
}
|
|
427
425
|
}
|
|
428
426
|
|
|
427
|
+
|
|
429
428
|
/**
|
|
430
|
-
*
|
|
429
|
+
* GenesisDocument extends the DidDocument class for creating and managing intermediate DID documents.
|
|
431
430
|
* This class is used to create a minimal DID document with a placeholder ID.
|
|
432
431
|
* It is used in the process of creating a new DID document.
|
|
433
|
-
* @class
|
|
432
|
+
* @class GenesisDocument
|
|
434
433
|
* @extends {DidDocument}
|
|
435
434
|
*/
|
|
436
|
-
export class
|
|
437
|
-
constructor(document:
|
|
438
|
-
super(document as
|
|
435
|
+
export class GenesisDocument extends DidDocument {
|
|
436
|
+
constructor(document: object | DidDocument) {
|
|
437
|
+
super(document as DidDocument);
|
|
439
438
|
}
|
|
440
439
|
|
|
441
440
|
/**
|
|
442
|
-
* Convert the
|
|
441
|
+
* Convert the GenesisDocument to a DidDocument by replacing the placeholder value with the provided DID.
|
|
443
442
|
* @param did The DID to replace the placeholder value in the document.
|
|
444
443
|
* @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
|
|
445
444
|
*/
|
|
446
445
|
public toDidDocument(did: string): DidDocument {
|
|
447
446
|
const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
|
|
448
|
-
const parseThis = JSON.parse(stringThis) as
|
|
447
|
+
const parseThis = JSON.parse(stringThis) as Btcr2DidDocument;
|
|
449
448
|
return new DidDocument(parseThis);
|
|
450
449
|
}
|
|
451
450
|
|
|
452
451
|
|
|
453
452
|
/**
|
|
454
|
-
* Create an
|
|
453
|
+
* Create an GenesisDocument from a DidDocument by replacing the DID with a placeholder value.
|
|
455
454
|
* @param {DidDocument} didDocument The DidDocument to convert.
|
|
456
|
-
* @returns {
|
|
455
|
+
* @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
|
|
457
456
|
*/
|
|
458
|
-
public static fromDidDocument(didDocument: DidDocument):
|
|
459
|
-
const intermediateDocument =
|
|
460
|
-
return new
|
|
457
|
+
public static fromDidDocument(didDocument: DidDocument): GenesisDocument {
|
|
458
|
+
const intermediateDocument = JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as Btcr2DidDocument;
|
|
459
|
+
return new GenesisDocument(intermediateDocument);
|
|
461
460
|
}
|
|
462
461
|
|
|
463
462
|
/**
|
|
464
|
-
* Create a minimal
|
|
463
|
+
* Create a minimal GenesisDocument with a placeholder ID.
|
|
465
464
|
* @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
|
|
466
465
|
* @param {VerificationRelationships} relationships The public key in multibase format.
|
|
467
466
|
* @param {Array<BeaconService>} service The service to be included in the document.
|
|
468
|
-
* @returns {
|
|
467
|
+
* @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
|
|
469
468
|
*/
|
|
470
469
|
public static create(
|
|
471
470
|
verificationMethod: Array<DidVerificationMethod>,
|
|
472
471
|
relationships: VerificationRelationships,
|
|
473
472
|
service: Array<BeaconService>
|
|
474
|
-
):
|
|
473
|
+
): GenesisDocument {
|
|
475
474
|
const id = ID_PLACEHOLDER_VALUE;
|
|
476
|
-
return new
|
|
475
|
+
return new GenesisDocument({ id, ...relationships, verificationMethod, service, });
|
|
477
476
|
}
|
|
478
477
|
|
|
479
478
|
/**
|
|
480
|
-
* Create a minimal
|
|
479
|
+
* Create a minimal GenesisDocument from a public key.
|
|
481
480
|
* @param {KeyBytes} publicKey The public key in bytes format.
|
|
482
|
-
* @returns {
|
|
481
|
+
* @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
|
|
483
482
|
*/
|
|
484
|
-
public static fromPublicKey(publicKey: KeyBytes, network: string):
|
|
483
|
+
public static fromPublicKey(publicKey: KeyBytes, network: string): GenesisDocument {
|
|
485
484
|
const pk = new CompressedSecp256k1PublicKey(publicKey);
|
|
486
485
|
const id = ID_PLACEHOLDER_VALUE;
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
});
|
|
486
|
+
const address = payments.p2pkh({ pubkey: pk.compressed, network: getNetwork(network) })?.address;
|
|
487
|
+
const services = [{
|
|
488
|
+
id : `${id}#key-0`,
|
|
489
|
+
serviceEndpoint : `bitcoin:${address}`,
|
|
490
|
+
type : 'SingletonBeacon',
|
|
491
|
+
}];
|
|
494
492
|
|
|
495
493
|
const relationships = {
|
|
496
494
|
authentication : [`${id}#key-0`],
|
|
@@ -507,21 +505,15 @@ export class IntermediateDidDocument extends DidDocument {
|
|
|
507
505
|
}
|
|
508
506
|
];
|
|
509
507
|
|
|
510
|
-
return
|
|
508
|
+
return GenesisDocument.create(verificationMethod, relationships, services);
|
|
511
509
|
}
|
|
512
510
|
|
|
513
511
|
/**
|
|
514
512
|
* Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
|
|
515
|
-
* @param {
|
|
513
|
+
* @param {object | DidDocument} object The JSON object to convert.
|
|
516
514
|
* @returns {DidDocument} The created DidDocument.
|
|
517
515
|
*/
|
|
518
|
-
public static fromJSON(object:
|
|
519
|
-
return new
|
|
516
|
+
public static fromJSON(object: object | DidDocument): GenesisDocument {
|
|
517
|
+
return new GenesisDocument(object as Btcr2DidDocument);
|
|
520
518
|
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
export class Document {
|
|
524
|
-
public static isValid(didDocument: DidDocument | IntermediateDidDocument): boolean {
|
|
525
|
-
return new DidDocument(didDocument).validateIntermediate();
|
|
526
|
-
}
|
|
527
|
-
}
|
|
519
|
+
}
|