@did-btcr2/method 0.13.1
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/LICENSE +373 -0
- package/README.md +7 -0
- package/dist/browser.js +2364 -0
- package/dist/browser.js.map +7 -0
- package/dist/browser.mjs +2364 -0
- package/dist/browser.mjs.map +7 -0
- package/dist/cjs/bitcoin/constants.js +20 -0
- package/dist/cjs/bitcoin/constants.js.map +1 -0
- package/dist/cjs/bitcoin/errors.js +11 -0
- package/dist/cjs/bitcoin/errors.js.map +1 -0
- package/dist/cjs/bitcoin/index.js +95 -0
- package/dist/cjs/bitcoin/index.js.map +1 -0
- package/dist/cjs/bitcoin/interface.js +2 -0
- package/dist/cjs/bitcoin/interface.js.map +1 -0
- package/dist/cjs/bitcoin/network.js +17 -0
- package/dist/cjs/bitcoin/network.js.map +1 -0
- package/dist/cjs/bitcoin/rest-client.js +289 -0
- package/dist/cjs/bitcoin/rest-client.js.map +1 -0
- package/dist/cjs/bitcoin/rpc-client.js +722 -0
- package/dist/cjs/bitcoin/rpc-client.js.map +1 -0
- package/dist/cjs/bitcoin/taproot.js +219 -0
- package/dist/cjs/bitcoin/taproot.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/coordinator.js +120 -0
- package/dist/cjs/btcr2/beacon/aggregation/coordinator.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/advert.js +24 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/advert.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/base.js +37 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/base.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/cohort-set.js +25 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/cohort-set.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/keygen.js +8 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/keygen.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/opt-in.js +23 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/opt-in.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/sign.js +7 -0
- package/dist/cjs/btcr2/beacon/aggregation/messages/sign.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/models/cohort/index.js +92 -0
- package/dist/cjs/btcr2/beacon/aggregation/models/cohort/index.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/models/cohort/status.js +8 -0
- package/dist/cjs/btcr2/beacon/aggregation/models/cohort/status.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/participant.js +2 -0
- package/dist/cjs/btcr2/beacon/aggregation/participant.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/protocol/nostr.js +57 -0
- package/dist/cjs/btcr2/beacon/aggregation/protocol/nostr.js.map +1 -0
- package/dist/cjs/btcr2/beacon/aggregation/protocol/service.js +2 -0
- package/dist/cjs/btcr2/beacon/aggregation/protocol/service.js.map +1 -0
- package/dist/cjs/btcr2/beacon/cid-aggregate.js +116 -0
- package/dist/cjs/btcr2/beacon/cid-aggregate.js.map +1 -0
- package/dist/cjs/btcr2/beacon/factory.js +30 -0
- package/dist/cjs/btcr2/beacon/factory.js.map +1 -0
- package/dist/cjs/btcr2/beacon/singleton.js +220 -0
- package/dist/cjs/btcr2/beacon/singleton.js.map +1 -0
- package/dist/cjs/btcr2/beacon/smt-aggregate.js +126 -0
- package/dist/cjs/btcr2/beacon/smt-aggregate.js.map +1 -0
- package/dist/cjs/btcr2/crud/create.js +102 -0
- package/dist/cjs/btcr2/crud/create.js.map +1 -0
- package/dist/cjs/btcr2/crud/deactivate.js +14 -0
- package/dist/cjs/btcr2/crud/deactivate.js.map +1 -0
- package/dist/cjs/btcr2/crud/read.js +686 -0
- package/dist/cjs/btcr2/crud/read.js.map +1 -0
- package/dist/cjs/btcr2/crud/update.js +195 -0
- package/dist/cjs/btcr2/crud/update.js.map +1 -0
- package/dist/cjs/btcr2/key-manager/index.js +290 -0
- package/dist/cjs/btcr2/key-manager/index.js.map +1 -0
- package/dist/cjs/btcr2/key-manager/interface.js +2 -0
- package/dist/cjs/btcr2/key-manager/interface.js.map +1 -0
- package/dist/cjs/did-btcr2.js +222 -0
- package/dist/cjs/did-btcr2.js.map +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interfaces/beacon.js +41 -0
- package/dist/cjs/interfaces/beacon.js.map +1 -0
- package/dist/cjs/interfaces/crud.js +2 -0
- package/dist/cjs/interfaces/crud.js.map +1 -0
- package/dist/cjs/interfaces/ibeacon.js +2 -0
- package/dist/cjs/interfaces/ibeacon.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/bitcoin.js +62 -0
- package/dist/cjs/types/bitcoin.js.map +1 -0
- package/dist/cjs/types/crud.js +2 -0
- package/dist/cjs/types/crud.js.map +1 -0
- package/dist/cjs/utils/appendix.js +221 -0
- package/dist/cjs/utils/appendix.js.map +1 -0
- package/dist/cjs/utils/beacons.js +206 -0
- package/dist/cjs/utils/beacons.js.map +1 -0
- package/dist/cjs/utils/did-document-builder.js +61 -0
- package/dist/cjs/utils/did-document-builder.js.map +1 -0
- package/dist/cjs/utils/did-document.js +380 -0
- package/dist/cjs/utils/did-document.js.map +1 -0
- package/dist/cjs/utils/general.js +195 -0
- package/dist/cjs/utils/general.js.map +1 -0
- package/dist/cjs/utils/identifier.js +238 -0
- package/dist/cjs/utils/identifier.js.map +1 -0
- package/dist/esm/bitcoin/constants.js +20 -0
- package/dist/esm/bitcoin/constants.js.map +1 -0
- package/dist/esm/bitcoin/errors.js +11 -0
- package/dist/esm/bitcoin/errors.js.map +1 -0
- package/dist/esm/bitcoin/index.js +95 -0
- package/dist/esm/bitcoin/index.js.map +1 -0
- package/dist/esm/bitcoin/interface.js +2 -0
- package/dist/esm/bitcoin/interface.js.map +1 -0
- package/dist/esm/bitcoin/network.js +17 -0
- package/dist/esm/bitcoin/network.js.map +1 -0
- package/dist/esm/bitcoin/rest-client.js +289 -0
- package/dist/esm/bitcoin/rest-client.js.map +1 -0
- package/dist/esm/bitcoin/rpc-client.js +722 -0
- package/dist/esm/bitcoin/rpc-client.js.map +1 -0
- package/dist/esm/bitcoin/taproot.js +219 -0
- package/dist/esm/bitcoin/taproot.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/coordinator.js +120 -0
- package/dist/esm/btcr2/beacon/aggregation/coordinator.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/advert.js +24 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/advert.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/base.js +37 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/base.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/cohort-set.js +25 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/cohort-set.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/keygen.js +8 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/keygen.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/opt-in.js +23 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/opt-in.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/sign.js +7 -0
- package/dist/esm/btcr2/beacon/aggregation/messages/sign.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/models/cohort/index.js +92 -0
- package/dist/esm/btcr2/beacon/aggregation/models/cohort/index.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/models/cohort/status.js +8 -0
- package/dist/esm/btcr2/beacon/aggregation/models/cohort/status.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/participant.js +2 -0
- package/dist/esm/btcr2/beacon/aggregation/participant.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/protocol/nostr.js +57 -0
- package/dist/esm/btcr2/beacon/aggregation/protocol/nostr.js.map +1 -0
- package/dist/esm/btcr2/beacon/aggregation/protocol/service.js +2 -0
- package/dist/esm/btcr2/beacon/aggregation/protocol/service.js.map +1 -0
- package/dist/esm/btcr2/beacon/cid-aggregate.js +116 -0
- package/dist/esm/btcr2/beacon/cid-aggregate.js.map +1 -0
- package/dist/esm/btcr2/beacon/factory.js +30 -0
- package/dist/esm/btcr2/beacon/factory.js.map +1 -0
- package/dist/esm/btcr2/beacon/singleton.js +220 -0
- package/dist/esm/btcr2/beacon/singleton.js.map +1 -0
- package/dist/esm/btcr2/beacon/smt-aggregate.js +126 -0
- package/dist/esm/btcr2/beacon/smt-aggregate.js.map +1 -0
- package/dist/esm/btcr2/crud/create.js +102 -0
- package/dist/esm/btcr2/crud/create.js.map +1 -0
- package/dist/esm/btcr2/crud/deactivate.js +14 -0
- package/dist/esm/btcr2/crud/deactivate.js.map +1 -0
- package/dist/esm/btcr2/crud/read.js +686 -0
- package/dist/esm/btcr2/crud/read.js.map +1 -0
- package/dist/esm/btcr2/crud/update.js +195 -0
- package/dist/esm/btcr2/crud/update.js.map +1 -0
- package/dist/esm/btcr2/key-manager/index.js +290 -0
- package/dist/esm/btcr2/key-manager/index.js.map +1 -0
- package/dist/esm/btcr2/key-manager/interface.js +2 -0
- package/dist/esm/btcr2/key-manager/interface.js.map +1 -0
- package/dist/esm/did-btcr2.js +222 -0
- package/dist/esm/did-btcr2.js.map +1 -0
- package/dist/esm/index.js +27 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces/beacon.js +41 -0
- package/dist/esm/interfaces/beacon.js.map +1 -0
- package/dist/esm/interfaces/crud.js +2 -0
- package/dist/esm/interfaces/crud.js.map +1 -0
- package/dist/esm/interfaces/ibeacon.js +2 -0
- package/dist/esm/interfaces/ibeacon.js.map +1 -0
- package/dist/esm/types/bitcoin.js +62 -0
- package/dist/esm/types/bitcoin.js.map +1 -0
- package/dist/esm/types/crud.js +2 -0
- package/dist/esm/types/crud.js.map +1 -0
- package/dist/esm/utils/appendix.js +221 -0
- package/dist/esm/utils/appendix.js.map +1 -0
- package/dist/esm/utils/beacons.js +206 -0
- package/dist/esm/utils/beacons.js.map +1 -0
- package/dist/esm/utils/did-document-builder.js +61 -0
- package/dist/esm/utils/did-document-builder.js.map +1 -0
- package/dist/esm/utils/did-document.js +380 -0
- package/dist/esm/utils/did-document.js.map +1 -0
- package/dist/esm/utils/general.js +195 -0
- package/dist/esm/utils/general.js.map +1 -0
- package/dist/esm/utils/identifier.js +238 -0
- package/dist/esm/utils/identifier.js.map +1 -0
- package/dist/types/bitcoin/constants.d.ts +19 -0
- package/dist/types/bitcoin/constants.d.ts.map +1 -0
- package/dist/types/bitcoin/errors.d.ts +5 -0
- package/dist/types/bitcoin/errors.d.ts.map +1 -0
- package/dist/types/bitcoin/index.d.ts +75 -0
- package/dist/types/bitcoin/index.d.ts.map +1 -0
- package/dist/types/bitcoin/interface.d.ts +86 -0
- package/dist/types/bitcoin/interface.d.ts.map +1 -0
- package/dist/types/bitcoin/network.d.ts +2 -0
- package/dist/types/bitcoin/network.d.ts.map +1 -0
- package/dist/types/bitcoin/rest-client.d.ts +268 -0
- package/dist/types/bitcoin/rest-client.d.ts.map +1 -0
- package/dist/types/bitcoin/rpc-client.d.ts +506 -0
- package/dist/types/bitcoin/rpc-client.d.ts.map +1 -0
- package/dist/types/bitcoin/taproot.d.ts +34 -0
- package/dist/types/bitcoin/taproot.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/coordinator.d.ts +74 -0
- package/dist/types/btcr2/beacon/aggregation/coordinator.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/advert.d.ts +22 -0
- package/dist/types/btcr2/beacon/aggregation/messages/advert.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/base.d.ts +36 -0
- package/dist/types/btcr2/beacon/aggregation/messages/base.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/cohort-set.d.ts +23 -0
- package/dist/types/btcr2/beacon/aggregation/messages/cohort-set.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/keygen.d.ts +6 -0
- package/dist/types/btcr2/beacon/aggregation/messages/keygen.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/opt-in.d.ts +22 -0
- package/dist/types/btcr2/beacon/aggregation/messages/opt-in.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/messages/sign.d.ts +5 -0
- package/dist/types/btcr2/beacon/aggregation/messages/sign.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/models/cohort/index.d.ts +77 -0
- package/dist/types/btcr2/beacon/aggregation/models/cohort/index.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/models/cohort/status.d.ts +7 -0
- package/dist/types/btcr2/beacon/aggregation/models/cohort/status.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/participant.d.ts +1 -0
- package/dist/types/btcr2/beacon/aggregation/participant.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/protocol/nostr.d.ts +36 -0
- package/dist/types/btcr2/beacon/aggregation/protocol/nostr.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/aggregation/protocol/service.d.ts +6 -0
- package/dist/types/btcr2/beacon/aggregation/protocol/service.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/cid-aggregate.d.ts +103 -0
- package/dist/types/btcr2/beacon/cid-aggregate.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/factory.d.ts +17 -0
- package/dist/types/btcr2/beacon/factory.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/singleton.d.ts +93 -0
- package/dist/types/btcr2/beacon/singleton.d.ts.map +1 -0
- package/dist/types/btcr2/beacon/smt-aggregate.d.ts +112 -0
- package/dist/types/btcr2/beacon/smt-aggregate.d.ts.map +1 -0
- package/dist/types/btcr2/crud/create.d.ts +92 -0
- package/dist/types/btcr2/crud/create.d.ts.map +1 -0
- package/dist/types/btcr2/crud/deactivate.d.ts +13 -0
- package/dist/types/btcr2/crud/deactivate.d.ts.map +1 -0
- package/dist/types/btcr2/crud/read.d.ts +341 -0
- package/dist/types/btcr2/crud/read.d.ts.map +1 -0
- package/dist/types/btcr2/crud/update.d.ts +83 -0
- package/dist/types/btcr2/crud/update.d.ts.map +1 -0
- package/dist/types/btcr2/key-manager/index.d.ts +145 -0
- package/dist/types/btcr2/key-manager/index.d.ts.map +1 -0
- package/dist/types/btcr2/key-manager/interface.d.ts +113 -0
- package/dist/types/btcr2/key-manager/interface.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +117 -0
- package/dist/types/did-btcr2.d.ts.map +1 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/interfaces/beacon.d.ts +57 -0
- package/dist/types/interfaces/beacon.d.ts.map +1 -0
- package/dist/types/interfaces/crud.d.ts +35 -0
- package/dist/types/interfaces/crud.d.ts.map +1 -0
- package/dist/types/interfaces/ibeacon.d.ts +66 -0
- package/dist/types/interfaces/ibeacon.d.ts.map +1 -0
- package/dist/types/types/bitcoin.d.ts +827 -0
- package/dist/types/types/bitcoin.d.ts.map +1 -0
- package/dist/types/types/crud.d.ts +38 -0
- package/dist/types/types/crud.d.ts.map +1 -0
- package/dist/types/utils/appendix.d.ts +118 -0
- package/dist/types/utils/appendix.d.ts.map +1 -0
- package/dist/types/utils/beacons.d.ts +156 -0
- package/dist/types/utils/beacons.d.ts.map +1 -0
- package/dist/types/utils/did-document-builder.d.ts +13 -0
- package/dist/types/utils/did-document-builder.d.ts.map +1 -0
- package/dist/types/utils/did-document.d.ts +211 -0
- package/dist/types/utils/did-document.d.ts.map +1 -0
- package/dist/types/utils/general.d.ts +85 -0
- package/dist/types/utils/general.d.ts.map +1 -0
- package/dist/types/utils/identifier.d.ts +59 -0
- package/dist/types/utils/identifier.d.ts.map +1 -0
- package/package.json +137 -0
- package/src/bitcoin/constants.ts +19 -0
- package/src/bitcoin/errors.ts +10 -0
- package/src/bitcoin/index.ts +154 -0
- package/src/bitcoin/interface.ts +160 -0
- package/src/bitcoin/network.ts +17 -0
- package/src/bitcoin/rest-client.ts +415 -0
- package/src/bitcoin/rpc-client.ts +888 -0
- package/src/bitcoin/taproot.ts +237 -0
- package/src/btcr2/beacon/aggregation/coordinator.ts +135 -0
- package/src/btcr2/beacon/aggregation/messages/advert.ts +36 -0
- package/src/btcr2/beacon/aggregation/messages/base.ts +59 -0
- package/src/btcr2/beacon/aggregation/messages/cohort-set.ts +37 -0
- package/src/btcr2/beacon/aggregation/messages/keygen.ts +8 -0
- package/src/btcr2/beacon/aggregation/messages/opt-in.ts +35 -0
- package/src/btcr2/beacon/aggregation/messages/sign.ts +7 -0
- package/src/btcr2/beacon/aggregation/models/cohort/index.ts +112 -0
- package/src/btcr2/beacon/aggregation/models/cohort/status.ts +7 -0
- package/src/btcr2/beacon/aggregation/participant.ts +0 -0
- package/src/btcr2/beacon/aggregation/protocol/nostr.ts +81 -0
- package/src/btcr2/beacon/aggregation/protocol/service.ts +6 -0
- package/src/btcr2/beacon/cid-aggregate.ts +154 -0
- package/src/btcr2/beacon/factory.ts +36 -0
- package/src/btcr2/beacon/singleton.ts +257 -0
- package/src/btcr2/beacon/smt-aggregate.ts +136 -0
- package/src/btcr2/crud/create.ts +160 -0
- package/src/btcr2/crud/deactivate.ts +13 -0
- package/src/btcr2/crud/read.ts +946 -0
- package/src/btcr2/crud/update.ts +277 -0
- package/src/btcr2/key-manager/index.ts +364 -0
- package/src/btcr2/key-manager/interface.ts +129 -0
- package/src/canonicalize.d.ts +6 -0
- package/src/did-btcr2.ts +288 -0
- package/src/index.ts +34 -0
- package/src/interfaces/beacon.ts +68 -0
- package/src/interfaces/crud.ts +36 -0
- package/src/interfaces/ibeacon.ts +76 -0
- package/src/types/bitcoin.ts +1028 -0
- package/src/types/crud.ts +41 -0
- package/src/utils/appendix.ts +257 -0
- package/src/utils/beacons.ts +276 -0
- package/src/utils/did-document-builder.ts +73 -0
- package/src/utils/did-document.ts +474 -0
- package/src/utils/general.ts +204 -0
- package/src/utils/identifier.ts +276 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Btcr2Error, Btcr2IdentifierTypes, INVALID_DID, INVALID_DID_DOCUMENT, METHOD_NOT_SUPPORTED, W3C_DID_RESOLUTION_V1 } from '@did-btcr2/common';
|
|
2
|
+
import { Did, DidError, DidErrorCode, EMPTY_DID_RESOLUTION_RESULT } from '@web5/dids';
|
|
3
|
+
import { initEccLib } from 'bitcoinjs-lib';
|
|
4
|
+
import * as tinysecp from 'tiny-secp256k1';
|
|
5
|
+
import { Btc1Create } from './btcr2/crud/create.js';
|
|
6
|
+
import { Btc1Read } from './btcr2/crud/read.js';
|
|
7
|
+
import { Btc1Update } from './btcr2/crud/update.js';
|
|
8
|
+
import { Btc1Appendix } from './utils/appendix.js';
|
|
9
|
+
import { Btc1Identifier } from './utils/identifier.js';
|
|
10
|
+
/** Initialize tiny secp256k1 */
|
|
11
|
+
initEccLib(tinysecp);
|
|
12
|
+
/**
|
|
13
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
|
|
14
|
+
* did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce
|
|
15
|
+
* changes to the DID document. It improves on prior work by allowing: zero-cost off-chain DID creation; aggregated
|
|
16
|
+
* updates for scalable on-chain update costs; long-term identifiers that can support frequent updates; private
|
|
17
|
+
* communication of the DID document; private DID resolution; and non-repudiation appropriate for serious contracts.
|
|
18
|
+
*
|
|
19
|
+
* @class DidBtc1
|
|
20
|
+
* @type {DidBtc1}
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export class DidBtc1 {
|
|
24
|
+
/** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
|
|
25
|
+
static methodName = 'btcr2';
|
|
26
|
+
/**
|
|
27
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
|
|
28
|
+
* See {@link Btc1Create} for implementation details.
|
|
29
|
+
*
|
|
30
|
+
* A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic
|
|
31
|
+
* seed, or it can be created from an arbitrary genesis intermediate DID document representation. In both cases,
|
|
32
|
+
* DID creation can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the
|
|
33
|
+
* Bitcoin network to create their DID.
|
|
34
|
+
* @param {Btc1CreateParams} params See {@link Btc1CreateParams} for details.
|
|
35
|
+
* @param {IdType} params.idType Type of identifier to create (key or external).
|
|
36
|
+
* @param {KeyBytes} params.pubKeyBytes Public key byte array used to create a btcr2 "key" identifier.
|
|
37
|
+
* @param {IntermediateDocument} params.intermediateDocument DID Document used to create a btcr2 "external" identifier.
|
|
38
|
+
* @param {DidCreateOptions} params.options See {@link DidCreateOptions} for create options.
|
|
39
|
+
* @param {number} params.options.version Version number of the btcr2 method.
|
|
40
|
+
* @param {string} params.options.network Bitcoin network name (mainnet, testnet, signet, regtest).
|
|
41
|
+
* @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
|
|
42
|
+
* @throws {DidBtc1Error} if any of the checks fail
|
|
43
|
+
*/
|
|
44
|
+
static async create(params) {
|
|
45
|
+
// Deconstruct the idType and options from the params
|
|
46
|
+
const { idType, options = {} } = params;
|
|
47
|
+
// If idType is key, call Btc1Create.deterministic
|
|
48
|
+
if (idType === Btcr2IdentifierTypes.KEY) {
|
|
49
|
+
// Deconstruct the pubKeyBytes from the params
|
|
50
|
+
const { pubKeyBytes } = params;
|
|
51
|
+
// Return call to Btc1Create.deterministic
|
|
52
|
+
return Btc1Create.deterministic({ pubKeyBytes, options });
|
|
53
|
+
}
|
|
54
|
+
// If idType is external, call Btc1Create.external
|
|
55
|
+
if (idType === Btcr2IdentifierTypes.EXTERNAL) {
|
|
56
|
+
// Deconstruct the intermediateDocument from the params
|
|
57
|
+
const { intermediateDocument } = params;
|
|
58
|
+
// Return call to Btc1Create.external
|
|
59
|
+
return await Btc1Create.external({ intermediateDocument, options });
|
|
60
|
+
}
|
|
61
|
+
// Throw error if idType is not key or external
|
|
62
|
+
throw new Btcr2Error('Invalid idType: expected "KEY" or "EXTERNAL"', INVALID_DID, params);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Read}.
|
|
66
|
+
* See {@link Btc1Read} for implementation details.
|
|
67
|
+
*
|
|
68
|
+
* The Read operation is an algorithm consisting of a series of subroutine algorithms executed by a resolver after a
|
|
69
|
+
* resolution request identifying a specific did:btcr2 identifier is received from a client at Resolution Time. The
|
|
70
|
+
* request MUST always contain the resolutionOptions object containing additional information to be used in resolution.
|
|
71
|
+
* This object MAY be empty. See the DID Resolution specification for further details about the DID Resolution Options
|
|
72
|
+
* object. The resolver then attempts to resolve the DID document of the identifier at a specific Target Time. The
|
|
73
|
+
* Target Time is either provided in resolutionOptions or is set to the Resolution Time of the request.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} identifier a valid did:btcr2 identifier to be resolved
|
|
76
|
+
* @param {DidResolutionOptions} [resolutionsOptions] see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | DidResolutionOptions}
|
|
77
|
+
* @param {number} options.versionId the version of the identifier and/or DID document
|
|
78
|
+
* @param {number} options.versionTime a timestamp used during resolution as a bound for when to stop resolving
|
|
79
|
+
* @param {Btc1DidDocument} options.sidecarData data necessary for resolving a DID
|
|
80
|
+
* @param {string} options.network Bitcoin network name (mainnet, testnet, signet, regtest).
|
|
81
|
+
* @returns {DidResolutionResult} Promise resolving to a DID Resolution Result containing the `targetDocument`
|
|
82
|
+
* @throws {Error} if the resolution fails for any reason
|
|
83
|
+
* @throws {DidError} InvalidDid if the identifier is invalid
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const resolution = await DidBtc1.resolve('did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh')
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
static async resolve(identifier, resolutionsOptions = {}) {
|
|
90
|
+
try {
|
|
91
|
+
// 1. Pass identifier to the did:btcr2 Identifier Decoding algorithm, retrieving idType, version, network, and genesisBytes.
|
|
92
|
+
// 2. Set identifierComponents to a map of idType, version, network, and genesisBytes.
|
|
93
|
+
const identifierComponents = Btc1Identifier.decode(identifier);
|
|
94
|
+
// 3. Set initialDocument to the result of running the algorithm in Resolve Initial Document passing in the
|
|
95
|
+
// identifier, identifierComponents and resolutionOptions.
|
|
96
|
+
const initialDocument = await Btc1Read.initialDocument({ identifier, identifierComponents, resolutionsOptions });
|
|
97
|
+
// 4. Set targetDocument to the result of running the algorithm in Resolve Target Document passing in
|
|
98
|
+
// initialDocument and resolutionOptions.
|
|
99
|
+
const targetDocument = await Btc1Read.targetDocument({ initialDocument, resolutionsOptions });
|
|
100
|
+
// 5. Return targetDocument.
|
|
101
|
+
const didResolutionResult = {
|
|
102
|
+
'@context': W3C_DID_RESOLUTION_V1,
|
|
103
|
+
didResolutionMetadata: { contentType: 'application/ld+json' },
|
|
104
|
+
didDocumentMetadata: { created: new Date().getUTCDateTime() },
|
|
105
|
+
didDocument: targetDocument,
|
|
106
|
+
};
|
|
107
|
+
// Return didResolutionResult;
|
|
108
|
+
return didResolutionResult;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(error);
|
|
112
|
+
// Rethrow any unexpected errors that are not a `DidError`.
|
|
113
|
+
if (!(error instanceof DidError))
|
|
114
|
+
throw new Error(error);
|
|
115
|
+
// Return a DID Resolution Result with the appropriate error code.
|
|
116
|
+
return {
|
|
117
|
+
...EMPTY_DID_RESOLUTION_RESULT,
|
|
118
|
+
didResolutionMetadata: {
|
|
119
|
+
error: error.code,
|
|
120
|
+
...error.message && { errorMessage: error.message }
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
|
|
127
|
+
* See {@link Btc1Update} for implementation details.
|
|
128
|
+
*
|
|
129
|
+
* An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
|
|
130
|
+
* verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
|
|
131
|
+
* invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
|
|
132
|
+
* cryptosuite with a proofPurpose of capabilityInvocation.
|
|
133
|
+
*
|
|
134
|
+
* The Update algorithm takes as inputs a btc1Identifier, sourceDocument, sourceVersionId, documentPatch, a
|
|
135
|
+
* verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
|
|
136
|
+
* documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
|
|
137
|
+
* The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
|
|
138
|
+
* verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
|
|
139
|
+
* identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
|
|
140
|
+
* Types SingletonBeacon, CIDAggregateBeacon, and SMTAggregateBeacon.
|
|
141
|
+
*
|
|
142
|
+
* @param {Btc1UpdateParams} params Required parameters for the update operation.
|
|
143
|
+
* @param {string} params.identifier The btcr2 identifier to be updated.
|
|
144
|
+
* @param {Btc1DidDocument} params.sourceDocument The DID document being updated.
|
|
145
|
+
* @param {string} params.sourceVersionId The versionId of the source document.
|
|
146
|
+
* @param {Btc1DocumentPatch} params.documentPatch The JSON patch to be applied to the source document.
|
|
147
|
+
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update
|
|
148
|
+
* @param {string[]} params.beaconIds The beacon IDs to announce the update
|
|
149
|
+
* @returns {Promise<void>} Promise resolving to void
|
|
150
|
+
* @throws {Btcr2Error} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
|
|
151
|
+
*/
|
|
152
|
+
static async update(params) {
|
|
153
|
+
// Deconstruct the params
|
|
154
|
+
const { identifier, sourceDocument, sourceVersionId, patch, verificationMethodId: methodId, beaconIds, } = params;
|
|
155
|
+
// 1. Set unsignedUpdate to the result of passing btc1Identifier, sourceDocument,
|
|
156
|
+
// sourceVersionId, and documentPatch into the Construct DID Update
|
|
157
|
+
// Payload algorithm.
|
|
158
|
+
const didUpdatePayload = await Btc1Update.construct({
|
|
159
|
+
identifier,
|
|
160
|
+
sourceDocument,
|
|
161
|
+
sourceVersionId,
|
|
162
|
+
patch,
|
|
163
|
+
});
|
|
164
|
+
// 2. Set verificationMethod to the result of retrieving the verificationMethod
|
|
165
|
+
// from sourceDocument using the verificationMethodId.
|
|
166
|
+
const verificationMethod = this.getSigningMethod({ didDocument: sourceDocument, methodId, });
|
|
167
|
+
// Validate the verificationMethod exists in the sourceDocument
|
|
168
|
+
if (!verificationMethod) {
|
|
169
|
+
throw new Btcr2Error('Verification method not found in did document', INVALID_DID_DOCUMENT, sourceDocument);
|
|
170
|
+
}
|
|
171
|
+
// 3. Validate the verificationMethod is a BIP340 Multikey:
|
|
172
|
+
// 3.1 verificationMethod.type == Multikey
|
|
173
|
+
if (verificationMethod.type !== 'Multikey') {
|
|
174
|
+
throw new Btcr2Error('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT, verificationMethod);
|
|
175
|
+
}
|
|
176
|
+
// 3.2 verificationMethod.publicKeyMultibase[4] == zQ3s
|
|
177
|
+
const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
|
|
178
|
+
if (mbasePrefix !== 'zQ3s') {
|
|
179
|
+
throw new Btcr2Error(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT, verificationMethod);
|
|
180
|
+
}
|
|
181
|
+
// 4. Set didUpdateInvocation to the result of passing btc1Identifier, unsignedUpdate as didUpdatePayload, and
|
|
182
|
+
// verificationMethod to the Invoke DID Update Payload algorithm.
|
|
183
|
+
const didUpdateInvocation = await Btc1Update.invoke({ identifier, verificationMethod, didUpdatePayload, });
|
|
184
|
+
// 5. Set signalsMetadata to the result of passing btc1Identifier, sourceDocument, beaconIds and didUpdateInvocation
|
|
185
|
+
// to the Announce DID Update algorithm.
|
|
186
|
+
const signalsMetadata = await Btc1Update.announce({ sourceDocument, beaconIds, didUpdateInvocation, });
|
|
187
|
+
// 6. Return signalsMetadata. It is up to implementations to ensure that the signalsMetadata is persisted.
|
|
188
|
+
return signalsMetadata;
|
|
189
|
+
// TODO: Should we be applying the patch, producing a target did document and returning it?
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
|
|
193
|
+
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
194
|
+
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
195
|
+
* of '#initialKey' is used.
|
|
196
|
+
*
|
|
197
|
+
* @param {{ didDocument: Btc1DidDocument; methodId?: string; }} params Parameters for the `getSigningMethod` method.
|
|
198
|
+
* @param {DidDocument} params.didDocument DID Document to get the verification method from.
|
|
199
|
+
* @param {string} params.methodId Optional ID of the verification method to use for signing.
|
|
200
|
+
* @returns {Btc1VerificationMethod} Promise resolving to the {@link Btc1VerificationMethod} object used for signing.
|
|
201
|
+
* @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
|
|
202
|
+
*/
|
|
203
|
+
static getSigningMethod({ didDocument, methodId }) {
|
|
204
|
+
// Set the default methodId to the first assertionMethod if not given
|
|
205
|
+
methodId ??= '#initialKey';
|
|
206
|
+
// Verify the DID method is supported.
|
|
207
|
+
const parsedDid = Did.parse(didDocument.id);
|
|
208
|
+
if (parsedDid && parsedDid.method !== this.methodName) {
|
|
209
|
+
throw new Btcr2Error(`Method not supported: ${parsedDid.method}`, METHOD_NOT_SUPPORTED, { identifier: didDocument.id });
|
|
210
|
+
}
|
|
211
|
+
// Attempt to find a verification method that matches the given method ID, or if not given,
|
|
212
|
+
// find the first verification method intended for signing claims.
|
|
213
|
+
const verificationMethod = didDocument.verificationMethod?.find((vm) => Btc1Appendix.extractDidFragment(vm.id) === (Btc1Appendix.extractDidFragment(methodId)
|
|
214
|
+
?? Btc1Appendix.extractDidFragment(didDocument.assertionMethod?.[0])));
|
|
215
|
+
// If no verification method is found, throw an error
|
|
216
|
+
if (!(verificationMethod && verificationMethod.publicKeyMultibase)) {
|
|
217
|
+
throw new DidError(DidErrorCode.InternalError, 'A verification method intended for signing could not be determined from the DID Document');
|
|
218
|
+
}
|
|
219
|
+
return verificationMethod;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=did-btcr2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"did-btcr2.js","sourceRoot":"","sources":["../../src/did-btcr2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EAEpB,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EACL,GAAG,EACH,QAAQ,EACR,YAAY,EAEZ,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAwC,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,gCAAgC;AAChC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAErB;;;;;;;;;;GAUG;AACH,MAAM,OAAO,OAAO;IAClB,uFAAuF;IAChF,MAAM,CAAC,UAAU,GAAW,OAAO,CAAC;IAE3C;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,KAA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E,CAAC;YACtD,MAAM,IAAI,UAAU,CAAC,yBAAyB,SAAS,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1H,CAAC;QAED,2FAA2F;QAC3F,kEAAkE;QAClE,MAAM,kBAAkB,GAAG,WAAW,CAAC,kBAAkB,EAAE,IAAI,CAC7D,CAAC,EAAyB,EAAE,EAAE,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,kBAAkB,CAAC,QAAQ,CAAC;eAC/G,YAAY,CAAC,kBAAkB,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACxE,CAAC;QAEF,qDAAqD;QACrD,IAAI,CAAC,CAAC,kBAAkB,IAAI,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACnE,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,aAAa,EAC1B,0FAA0F,CAC3F,CAAC;QACJ,CAAC;QACD,OAAO,kBAA4C,CAAC;IACtD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './bitcoin/constants.js';
|
|
2
|
+
export * from './bitcoin/interface.js';
|
|
3
|
+
export * from './bitcoin/network.js';
|
|
4
|
+
export * from './bitcoin/rpc-client.js';
|
|
5
|
+
export * from './btcr2/beacon/cid-aggregate.js';
|
|
6
|
+
export * from './btcr2/beacon/factory.js';
|
|
7
|
+
export * from './btcr2/beacon/singleton.js';
|
|
8
|
+
export * from './btcr2/beacon/smt-aggregate.js';
|
|
9
|
+
export * from './btcr2/crud/create.js';
|
|
10
|
+
export * from './btcr2/crud/deactivate.js';
|
|
11
|
+
export * from './btcr2/crud/read.js';
|
|
12
|
+
export * from './btcr2/crud/update.js';
|
|
13
|
+
export * from './btcr2/key-manager/index.js';
|
|
14
|
+
export * from './btcr2/key-manager/interface.js';
|
|
15
|
+
export * from './interfaces/beacon.js';
|
|
16
|
+
export * from './interfaces/crud.js';
|
|
17
|
+
export * from './interfaces/ibeacon.js';
|
|
18
|
+
export * from './types/bitcoin.js';
|
|
19
|
+
export * from './types/crud.js';
|
|
20
|
+
export * from './utils/appendix.js';
|
|
21
|
+
export * from './utils/beacons.js';
|
|
22
|
+
export * from './utils/did-document-builder.js';
|
|
23
|
+
export * from './utils/did-document.js';
|
|
24
|
+
export * from './utils/general.js';
|
|
25
|
+
export * from './utils/identifier.js';
|
|
26
|
+
export * from './did-btcr2.js';
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AAExC,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAEhD,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AAExC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#update-beacons | 5. Beacons}.
|
|
3
|
+
* Beacons are the mechanism by which a DID controller announces an update to their DID document by broadcasting an
|
|
4
|
+
* attestation to this update onto the public Bitcoin network. Beacons are identified by a Bitcoin address and emit
|
|
5
|
+
* Beacon Signals by broadcasting a valid Bitcoin transaction that spends from this Beacon address. These transactions
|
|
6
|
+
* include attestations to a set of didUpdatePayloads, either in the form of Content Identifiers (CIDs) or Sparse Merkle
|
|
7
|
+
* Tree (SMT) roots. Beacons are included as a service in DID documents, with the Service Endpoint identifying a Bitcoin
|
|
8
|
+
* address to watch for Beacon Signals. All Beacon Signals broadcast from this Beacon MUST be processed as part of
|
|
9
|
+
* resolution (see Read). The type of the Beacon service in the DID document defines how Beacon Signals SHOULD be
|
|
10
|
+
* processed.
|
|
11
|
+
* did:btcr2 supports different Beacon Types, with each type defining a set of algorithms for:
|
|
12
|
+
* 1. How a Beacon can be established and added as a service to a DID document.
|
|
13
|
+
* 2. How attestations to DID updates are broadcast within Beacon Signals.
|
|
14
|
+
* 3. How a resolver processes a Beacon Signal, identifying, verifying, and applying the authorized mutations to a
|
|
15
|
+
* DID document for a specific DID.
|
|
16
|
+
* This is an extendable mechanism, such that in the future new Beacon Types could be added. It would be up to the
|
|
17
|
+
* resolver to determine if the Beacon Type is a mechanism they support and are willing to trust. If they are unable to
|
|
18
|
+
* support a Beacon Type and a DID they are resolving uses that type then the DID MUST be treated as invalid.
|
|
19
|
+
* The current, active Beacons of a DID document are specified in the document’s service property. By updating the DID
|
|
20
|
+
* document, a DID controller can change the set of Beacons they can use to broadcast updates to their DID document over
|
|
21
|
+
* time. Resolution of a DID MUST process signals from all Beacons identified in the latest DID document and apply them
|
|
22
|
+
* in order determined by the version specified by the didUpdatePayload.
|
|
23
|
+
* All resolvers of did:btcr2 DIDs MUST support the core Beacon Types defined in this specification.
|
|
24
|
+
*
|
|
25
|
+
* @abstract
|
|
26
|
+
* @class Beacon
|
|
27
|
+
* @type {Beacon}
|
|
28
|
+
*/
|
|
29
|
+
export class Beacon {
|
|
30
|
+
id;
|
|
31
|
+
type;
|
|
32
|
+
serviceEndpoint;
|
|
33
|
+
sidecar;
|
|
34
|
+
constructor({ id, type, serviceEndpoint }, sidecar) {
|
|
35
|
+
this.id = id;
|
|
36
|
+
this.type = type;
|
|
37
|
+
this.serviceEndpoint = serviceEndpoint;
|
|
38
|
+
this.sidecar = sidecar;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=beacon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beacon.js","sourceRoot":"","sources":["../../../src/interfaces/beacon.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAgB,MAAM;IACnB,EAAE,CAAS;IACX,IAAI,CAAS;IACb,eAAe,CAAqB;IACpC,OAAO,CAAe;IAE7B,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,eAAe,EAAiB,EAAE,OAAqB;QAC7E,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CAqBF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.js","sourceRoot":"","sources":["../../../src/interfaces/crud.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ibeacon.js","sourceRoot":"","sources":["../../../src/interfaces/ibeacon.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export class RpcClientConfig {
|
|
2
|
+
network;
|
|
3
|
+
headers;
|
|
4
|
+
host;
|
|
5
|
+
logger;
|
|
6
|
+
password;
|
|
7
|
+
timeout;
|
|
8
|
+
username;
|
|
9
|
+
version;
|
|
10
|
+
wallet;
|
|
11
|
+
allowDefaultWallet;
|
|
12
|
+
constructor(options = {
|
|
13
|
+
headers: {},
|
|
14
|
+
host: 'localhost',
|
|
15
|
+
logger: console,
|
|
16
|
+
password: '',
|
|
17
|
+
timeout: 30000,
|
|
18
|
+
username: '',
|
|
19
|
+
version: '0.21.1',
|
|
20
|
+
wallet: '',
|
|
21
|
+
allowDefaultWallet: false,
|
|
22
|
+
}) {
|
|
23
|
+
this.headers = options.headers;
|
|
24
|
+
this.host = options.host;
|
|
25
|
+
this.logger = options.logger;
|
|
26
|
+
this.password = options.password;
|
|
27
|
+
this.timeout = options.timeout;
|
|
28
|
+
this.username = options.username;
|
|
29
|
+
this.version = options.version;
|
|
30
|
+
this.wallet = options.wallet;
|
|
31
|
+
this.allowDefaultWallet = options.allowDefaultWallet;
|
|
32
|
+
}
|
|
33
|
+
static initialize(options) {
|
|
34
|
+
return new RpcClientConfig(options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
;
|
|
39
|
+
/**
|
|
40
|
+
* Defines verbosity levels for block and transaction outputs.
|
|
41
|
+
* Used to specify the format of returned block or transaction data.
|
|
42
|
+
* @enum {number} VerbosityLevel for block and transaction outputs.
|
|
43
|
+
*/
|
|
44
|
+
export var VerbosityLevel;
|
|
45
|
+
(function (VerbosityLevel) {
|
|
46
|
+
/** Return block or transaction data in raw hex-encoded format */
|
|
47
|
+
VerbosityLevel[VerbosityLevel["hex"] = 0] = "hex";
|
|
48
|
+
/** Return block or transaction data in JSON object format */
|
|
49
|
+
VerbosityLevel[VerbosityLevel["json"] = 1] = "json";
|
|
50
|
+
/**
|
|
51
|
+
* Return block or transaction data in JSON object format with additional information.
|
|
52
|
+
* Returns block data with information about each transaction.
|
|
53
|
+
* Returns transaction data with information about the transaction including fee and prevout information.
|
|
54
|
+
*/
|
|
55
|
+
VerbosityLevel[VerbosityLevel["jsonext"] = 2] = "jsonext";
|
|
56
|
+
/**
|
|
57
|
+
* Return block data in JSON object format with additional information.
|
|
58
|
+
* Returns block data with information about each transaction, including prevout information for inputs.
|
|
59
|
+
*/
|
|
60
|
+
VerbosityLevel[VerbosityLevel["jsonextprev"] = 3] = "jsonextprev";
|
|
61
|
+
})(VerbosityLevel || (VerbosityLevel = {}));
|
|
62
|
+
//# sourceMappingURL=bitcoin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../../../src/types/bitcoin.ts"],"names":[],"mappings":"AAuBA,MAAM,OAAO,eAAe;IAC1B,OAAO,CAAU;IACjB,OAAO,CAA0B;IACjC,IAAI,CAAU;IACd,MAAM,CAAO;IACb,QAAQ,CAAU;IAClB,OAAO,CAAU;IACjB,QAAQ,CAAU;IAClB,OAAO,CAAU;IACjB,MAAM,CAAU;IAChB,kBAAkB,CAAW;IAE7B,YAAY,UAAyB;QACnC,OAAO,EAAc,EAAE;QACvB,IAAI,EAAiB,WAAW;QAChC,MAAM,EAAe,OAAO;QAC5B,QAAQ,EAAa,EAAE;QACvB,OAAO,EAAc,KAAK;QAC1B,QAAQ,EAAa,EAAE;QACvB,OAAO,EAAc,QAAQ;QAC7B,MAAM,EAAe,EAAE;QACvB,kBAAkB,EAAG,KAAK;KAC3B;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACvD,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,OAAuB;QAC9C,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACF;AAiZA,CAAC;AAKD,CAAC;AA8gBF;;;;GAIG;AACH,MAAM,CAAN,IAAY,cAgBX;AAhBD,WAAY,cAAc;IACtB,iEAAiE;IACjE,iDAAO,CAAA;IACP,6DAA6D;IAC7D,mDAAQ,CAAA;IACR;;;;OAIG;IACH,yDAAW,CAAA;IACX;;;OAGG;IACH,iEAAe,CAAA;AACnB,CAAC,EAhBW,cAAc,KAAd,cAAc,QAgBzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.js","sourceRoot":"","sources":["../../../src/types/crud.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { Logger, W3C_ZCAP_V1 } from '@did-btcr2/common';
|
|
2
|
+
import { strings } from '@helia/strings';
|
|
3
|
+
import { DidError, DidErrorCode, DidVerificationRelationship } from '@web5/dids';
|
|
4
|
+
import { createHelia } from 'helia';
|
|
5
|
+
import { CID } from 'multiformats';
|
|
6
|
+
import { create as createDigest } from 'multiformats/hashes/digest';
|
|
7
|
+
;
|
|
8
|
+
/**
|
|
9
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#appendix | 9. Appendix} methods.
|
|
10
|
+
*
|
|
11
|
+
* @class Btc1Appendix
|
|
12
|
+
* @type {Btc1Appendix}
|
|
13
|
+
*/
|
|
14
|
+
export class Btc1Appendix {
|
|
15
|
+
/**
|
|
16
|
+
* Extracts a DID fragment from a given input
|
|
17
|
+
* @param {unknown} input The input to extract the DID fragment from
|
|
18
|
+
* @returns {string | undefined} The extracted DID fragment or undefined if not found
|
|
19
|
+
*/
|
|
20
|
+
static extractDidFragment(input) {
|
|
21
|
+
if (typeof input !== 'string')
|
|
22
|
+
return undefined;
|
|
23
|
+
if (input.length === 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
return input;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validates that the given object is a DidVerificationMethod
|
|
29
|
+
* @param {unknown} obj The object to validate
|
|
30
|
+
* @returns {boolean} A boolean indicating whether the object is a DidVerificationMethod
|
|
31
|
+
*/
|
|
32
|
+
static isDidVerificationMethod(obj) {
|
|
33
|
+
// Validate that the given value is an object.
|
|
34
|
+
if (!obj || typeof obj !== 'object' || obj === null)
|
|
35
|
+
return false;
|
|
36
|
+
// Validate that the object has the necessary properties of a DidVerificationMethod.
|
|
37
|
+
if (!('id' in obj && 'type' in obj && 'controller' in obj))
|
|
38
|
+
return false;
|
|
39
|
+
if (typeof obj.id !== 'string')
|
|
40
|
+
return false;
|
|
41
|
+
if (typeof obj.type !== 'string')
|
|
42
|
+
return false;
|
|
43
|
+
if (typeof obj.controller !== 'string')
|
|
44
|
+
return false;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validates that the given object is a DidService
|
|
49
|
+
* @param {unknown} obj The object to validate
|
|
50
|
+
* @returns {boolean} A boolean indicating whether the object is a DidService
|
|
51
|
+
*/
|
|
52
|
+
static isDidService(obj) {
|
|
53
|
+
// Validate that the given value is an object.
|
|
54
|
+
if (!obj || typeof obj !== 'object' || obj === null)
|
|
55
|
+
return false;
|
|
56
|
+
// Validate that the object has the necessary properties of a DidService.
|
|
57
|
+
if (!('id' in obj && 'type' in obj && 'serviceEndpoint' in obj))
|
|
58
|
+
return false;
|
|
59
|
+
if (typeof obj.id !== 'string')
|
|
60
|
+
return false;
|
|
61
|
+
if (typeof obj.type !== 'string')
|
|
62
|
+
return false;
|
|
63
|
+
if (typeof obj.serviceEndpoint !== 'string')
|
|
64
|
+
return false;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Extracts the verification methods from a given DID Document
|
|
69
|
+
* @param {DidDocument} params.didDocument The DID Document to extract the verification methods from
|
|
70
|
+
* @returns {DidVerificationMethod[]} An array of DidVerificationMethod objects
|
|
71
|
+
* @throws {TypeError} if the didDocument is not provided
|
|
72
|
+
*/
|
|
73
|
+
static getVerificationMethods(didDocument) {
|
|
74
|
+
if (!didDocument)
|
|
75
|
+
throw new TypeError(`Required parameter missing: 'didDocument'`);
|
|
76
|
+
const verificationMethods = [];
|
|
77
|
+
// Check the 'verificationMethod' array.
|
|
78
|
+
verificationMethods.push(...didDocument.verificationMethod?.filter(Btc1Appendix.isDidVerificationMethod) ?? []);
|
|
79
|
+
// Check verification relationship properties for embedded verification methods.
|
|
80
|
+
Object.keys(DidVerificationRelationship).forEach((relationship) => {
|
|
81
|
+
verificationMethods.push(...didDocument[relationship]
|
|
82
|
+
?.filter(Btc1Appendix.isDidVerificationMethod) ?? []);
|
|
83
|
+
});
|
|
84
|
+
return verificationMethods;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#derive-root-capability-from-didbtc1-identifier | 9.4.1 Derive Root Capability from did:btcr2 Identifier}.
|
|
88
|
+
*
|
|
89
|
+
* The Derive Root Capability algorithm deterministically generates a ZCAP-LD root capability from a given did:btcr2
|
|
90
|
+
* identifier. Each root capability is unique to the identifier. This root capability is defined and understood by the
|
|
91
|
+
* did:btcr2 specification as the root capability to authorize updates to the specific did:btcr2 identifiers DID
|
|
92
|
+
* document. It takes in a did:btcr2 identifier and returns a rootCapability object. It returns the root capability.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} identifier The did-btcr2 identifier to derive the root capability from
|
|
95
|
+
* @returns {Btc1RootCapability} The root capability object
|
|
96
|
+
* @example Root capability for updating the DID document for
|
|
97
|
+
* did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u
|
|
98
|
+
* ```
|
|
99
|
+
* {
|
|
100
|
+
* "@context": "https://w3id.org/zcap/v1",
|
|
101
|
+
* "id": "urn:zcap:root:did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
102
|
+
* "controller": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
103
|
+
* "invocationTarget": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u"
|
|
104
|
+
* }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
static deriveRootCapability(identifier) {
|
|
108
|
+
// 1. Define rootCapability as an empty object.
|
|
109
|
+
const rootCapability = {};
|
|
110
|
+
// 2. Set rootCapability.@context to ‘https://w3id.org/zcap/v1’.
|
|
111
|
+
rootCapability['@context'] = W3C_ZCAP_V1;
|
|
112
|
+
// 3. Set encodedIdentifier to result of calling algorithm encodeURIComponent(identifier).
|
|
113
|
+
const encodedIdentifier = encodeURIComponent(identifier);
|
|
114
|
+
// 4. Set rootCapability.id to urn:zcap:root:${encodedIdentifier}.
|
|
115
|
+
rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
|
|
116
|
+
// 5. Set rootCapability.controller to identifier.
|
|
117
|
+
rootCapability.controller = identifier;
|
|
118
|
+
// 6. Set rootCapability.invocationTarget to identifier.
|
|
119
|
+
rootCapability.invocationTarget = identifier;
|
|
120
|
+
// 7. Return rootCapability.
|
|
121
|
+
return rootCapability;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#dereference-root-capability-identifier | 9.4.2 Dereference Root Capability Identifier}.
|
|
125
|
+
*
|
|
126
|
+
* This algorithm takes in capabilityId, a root capability identifier, and dereferences it to rootCapability, the root
|
|
127
|
+
* capability object.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} capabilityId The root capability identifier to dereference.
|
|
130
|
+
* @returns {Btc1RootCapability} The root capability object.
|
|
131
|
+
* @example a didUpdatePayload with an invoked ZCAP-LD capability containing a patch defining how the DID document
|
|
132
|
+
* for did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u SHOULD be mutated.
|
|
133
|
+
* ```
|
|
134
|
+
* {
|
|
135
|
+
* "@context": [
|
|
136
|
+
* "https://w3id.org/zcap/v1",
|
|
137
|
+
* "https://w3id.org/security/data-integrity/v2",
|
|
138
|
+
* "https://w3id.org/json-ld-patch/v1"
|
|
139
|
+
* ],
|
|
140
|
+
* "patch": [
|
|
141
|
+
* {
|
|
142
|
+
* "op": "add",
|
|
143
|
+
* "path": "/service/4",
|
|
144
|
+
* "value": {
|
|
145
|
+
* "id": "#linked-domain",
|
|
146
|
+
* "type": "LinkedDomains",
|
|
147
|
+
* "serviceEndpoint": "https://contact-me.com"
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
* ],
|
|
151
|
+
* "proof": {
|
|
152
|
+
* "type": "DataIntegrityProof",
|
|
153
|
+
* "cryptosuite": "schnorr-secp256k1-jcs-2025",
|
|
154
|
+
* "verificationMethod": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u#initialKey",
|
|
155
|
+
* "invocationTarget": "did:btcr2:k1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
156
|
+
* "capability": "urn:zcap:root:did%3Abtc1%3Ak1q0rnnwf657vuu8trztlczvlmphjgc6q598h79cm6sp7c4fgqh0fkc0vzd9u",
|
|
157
|
+
* "capabilityAction": "Write",
|
|
158
|
+
* "proofPurpose": "assertionMethod",
|
|
159
|
+
* "proofValue": "z381yXYmxU8NudZ4HXY56DfMN6zfD8syvWcRXzT9xD9uYoQToo8QsXD7ahM3gXTzuay5WJbqTswt2BKaGWYn2hHhVFKJLXaDz"
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
*/
|
|
163
|
+
static derefernceRootCapabilityIdentifier(capabilityId) {
|
|
164
|
+
// 1. Set rootCapability to an empty object.
|
|
165
|
+
const rootCapability = {};
|
|
166
|
+
// 2. Set components to the result of capabilityId.split(":").
|
|
167
|
+
const [urn, zcap, root, did] = capabilityId.split(':') ?? [];
|
|
168
|
+
// 3. Validate components:
|
|
169
|
+
// 1. Assert length of components is 4.
|
|
170
|
+
if ([urn, zcap, root, did].length !== 4) {
|
|
171
|
+
throw new DidError(DidErrorCode.InvalidDid, `Invalid capabilityId: ${capabilityId}`);
|
|
172
|
+
}
|
|
173
|
+
// 2. components[0] == urn.
|
|
174
|
+
if (!urn || urn !== 'urn') {
|
|
175
|
+
throw new DidError(DidErrorCode.InvalidDid, `Invalid capabilityId: ${capabilityId}`);
|
|
176
|
+
}
|
|
177
|
+
// 3. components[1] == zcap.
|
|
178
|
+
if (!zcap || zcap !== 'zcap') {
|
|
179
|
+
throw new DidError(DidErrorCode.InvalidDid, `Invalid capabilityId: ${capabilityId}`);
|
|
180
|
+
}
|
|
181
|
+
// 4. components[2] == root.
|
|
182
|
+
if (!root || root !== 'root') {
|
|
183
|
+
throw new DidError(DidErrorCode.InvalidDid, `Invalid capabilityId: ${capabilityId}`);
|
|
184
|
+
}
|
|
185
|
+
// 4. Set uriEncodedId to components[3].
|
|
186
|
+
const uriEncodedId = did;
|
|
187
|
+
// 5. Set btc1Identifier the result of decodeURIComponent(uriEncodedId).
|
|
188
|
+
const btc1Identifier = decodeURIComponent(uriEncodedId);
|
|
189
|
+
// 6. Set rootCapability.id to capabilityId.
|
|
190
|
+
rootCapability.id = capabilityId;
|
|
191
|
+
// 7. Set rootCapability.controller to btc1Identifier.
|
|
192
|
+
rootCapability.controller = btc1Identifier;
|
|
193
|
+
// 8. Set rootCapability.invocationTarget to btc1Identifier.
|
|
194
|
+
rootCapability.invocationTarget = btc1Identifier;
|
|
195
|
+
// 9. Return rootCapability.
|
|
196
|
+
return rootCapability;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Implements {@link https://dcdpr.github.io/did-btcr2/#fetch-content-from-addressable-storage | 9.3. Fetch Content from Addressable Storage}.
|
|
200
|
+
*
|
|
201
|
+
* The Fetch Content from Addressable Storage function takes in SHA256 hash of some content, hashBytes, converts these
|
|
202
|
+
* bytes to a IPFS v1 Content Identifier and attempts to retrieve the identified content from Content Addressable
|
|
203
|
+
* Storage (CAS). It returns the retrieved content or null.
|
|
204
|
+
*
|
|
205
|
+
* @param {HashBytes} hashBytes The SHA256 hash of the content to be fetched.
|
|
206
|
+
* @returns {string} The fetched content or null if not found.
|
|
207
|
+
*/
|
|
208
|
+
static async fetchFromCas(hashBytes) {
|
|
209
|
+
// 1. Set cid to the result of converting hashBytes to an IPFS v1 CID.
|
|
210
|
+
const cid = CID.create(1, 1, createDigest(1, hashBytes));
|
|
211
|
+
// Create a Helia node connection to IPFS
|
|
212
|
+
const helia = strings(await createHelia());
|
|
213
|
+
// 2. Set content to the result of fetching the cid from a CAS system. Which CAS systems checked is up to implementation.
|
|
214
|
+
Logger.warn('// TODO: Is this right? Are implementations just supposed to check all CAS they trust?');
|
|
215
|
+
const content = await helia.get(cid, {});
|
|
216
|
+
// 3. If content for cid cannot be found, set content to null.
|
|
217
|
+
// 4. Return content.
|
|
218
|
+
return content;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=appendix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendix.js","sourceRoot":"","sources":["../../../src/utils/appendix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAEL,QAAQ,EACR,YAAY,EAGZ,2BAA2B,EAC5B,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,E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