@did-btcr2/method 0.17.2 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +30124 -19552
- package/dist/browser.mjs +30123 -19551
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +225 -0
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -0
- package/dist/{esm/core/beacon/aggregation → cjs/core/beacon/aggregation/cohort}/messages/base.js +3 -11
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +11 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +98 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
- package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/communication/error.js +12 -0
- package/dist/cjs/core/beacon/aggregation/communication/error.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/communication/factory.js +21 -0
- package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/communication/service.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/coordinator.js +282 -56
- package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/participant.js +435 -1
- package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +233 -0
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -0
- package/dist/cjs/core/beacon/aggregation/session/status.js +11 -0
- package/dist/cjs/core/beacon/aggregation/session/status.js.map +1 -0
- package/dist/cjs/core/beacon/cid-aggregate.js.map +1 -1
- package/dist/cjs/core/beacon/error.js +37 -0
- package/dist/cjs/core/beacon/error.js.map +1 -0
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/singleton.js +8 -5
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-aggregate.js.map +1 -1
- package/dist/cjs/{utils/beacons.js → core/beacon/utils.js} +4 -4
- package/dist/cjs/core/beacon/utils.js.map +1 -0
- package/dist/cjs/core/crud/read.js +2 -9
- package/dist/cjs/core/crud/read.js.map +1 -1
- package/dist/cjs/core/crud/update.js +18 -19
- package/dist/cjs/core/crud/update.js.map +1 -1
- package/dist/{esm/utils → cjs/core}/identifier.js +18 -3
- package/dist/cjs/core/identifier.js.map +1 -0
- package/dist/cjs/did-btcr2.js +2 -2
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +28 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/beacon.js.map +1 -1
- package/dist/cjs/utils/appendix.js +2 -3
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document.js +4 -6
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/cjs/utils/types.js +2 -0
- package/dist/cjs/utils/types.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/index.js +225 -0
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -0
- package/dist/{cjs/core/beacon/aggregation → esm/core/beacon/aggregation/cohort}/messages/base.js +3 -11
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +11 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +98 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/cohort/status.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/communication/error.js +12 -0
- package/dist/esm/core/beacon/aggregation/communication/error.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/communication/factory.js +21 -0
- package/dist/esm/core/beacon/aggregation/communication/factory.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/communication/service.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/coordinator.js +282 -56
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/participant.js +435 -1
- package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +233 -0
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -0
- package/dist/esm/core/beacon/aggregation/session/status.js +11 -0
- package/dist/esm/core/beacon/aggregation/session/status.js.map +1 -0
- package/dist/esm/core/beacon/cid-aggregate.js.map +1 -1
- package/dist/esm/core/beacon/error.js +37 -0
- package/dist/esm/core/beacon/error.js.map +1 -0
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/singleton.js +8 -5
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-aggregate.js.map +1 -1
- package/dist/esm/{utils/beacons.js → core/beacon/utils.js} +4 -4
- package/dist/esm/core/beacon/utils.js.map +1 -0
- package/dist/esm/core/crud/read.js +2 -9
- package/dist/esm/core/crud/read.js.map +1 -1
- package/dist/esm/core/crud/update.js +18 -19
- package/dist/esm/core/crud/update.js.map +1 -1
- package/dist/{cjs/utils → esm/core}/identifier.js +18 -3
- package/dist/esm/core/identifier.js.map +1 -0
- package/dist/esm/did-btcr2.js +2 -2
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +28 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces/beacon.js.map +1 -1
- package/dist/esm/utils/appendix.js +2 -3
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document.js +4 -6
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/esm/utils/types.js +2 -0
- package/dist/esm/utils/types.js.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +135 -0
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/{messages → cohort/messages}/base.d.ts +13 -8
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +10 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +64 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +28 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +26 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +23 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +19 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +24 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +24 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +25 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +25 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +25 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +26 -0
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +88 -0
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +93 -0
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/communication/error.d.ts +7 -0
- package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts +9 -0
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/communication/service.d.ts +35 -0
- package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +79 -26
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts +190 -0
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +155 -0
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -0
- package/dist/types/core/beacon/aggregation/session/status.d.ts +10 -0
- package/dist/types/core/beacon/aggregation/session/status.d.ts.map +1 -0
- package/dist/types/core/beacon/cid-aggregate.d.ts +3 -4
- package/dist/types/core/beacon/cid-aggregate.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +22 -0
- package/dist/types/core/beacon/error.d.ts.map +1 -0
- package/dist/types/core/beacon/factory.d.ts +2 -3
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton.d.ts +2 -3
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-aggregate.d.ts +3 -4
- package/dist/types/core/beacon/smt-aggregate.d.ts.map +1 -1
- package/dist/types/{utils/beacons.d.ts → core/beacon/utils.d.ts} +3 -3
- package/dist/types/core/beacon/utils.d.ts.map +1 -0
- package/dist/types/core/crud/read.d.ts +3 -3
- package/dist/types/core/crud/read.d.ts.map +1 -1
- package/dist/types/core/crud/update.d.ts +1 -1
- package/dist/types/core/crud/update.d.ts.map +1 -1
- package/dist/types/{utils → core}/identifier.d.ts +24 -3
- package/dist/types/core/identifier.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +1 -1
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +28 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/beacon.d.ts +65 -5
- package/dist/types/interfaces/beacon.d.ts.map +1 -1
- package/dist/types/interfaces/crud.d.ts +1 -1
- package/dist/types/interfaces/crud.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts +2 -10
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +1 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +1 -1
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/dist/types/{types/crud.d.ts → utils/types.d.ts} +2 -2
- package/dist/types/utils/types.d.ts.map +1 -0
- package/package.json +4 -3
- package/src/core/beacon/aggregation/cohort/index.ts +292 -0
- package/src/core/beacon/aggregation/{messages → cohort/messages}/base.ts +14 -16
- package/src/core/beacon/aggregation/cohort/messages/constants.ts +12 -0
- package/src/core/beacon/aggregation/cohort/messages/index.ts +143 -0
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +43 -0
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +39 -0
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +34 -0
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +33 -0
- package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +35 -0
- package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +38 -0
- package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +39 -0
- package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +39 -0
- package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +39 -0
- package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +40 -0
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +153 -0
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +300 -0
- package/src/core/beacon/aggregation/communication/error.ts +13 -0
- package/src/core/beacon/aggregation/communication/factory.ts +25 -0
- package/src/core/beacon/aggregation/communication/service.ts +42 -0
- package/src/core/beacon/aggregation/coordinator.ts +338 -67
- package/src/core/beacon/aggregation/participant.ts +512 -0
- package/src/core/beacon/aggregation/session/index.ts +289 -0
- package/src/core/beacon/aggregation/session/status.ts +18 -0
- package/src/core/beacon/cid-aggregate.ts +4 -5
- package/src/core/beacon/error.ts +44 -0
- package/src/core/beacon/factory.ts +2 -3
- package/src/core/beacon/singleton.ts +10 -8
- package/src/core/beacon/smt-aggregate.ts +4 -5
- package/src/{utils/beacons.ts → core/beacon/utils.ts} +5 -5
- package/src/core/crud/read.ts +7 -16
- package/src/core/crud/update.ts +25 -22
- package/src/{utils → core}/identifier.ts +35 -5
- package/src/did-btcr2.ts +4 -4
- package/src/index.ts +36 -8
- package/src/interfaces/beacon.ts +75 -5
- package/src/interfaces/crud.ts +1 -1
- package/src/utils/appendix.ts +3 -11
- package/src/utils/did-document-builder.ts +1 -1
- package/src/utils/did-document.ts +4 -7
- package/src/{types/crud.ts → utils/types.ts} +2 -2
- package/dist/cjs/core/beacon/aggregation/messages/advert.js +0 -24
- package/dist/cjs/core/beacon/aggregation/messages/advert.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/messages/base.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js +0 -25
- package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/messages/keygen.js +0 -8
- package/dist/cjs/core/beacon/aggregation/messages/keygen.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/messages/opt-in.js +0 -23
- package/dist/cjs/core/beacon/aggregation/messages/opt-in.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/messages/sign.js +0 -7
- package/dist/cjs/core/beacon/aggregation/messages/sign.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/models/cohort/index.js +0 -92
- package/dist/cjs/core/beacon/aggregation/models/cohort/index.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/models/cohort/status.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +0 -57
- package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +0 -1
- package/dist/cjs/core/beacon/aggregation/protocol/service.js.map +0 -1
- package/dist/cjs/core/key-manager/index.js +0 -290
- package/dist/cjs/core/key-manager/index.js.map +0 -1
- package/dist/cjs/core/key-manager/interface.js +0 -2
- package/dist/cjs/core/key-manager/interface.js.map +0 -1
- package/dist/cjs/interfaces/ibeacon.js +0 -2
- package/dist/cjs/interfaces/ibeacon.js.map +0 -1
- package/dist/cjs/types/crud.js +0 -2
- package/dist/cjs/types/crud.js.map +0 -1
- package/dist/cjs/utils/beacons.js.map +0 -1
- package/dist/cjs/utils/identifier.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/advert.js +0 -24
- package/dist/esm/core/beacon/aggregation/messages/advert.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/base.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/cohort-set.js +0 -25
- package/dist/esm/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/keygen.js +0 -8
- package/dist/esm/core/beacon/aggregation/messages/keygen.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/opt-in.js +0 -23
- package/dist/esm/core/beacon/aggregation/messages/opt-in.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/messages/sign.js +0 -7
- package/dist/esm/core/beacon/aggregation/messages/sign.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/models/cohort/index.js +0 -92
- package/dist/esm/core/beacon/aggregation/models/cohort/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/models/cohort/status.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js +0 -57
- package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/protocol/service.js.map +0 -1
- package/dist/esm/core/key-manager/index.js +0 -290
- package/dist/esm/core/key-manager/index.js.map +0 -1
- package/dist/esm/core/key-manager/interface.js +0 -2
- package/dist/esm/core/key-manager/interface.js.map +0 -1
- package/dist/esm/interfaces/ibeacon.js +0 -2
- package/dist/esm/interfaces/ibeacon.js.map +0 -1
- package/dist/esm/types/crud.js +0 -2
- package/dist/esm/types/crud.js.map +0 -1
- package/dist/esm/utils/beacons.js.map +0 -1
- package/dist/esm/utils/identifier.js.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/advert.d.ts +0 -22
- package/dist/types/core/beacon/aggregation/messages/advert.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/base.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts +0 -23
- package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/keygen.d.ts +0 -6
- package/dist/types/core/beacon/aggregation/messages/keygen.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts +0 -22
- package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/messages/sign.d.ts +0 -5
- package/dist/types/core/beacon/aggregation/messages/sign.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts +0 -77
- package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/models/cohort/status.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +0 -36
- package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/protocol/service.d.ts +0 -6
- package/dist/types/core/beacon/aggregation/protocol/service.d.ts.map +0 -1
- package/dist/types/core/key-manager/index.d.ts +0 -145
- package/dist/types/core/key-manager/index.d.ts.map +0 -1
- package/dist/types/core/key-manager/interface.d.ts +0 -113
- package/dist/types/core/key-manager/interface.d.ts.map +0 -1
- package/dist/types/interfaces/ibeacon.d.ts +0 -65
- package/dist/types/interfaces/ibeacon.d.ts.map +0 -1
- package/dist/types/types/crud.d.ts.map +0 -1
- package/dist/types/utils/beacons.d.ts.map +0 -1
- package/dist/types/utils/identifier.d.ts.map +0 -1
- package/src/core/beacon/aggregation/messages/advert.ts +0 -36
- package/src/core/beacon/aggregation/messages/cohort-set.ts +0 -37
- package/src/core/beacon/aggregation/messages/keygen.ts +0 -8
- package/src/core/beacon/aggregation/messages/opt-in.ts +0 -35
- package/src/core/beacon/aggregation/messages/sign.ts +0 -7
- package/src/core/beacon/aggregation/models/cohort/index.ts +0 -112
- package/src/core/beacon/aggregation/protocol/nostr.ts +0 -81
- package/src/core/beacon/aggregation/protocol/service.ts +0 -6
- package/src/core/key-manager/index.ts +0 -364
- package/src/core/key-manager/interface.ts +0 -129
- package/src/interfaces/ibeacon.ts +0 -75
- /package/dist/cjs/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
- /package/dist/cjs/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
- /package/dist/esm/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
- /package/dist/esm/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
- /package/dist/types/core/beacon/aggregation/{models/cohort → cohort}/status.d.ts +0 -0
- /package/src/core/beacon/aggregation/{models/cohort → cohort}/status.ts +0 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
|
|
2
|
+
import { payments, Transaction } from 'bitcoinjs-lib';
|
|
3
|
+
import { BeaconCoordinatorError } from '../../error.js';
|
|
4
|
+
import { BeaconCohortSigningSession } from '../session/index.js';
|
|
5
|
+
import { BeaconCohortReadyMessage } from './messages/keygen/cohort-ready.js';
|
|
6
|
+
import { BeaconCohortRequestSignatureMessage } from './messages/sign/request-signature.js';
|
|
7
|
+
import { COHORT_STATUS, COHORT_STATUS_TYPE } from './status.js';
|
|
8
|
+
|
|
9
|
+
export type Musig2CohortObject = {
|
|
10
|
+
id?: string;
|
|
11
|
+
coordinatorDid?: string;
|
|
12
|
+
minParticipants?: number;
|
|
13
|
+
status?: COHORT_STATUS_TYPE;
|
|
14
|
+
network: string;
|
|
15
|
+
beaconType?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface BeaconCohort {
|
|
19
|
+
id?: string;
|
|
20
|
+
coordinatorDid: string;
|
|
21
|
+
minParticipants: number;
|
|
22
|
+
status: COHORT_STATUS_TYPE;
|
|
23
|
+
network: string;
|
|
24
|
+
pendingSignatureRequests?: Record<string, string>;
|
|
25
|
+
participants?: Array<string>;
|
|
26
|
+
cohortKeys?: Array<Uint8Array>;
|
|
27
|
+
trMerkleRoot?: Uint8Array;
|
|
28
|
+
beaconAddress?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class AggregateBeaconCohort implements BeaconCohort {
|
|
32
|
+
/**
|
|
33
|
+
* Unique identifier for the cohort.
|
|
34
|
+
* @type {string}
|
|
35
|
+
*/
|
|
36
|
+
public id: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* DID of the coordinator.
|
|
40
|
+
* @type {string}
|
|
41
|
+
*/
|
|
42
|
+
public coordinatorDid: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Minimum number of participants required to finalize the cohort.
|
|
46
|
+
* @type {number}
|
|
47
|
+
*/
|
|
48
|
+
public minParticipants: number;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Status of the cohort.
|
|
52
|
+
* @type {string}
|
|
53
|
+
*/
|
|
54
|
+
public status: COHORT_STATUS_TYPE;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Network on which the cohort operates (e.g., 'mainnet', 'testnet').
|
|
58
|
+
* @type {string}
|
|
59
|
+
*/
|
|
60
|
+
public network: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Pending signature requests, mapping participant DIDs to their pending signatures.
|
|
64
|
+
* @type {Record<string, string>}
|
|
65
|
+
*/
|
|
66
|
+
public pendingSignatureRequests: Record<string, string> = {};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* List of participant DIDs.
|
|
70
|
+
* @type {Array<string>}
|
|
71
|
+
*/
|
|
72
|
+
public participants: Array<string> = new Array<string>();
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List of cohort keys.
|
|
76
|
+
* @type {Array<Uint8Array>}
|
|
77
|
+
*/
|
|
78
|
+
public _cohortKeys: Array<Uint8Array> = new Array<Uint8Array>();
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Taproot Merkle root for the cohort.
|
|
82
|
+
* @type {Uint8Array}
|
|
83
|
+
*/
|
|
84
|
+
public trMerkleRoot: Uint8Array = new Uint8Array();
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Beacon address for the cohort, calculated from the Taproot multisig.
|
|
88
|
+
* @type {string}
|
|
89
|
+
*/
|
|
90
|
+
public beaconAddress: string = '';
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Type of beacon used in the cohort (default is 'SMTAggregateBeacon').
|
|
94
|
+
* @type {string}
|
|
95
|
+
*/
|
|
96
|
+
public beaconType: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new Musig2Cohort instance.
|
|
100
|
+
* @param {Musig2CohortObject} params Parameters for initializing the cohort.
|
|
101
|
+
* @param {string} [params.id] Optional unique identifier for the cohort. If not provided, a random UUID will be generated.
|
|
102
|
+
* @param {number} params.minParticipants Minimum number of participants required to finalize the cohort.
|
|
103
|
+
* @param {string} [params.coordinatorDid] DID of the coordinator managing the cohort.
|
|
104
|
+
* @param {string} params.status Initial status of the cohort (e.g., 'PENDING', 'COHORT_SET').
|
|
105
|
+
* @param {string} params.network Network on which the cohort operates (e.g., 'mainnet', 'testnet').
|
|
106
|
+
*/
|
|
107
|
+
constructor({ id, minParticipants, coordinatorDid, status, network, beaconType }: Musig2CohortObject) {
|
|
108
|
+
this.id = id || crypto.randomUUID();
|
|
109
|
+
this.minParticipants = minParticipants || 2;
|
|
110
|
+
this.coordinatorDid = coordinatorDid || '';
|
|
111
|
+
this.status = status as COHORT_STATUS_TYPE || COHORT_STATUS.COHORT_ADVERTISED;
|
|
112
|
+
this.network = network;
|
|
113
|
+
this.beaconType = beaconType || 'SMTAggregateBeacon';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
set cohortKeys(keys: Array<Uint8Array>) {
|
|
117
|
+
this.cohortKeys = sortKeys(keys);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public validateCohort(participantKeys: Array<string>, cohortKeys: Array<string>, beaconAddress: string): void {
|
|
121
|
+
for(const key of participantKeys){
|
|
122
|
+
if(!cohortKeys.includes(key)) {
|
|
123
|
+
this.status = COHORT_STATUS.COHORT_FAILED;
|
|
124
|
+
throw new BeaconCoordinatorError(
|
|
125
|
+
`Participant key ${key} not found in cohort ${this.id}.`,
|
|
126
|
+
'COHORT_VALIDATION_ERROR',
|
|
127
|
+
{
|
|
128
|
+
cohortId : this.id,
|
|
129
|
+
participantKeys : participantKeys,
|
|
130
|
+
cohortKeys : cohortKeys,
|
|
131
|
+
beaconAddress : beaconAddress
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.cohortKeys = cohortKeys.map(key => Buffer.from(key, 'hex'));
|
|
137
|
+
const calculatedAddress = this.calulateBeaconAddress();
|
|
138
|
+
if (calculatedAddress !== beaconAddress) {
|
|
139
|
+
this.status = COHORT_STATUS.COHORT_FAILED;
|
|
140
|
+
throw new BeaconCoordinatorError(
|
|
141
|
+
`Calculated beacon address ${calculatedAddress} does not match provided address ${beaconAddress}.`,
|
|
142
|
+
'COHORT_ADDRESS_MISMATCH_ERROR',
|
|
143
|
+
{
|
|
144
|
+
cohortId : this.id,
|
|
145
|
+
calculatedAddress,
|
|
146
|
+
providedAddress : beaconAddress
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
this.beaconAddress = beaconAddress;
|
|
151
|
+
this.status = COHORT_STATUS.COHORT_SET_STATUS;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Finalizes the cohort by checking if the minimum number of participants is met.
|
|
156
|
+
* If the minimum is met, it sets the status to 'COHORT_SET_STATUS' and calculates the beacon address.
|
|
157
|
+
* @throws {BeaconCoordinatorError} If the number of participants is less than the minimum required.
|
|
158
|
+
* @returns {void}
|
|
159
|
+
*/
|
|
160
|
+
public finalize(): void {
|
|
161
|
+
if(this.participants.length < this.minParticipants) {
|
|
162
|
+
throw new BeaconCoordinatorError(
|
|
163
|
+
'Not enough participants to finalize the cohort',
|
|
164
|
+
'FINALIZE_COHORT_ERROR',
|
|
165
|
+
{
|
|
166
|
+
cohortId : this.id,
|
|
167
|
+
participants : this.participants,
|
|
168
|
+
minParticipants : this.minParticipants
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
this.status = COHORT_STATUS.COHORT_SET_STATUS;
|
|
173
|
+
this.beaconAddress = this.calulateBeaconAddress();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Calculates the beacon Taproot multisig address for the cohort using participant keys.
|
|
178
|
+
* @returns {string} The Taproot address for the cohort.
|
|
179
|
+
* @throws {BeaconCoordinatorError} If the Taproot address cannot be calculated.
|
|
180
|
+
*/
|
|
181
|
+
public calulateBeaconAddress(): string {
|
|
182
|
+
const keyAggContext = keyAggregate(this.cohortKeys);
|
|
183
|
+
const aggPubkey = keyAggExport(keyAggContext);
|
|
184
|
+
const payment = payments.p2tr({ internalPubkey: aggPubkey });
|
|
185
|
+
if(!payment.hash) {
|
|
186
|
+
throw new BeaconCoordinatorError(
|
|
187
|
+
'Failed to calculate Taproot Merkle root',
|
|
188
|
+
'CALCULATE_BEACON_MERKLE_ROOT_ERROR',
|
|
189
|
+
{
|
|
190
|
+
cohortId : this.id,
|
|
191
|
+
cohortKeys : this.cohortKeys,
|
|
192
|
+
minParticipants : this.minParticipants
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
this.trMerkleRoot = payment.hash;
|
|
197
|
+
if(!payment.address) {
|
|
198
|
+
throw new BeaconCoordinatorError(
|
|
199
|
+
'Failed to calculate Taproot address',
|
|
200
|
+
'CALCULATE_BEACON_ADDRESS_ERROR',
|
|
201
|
+
{
|
|
202
|
+
cohortId : this.id,
|
|
203
|
+
cohortKeys : this.cohortKeys,
|
|
204
|
+
minParticipants : this.minParticipants
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return payment.address;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Generates a CohortReadyMessage to be sent to participants when the cohort is set.
|
|
213
|
+
* @param {string} to The DID of the participant to whom the message is sent.
|
|
214
|
+
* @param {string} from The DID of the coordinator sending the message.
|
|
215
|
+
* @returns {BeaconCohortReadyMessage} The CohortReadyMessage containing the cohort details.
|
|
216
|
+
*/
|
|
217
|
+
public getCohortReadyMessage(to: string, from: string): BeaconCohortReadyMessage {
|
|
218
|
+
if(this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
|
|
219
|
+
throw new BeaconCoordinatorError('Cohort status not "COHORT_SET".');
|
|
220
|
+
}
|
|
221
|
+
return new BeaconCohortReadyMessage({
|
|
222
|
+
to,
|
|
223
|
+
from,
|
|
224
|
+
cohortId : this.id,
|
|
225
|
+
beaconAddress : this.beaconAddress,
|
|
226
|
+
cohortKeys : this.cohortKeys,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Adds a signature request to the pending requests for the cohort.
|
|
232
|
+
* @param {BeaconCohortRequestSignatureMessage} message The signature request message to add.
|
|
233
|
+
* @throws {Error} If a signature request from the same participant already exists.
|
|
234
|
+
*/
|
|
235
|
+
public addSignatureRequest(message: BeaconCohortRequestSignatureMessage): void {
|
|
236
|
+
if(!this.validateSignatureRequest(message)) {
|
|
237
|
+
throw new BeaconCoordinatorError(`No signature request from ${message.from} in cohort ${this.id}.`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if(!message.body?.data) {
|
|
241
|
+
throw new BeaconCoordinatorError(`No signature data in request from ${message.from} in cohort ${this.id}.`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
this.pendingSignatureRequests[message.from] = message.body.data;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Validates a signature request message to ensure it is from a participant in the cohort.
|
|
249
|
+
* @param {BeaconCohortRequestSignatureMessage} message The signature request message to validate.
|
|
250
|
+
* @returns {boolean} True if the message is valid, false otherwise.
|
|
251
|
+
*/
|
|
252
|
+
public validateSignatureRequest(message: BeaconCohortRequestSignatureMessage): boolean {
|
|
253
|
+
const cohortId = message.body?.cohortId;
|
|
254
|
+
if(cohortId !== this.id) {
|
|
255
|
+
console.info(`Signature request for wrong cohort: ${cohortId}.`);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if(!this.participants.includes(message.from)) {
|
|
260
|
+
console.info(`Participant ${message.from} not in cohort ${this.id}.`);
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Starts a signing session for the cohort.
|
|
269
|
+
* @returns {BeaconCohortSigningSession} The request signature message for the signing session.
|
|
270
|
+
*/
|
|
271
|
+
public startSigningSession(): BeaconCohortSigningSession {
|
|
272
|
+
console.debug(`Starting signing session for cohort ${this.id} with status ${this.status}`);
|
|
273
|
+
if(this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
|
|
274
|
+
throw new BeaconCoordinatorError(`Cohort ${this.id} is not set.`);
|
|
275
|
+
}
|
|
276
|
+
// const smtRootBytes = new Uint8Array(32).map(() => Math.floor(Math.random() * 256));
|
|
277
|
+
const cohort = new AggregateBeaconCohort(this);
|
|
278
|
+
return new BeaconCohortSigningSession({
|
|
279
|
+
cohort,
|
|
280
|
+
pendingTx : new Transaction(),
|
|
281
|
+
processedRequests : this.pendingSignatureRequests,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Converts the cohort instance to a JSON object representation.
|
|
287
|
+
* @returns {BeaconCohort} The JSON object representation of the cohort.
|
|
288
|
+
*/
|
|
289
|
+
public json(): BeaconCohort {
|
|
290
|
+
return Object.json(this) as BeaconCohort;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -9,34 +9,38 @@ export type BaseBody = {
|
|
|
9
9
|
participantPk?: Uint8Array;
|
|
10
10
|
beaconAddress?: string;
|
|
11
11
|
cohortKeys?: Array<Uint8Array>;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
aggregatedNonce?: Uint8Array;
|
|
14
|
+
nonceContribution?: Uint8Array;
|
|
15
|
+
partialSignature?: Uint8Array;
|
|
16
|
+
pendingTx?: string;
|
|
17
|
+
beaconType?: string;
|
|
18
|
+
data?: string;
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
export type Base = {
|
|
15
22
|
type: string;
|
|
16
|
-
to
|
|
23
|
+
to?: string;
|
|
17
24
|
from: string;
|
|
18
|
-
|
|
19
|
-
body: BaseBody;
|
|
25
|
+
body?: BaseBody;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
export class BaseMessage {
|
|
23
29
|
public type: string;
|
|
24
|
-
public to
|
|
30
|
+
public to?: string;
|
|
25
31
|
public from: string;
|
|
26
|
-
public
|
|
27
|
-
public body: BaseBody;
|
|
32
|
+
public body?: BaseBody;
|
|
28
33
|
|
|
29
|
-
constructor({ type, to, from,
|
|
34
|
+
constructor({ type, to, from, body }: Base) {
|
|
30
35
|
this.type = type;
|
|
31
36
|
this.to = to;
|
|
32
37
|
this.from = from;
|
|
33
|
-
this.threadId = threadId;
|
|
34
38
|
this.body = body;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
42
|
* Creates a BaseMessage from a JSON object.
|
|
39
|
-
* @param {Maybe<Base>} data
|
|
43
|
+
* @param {Maybe<Base>} data The JSON object to initialize the BaseMessage.
|
|
40
44
|
* @returns {BaseMessage} The initialized BaseMessage.
|
|
41
45
|
*/
|
|
42
46
|
public static fromJSON(data: Maybe<Base>): BaseMessage {
|
|
@@ -48,12 +52,6 @@ export class BaseMessage {
|
|
|
48
52
|
* @returns {Base} The JSON representation of the BaseMessage.
|
|
49
53
|
*/
|
|
50
54
|
public json(): Base {
|
|
51
|
-
return
|
|
52
|
-
type : this.type,
|
|
53
|
-
to : this.to,
|
|
54
|
-
from : this.from,
|
|
55
|
-
threadId : this.threadId,
|
|
56
|
-
body : this.body ?? {}
|
|
57
|
-
};
|
|
55
|
+
return Object.json(this) as Base;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const BEACON_COHORT_MESSAGE_PREFIX = 'https://btcr2.dev';
|
|
2
|
+
|
|
3
|
+
export const BEACON_COHORT_ADVERT = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_advert`;
|
|
4
|
+
export const BEACON_COHORT_OPT_IN = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_opt_in`;
|
|
5
|
+
export const BEACON_COHORT_OPT_IN_ACCEPT = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_opt_in_accept`;
|
|
6
|
+
export const BEACON_COHORT_READY = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_ready`;
|
|
7
|
+
|
|
8
|
+
export const BEACON_COHORT_REQUEST_SIGNATURE = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_request_signature`;
|
|
9
|
+
export const BEACON_COHORT_AUTHORIZATION_REQUEST = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_authorization_request`;
|
|
10
|
+
export const BEACON_COHORT_NONCE_CONTRIBUTION = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_nonce_contribution`;
|
|
11
|
+
export const BEACON_COHORT_AGGREGATED_NONCE = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_aggregated_nonce`;
|
|
12
|
+
export const BEACON_COHORT_SIGNATURE_AUTHORIZATION = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_signature_authorization`;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BEACON_COHORT_ADVERT,
|
|
3
|
+
BEACON_COHORT_AGGREGATED_NONCE,
|
|
4
|
+
BEACON_COHORT_AUTHORIZATION_REQUEST,
|
|
5
|
+
BEACON_COHORT_NONCE_CONTRIBUTION,
|
|
6
|
+
BEACON_COHORT_OPT_IN,
|
|
7
|
+
BEACON_COHORT_OPT_IN_ACCEPT,
|
|
8
|
+
BEACON_COHORT_READY,
|
|
9
|
+
BEACON_COHORT_REQUEST_SIGNATURE,
|
|
10
|
+
BEACON_COHORT_SIGNATURE_AUTHORIZATION
|
|
11
|
+
} from './constants.js';
|
|
12
|
+
import { CohortAdvertMessage } from './keygen/cohort-advert.js';
|
|
13
|
+
import { CohortReadyMessage } from './keygen/cohort-ready.js';
|
|
14
|
+
import { CohortOptInAcceptMessage } from './keygen/opt-in-accept.js';
|
|
15
|
+
import { CohortOptInMessage } from './keygen/opt-in.js';
|
|
16
|
+
import { CohortSubscribeMessage } from './keygen/subscribe.js';
|
|
17
|
+
import { CohortAggregatedNonceMessage } from './sign/aggregated-nonce.js';
|
|
18
|
+
import { CohortAuthorizationRequestMessage } from './sign/authorization-request.js';
|
|
19
|
+
import { CohortNonceContributionMessage } from './sign/nonce-contribution.js';
|
|
20
|
+
import { CohortRequestSignatureMessage } from './sign/request-signature.js';
|
|
21
|
+
import { CohortSignatureAuthorizationMessage } from './sign/signature-authorization.js';
|
|
22
|
+
|
|
23
|
+
export type KeyGenMessageType =
|
|
24
|
+
| CohortAdvertMessage
|
|
25
|
+
| CohortReadyMessage
|
|
26
|
+
| CohortOptInMessage
|
|
27
|
+
| CohortOptInAcceptMessage
|
|
28
|
+
| CohortSubscribeMessage;
|
|
29
|
+
|
|
30
|
+
export type SignMessageType =
|
|
31
|
+
| CohortAggregatedNonceMessage
|
|
32
|
+
| CohortAuthorizationRequestMessage
|
|
33
|
+
| CohortNonceContributionMessage
|
|
34
|
+
| CohortRequestSignatureMessage
|
|
35
|
+
| CohortSignatureAuthorizationMessage;
|
|
36
|
+
|
|
37
|
+
export type AggregateBeaconMessageType = KeyGenMessageType | SignMessageType;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* AggregateBeaconMessage is a utility class that provides constants and type checks
|
|
41
|
+
* for various message types used in the aggregate beacon communication protocol.
|
|
42
|
+
* It includes methods to validate message types and retrieve message types from objects.
|
|
43
|
+
* @class AggregateBeaconMessage
|
|
44
|
+
* @type {AggregateBeaconMessageType}
|
|
45
|
+
*/
|
|
46
|
+
export class AggregateBeaconMessage {
|
|
47
|
+
static BEACON_COHORT_ADVERT = BEACON_COHORT_ADVERT;
|
|
48
|
+
static BEACON_COHORT_OPT_IN = BEACON_COHORT_OPT_IN;
|
|
49
|
+
static BEACON_COHORT_READY = BEACON_COHORT_READY;
|
|
50
|
+
static BEACON_COHORT_OPT_IN_ACCEPT = BEACON_COHORT_OPT_IN_ACCEPT;
|
|
51
|
+
|
|
52
|
+
static BEACON_COHORT_KEY_GEN_MESSAGES: Map<string, string> = new Map([
|
|
53
|
+
['BEACON_COHORT_ADVERT', 'BEACON_COHORT_ADVERT'],
|
|
54
|
+
['BEACON_COHORT_OPT_IN', 'BEACON_COHORT_OPT_IN'],
|
|
55
|
+
['BEACON_COHORT_READY', 'BEACON_COHORT_READY'],
|
|
56
|
+
['BEACON_COHORT_OPT_IN_ACCEPT', 'BEACON_COHORT_OPT_IN_ACCEPT'],
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
static BEACON_COHORT_REQUEST_SIGNATURE = BEACON_COHORT_REQUEST_SIGNATURE;
|
|
60
|
+
static BEACON_COHORT_AUTHORIZATION_REQUEST = BEACON_COHORT_AUTHORIZATION_REQUEST;
|
|
61
|
+
static BEACON_COHORT_NONCE_CONTRIBUTION = BEACON_COHORT_NONCE_CONTRIBUTION;
|
|
62
|
+
static BEACON_COHORT_AGGREGATED_NONCE = BEACON_COHORT_AGGREGATED_NONCE;
|
|
63
|
+
static BEACON_COHORT_SIGNATURE_AUTHORIZATION = BEACON_COHORT_SIGNATURE_AUTHORIZATION;
|
|
64
|
+
|
|
65
|
+
static BEACON_COHORT_SIGN_MESSAGES: Map<string, string> = new Map([
|
|
66
|
+
['BEACON_COHORT_REQUEST_SIGNATURE', 'BEACON_COHORT_REQUEST_SIGNATURE'],
|
|
67
|
+
['BEACON_COHORT_AUTHORIZATION_REQUEST', 'BEACON_COHORT_AUTHORIZATION_REQUEST'],
|
|
68
|
+
['BEACON_COHORT_NONCE_CONTRIBUTION', 'BEACON_COHORT_NONCE_CONTRIBUTION'],
|
|
69
|
+
['BEACON_COHORT_AGGREGATED_NONCE', 'BEACON_COHORT_AGGREGATED_NONCE'],
|
|
70
|
+
['BEACON_COHORT_SIGNATURE_AUTHORIZATION', 'BEACON_COHORT_SIGNATURE_AUTHORIZATION'],
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
static ALL_MESSAGES: string[] = [
|
|
74
|
+
BEACON_COHORT_ADVERT,
|
|
75
|
+
BEACON_COHORT_OPT_IN,
|
|
76
|
+
BEACON_COHORT_READY,
|
|
77
|
+
BEACON_COHORT_OPT_IN_ACCEPT,
|
|
78
|
+
BEACON_COHORT_REQUEST_SIGNATURE,
|
|
79
|
+
BEACON_COHORT_AUTHORIZATION_REQUEST,
|
|
80
|
+
BEACON_COHORT_NONCE_CONTRIBUTION,
|
|
81
|
+
BEACON_COHORT_AGGREGATED_NONCE,
|
|
82
|
+
BEACON_COHORT_SIGNATURE_AUTHORIZATION
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the name provided is a valid message name.
|
|
87
|
+
* @param {string} type - The type of the message.
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
static isValidType(type: string): boolean {
|
|
91
|
+
return this.BEACON_COHORT_KEY_GEN_MESSAGES.has(type) || this.BEACON_COHORT_SIGN_MESSAGES.has(type);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the message value based on the type.
|
|
96
|
+
* @param {string} type - The type (or name) of the message.
|
|
97
|
+
* @returns {string | undefined} - The corresponding type value.
|
|
98
|
+
*/
|
|
99
|
+
static getMessageValueByType(type: string): string | undefined {
|
|
100
|
+
if(!this.isValidType(type)) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return this.BEACON_COHORT_KEY_GEN_MESSAGES.get(type) || this.BEACON_COHORT_SIGN_MESSAGES.get(type);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Checks if the provided type is a valid AggregateBeaconMessageType.
|
|
108
|
+
* @param {string} type - The message type to check.
|
|
109
|
+
* @returns {boolean} - Returns true if the type is valid, otherwise false.
|
|
110
|
+
*/
|
|
111
|
+
static isValidValue(type: string): boolean {
|
|
112
|
+
return this.ALL_MESSAGES.includes(type);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the provided type is a valid KeyGenMessageType.
|
|
117
|
+
* @param {string} value - The message type to check.
|
|
118
|
+
* @returns {boolean} - Returns true if the type is a key generation message type, otherwise false.
|
|
119
|
+
*/
|
|
120
|
+
static isKeyGenMessageValue(value: string): boolean {
|
|
121
|
+
return this.isValidValue(value) && [
|
|
122
|
+
BEACON_COHORT_ADVERT,
|
|
123
|
+
BEACON_COHORT_READY,
|
|
124
|
+
BEACON_COHORT_OPT_IN,
|
|
125
|
+
BEACON_COHORT_OPT_IN_ACCEPT,
|
|
126
|
+
].includes(value);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the provided type is a valid SignMessageType.
|
|
131
|
+
* @param {string} value - The message type to check.
|
|
132
|
+
* @returns {boolean} - Returns true if the type is a sign message type, otherwise false.
|
|
133
|
+
*/
|
|
134
|
+
static isSignMessageValue(value: string): boolean {
|
|
135
|
+
return this.isValidValue(value) && [
|
|
136
|
+
BEACON_COHORT_AGGREGATED_NONCE,
|
|
137
|
+
BEACON_COHORT_AUTHORIZATION_REQUEST,
|
|
138
|
+
BEACON_COHORT_NONCE_CONTRIBUTION,
|
|
139
|
+
BEACON_COHORT_REQUEST_SIGNATURE,
|
|
140
|
+
BEACON_COHORT_SIGNATURE_AUTHORIZATION
|
|
141
|
+
].includes(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { BaseMessage } from '../base.js';
|
|
3
|
+
import { BEACON_COHORT_ADVERT } from '../constants.js';
|
|
4
|
+
|
|
5
|
+
export interface CohortAdvertMessage {
|
|
6
|
+
type?: typeof BEACON_COHORT_ADVERT;
|
|
7
|
+
id?: string;
|
|
8
|
+
from: string;
|
|
9
|
+
cohortId: string;
|
|
10
|
+
cohortSize: number;
|
|
11
|
+
beaconType: string;
|
|
12
|
+
network: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents a message advertising a cohort to potential participants.
|
|
17
|
+
* @class BeaconCohortAdvertMessage
|
|
18
|
+
* @extends BaseMessage
|
|
19
|
+
* @type {BeaconCohortAdvertMessage}
|
|
20
|
+
*/
|
|
21
|
+
export class BeaconCohortAdvertMessage extends BaseMessage {
|
|
22
|
+
public id: string;
|
|
23
|
+
|
|
24
|
+
constructor({ from, id, cohortId, cohortSize, beaconType, network }: CohortAdvertMessage) {
|
|
25
|
+
const body = { cohortId, cohortSize, beaconType, network };
|
|
26
|
+
const type = BEACON_COHORT_ADVERT;
|
|
27
|
+
super({ from, body, type });
|
|
28
|
+
this.id = id || `${type}/${cohortId}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initializes a BeaconCohortAdvertMessage from a possible CohortAdvertMessage object.
|
|
33
|
+
* @param {CohortAdvertMessage} data The CohortAdvertMessage object to initialize the BeaconCohortAdvertMessage.
|
|
34
|
+
* @returns {BeaconCohortAdvertMessage} The new BeaconCohortAdvertMessage.
|
|
35
|
+
*/
|
|
36
|
+
public static fromJSON(data: Maybe<CohortAdvertMessage>): BeaconCohortAdvertMessage {
|
|
37
|
+
const message = JSON.parse(data);
|
|
38
|
+
if (message.type !== BEACON_COHORT_ADVERT){
|
|
39
|
+
throw new Error(`Invalid type: ${message.type}`);
|
|
40
|
+
}
|
|
41
|
+
return new BeaconCohortAdvertMessage(message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { BaseMessage } from '../base.js';
|
|
3
|
+
import { BEACON_COHORT_READY } from '../constants.js';
|
|
4
|
+
|
|
5
|
+
export interface CohortReadyMessage {
|
|
6
|
+
type?: typeof BEACON_COHORT_READY;
|
|
7
|
+
to: string;
|
|
8
|
+
from: string;
|
|
9
|
+
cohortId: string;
|
|
10
|
+
beaconAddress: string;
|
|
11
|
+
cohortKeys: Array<Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents a message indicating that a cohort has met the required conditions.
|
|
16
|
+
* @class BeaconCohortReadyMessage
|
|
17
|
+
* @extends BaseMessage
|
|
18
|
+
* @type {BeaconCohortReadyMessage}
|
|
19
|
+
*/
|
|
20
|
+
export class BeaconCohortReadyMessage extends BaseMessage {
|
|
21
|
+
constructor({ from, to, cohortId, beaconAddress, cohortKeys }: CohortReadyMessage) {
|
|
22
|
+
const body = { cohortId, beaconAddress, cohortKeys };
|
|
23
|
+
const type = BEACON_COHORT_READY;
|
|
24
|
+
super({ from, to, body, type });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initializes an BeaconCohortReadyMessage from a given OptIn object.
|
|
29
|
+
* @param {CohortReadyMessage} data The CohortReadyMessage object to initialize the BeaconCohortReadyMessage.
|
|
30
|
+
* @returns {BeaconCohortReadyMessage} The new BeaconCohortReadyMessage.
|
|
31
|
+
*/
|
|
32
|
+
public static fromJSON(data: Maybe<CohortReadyMessage>): BeaconCohortReadyMessage {
|
|
33
|
+
const message = JSON.parse(data);
|
|
34
|
+
if (message.type !== BEACON_COHORT_READY) {
|
|
35
|
+
throw new Error(`Invalid type: ${message.type}`);
|
|
36
|
+
}
|
|
37
|
+
return new BeaconCohortReadyMessage(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { BaseMessage } from '../base.js';
|
|
3
|
+
import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
|
|
4
|
+
|
|
5
|
+
export interface CohortOptInAcceptMessage {
|
|
6
|
+
type?: typeof BEACON_COHORT_OPT_IN_ACCEPT;
|
|
7
|
+
to: string;
|
|
8
|
+
from: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a message for a coordinator accepting a participant subscribe to a cohort.
|
|
13
|
+
* @class BeaconCohortOptInAcceptMessage
|
|
14
|
+
* @extends BaseMessage
|
|
15
|
+
* @type {BeaconCohortOptInAcceptMessage}
|
|
16
|
+
*/
|
|
17
|
+
export class BeaconCohortOptInAcceptMessage extends BaseMessage {
|
|
18
|
+
constructor({ to, from }: CohortOptInAcceptMessage) {
|
|
19
|
+
super({ to, from, type: BEACON_COHORT_OPT_IN_ACCEPT });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Initializes a BeaconCohortOptInAcceptMessage from a possible CohortOptInAcceptMessage object.
|
|
24
|
+
* @param {CohortOptInAcceptMessage} data The CohortOptInAcceptMessage object to initialize the BeaconCohortOptInAcceptMessage.
|
|
25
|
+
* @returns {BeaconCohortOptInAcceptMessage} The new BeaconCohortOptInAcceptMessage.
|
|
26
|
+
*/
|
|
27
|
+
public static fromJSON(data: Maybe<CohortOptInAcceptMessage>): BeaconCohortOptInAcceptMessage {
|
|
28
|
+
const message = JSON.parse(data);
|
|
29
|
+
if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
|
|
30
|
+
throw new Error(`Invalid type: ${message.type}`);
|
|
31
|
+
}
|
|
32
|
+
return new BeaconCohortOptInAcceptMessage(message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { BaseMessage } from '../base.js';
|
|
3
|
+
import { BEACON_COHORT_OPT_IN } from '../constants.js';
|
|
4
|
+
|
|
5
|
+
export interface CohortOptInMessage {
|
|
6
|
+
type?: typeof BEACON_COHORT_OPT_IN;
|
|
7
|
+
to: string;
|
|
8
|
+
from: string;
|
|
9
|
+
cohortId: string;
|
|
10
|
+
participantPk: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class BeaconCohortOptInMessage extends BaseMessage {
|
|
14
|
+
|
|
15
|
+
constructor({ from, to, cohortId, participantPk }: CohortOptInMessage) {
|
|
16
|
+
const body = { cohortId, participantPk };
|
|
17
|
+
const type = BEACON_COHORT_OPT_IN;
|
|
18
|
+
super({ from, to, body, type });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Initializes a BeaconCohortOptInMessage from a possible CohortOptInMessage object.
|
|
23
|
+
* @param {CohortOptInMessage} data The CohortOptInMessage object to initialize the BeaconCohortOptInMessage.
|
|
24
|
+
* @returns {BeaconCohortOptInMessage} The new BeaconCohortOptInMessage.
|
|
25
|
+
*/
|
|
26
|
+
public static fromJSON(data: Maybe<CohortOptInMessage>): BeaconCohortOptInMessage {
|
|
27
|
+
const message = JSON.parse(data);
|
|
28
|
+
if (message.type != BEACON_COHORT_OPT_IN) {
|
|
29
|
+
throw new Error(`Invalid type: ${message.type}`);
|
|
30
|
+
}
|
|
31
|
+
return new BeaconCohortOptInMessage(message);
|
|
32
|
+
}
|
|
33
|
+
}
|