@did-btcr2/method 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -236
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +27665 -23764
- package/dist/browser.mjs +27665 -23764
- package/dist/cjs/index.js +2661 -2239
- package/dist/esm/core/aggregation/cohort.js +178 -0
- package/dist/esm/core/aggregation/cohort.js.map +1 -0
- package/dist/esm/core/aggregation/errors.js +22 -0
- package/dist/esm/core/aggregation/errors.js.map +1 -0
- package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
- package/dist/esm/core/aggregation/messages/base.js.map +1 -0
- package/dist/esm/core/aggregation/messages/constants.js +26 -0
- package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
- package/dist/esm/core/aggregation/messages/factories.js +113 -0
- package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
- package/dist/esm/core/aggregation/messages/guards.js +37 -0
- package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
- package/dist/esm/core/aggregation/messages/index.js +5 -0
- package/dist/esm/core/aggregation/messages/index.js.map +1 -0
- package/dist/esm/core/aggregation/participant.js +376 -0
- package/dist/esm/core/aggregation/participant.js.map +1 -0
- package/dist/esm/core/aggregation/phases.js +39 -0
- package/dist/esm/core/aggregation/phases.js.map +1 -0
- package/dist/esm/core/aggregation/runner/events.js +2 -0
- package/dist/esm/core/aggregation/runner/events.js.map +1 -0
- package/dist/esm/core/aggregation/runner/index.js +5 -0
- package/dist/esm/core/aggregation/runner/index.js.map +1 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js +286 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
- package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
- package/dist/esm/core/aggregation/service.js +416 -0
- package/dist/esm/core/aggregation/service.js.map +1 -0
- package/dist/esm/core/aggregation/signing-session.js +133 -0
- package/dist/esm/core/aggregation/signing-session.js.map +1 -0
- package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
- package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
- package/dist/esm/core/aggregation/transport/error.js +12 -0
- package/dist/esm/core/aggregation/transport/error.js.map +1 -0
- package/dist/esm/core/aggregation/transport/factory.js +20 -0
- package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
- package/dist/esm/core/aggregation/transport/index.js +6 -0
- package/dist/esm/core/aggregation/transport/index.js.map +1 -0
- package/dist/esm/core/aggregation/transport/nostr.js +262 -0
- package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
- package/dist/esm/core/aggregation/transport/transport.js +2 -0
- package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
- package/dist/esm/core/beacon/beacon.js +80 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +15 -56
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +0 -10
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/fee-estimator.js +30 -0
- package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
- package/dist/esm/core/beacon/singleton-beacon.js +10 -53
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +85 -9
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +13 -0
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolver.js +9 -0
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/esm/core/updater.js +269 -0
- package/dist/esm/core/updater.js.map +1 -0
- package/dist/esm/did-btcr2.js +30 -42
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +16 -25
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/aggregation/cohort.d.ts +94 -0
- package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
- package/dist/types/core/aggregation/errors.d.ts +14 -0
- package/dist/types/core/aggregation/errors.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
- package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
- package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
- package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
- package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/index.d.ts +5 -0
- package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/participant.d.ts +101 -0
- package/dist/types/core/aggregation/participant.d.ts.map +1 -0
- package/dist/types/core/aggregation/phases.d.ts +49 -0
- package/dist/types/core/aggregation/phases.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/events.d.ts +89 -0
- package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/index.d.ts +5 -0
- package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +111 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
- package/dist/types/core/aggregation/service.d.ts +112 -0
- package/dist/types/core/aggregation/service.d.ts.map +1 -0
- package/dist/types/core/aggregation/signing-session.d.ts +69 -0
- package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
- package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
- package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts +6 -0
- package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
- package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
- package/dist/types/core/beacon/beacon.d.ts +37 -2
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +0 -6
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
- package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
- package/dist/types/core/beacon/interfaces.d.ts +8 -0
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +8 -0
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +2 -2
- package/dist/types/core/resolver.d.ts +11 -1
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts +178 -0
- package/dist/types/core/updater.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +23 -23
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -25
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +31 -30
- package/src/core/aggregation/cohort.ts +247 -0
- package/src/core/aggregation/errors.ts +25 -0
- package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
- package/src/core/aggregation/messages/constants.ts +28 -0
- package/src/core/aggregation/messages/factories.ts +240 -0
- package/src/core/aggregation/messages/guards.ts +55 -0
- package/src/core/aggregation/messages/index.ts +4 -0
- package/src/core/aggregation/participant.ts +510 -0
- package/src/core/aggregation/phases.ts +82 -0
- package/src/core/aggregation/runner/events.ts +77 -0
- package/src/core/aggregation/runner/index.ts +4 -0
- package/src/core/aggregation/runner/participant-runner.ts +364 -0
- package/src/core/aggregation/runner/service-runner.ts +365 -0
- package/src/core/aggregation/runner/typed-emitter.ts +87 -0
- package/src/core/aggregation/service.ts +547 -0
- package/src/core/aggregation/signing-session.ts +209 -0
- package/src/core/aggregation/transport/didcomm.ts +42 -0
- package/src/core/aggregation/transport/error.ts +13 -0
- package/src/core/aggregation/transport/factory.ts +29 -0
- package/src/core/aggregation/transport/index.ts +5 -0
- package/src/core/aggregation/transport/nostr.ts +333 -0
- package/src/core/aggregation/transport/transport.ts +46 -0
- package/src/core/beacon/beacon.ts +122 -2
- package/src/core/beacon/cas-beacon.ts +28 -76
- package/src/core/beacon/error.ts +0 -12
- package/src/core/beacon/fee-estimator.ts +52 -0
- package/src/core/beacon/interfaces.ts +10 -1
- package/src/core/beacon/singleton-beacon.ts +14 -75
- package/src/core/beacon/smt-beacon.ts +109 -11
- package/src/core/identifier.ts +17 -0
- package/src/core/interfaces.ts +2 -2
- package/src/core/resolver.ts +25 -2
- package/src/core/updater.ts +415 -0
- package/src/did-btcr2.ts +36 -66
- package/src/index.ts +17 -30
- package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
- package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
- package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
- package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
- package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/participant.js +0 -435
- package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
- package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
- package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
- package/dist/esm/core/update.js +0 -112
- package/dist/esm/core/update.js.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
- package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
- package/dist/types/core/update.d.ts +0 -52
- package/dist/types/core/update.d.ts.map +0 -1
- package/src/core/beacon/aggregation/cohort/index.ts +0 -305
- package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
- package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
- package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
- package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
- package/src/core/beacon/aggregation/cohort/status.ts +0 -7
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
- package/src/core/beacon/aggregation/communication/error.ts +0 -13
- package/src/core/beacon/aggregation/communication/factory.ts +0 -25
- package/src/core/beacon/aggregation/communication/service.ts +0 -42
- package/src/core/beacon/aggregation/coordinator.ts +0 -419
- package/src/core/beacon/aggregation/participant.ts +0 -517
- package/src/core/beacon/aggregation/session/index.ts +0 -301
- package/src/core/beacon/aggregation/session/status.ts +0 -18
- package/src/core/update.ts +0 -158
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
// TODO: Finish nostr adapter implementation. Rethink patterns used.
|
|
2
|
-
import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
|
|
3
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
4
|
-
import { nonceGen } from '@scure/btc-signer/musig2';
|
|
5
|
-
import { finalizeEvent, nip44, SimplePool } from 'nostr-tools';
|
|
6
|
-
import { Identifier } from '../../../../identifier.js';
|
|
7
|
-
import { BEACON_COHORT_ADVERT, BEACON_COHORT_AGGREGATED_NONCE, BEACON_COHORT_AUTHORIZATION_REQUEST, BEACON_COHORT_NONCE_CONTRIBUTION, BEACON_COHORT_OPT_IN, BEACON_COHORT_OPT_IN_ACCEPT, BEACON_COHORT_READY, BEACON_COHORT_REQUEST_SIGNATURE, BEACON_COHORT_SIGNATURE_AUTHORIZATION } from '../../cohort/messages/constants.js';
|
|
8
|
-
import { AggregateBeaconMessage } from '../../cohort/messages/index.js';
|
|
9
|
-
import { CommunicationAdapterError } from '../error.js';
|
|
10
|
-
/**
|
|
11
|
-
* TODO: Determine set of default Nostr relays to use.
|
|
12
|
-
* DEFAULT_NOSTR_RELAYS provides a list of default Nostr relay URLs for communication.
|
|
13
|
-
* These relays are used to connect to the Nostr network for sending and receiving messages.
|
|
14
|
-
* @constant {Array<string>} DEFAULT_NOSTR_RELAYS
|
|
15
|
-
*/
|
|
16
|
-
export const DEFAULT_NOSTR_RELAYS = [
|
|
17
|
-
'wss://relay.damus.io',
|
|
18
|
-
// 'wss://nos.lol',
|
|
19
|
-
// 'wss://relay.snort.social',
|
|
20
|
-
// 'wss://nostr-pub.wellorder.net',
|
|
21
|
-
];
|
|
22
|
-
/**
|
|
23
|
-
* NostrAdapter implements the CommunicationService interface for Nostr protocol communication.
|
|
24
|
-
* It provides methods for starting the service, sending messages, and handling incoming events.
|
|
25
|
-
* @class NostrAdapter
|
|
26
|
-
* @type {NostrAdapter}
|
|
27
|
-
* @implements {CommunicationService}
|
|
28
|
-
*/
|
|
29
|
-
export class NostrAdapter {
|
|
30
|
-
/**
|
|
31
|
-
* The name of the NostrAdapter service.
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
name = 'nostr';
|
|
35
|
-
/**
|
|
36
|
-
* The configuration for the NostrAdapter.
|
|
37
|
-
* @type {NostrAdapterConfig}
|
|
38
|
-
*/
|
|
39
|
-
config;
|
|
40
|
-
/**
|
|
41
|
-
* A map of message handlers for different message types.
|
|
42
|
-
* @type {Map<string, MessageHandler>}
|
|
43
|
-
*/
|
|
44
|
-
#handlers = new Map();
|
|
45
|
-
/**
|
|
46
|
-
* The SimplePool instance for managing Nostr subscriptions.
|
|
47
|
-
* @type {SimplePool}
|
|
48
|
-
*/
|
|
49
|
-
pool;
|
|
50
|
-
/**
|
|
51
|
-
* Constructs a new NostrAdapter instance with the given configuration.
|
|
52
|
-
* @param {NostrAdapterConfig} config - The configuration for the NostrAdapter.
|
|
53
|
-
* If no configuration is provided, a new key pair is generated and default relays are used.
|
|
54
|
-
* @constructor
|
|
55
|
-
*/
|
|
56
|
-
constructor(config = { keys: {}, components: {}, relays: DEFAULT_NOSTR_RELAYS }) {
|
|
57
|
-
this.config = config;
|
|
58
|
-
this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
|
|
59
|
-
this.config.did = config.did || Identifier.encode(this.config.keys.public, {
|
|
60
|
-
idType: config.components.idType || 'KEY',
|
|
61
|
-
version: config.components.version || 1,
|
|
62
|
-
network: config.components.network || 'signet'
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Sets the keys for the NostrAdapter.
|
|
67
|
-
* @param {ServiceAdapterIdentity<RawSchnorrKeyPair>} keys - The key pair to set.
|
|
68
|
-
*/
|
|
69
|
-
setKeys(keys) {
|
|
70
|
-
this.config.keys = keys;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* TODO: Complete this method. Figure out best subscription patterns.
|
|
74
|
-
* Starts the Nostr communication service by subscribing to relays.
|
|
75
|
-
* @returns {ServiceAdapter<NostrAdapter>} Returns the NostrAdapter instance for method chaining.
|
|
76
|
-
*/
|
|
77
|
-
start() {
|
|
78
|
-
this.pool = new SimplePool();
|
|
79
|
-
this.pool.subscribe(this.config.relays, { kinds: [1] }, {
|
|
80
|
-
onclose: (reasons) => console.log('Subscription to kind 1 closed', reasons),
|
|
81
|
-
onevent: this.onEvent.bind(this),
|
|
82
|
-
});
|
|
83
|
-
// this.pool.subscribe(this.config.relays, { kinds: [1059] } as Filter, {
|
|
84
|
-
// onclose : (reasons: string[]) => console.log('Subscription to kind 1059 closed for reasons:', reasons),
|
|
85
|
-
// onevent : this.onEvent.bind(this),
|
|
86
|
-
// oneose : () => { Logger.info('EOSE kinds 1059'); }
|
|
87
|
-
// });
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* TODO: Complete this method. Figure out best way to filter incoming nostr events.
|
|
92
|
-
* Handles incoming Nostr events and dispatches them to the appropriate message handler.
|
|
93
|
-
* @param {Event} event The Nostr event received from the relay.
|
|
94
|
-
*/
|
|
95
|
-
async onEvent(event) {
|
|
96
|
-
// Logger.debug('nostr.onEvent: event.tags', event.tags);
|
|
97
|
-
// Dispatch the event to the registered handler
|
|
98
|
-
const ptags = event.tags.filter(([name, _]) => name === 'p') ?? [];
|
|
99
|
-
// Logger.debug('nostr.onEvent: event.tags.find => ptags', ptags);
|
|
100
|
-
for (const [p, pk] of ptags) {
|
|
101
|
-
if (pk === 'b71d3052dcdc8ba4564388948b655b58aaa7f37497ef1fc98829f9191adc8f85') {
|
|
102
|
-
console.debug('nostr.onEvent: event.tags.find => p, pk', p, pk);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// if(!type && !value) {
|
|
106
|
-
// // Logger.warn(`Event ${event.id} does not have a valid tag, skipping handler dispatch.`);
|
|
107
|
-
// return;
|
|
108
|
-
// }
|
|
109
|
-
// Logger.debug('nostr.onEvent: event.tags.find => type, value', type, value);
|
|
110
|
-
// Logger.debug('nostr.onEvent: event', event);
|
|
111
|
-
// Logger.debug('nostr.onEvent: event.tags', event.tags);
|
|
112
|
-
// if(event.kind === 1 && !AggregateBeaconMessage.isKeyGenMessageValue(value)) {
|
|
113
|
-
// Logger.warn(`Event ${event.id} is not a key generation message type: ${value}, skipping handler dispatch.`);
|
|
114
|
-
// return;
|
|
115
|
-
// }
|
|
116
|
-
// if(event.kind === 1059 && !AggregateBeaconMessage.isSignMessageValue(value)) {
|
|
117
|
-
// Logger.warn(`Event ${event.id} has an invalid title tag: ${value}, skipping handler dispatch.`);
|
|
118
|
-
// return;
|
|
119
|
-
// }
|
|
120
|
-
// const handler = this.handlers.get(value);
|
|
121
|
-
// if (!handler) {
|
|
122
|
-
// Logger.warn(`No handler found for message with tag value: ${value}`);
|
|
123
|
-
// return;
|
|
124
|
-
// }
|
|
125
|
-
// await handler(event);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Registers a message handler for a specific message type.
|
|
129
|
-
* @param {string} messageType The type of message to handle.
|
|
130
|
-
* @param {MessageHandler} handler The handler function that processes the message.
|
|
131
|
-
*/
|
|
132
|
-
registerMessageHandler(messageType, handler) {
|
|
133
|
-
this.#handlers.set(messageType, handler);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* TODO: Clean up and complete this method.
|
|
137
|
-
* Sends a message to a recipient using the Nostr protocol.
|
|
138
|
-
* This method is a placeholder and should be implemented with actual Nostr message sending logic.
|
|
139
|
-
* @param {AggregateBeaconMessageType} message The message to send, typically containing the content and metadata.
|
|
140
|
-
* @param {Did} from The identifier of the sender.
|
|
141
|
-
* @param {Did} [to] The identifier of the recipient.
|
|
142
|
-
* @returns {Promise<void>} A promise that resolves when the message is sent.
|
|
143
|
-
*/
|
|
144
|
-
async sendMessage(message, from, to) {
|
|
145
|
-
// Check if the sender and recipient DIDs are valid identifiers
|
|
146
|
-
if ([from, to]
|
|
147
|
-
.filter(did => !!did)
|
|
148
|
-
.every(did => !Identifier.isValid(did))) {
|
|
149
|
-
console.error(`Invalid identifiers: sender ${from}, recipient ${to}`);
|
|
150
|
-
throw new CommunicationAdapterError(`Invalid identifiers: sender ${from}, recipient ${to}`, 'SEND_MESSAGE_ERROR', { adapter: this.name });
|
|
151
|
-
}
|
|
152
|
-
// Decode the sender and recipient DIDs to get their genesis bytes in hex
|
|
153
|
-
const sender = new CompressedSecp256k1PublicKey(Identifier.decode(from).genesisBytes);
|
|
154
|
-
console.info(`Sending message from ${sender}:`, message);
|
|
155
|
-
// if(message.type === BEACON_COHORT_SUBSCRIBE_ACCEPT) {
|
|
156
|
-
// this.config.coordinatorDids.push(recipient);
|
|
157
|
-
// }
|
|
158
|
-
const tags = [['p', bytesToHex(sender.x)]];
|
|
159
|
-
if (to) {
|
|
160
|
-
const recipient = new CompressedSecp256k1PublicKey(Identifier.decode(to).genesisBytes);
|
|
161
|
-
tags.push(['p', bytesToHex(recipient.x)]);
|
|
162
|
-
}
|
|
163
|
-
const { type } = message ?? {};
|
|
164
|
-
if (!type) {
|
|
165
|
-
console.error('Message type is undefined:', message);
|
|
166
|
-
throw new CommunicationAdapterError('Message type is undefined', 'SEND_MESSAGE_ERROR', { adapter: this.name });
|
|
167
|
-
}
|
|
168
|
-
if (AggregateBeaconMessage.isKeyGenMessageValue(type)) {
|
|
169
|
-
switch (type) {
|
|
170
|
-
case BEACON_COHORT_ADVERT:
|
|
171
|
-
console.info('Add tag', ['BEACON_COHORT_ADVERT', type]);
|
|
172
|
-
break;
|
|
173
|
-
case BEACON_COHORT_OPT_IN:
|
|
174
|
-
console.info('Add tag', ['BEACON_COHORT_OPT_IN', type]);
|
|
175
|
-
break;
|
|
176
|
-
case BEACON_COHORT_OPT_IN_ACCEPT:
|
|
177
|
-
console.info('Add tag', ['BEACON_COHORT_OPT_IN_ACCEPT', type]);
|
|
178
|
-
break;
|
|
179
|
-
case BEACON_COHORT_READY:
|
|
180
|
-
console.info('Add tag', ['BEACON_COHORT_READY', type]);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
const event = finalizeEvent({
|
|
184
|
-
kind: 1,
|
|
185
|
-
created_at: Math.floor(Date.now() / 1000),
|
|
186
|
-
tags,
|
|
187
|
-
content: JSON.stringify(message)
|
|
188
|
-
}, this.config.keys.secret);
|
|
189
|
-
console.info(`Sending message kind 1 event ...`, event);
|
|
190
|
-
return this.pool?.publish(this.config.relays, event);
|
|
191
|
-
}
|
|
192
|
-
if (AggregateBeaconMessage.isSignMessageValue(type)) {
|
|
193
|
-
switch (type) {
|
|
194
|
-
case BEACON_COHORT_REQUEST_SIGNATURE:
|
|
195
|
-
console.info('Add tag', ['BEACON_COHORT_REQUEST_SIGNATURE', type]);
|
|
196
|
-
break;
|
|
197
|
-
case BEACON_COHORT_AUTHORIZATION_REQUEST:
|
|
198
|
-
console.info('Add tag', ['BEACON_COHORT_AUTHORIZATION_REQUEST', type]);
|
|
199
|
-
break;
|
|
200
|
-
case BEACON_COHORT_NONCE_CONTRIBUTION:
|
|
201
|
-
console.info('Add tag', ['BEACON_COHORT_NONCE_CONTRIBUTION', type]);
|
|
202
|
-
break;
|
|
203
|
-
case BEACON_COHORT_AGGREGATED_NONCE:
|
|
204
|
-
console.info('Add tag', ['BEACON_COHORT_AGGREGATED_NONCE', type]);
|
|
205
|
-
break;
|
|
206
|
-
case BEACON_COHORT_SIGNATURE_AUTHORIZATION:
|
|
207
|
-
console.info('Add tag', ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', type]);
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
const { publicKey, secretKey } = SchnorrKeyPair.generate();
|
|
211
|
-
const content = nip44.encrypt(JSON.stringify(message), secretKey.bytes, nonceGen(publicKey.x).public);
|
|
212
|
-
console.debug('NostrAdapter content:', content);
|
|
213
|
-
const event = finalizeEvent({ content, tags, kind: 1059 }, this.config.keys.secret);
|
|
214
|
-
console.debug('NostrAdapter event:', event);
|
|
215
|
-
return this.pool?.publish(this.config.relays, event);
|
|
216
|
-
}
|
|
217
|
-
console.error(`Unsupported message type: ${type}`);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* TODO: Determine if this method is needed.
|
|
221
|
-
* Generates a Nostr identity using the Secp256k1SecretKey and Identifier classes.
|
|
222
|
-
* @param {RawSchnorrKeyPair} [keys] Optional keys to use for identity generation.
|
|
223
|
-
* @returns {ServiceAdapterConfig} The generated Nostr identity configuration.
|
|
224
|
-
*/
|
|
225
|
-
generateIdentity(keys) {
|
|
226
|
-
if (!keys) {
|
|
227
|
-
this.config.keys.secret = Secp256k1SecretKey.random();
|
|
228
|
-
this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
|
|
229
|
-
this.config.did = Identifier.encode(this.config.keys.public, {
|
|
230
|
-
idType: this.config.components.idType || 'KEY',
|
|
231
|
-
version: this.config.components.version || 1,
|
|
232
|
-
network: this.config.components.network || 'signet',
|
|
233
|
-
});
|
|
234
|
-
return this.config;
|
|
235
|
-
}
|
|
236
|
-
this.config.keys = keys;
|
|
237
|
-
this.config.did = Identifier.encode(this.config.keys.public, {
|
|
238
|
-
idType: this.config.components.idType || 'KEY',
|
|
239
|
-
version: this.config.components.version || 1,
|
|
240
|
-
network: this.config.components.network || 'signet',
|
|
241
|
-
});
|
|
242
|
-
return this.config;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
//# sourceMappingURL=nostr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nostr.js","sourceRoot":"","sources":["../../../../../../../src/core/beacon/aggregation/communication/adapter/nostr.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAIpE,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtG,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,8BAA8B,EAC9B,mCAAmC,EACnC,gCAAgC,EAChC,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,+BAA+B,EAC/B,qCAAqC,EACtC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,sBAAsB;IACtB,mBAAmB;IACnB,8BAA8B;IAC9B,mCAAmC;CACpC,CAAC;AAoBF;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACvB;;;OAGG;IACH,IAAI,GAAW,OAA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1
|
-
import { MethodError } from '@did-btcr2/common';
|
|
2
|
-
export class CommunicationServiceError extends MethodError {
|
|
3
|
-
constructor(message, type = 'CommunicationServiceError', data) {
|
|
4
|
-
super(message, type, data);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export class CommunicationAdapterError extends MethodError {
|
|
8
|
-
constructor(message, type = 'CommunicationAdapterError', data) {
|
|
9
|
-
super(message, type, data);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../../../src/core/beacon/aggregation/communication/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,yBAA0B,SAAQ,WAAW;IACxD,YAAY,OAAe,EAAE,OAAe,2BAA2B,EAAE,IAA0B;QACjG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,WAAW;IACxD,YAAY,OAAe,EAAE,OAAe,2BAA2B,EAAE,IAA0B;QACjG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { NotImplementedError } from '@did-btcr2/common';
|
|
2
|
-
import { NostrAdapter } from './adapter/nostr.js';
|
|
3
|
-
import { CommunicationServiceError } from './error.js';
|
|
4
|
-
/**
|
|
5
|
-
* Communication Factory pattern to create Communication Service instances.
|
|
6
|
-
* @class CommunicationFactory
|
|
7
|
-
* @type {CommunicationFactory}
|
|
8
|
-
*/
|
|
9
|
-
export class CommunicationFactory {
|
|
10
|
-
static establish(service) {
|
|
11
|
-
switch (service.type) {
|
|
12
|
-
case 'nostr':
|
|
13
|
-
return new NostrAdapter();
|
|
14
|
-
case 'didcomm':
|
|
15
|
-
throw new NotImplementedError('DID Comm service not implemented yet.');
|
|
16
|
-
default:
|
|
17
|
-
throw new CommunicationServiceError(`Invalid service type ${service.type}`, 'INVALID_BEACON_ERROR', { service });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../src/core/beacon/aggregation/communication/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAC/B,MAAM,CAAC,SAAS,CAAC,OAAgB;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,OAAO;gBACV,OAAO,IAAI,YAAY,EAAE,CAAC;YAC5B,KAAK,SAAS;gBACZ,MAAM,IAAI,mBAAmB,CAAC,uCAAuC,CAAC,CAAC;YACzE;gBACE,MAAM,IAAI,yBAAyB,CACjC,wBAAwB,OAAO,CAAC,IAAI,EAAE,EACtC,sBAAsB,EAAE,EAAE,OAAO,EAAE,CACpC,CAAC;QACN,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../../src/core/beacon/aggregation/communication/service.ts"],"names":[],"mappings":""}
|
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
2
|
-
import { BeaconCoordinatorError } from '../error.js';
|
|
3
|
-
import { AggregateBeaconCohort } from './cohort/index.js';
|
|
4
|
-
import { BEACON_COHORT_ADVERT, BEACON_COHORT_NONCE_CONTRIBUTION, BEACON_COHORT_OPT_IN, BEACON_COHORT_REQUEST_SIGNATURE, BEACON_COHORT_SIGNATURE_AUTHORIZATION } from './cohort/messages/constants.js';
|
|
5
|
-
import { BeaconCohortAdvertMessage } from './cohort/messages/keygen/cohort-advert.js';
|
|
6
|
-
import { BeaconCohortReadyMessage } from './cohort/messages/keygen/cohort-ready.js';
|
|
7
|
-
import { BeaconCohortOptInAcceptMessage } from './cohort/messages/keygen/opt-in-accept.js';
|
|
8
|
-
import { BeaconCohortOptInMessage } from './cohort/messages/keygen/opt-in.js';
|
|
9
|
-
import { BeaconCohortAggregatedNonceMessage } from './cohort/messages/sign/aggregated-nonce.js';
|
|
10
|
-
import { BeaconCohortNonceContributionMessage } from './cohort/messages/sign/nonce-contribution.js';
|
|
11
|
-
import { BeaconCohortRequestSignatureMessage } from './cohort/messages/sign/request-signature.js';
|
|
12
|
-
import { BeaconCohortSignatureAuthorizationMessage } from './cohort/messages/sign/signature-authorization.js';
|
|
13
|
-
import { NostrAdapter } from './communication/adapter/nostr.js';
|
|
14
|
-
import { CommunicationFactory } from './communication/factory.js';
|
|
15
|
-
import { SIGNING_SESSION_STATUS } from './session/status.js';
|
|
16
|
-
/**
|
|
17
|
-
* The BeaconCoordinator class is responsible for managing the coordination of beacon aggregation.
|
|
18
|
-
* @class BeaconCoordinator
|
|
19
|
-
* @type {BeaconCoordinator}
|
|
20
|
-
*/
|
|
21
|
-
export class BeaconCoordinator {
|
|
22
|
-
/**
|
|
23
|
-
* The name of the BeaconCoordinator service.
|
|
24
|
-
* @type {string}
|
|
25
|
-
*/
|
|
26
|
-
name;
|
|
27
|
-
/**
|
|
28
|
-
* The DID of the BeaconCoordinator.
|
|
29
|
-
* @type {Array<string>}
|
|
30
|
-
*/
|
|
31
|
-
did;
|
|
32
|
-
/**
|
|
33
|
-
* The communication protocol used by the BeaconCoordinator.
|
|
34
|
-
* @type {CommunicationService}
|
|
35
|
-
*/
|
|
36
|
-
protocol;
|
|
37
|
-
/**
|
|
38
|
-
* List of subscribers engaged in a Musig2 Cohort signing session with the BeaconCoordinator.
|
|
39
|
-
* @type {Array<string>}
|
|
40
|
-
*/
|
|
41
|
-
cohorts = [];
|
|
42
|
-
/**
|
|
43
|
-
* Active signing sessions for the BeaconCoordinator.
|
|
44
|
-
* @type {Record<string, BeaconCohortSigningSession>}
|
|
45
|
-
*/
|
|
46
|
-
activeSigningSessions = new Map();
|
|
47
|
-
/**
|
|
48
|
-
* Constructs a new BeaconCoordinator instance.
|
|
49
|
-
* @param {BeaconCoordinatorParams} params The parameters for the coordinator.
|
|
50
|
-
* @param {CommunicationService} params.protocol The protocol service used for communication.
|
|
51
|
-
* @param {string} [params.name] Optional name for the coordinator. If not provided, a default name will be generated.
|
|
52
|
-
* @param {string} [params.did] Optional DID to use for the coordinator. If not provided, a new DID will be generated.
|
|
53
|
-
* @param {ServiceAdapterIdentity<RawKeyPair>} params.keys The keys used for cryptographic operations.
|
|
54
|
-
*/
|
|
55
|
-
constructor(params) {
|
|
56
|
-
this.did = params.did;
|
|
57
|
-
this.protocol = params.protocol || new NostrAdapter();
|
|
58
|
-
this.protocol.setKeys(params.keys);
|
|
59
|
-
this.name = params.name || `btcr2-beacon-coordinator-${crypto.randomUUID()}`;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Setup and start the BeaconCoordinator communication protocol.
|
|
63
|
-
* @returns {void}
|
|
64
|
-
*/
|
|
65
|
-
start() {
|
|
66
|
-
console.info(`Setting up BeaconCoordinator ${this.name} (${this.did}) on ${this.protocol.name} ...`);
|
|
67
|
-
this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN, this.#handleOptIn.bind(this));
|
|
68
|
-
this.protocol.registerMessageHandler(BEACON_COHORT_REQUEST_SIGNATURE, this.#handleRequestSignature.bind(this));
|
|
69
|
-
this.protocol.registerMessageHandler(BEACON_COHORT_NONCE_CONTRIBUTION, this.#handleNonceContribution.bind(this));
|
|
70
|
-
this.protocol.registerMessageHandler(BEACON_COHORT_SIGNATURE_AUTHORIZATION, this.#handleSignatureAuthorization.bind(this));
|
|
71
|
-
this.protocol.start();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Handles opt-in requests from participants to join a cohort.
|
|
75
|
-
* @param {OptInMessage} message The message containing the opt-in request.
|
|
76
|
-
* @returns {Promise<void>}
|
|
77
|
-
*/
|
|
78
|
-
async #handleOptIn(message) {
|
|
79
|
-
const optIn = BeaconCohortOptInMessage.fromJSON(message);
|
|
80
|
-
const cohortId = optIn.body?.cohortId;
|
|
81
|
-
const participant = optIn.from;
|
|
82
|
-
const participantPk = optIn.body?.participantPk;
|
|
83
|
-
if (!cohortId || !participant || !participantPk) {
|
|
84
|
-
console.warn(`Invalid opt-in message from ${participant}: missing cohortId, participant or participantPk`);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
88
|
-
if (cohort && !cohort.participants.includes(participant)) {
|
|
89
|
-
cohort.participants.push(participant);
|
|
90
|
-
cohort.cohortKeys.push(participantPk);
|
|
91
|
-
await this.acceptSubscription(participant);
|
|
92
|
-
// If the cohort has enough participants, start the key generation process.
|
|
93
|
-
if (cohort.participants.length >= cohort.minParticipants) {
|
|
94
|
-
await this._startKeyGeneration(cohort);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Handles request signature messages from participants.
|
|
100
|
-
* @private
|
|
101
|
-
* @param {CohortRequestSignatureMessage} message The message containing the request signature.
|
|
102
|
-
* @returns {Promise<void>}
|
|
103
|
-
*/
|
|
104
|
-
async #handleRequestSignature(message) {
|
|
105
|
-
const signatureRequest = BeaconCohortRequestSignatureMessage.fromJSON(message);
|
|
106
|
-
const cohortId = signatureRequest.body?.cohortId;
|
|
107
|
-
if (!cohortId) {
|
|
108
|
-
console.warn(`Signature request missing cohort ID from ${signatureRequest.from}`);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
112
|
-
if (!cohort) {
|
|
113
|
-
console.error(`Cohort with ID ${cohortId} not found.`);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
cohort.addSignatureRequest(signatureRequest);
|
|
117
|
-
console.info(`Received signature request from ${signatureRequest.from} for cohort ${cohortId}.`);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Handles nonce contribution messages from participants.
|
|
121
|
-
* @param {CohortNonceContributionMessage} message The message containing the nonce contribution.
|
|
122
|
-
* @returns {Promise<void>}
|
|
123
|
-
*/
|
|
124
|
-
async #handleNonceContribution(message) {
|
|
125
|
-
// Cast message to NonceContributionMessage type.
|
|
126
|
-
const nonceContribMessage = BeaconCohortNonceContributionMessage.fromJSON(message);
|
|
127
|
-
const cohortId = nonceContribMessage.body?.cohortId;
|
|
128
|
-
if (!cohortId) {
|
|
129
|
-
console.warn(`Nonce contribution message missing cohort ID from ${nonceContribMessage.from}`);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const sessionId = nonceContribMessage.body?.sessionId;
|
|
133
|
-
if (!sessionId) {
|
|
134
|
-
console.warn(`Nonce contribution message missing session ID from ${nonceContribMessage.from}`);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
// Get the signing session using the cohort ID from the message.
|
|
138
|
-
const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
|
|
139
|
-
// If the signing session does not exist, log an error and return.
|
|
140
|
-
if (!signingSession) {
|
|
141
|
-
console.error(`Session ${cohortId || sessionId} not found.`);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
// If the message.cohortId does not match the signingSession.cohortId, throw an error.
|
|
145
|
-
if (cohortId !== signingSession.cohort.id) {
|
|
146
|
-
throw new BeaconCoordinatorError(`Nonce contribution for wrong cohort: ${signingSession.cohort.id} != ${cohortId}`, 'NONCE_CONTRIBUTION_ERROR', message);
|
|
147
|
-
}
|
|
148
|
-
const nonceContribution = nonceContribMessage.body?.nonceContribution;
|
|
149
|
-
if (!nonceContribution) {
|
|
150
|
-
console.warn(`Nonce contribution message missing nonce contribution from ${nonceContribMessage.from}`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
// Add the nonce contribution to the signing session.
|
|
154
|
-
signingSession.addNonceContribution(nonceContribMessage.from, nonceContribution);
|
|
155
|
-
console.info(`Nonce contribution received from ${nonceContribMessage.from} for session ${sessionId}.`);
|
|
156
|
-
if (signingSession.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
|
|
157
|
-
await this.sendAggregatedNonce(signingSession);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Handles signature authorization messages from participants.
|
|
162
|
-
* @param {Maybe<CohortSignatureAuthorizationMessage>} message The message containing the signature authorization request.
|
|
163
|
-
* @returns {Promise<void>}
|
|
164
|
-
*/
|
|
165
|
-
async #handleSignatureAuthorization(message) {
|
|
166
|
-
const sigAuthMessage = BeaconCohortSignatureAuthorizationMessage.fromJSON(message);
|
|
167
|
-
const cohortId = sigAuthMessage.body?.cohortId;
|
|
168
|
-
if (!cohortId) {
|
|
169
|
-
console.warn(`Signature authorization message missing cohort ID from ${sigAuthMessage.from}`);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const sessionId = sigAuthMessage.body?.sessionId;
|
|
173
|
-
if (!sessionId) {
|
|
174
|
-
console.warn(`Signature authorization message missing session ID from ${sigAuthMessage.from}`);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
|
|
178
|
-
if (!signingSession) {
|
|
179
|
-
console.error(`Session ${sessionId} not found.`);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (signingSession.id !== sessionId) {
|
|
183
|
-
throw new BeaconCoordinatorError(`Signature authorization for wrong session: ${signingSession.id} != ${sessionId}`, 'SIGNATURE_AUTHORIZATION_ERROR', { original: message, converted: sigAuthMessage });
|
|
184
|
-
}
|
|
185
|
-
if (signingSession.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
|
|
186
|
-
throw new BeaconCoordinatorError(`Partial signature received but not expected. Current status: ${signingSession.status}`, 'SIGNATURE_AUTHORIZATION_ERROR', { original: message, converted: sigAuthMessage });
|
|
187
|
-
}
|
|
188
|
-
const partialSignature = sigAuthMessage.body?.partialSignature;
|
|
189
|
-
if (!partialSignature) {
|
|
190
|
-
console.warn(`Signature authorization message missing partial signature from ${sigAuthMessage.from}`);
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
// Add the signature authorization to the signing session.
|
|
194
|
-
signingSession.addPartialSignature(sigAuthMessage.from, partialSignature);
|
|
195
|
-
console.info(`Received partial signature from ${sigAuthMessage.from} for session ${sessionId}.`);
|
|
196
|
-
if (signingSession.partialSignatures.size === signingSession.cohort.participants.length) {
|
|
197
|
-
signingSession.status = SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED;
|
|
198
|
-
}
|
|
199
|
-
if (signingSession.status === SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
|
|
200
|
-
const signature = await signingSession.generateFinalSignature();
|
|
201
|
-
console.info(`Final signature ${bytesToHex(signature)} generated for session ${signingSession.id}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Starts the key generation process for a cohort once it has enough participants.
|
|
206
|
-
* @param {Musig2Cohort} cohort The cohort for which to start key generation.
|
|
207
|
-
* @returns {Promise<void>}
|
|
208
|
-
*/
|
|
209
|
-
async _startKeyGeneration(cohort) {
|
|
210
|
-
console.info(`Starting key generation for cohort ${cohort.id} with participants: ${cohort.participants.join(', ')}`);
|
|
211
|
-
cohort.finalize();
|
|
212
|
-
for (const participant of cohort.participants) {
|
|
213
|
-
const message = cohort.getCohortReadyMessage(participant, this.did);
|
|
214
|
-
console.info(`Sending BEACON_COHORT_READY message to ${participant}`);
|
|
215
|
-
await this.protocol.sendMessage(message, participant, this.did);
|
|
216
|
-
}
|
|
217
|
-
console.info(`Finished sending BEACON_COHORT_READY message to ${cohort.participants.length} participants`);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Accepts a subscription request from a participant.
|
|
221
|
-
* @param {string} participant The DID of the participant requesting the subscription.
|
|
222
|
-
* @returns {Promise<void>}
|
|
223
|
-
*/
|
|
224
|
-
async acceptSubscription(participant) {
|
|
225
|
-
console.info(`Accepting subscription from ${participant}`);
|
|
226
|
-
const message = new BeaconCohortOptInAcceptMessage({ to: participant, from: this.did });
|
|
227
|
-
await this.protocol.sendMessage(message, this.did, participant);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Sends the aggregated nonce to all participants in the session.
|
|
231
|
-
* @param {BeaconCohortSigningSession} session The session containing the aggregated nonce.
|
|
232
|
-
* @returns {Promise<void>}
|
|
233
|
-
*/
|
|
234
|
-
async sendAggregatedNonce(session) {
|
|
235
|
-
const aggregatedNonce = session.generateAggregatedNonce();
|
|
236
|
-
console.info(`Aggregated Nonces for session ${session.id}:`, aggregatedNonce);
|
|
237
|
-
session.status = SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES;
|
|
238
|
-
for (const participant of session.cohort.participants) {
|
|
239
|
-
const message = new BeaconCohortAggregatedNonceMessage({
|
|
240
|
-
to: participant,
|
|
241
|
-
from: this.did,
|
|
242
|
-
cohortId: session.cohort.id,
|
|
243
|
-
sessionId: session.id,
|
|
244
|
-
aggregatedNonce: aggregatedNonce
|
|
245
|
-
});
|
|
246
|
-
console.info(`Sending AGGREGATED_NONCE message to ${participant}`);
|
|
247
|
-
await this.protocol.sendMessage(message, participant, this.did);
|
|
248
|
-
}
|
|
249
|
-
console.info(`Successfully sent aggregated nonce message to all participants in session ${session.id}.`);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Announces a new cohort to all subscribers.
|
|
253
|
-
* @param {number} minParticipants The minimum number of participants required for the cohort.
|
|
254
|
-
* @param {string} [network='mutinynet'] The network on which the cohort operates (default is 'signet').
|
|
255
|
-
* @param {string} [beaconType='SMTBeacon'] The type of beacon to be used (default is 'SMTBeacon').
|
|
256
|
-
* @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
|
|
257
|
-
*/
|
|
258
|
-
async advertiseCohort(minParticipants, network = 'mutinynet', beaconType = 'SMTBeacon') {
|
|
259
|
-
const cohort = new AggregateBeaconCohort({ minParticipants, network, beaconType });
|
|
260
|
-
console.info(`Advertising new cohort ${cohort.id} ...`);
|
|
261
|
-
this.cohorts.push(cohort);
|
|
262
|
-
const message = new BeaconCohortAdvertMessage({
|
|
263
|
-
from: this.did,
|
|
264
|
-
cohortId: cohort.id,
|
|
265
|
-
cohortSize: cohort.minParticipants,
|
|
266
|
-
network: cohort.network,
|
|
267
|
-
beaconType
|
|
268
|
-
});
|
|
269
|
-
console.info(`Sending ${BEACON_COHORT_ADVERT} message to network ...`, message);
|
|
270
|
-
await this.protocol.sendMessage(message, this.did);
|
|
271
|
-
console.info(`Cohort ${cohort.id} advertised successfully.`);
|
|
272
|
-
return cohort;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Announces to all subscribers a cohort is ready for signing.
|
|
276
|
-
* @param {string} cohortId The minimum number of participants required for the cohort.
|
|
277
|
-
* @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
|
|
278
|
-
*/
|
|
279
|
-
async announceCohortReady(cohortId) {
|
|
280
|
-
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
281
|
-
if (!cohort) {
|
|
282
|
-
console.error(`Cohort with ID ${cohortId} not found.`);
|
|
283
|
-
throw new BeaconCoordinatorError(`Cohort with ID ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
|
|
284
|
-
}
|
|
285
|
-
console.info(`Announcing cohort ${cohort.id} to ${cohort.participants.length} subscribers...`);
|
|
286
|
-
this.cohorts.push(cohort);
|
|
287
|
-
for (const participant of cohort.participants) {
|
|
288
|
-
const message = new BeaconCohortReadyMessage({
|
|
289
|
-
to: participant,
|
|
290
|
-
from: this.did,
|
|
291
|
-
cohortId: cohort.id,
|
|
292
|
-
beaconAddress: cohort.beaconAddress,
|
|
293
|
-
cohortKeys: cohort.cohortKeys,
|
|
294
|
-
});
|
|
295
|
-
console.info(`Sending ${BEACON_COHORT_ADVERT} message to ${participant}`);
|
|
296
|
-
await this.protocol.sendMessage(message, this.did, participant);
|
|
297
|
-
}
|
|
298
|
-
return cohort;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Starts a signing session for a given cohort.
|
|
302
|
-
* @param {string} cohortId The ID of the cohort for which to start a signing session.
|
|
303
|
-
* @returns {Promise<BeaconCohortSigningSession>} The started signing session.
|
|
304
|
-
* @throws {BeaconCoordinatorError} If the cohort with the given ID is not found.
|
|
305
|
-
*/
|
|
306
|
-
async startSigningSession(cohortId) {
|
|
307
|
-
console.info(`Attempting to start signing session for cohort ${cohortId}`);
|
|
308
|
-
const cohort = this.cohorts.find(c => c.id === cohortId);
|
|
309
|
-
if (!cohort) {
|
|
310
|
-
console.error(`Cohort with ID ${cohortId} not found.`);
|
|
311
|
-
throw new BeaconCoordinatorError(`Cohort with ID ${cohortId} not found.`, 'COHORT_NOT_FOUND');
|
|
312
|
-
}
|
|
313
|
-
console.info(`Cohort ${cohortId} found. Starting signing session.`);
|
|
314
|
-
const signingSession = cohort.startSigningSession();
|
|
315
|
-
console.info(`Starting signing session ${signingSession.id} for cohort ${cohortId}`);
|
|
316
|
-
for (const participant of cohort.participants) {
|
|
317
|
-
const msg = signingSession.getAuthorizationRequest(participant, this.did);
|
|
318
|
-
console.info(`Sending authorization request to ${participant}`);
|
|
319
|
-
await this.protocol.sendMessage(msg, this.did, participant).catch(error => {
|
|
320
|
-
console.error(`Error sending authorization request to ${participant}: ${error.message}`);
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
this.activeSigningSessions.set(cohortId, signingSession);
|
|
324
|
-
console.info(`Signing session ${signingSession.id} started for cohort ${cohortId}`);
|
|
325
|
-
return signingSession;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Static initialization method for the BeaconCoordinator.
|
|
329
|
-
* @param {Service} service The communication service configuration.
|
|
330
|
-
* @returns {BeaconCoordinator} Initialized BeaconCoordinator instance.
|
|
331
|
-
*/
|
|
332
|
-
static initialize(service) {
|
|
333
|
-
const communicationService = CommunicationFactory.establish(service);
|
|
334
|
-
const coordinator = new BeaconCoordinator({
|
|
335
|
-
protocol: communicationService,
|
|
336
|
-
did: service.did,
|
|
337
|
-
keys: service.keys,
|
|
338
|
-
});
|
|
339
|
-
console.info(`BeaconCoordinator ${coordinator.name} initialized with DID ${coordinator.did}. Run .start() to listen for messages`);
|
|
340
|
-
return coordinator;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
//# sourceMappingURL=coordinator.js.map
|