@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,289 @@
|
|
|
1
|
+
import { Logger } from '@did-btcr2/common';
|
|
2
|
+
import * as musig2 from '@scure/btc-signer/musig2';
|
|
3
|
+
import { Transaction } from 'bitcoinjs-lib';
|
|
4
|
+
import { AggregateBeaconError } from '../../error.js';
|
|
5
|
+
import { AggregateBeaconCohort } from '../cohort/index.js';
|
|
6
|
+
import { BeaconCohortAuthorizationRequestMessage } from '../cohort/messages/sign/authorization-request.js';
|
|
7
|
+
import { SIGNING_SESSION_STATUS, SIGNING_SESSION_STATUS_TYPE } from './status.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert a big-endian byte array into a bigint.
|
|
11
|
+
* @param bytes - The input Uint8Array representing a big-endian integer.
|
|
12
|
+
* @returns The integer value as a bigint.
|
|
13
|
+
*/
|
|
14
|
+
export function bigEndianToInt(bytes: Uint8Array): bigint {
|
|
15
|
+
return bytes.reduce((num, b) => (num << 8n) + BigInt(b), 0n);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Convert a bigint to a big-endian Uint8Array of specified length.
|
|
20
|
+
* @param xInit - The bigint to convert.
|
|
21
|
+
* @param length - The desired length of the output array in bytes.
|
|
22
|
+
* @returns A Uint8Array representing the bigint in big-endian form.
|
|
23
|
+
*/
|
|
24
|
+
export function intToBigEndian(xInit: bigint, length: number): Uint8Array {
|
|
25
|
+
let x = xInit;
|
|
26
|
+
const result = new Uint8Array(length);
|
|
27
|
+
for (let i = length - 1; i >= 0; i--) {
|
|
28
|
+
result[i] = Number(x & 0xffn);
|
|
29
|
+
x >>= 8n;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type PublicKeyHex = string;
|
|
35
|
+
type Nonce = Uint8Array;
|
|
36
|
+
type NonceContributions = Map<PublicKeyHex, Nonce>;
|
|
37
|
+
type PartialSignatures = Map<string, Uint8Array>;
|
|
38
|
+
type ProcessedRequests = Record<string, string>;
|
|
39
|
+
|
|
40
|
+
export interface SigningSession {
|
|
41
|
+
id?: string;
|
|
42
|
+
cohort: AggregateBeaconCohort;
|
|
43
|
+
pendingTx: Transaction;
|
|
44
|
+
nonceContributions?: NonceContributions;
|
|
45
|
+
aggregatedNonce?: Uint8Array;
|
|
46
|
+
partialSignatures?: PartialSignatures;
|
|
47
|
+
signature?: Uint8Array;
|
|
48
|
+
status?: SIGNING_SESSION_STATUS_TYPE;
|
|
49
|
+
processedRequests?: ProcessedRequests;
|
|
50
|
+
nonceSecrets?: bigint;
|
|
51
|
+
}
|
|
52
|
+
export class BeaconCohortSigningSession implements SigningSession {
|
|
53
|
+
/**
|
|
54
|
+
* Unique identifier for the signing session.
|
|
55
|
+
* @type {string}
|
|
56
|
+
*/
|
|
57
|
+
public id: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* DID of the coordinator.
|
|
61
|
+
* @type {AggregateBeaconCohort}
|
|
62
|
+
*/
|
|
63
|
+
public cohort: AggregateBeaconCohort;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Pending transaction to be signed.
|
|
67
|
+
* @type {Transaction}
|
|
68
|
+
*/
|
|
69
|
+
public pendingTx: Transaction;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Map of nonce contributions from participants.
|
|
73
|
+
* @type {Map<PublicKeyHex, Nonce>}
|
|
74
|
+
*/
|
|
75
|
+
public nonceContributions: Map<PublicKeyHex, Nonce> = new Map();
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Aggregated nonce from all participants.
|
|
79
|
+
* @type {Uint8Array}
|
|
80
|
+
*/
|
|
81
|
+
public aggregatedNonce?: Uint8Array;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Map of partial signatures from participants.
|
|
85
|
+
* @type {Map<string, Uint8Array>}
|
|
86
|
+
*/
|
|
87
|
+
public partialSignatures: Map<string, Uint8Array> = new Map();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Final signature for the transaction.
|
|
91
|
+
* @type {Uint8Array}
|
|
92
|
+
*/
|
|
93
|
+
public signature?: Uint8Array;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Current status of the signing session.
|
|
97
|
+
* @type {SIGNING_SESSION_STATUS_TYPE}
|
|
98
|
+
*/
|
|
99
|
+
public status: SIGNING_SESSION_STATUS_TYPE;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Map of processed requests from participants.
|
|
103
|
+
* @type {Record<string, string>}
|
|
104
|
+
*/
|
|
105
|
+
public processedRequests: Record<string, string>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Secrets for nonces contributed by participants.
|
|
109
|
+
* @type {Array<bigint>}
|
|
110
|
+
*/
|
|
111
|
+
public nonceSecrets?: bigint;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Musig2 session for signing operations.
|
|
115
|
+
* @type {musig2.Session}
|
|
116
|
+
*/
|
|
117
|
+
public musig2Session?: musig2.Session;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new instance of BeaconCohortSigningSession.
|
|
121
|
+
* @param {SigningSession} params Parameters to initialize the signing session.
|
|
122
|
+
* @param {Transaction} params.pendingTx The pending transaction to be signed.
|
|
123
|
+
* @param {string} [params.id] Optional unique identifier for the signing session. If not provided, a new UUID will be generated.
|
|
124
|
+
* @param {AggregateBeaconCohort} [params.cohort] The cohort associated with the signing session.
|
|
125
|
+
* @param {Record<string, string>} [params.processedRequests] Map of processed requests from participants.
|
|
126
|
+
* @param {SIGNING_SESSION_STATUS_TYPE} [params.status] The current status of the signing session. Defaults to AWAITING_NONCE_CONTRIBUTIONS.
|
|
127
|
+
*/
|
|
128
|
+
constructor({ id, cohort, pendingTx, processedRequests, status }: SigningSession) {
|
|
129
|
+
this.id = id || crypto.randomUUID();
|
|
130
|
+
this.cohort = cohort;
|
|
131
|
+
this.pendingTx = pendingTx;
|
|
132
|
+
this.processedRequests = processedRequests || {};
|
|
133
|
+
this.status = status || SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gets the authorization request message for a participant.
|
|
138
|
+
* @param {string} to The public key of the participant to whom the request is sent.
|
|
139
|
+
* @param {string} from The public key of the participant sending the request.
|
|
140
|
+
* @returns {AuthorizationRequest} The authorization request message.
|
|
141
|
+
*/
|
|
142
|
+
public getAuthorizationRequest(to: string, from: string): BeaconCohortAuthorizationRequestMessage {
|
|
143
|
+
const txHex = this.pendingTx instanceof Transaction ? this.pendingTx?.toHex() : this.pendingTx;
|
|
144
|
+
return new BeaconCohortAuthorizationRequestMessage({
|
|
145
|
+
to,
|
|
146
|
+
from,
|
|
147
|
+
sessionId : this.id,
|
|
148
|
+
cohortId : this.cohort?.id,
|
|
149
|
+
pendingTx : txHex,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Adds a nonce contribution from a participant to the session.
|
|
155
|
+
* @param {string} from The public key of the participant contributing the nonce.
|
|
156
|
+
* @param {Array<string>} nonceContribution The nonce contribution from the participant.
|
|
157
|
+
* @throws {Error} If the session is not awaiting nonce contributions or if the contribution is invalid.
|
|
158
|
+
*/
|
|
159
|
+
public addNonceContribution(from: string, nonceContribution: Uint8Array): void {
|
|
160
|
+
if(this.status !== SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS) {
|
|
161
|
+
throw new AggregateBeaconError(`Nonce contributions already received. Current status: ${this.status}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if(nonceContribution.length !== 2) {
|
|
165
|
+
throw new AggregateBeaconError(`Invalid nonce contribution. Expected 2 points, received ${nonceContribution.length}.`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (this.nonceContributions.get(from)) {
|
|
169
|
+
Logger.warn(`WARNING: Nonce contribution already received from ${from}.`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this.nonceContributions.set(from, nonceContribution);
|
|
173
|
+
|
|
174
|
+
if(this.nonceContributions.size === this.cohort?.participants.length) {
|
|
175
|
+
this.status = SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Generates the aggregated nonce from all nonce contributions for the session.
|
|
181
|
+
* @returns {Uint8Array} The aggregated nonce.
|
|
182
|
+
* @throws {AggregateBeaconError} If not all nonce contributions have been received.
|
|
183
|
+
*/
|
|
184
|
+
public generateAggregatedNonce(): Uint8Array {
|
|
185
|
+
if(this.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
|
|
186
|
+
const missing = this.cohort?.participants.length - this.nonceContributions.size;
|
|
187
|
+
throw new AggregateBeaconError(
|
|
188
|
+
`Missing ${missing} nonce contributions. ` +
|
|
189
|
+
`Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. ` +
|
|
190
|
+
`Current status: ${this.status}`,
|
|
191
|
+
'NONCE_CONTRIBUTION_ERROR', this.json()
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const sortedPubkeys = musig2.sortKeys(this.cohort.cohortKeys);
|
|
195
|
+
const keyAggContext = musig2.keyAggregate(sortedPubkeys);
|
|
196
|
+
const aggPubkey = musig2.keyAggExport(keyAggContext);
|
|
197
|
+
this.aggregatedNonce = musig2.nonceAggregate(this.cohort.cohortKeys.map(key => musig2.nonceGen(key, undefined, aggPubkey, this.cohort.trMerkleRoot).public));
|
|
198
|
+
this.musig2Session = new musig2.Session(this.aggregatedNonce, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
199
|
+
return this.aggregatedNonce;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Adds a partial signature from a participant to the session.
|
|
204
|
+
* @param {string} from The public key of the participant contributing the partial signature.
|
|
205
|
+
* @param {Uint8Array} partialSignature The partial signature from the participant.
|
|
206
|
+
*/
|
|
207
|
+
public addPartialSignature(from: string, partialSignature: Uint8Array): void {
|
|
208
|
+
if(this.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
|
|
209
|
+
throw new AggregateBeaconError(`Partial signatures not expected. Current status: ${this.status}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if(this.partialSignatures.get(from)) {
|
|
213
|
+
Logger.warn(`WARNING: Partial signature already received from ${from}.`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
this.partialSignatures.set(from, partialSignature);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Generates the final signature from all partial signatures.
|
|
221
|
+
* @returns {Uint8Array} The final aggregated signature.
|
|
222
|
+
*/
|
|
223
|
+
public async generateFinalSignature(): Promise<Uint8Array> {
|
|
224
|
+
if(this.status !== SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
|
|
225
|
+
throw new AggregateBeaconError(`Partial signatures not received. Current status: ${this.status}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const inputIdx = (this.pendingTx?.ins?.length || 0) - 1;
|
|
229
|
+
if (inputIdx < 0) {
|
|
230
|
+
throw new AggregateBeaconError('No inputs in the pending transaction to sign.');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const prevoutScript = this.pendingTx?.ins[inputIdx].script;
|
|
234
|
+
if (!prevoutScript) {
|
|
235
|
+
throw new AggregateBeaconError('Previous output script is missing for the input to sign.');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const sigSum = [...this.partialSignatures.values()].reduce((sum, sig) => sum + bigEndianToInt(sig), 0n);
|
|
239
|
+
Logger.info(`Aggregated Signature computed: ${sigSum}`);
|
|
240
|
+
|
|
241
|
+
this.aggregatedNonce ??= this.generateAggregatedNonce();
|
|
242
|
+
|
|
243
|
+
const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
244
|
+
this.signature = session.partialSigAgg([...this.partialSignatures.values()]);
|
|
245
|
+
|
|
246
|
+
return this.signature;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Generates a partial signature for the session using the participant's secret key.
|
|
251
|
+
* @param {Uint8Array} participantSk The secret key of the participant.
|
|
252
|
+
* @returns {Uint8Array} The partial signature generated by the participant.
|
|
253
|
+
*/
|
|
254
|
+
public generatePartialSignature(participantSk: Uint8Array): Uint8Array {
|
|
255
|
+
if (!this.aggregatedNonce) {
|
|
256
|
+
throw new AggregateBeaconError('Aggregated nonce is not available. Please generate it first.');
|
|
257
|
+
}
|
|
258
|
+
const sigHash = this.pendingTx?.hashForSignature(0, this.pendingTx?.ins[0].script, Transaction.SIGHASH_DEFAULT);
|
|
259
|
+
if(!sigHash) {
|
|
260
|
+
throw new AggregateBeaconError('Signature hash is not available. Please ensure the transaction is properly set up.');
|
|
261
|
+
}
|
|
262
|
+
const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
263
|
+
return session.sign(this.aggregatedNonce, participantSk);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Converts the signing session instance to a JSON object representation.
|
|
268
|
+
* @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
|
|
269
|
+
*/
|
|
270
|
+
public json(): BeaconCohortSigningSession {
|
|
271
|
+
return Object.json(this) as BeaconCohortSigningSession;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Checks if the signing session is a completed state.
|
|
276
|
+
* @returns {boolean} True if the session is complete, false otherwise.
|
|
277
|
+
*/
|
|
278
|
+
public isComplete(): boolean {
|
|
279
|
+
return this.status === SIGNING_SESSION_STATUS.SIGNATURE_COMPLETE;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Checks if the signing session is in a failed state.
|
|
284
|
+
* @returns {boolean} True if the session has failed, false otherwise.
|
|
285
|
+
*/
|
|
286
|
+
public isFailed(): boolean {
|
|
287
|
+
return this.status === SIGNING_SESSION_STATUS.FAILED;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SIGNING_SESSION_STATUS_TYPE =
|
|
2
|
+
| 'AWAITING_NONCE_CONTRIBUTIONS'
|
|
3
|
+
| 'NONCE_CONTRIBUTION_SENT'
|
|
4
|
+
| 'NONCE_CONTRIBUTIONS_RECEIVED'
|
|
5
|
+
| 'AWAITING_PARTIAL_SIGNATURES'
|
|
6
|
+
| 'PARTIAL_SIGNATURES_RECEIVED'
|
|
7
|
+
| 'SIGNATURE_COMPLETE'
|
|
8
|
+
| 'FAILED'
|
|
9
|
+
|
|
10
|
+
export enum SIGNING_SESSION_STATUS {
|
|
11
|
+
AWAITING_NONCE_CONTRIBUTIONS = 'AWAITING_NONCE_CONTRIBUTIONS',
|
|
12
|
+
NONCE_CONTRIBUTION_SENT = 'NONCE_CONTRIBUTION_SENT',
|
|
13
|
+
NONCE_CONTRIBUTIONS_RECEIVED = 'NONCE_CONTRIBUTIONS_RECEIVED',
|
|
14
|
+
AWAITING_PARTIAL_SIGNATURES = 'AWAITING_PARTIAL_SIGNATURES',
|
|
15
|
+
PARTIAL_SIGNATURES_RECEIVED = 'PARTIAL_SIGNATURES_RECEIVED',
|
|
16
|
+
SIGNATURE_COMPLETE = 'SIGNATURE_COMPLETE',
|
|
17
|
+
FAILED = 'FAILED',
|
|
18
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { MethodError, DidUpdateInvocation, DidUpdatePayload } from '@did-btcr2/common';
|
|
2
|
-
import { DidServiceEndpoint } from '@web5/dids';
|
|
3
|
-
import { Beacon } from '../../interfaces/beacon.js';
|
|
4
|
-
import { BeaconService, BeaconSignal } from '../../interfaces/ibeacon.js';
|
|
5
1
|
import { RawTransactionV2 } from '@did-btcr2/bitcoin';
|
|
6
|
-
import {
|
|
2
|
+
import { DidUpdateInvocation, DidUpdatePayload, MethodError } from '@did-btcr2/common';
|
|
3
|
+
import { DidServiceEndpoint } from '@web5/dids';
|
|
4
|
+
import { Beacon, BeaconService, BeaconSignal } from '../../interfaces/beacon.js';
|
|
5
|
+
import { BeaconSidecarData, CIDAggregateSidecar, SignalsMetadata } from '../../utils/types.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#cidaggregate-beacon | 5.2 CIDAggregate Beacon}.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { MethodError } from '@did-btcr2/common';
|
|
2
|
+
|
|
3
|
+
export class BeaconError extends MethodError {
|
|
4
|
+
constructor(message: string, type: string = 'BeaconError', data?: Record<string, any>) {
|
|
5
|
+
super(message, type, data);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class BeaconCoordinatorError extends MethodError {
|
|
10
|
+
constructor(message: string, type: string = 'BeaconCoordinatorError', data?: Record<string, any>) {
|
|
11
|
+
super(message, type, data);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class BeaconParticipantError extends MethodError {
|
|
16
|
+
constructor(message: string, type: string = 'BeaconParticipantError', data?: Record<string, any>) {
|
|
17
|
+
super(message, type, data);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export class SingletonBeaconError extends MethodError {
|
|
23
|
+
constructor(message: string, type: string = 'SingletonBeaconError', data?: Record<string, any>) {
|
|
24
|
+
super(message, type, data);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class AggregateBeaconError extends MethodError {
|
|
29
|
+
constructor(message: string, type: string = 'AggregateBeaconError', data?: Record<string, any>) {
|
|
30
|
+
super(message, type, data);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class CIDAggregateBeaconError extends MethodError {
|
|
35
|
+
constructor(message: string, type: string = 'CIDAggregateBeaconError', data?: Record<string, any>) {
|
|
36
|
+
super(message, type, data);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class SMTAggregateBeaconError extends MethodError {
|
|
41
|
+
constructor(message: string, type: string = 'SMTAggregateBeaconError', data?: Record<string, any>) {
|
|
42
|
+
super(message, type, data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MethodError } from '@did-btcr2/common';
|
|
2
|
-
import { Beacon } from '../../interfaces/beacon.js';
|
|
3
|
-
import {
|
|
4
|
-
import { CIDAggregateSidecar, SidecarData, SMTAggregateSidecar } from '../../types/crud.js';
|
|
2
|
+
import { Beacon, BeaconService } from '../../interfaces/beacon.js';
|
|
3
|
+
import { CIDAggregateSidecar, SidecarData, SMTAggregateSidecar } from '../../utils/types.js';
|
|
5
4
|
import { CIDAggregateBeacon } from './cid-aggregate.js';
|
|
6
5
|
import { SingletonBeacon } from './singleton.js';
|
|
7
6
|
import { SMTAggregateBeacon } from './smt-aggregate.js';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AddressUtxo, BitcoinNetworkConnection, RawTransactionRest, RawTransactionV2, TxOut, Vout } from '@did-btcr2/bitcoin';
|
|
2
2
|
import { DidUpdatePayload, INVALID_SIDECAR_DATA, LATE_PUBLISHING_ERROR, SingletonBeaconError } from '@did-btcr2/common';
|
|
3
|
+
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
4
|
+
import { Kms, Signer } from '@did-btcr2/kms';
|
|
3
5
|
import { opcodes, Psbt, script } from 'bitcoinjs-lib';
|
|
4
6
|
import { base58btc } from 'multiformats/bases/base58';
|
|
5
|
-
import { Beacon } from '../../interfaces/beacon.js';
|
|
6
|
-
import {
|
|
7
|
-
import { BeaconSidecarData, Metadata, SignalsMetadata, SingletonSidecar } from '../../types/crud.js';
|
|
7
|
+
import { Beacon, BeaconService, BeaconSignal } from '../../interfaces/beacon.js';
|
|
8
|
+
import { BeaconSidecarData, Metadata, SignalsMetadata, SingletonSidecar } from '../../utils/types.js';
|
|
8
9
|
import { Appendix } from '../../utils/appendix.js';
|
|
9
|
-
import {
|
|
10
|
+
import { Identifier } from '../identifier.js';
|
|
10
11
|
|
|
11
12
|
const bitcoin = new BitcoinNetworkConnection();
|
|
12
13
|
|
|
@@ -219,13 +220,14 @@ export class SingletonBeacon extends Beacon {
|
|
|
219
220
|
|
|
220
221
|
// 6. Retrieve the cryptographic material, e.g private key or signing capability, associated with the bitcoinAddress
|
|
221
222
|
// or service. How this is done is left to the implementer.
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
223
|
+
const components = Identifier.decode(this.service.id);
|
|
224
|
+
const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
|
|
225
|
+
const keyPair = Kms.getKey(keyUri as string);
|
|
226
|
+
if (!keyPair) {
|
|
225
227
|
throw new Error('Key pair not found.');
|
|
226
228
|
}
|
|
227
229
|
|
|
228
|
-
const signer = new Signer({
|
|
230
|
+
const signer = new Signer({ keyPair, network: bitcoin.network.name });
|
|
229
231
|
|
|
230
232
|
// 7. Sign the spendTx.
|
|
231
233
|
const signedTx = spendTx.signInput(0, signer)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { MethodError, DidUpdatePayload } from '@did-btcr2/common';
|
|
2
|
-
import { DidServiceEndpoint } from '@web5/dids';
|
|
3
|
-
import { Beacon } from '../../interfaces/beacon.js';
|
|
4
|
-
import { BeaconService, BeaconSignal } from '../../interfaces/ibeacon.js';
|
|
5
1
|
import { RawTransactionV2 } from '@did-btcr2/bitcoin';
|
|
6
|
-
import {
|
|
2
|
+
import { DidUpdatePayload, MethodError } from '@did-btcr2/common';
|
|
3
|
+
import { DidServiceEndpoint } from '@web5/dids';
|
|
4
|
+
import { Beacon, BeaconService, BeaconSignal } from '../../interfaces/beacon.js';
|
|
5
|
+
import { BeaconSidecarData, SignalsMetadata, SMTAggregateSidecar } from '../../utils/types.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* TODO: Finish implementation
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DidMethodError, KeyBytes, Maybe, MethodError } from '@did-btcr2/common';
|
|
2
2
|
import { DidService } from '@web5/dids';
|
|
3
3
|
import { networks, payments } from 'bitcoinjs-lib';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { BeaconService, BeaconServiceAddress } from '../../interfaces/beacon.js';
|
|
5
|
+
import { Appendix } from '../../utils/appendix.js';
|
|
6
|
+
import { DidDocument } from '../../utils/did-document.js';
|
|
7
|
+
import { BeaconFactory } from './factory.js';
|
|
8
8
|
export interface GenerateBeaconParams {
|
|
9
9
|
identifier: string;
|
|
10
10
|
publicKey: KeyBytes;
|
package/src/core/crud/read.ts
CHANGED
|
@@ -27,17 +27,18 @@ import { Cryptosuite, DataIntegrityProof, SchnorrMultikey } from '@did-btcr2/cry
|
|
|
27
27
|
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
28
28
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
29
29
|
import { DidBtcr2 } from '../../did-btcr2.js';
|
|
30
|
+
import { BeaconService, BeaconServiceAddress, BeaconSignal } from '../../interfaces/beacon.js';
|
|
30
31
|
import { DidResolutionOptions } from '../../interfaces/crud.js';
|
|
31
|
-
import {
|
|
32
|
+
import { Appendix } from '../../utils/appendix.js';
|
|
33
|
+
import { DidDocument } from '../../utils/did-document.js';
|
|
32
34
|
import {
|
|
33
35
|
CIDAggregateSidecar,
|
|
34
36
|
SidecarData,
|
|
35
37
|
SignalsMetadata
|
|
36
|
-
} from '../../types
|
|
37
|
-
import { Appendix, DidComponents } from '../../utils/appendix.js';
|
|
38
|
-
import { BeaconUtils } from '../../utils/beacons.js';
|
|
39
|
-
import { DidDocument } from '../../utils/did-document.js';
|
|
38
|
+
} from '../../utils/types.js';
|
|
40
39
|
import { BeaconFactory } from '../beacon/factory.js';
|
|
40
|
+
import { BeaconUtils } from '../beacon/utils.js';
|
|
41
|
+
import { DidComponents } from '../identifier.js';
|
|
41
42
|
|
|
42
43
|
export type FindNextSignalsRestParams = {
|
|
43
44
|
connection: BitcoinRestClient;
|
|
@@ -905,17 +906,7 @@ export class Resolve {
|
|
|
905
906
|
|
|
906
907
|
// Construct a new Multikey.
|
|
907
908
|
const multikey = SchnorrMultikey.fromPublicKeyMultibase({ id: `#${id}`, controller, publicKeyMultibase });
|
|
908
|
-
// Logger.warn('// TODO: applyDidUpdate - Refactor Multikey to accept pub/priv bytes => Pub/PrivKey => KeyPair.');
|
|
909
|
-
|
|
910
909
|
const cryptosuite = new Cryptosuite({ cryptosuite: 'bip340-jcs-2025', multikey });
|
|
911
|
-
// Logger.warn('// TODO: applyDidUpdate - Refactor Cryptosuite to default to RDFC.');
|
|
912
|
-
|
|
913
|
-
// 5. Set expectedProofPurpose to capabilityInvocation.
|
|
914
|
-
const expectedPurpose = 'capabilityInvocation';
|
|
915
|
-
|
|
916
|
-
// 6. Set mediaType to ????
|
|
917
|
-
// const mediaType = 'application/json';
|
|
918
|
-
// Logger.warn('// TODO: applyDidUpdate - is this just application/json?');
|
|
919
910
|
|
|
920
911
|
// 7. Set documentBytes to the bytes representation of update.
|
|
921
912
|
const documentBytes = await JSON.canonicalization.canonicalize(update);
|
|
@@ -923,7 +914,7 @@ export class Resolve {
|
|
|
923
914
|
// 8. Set verificationResult to the result of passing mediaType, documentBytes, cryptosuite, and
|
|
924
915
|
// expectedProofPurpose into the Verify Proof algorithm defined in the VC Data Integrity specification.
|
|
925
916
|
const diProof = new DataIntegrityProof(cryptosuite);
|
|
926
|
-
const verificationResult = await diProof.verifyProof({ document: documentBytes, expectedPurpose });
|
|
917
|
+
const verificationResult = await diProof.verifyProof({ document: documentBytes, expectedPurpose: 'capabilityInvocation' });
|
|
927
918
|
|
|
928
919
|
// 9. If verificationResult.verified equals False, MUST raise a invalidUpdateProof exception.
|
|
929
920
|
if (!verificationResult.verified) {
|
package/src/core/crud/update.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BTCR2_DID_UPDATE_PAYLOAD_CONTEXT,
|
|
3
|
-
MethodError,
|
|
4
3
|
DidUpdateInvocation,
|
|
5
4
|
DidUpdatePayload,
|
|
6
5
|
INVALID_DID_DOCUMENT,
|
|
7
6
|
INVALID_DID_UPDATE,
|
|
8
7
|
INVALID_PUBLIC_KEY_TYPE,
|
|
9
8
|
Logger,
|
|
9
|
+
MethodError,
|
|
10
10
|
NOT_FOUND,
|
|
11
11
|
PatchOperation,
|
|
12
12
|
ProofOptions
|
|
13
13
|
} from '@did-btcr2/common';
|
|
14
14
|
import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
15
|
-
import { SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
|
|
15
|
+
import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
|
|
16
|
+
import { Kms } from '@did-btcr2/kms';
|
|
16
17
|
import type { DidService } from '@web5/dids';
|
|
17
|
-
import { BeaconService } from '../../interfaces/
|
|
18
|
-
import { SignalsMetadata } from '../../types/crud.js';
|
|
18
|
+
import { BeaconService } from '../../interfaces/beacon.js';
|
|
19
19
|
import { Appendix } from '../../utils/appendix.js';
|
|
20
20
|
import { DidDocument, DidVerificationMethod } from '../../utils/did-document.js';
|
|
21
|
+
import { SignalsMetadata } from '../../utils/types.js';
|
|
21
22
|
import { BeaconFactory } from '../beacon/factory.js';
|
|
22
|
-
import {
|
|
23
|
+
import { Identifier } from '../identifier.js';
|
|
23
24
|
|
|
24
25
|
export interface ConstructUpdateParams {
|
|
25
26
|
identifier: string;
|
|
@@ -160,28 +161,33 @@ export class Update {
|
|
|
160
161
|
|
|
161
162
|
// 1. Set privateKeyBytes to the result of retrieving the private key bytes
|
|
162
163
|
// associated with the verificationMethod value.
|
|
164
|
+
// 1.1 Let id be the fragment portion of verificationMethod.id.
|
|
163
165
|
const id = fullId.slice(fullId.indexOf('#'));
|
|
164
|
-
const multikey = !secretKeyMultibase
|
|
165
|
-
// 1.1 Compute the keyUri and check if the key is in the keystore
|
|
166
|
-
? await KeyManager.getKeyPair(fullId)
|
|
167
|
-
// 1.2 If not, use the secretKeyMultibase from the verificationMethod
|
|
168
|
-
: SchnorrMultikey
|
|
169
|
-
.create({
|
|
170
|
-
id,
|
|
171
|
-
controller,
|
|
172
|
-
keys : new SchnorrKeyPair({
|
|
173
|
-
secretKey : Secp256k1SecretKey.decode(secretKeyMultibase)
|
|
174
|
-
})
|
|
175
|
-
});
|
|
176
166
|
|
|
177
|
-
// 1.
|
|
178
|
-
|
|
167
|
+
// 1.2 Retrieve the key pair from the KMS or from the secretKeyMultibase
|
|
168
|
+
const components = Identifier.decode(id);
|
|
169
|
+
const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
|
|
170
|
+
const keys = secretKeyMultibase
|
|
171
|
+
? new SchnorrKeyPair({ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase) })
|
|
172
|
+
: await Kms.getKey(keyUri as string);
|
|
173
|
+
if (!keys) {
|
|
179
174
|
throw new MethodError(
|
|
180
175
|
'No privateKey found in kms or vm',
|
|
181
176
|
NOT_FOUND, verificationMethod
|
|
182
177
|
);
|
|
183
178
|
}
|
|
184
179
|
|
|
180
|
+
// 1.3 Set multikey to the result of passing verificationMethod and privateKeyBytes into the Multikey Creation algorithm.
|
|
181
|
+
const multikey = SchnorrMultikey.create({ id, controller, keys });
|
|
182
|
+
|
|
183
|
+
// 1.4 If the privateKey is not found, throw an error
|
|
184
|
+
if (!multikey) {
|
|
185
|
+
throw new MethodError(
|
|
186
|
+
'Failed to create multikey from verification method',
|
|
187
|
+
'MULTKEY_CREATE_FAILED', verificationMethod
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
185
191
|
// 2. Set rootCapability to the result of passing Identifier into the Derive Root Capability from did:btcr2
|
|
186
192
|
// Identifier algorithm.
|
|
187
193
|
const rootCapability = Appendix.deriveRootCapability(identifier);
|
|
@@ -193,7 +199,6 @@ export class Update {
|
|
|
193
199
|
// 7. Set proofOptions.proofPurpose to capabilityInvocation.
|
|
194
200
|
// 8. Set proofOptions.capability to rootCapability.id.
|
|
195
201
|
// 9. Set proofOptions.capabilityAction to Write.
|
|
196
|
-
// TODO: Wonder if we actually need this. Arent we always writing?
|
|
197
202
|
const options: ProofOptions = {
|
|
198
203
|
cryptosuite,
|
|
199
204
|
type : 'DataIntegrityProof',
|
|
@@ -207,8 +212,6 @@ export class Update {
|
|
|
207
212
|
// Integrity specification passing in proofOptions.
|
|
208
213
|
const diproof = multikey.toCryptosuite(cryptosuite).toDataIntegrityProof();
|
|
209
214
|
|
|
210
|
-
// TODO: 11. need to set up the proof instantiation such that it can resolve / dereference the root capability. This is deterministic from the DID.
|
|
211
|
-
|
|
212
215
|
// 12. Set didUpdateInvocation to the result of executing the Add Proof algorithm from VC Data Integrity passing
|
|
213
216
|
// didUpdatePayload as the input document, cryptosuite, and the set of proofOptions.
|
|
214
217
|
// 13. Return didUpdateInvocation.
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
import { BitcoinNetworkNames,
|
|
1
|
+
import { BitcoinNetworkNames, Bytes, IdentifierTypes, INVALID_DID, METHOD_NOT_SUPPORTED, MethodError } from '@did-btcr2/common';
|
|
2
2
|
import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
3
|
import { bech32m } from '@scure/base';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Components of a did:btcr2 identifier.
|
|
7
|
+
* @interface DidComponents
|
|
8
|
+
* @property {string} hrp The human-readable part of the Bech32m encoding.
|
|
9
|
+
* @property {string} idType Identifier type (key or external).
|
|
10
|
+
* @property {number} version Identifier version.
|
|
11
|
+
* @property {string | number} network Bitcoin network name or number.
|
|
12
|
+
* @property {Bytes} genesisBytes Public key or an intermediate document bytes.
|
|
13
|
+
*/
|
|
14
|
+
export interface DidComponents {
|
|
15
|
+
hrp: string;
|
|
16
|
+
idType: string;
|
|
17
|
+
version: number;
|
|
18
|
+
network: string;
|
|
19
|
+
genesisBytes: Bytes;
|
|
20
|
+
};
|
|
5
21
|
|
|
6
22
|
/**
|
|
7
23
|
* Implements {@link https://dcdpr.github.io/did-btcr2/#syntax | 3 Syntax}.
|
|
@@ -25,7 +41,7 @@ export class Identifier {
|
|
|
25
41
|
* - a key-value representing a secp256k1 public key; or
|
|
26
42
|
* - a hash-value representing the hash of an initiating external DID document.
|
|
27
43
|
*
|
|
28
|
-
* @param {
|
|
44
|
+
* @param {DidComponents} params See {@link DidComponents} for details.
|
|
29
45
|
* @param {IdentifierTypes} params.idType Identifier type (key or external).
|
|
30
46
|
* @param {string} params.network Bitcoin network name.
|
|
31
47
|
* @param {number} params.version Identifier version.
|
|
@@ -35,7 +51,7 @@ export class Identifier {
|
|
|
35
51
|
public static encode({ idType, version, network, genesisBytes }: {
|
|
36
52
|
idType: string;
|
|
37
53
|
version: number;
|
|
38
|
-
network: string
|
|
54
|
+
network: string;
|
|
39
55
|
genesisBytes: Bytes;
|
|
40
56
|
}): string {
|
|
41
57
|
// 1. If idType is not a valid value per above, raise invalidDid error.
|
|
@@ -267,10 +283,24 @@ export class Identifier {
|
|
|
267
283
|
const did = this.encode({
|
|
268
284
|
idType : IdentifierTypes.KEY,
|
|
269
285
|
version : 1,
|
|
270
|
-
network :
|
|
286
|
+
network : 'bitcoin',
|
|
271
287
|
genesisBytes : keys.publicKey.compressed
|
|
272
288
|
});
|
|
273
289
|
|
|
274
290
|
return { keys, identifier: { controller: did, id: '#initialKey'} };
|
|
275
291
|
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Validates a did:btcr2 identifier.
|
|
295
|
+
* @param {string} identifier The did:btcr2 identifier to validate.
|
|
296
|
+
* @returns {boolean} True if the identifier is valid, false otherwise.
|
|
297
|
+
*/
|
|
298
|
+
static isValid(identifier: string): boolean {
|
|
299
|
+
try {
|
|
300
|
+
this.decode(identifier);
|
|
301
|
+
return true;
|
|
302
|
+
} catch {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
276
306
|
}
|