@did-btcr2/method 0.18.0 → 0.19.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 +5240 -6079
- package/dist/browser.mjs +5240 -6079
- 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/cas-beacon.js +55 -0
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -0
- package/dist/cjs/core/beacon/factory.js +11 -10
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/interfaces.js +32 -0
- package/dist/cjs/core/beacon/interfaces.js.map +1 -0
- package/dist/cjs/core/beacon/singleton.js +59 -135
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +56 -0
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -0
- package/dist/cjs/core/beacon/utils.js +67 -105
- 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 +511 -0
- package/dist/cjs/core/resolve.js.map +1 -0
- package/dist/cjs/{utils → core}/types.js.map +1 -1
- package/dist/cjs/core/{crud/update.js → update.js} +62 -52
- package/dist/cjs/core/update.js.map +1 -0
- package/dist/cjs/did-btcr2.js +109 -75
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +14 -15
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/appendix.js +10 -18
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document.js +51 -58
- 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/cas-beacon.js +55 -0
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -0
- package/dist/esm/core/beacon/factory.js +11 -10
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/interfaces.js +32 -0
- package/dist/esm/core/beacon/interfaces.js.map +1 -0
- package/dist/esm/core/beacon/singleton.js +59 -135
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +56 -0
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -0
- package/dist/esm/core/beacon/utils.js +67 -105
- 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 +511 -0
- package/dist/esm/core/resolve.js.map +1 -0
- package/dist/esm/{utils → core}/types.js.map +1 -1
- package/dist/esm/core/{crud/update.js → update.js} +62 -52
- package/dist/esm/core/update.js.map +1 -0
- package/dist/esm/did-btcr2.js +109 -75
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +14 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +10 -18
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document.js +51 -58
- 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/cas-beacon.d.ts +47 -0
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/factory.d.ts +5 -4
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/interfaces.d.ts +98 -0
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -0
- package/dist/types/core/beacon/singleton.d.ts +22 -65
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +48 -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 +94 -0
- package/dist/types/core/interfaces.d.ts.map +1 -0
- package/dist/types/core/resolve.d.ts +105 -0
- package/dist/types/core/resolve.d.ts.map +1 -0
- package/dist/types/core/types.d.ts +71 -0
- package/dist/types/core/types.d.ts.map +1 -0
- package/dist/types/core/{crud/update.d.ts → update.d.ts} +21 -20
- package/dist/types/core/update.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +45 -57
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +14 -15
- 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 +1 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +31 -29
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +5 -5
- 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/cas-beacon.ts +67 -0
- package/src/core/beacon/factory.ts +13 -15
- package/src/core/beacon/interfaces.ts +124 -0
- package/src/core/beacon/singleton.ts +75 -145
- package/src/core/beacon/smt-beacon.ts +70 -0
- package/src/core/beacon/utils.ts +80 -170
- package/src/core/identifier.ts +21 -24
- package/src/core/interfaces.ts +101 -0
- package/src/core/resolve.ts +707 -0
- package/src/core/types.ts +78 -0
- package/src/core/{crud/update.ts → update.ts} +75 -68
- package/src/did-btcr2.ts +152 -92
- package/src/index.ts +14 -24
- package/src/utils/appendix.ts +18 -22
- package/src/utils/did-document-builder.ts +1 -1
- package/src/utils/did-document.ts +67 -71
- 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.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.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.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/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,48 +1,61 @@
|
|
|
1
|
+
import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
|
|
1
2
|
import {
|
|
3
|
+
Canonicalization,
|
|
2
4
|
DocumentBytes,
|
|
5
|
+
IdentifierHrp,
|
|
3
6
|
INVALID_DID_DOCUMENT,
|
|
4
7
|
KeyBytes,
|
|
5
8
|
METHOD_NOT_SUPPORTED,
|
|
6
9
|
MethodError,
|
|
10
|
+
MISSING_UPDATE_DATA,
|
|
7
11
|
PatchOperation,
|
|
8
|
-
|
|
12
|
+
ResolveError
|
|
9
13
|
} from '@did-btcr2/common';
|
|
10
|
-
import type { DidResolutionResult } from '@web5/dids';
|
|
11
14
|
import {
|
|
12
15
|
Did,
|
|
13
16
|
DidError,
|
|
14
17
|
DidErrorCode,
|
|
15
18
|
DidMethod,
|
|
19
|
+
DidResolutionResult,
|
|
16
20
|
EMPTY_DID_RESOLUTION_RESULT
|
|
17
21
|
} from '@web5/dids';
|
|
18
22
|
import { initEccLib } from 'bitcoinjs-lib';
|
|
19
23
|
import * as tinysecp from 'tiny-secp256k1';
|
|
20
|
-
import {
|
|
21
|
-
import { Update } from './core/crud/update.js';
|
|
22
|
-
import { DidResolutionOptions } from './interfaces/crud.js';
|
|
23
|
-
import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
|
|
24
|
-
import { SignalsMetadata } from './utils/types.js';
|
|
24
|
+
import { BeaconUtils } from './core/beacon/utils.js';
|
|
25
25
|
import { Identifier } from './core/identifier.js';
|
|
26
|
+
import { ResolutionOptions } from './core/interfaces.js';
|
|
27
|
+
import { Resolve } from './core/resolve.js';
|
|
28
|
+
import { SidecarData } from './core/types.js';
|
|
29
|
+
import { Update } from './core/update.js';
|
|
26
30
|
import { Appendix } from './utils/appendix.js';
|
|
31
|
+
import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
|
|
32
|
+
|
|
33
|
+
// TODO: convert to API driver
|
|
34
|
+
export const canonicalization = new Canonicalization();
|
|
27
35
|
|
|
28
36
|
export type Btcr2Identifier = string;
|
|
29
37
|
|
|
30
38
|
export interface DidCreateOptions {
|
|
39
|
+
/** Type of identifier to create (key or external) */
|
|
40
|
+
idType: 'KEY' | 'EXTERNAL';
|
|
31
41
|
/** DID BTCR2 Version Number */
|
|
32
42
|
version?: number;
|
|
33
43
|
/** Bitcoin Network */
|
|
34
44
|
network?: string;
|
|
35
45
|
}
|
|
36
46
|
|
|
47
|
+
// TODO: convert to API driver
|
|
37
48
|
/** Initialize tiny secp256k1 */
|
|
38
49
|
initEccLib(tinysecp);
|
|
39
50
|
|
|
40
51
|
/**
|
|
41
52
|
* Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
|
|
42
|
-
* did:btcr2 is a censorship
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
53
|
+
* did:btcr2 is a censorship-resistant Decentralized Identifier (DID) method using
|
|
54
|
+
* the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the
|
|
55
|
+
* DID document. It supports zero-cost off-chain DID creation; aggregated updates
|
|
56
|
+
* for scalable on-chain update costs; long-term identifiers that can support
|
|
57
|
+
* frequent updates; private communication of the DID document; private DID resolution;
|
|
58
|
+
* and non-repudiation.
|
|
46
59
|
*
|
|
47
60
|
* @class DidBtcr2
|
|
48
61
|
* @type {DidBtcr2}
|
|
@@ -50,105 +63,157 @@ initEccLib(tinysecp);
|
|
|
50
63
|
*/
|
|
51
64
|
export class DidBtcr2 implements DidMethod {
|
|
52
65
|
/** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
|
|
53
|
-
|
|
66
|
+
static methodName: string = 'btcr2';
|
|
54
67
|
|
|
55
68
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* Bitcoin network to
|
|
63
|
-
* @
|
|
64
|
-
* @
|
|
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
|
|
69
|
+
* Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
|
|
70
|
+
* @param {KeyBytes | DocumentBytes} genesisBytes The bytes used to create the genesis document for a did:btcr2 identifier.
|
|
71
|
+
* 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.
|
|
72
|
+
* @param {DidCreateOptions} options Options for creating the identifier, including the idType (key or external), version, and network.
|
|
73
|
+
* @param {string} options.idType The type of identifier to create, either 'KEY' or 'EXTERNAL'. Defaults to 'KEY'.
|
|
74
|
+
* @param {number} options.version The version number of the did:btcr2 specification to use for creating the identifier. Defaults to 1.
|
|
75
|
+
* @param {string} options.network The Bitcoin network to use for the identifier, e.g. 'bitcoin', 'testnet', etc. Defaults to 'bitcoin'.
|
|
76
|
+
* @returns {Promise<Btcr2Identifier>} Promise resolving to a Btcr2Identifier string.
|
|
77
|
+
* @throws {MethodError} if any of the checks fail
|
|
72
78
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const { idType, options = {} } = params;
|
|
79
|
+
static async create(
|
|
80
|
+
genesisBytes: KeyBytes | DocumentBytes,
|
|
81
|
+
options?: DidCreateOptions
|
|
82
|
+
): Promise<Btcr2Identifier> {
|
|
83
|
+
// Deconstruct the idType, version and network from the options, setting defaults if not given
|
|
84
|
+
const { idType, version = 1, network = 'bitcoin' } = options || {};
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if(!idType) {
|
|
87
|
+
throw new MethodError(
|
|
88
|
+
'idType is required for creating a did:btcr2 identifier',
|
|
89
|
+
INVALID_DID_DOCUMENT, options
|
|
90
|
+
);
|
|
91
|
+
}
|
|
86
92
|
|
|
93
|
+
// Call identifier encoding algorithm
|
|
87
94
|
return Identifier.encode({ idType, genesisBytes, version, network });
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
/**
|
|
91
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2
|
|
92
|
-
* See {@link
|
|
98
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Resolve}.
|
|
99
|
+
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
100
|
+
* See {@link Resolve | Resolve (class)} for class implementation.
|
|
93
101
|
*
|
|
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.
|
|
102
|
+
* Resolving a did:btcr2 identifier iteratively builds a DID document by applying
|
|
103
|
+
* BTCR2 Updates to an Initial DID Document that have been committed to the Bitcoin
|
|
104
|
+
* blockchain by Authorized Beacon Signals. The Initial DID Document is either
|
|
105
|
+
* deterministically created from the DID or provided by Sidecar Data.
|
|
100
106
|
*
|
|
101
|
-
* @param {string}
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {number}
|
|
104
|
-
* @param {number}
|
|
105
|
-
* @param {DidDocument}
|
|
106
|
-
* @
|
|
107
|
-
* @returns {DidResolutionResult} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
107
|
+
* @param {string} did a valid did:btcr2 identifier to be resolved
|
|
108
|
+
* @param {ResolutionOptions} resolutionOptions see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | ResolutionOptions}
|
|
109
|
+
* @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
|
|
110
|
+
* @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
|
|
111
|
+
* @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
|
|
112
|
+
* @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
108
113
|
* @throws {Error} if the resolution fails for any reason
|
|
109
114
|
* @throws {DidError} InvalidDid if the identifier is invalid
|
|
110
115
|
* @example
|
|
111
116
|
* ```ts
|
|
112
|
-
* const resolution = await DidBtcr2.resolve(
|
|
117
|
+
* const resolution = await DidBtcr2.resolve(
|
|
118
|
+
* 'did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh'
|
|
119
|
+
* )
|
|
113
120
|
* ```
|
|
114
121
|
*/
|
|
115
|
-
|
|
122
|
+
static async resolve(did: string, resolutionOptions: ResolutionOptions = {drivers: {}}): Promise<DidResolutionResult> {
|
|
116
123
|
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
124
|
|
|
121
|
-
//
|
|
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
|
-
|
|
128
|
-
// 4. Set targetDocument to the result of running the algorithm in Resolve Target Document passing in
|
|
129
|
-
// initialDocument and resolutionOptions.
|
|
130
|
-
const targetDocument = await Resolve.targetDocument({ initialDocument, resolutionsOptions });
|
|
131
|
-
|
|
132
|
-
// 5. Return targetDocument.
|
|
125
|
+
// Initialize an empty DID Resolution Result
|
|
133
126
|
const didResolutionResult: DidResolutionResult = {
|
|
134
|
-
'@context' :
|
|
127
|
+
'@context' : 'https://w3id.org/did-resolution/v1',
|
|
135
128
|
didResolutionMetadata : { contentType: 'application/ld+json' },
|
|
136
|
-
didDocumentMetadata : {
|
|
137
|
-
|
|
129
|
+
didDocumentMetadata : {
|
|
130
|
+
deactivated : false,
|
|
131
|
+
updated : undefined,
|
|
132
|
+
versionId : resolutionOptions.versionId,
|
|
133
|
+
confirmations : undefined,
|
|
134
|
+
},
|
|
135
|
+
didDocument : null,
|
|
138
136
|
};
|
|
139
137
|
|
|
138
|
+
// Decode the did to be resolved
|
|
139
|
+
const didComponents = Identifier.decode(did);
|
|
140
|
+
|
|
141
|
+
// Process sidecar if provided
|
|
142
|
+
const sidecarData = Resolve.processSidecarData(resolutionOptions.sidecar);
|
|
143
|
+
|
|
144
|
+
// Establish a connection to a bitcoin network
|
|
145
|
+
if(!resolutionOptions.drivers.bitcoin) {
|
|
146
|
+
resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
|
|
147
|
+
// Set the network based on the decoded identifier
|
|
148
|
+
resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Parse the genesis document from the resolution options if provided
|
|
152
|
+
const genesisDocument = resolutionOptions.sidecar?.genesisDocument;
|
|
153
|
+
// Since genesisDocument is optional, check if it exists
|
|
154
|
+
if(!genesisDocument) {
|
|
155
|
+
// If no genesisDocument and x HRP, throw MISSING_UPDATE_DATA error
|
|
156
|
+
if(didComponents.hrp === IdentifierHrp.x)
|
|
157
|
+
throw new ResolveError(
|
|
158
|
+
'External resolution requires genesisDocument',
|
|
159
|
+
MISSING_UPDATE_DATA, { resolutionOptions }
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Establish the current document
|
|
164
|
+
const currentDocument = await Resolve.establishCurrentDocument(didComponents, genesisDocument);
|
|
165
|
+
|
|
166
|
+
// Extract all Beacon services from the current DID Document
|
|
167
|
+
const beaconServices = currentDocument.service
|
|
168
|
+
.filter(BeaconUtils.isBeaconService)
|
|
169
|
+
.map(BeaconUtils.parseBeaconServiceEndpoint);
|
|
170
|
+
|
|
171
|
+
// Process the Beacon Signals to get the required updates
|
|
172
|
+
const unsortedUpdates = await Resolve.processBeaconSignals(
|
|
173
|
+
beaconServices,
|
|
174
|
+
sidecarData,
|
|
175
|
+
resolutionOptions.drivers.bitcoin,
|
|
176
|
+
resolutionOptions.fullBlockchainTraversal
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
// If no updates found, return the current document
|
|
180
|
+
if(!unsortedUpdates.length) {
|
|
181
|
+
// Set the current document in the didResolutionResult
|
|
182
|
+
didResolutionResult.didDocument = currentDocument;
|
|
183
|
+
|
|
184
|
+
// Set the deactivated status in the didDocumentMetadata
|
|
185
|
+
didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
|
|
186
|
+
|
|
187
|
+
// Return the didResolutionResult early
|
|
188
|
+
return didResolutionResult;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Process the updates to apply updates to bring the current DID Document to its more current state
|
|
192
|
+
const result = await Resolve.processUpdatesArray(
|
|
193
|
+
currentDocument,
|
|
194
|
+
unsortedUpdates,
|
|
195
|
+
resolutionOptions.versionTime,
|
|
196
|
+
resolutionOptions.versionId
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
// Set all of the required fields in the didResolutionResult
|
|
200
|
+
didResolutionResult.didDocument = result.currentDocument;
|
|
201
|
+
didResolutionResult.didDocumentMetadata.confirmations = result.confirmations;
|
|
202
|
+
didResolutionResult.didDocumentMetadata.versionId = result.versionId;
|
|
203
|
+
didResolutionResult.didDocumentMetadata.deactivated = !!result.currentDocument.deactivated;
|
|
204
|
+
|
|
140
205
|
// Return didResolutionResult;
|
|
141
206
|
return didResolutionResult;
|
|
142
207
|
} catch (error: any) {
|
|
143
208
|
console.error(error);
|
|
144
|
-
// Rethrow any unexpected errors that are not a `
|
|
145
|
-
if (!(error instanceof
|
|
209
|
+
// Rethrow any unexpected errors that are not a `ResolveError`.
|
|
210
|
+
if (!(error instanceof ResolveError)) throw new Error(error);
|
|
146
211
|
|
|
147
212
|
// Return a DID Resolution Result with the appropriate error code.
|
|
148
213
|
return {
|
|
149
214
|
...EMPTY_DID_RESOLUTION_RESULT,
|
|
150
215
|
didResolutionMetadata : {
|
|
151
|
-
error : error.
|
|
216
|
+
error : error.type,
|
|
152
217
|
...error.message && { errorMessage: error.message }
|
|
153
218
|
}
|
|
154
219
|
};
|
|
@@ -170,7 +235,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
170
235
|
* The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
|
|
171
236
|
* verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
|
|
172
237
|
* identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
|
|
173
|
-
* Types SingletonBeacon,
|
|
238
|
+
* Types SingletonBeacon, CASBeacon, and SMTBeacon.
|
|
174
239
|
*
|
|
175
240
|
* @param {UpdateParams} params Required parameters for the update operation.
|
|
176
241
|
* @param {string} params.identifier The btcr2 identifier to be updated.
|
|
@@ -189,7 +254,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
189
254
|
patch: PatchOperation[];
|
|
190
255
|
verificationMethodId: string;
|
|
191
256
|
beaconIds: string[];
|
|
192
|
-
}): Promise<
|
|
257
|
+
}): Promise<SidecarData> {
|
|
193
258
|
// Deconstruct the params
|
|
194
259
|
const {
|
|
195
260
|
identifier,
|
|
@@ -203,7 +268,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
203
268
|
// 1. Set unsignedUpdate to the result of passing Identifier, sourceDocument,
|
|
204
269
|
// sourceVersionId, and documentPatch into the Construct DID Update
|
|
205
270
|
// Payload algorithm.
|
|
206
|
-
const
|
|
271
|
+
const unsignedUpdate = await Update.construct({
|
|
207
272
|
identifier,
|
|
208
273
|
sourceDocument,
|
|
209
274
|
sourceVersionId,
|
|
@@ -212,7 +277,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
212
277
|
|
|
213
278
|
// 2. Set verificationMethod to the result of retrieving the verificationMethod
|
|
214
279
|
// from sourceDocument using the verificationMethodId.
|
|
215
|
-
const verificationMethod = this.getSigningMethod(
|
|
280
|
+
const verificationMethod = this.getSigningMethod(sourceDocument, methodId);
|
|
216
281
|
|
|
217
282
|
// Validate the verificationMethod exists in the sourceDocument
|
|
218
283
|
if (!verificationMethod) {
|
|
@@ -233,11 +298,11 @@ export class DidBtcr2 implements DidMethod {
|
|
|
233
298
|
|
|
234
299
|
// 4. Set didUpdateInvocation to the result of passing Identifier, unsignedUpdate as didUpdatePayload, and
|
|
235
300
|
// verificationMethod to the Invoke DID Update Payload algorithm.
|
|
236
|
-
const
|
|
301
|
+
const signedUpdate = await Update.invoke({ identifier, verificationMethod, unsignedUpdate });
|
|
237
302
|
|
|
238
303
|
// 5. Set signalsMetadata to the result of passing Identifier, sourceDocument, beaconIds and didUpdateInvocation
|
|
239
304
|
// to the Announce DID Update algorithm.
|
|
240
|
-
const signalsMetadata = await Update.announce({ sourceDocument, beaconIds,
|
|
305
|
+
const signalsMetadata = await Update.announce({ sourceDocument, beaconIds, signedUpdate });
|
|
241
306
|
|
|
242
307
|
// 6. Return signalsMetadata. It is up to implementations to ensure that the signalsMetadata is persisted.
|
|
243
308
|
return signalsMetadata;
|
|
@@ -249,17 +314,12 @@ export class DidBtcr2 implements DidMethod {
|
|
|
249
314
|
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
250
315
|
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
251
316
|
* 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.
|
|
317
|
+
* @param {DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
|
|
318
|
+
* @param {string} [methodId] Optional verification method ID to be used for signing.
|
|
256
319
|
* @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
|
|
257
320
|
* @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
|
|
258
321
|
*/
|
|
259
|
-
public static getSigningMethod(
|
|
260
|
-
didDocument: DidDocument;
|
|
261
|
-
methodId?: string;
|
|
262
|
-
}): DidVerificationMethod {
|
|
322
|
+
public static getSigningMethod(didDocument: DidDocument, methodId?: string): DidVerificationMethod {
|
|
263
323
|
// Set the default methodId to the first assertionMethod if not given
|
|
264
324
|
methodId ??= '#initialKey';
|
|
265
325
|
|
package/src/index.ts
CHANGED
|
@@ -1,54 +1,44 @@
|
|
|
1
|
+
export * from './core/beacon/aggregation/cohort/index.js';
|
|
2
|
+
export * from './core/beacon/aggregation/cohort/messages/base.js';
|
|
3
|
+
export * from './core/beacon/aggregation/cohort/messages/constants.js';
|
|
4
|
+
export * from './core/beacon/aggregation/cohort/messages/index.js';
|
|
5
|
+
export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
|
|
1
6
|
export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js';
|
|
2
7
|
export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js';
|
|
3
8
|
export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js';
|
|
4
9
|
export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in.js';
|
|
5
|
-
export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
|
|
6
|
-
|
|
7
10
|
export * from './core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js';
|
|
8
11
|
export * from './core/beacon/aggregation/cohort/messages/sign/authorization-request.js';
|
|
9
12
|
export * from './core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js';
|
|
10
13
|
export * from './core/beacon/aggregation/cohort/messages/sign/request-signature.js';
|
|
11
14
|
export * from './core/beacon/aggregation/cohort/messages/sign/signature-authorization.js';
|
|
12
|
-
|
|
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
15
|
export * from './core/beacon/aggregation/cohort/status.js';
|
|
19
|
-
|
|
20
16
|
export * from './core/beacon/aggregation/communication/adapter/did-comm.js';
|
|
21
17
|
export * from './core/beacon/aggregation/communication/adapter/nostr.js';
|
|
22
18
|
export * from './core/beacon/aggregation/communication/error.js';
|
|
23
19
|
export * from './core/beacon/aggregation/communication/factory.js';
|
|
24
20
|
export * from './core/beacon/aggregation/communication/service.js';
|
|
25
|
-
|
|
26
|
-
export * from './core/beacon/aggregation/session/index.js';
|
|
27
|
-
export * from './core/beacon/aggregation/session/status.js';
|
|
28
|
-
|
|
29
21
|
export * from './core/beacon/aggregation/coordinator.js';
|
|
30
22
|
export * from './core/beacon/aggregation/participant.js';
|
|
31
|
-
|
|
32
|
-
export * from './core/beacon/
|
|
23
|
+
export * from './core/beacon/aggregation/session/index.js';
|
|
24
|
+
export * from './core/beacon/aggregation/session/status.js';
|
|
25
|
+
export * from './core/beacon/cas-beacon.js';
|
|
33
26
|
export * from './core/beacon/error.js';
|
|
34
27
|
export * from './core/beacon/factory.js';
|
|
28
|
+
export * from './core/beacon/interfaces.js';
|
|
35
29
|
export * from './core/beacon/singleton.js';
|
|
36
|
-
export * from './core/beacon/smt-
|
|
30
|
+
export * from './core/beacon/smt-beacon.js';
|
|
37
31
|
export * from './core/beacon/utils.js';
|
|
38
32
|
|
|
39
|
-
export * from './core/crud/deactivate.js';
|
|
40
|
-
export * from './core/crud/read.js';
|
|
41
|
-
export * from './core/crud/update.js';
|
|
42
|
-
|
|
43
33
|
export * from './core/identifier.js';
|
|
44
|
-
|
|
45
|
-
export * from './
|
|
46
|
-
export * from './
|
|
34
|
+
export * from './core/interfaces.js';
|
|
35
|
+
export * from './core/resolve.js';
|
|
36
|
+
export * from './core/types.js';
|
|
37
|
+
export * from './core/update.js';
|
|
47
38
|
|
|
48
39
|
export * from './utils/appendix.js';
|
|
49
40
|
export * from './utils/did-document-builder.js';
|
|
50
41
|
export * from './utils/did-document.js';
|
|
51
42
|
export * from './utils/general.js';
|
|
52
|
-
export * from './utils/types.js';
|
|
53
43
|
|
|
54
44
|
export * from './did-btcr2.js';
|
package/src/utils/appendix.ts
CHANGED
|
@@ -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.
|
|
@@ -173,7 +173,7 @@ export class Appendix {
|
|
|
173
173
|
* }
|
|
174
174
|
* }
|
|
175
175
|
*/
|
|
176
|
-
public static
|
|
176
|
+
public static dereferenceZcapId(capabilityId: string): RootCapability {
|
|
177
177
|
// 1. Set rootCapability to an empty object.
|
|
178
178
|
const rootCapability = {} as RootCapability;
|
|
179
179
|
|
|
@@ -221,28 +221,24 @@ export class Appendix {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
|
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.
|
|
224
|
+
* Implements CAS Lookup Step from {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-beacon-signals | 7.2.e Process Beacon Signals }.
|
|
225
|
+
* @param {HashBytes} hashBytes The hash bytes to look up in the CAS system.
|
|
226
|
+
* @returns {Promise<string | undefined>} The content fetched from the CAS system, or undefined if not found.
|
|
232
227
|
*/
|
|
233
|
-
|
|
234
|
-
//
|
|
228
|
+
static async fetchFromCas(hashBytes: HashBytes): Promise<string | undefined> {
|
|
229
|
+
// Construct CID from hash bytes
|
|
235
230
|
const cid = CID.create(1, 1, createDigest(1, hashBytes));
|
|
236
231
|
|
|
237
|
-
//
|
|
238
|
-
const helia =
|
|
232
|
+
// Connect to IPFS/Helia node
|
|
233
|
+
const helia = await createHelia();
|
|
234
|
+
const node = strings(helia);
|
|
239
235
|
|
|
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;
|
|
236
|
+
// Return the IPFS get result
|
|
237
|
+
return await node.get(cid, {});
|
|
247
238
|
}
|
|
248
|
-
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
export class DidDocumentBuilder {
|