@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,13 @@
|
|
|
1
|
+
import { MethodError } from '@did-btcr2/common';
|
|
2
|
+
|
|
3
|
+
export class CommunicationServiceError extends MethodError {
|
|
4
|
+
constructor(message: string, type: string = 'CommunicationServiceError', data?: Record<string, any>) {
|
|
5
|
+
super(message, type, data);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class CommunicationAdapterError extends MethodError {
|
|
10
|
+
constructor(message: string, type: string = 'CommunicationAdapterError', data?: Record<string, any>) {
|
|
11
|
+
super(message, type, data);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NotImplementedError } from '@did-btcr2/common';
|
|
2
|
+
import { NostrAdapter } from './adapter/nostr.js';
|
|
3
|
+
import { CommunicationServiceError } from './error.js';
|
|
4
|
+
import { CommunicationService, Service } from './service.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Communication Factory pattern to create Communication Service instances.
|
|
8
|
+
* @class CommunicationFactory
|
|
9
|
+
* @type {CommunicationFactory}
|
|
10
|
+
*/
|
|
11
|
+
export class CommunicationFactory {
|
|
12
|
+
static establish(service: Service): CommunicationService {
|
|
13
|
+
switch (service.type) {
|
|
14
|
+
case 'nostr':
|
|
15
|
+
return new NostrAdapter();
|
|
16
|
+
case 'didcomm':
|
|
17
|
+
throw new NotImplementedError('DID Comm service not implemented yet.');
|
|
18
|
+
default:
|
|
19
|
+
throw new CommunicationServiceError(
|
|
20
|
+
`Invalid service type ${service.type}`,
|
|
21
|
+
'INVALID_BEACON_ERROR', { service }
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { AggregateBeaconMessageType } from '../cohort/messages/index.js';
|
|
3
|
+
import { RawSchnorrKeyPair } from '@did-btcr2/keypair';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ServiceAdapterConfig defines the configuration structure for the Nostr communication service.
|
|
7
|
+
* It includes relay URLs, key pairs, and components for identity generation.
|
|
8
|
+
* @interface ServiceAdapterConfig
|
|
9
|
+
* @extends {Record<string, any>}
|
|
10
|
+
* @type {ServiceAdapterConfig}
|
|
11
|
+
*/
|
|
12
|
+
export interface ServiceAdapterConfig extends Record<string, any> {
|
|
13
|
+
keys: ServiceAdapterIdentity<any>;
|
|
14
|
+
did: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SyncMessageHandler = (msg: any) => void;
|
|
18
|
+
export type AsyncMessageHandler = (msg: any) => Promise<void>;
|
|
19
|
+
export type MessageHandler = SyncMessageHandler | AsyncMessageHandler;
|
|
20
|
+
|
|
21
|
+
export type CommunicationServiceType = 'nostr' | 'didcomm';
|
|
22
|
+
export type ServiceAdapterConfigType<T extends ServiceAdapterConfig> = T;
|
|
23
|
+
export interface Service {
|
|
24
|
+
type: CommunicationServiceType;
|
|
25
|
+
keys: ServiceAdapterIdentity<RawSchnorrKeyPair>;
|
|
26
|
+
did: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
}
|
|
29
|
+
export type ServiceAdapter<T extends CommunicationService> = T;
|
|
30
|
+
export type ServiceAdapterIdentity<T extends RawSchnorrKeyPair> = T;
|
|
31
|
+
export interface CommunicationService {
|
|
32
|
+
name: string;
|
|
33
|
+
start(): void;
|
|
34
|
+
setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void;
|
|
35
|
+
registerMessageHandler(messageType: string, handler: MessageHandler): void;
|
|
36
|
+
sendMessage(
|
|
37
|
+
message: Maybe<AggregateBeaconMessageType>,
|
|
38
|
+
sender: string,
|
|
39
|
+
recipient?: string
|
|
40
|
+
): Promise<void | Promise<string>[]>;
|
|
41
|
+
generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfigType<ServiceAdapterConfig>;
|
|
42
|
+
}
|
|
@@ -1,135 +1,406 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Logger, Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { RawSchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
|
+
import { BeaconCoordinatorError } from '../error.js';
|
|
4
|
+
import { AggregateBeaconCohort } from './cohort/index.js';
|
|
5
|
+
import {
|
|
6
|
+
BEACON_COHORT_ADVERT,
|
|
7
|
+
BEACON_COHORT_NONCE_CONTRIBUTION,
|
|
8
|
+
BEACON_COHORT_OPT_IN,
|
|
9
|
+
BEACON_COHORT_OPT_IN_ACCEPT,
|
|
10
|
+
BEACON_COHORT_REQUEST_SIGNATURE,
|
|
11
|
+
BEACON_COHORT_SIGNATURE_AUTHORIZATION
|
|
12
|
+
} from './cohort/messages/constants.js';
|
|
13
|
+
import { BeaconCohortAdvertMessage } from './cohort/messages/keygen/cohort-advert.js';
|
|
14
|
+
import { BeaconCohortReadyMessage } from './cohort/messages/keygen/cohort-ready.js';
|
|
15
|
+
import { BeaconCohortOptInMessage, CohortOptInMessage } from './cohort/messages/keygen/opt-in.js';
|
|
16
|
+
import { BeaconCohortAggregatedNonceMessage } from './cohort/messages/sign/aggregated-nonce.js';
|
|
17
|
+
import { BeaconCohortNonceContributionMessage, CohortNonceContributionMessage } from './cohort/messages/sign/nonce-contribution.js';
|
|
18
|
+
import { BeaconCohortRequestSignatureMessage, CohortRequestSignatureMessage } from './cohort/messages/sign/request-signature.js';
|
|
19
|
+
import { BeaconCohortSignatureAuthorizationMessage, CohortSignatureAuthorizationMessage } from './cohort/messages/sign/signature-authorization.js';
|
|
20
|
+
import { NostrAdapter } from './communication/adapter/nostr.js';
|
|
21
|
+
import { CommunicationFactory } from './communication/factory.js';
|
|
22
|
+
import { CommunicationService, Service, ServiceAdapterIdentity } from './communication/service.js';
|
|
23
|
+
import { BeaconCohortSigningSession } from './session/index.js';
|
|
24
|
+
import { SIGNING_SESSION_STATUS } from './session/status.js';
|
|
8
25
|
|
|
26
|
+
type BeaconCoordinatorParams = {
|
|
27
|
+
protocol?: CommunicationService;
|
|
28
|
+
did: string;
|
|
29
|
+
keys: ServiceAdapterIdentity<RawSchnorrKeyPair>
|
|
30
|
+
name?: string;
|
|
31
|
+
}
|
|
9
32
|
/**
|
|
10
33
|
* The BeaconCoordinator class is responsible for managing the coordination of beacon aggregation.
|
|
11
34
|
* @class BeaconCoordinator
|
|
12
35
|
* @type {BeaconCoordinator}
|
|
13
36
|
*/
|
|
37
|
+
|
|
14
38
|
export class BeaconCoordinator {
|
|
15
39
|
/**
|
|
16
40
|
* The name of the BeaconCoordinator service.
|
|
17
41
|
* @type {string}
|
|
18
42
|
*/
|
|
19
|
-
public name: string
|
|
43
|
+
public name: string;
|
|
20
44
|
|
|
21
45
|
/**
|
|
22
46
|
* The DID of the BeaconCoordinator.
|
|
23
47
|
* @type {Array<string>}
|
|
24
48
|
*/
|
|
25
|
-
public did: string
|
|
49
|
+
public did: string;
|
|
26
50
|
|
|
27
51
|
/**
|
|
28
|
-
* The protocol
|
|
29
|
-
* @type {
|
|
52
|
+
* The communication protocol used by the BeaconCoordinator.
|
|
53
|
+
* @type {CommunicationService}
|
|
30
54
|
*/
|
|
31
|
-
public protocol:
|
|
55
|
+
public protocol: CommunicationService;
|
|
32
56
|
|
|
33
57
|
/**
|
|
34
|
-
* List of subscribers
|
|
58
|
+
* List of subscribers engaged in a Musig2 Cohort signing session with the BeaconCoordinator.
|
|
35
59
|
* @type {Array<string>}
|
|
36
60
|
*/
|
|
37
|
-
public cohorts: Array<
|
|
61
|
+
public cohorts: Array<AggregateBeaconCohort> = [];
|
|
38
62
|
|
|
39
63
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @type {
|
|
64
|
+
* Active signing sessions for the BeaconCoordinator.
|
|
65
|
+
* @type {Record<string, BeaconCohortSigningSession>}
|
|
42
66
|
*/
|
|
43
|
-
|
|
67
|
+
public activeSigningSessions: Map<string, BeaconCohortSigningSession> = new Map();
|
|
44
68
|
|
|
45
69
|
/**
|
|
46
70
|
* Constructs a new BeaconCoordinator instance.
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
71
|
+
* @param {BeaconCoordinatorParams} params The parameters for the coordinator.
|
|
72
|
+
* @param {CommunicationService} params.protocol The protocol service used for communication.
|
|
73
|
+
* @param {string} [params.name] Optional name for the coordinator. If not provided, a default name will be generated.
|
|
74
|
+
* @param {string} [params.did] Optional DID to use for the coordinator. If not provided, a new DID will be generated.
|
|
75
|
+
* @param {ServiceAdapterIdentity<RawKeyPair>} params.keys The keys used for cryptographic operations.
|
|
49
76
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
77
|
+
constructor(params: BeaconCoordinatorParams) {
|
|
78
|
+
this.name = params.name || `btcr2-beacon-coordinator-${crypto.randomUUID()}`;
|
|
79
|
+
this.did = params.did;
|
|
80
|
+
this.protocol = params.protocol || new NostrAdapter();
|
|
81
|
+
this.protocol.setKeys(params.keys);
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
/**
|
|
57
|
-
*
|
|
85
|
+
* Setup and start the BeaconCoordinator communication protocol.
|
|
58
86
|
* @returns {void}
|
|
59
87
|
*/
|
|
60
|
-
public
|
|
61
|
-
this.
|
|
62
|
-
this.protocol.registerMessageHandler(
|
|
63
|
-
this.protocol.registerMessageHandler(
|
|
64
|
-
this.protocol.registerMessageHandler(
|
|
65
|
-
this.protocol.registerMessageHandler(
|
|
66
|
-
this.protocol.
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Initializes the BeaconCoordinator by setting up the protocol and starting it.
|
|
71
|
-
* @param {string} [did] Optional DID to use for the coordinator. If not provided, the existing DID will be used.
|
|
72
|
-
*/
|
|
73
|
-
async initialize(did?: string): Promise<void> {
|
|
74
|
-
this.setup(did);
|
|
75
|
-
await this.protocol.start();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Handles subscription requests from other participants.
|
|
80
|
-
* @param {Base} message The message containing the subscription request.
|
|
81
|
-
* @returns {Promise<void>}
|
|
82
|
-
*/
|
|
83
|
-
private async _handleSubscribe(message: Base): Promise<void> {
|
|
84
|
-
const sender = message.from;
|
|
85
|
-
if (!this.subscribers.includes(sender)) {
|
|
86
|
-
this.subscribers.push(sender);
|
|
87
|
-
await this.acceptSubscription(sender);
|
|
88
|
-
}
|
|
88
|
+
public start(): void {
|
|
89
|
+
Logger.info(`Setting up BeaconCoordinator ${this.name} (${this.did}) on ${this.protocol.name} ...`);
|
|
90
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN, this._handleOptIn.bind(this));
|
|
91
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_REQUEST_SIGNATURE, this._handleRequestSignature.bind(this));
|
|
92
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_NONCE_CONTRIBUTION, this._handleNonceContribution.bind(this));
|
|
93
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_SIGNATURE_AUTHORIZATION, this._handleSignatureAuthorization.bind(this));
|
|
94
|
+
this.protocol.start();
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
/**
|
|
92
98
|
* Handles opt-in requests from participants to join a cohort.
|
|
93
|
-
* @param {
|
|
99
|
+
* @param {OptInMessage} message The message containing the opt-in request.
|
|
94
100
|
* @returns {Promise<void>}
|
|
95
101
|
*/
|
|
96
|
-
private async _handleOptIn(message:
|
|
97
|
-
const optIn =
|
|
98
|
-
const cohortId = optIn.cohortId;
|
|
102
|
+
private async _handleOptIn(message: CohortOptInMessage): Promise<void> {
|
|
103
|
+
const optIn = BeaconCohortOptInMessage.fromJSON(message);
|
|
104
|
+
const cohortId = optIn.body?.cohortId;
|
|
99
105
|
const participant = optIn.from;
|
|
100
|
-
const participantPk = optIn.participantPk;
|
|
106
|
+
const participantPk = optIn.body?.participantPk;
|
|
107
|
+
if(!cohortId || !participant || !participantPk) {
|
|
108
|
+
Logger.warn(`Invalid opt-in message from ${participant}: missing cohortId, participant or participantPk`);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
101
111
|
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
102
112
|
if (cohort && !cohort.participants.includes(participant)) {
|
|
103
113
|
cohort.participants.push(participant);
|
|
104
114
|
cohort.cohortKeys.push(participantPk);
|
|
105
115
|
await this.acceptSubscription(participant);
|
|
116
|
+
// If the cohort has enough participants, start the key generation process.
|
|
106
117
|
if (cohort.participants.length >= cohort.minParticipants) {
|
|
107
118
|
await this._startKeyGeneration(cohort);
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Handles request signature messages from participants.
|
|
125
|
+
* @private
|
|
126
|
+
* @param {CohortRequestSignatureMessage} message The message containing the request signature.
|
|
127
|
+
* @returns {Promise<void>}
|
|
128
|
+
*/
|
|
129
|
+
private async _handleRequestSignature(message: Maybe<CohortRequestSignatureMessage>): Promise<void> {
|
|
130
|
+
const signatureRequest = BeaconCohortRequestSignatureMessage.fromJSON(message);
|
|
131
|
+
const cohortId = signatureRequest.body?.cohortId;
|
|
132
|
+
if (!cohortId) {
|
|
133
|
+
Logger.warn(`Signature request missing cohort ID from ${signatureRequest.from}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
137
|
+
if (!cohort) {
|
|
138
|
+
Logger.error(`Cohort with ID ${cohortId} not found.`);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
cohort.addSignatureRequest(signatureRequest);
|
|
142
|
+
Logger.info(`Received signature request from ${signatureRequest.from} for cohort ${cohortId}.`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Handles nonce contribution messages from participants.
|
|
147
|
+
* @param {CohortNonceContributionMessage} message The message containing the nonce contribution.
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
*/
|
|
150
|
+
private async _handleNonceContribution(message: CohortNonceContributionMessage): Promise<void> {
|
|
151
|
+
// Cast message to NonceContributionMessage type.
|
|
152
|
+
const nonceContribMessage = BeaconCohortNonceContributionMessage.fromJSON(message);
|
|
153
|
+
const cohortId = nonceContribMessage.body?.cohortId;
|
|
154
|
+
if (!cohortId) {
|
|
155
|
+
Logger.warn(`Nonce contribution message missing cohort ID from ${nonceContribMessage.from}`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const sessionId = nonceContribMessage.body?.sessionId;
|
|
159
|
+
if (!sessionId) {
|
|
160
|
+
Logger.warn(`Nonce contribution message missing session ID from ${nonceContribMessage.from}`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// Get the signing session using the cohort ID from the message.
|
|
164
|
+
const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
|
|
165
|
+
|
|
166
|
+
// If the signing session does not exist, log an error and return.
|
|
167
|
+
if(!signingSession) {
|
|
168
|
+
Logger.error(`Session ${cohortId || sessionId} not found.`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// If the message.cohortId does not match the signingSession.cohortId, throw an error.
|
|
173
|
+
if(cohortId !== signingSession.cohort.id) {
|
|
174
|
+
throw new BeaconCoordinatorError(
|
|
175
|
+
`Nonce contribution for wrong cohort: ${signingSession.cohort.id} != ${cohortId}`,
|
|
176
|
+
'NONCE_CONTRIBUTION_ERROR', message
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
const nonceContribution = nonceContribMessage.body?.nonceContribution;
|
|
180
|
+
if(!nonceContribution) {
|
|
181
|
+
Logger.warn(`Nonce contribution message missing nonce contribution from ${nonceContribMessage.from}`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Add the nonce contribution to the signing session.
|
|
185
|
+
signingSession.addNonceContribution(nonceContribMessage.from, nonceContribution);
|
|
186
|
+
Logger.info(`Nonce contribution received from ${nonceContribMessage.from} for session ${sessionId}.`);
|
|
187
|
+
|
|
188
|
+
if (signingSession.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
|
|
189
|
+
await this.sendAggregatedNonce(signingSession);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Handles signature authorization messages from participants.
|
|
195
|
+
* @param {Maybe<CohortSignatureAuthorizationMessage>} message The message containing the signature authorization request.
|
|
196
|
+
* @returns {Promise<void>}
|
|
197
|
+
*/
|
|
198
|
+
private async _handleSignatureAuthorization(message: Maybe<CohortSignatureAuthorizationMessage>): Promise<void> {
|
|
199
|
+
const sigAuthMessage = BeaconCohortSignatureAuthorizationMessage.fromJSON(message);
|
|
200
|
+
const cohortId = sigAuthMessage.body?.cohortId;
|
|
201
|
+
if (!cohortId) {
|
|
202
|
+
Logger.warn(`Signature authorization message missing cohort ID from ${sigAuthMessage.from}`);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const sessionId = sigAuthMessage.body?.sessionId;
|
|
206
|
+
if (!sessionId) {
|
|
207
|
+
Logger.warn(`Signature authorization message missing session ID from ${sigAuthMessage.from}`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
|
|
211
|
+
if (!signingSession) {
|
|
212
|
+
Logger.error(`Session ${sessionId} not found.`);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if(signingSession.id !== sessionId) {
|
|
217
|
+
throw new BeaconCoordinatorError(
|
|
218
|
+
`Signature authorization for wrong session: ${signingSession.id} != ${sessionId}`,
|
|
219
|
+
'SIGNATURE_AUTHORIZATION_ERROR', message
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if(signingSession.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
|
|
224
|
+
throw new BeaconCoordinatorError(
|
|
225
|
+
`Partial signature received but not expected. Current status: ${signingSession.status}`,
|
|
226
|
+
'SIGNATURE_AUTHORIZATION_ERROR', message
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
const partialSignature = sigAuthMessage.body?.partialSignature;
|
|
230
|
+
if (!partialSignature) {
|
|
231
|
+
Logger.warn(`Signature authorization message missing partial signature from ${sigAuthMessage.from}`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
// Add the signature authorization to the signing session.
|
|
235
|
+
signingSession.addPartialSignature(sigAuthMessage.from, partialSignature);
|
|
236
|
+
Logger.info(`Received partial signature from ${sigAuthMessage.from} for session ${sessionId}.`);
|
|
237
|
+
|
|
238
|
+
if(signingSession.partialSignatures.size === signingSession.cohort.participants.length) {
|
|
239
|
+
signingSession.status = SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (signingSession.status === SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
|
|
243
|
+
const signature = await signingSession.generateFinalSignature();
|
|
244
|
+
Logger.info(`Final signature ${signature.toHex()} generated for session ${signingSession.id}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
112
248
|
/**
|
|
113
249
|
* Starts the key generation process for a cohort once it has enough participants.
|
|
114
250
|
* @param {Musig2Cohort} cohort The cohort for which to start key generation.
|
|
115
251
|
* @returns {Promise<void>}
|
|
116
252
|
*/
|
|
117
|
-
private async _startKeyGeneration(cohort:
|
|
253
|
+
private async _startKeyGeneration(cohort: AggregateBeaconCohort): Promise<void> {
|
|
254
|
+
Logger.info(`Starting key generation for cohort ${cohort.id} with participants: ${cohort.participants.join(', ')}`);
|
|
118
255
|
cohort.finalize();
|
|
256
|
+
for(const participant of cohort.participants) {
|
|
257
|
+
const message = cohort.getCohortReadyMessage(participant, this.did);
|
|
258
|
+
Logger.info(`Sending BEACON_COHORT_READY message to ${participant}`);
|
|
259
|
+
await this.protocol.sendMessage(message, participant, this.did);
|
|
260
|
+
}
|
|
261
|
+
Logger.info(`Finished sending BEACON_COHORT_READY message to ${cohort.participants.length} participants`);
|
|
119
262
|
}
|
|
120
263
|
|
|
121
264
|
/**
|
|
122
265
|
* Accepts a subscription request from a participant.
|
|
123
|
-
* @param {string}
|
|
266
|
+
* @param {string} participant The DID of the participant requesting the subscription.
|
|
124
267
|
* @returns {Promise<void>}
|
|
125
268
|
*/
|
|
126
|
-
public async acceptSubscription(
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
type :
|
|
130
|
-
to :
|
|
269
|
+
public async acceptSubscription(participant: string): Promise<void> {
|
|
270
|
+
Logger.info(`Accepting subscription from ${participant}`);
|
|
271
|
+
const message = {
|
|
272
|
+
type : BEACON_COHORT_OPT_IN_ACCEPT,
|
|
273
|
+
to : participant,
|
|
131
274
|
from : this.did
|
|
132
275
|
};
|
|
133
|
-
await this.protocol.sendMessage(
|
|
276
|
+
await this.protocol.sendMessage(message, this.did, participant);
|
|
134
277
|
}
|
|
135
|
-
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Sends the aggregated nonce to all participants in the session.
|
|
281
|
+
* @param {BeaconCohortSigningSession} session The session containing the aggregated nonce.
|
|
282
|
+
* @returns {Promise<void>}
|
|
283
|
+
*/
|
|
284
|
+
public async sendAggregatedNonce(session: BeaconCohortSigningSession): Promise<void> {
|
|
285
|
+
const aggregatedNonce = session.generateAggregatedNonce();
|
|
286
|
+
Logger.info(`Aggregated Nonces for session ${session.id}:`, aggregatedNonce);
|
|
287
|
+
|
|
288
|
+
session.status = SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES;
|
|
289
|
+
for (const participant of session.cohort.participants) {
|
|
290
|
+
const message = new BeaconCohortAggregatedNonceMessage({
|
|
291
|
+
to : participant,
|
|
292
|
+
from : this.did,
|
|
293
|
+
cohortId : session.cohort.id,
|
|
294
|
+
sessionId : session.id,
|
|
295
|
+
aggregatedNonce : aggregatedNonce
|
|
296
|
+
});
|
|
297
|
+
Logger.info(`Sending AGGREGATED_NONCE message to ${participant}`);
|
|
298
|
+
await this.protocol.sendMessage(message, participant, this.did);
|
|
299
|
+
}
|
|
300
|
+
Logger.info(`Successfully sent aggregated nonce message to all participants in session ${session.id}.`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Announces a new cohort to all subscribers.
|
|
305
|
+
* @param {number} minParticipants The minimum number of participants required for the cohort.
|
|
306
|
+
* @param {string} [network='mutinynet'] The network on which the cohort operates (default is 'signet').
|
|
307
|
+
* @param {string} [beaconType='SMTAggregateBeacon'] The type of beacon to be used (default is 'SMTAggregateBeacon').
|
|
308
|
+
* @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
|
|
309
|
+
*/
|
|
310
|
+
public async advertiseCohort(
|
|
311
|
+
minParticipants: number,
|
|
312
|
+
network: string = 'mutinynet',
|
|
313
|
+
beaconType: string = 'SMTAggregateBeacon'
|
|
314
|
+
): Promise<AggregateBeaconCohort> {
|
|
315
|
+
const cohort = new AggregateBeaconCohort({ minParticipants, network, beaconType });
|
|
316
|
+
Logger.info(`Advertising new cohort ${cohort.id} ...`);
|
|
317
|
+
this.cohorts.push(cohort);
|
|
318
|
+
const message = new BeaconCohortAdvertMessage({
|
|
319
|
+
from : this.did,
|
|
320
|
+
cohortId : cohort.id,
|
|
321
|
+
cohortSize : cohort.minParticipants,
|
|
322
|
+
network : cohort.network,
|
|
323
|
+
beaconType
|
|
324
|
+
});
|
|
325
|
+
Logger.info(`Sending ${BEACON_COHORT_ADVERT} message to network ...`, message);
|
|
326
|
+
await this.protocol.sendMessage(message, this.did);
|
|
327
|
+
Logger.info(`Cohort ${cohort.id} advertised successfully.`);
|
|
328
|
+
return cohort;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Announces to all subscribers a cohort is ready for signing.
|
|
334
|
+
* @param {string} cohortId The minimum number of participants required for the cohort.
|
|
335
|
+
* @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
|
|
336
|
+
*/
|
|
337
|
+
public async announceCohortReady(cohortId: string): Promise<AggregateBeaconCohort> {
|
|
338
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
339
|
+
if (!cohort) {
|
|
340
|
+
Logger.error(`Cohort with ID ${cohortId} not found.`);
|
|
341
|
+
throw new BeaconCoordinatorError(
|
|
342
|
+
`Cohort with ID ${cohortId} not found.`,
|
|
343
|
+
'COHORT_NOT_FOUND', { cohortId }
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
Logger.info(`Announcing cohort ${cohort.id} to ${cohort.participants.length} subscribers...`);
|
|
347
|
+
this.cohorts.push(cohort);
|
|
348
|
+
for (const participant of cohort.participants) {
|
|
349
|
+
const message = new BeaconCohortReadyMessage({
|
|
350
|
+
to : participant,
|
|
351
|
+
from : this.did,
|
|
352
|
+
cohortId : cohort.id,
|
|
353
|
+
beaconAddress : cohort.beaconAddress,
|
|
354
|
+
cohortKeys : cohort.cohortKeys,
|
|
355
|
+
});
|
|
356
|
+
Logger.info(`Sending ${BEACON_COHORT_ADVERT} message to ${participant}`);
|
|
357
|
+
|
|
358
|
+
await this.protocol.sendMessage(message, this.did, participant);
|
|
359
|
+
}
|
|
360
|
+
return cohort;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Starts a signing session for a given cohort.
|
|
365
|
+
* @param {string} cohortId The ID of the cohort for which to start a signing session.
|
|
366
|
+
* @returns {Promise<BeaconCohortSigningSession>} The started signing session.
|
|
367
|
+
* @throws {BeaconCoordinatorError} If the cohort with the given ID is not found.
|
|
368
|
+
*/
|
|
369
|
+
public async startSigningSession(cohortId: string): Promise<BeaconCohortSigningSession> {
|
|
370
|
+
Logger.info(`Attempting to start signing session for cohort ${cohortId}`);
|
|
371
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
372
|
+
if (!cohort) {
|
|
373
|
+
Logger.error(`Cohort with ID ${cohortId} not found.`);
|
|
374
|
+
throw new BeaconCoordinatorError(`Cohort with ID ${cohortId} not found.`, 'COHORT_NOT_FOUND');
|
|
375
|
+
}
|
|
376
|
+
Logger.info(`Cohort ${cohortId} found. Starting signing session.`);
|
|
377
|
+
const signingSession = cohort.startSigningSession();
|
|
378
|
+
Logger.info(`Starting signing session ${signingSession.id} for cohort ${cohortId}`);
|
|
379
|
+
for (const participant of cohort.participants) {
|
|
380
|
+
const msg = signingSession.getAuthorizationRequest(participant, this.did);
|
|
381
|
+
Logger.info(`Sending authorization request to ${participant}`);
|
|
382
|
+
await this.protocol.sendMessage(msg, this.did, participant).catch(error => {
|
|
383
|
+
Logger.error(`Error sending authorization request to ${participant}: ${error.message}`);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
this.activeSigningSessions.set(cohortId, signingSession);
|
|
387
|
+
Logger.info(`Signing session ${signingSession.id} started for cohort ${cohortId}`);
|
|
388
|
+
return signingSession;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Static initialization method for the BeaconCoordinator.
|
|
393
|
+
* @param {Service} service The communication service configuration.
|
|
394
|
+
* @returns {BeaconCoordinator} Initialized BeaconCoordinator instance.
|
|
395
|
+
*/
|
|
396
|
+
public static initialize(service: Service): BeaconCoordinator {
|
|
397
|
+
const communicationService = CommunicationFactory.establish(service);
|
|
398
|
+
const coordinator = new BeaconCoordinator({
|
|
399
|
+
protocol : communicationService,
|
|
400
|
+
did : service.did,
|
|
401
|
+
keys : service.keys,
|
|
402
|
+
});
|
|
403
|
+
Logger.info(`BeaconCoordinator ${coordinator.name} initialized with DID ${coordinator.did}. Run .start() to listen for messages`);
|
|
404
|
+
return coordinator;
|
|
405
|
+
}
|
|
406
|
+
}
|