@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,512 @@
|
|
|
1
|
+
import { KeyBytes, Logger, Maybe } from '@did-btcr2/common';
|
|
2
|
+
import { HDKey } from '@scure/bip32';
|
|
3
|
+
import { mnemonicToSeedSync } from '@scure/bip39';
|
|
4
|
+
import * as musig2 from '@scure/btc-signer/musig2';
|
|
5
|
+
import { Transaction } from 'bitcoinjs-lib';
|
|
6
|
+
import { BeaconParticipantError } from '../error.js';
|
|
7
|
+
import { AggregateBeaconCohort } from './cohort/index.js';
|
|
8
|
+
import {
|
|
9
|
+
BEACON_COHORT_ADVERT,
|
|
10
|
+
BEACON_COHORT_AGGREGATED_NONCE,
|
|
11
|
+
BEACON_COHORT_AUTHORIZATION_REQUEST,
|
|
12
|
+
BEACON_COHORT_OPT_IN_ACCEPT,
|
|
13
|
+
BEACON_COHORT_READY
|
|
14
|
+
} from './cohort/messages/constants.js';
|
|
15
|
+
import { BeaconCohortAdvertMessage, CohortAdvertMessage } from './cohort/messages/keygen/cohort-advert.js';
|
|
16
|
+
import { BeaconCohortReadyMessage, CohortReadyMessage } from './cohort/messages/keygen/cohort-ready.js';
|
|
17
|
+
import { BeaconCohortOptInAcceptMessage, CohortOptInAcceptMessage } from './cohort/messages/keygen/opt-in-accept.js';
|
|
18
|
+
import { BeaconCohortOptInMessage } from './cohort/messages/keygen/opt-in.js';
|
|
19
|
+
import { BeaconCohortSubscribeMessage } from './cohort/messages/keygen/subscribe.js';
|
|
20
|
+
import { BeaconCohortAggregatedNonceMessage, CohortAggregatedNonceMessage } from './cohort/messages/sign/aggregated-nonce.js';
|
|
21
|
+
import { BeaconCohortAuthorizationRequestMessage, CohortAuthorizationRequestMessage } from './cohort/messages/sign/authorization-request.js';
|
|
22
|
+
import { BeaconCohortNonceContributionMessage } from './cohort/messages/sign/nonce-contribution.js';
|
|
23
|
+
import { BeaconCohortRequestSignatureMessage } from './cohort/messages/sign/request-signature.js';
|
|
24
|
+
import { BeaconCohortSignatureAuthorizationMessage } from './cohort/messages/sign/signature-authorization.js';
|
|
25
|
+
import { COHORT_STATUS } from './cohort/status.js';
|
|
26
|
+
import { NostrAdapter } from './communication/adapter/nostr.js';
|
|
27
|
+
import { CommunicationService } from './communication/service.js';
|
|
28
|
+
import { BeaconCohortSigningSession } from './session/index.js';
|
|
29
|
+
|
|
30
|
+
type Seed = KeyBytes;
|
|
31
|
+
type Mnemonic = string;
|
|
32
|
+
|
|
33
|
+
type SessionId = string;
|
|
34
|
+
type ActiveSigningSessions = Map<SessionId, BeaconCohortSigningSession>;
|
|
35
|
+
|
|
36
|
+
type CohortId = string;
|
|
37
|
+
type KeyIndex = number;
|
|
38
|
+
type CohortKeyState = Map<CohortId, KeyIndex>;
|
|
39
|
+
|
|
40
|
+
type BeaconParticipantParams = {
|
|
41
|
+
ent: Seed | Mnemonic;
|
|
42
|
+
protocol?: CommunicationService;
|
|
43
|
+
did: string;
|
|
44
|
+
name?: string
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Represents a participant in the did:btc1 Beacon Aggregation protocol.
|
|
48
|
+
* @class BeaconParticipant
|
|
49
|
+
* @type {BeaconParticipant}
|
|
50
|
+
*/
|
|
51
|
+
export class BeaconParticipant {
|
|
52
|
+
/**
|
|
53
|
+
* The name of the BeaconParticipant service.
|
|
54
|
+
* @type {string}
|
|
55
|
+
*/
|
|
56
|
+
public name: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The DID of the BeaconParticipant.
|
|
60
|
+
* @type {Array<string>}
|
|
61
|
+
*/
|
|
62
|
+
public did: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The communication protocol used by the BeaconParticipant.
|
|
66
|
+
* @type {CommunicationService}
|
|
67
|
+
*/
|
|
68
|
+
public protocol: CommunicationService;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The HD key used by the BeaconParticipant.
|
|
72
|
+
* @type {HDKey}
|
|
73
|
+
*/
|
|
74
|
+
public hdKey: HDKey;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The current index for the beacon key.
|
|
78
|
+
* @type {number}
|
|
79
|
+
*/
|
|
80
|
+
public beaconKeyIndex: number = 0;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The coordinator DIDs that the participant is subscribed to.
|
|
84
|
+
* @type {Array<string>}
|
|
85
|
+
*/
|
|
86
|
+
public coordinatorDids: Array<string> = new Array<string>();
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The cohorts that the participant is part of.
|
|
90
|
+
* @type {Array<AggregateBeaconCohort>}
|
|
91
|
+
*/
|
|
92
|
+
public cohorts: Array<AggregateBeaconCohort> = new Array<AggregateBeaconCohort>();
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A mapping of Cohort IDs to HDKey indexes (CohortId => KeyIndex).
|
|
96
|
+
* @type {CohortKeyState}
|
|
97
|
+
*/
|
|
98
|
+
public cohortKeyState: CohortKeyState = new Map<CohortId, KeyIndex>();
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A mapping of active Session IDs to their sessions (sessionId => BeaconCohortSigningSession).
|
|
102
|
+
* @type {ActiveSigningSessions}
|
|
103
|
+
*/
|
|
104
|
+
public activeSigningSessions: ActiveSigningSessions = new Map<string, BeaconCohortSigningSession>();
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates an instance of BeaconParticipant.
|
|
108
|
+
* @param {BeaconParticipantParams} params The parameters for the participant.
|
|
109
|
+
* @param {Seed | Mnemonic} params.ent The seed or mnemonic to derive the HD key.
|
|
110
|
+
* @param {CommunicationService} params.protocol The communication protocol to use.
|
|
111
|
+
* @param {string} params.did The DID of the participant.
|
|
112
|
+
* @param {string} [params.name] Optional name for the participant. If not provided, a random name will be generated.
|
|
113
|
+
*/
|
|
114
|
+
constructor({ ent, protocol, did, name }: BeaconParticipantParams) {
|
|
115
|
+
this.did = did;
|
|
116
|
+
this.name = name || `btcr2-beacon-participant-${crypto.randomUUID()}`;
|
|
117
|
+
this.beaconKeyIndex = this.cohortKeyState.size;
|
|
118
|
+
|
|
119
|
+
this.hdKey = ent instanceof Uint8Array
|
|
120
|
+
? HDKey.fromMasterSeed(ent)
|
|
121
|
+
: HDKey.fromMasterSeed(mnemonicToSeedSync(ent));
|
|
122
|
+
|
|
123
|
+
const { publicKey: pk, privateKey: secret } = this.hdKey.deriveChild(this.beaconKeyIndex);
|
|
124
|
+
if(!pk || !secret) {
|
|
125
|
+
throw new BeaconParticipantError(
|
|
126
|
+
`Failed to derive HD key for participant ${this.name} at index ${this.beaconKeyIndex}`,
|
|
127
|
+
'CONSTRUCTOR_ERROR', { public: pk, secret }
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
this.protocol = protocol || new NostrAdapter();
|
|
131
|
+
this.protocol.setKeys({ public: pk, secret });
|
|
132
|
+
this.cohortKeyState.set('__UNSET__', this.beaconKeyIndex);
|
|
133
|
+
Logger.debug(`BeaconParticipant initialized with DID: ${this.did}, Name: ${this.name}, Key Index: ${this.beaconKeyIndex}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Setup and start the BeaconParticipant communication protocol..
|
|
138
|
+
* @returns {void}
|
|
139
|
+
*/
|
|
140
|
+
public start(): void {
|
|
141
|
+
Logger.info(`Setting up BeaconParticipant ${this.name} (${this.did}) on ${this.protocol.name} ...`);
|
|
142
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_ADVERT, this._handleCohortAdvert.bind(this));
|
|
143
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN_ACCEPT, this._handleSubscribeAccept.bind(this));
|
|
144
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_READY, this._handleCohortReady.bind(this));
|
|
145
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_AUTHORIZATION_REQUEST, this._handleAuthorizationRequest.bind(this));
|
|
146
|
+
this.protocol.registerMessageHandler(BEACON_COHORT_AGGREGATED_NONCE, this._handleAggregatedNonce.bind(this));
|
|
147
|
+
this.protocol.start();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves the HD key for a specific cohort based on its ID.
|
|
152
|
+
* @param {string} cohortId The ID of the cohort for which to retrieve the key.
|
|
153
|
+
* @returns {HDKey} The HD key for the cohort, or throws an error if not found.
|
|
154
|
+
* @throws {BeaconParticipantError} If the cohort key state is not found for the given cohort ID.
|
|
155
|
+
*/
|
|
156
|
+
public getCohortKey(cohortId: string): HDKey {
|
|
157
|
+
const keyIndex = this.cohortKeyState.get(cohortId);
|
|
158
|
+
if(keyIndex === undefined) {
|
|
159
|
+
throw new BeaconParticipantError(`Cohort key state for cohort ${cohortId} not found.`, 'COHORT_KEY_NOT_FOUND');
|
|
160
|
+
}
|
|
161
|
+
return this.hdKey.deriveChild(keyIndex);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Sets the state of the cohort key for a given cohort ID and key index.
|
|
166
|
+
* @param {string} cohortId The ID of the cohort for which to set the key state.
|
|
167
|
+
* @returns {void}
|
|
168
|
+
*/
|
|
169
|
+
public setCohortKey(cohortId: string): void {
|
|
170
|
+
if(this.cohortKeyState.size > 0) {
|
|
171
|
+
this.beaconKeyIndex = this.cohortKeyState.size + 1;
|
|
172
|
+
}
|
|
173
|
+
if(this.cohortKeyState.has(cohortId)) {
|
|
174
|
+
Logger.warn(`Cohort key state for cohort ${cohortId} already exists. Updating key index.`);
|
|
175
|
+
}
|
|
176
|
+
this.cohortKeyState.set(cohortId, this.beaconKeyIndex);
|
|
177
|
+
Logger.info(`Cohort key state updated. Next beacon key index: ${this.beaconKeyIndex + 1}`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Finalizes the placeholder "__UNSET__" key and assigns it to the provided cohortId.
|
|
182
|
+
* If no "__UNSET__" entry exists, throws an error.
|
|
183
|
+
* If cohortId already exists, logs a warning and does nothing.
|
|
184
|
+
* @param {string} cohortId The ID of the cohort to finalize the unset key for.
|
|
185
|
+
* @throws {BeaconParticipantError} If no "__UNSET__" cohort key state is found.
|
|
186
|
+
* @returns {void}
|
|
187
|
+
*/
|
|
188
|
+
public finalizeUnsetCohortKey(cohortId: string): void {
|
|
189
|
+
const unsetKey = '__UNSET__';
|
|
190
|
+
|
|
191
|
+
if (!this.cohortKeyState.has(unsetKey)) {
|
|
192
|
+
throw new BeaconParticipantError(
|
|
193
|
+
`No '__UNSET__' cohort key to finalize for ${this.did}`,
|
|
194
|
+
'UNSET_KEY_NOT_FOUND'
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.cohortKeyState.has(cohortId)) {
|
|
199
|
+
Logger.warn(`Cohort key state already exists for ${cohortId}. Skipping migration from '__UNSET__'.`);
|
|
200
|
+
this.cohortKeyState.delete(unsetKey);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
this.setCohortKey(cohortId);
|
|
205
|
+
this.cohortKeyState.delete(unsetKey);
|
|
206
|
+
|
|
207
|
+
Logger.info(`Finalized '__UNSET__' CohortKeyState with ${cohortId} for ${this.did}`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Handle subscription acceptance from a coordinator.
|
|
212
|
+
* @param {CohortOptInAcceptMessage} message The message containing the subscription acceptance.
|
|
213
|
+
* @returns {Promise<void>}
|
|
214
|
+
*/
|
|
215
|
+
private async _handleSubscribeAccept(message: Maybe<CohortOptInAcceptMessage>): Promise<void> {
|
|
216
|
+
const subscribeAcceptMessage = BeaconCohortOptInAcceptMessage.fromJSON(message);
|
|
217
|
+
const coordinatorDid = subscribeAcceptMessage.from;
|
|
218
|
+
if (!this.coordinatorDids.includes(coordinatorDid)) {
|
|
219
|
+
this.coordinatorDids.push(coordinatorDid);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Handles a cohort advertisement message.
|
|
225
|
+
* @param {Maybe<BeaconCohortAdvertMessage>} message The cohort advertisement message.
|
|
226
|
+
* @returns {Promise<void>}
|
|
227
|
+
*/
|
|
228
|
+
public async _handleCohortAdvert(message: Maybe<CohortAdvertMessage>): Promise<void> {
|
|
229
|
+
Logger.debug('_handleCohortAdvert', message);
|
|
230
|
+
const cohortAdvertMessage = BeaconCohortAdvertMessage.fromJSON(message);
|
|
231
|
+
Logger.info(`Received new cohort announcement from ${cohortAdvertMessage.from}`, cohortAdvertMessage);
|
|
232
|
+
|
|
233
|
+
const cohortId = cohortAdvertMessage.body?.cohortId;
|
|
234
|
+
if (!cohortId) {
|
|
235
|
+
Logger.warn('Received malformed cohort advert message: missing cohortId', cohortAdvertMessage);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const network = cohortAdvertMessage.body?.network;
|
|
240
|
+
if (!network) {
|
|
241
|
+
Logger.warn('Received malformed cohort advert message: missing network', cohortAdvertMessage);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const minParticipants = cohortAdvertMessage.body?.cohortSize;
|
|
246
|
+
if (!cohortId || !network || !minParticipants) {
|
|
247
|
+
Logger.warn('Received malformed cohort advert message: missing minParticipants', cohortAdvertMessage);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const from = cohortAdvertMessage.from;
|
|
252
|
+
const cohort = new AggregateBeaconCohort(
|
|
253
|
+
{
|
|
254
|
+
network,
|
|
255
|
+
minParticipants,
|
|
256
|
+
id : cohortId,
|
|
257
|
+
coordinatorDid : from,
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
this.cohorts.push(cohort);
|
|
261
|
+
await this.joinCohort(cohort.id, from);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Handles a cohort set message.
|
|
266
|
+
* @param {Maybe<CohortReadyMessage>} message The cohort set message.
|
|
267
|
+
* @returns {Promise<void>}
|
|
268
|
+
*/
|
|
269
|
+
public async _handleCohortReady(message: Maybe<CohortReadyMessage>): Promise<void> {
|
|
270
|
+
const cohortSetMessage = BeaconCohortReadyMessage.fromJSON(message);
|
|
271
|
+
const cohortId = cohortSetMessage.body?.cohortId;
|
|
272
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
273
|
+
if (!cohortId || !cohort) {
|
|
274
|
+
Logger.warn(`Cohort with ID ${cohortId} not found or not joined by participant ${this.did}.`);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.finalizeUnsetCohortKey(cohortId);
|
|
278
|
+
const participantPk = this.getCohortKey(cohortId).publicKey?.toHex();
|
|
279
|
+
if(!participantPk) {
|
|
280
|
+
Logger.error(`Failed to derive public key for cohort ${cohortId}`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const beaconAddress = cohortSetMessage.body?.beaconAddress;
|
|
284
|
+
if(!beaconAddress) {
|
|
285
|
+
Logger.error(`Beacon address not provided in cohort set message for ${cohortId}`);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const cohortKeys = cohortSetMessage.body?.cohortKeys;
|
|
289
|
+
if(!cohortKeys) {
|
|
290
|
+
Logger.error(`Cohort keys not provided in cohort set message for ${cohortId}`);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const keys = cohortKeys.map(key => key.toHex());
|
|
294
|
+
cohort.validateCohort([participantPk], keys, beaconAddress);
|
|
295
|
+
Logger.info(`BeaconParticipant w/ pk ${participantPk} successfully joined cohort ${cohortId} with beacon address ${beaconAddress}.`);
|
|
296
|
+
Logger.info(`Cohort status: ${cohort.status}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Handles an authorization request message.
|
|
301
|
+
* @param {Maybe<CohortAuthorizationRequestMessage>} message The authorization request message.
|
|
302
|
+
* @returns {Promise<void>}
|
|
303
|
+
*/
|
|
304
|
+
public async _handleAuthorizationRequest(message: Maybe<CohortAuthorizationRequestMessage>): Promise<void> {
|
|
305
|
+
const authRequest = BeaconCohortAuthorizationRequestMessage.fromJSON(message);
|
|
306
|
+
const cohort = this.cohorts.find(c => c.id === authRequest.body?.cohortId);
|
|
307
|
+
if (!cohort) {
|
|
308
|
+
Logger.warn(`Authorization request for unknown cohort ${authRequest.body?.cohortId} from ${authRequest.from}`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const id = authRequest.body?.sessionId;
|
|
312
|
+
if (!id) {
|
|
313
|
+
Logger.warn(`Authorization request missing session ID from ${authRequest.from}`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const pendingTx = authRequest.body?.pendingTx;
|
|
317
|
+
if (!pendingTx) {
|
|
318
|
+
Logger.warn(`Authorization request missing pending transaction from ${authRequest.from}`);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const session = new BeaconCohortSigningSession({
|
|
322
|
+
cohort,
|
|
323
|
+
id,
|
|
324
|
+
pendingTx : Transaction.fromHex(pendingTx),
|
|
325
|
+
});
|
|
326
|
+
this.activeSigningSessions.set(session.id, session);
|
|
327
|
+
const nonceContribution = this.generateNonceContribution(cohort, session);
|
|
328
|
+
await this.sendNonceContribution(cohort, nonceContribution, session);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Handles an aggregated nonce message.
|
|
333
|
+
* @param {Maybe<CohortAggregatedNonceMessage>} message The aggregated nonce message.
|
|
334
|
+
* @returns {Promise<void>}
|
|
335
|
+
*/
|
|
336
|
+
public async _handleAggregatedNonce(message: Maybe<CohortAggregatedNonceMessage>): Promise<void> {
|
|
337
|
+
const aggNonceMessage = BeaconCohortAggregatedNonceMessage.fromJSON(message);
|
|
338
|
+
const sessionId = aggNonceMessage.body?.sessionId;
|
|
339
|
+
if (!sessionId) {
|
|
340
|
+
Logger.warn(`Aggregated nonce message missing session ID from ${aggNonceMessage.from}`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const session = this.activeSigningSessions.get(sessionId);
|
|
344
|
+
if (!session) {
|
|
345
|
+
Logger.warn(`Aggregated nonce message received for unknown session ${sessionId}`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const aggregatedNonce = aggNonceMessage.body?.aggregatedNonce;
|
|
349
|
+
if (!aggregatedNonce) {
|
|
350
|
+
Logger.warn(`Aggregated nonce message missing aggregated nonce from ${aggNonceMessage.from}`);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
session.aggregatedNonce = aggregatedNonce;
|
|
354
|
+
const participantSk = this.getCohortKey(session.cohort.id).privateKey;
|
|
355
|
+
if(!participantSk) {
|
|
356
|
+
Logger.error(`Failed to derive secret key for cohort ${session.cohort.id}`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const partialSig = session.generatePartialSignature(participantSk);
|
|
360
|
+
await this.sendPartialSignature(session, partialSig);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Subscribes to a coordinator's messages.
|
|
365
|
+
* @param {string} coordinatorDid The DID of the coordinator to subscribe to.
|
|
366
|
+
* @returns {Promise<void>}
|
|
367
|
+
*/
|
|
368
|
+
public async subscribeToCoordinator(coordinatorDid: string): Promise<any> {
|
|
369
|
+
if(this.coordinatorDids.includes(coordinatorDid)) {
|
|
370
|
+
Logger.info(`Already subscribed to coordinator ${coordinatorDid}`);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const subMessage = new BeaconCohortSubscribeMessage({ to: coordinatorDid, from: this.did });
|
|
374
|
+
return await this.protocol.sendMessage(subMessage, this.did, coordinatorDid);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Joins a cohort with the given ID and coordinator DID.
|
|
379
|
+
* @param {string} cohortId The ID of the cohort to join.
|
|
380
|
+
* @param {string} coordinatorDid The DID of the cohort coordinator.
|
|
381
|
+
* @returns {Promise<void>}
|
|
382
|
+
*/
|
|
383
|
+
public async joinCohort(cohortId: string, coordinatorDid: string): Promise<void> {
|
|
384
|
+
Logger.info(`BeaconParticipant ${this.did} joining cohort ${cohortId} with coordinator ${coordinatorDid}`);
|
|
385
|
+
this.finalizeUnsetCohortKey(cohortId);
|
|
386
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
387
|
+
if (!cohort) {
|
|
388
|
+
Logger.warn(`Cohort with ID ${cohortId} not found.`);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const pk = this.getCohortKey(cohortId).publicKey;
|
|
392
|
+
if(!pk) {
|
|
393
|
+
Logger.error(`Failed to derive public key for cohort ${cohortId} at index ${this.beaconKeyIndex}`);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.setCohortKey(cohortId);
|
|
397
|
+
const optInMessage = new BeaconCohortOptInMessage({
|
|
398
|
+
cohortId,
|
|
399
|
+
participantPk : pk,
|
|
400
|
+
from : this.did,
|
|
401
|
+
to : coordinatorDid,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
await this.protocol.sendMessage(optInMessage, this.did, coordinatorDid);
|
|
405
|
+
cohort.status = COHORT_STATUS.COHORT_OPTED_IN;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Requests a signature for the given cohort and data.
|
|
410
|
+
* @param {string} cohortId The ID of the cohort for which to request a signature.
|
|
411
|
+
* @param {string} data The data for which to request a signature.
|
|
412
|
+
* @returns {Promise<boolean>} Whether the signature request was successful.
|
|
413
|
+
*/
|
|
414
|
+
public async requestCohortSignature(cohortId: string, data: string): Promise<boolean> {
|
|
415
|
+
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
416
|
+
if (!cohort) {
|
|
417
|
+
Logger.warn(`Cohort with ID ${cohortId} not found.`);
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
if(cohort.status !== COHORT_STATUS.COHORT_SET_STATUS) {
|
|
421
|
+
Logger.warn(`Cohort ${cohortId} not in a set state. Current status: ${cohort.status}`);
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
const reqSigMessage = new BeaconCohortRequestSignatureMessage({
|
|
425
|
+
to : cohort.coordinatorDid,
|
|
426
|
+
from : this.did,
|
|
427
|
+
data,
|
|
428
|
+
cohortId
|
|
429
|
+
});
|
|
430
|
+
await this.protocol.sendMessage(reqSigMessage, this.did, cohort.coordinatorDid);
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Generates a nonce contribution for the given cohort and session.
|
|
436
|
+
* @param {AggregateBeaconCohort} cohort The cohort for which to generate the nonce contribution.
|
|
437
|
+
* @param {BeaconCohortSigningSession} session The session for which to generate the nonce contribution.
|
|
438
|
+
* @returns {Promise<string[]>} An array of nonce points in hexadecimal format.
|
|
439
|
+
*/
|
|
440
|
+
public generateNonceContribution(cohort: AggregateBeaconCohort, session: BeaconCohortSigningSession): Uint8Array {
|
|
441
|
+
const cohortKey = this.getCohortKey(cohort.id);
|
|
442
|
+
if (!cohortKey) {
|
|
443
|
+
throw new BeaconParticipantError(
|
|
444
|
+
`Cohort key state not found for cohort ${cohort.id}`,
|
|
445
|
+
'COHORT_KEY_NOT_FOUND', cohortKey
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
const { publicKey, privateKey } = cohortKey;
|
|
449
|
+
if(!publicKey || !privateKey) {
|
|
450
|
+
throw new BeaconParticipantError(
|
|
451
|
+
`Failed to derive public key for cohort ${cohort.id}`,
|
|
452
|
+
'PARTICIPANT_PK_NOT_FOUND', cohortKey
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
session.aggregatedNonce ??= session.generateAggregatedNonce();
|
|
456
|
+
return musig2.nonceGen(publicKey, privateKey, session.aggregatedNonce, cohort.trMerkleRoot).public;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Sends a nonce contribution message to the cohort coordinator.
|
|
461
|
+
* @param {AggregateBeaconCohort} cohort The cohort to which the nonce contribution is sent.
|
|
462
|
+
* @param {Uint8Array} nonceContribution The nonce contribution points in hexadecimal format.
|
|
463
|
+
* @param {BeaconCohortSigningSession} session The session associated with the nonce contribution.
|
|
464
|
+
*/
|
|
465
|
+
public async sendNonceContribution(
|
|
466
|
+
cohort: AggregateBeaconCohort,
|
|
467
|
+
nonceContribution: Uint8Array,
|
|
468
|
+
session: BeaconCohortSigningSession
|
|
469
|
+
): Promise<void> {
|
|
470
|
+
const nonceContributionMessage = BeaconCohortNonceContributionMessage.fromJSON({
|
|
471
|
+
to : cohort.coordinatorDid,
|
|
472
|
+
from : this.did,
|
|
473
|
+
body : {
|
|
474
|
+
sessionId : session.id,
|
|
475
|
+
cohortId : cohort.id,
|
|
476
|
+
nonceContribution
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
await this.protocol.sendMessage(nonceContributionMessage, this.did, cohort.coordinatorDid);
|
|
480
|
+
Logger.info(`Nonce contribution sent for session ${session.id} in cohort ${cohort.id} by participant ${this.did}`);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Sends a partial signature for the given session.
|
|
485
|
+
* @param {BeaconCohortSigningSession} session The session for which the partial signature is sent.
|
|
486
|
+
* @param {Uint8Array} partialSig The partial signature to send.
|
|
487
|
+
* @returns {Promise<void>}
|
|
488
|
+
*/
|
|
489
|
+
public async sendPartialSignature(session: BeaconCohortSigningSession, partialSig: Uint8Array): Promise<void> {
|
|
490
|
+
const sigAuthMessage = new BeaconCohortSignatureAuthorizationMessage({
|
|
491
|
+
to : session.cohort.coordinatorDid,
|
|
492
|
+
from : this.did,
|
|
493
|
+
cohortId : session.cohort.id,
|
|
494
|
+
sessionId : session.id,
|
|
495
|
+
partialSignature : partialSig,
|
|
496
|
+
});
|
|
497
|
+
await this.protocol.sendMessage(sigAuthMessage, this.did, session.cohort.coordinatorDid);
|
|
498
|
+
Logger.info(`Partial signature sent for session ${session.id} in cohort ${session.cohort.id} by participant ${this.did}`);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Initializes a new BeaconParticipant instance.
|
|
503
|
+
* @param {Seed | Mnemonic} ent The secret key used for signing.
|
|
504
|
+
* @param {CommunicationService} protocol The communication protocol used by the participant.
|
|
505
|
+
* @param {string} [name] The name of the participant.
|
|
506
|
+
* @param {string} [did] The decentralized identifier (DID) of the participant.
|
|
507
|
+
* @returns {BeaconParticipant} A new instance of BeaconParticipant.
|
|
508
|
+
*/
|
|
509
|
+
public static initialize(ent: Seed | Mnemonic, protocol: CommunicationService, did: string, name?: string): BeaconParticipant {
|
|
510
|
+
return new BeaconParticipant({ent, protocol, name, did});
|
|
511
|
+
}
|
|
512
|
+
}
|