@did-btcr2/method 0.25.3 → 0.27.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/README.md +86 -233
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser.js +129207 -122358
- package/dist/browser.mjs +129235 -122386
- package/dist/cjs/index.js +5332 -43
- package/dist/esm/core/aggregation/cohort.js +178 -0
- package/dist/esm/core/aggregation/cohort.js.map +1 -0
- package/dist/esm/core/aggregation/errors.js +22 -0
- package/dist/esm/core/aggregation/errors.js.map +1 -0
- package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
- package/dist/esm/core/aggregation/messages/base.js.map +1 -0
- package/dist/esm/core/aggregation/messages/constants.js +26 -0
- package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
- package/dist/esm/core/aggregation/messages/factories.js +113 -0
- package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
- package/dist/esm/core/aggregation/messages/guards.js +37 -0
- package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
- package/dist/esm/core/aggregation/messages/index.js +5 -0
- package/dist/esm/core/aggregation/messages/index.js.map +1 -0
- package/dist/esm/core/aggregation/participant.js +376 -0
- package/dist/esm/core/aggregation/participant.js.map +1 -0
- package/dist/esm/core/aggregation/phases.js +39 -0
- package/dist/esm/core/aggregation/phases.js.map +1 -0
- package/dist/esm/core/aggregation/runner/events.js +2 -0
- package/dist/esm/core/aggregation/runner/events.js.map +1 -0
- package/dist/esm/core/aggregation/runner/index.js +5 -0
- package/dist/esm/core/aggregation/runner/index.js.map +1 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
- package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
- package/dist/esm/core/aggregation/service.js +416 -0
- package/dist/esm/core/aggregation/service.js.map +1 -0
- package/dist/esm/core/aggregation/signing-session.js +133 -0
- package/dist/esm/core/aggregation/signing-session.js.map +1 -0
- package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
- package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
- package/dist/esm/core/aggregation/transport/error.js +12 -0
- package/dist/esm/core/aggregation/transport/error.js.map +1 -0
- package/dist/esm/core/aggregation/transport/factory.js +20 -0
- package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
- package/dist/esm/core/aggregation/transport/index.js +6 -0
- package/dist/esm/core/aggregation/transport/index.js.map +1 -0
- package/dist/esm/core/aggregation/transport/nostr.js +262 -0
- package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
- package/dist/esm/core/aggregation/transport/transport.js +2 -0
- package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
- package/dist/esm/core/beacon/beacon.js +80 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +21 -60
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +0 -10
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/fee-estimator.js +30 -0
- package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
- package/dist/esm/core/beacon/signal-discovery.js +1 -1
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
- package/dist/esm/core/beacon/singleton-beacon.js +13 -56
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +85 -9
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/identifier.js +13 -0
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolver.js +50 -35
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +1 -1
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +14 -24
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +7 -6
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +2 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/aggregation/cohort.d.ts +94 -0
- package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
- package/dist/types/core/aggregation/errors.d.ts +14 -0
- package/dist/types/core/aggregation/errors.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
- package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
- package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
- package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
- package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/index.d.ts +5 -0
- package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/participant.d.ts +101 -0
- package/dist/types/core/aggregation/participant.d.ts.map +1 -0
- package/dist/types/core/aggregation/phases.d.ts +49 -0
- package/dist/types/core/aggregation/phases.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/events.d.ts +89 -0
- package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/index.d.ts +5 -0
- package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
- package/dist/types/core/aggregation/service.d.ts +112 -0
- package/dist/types/core/aggregation/service.d.ts.map +1 -0
- package/dist/types/core/aggregation/signing-session.d.ts +69 -0
- package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
- package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
- package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts +6 -0
- package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
- package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
- package/dist/types/core/beacon/beacon.d.ts +41 -6
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +23 -11
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +0 -6
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +2 -2
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
- package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
- package/dist/types/core/beacon/interfaces.d.ts +11 -3
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +3 -3
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton-beacon.d.ts +14 -7
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +32 -12
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts +4 -4
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +10 -2
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +4 -4
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolver.d.ts +19 -9
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +6 -5
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +5 -5
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +6 -6
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -24
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +7 -7
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +3 -2
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +3 -3
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +35 -33
- package/src/core/aggregation/cohort.ts +247 -0
- package/src/core/aggregation/errors.ts +25 -0
- package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
- package/src/core/aggregation/messages/constants.ts +28 -0
- package/src/core/aggregation/messages/factories.ts +240 -0
- package/src/core/aggregation/messages/guards.ts +55 -0
- package/src/core/aggregation/messages/index.ts +4 -0
- package/src/core/aggregation/participant.ts +510 -0
- package/src/core/aggregation/phases.ts +82 -0
- package/src/core/aggregation/runner/events.ts +77 -0
- package/src/core/aggregation/runner/index.ts +4 -0
- package/src/core/aggregation/runner/participant-runner.ts +360 -0
- package/src/core/aggregation/runner/service-runner.ts +365 -0
- package/src/core/aggregation/runner/typed-emitter.ts +87 -0
- package/src/core/aggregation/service.ts +547 -0
- package/src/core/aggregation/signing-session.ts +209 -0
- package/src/core/aggregation/transport/didcomm.ts +42 -0
- package/src/core/aggregation/transport/error.ts +13 -0
- package/src/core/aggregation/transport/factory.ts +29 -0
- package/src/core/aggregation/transport/index.ts +5 -0
- package/src/core/aggregation/transport/nostr.ts +333 -0
- package/src/core/aggregation/transport/transport.ts +46 -0
- package/src/core/beacon/beacon.ts +126 -6
- package/src/core/beacon/cas-beacon.ts +39 -83
- package/src/core/beacon/error.ts +0 -12
- package/src/core/beacon/factory.ts +2 -2
- package/src/core/beacon/fee-estimator.ts +52 -0
- package/src/core/beacon/interfaces.ts +13 -4
- package/src/core/beacon/signal-discovery.ts +5 -4
- package/src/core/beacon/singleton-beacon.ts +21 -81
- package/src/core/beacon/smt-beacon.ts +113 -15
- package/src/core/beacon/utils.ts +6 -4
- package/src/core/identifier.ts +20 -2
- package/src/core/interfaces.ts +4 -4
- package/src/core/resolver.ts +84 -53
- package/src/core/types.ts +6 -5
- package/src/core/update.ts +11 -7
- package/src/did-btcr2.ts +12 -10
- package/src/index.ts +15 -29
- package/src/utils/appendix.ts +14 -16
- package/src/utils/did-document-builder.ts +3 -2
- package/src/utils/did-document.ts +10 -8
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +0 -237
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +0 -26
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +0 -11
- package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +0 -98
- package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/cohort/status.js +0 -8
- package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/communication/error.js +0 -12
- package/dist/cjs/core/beacon/aggregation/communication/error.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/communication/factory.js +0 -21
- package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/communication/service.js +0 -2
- package/dist/cjs/core/beacon/aggregation/communication/service.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/coordinator.js +0 -343
- package/dist/cjs/core/beacon/aggregation/coordinator.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/participant.js +0 -435
- package/dist/cjs/core/beacon/aggregation/participant.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +0 -244
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/session/status.js +0 -11
- package/dist/cjs/core/beacon/aggregation/session/status.js.map +0 -1
- package/dist/cjs/core/beacon/beacon.js +0 -25
- package/dist/cjs/core/beacon/beacon.js.map +0 -1
- package/dist/cjs/core/beacon/cas-beacon.js +0 -152
- package/dist/cjs/core/beacon/cas-beacon.js.map +0 -1
- package/dist/cjs/core/beacon/error.js +0 -37
- package/dist/cjs/core/beacon/error.js.map +0 -1
- package/dist/cjs/core/beacon/factory.js +0 -29
- package/dist/cjs/core/beacon/factory.js.map +0 -1
- package/dist/cjs/core/beacon/interfaces.js +0 -2
- package/dist/cjs/core/beacon/interfaces.js.map +0 -1
- package/dist/cjs/core/beacon/signal-discovery.js +0 -183
- package/dist/cjs/core/beacon/signal-discovery.js.map +0 -1
- package/dist/cjs/core/beacon/singleton-beacon.js +0 -107
- package/dist/cjs/core/beacon/singleton-beacon.js.map +0 -1
- package/dist/cjs/core/beacon/smt-beacon.js +0 -39
- package/dist/cjs/core/beacon/smt-beacon.js.map +0 -1
- package/dist/cjs/core/beacon/utils.js +0 -163
- package/dist/cjs/core/beacon/utils.js.map +0 -1
- package/dist/cjs/core/identifier.js +0 -248
- package/dist/cjs/core/identifier.js.map +0 -1
- package/dist/cjs/core/interfaces.js +0 -2
- package/dist/cjs/core/interfaces.js.map +0 -1
- package/dist/cjs/core/resolver.js +0 -476
- package/dist/cjs/core/resolver.js.map +0 -1
- package/dist/cjs/core/types.js +0 -2
- package/dist/cjs/core/types.js.map +0 -1
- package/dist/cjs/core/update.js +0 -112
- package/dist/cjs/core/update.js.map +0 -1
- package/dist/cjs/did-btcr2.js +0 -193
- package/dist/cjs/did-btcr2.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/utils/appendix.js +0 -203
- package/dist/cjs/utils/appendix.js.map +0 -1
- package/dist/cjs/utils/did-document-builder.js +0 -60
- package/dist/cjs/utils/did-document-builder.js.map +0 -1
- package/dist/cjs/utils/did-document.js +0 -424
- package/dist/cjs/utils/did-document.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
- package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
- package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
- package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
- package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/participant.js +0 -435
- package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
- package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
- package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
- package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
- package/src/core/beacon/aggregation/cohort/index.ts +0 -304
- package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
- package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -43
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -34
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -33
- package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -35
- package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -38
- package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -40
- package/src/core/beacon/aggregation/cohort/status.ts +0 -7
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -147
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -321
- package/src/core/beacon/aggregation/communication/error.ts +0 -13
- package/src/core/beacon/aggregation/communication/factory.ts +0 -25
- package/src/core/beacon/aggregation/communication/service.ts +0 -42
- package/src/core/beacon/aggregation/coordinator.ts +0 -415
- package/src/core/beacon/aggregation/participant.ts +0 -512
- package/src/core/beacon/aggregation/session/index.ts +0 -300
- package/src/core/beacon/aggregation/session/status.ts +0 -18
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import { getNetwork } from '@did-btcr2/bitcoin';
|
|
2
|
-
import { canonicalize, DidDocumentError, hash, IdentifierTypes, INVALID_DID_DOCUMENT, JSONUtils } from '@did-btcr2/common';
|
|
3
|
-
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
4
|
-
import { payments } from 'bitcoinjs-lib';
|
|
5
|
-
import { BeaconUtils } from '../core/beacon/utils.js';
|
|
6
|
-
import { Identifier } from '../core/identifier.js';
|
|
7
|
-
import { Appendix } from './appendix.js';
|
|
8
|
-
export const BTCR2_DID_DOCUMENT_CONTEXT = [
|
|
9
|
-
'https://www.w3.org/ns/did/v1.1',
|
|
10
|
-
'https://btcr2.dev/context/v1',
|
|
11
|
-
];
|
|
12
|
-
export const ID_PLACEHOLDER_VALUE = 'did:btcr2:_';
|
|
13
|
-
export const BECH32M_CHARS = '';
|
|
14
|
-
export const DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
|
|
15
|
-
/**
|
|
16
|
-
* DID BTCR2 Verification Method extends the DidVerificationMethod class adding helper methods and properties
|
|
17
|
-
* @class DidVerificationMethod
|
|
18
|
-
* @type {DidVerificationMethod}
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export class DidVerificationMethod {
|
|
22
|
-
id;
|
|
23
|
-
type;
|
|
24
|
-
controller;
|
|
25
|
-
publicKeyMultibase;
|
|
26
|
-
secretKeyMultibase;
|
|
27
|
-
constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }) {
|
|
28
|
-
this.id = id;
|
|
29
|
-
this.type = type;
|
|
30
|
-
this.controller = controller;
|
|
31
|
-
this.publicKeyMultibase = publicKeyMultibase;
|
|
32
|
-
this.secretKeyMultibase = secretKeyMultibase;
|
|
33
|
-
if (!secretKeyMultibase) {
|
|
34
|
-
delete this.secretKeyMultibase;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* BTCR2 DID Document extends the DidDocument class adding helper methods and properties
|
|
40
|
-
* @class DidDocument
|
|
41
|
-
* @type {DidDocument}
|
|
42
|
-
* @implements {Btcr2DidDocument}
|
|
43
|
-
* @property {string} id - The identifier of the DID Document.
|
|
44
|
-
* @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
|
|
45
|
-
* @property {Array<DidVerificationMethod>} verificationMethod - The verification methods of the DID Document.
|
|
46
|
-
* @property {Array<string | DidVerificationMethod>} [authentication] - The authentication methods of the DID Document.
|
|
47
|
-
* @property {Array<string | DidVerificationMethod>} [assertionMethod] - The assertion methods of the DID Document.
|
|
48
|
-
* @property {Array<string | DidVerificationMethod>} [capabilityInvocation] - The capability invocation methods of the DID Document.
|
|
49
|
-
* @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
|
|
50
|
-
* @property {Array<BeaconService>} service - The services of the DID Document.
|
|
51
|
-
* @property {boolean} [deactivated] - Indicates if the DID Document is deactivated.
|
|
52
|
-
*/
|
|
53
|
-
export class DidDocument {
|
|
54
|
-
id;
|
|
55
|
-
'@context' = [
|
|
56
|
-
'https://www.w3.org/ns/did/v1.1',
|
|
57
|
-
'https://btcr2.dev/context/v1',
|
|
58
|
-
];
|
|
59
|
-
verificationMethod;
|
|
60
|
-
authentication;
|
|
61
|
-
assertionMethod;
|
|
62
|
-
capabilityInvocation;
|
|
63
|
-
capabilityDelegation;
|
|
64
|
-
service;
|
|
65
|
-
deactivated;
|
|
66
|
-
constructor(document) {
|
|
67
|
-
// Ensure document has an id
|
|
68
|
-
if (!document.id) {
|
|
69
|
-
throw new DidDocumentError('DID Document must have an id', INVALID_DID_DOCUMENT, document);
|
|
70
|
-
}
|
|
71
|
-
// Set the ID and ID type
|
|
72
|
-
const idType = document.id.includes('k1')
|
|
73
|
-
? IdentifierTypes.KEY
|
|
74
|
-
: IdentifierTypes.EXTERNAL;
|
|
75
|
-
// Validate ID and parts for non-intermediate
|
|
76
|
-
const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
|
|
77
|
-
// Deconstruct the document parts for validation
|
|
78
|
-
const { id, verificationMethod: vm, service } = document;
|
|
79
|
-
// If not genesis, validate core properties
|
|
80
|
-
if (!isGenesis) {
|
|
81
|
-
if (!DidDocument.isValidId(id)) {
|
|
82
|
-
throw new DidDocumentError(`Invalid id: ${id}`, INVALID_DID_DOCUMENT, document);
|
|
83
|
-
}
|
|
84
|
-
if (!DidDocument.isValidVerificationMethods(vm)) {
|
|
85
|
-
throw new DidDocumentError('Invalid verificationMethod: ' + vm, INVALID_DID_DOCUMENT, document);
|
|
86
|
-
}
|
|
87
|
-
if (!DidDocument.isValidServices(service)) {
|
|
88
|
-
throw new DidDocumentError('Invalid service: ' + service, INVALID_DID_DOCUMENT, document);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// Set core properties
|
|
92
|
-
this.id = document.id;
|
|
93
|
-
this.verificationMethod = document.verificationMethod || [];
|
|
94
|
-
this.service = document.service || [];
|
|
95
|
-
this['@context'] = document['@context'] || [
|
|
96
|
-
'https://www.w3.org/ns/did/v1.1',
|
|
97
|
-
'https://btcr2.dev/context/v1'
|
|
98
|
-
];
|
|
99
|
-
// Relationships logic based on idType
|
|
100
|
-
if (idType === IdentifierTypes.KEY) {
|
|
101
|
-
// auto-generate #initialKey if missing
|
|
102
|
-
const keyRef = `${this.id}#initialKey`;
|
|
103
|
-
this.authentication = document.authentication || [keyRef];
|
|
104
|
-
this.assertionMethod = document.assertionMethod || [keyRef];
|
|
105
|
-
this.capabilityInvocation = document.capabilityInvocation || [keyRef];
|
|
106
|
-
this.capabilityDelegation = document.capabilityDelegation || [keyRef];
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
// EXTERNAL: use provided arrays, must be defined
|
|
110
|
-
this.authentication = document.authentication;
|
|
111
|
-
this.assertionMethod = document.assertionMethod;
|
|
112
|
-
this.capabilityInvocation = document.capabilityInvocation;
|
|
113
|
-
this.capabilityDelegation = document.capabilityDelegation;
|
|
114
|
-
}
|
|
115
|
-
// Sanitize the DID Document
|
|
116
|
-
DidDocument.sanitize(this);
|
|
117
|
-
// If the DID Document is not an intermediateDocument, validate it
|
|
118
|
-
if (isGenesis) {
|
|
119
|
-
this.validateGenesis();
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
DidDocument.validate(this);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Convert the DidDocument to a JSON object.
|
|
127
|
-
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
128
|
-
*/
|
|
129
|
-
toJSON() {
|
|
130
|
-
return {
|
|
131
|
-
id: this.id,
|
|
132
|
-
'@context': this['@context'],
|
|
133
|
-
verificationMethod: this.verificationMethod,
|
|
134
|
-
authentication: this.authentication,
|
|
135
|
-
assertionMethod: this.assertionMethod,
|
|
136
|
-
capabilityInvocation: this.capabilityInvocation,
|
|
137
|
-
capabilityDelegation: this.capabilityDelegation,
|
|
138
|
-
service: this.service,
|
|
139
|
-
deactivated: this.deactivated
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create a minimal DidDocument from "k1" btcr2 identifier.
|
|
144
|
-
* @param {string} publicKeyMultibase The public key in multibase format.
|
|
145
|
-
* @param {Array<BeaconService>} service The beacon services to be included in the document.
|
|
146
|
-
* @returns {DidDocument} A new DidDocument with the placeholder ID.
|
|
147
|
-
*/
|
|
148
|
-
static fromKeyIdentifier(id, publicKeyMultibase, service) {
|
|
149
|
-
// Ensure the ID is in the correct format
|
|
150
|
-
id = id.includes('#') ? id : `${id}#initialKey`;
|
|
151
|
-
// Create the verification method and the DidDocument
|
|
152
|
-
const document = {
|
|
153
|
-
id,
|
|
154
|
-
verificationMethod: [
|
|
155
|
-
new DidVerificationMethod({
|
|
156
|
-
id,
|
|
157
|
-
type: 'Multikey',
|
|
158
|
-
controller: id,
|
|
159
|
-
publicKeyMultibase
|
|
160
|
-
})
|
|
161
|
-
],
|
|
162
|
-
service
|
|
163
|
-
};
|
|
164
|
-
return new DidDocument(document);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Create a DidDocument from "x1" btcr2 identifier.
|
|
168
|
-
* @param {ExternalData} data The verification methods of the DID Document.
|
|
169
|
-
* @returns {DidDocument} A new DidDocument.
|
|
170
|
-
*/
|
|
171
|
-
static fromExternalIdentifier(data) {
|
|
172
|
-
return new DidDocument(data);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Sanitize the DID Document by removing undefined values
|
|
176
|
-
* @returns {DidDocument} The sanitized DID Document
|
|
177
|
-
*/
|
|
178
|
-
static sanitize(doc) {
|
|
179
|
-
for (const key of Object.keys(doc)) {
|
|
180
|
-
if (doc[key] === undefined) {
|
|
181
|
-
delete doc[key];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return doc;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Validates a DidDocument by breaking it into modular validation methods.
|
|
188
|
-
* @param {DidDocument} didDocument The DID document to validate.
|
|
189
|
-
* @returns {boolean} True if the DID document is valid.
|
|
190
|
-
* @throws {DidDocumentError} If any validation check fails.
|
|
191
|
-
*/
|
|
192
|
-
static isValid(didDocument) {
|
|
193
|
-
if (!this.isValidContext(didDocument?.['@context'])) {
|
|
194
|
-
throw new DidDocumentError('Invalid "@context"', INVALID_DID_DOCUMENT, didDocument);
|
|
195
|
-
}
|
|
196
|
-
if (!this.isValidId(didDocument?.id)) {
|
|
197
|
-
throw new DidDocumentError('Invalid "id"', INVALID_DID_DOCUMENT, didDocument);
|
|
198
|
-
}
|
|
199
|
-
if (!this.isValidVerificationMethods(didDocument?.verificationMethod)) {
|
|
200
|
-
throw new DidDocumentError('Invalid "verificationMethod"', INVALID_DID_DOCUMENT, didDocument);
|
|
201
|
-
}
|
|
202
|
-
if (!this.isValidServices(didDocument?.service)) {
|
|
203
|
-
throw new DidDocumentError('Invalid "service"', INVALID_DID_DOCUMENT, didDocument);
|
|
204
|
-
}
|
|
205
|
-
if (!this.isValidVerificationRelationships(didDocument)) {
|
|
206
|
-
throw new DidDocumentError('Invalid verification relationships', INVALID_DID_DOCUMENT, didDocument);
|
|
207
|
-
}
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Validates that "@context" exists and includes correct values.
|
|
212
|
-
* @private
|
|
213
|
-
* @param {DidDocument['@context']} context The context to validate.
|
|
214
|
-
* @returns {boolean} True if the context is valid.
|
|
215
|
-
*/
|
|
216
|
-
static isValidContext(context) {
|
|
217
|
-
if (!context)
|
|
218
|
-
return false;
|
|
219
|
-
if (!Array.isArray(context))
|
|
220
|
-
return false;
|
|
221
|
-
if (!context.every(ctx => typeof ctx === 'string' && BTCR2_DID_DOCUMENT_CONTEXT.includes(ctx)))
|
|
222
|
-
return false;
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Validates that the DID Document has a valid id.
|
|
227
|
-
* @private
|
|
228
|
-
* @param {string} id The id to validate.
|
|
229
|
-
* @returns {boolean} True if the id is valid.
|
|
230
|
-
*/
|
|
231
|
-
static isValidId(id) {
|
|
232
|
-
if (typeof id !== 'string')
|
|
233
|
-
return false;
|
|
234
|
-
try {
|
|
235
|
-
Identifier.decode(id);
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Validates that verification methods exist and are correctly formatted.
|
|
244
|
-
* @private
|
|
245
|
-
* @param {DidVerificationMethod[]} verificationMethod The verification methods to validate.
|
|
246
|
-
* @returns {boolean} True if the verification methods are valid.
|
|
247
|
-
*/
|
|
248
|
-
static isValidVerificationMethods(verificationMethod) {
|
|
249
|
-
return Array.isArray(verificationMethod) && verificationMethod.every(Appendix.isDidVerificationMethod);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Validates that the DID Document has valid services.
|
|
253
|
-
* @private
|
|
254
|
-
* @param {DidService[]} service The services to validate.
|
|
255
|
-
* @returns {boolean} True if the services are valid.
|
|
256
|
-
*/
|
|
257
|
-
static isValidServices(service) {
|
|
258
|
-
return Array.isArray(service) && service.every(BeaconUtils.isBeaconService);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Validates verification relationships (authentication, assertionMethod, capabilityInvocation, capabilityDelegation).
|
|
262
|
-
* @private
|
|
263
|
-
* @param {DidDocument} didDocument The DID Document to validate.
|
|
264
|
-
* @returns {boolean} True if the verification relationships are valid.
|
|
265
|
-
*/
|
|
266
|
-
static isValidVerificationRelationships(didDocument) {
|
|
267
|
-
const possibleVerificationRelationships = [
|
|
268
|
-
'authentication',
|
|
269
|
-
'assertionMethod',
|
|
270
|
-
'capabilityInvocation',
|
|
271
|
-
'capabilityDelegation'
|
|
272
|
-
];
|
|
273
|
-
const keys = Object.keys(didDocument);
|
|
274
|
-
const availableKeys = possibleVerificationRelationships.filter(key => keys.includes(key));
|
|
275
|
-
return availableKeys.every((key) => {
|
|
276
|
-
const value = didDocument[key];
|
|
277
|
-
return value &&
|
|
278
|
-
Array.isArray(value) &&
|
|
279
|
-
value.every((entry) => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry));
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Validate the DID Document
|
|
284
|
-
* @returns {DidDocument} Validated DID Document.
|
|
285
|
-
* @throws {DidDocumentError} If the DID Document is invalid.
|
|
286
|
-
*/
|
|
287
|
-
static validate(didDocument) {
|
|
288
|
-
// Validate the DID Document
|
|
289
|
-
if (didDocument.id === ID_PLACEHOLDER_VALUE) {
|
|
290
|
-
didDocument.validateGenesis();
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
DidDocument.isValid(didDocument);
|
|
294
|
-
}
|
|
295
|
-
// Return the DID Document
|
|
296
|
-
return didDocument;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Validate the GenesisDocument.
|
|
300
|
-
* @returns {boolean} True if the GenesisDocument is valid.
|
|
301
|
-
*/
|
|
302
|
-
validateGenesis() {
|
|
303
|
-
// Validate the id
|
|
304
|
-
if (this.id !== ID_PLACEHOLDER_VALUE) {
|
|
305
|
-
throw new DidDocumentError('Invalid GenesisDocument ID', INVALID_DID_DOCUMENT, this);
|
|
306
|
-
}
|
|
307
|
-
// Validate the verificationMethod
|
|
308
|
-
if (!this.verificationMethod.every(vm => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
|
|
309
|
-
throw new DidDocumentError('Invalid GenesisDocument verificationMethod', INVALID_DID_DOCUMENT, this);
|
|
310
|
-
}
|
|
311
|
-
// Validate the service
|
|
312
|
-
if (!this.service.every(svc => svc.id.includes(ID_PLACEHOLDER_VALUE))) {
|
|
313
|
-
throw new DidDocumentError('Invalid GenesisDocument service', INVALID_DID_DOCUMENT, this);
|
|
314
|
-
}
|
|
315
|
-
if (!DidDocument.isValidVerificationRelationships(this)) {
|
|
316
|
-
// Return true if all validations pass
|
|
317
|
-
throw new DidDocumentError('Invalid GenesisDocument assertionMethod', INVALID_DID_DOCUMENT, this);
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Convert the DidDocument to an GenesisDocument.
|
|
323
|
-
* @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
|
|
324
|
-
*/
|
|
325
|
-
toIntermediate() {
|
|
326
|
-
if (this.id.includes('k1')) {
|
|
327
|
-
throw new DidDocumentError('Cannot convert a key identifier to an intermediate document', INVALID_DID_DOCUMENT, this);
|
|
328
|
-
}
|
|
329
|
-
return new GenesisDocument(this);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
export class Document {
|
|
333
|
-
static isValid(didDocument) {
|
|
334
|
-
return new DidDocument(didDocument).validateGenesis();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* GenesisDocument extends the DidDocument class for creating and managing intermediate DID documents.
|
|
339
|
-
* This class is used to create a minimal DID document with a placeholder ID.
|
|
340
|
-
* It is used in the process of creating a new DID document.
|
|
341
|
-
* @class GenesisDocument
|
|
342
|
-
* @extends {DidDocument}
|
|
343
|
-
*/
|
|
344
|
-
export class GenesisDocument extends DidDocument {
|
|
345
|
-
constructor(document) {
|
|
346
|
-
super(document);
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Convert the GenesisDocument to a DidDocument by replacing the placeholder value with the provided DID.
|
|
350
|
-
* @param did The DID to replace the placeholder value in the document.
|
|
351
|
-
* @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
|
|
352
|
-
*/
|
|
353
|
-
toDidDocument(did) {
|
|
354
|
-
const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
|
|
355
|
-
const parseThis = JSON.parse(stringThis);
|
|
356
|
-
return new DidDocument(parseThis);
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Create an GenesisDocument from a DidDocument by replacing the DID with a placeholder value.
|
|
360
|
-
* @param {DidDocument} didDocument The DidDocument to convert.
|
|
361
|
-
* @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
|
|
362
|
-
*/
|
|
363
|
-
static fromDidDocument(didDocument) {
|
|
364
|
-
const intermediateDocument = JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE);
|
|
365
|
-
return new GenesisDocument(intermediateDocument);
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Create a minimal GenesisDocument with a placeholder ID.
|
|
369
|
-
* @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
|
|
370
|
-
* @param {VerificationRelationships} relationships The public key in multibase format.
|
|
371
|
-
* @param {Array<BeaconService>} service The service to be included in the document.
|
|
372
|
-
* @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
|
|
373
|
-
*/
|
|
374
|
-
static create(verificationMethod, relationships, service) {
|
|
375
|
-
return new GenesisDocument({ id: ID_PLACEHOLDER_VALUE, ...relationships, verificationMethod, service, });
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Create a minimal GenesisDocument from a public key.
|
|
379
|
-
* @param {KeyBytes} publicKey The public key in bytes format.
|
|
380
|
-
* @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
|
|
381
|
-
*/
|
|
382
|
-
static fromPublicKey(publicKey, network) {
|
|
383
|
-
const pk = new CompressedSecp256k1PublicKey(publicKey);
|
|
384
|
-
const id = ID_PLACEHOLDER_VALUE;
|
|
385
|
-
const address = payments.p2pkh({ pubkey: pk.compressed, network: getNetwork(network) })?.address;
|
|
386
|
-
const services = [{
|
|
387
|
-
id: `${id}#service-0`,
|
|
388
|
-
serviceEndpoint: `bitcoin:${address}`,
|
|
389
|
-
type: 'SingletonBeacon',
|
|
390
|
-
}];
|
|
391
|
-
const relationships = {
|
|
392
|
-
authentication: [`${id}#key-0`],
|
|
393
|
-
assertionMethod: [`${id}#key-0`],
|
|
394
|
-
capabilityInvocation: [`${id}#key-0`],
|
|
395
|
-
capabilityDelegation: [`${id}#key-0`]
|
|
396
|
-
};
|
|
397
|
-
const verificationMethod = [
|
|
398
|
-
{
|
|
399
|
-
id: `${id}#key-0`,
|
|
400
|
-
type: 'Multikey',
|
|
401
|
-
controller: id,
|
|
402
|
-
publicKeyMultibase: pk.multibase.encoded,
|
|
403
|
-
}
|
|
404
|
-
];
|
|
405
|
-
return GenesisDocument.create(verificationMethod, relationships, services);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
|
|
409
|
-
* @param {object | DidDocument} object The JSON object to convert.
|
|
410
|
-
* @returns {DidDocument} The created DidDocument.
|
|
411
|
-
*/
|
|
412
|
-
static fromJSON(object) {
|
|
413
|
-
return new GenesisDocument(object);
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Convert a GenesisDocument to genesis bytes.
|
|
417
|
-
* @param {GenesisDocument} genesisDocument The GenesisDocument to convert.
|
|
418
|
-
* @returns {Bytes} The genesis bytes.
|
|
419
|
-
*/
|
|
420
|
-
static toGenesisBytes(genesisDocument) {
|
|
421
|
-
return hash(canonicalize(genesisDocument));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
//# sourceMappingURL=did-document.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"did-document.js","sourceRoot":"","sources":["../../../src/utils/did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,IAAI,EAEJ,eAAe,EACf,oBAAoB,EAEpB,SAAS,EAEV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,gCAAgC;IAChC,8BAA8B;CAC/B,CAAC;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAChC,MAAM,CAAC,MAAM,SAAS,GAAG,oDAAoD,CAAC;AA8B9E;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAChC,EAAE,CAAS;IACX,IAAI,CAAS;IACb,UAAU,CAAS;IACnB,kBAAkB,CAAS;IAC3B,kBAAkB,CAAsB;IAExC,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,kBAAk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,eAAe,EAAG,WAAW,OAAO,EAAE;gBACtC,IAAI,EAAc,iBAAiB;aACpC,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG;YACpB,cAAc,EAAS,CAAC,GAAG,EAAE,QAAQ,CAAC;YACtC,eAAe,EAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;YACtC,oBAAoB,EAAG,CAAC,GAAG,EAAE,QAAQ,CAAC;YACtC,oBAAoB,EAAG,CAAC,GAAG,EAAE,QAAQ,CAAC;SACvC,CAAC;QACF,MAAM,kBAAkB,GAAG;YACzB;gBACE,EAAE,EAAmB,GAAG,EAAE,QAAQ;gBAClC,IAAI,EAAiB,UAAU;gBAC/B,UAAU,EAAW,EAAE;gBACvB,kBAAkB,EAAG,EAAE,CAAC,SAAS,CAAC,OAAO;aAC1C;SACF,CAAC;QAEF,OAAO,eAAe,CAAC,MAAM,CAAC,kBAAkB,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC7E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,MAA4B;QACjD,OAAO,IAAI,eAAe,CAAC,MAA0B,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,eAAoC;QACxD,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { hexToBytes } from '@noble/hashes/utils';
|
|
2
|
-
import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
|
|
3
|
-
import { payments, Transaction } from 'bitcoinjs-lib';
|
|
4
|
-
import { BeaconCoordinatorError } from '../../error.js';
|
|
5
|
-
import { BeaconCohortSigningSession } from '../session/index.js';
|
|
6
|
-
import { BeaconCohortReadyMessage } from './messages/keygen/cohort-ready.js';
|
|
7
|
-
import { COHORT_STATUS } from './status.js';
|
|
8
|
-
export class AggregateBeaconCohort {
|
|
9
|
-
/**
|
|
10
|
-
* Unique identifier for the cohort.
|
|
11
|
-
* @type {string}
|
|
12
|
-
*/
|
|
13
|
-
id;
|
|
14
|
-
/**
|
|
15
|
-
* DID of the coordinator.
|
|
16
|
-
* @type {string}
|
|
17
|
-
*/
|
|
18
|
-
coordinatorDid;
|
|
19
|
-
/**
|
|
20
|
-
* Minimum number of participants required to finalize the cohort.
|
|
21
|
-
* @type {number}
|
|
22
|
-
*/
|
|
23
|
-
minParticipants;
|
|
24
|
-
/**
|
|
25
|
-
* Status of the cohort.
|
|
26
|
-
* @type {string}
|
|
27
|
-
*/
|
|
28
|
-
status;
|
|
29
|
-
/**
|
|
30
|
-
* Network on which the cohort operates (e.g., 'mainnet', 'testnet').
|
|
31
|
-
* @type {string}
|
|
32
|
-
*/
|
|
33
|
-
network;
|
|
34
|
-
/**
|
|
35
|
-
* Pending signature requests, mapping participant DIDs to their pending signatures.
|
|
36
|
-
* @type {Record<string, string>}
|
|
37
|
-
*/
|
|
38
|
-
pendingSignatureRequests = {};
|
|
39
|
-
/**
|
|
40
|
-
* List of participant DIDs.
|
|
41
|
-
* @type {Array<string>}
|
|
42
|
-
*/
|
|
43
|
-
participants = new Array();
|
|
44
|
-
/**
|
|
45
|
-
* List of cohort keys.
|
|
46
|
-
* @type {Array<Uint8Array>}
|
|
47
|
-
*/
|
|
48
|
-
_cohortKeys = new Array();
|
|
49
|
-
/**
|
|
50
|
-
* Taproot Merkle root for the cohort.
|
|
51
|
-
* @type {Uint8Array}
|
|
52
|
-
*/
|
|
53
|
-
trMerkleRoot = new Uint8Array();
|
|
54
|
-
/**
|
|
55
|
-
* Beacon address for the cohort, calculated from the Taproot multisig.
|
|
56
|
-
* @type {string}
|
|
57
|
-
*/
|
|
58
|
-
beaconAddress = '';
|
|
59
|
-
/**
|
|
60
|
-
* Type of beacon used in the cohort (default is 'SMTBeacon').
|
|
61
|
-
* @type {string}
|
|
62
|
-
*/
|
|
63
|
-
beaconType;
|
|
64
|
-
/**
|
|
65
|
-
* Creates a new Musig2Cohort instance.
|
|
66
|
-
* @param {Musig2CohortObject} params Parameters for initializing the cohort.
|
|
67
|
-
* @param {string} [params.id] Optional unique identifier for the cohort. If not provided, a random UUID will be generated.
|
|
68
|
-
* @param {number} params.minParticipants Minimum number of participants required to finalize the cohort.
|
|
69
|
-
* @param {string} [params.coordinatorDid] DID of the coordinator managing the cohort.
|
|
70
|
-
* @param {string} params.status Initial status of the cohort (e.g., 'PENDING', 'COHORT_SET').
|
|
71
|
-
* @param {string} params.network Network on which the cohort operates (e.g., 'mainnet', 'testnet').
|
|
72
|
-
*/
|
|
73
|
-
constructor({ id, minParticipants, coordinatorDid, status, network, beaconType }) {
|
|
74
|
-
this.id = id || crypto.randomUUID();
|
|
75
|
-
this.minParticipants = minParticipants || 2;
|
|
76
|
-
this.coordinatorDid = coordinatorDid || '';
|
|
77
|
-
this.status = status || COHORT_STATUS.COHORT_ADVERTISED;
|
|
78
|
-
this.network = network;
|
|
79
|
-
this.beaconType = beaconType || 'SMTBeacon';
|
|
80
|
-
}
|
|
81
|
-
set cohortKeys(keys) {
|
|
82
|
-
this.cohortKeys = sortKeys(keys);
|
|
83
|
-
}
|
|
84
|
-
validateCohort(participantKeys, cohortKeys, beaconAddress) {
|
|
85
|
-
for (const key of participantKeys) {
|
|
86
|
-
if (!cohortKeys.includes(key)) {
|
|
87
|
-
this.status = COHORT_STATUS.COHORT_FAILED;
|
|
88
|
-
throw new BeaconCoordinatorError(`Participant key ${key} not found in cohort ${this.id}.`, 'COHORT_VALIDATION_ERROR', {
|
|
89
|
-
cohortId: this.id,
|
|
90
|
-
participantKeys: participantKeys,
|
|
91
|
-
cohortKeys: cohortKeys,
|
|
92
|
-
beaconAddress: beaconAddress
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this.cohortKeys = cohortKeys.map(key => hexToBytes(key));
|
|
97
|
-
const calculatedAddress = this.calulateBeaconAddress();
|
|
98
|
-
if (calculatedAddress !== beaconAddress) {
|
|
99
|
-
this.status = COHORT_STATUS.COHORT_FAILED;
|
|
100
|
-
throw new BeaconCoordinatorError(`Calculated beacon address ${calculatedAddress} does not match provided address ${beaconAddress}.`, 'COHORT_ADDRESS_MISMATCH_ERROR', {
|
|
101
|
-
cohortId: this.id,
|
|
102
|
-
calculatedAddress,
|
|
103
|
-
providedAddress: beaconAddress
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
this.beaconAddress = beaconAddress;
|
|
107
|
-
this.status = COHORT_STATUS.COHORT_SET_STATUS;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Finalizes the cohort by checking if the minimum number of participants is met.
|
|
111
|
-
* If the minimum is met, it sets the status to 'COHORT_SET_STATUS' and calculates the beacon address.
|
|
112
|
-
* @throws {BeaconCoordinatorError} If the number of participants is less than the minimum required.
|
|
113
|
-
* @returns {void}
|
|
114
|
-
*/
|
|
115
|
-
finalize() {
|
|
116
|
-
if (this.participants.length < this.minParticipants) {
|
|
117
|
-
throw new BeaconCoordinatorError('Not enough participants to finalize the cohort', 'FINALIZE_COHORT_ERROR', {
|
|
118
|
-
cohortId: this.id,
|
|
119
|
-
participants: this.participants,
|
|
120
|
-
minParticipants: this.minParticipants
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
this.status = COHORT_STATUS.COHORT_SET_STATUS;
|
|
124
|
-
this.beaconAddress = this.calulateBeaconAddress();
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Calculates the beacon Taproot multisig address for the cohort using participant keys.
|
|
128
|
-
* @returns {string} The Taproot address for the cohort.
|
|
129
|
-
* @throws {BeaconCoordinatorError} If the Taproot address cannot be calculated.
|
|
130
|
-
*/
|
|
131
|
-
calulateBeaconAddress() {
|
|
132
|
-
const keyAggContext = keyAggregate(this.cohortKeys);
|
|
133
|
-
const aggPubkey = keyAggExport(keyAggContext);
|
|
134
|
-
const payment = payments.p2tr({ internalPubkey: aggPubkey });
|
|
135
|
-
if (!payment.hash) {
|
|
136
|
-
throw new BeaconCoordinatorError('Failed to calculate Taproot Merkle root', 'CALCULATE_BEACON_MERKLE_ROOT_ERROR', {
|
|
137
|
-
cohortId: this.id,
|
|
138
|
-
cohortKeys: this.cohortKeys,
|
|
139
|
-
minParticipants: this.minParticipants
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
this.trMerkleRoot = payment.hash;
|
|
143
|
-
if (!payment.address) {
|
|
144
|
-
throw new BeaconCoordinatorError('Failed to calculate Taproot address', 'CALCULATE_BEACON_ADDRESS_ERROR', {
|
|
145
|
-
cohortId: this.id,
|
|
146
|
-
cohortKeys: this.cohortKeys,
|
|
147
|
-
minParticipants: this.minParticipants
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
return payment.address;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Generates a CohortReadyMessage to be sent to participants when the cohort is set.
|
|
154
|
-
* @param {string} to The DID of the participant to whom the message is sent.
|
|
155
|
-
* @param {string} from The DID of the coordinator sending the message.
|
|
156
|
-
* @returns {BeaconCohortReadyMessage} The CohortReadyMessage containing the cohort details.
|
|
157
|
-
*/
|
|
158
|
-
getCohortReadyMessage(to, from) {
|
|
159
|
-
if (this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
|
|
160
|
-
throw new BeaconCoordinatorError('Cohort status not "COHORT_SET".');
|
|
161
|
-
}
|
|
162
|
-
return new BeaconCohortReadyMessage({
|
|
163
|
-
to,
|
|
164
|
-
from,
|
|
165
|
-
cohortId: this.id,
|
|
166
|
-
beaconAddress: this.beaconAddress,
|
|
167
|
-
cohortKeys: this.cohortKeys,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Adds a signature request to the pending requests for the cohort.
|
|
172
|
-
* @param {BeaconCohortRequestSignatureMessage} message The signature request message to add.
|
|
173
|
-
* @throws {Error} If a signature request from the same participant already exists.
|
|
174
|
-
*/
|
|
175
|
-
addSignatureRequest(message) {
|
|
176
|
-
if (!this.validateSignatureRequest(message)) {
|
|
177
|
-
throw new BeaconCoordinatorError(`No signature request from ${message.from} in cohort ${this.id}.`);
|
|
178
|
-
}
|
|
179
|
-
if (!message.body?.data) {
|
|
180
|
-
throw new BeaconCoordinatorError(`No signature data in request from ${message.from} in cohort ${this.id}.`);
|
|
181
|
-
}
|
|
182
|
-
this.pendingSignatureRequests[message.from] = message.body.data;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Validates a signature request message to ensure it is from a participant in the cohort.
|
|
186
|
-
* @param {BeaconCohortRequestSignatureMessage} message The signature request message to validate.
|
|
187
|
-
* @returns {boolean} True if the message is valid, false otherwise.
|
|
188
|
-
*/
|
|
189
|
-
validateSignatureRequest(message) {
|
|
190
|
-
const cohortId = message.body?.cohortId;
|
|
191
|
-
if (cohortId !== this.id) {
|
|
192
|
-
console.info(`Signature request for wrong cohort: ${cohortId}.`);
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
if (!this.participants.includes(message.from)) {
|
|
196
|
-
console.info(`Participant ${message.from} not in cohort ${this.id}.`);
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Starts a signing session for the cohort.
|
|
203
|
-
* @returns {BeaconCohortSigningSession} The request signature message for the signing session.
|
|
204
|
-
*/
|
|
205
|
-
startSigningSession() {
|
|
206
|
-
console.debug(`Starting signing session for cohort ${this.id} with status ${this.status}`);
|
|
207
|
-
if (this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
|
|
208
|
-
throw new BeaconCoordinatorError(`Cohort ${this.id} is not set.`);
|
|
209
|
-
}
|
|
210
|
-
// const smtRootBytes = new Uint8Array(32).map(() => Math.floor(Math.random() * 256));
|
|
211
|
-
const cohort = new AggregateBeaconCohort(this);
|
|
212
|
-
return new BeaconCohortSigningSession({
|
|
213
|
-
cohort,
|
|
214
|
-
pendingTx: new Transaction(),
|
|
215
|
-
processedRequests: this.pendingSignatureRequests,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Converts the cohort instance to a JSON object representation.
|
|
220
|
-
* @returns {BeaconCohort} The JSON object representation of the cohort.
|
|
221
|
-
*/
|
|
222
|
-
toJSON() {
|
|
223
|
-
return {
|
|
224
|
-
id: this.id,
|
|
225
|
-
coordinatorDid: this.coordinatorDid,
|
|
226
|
-
minParticipants: this.minParticipants,
|
|
227
|
-
status: this.status,
|
|
228
|
-
network: this.network,
|
|
229
|
-
pendingSignatureRequests: this.pendingSignatureRequests,
|
|
230
|
-
participants: this.participants,
|
|
231
|
-
cohortKeys: this.cohortKeys,
|
|
232
|
-
trMerkleRoot: this.trMerkleRoot,
|
|
233
|
-
beaconAddress: this.beaconAddress,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
//# sourceMappingURL=index.js.map
|