@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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, } from '../messages/constants.js';
|
|
2
|
+
import { AggregationParticipant } from '../participant.js';
|
|
3
|
+
import { ParticipantCohortPhase } from '../phases.js';
|
|
4
|
+
import { TypedEventEmitter } from './typed-emitter.js';
|
|
5
|
+
/**
|
|
6
|
+
* High-level facade for an Aggregation Participant.
|
|
7
|
+
*
|
|
8
|
+
* Long-running listener: waits for cohort adverts, applies the `shouldJoin`
|
|
9
|
+
* filter, and drives each accepted cohort through the full protocol to
|
|
10
|
+
* completion in parallel.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const transport = new NostrTransport({ relays: [RELAY] });
|
|
15
|
+
* transport.registerActor(myDid, myKeys);
|
|
16
|
+
*
|
|
17
|
+
* const runner = new AggregationParticipantRunner({
|
|
18
|
+
* transport,
|
|
19
|
+
* did: myDid,
|
|
20
|
+
* keys: myKeys,
|
|
21
|
+
* shouldJoin: async (advert) => advert.beaconType === 'CASBeacon',
|
|
22
|
+
* onProvideUpdate: async ({ beaconAddress }) => {
|
|
23
|
+
<<<<<<< Updated upstream
|
|
24
|
+
* return Update.sign(myDid, unsigned, vm, secretKey);
|
|
25
|
+
=======
|
|
26
|
+
* return Updater.sign(myDid, unsigned, vm, secretKey);
|
|
27
|
+
>>>>>>> Stashed changes
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* runner.on('cohort-complete', ({ beaconAddress }) => {
|
|
32
|
+
* console.log(`Add to DID document: bitcoin:${beaconAddress}`);
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* await runner.start();
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* For full manual control, drop down to the underlying state machine via
|
|
39
|
+
* `runner.session`. The state machine has no transport coupling and exposes
|
|
40
|
+
* every protocol decision as an explicit method.
|
|
41
|
+
*
|
|
42
|
+
* @class AggregationParticipantRunner
|
|
43
|
+
* @extends TypedEventEmitter<AggregationParticipantEvents>
|
|
44
|
+
*/
|
|
45
|
+
export class AggregationParticipantRunner extends TypedEventEmitter {
|
|
46
|
+
/** Direct access to the underlying state machine for advanced use. */
|
|
47
|
+
session;
|
|
48
|
+
#transport;
|
|
49
|
+
#did;
|
|
50
|
+
#shouldJoin;
|
|
51
|
+
#onProvideUpdate;
|
|
52
|
+
#onValidateData;
|
|
53
|
+
#onApproveSigning;
|
|
54
|
+
#handlersRegistered = false;
|
|
55
|
+
#stopped = false;
|
|
56
|
+
constructor(options) {
|
|
57
|
+
super();
|
|
58
|
+
this.#transport = options.transport;
|
|
59
|
+
this.#did = options.did;
|
|
60
|
+
this.#shouldJoin = options.shouldJoin ?? (async () => false);
|
|
61
|
+
this.#onProvideUpdate = options.onProvideUpdate;
|
|
62
|
+
this.#onValidateData = options.onValidateData ?? (async (info) => ({ approved: info.matches }));
|
|
63
|
+
this.#onApproveSigning = options.onApproveSigning ?? (async () => ({ approved: true }));
|
|
64
|
+
this.session = new AggregationParticipant({ did: options.did, keys: options.keys });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Start listening for cohorts. The runner stays active until {@link stop}
|
|
68
|
+
* is called or the underlying transport disconnects.
|
|
69
|
+
*/
|
|
70
|
+
async start() {
|
|
71
|
+
this.#registerHandlers();
|
|
72
|
+
}
|
|
73
|
+
/** Stop the runner. Does not unregister transport handlers. */
|
|
74
|
+
stop() {
|
|
75
|
+
this.#stopped = true;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Single-shot helper: start, join the first cohort that passes `shouldJoin`,
|
|
79
|
+
* drive it to completion, and resolve. Convenient for tests and demos.
|
|
80
|
+
*/
|
|
81
|
+
static async joinFirst(options) {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
const runner = new AggregationParticipantRunner(options);
|
|
84
|
+
runner.once('cohort-complete', (info) => {
|
|
85
|
+
runner.stop();
|
|
86
|
+
resolve(info);
|
|
87
|
+
});
|
|
88
|
+
runner.on('error', reject);
|
|
89
|
+
runner.start().catch(reject);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Internal: handler registration with the transport. Idempotent and safe to call multiple times,
|
|
94
|
+
* but only registers handlers once.
|
|
95
|
+
*/
|
|
96
|
+
#registerHandlers() {
|
|
97
|
+
if (this.#handlersRegistered)
|
|
98
|
+
return;
|
|
99
|
+
this.#handlersRegistered = true;
|
|
100
|
+
this.#transport.registerMessageHandler(this.#did, COHORT_ADVERT, this.#handleAdvert.bind(this));
|
|
101
|
+
this.#transport.registerMessageHandler(this.#did, COHORT_OPT_IN_ACCEPT, this.#handleOptInAccept.bind(this));
|
|
102
|
+
this.#transport.registerMessageHandler(this.#did, COHORT_READY, this.#handleCohortReady.bind(this));
|
|
103
|
+
this.#transport.registerMessageHandler(this.#did, DISTRIBUTE_AGGREGATED_DATA, this.#handleDistributeData.bind(this));
|
|
104
|
+
this.#transport.registerMessageHandler(this.#did, AUTHORIZATION_REQUEST, this.#handleAuthorizationRequest.bind(this));
|
|
105
|
+
this.#transport.registerMessageHandler(this.#did, AGGREGATED_NONCE, this.#handleAggregatedNonce.bind(this));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Internal: handler for cohort adverts. Applies the `shouldJoin` filter and joins if approved.
|
|
109
|
+
* @param {BaseMessage} msg - The received cohort advert message.
|
|
110
|
+
* @returns {Promise<void>} Resolves when processing is complete.
|
|
111
|
+
*/
|
|
112
|
+
async #handleAdvert(msg) {
|
|
113
|
+
if (this.#stopped)
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
this.session.receive(msg);
|
|
117
|
+
const advert = this.session.discoveredCohorts.get(msg.body?.cohortId ?? '');
|
|
118
|
+
if (!advert)
|
|
119
|
+
return;
|
|
120
|
+
this.emit('cohort-discovered', advert);
|
|
121
|
+
// Register the service's communication key for encrypted message routing
|
|
122
|
+
if (advert.serviceCommunicationPk) {
|
|
123
|
+
this.#transport.registerPeer(advert.serviceDid, advert.serviceCommunicationPk);
|
|
124
|
+
}
|
|
125
|
+
const join = await this.#shouldJoin(advert);
|
|
126
|
+
if (!join)
|
|
127
|
+
return;
|
|
128
|
+
await this.#sendAll(this.session.joinCohort(advert.cohortId));
|
|
129
|
+
this.emit('cohort-joined', { cohortId: advert.cohortId });
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.emit('error', err);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Internal: handler for opt-in accept messages. Updates the session state accordingly.
|
|
137
|
+
* @param {BaseMessage} msg - The received opt-in accept message.
|
|
138
|
+
*/
|
|
139
|
+
#handleOptInAccept(msg) {
|
|
140
|
+
if (this.#stopped)
|
|
141
|
+
return;
|
|
142
|
+
try {
|
|
143
|
+
this.session.receive(msg);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
this.emit('error', err);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Internal: handler for cohort ready messages. Updates the session state, emits a 'cohort-ready'
|
|
151
|
+
* event, and triggers the update submission flow via the `onProvideUpdate` callback.
|
|
152
|
+
* @param {BaseMessage} msg - The received cohort ready message.
|
|
153
|
+
* @returns {Promise<void>} Resolves when processing is complete.
|
|
154
|
+
*/
|
|
155
|
+
async #handleCohortReady(msg) {
|
|
156
|
+
if (this.#stopped)
|
|
157
|
+
return;
|
|
158
|
+
try {
|
|
159
|
+
this.session.receive(msg);
|
|
160
|
+
const cohortId = msg.body?.cohortId;
|
|
161
|
+
if (!cohortId)
|
|
162
|
+
return;
|
|
163
|
+
const info = this.session.joinedCohorts.get(cohortId);
|
|
164
|
+
if (!info)
|
|
165
|
+
return;
|
|
166
|
+
this.emit('cohort-ready', { cohortId, beaconAddress: info.beaconAddress });
|
|
167
|
+
// Construct the signed update via caller callback and submit
|
|
168
|
+
const signedUpdate = await this.#onProvideUpdate({
|
|
169
|
+
cohortId,
|
|
170
|
+
beaconAddress: info.beaconAddress,
|
|
171
|
+
});
|
|
172
|
+
await this.#sendAll(this.session.submitUpdate(cohortId, signedUpdate));
|
|
173
|
+
this.emit('update-submitted', { cohortId });
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
this.emit('error', err);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Internal: handler for distribute aggregated data messages. Updates the session state, emits a
|
|
181
|
+
* 'validation-requested' event, and triggers the validation decision flow via the `onValidateData`
|
|
182
|
+
* callback. Depending on the decision, sends an approval or rejection message.
|
|
183
|
+
* @param {BaseMessage} msg - The received distribute aggregated data message.
|
|
184
|
+
* @returns {Promise<void>} Resolves when processing is complete.
|
|
185
|
+
* @throws {Error} If an error occurs during message processing or callback execution.
|
|
186
|
+
*/
|
|
187
|
+
async #handleDistributeData(msg) {
|
|
188
|
+
if (this.#stopped)
|
|
189
|
+
return;
|
|
190
|
+
try {
|
|
191
|
+
this.session.receive(msg);
|
|
192
|
+
const cohortId = msg.body?.cohortId;
|
|
193
|
+
if (!cohortId)
|
|
194
|
+
return;
|
|
195
|
+
const validation = this.session.pendingValidations.get(cohortId);
|
|
196
|
+
if (!validation)
|
|
197
|
+
return;
|
|
198
|
+
this.emit('validation-requested', validation);
|
|
199
|
+
const decision = await this.#onValidateData(validation);
|
|
200
|
+
if (decision.approved) {
|
|
201
|
+
await this.#sendAll(this.session.approveValidation(cohortId));
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
await this.#sendAll(this.session.rejectValidation(cohortId));
|
|
205
|
+
this.emit('cohort-failed', { cohortId, reason: 'Validation rejected by participant' });
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
this.emit('error', err);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Internal: handler for authorization request messages. Updates the session state, emits a
|
|
214
|
+
* 'signing-requested' event, and triggers the signing approval flow via the `onApproveSigning`
|
|
215
|
+
* callback. Depending on the decision, sends a nonce approval message or emits a 'cohort-failed'
|
|
216
|
+
* event.
|
|
217
|
+
* @param {BaseMessage} msg - The received authorization request message.
|
|
218
|
+
* @returns {Promise<void>} Resolves when processing is complete.
|
|
219
|
+
* @throws {Error} If an error occurs during message processing or callback execution.
|
|
220
|
+
*/
|
|
221
|
+
async #handleAuthorizationRequest(msg) {
|
|
222
|
+
if (this.#stopped)
|
|
223
|
+
return;
|
|
224
|
+
try {
|
|
225
|
+
this.session.receive(msg);
|
|
226
|
+
const cohortId = msg.body?.cohortId;
|
|
227
|
+
if (!cohortId)
|
|
228
|
+
return;
|
|
229
|
+
const req = this.session.pendingSigningRequests.get(cohortId);
|
|
230
|
+
if (!req)
|
|
231
|
+
return;
|
|
232
|
+
this.emit('signing-requested', req);
|
|
233
|
+
const decision = await this.#onApproveSigning(req);
|
|
234
|
+
if (!decision.approved) {
|
|
235
|
+
this.emit('cohort-failed', { cohortId, reason: 'Signing rejected by participant' });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
await this.#sendAll(this.session.approveNonce(cohortId));
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
this.emit('error', err);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Internal: handler for aggregated nonce messages. Updates the session state, triggers partial
|
|
246
|
+
* signature generation, and sends the partial signature to the aggregator. If the cohort reaches
|
|
247
|
+
* completion after processing the nonce, emits a 'cohort-complete' event.
|
|
248
|
+
* @param {BaseMessage} msg - The received aggregated nonce message.
|
|
249
|
+
* @returns {Promise<void>} Resolves when processing is complete.
|
|
250
|
+
* @throws {Error} If an error occurs during message processing or partial signature generation.
|
|
251
|
+
*/
|
|
252
|
+
async #handleAggregatedNonce(msg) {
|
|
253
|
+
if (this.#stopped)
|
|
254
|
+
return;
|
|
255
|
+
try {
|
|
256
|
+
this.session.receive(msg);
|
|
257
|
+
const cohortId = msg.body?.cohortId;
|
|
258
|
+
if (!cohortId)
|
|
259
|
+
return;
|
|
260
|
+
await this.#sendAll(this.session.generatePartialSignature(cohortId));
|
|
261
|
+
// Check if we've reached completion
|
|
262
|
+
if (this.session.getCohortPhase(cohortId) === ParticipantCohortPhase.Complete) {
|
|
263
|
+
const info = this.session.joinedCohorts.get(cohortId);
|
|
264
|
+
if (info) {
|
|
265
|
+
this.emit('cohort-complete', { cohortId, beaconAddress: info.beaconAddress });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
this.emit('error', err);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Internal: send helper to ensure messages are sent sequentially. This is important for protocol
|
|
275
|
+
* correctness, as some transports may not guarantee message order if sent in parallel.
|
|
276
|
+
* @param {BaseMessage[]} msgs - The messages to send.
|
|
277
|
+
* @returns {Promise<void>} Resolves when all messages have been sent.
|
|
278
|
+
* @throws {Error} If an error occurs during message sending.
|
|
279
|
+
*/
|
|
280
|
+
async #sendAll(msgs) {
|
|
281
|
+
for (const m of msgs) {
|
|
282
|
+
await this.#transport.sendMessage(m, this.#did, m.to);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=participant-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"participant-runner.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/participant-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EACL,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAkDvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,OAAO,4BAA6B,SAAQ,iBAA+C;IAC/F,sEAAsE;IAC7D,OAAO,CAAyB;IAEhC,UAAU,CAAY;IACtB,IAAI,CAAS;IACb,WAAW,CAAa;IACxB,gBAAgB,CAAkB;IAClC,eAAe,CAAiB;IAChC,iBAAiB,CAAmB;IAE7C,mBAAmB,GAAG,KAAK,CAAC;IAC5B,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAY,OAA4C;QACtD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,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CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,IAAmB;QAChC,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { COHORT_OPT_IN, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_UPDATE, VALIDATION_ACK, } from '../messages/constants.js';
|
|
2
|
+
import { ServiceCohortPhase } from '../phases.js';
|
|
3
|
+
import { AggregationService } from '../service.js';
|
|
4
|
+
import { TypedEventEmitter } from './typed-emitter.js';
|
|
5
|
+
/**
|
|
6
|
+
* High-level facade for running an Aggregation Service over a Transport.
|
|
7
|
+
*
|
|
8
|
+
* Wires the {@link AggregationService} state machine to a {@link Transport},
|
|
9
|
+
* encapsulating message handler registration, outgoing message dispatch,
|
|
10
|
+
* and decision callback orchestration.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const transport = new NostrTransport({ relays: [RELAY] });
|
|
15
|
+
* transport.registerActor(serviceDid, serviceKeys);
|
|
16
|
+
*
|
|
17
|
+
* const runner = new AggregationServiceRunner({
|
|
18
|
+
* transport,
|
|
19
|
+
* did: serviceDid,
|
|
20
|
+
* keys: serviceKeys,
|
|
21
|
+
* config: { minParticipants: 2, network: 'mutinynet', beaconType: 'CASBeacon' },
|
|
22
|
+
* onProvideTxData: async ({ beaconAddress, signalBytes }) => {
|
|
23
|
+
* return await buildBeaconTransaction(beaconAddress, signalBytes, bitcoin);
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* runner.on('keygen-complete', ({ beaconAddress }) => console.log(beaconAddress));
|
|
28
|
+
* runner.on('signing-complete', ({ signature }) => console.log('done'));
|
|
29
|
+
*
|
|
30
|
+
* const result = await runner.run();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* For full manual control, drop down to the underlying state machine via
|
|
34
|
+
* `runner.session`. The state machine has no transport coupling and exposes
|
|
35
|
+
* every protocol decision as an explicit method.
|
|
36
|
+
*
|
|
37
|
+
* @class AggregationServiceRunner
|
|
38
|
+
*/
|
|
39
|
+
export class AggregationServiceRunner extends TypedEventEmitter {
|
|
40
|
+
/** Direct access to the underlying state machine for advanced use. */
|
|
41
|
+
session;
|
|
42
|
+
#transport;
|
|
43
|
+
#did;
|
|
44
|
+
#config;
|
|
45
|
+
#onOptInReceived;
|
|
46
|
+
#onReadyToFinalize;
|
|
47
|
+
#onProvideTxData;
|
|
48
|
+
#cohortId;
|
|
49
|
+
#handlersRegistered = false;
|
|
50
|
+
#stopped = false;
|
|
51
|
+
#resolveRun;
|
|
52
|
+
#rejectRun;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
super();
|
|
55
|
+
this.#transport = options.transport;
|
|
56
|
+
this.#did = options.did;
|
|
57
|
+
this.#config = options.config;
|
|
58
|
+
this.#onOptInReceived = options.onOptInReceived ?? (async () => ({ accepted: true }));
|
|
59
|
+
this.#onReadyToFinalize = options.onReadyToFinalize ?? (async ({ acceptedCount, minRequired }) => ({
|
|
60
|
+
finalize: acceptedCount >= minRequired,
|
|
61
|
+
}));
|
|
62
|
+
this.#onProvideTxData = options.onProvideTxData;
|
|
63
|
+
this.session = new AggregationService({ did: options.did, keys: options.keys });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Run the protocol to completion. Resolves with the final aggregation result
|
|
67
|
+
* (signature + signed transaction) once signing is complete.
|
|
68
|
+
*
|
|
69
|
+
* @returns {Promise<AggregationResult>} The final result with signature and signed tx.
|
|
70
|
+
*/
|
|
71
|
+
run() {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
this.#resolveRun = resolve;
|
|
74
|
+
this.#rejectRun = reject;
|
|
75
|
+
try {
|
|
76
|
+
this.#registerHandlers();
|
|
77
|
+
this.#cohortId = this.session.createCohort(this.#config);
|
|
78
|
+
// Emit cohort-advertised BEFORE the send so the event fires before any downstream cascade
|
|
79
|
+
const advertMsgs = this.session.advertise(this.#cohortId);
|
|
80
|
+
this.emit('cohort-advertised', { cohortId: this.#cohortId });
|
|
81
|
+
this.#sendAll(advertMsgs).catch(err => this.#fail(err));
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
this.#fail(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stop the runner early. Cleans up internal state.
|
|
90
|
+
* Note: does not unregister transport handlers (the transport interface
|
|
91
|
+
* does not currently expose unregister).
|
|
92
|
+
*/
|
|
93
|
+
stop() {
|
|
94
|
+
this.#stopped = true;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Internal: handler registration with the transport. Idempotent.
|
|
98
|
+
*/
|
|
99
|
+
#registerHandlers() {
|
|
100
|
+
if (this.#handlersRegistered)
|
|
101
|
+
return;
|
|
102
|
+
this.#handlersRegistered = true;
|
|
103
|
+
this.#transport.registerMessageHandler(this.#did, COHORT_OPT_IN, this.#handleOptIn.bind(this));
|
|
104
|
+
this.#transport.registerMessageHandler(this.#did, SUBMIT_UPDATE, this.#handleSubmitUpdate.bind(this));
|
|
105
|
+
this.#transport.registerMessageHandler(this.#did, VALIDATION_ACK, this.#handleValidationAck.bind(this));
|
|
106
|
+
this.#transport.registerMessageHandler(this.#did, NONCE_CONTRIBUTION, this.#handleNonceContribution.bind(this));
|
|
107
|
+
this.#transport.registerMessageHandler(this.#did, SIGNATURE_AUTHORIZATION, this.#handleSignatureAuthorization.bind(this));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Internal: message handlers for each protocol step. Each handler:
|
|
111
|
+
* 1) feeds the message into the state machine via session.receive()
|
|
112
|
+
* 2) emits a high-level event for external observers
|
|
113
|
+
* 3) checks if the new state triggers any automatic next steps, and if so:
|
|
114
|
+
* a) calls the appropriate decision callback(s)
|
|
115
|
+
* b) sends any resulting messages from the state machine
|
|
116
|
+
* @param {BaseMessage} msg - The incoming message to handle.
|
|
117
|
+
* @returns {Promise<void>} Resolves when handling is complete.
|
|
118
|
+
* @throws {Error} If any step of handling fails, the error is emitted and the run promise is rejected.
|
|
119
|
+
* Note: if the runner has been stopped, handlers will ignore incoming messages.
|
|
120
|
+
*/
|
|
121
|
+
async #handleOptIn(msg) {
|
|
122
|
+
if (this.#stopped)
|
|
123
|
+
return;
|
|
124
|
+
try {
|
|
125
|
+
this.session.receive(msg);
|
|
126
|
+
const optIn = this.session.pendingOptIns(this.#cohortId).get(msg.from);
|
|
127
|
+
if (!optIn)
|
|
128
|
+
return;
|
|
129
|
+
this.emit('opt-in-received', optIn);
|
|
130
|
+
// Register peer key for encrypted messaging
|
|
131
|
+
if (optIn.communicationPk) {
|
|
132
|
+
this.#transport.registerPeer(msg.from, optIn.communicationPk);
|
|
133
|
+
}
|
|
134
|
+
const decision = await this.#onOptInReceived(optIn);
|
|
135
|
+
if (!decision.accepted)
|
|
136
|
+
return;
|
|
137
|
+
await this.#sendAll(this.session.acceptParticipant(this.#cohortId, msg.from));
|
|
138
|
+
this.emit('participant-accepted', { participantDid: msg.from });
|
|
139
|
+
// Check if it's time to finalize
|
|
140
|
+
const cohort = this.session.getCohort(this.#cohortId);
|
|
141
|
+
if (cohort.participants.length >= this.#config.minParticipants) {
|
|
142
|
+
const finalizeDecision = await this.#onReadyToFinalize({
|
|
143
|
+
acceptedCount: cohort.participants.length,
|
|
144
|
+
minRequired: this.#config.minParticipants,
|
|
145
|
+
});
|
|
146
|
+
if (finalizeDecision.finalize) {
|
|
147
|
+
// finalizeKeygen() computes the beacon address synchronously
|
|
148
|
+
// emit BEFORE awaiting sendAll. Otherwise the downstream cascade
|
|
149
|
+
// (which can run all the way to signing-complete) would resolve the
|
|
150
|
+
// run() promise before this event fires.
|
|
151
|
+
const readyMsgs = this.session.finalizeKeygen(this.#cohortId);
|
|
152
|
+
this.emit('keygen-complete', {
|
|
153
|
+
cohortId: this.#cohortId,
|
|
154
|
+
beaconAddress: cohort.beaconAddress,
|
|
155
|
+
});
|
|
156
|
+
await this.#sendAll(readyMsgs);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
this.#fail(err);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Handler for receiving participant updates. When all updates are received, automatically builds
|
|
166
|
+
* and distributes the data for validation.
|
|
167
|
+
* @param {BaseMessage} msg - The incoming message to handle.
|
|
168
|
+
* @returns {Promise<void>} Resolves when handling is complete.
|
|
169
|
+
* @throws {Error} If any step of handling fails, the error is emitted and the run promise is rejected.
|
|
170
|
+
* Note: if the runner has been stopped, handlers will ignore incoming messages.
|
|
171
|
+
*/
|
|
172
|
+
async #handleSubmitUpdate(msg) {
|
|
173
|
+
if (this.#stopped)
|
|
174
|
+
return;
|
|
175
|
+
try {
|
|
176
|
+
this.session.receive(msg);
|
|
177
|
+
this.emit('update-received', { participantDid: msg.from });
|
|
178
|
+
// When all updates collected, build and distribute
|
|
179
|
+
if (this.session.getCohortPhase(this.#cohortId) === ServiceCohortPhase.UpdatesCollected) {
|
|
180
|
+
const distributeMsgs = this.session.buildAndDistribute(this.#cohortId);
|
|
181
|
+
this.emit('data-distributed', { cohortId: this.#cohortId });
|
|
182
|
+
await this.#sendAll(distributeMsgs);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
this.#fail(err);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Handler for receiving validation acknowledgments. When all validations are received,
|
|
191
|
+
* automatically requests tx data and starts signing.
|
|
192
|
+
* @param {BaseMessage} msg - The incoming message to handle.
|
|
193
|
+
* @returns {Promise<void>} Resolves when handling is complete.
|
|
194
|
+
* @throws {Error} If any step of handling fails, the error is emitted and the run promise is rejected.
|
|
195
|
+
* Note: if the runner has been stopped, handlers will ignore incoming messages.
|
|
196
|
+
*/
|
|
197
|
+
async #handleValidationAck(msg) {
|
|
198
|
+
if (this.#stopped)
|
|
199
|
+
return;
|
|
200
|
+
try {
|
|
201
|
+
this.session.receive(msg);
|
|
202
|
+
const approved = !!msg.body?.approved;
|
|
203
|
+
this.emit('validation-received', { participantDid: msg.from, approved });
|
|
204
|
+
// When all validations received, request tx data and start signing
|
|
205
|
+
if (this.session.getCohortPhase(this.#cohortId) === ServiceCohortPhase.Validated) {
|
|
206
|
+
const cohort = this.session.getCohort(this.#cohortId);
|
|
207
|
+
const txData = await this.#onProvideTxData({
|
|
208
|
+
cohortId: this.#cohortId,
|
|
209
|
+
beaconAddress: cohort.beaconAddress,
|
|
210
|
+
signalBytes: cohort.signalBytes,
|
|
211
|
+
});
|
|
212
|
+
const authMsgs = this.session.startSigning(this.#cohortId, txData);
|
|
213
|
+
const sessionId = this.session.getSigningSessionId(this.#cohortId) ?? '';
|
|
214
|
+
this.emit('signing-started', { sessionId });
|
|
215
|
+
await this.#sendAll(authMsgs);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
this.#fail(err);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Handler for receiving nonce contributions and signature authorizations. When all nonces or
|
|
224
|
+
* signatures are received,
|
|
225
|
+
* @param {BaseMessage} msg - The incoming message to handle.
|
|
226
|
+
* @returns {Promise<void>} Resolves when handling is complete.
|
|
227
|
+
* @throws {Error} If any step of handling fails, the error is emitted and the run promise is rejected.
|
|
228
|
+
* Note: if the runner has been stopped, handlers will ignore incoming messages.
|
|
229
|
+
*/
|
|
230
|
+
async #handleNonceContribution(msg) {
|
|
231
|
+
if (this.#stopped)
|
|
232
|
+
return;
|
|
233
|
+
try {
|
|
234
|
+
this.session.receive(msg);
|
|
235
|
+
this.emit('nonce-received', { participantDid: msg.from });
|
|
236
|
+
// When all nonces collected, send aggregated nonce
|
|
237
|
+
if (this.session.getCohortPhase(this.#cohortId) === ServiceCohortPhase.NoncesCollected) {
|
|
238
|
+
await this.#sendAll(this.session.sendAggregatedNonce(this.#cohortId));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
this.#fail(err);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Handler for receiving signature authorizations. When all partial signatures are received, the
|
|
247
|
+
* session automatically completes and the final result is emitted and the run() promise is resolved.
|
|
248
|
+
* @param {BaseMessage} msg - The incoming message to handle.
|
|
249
|
+
* @returns {Promise<void>} Resolves when handling is complete.
|
|
250
|
+
* @throws {Error} If any step of handling fails, the error is emitted and the run promise is rejected.
|
|
251
|
+
* Note: if the runner has been stopped, handlers will ignore incoming messages.
|
|
252
|
+
*/
|
|
253
|
+
async #handleSignatureAuthorization(msg) {
|
|
254
|
+
if (this.#stopped)
|
|
255
|
+
return;
|
|
256
|
+
try {
|
|
257
|
+
this.session.receive(msg);
|
|
258
|
+
// The state machine auto-completes when all partial sigs received
|
|
259
|
+
const result = this.session.getResult(this.#cohortId);
|
|
260
|
+
if (result) {
|
|
261
|
+
this.emit('signing-complete', result);
|
|
262
|
+
this.#resolveRun?.(result);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
this.#fail(err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Internal: helper to send all messages sequentially. Catches and propagates errors.
|
|
271
|
+
* @param {BaseMessage[]} msgs - The messages to send.
|
|
272
|
+
* @returns {Promise<void>} Resolves when all messages have been sent.
|
|
273
|
+
* @throws {Error} If sending any message fails, the error is emitted and the run promise is
|
|
274
|
+
* rejected.
|
|
275
|
+
*/
|
|
276
|
+
async #sendAll(msgs) {
|
|
277
|
+
for (const m of msgs) {
|
|
278
|
+
await this.#transport.sendMessage(m, this.#did, m.to);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Internal: helper to handle errors. Emits an 'error' event and rejects the run promise.
|
|
283
|
+
* @param {Error} err - The error to handle.
|
|
284
|
+
*/
|
|
285
|
+
#fail(err) {
|
|
286
|
+
this.emit('error', err);
|
|
287
|
+
this.#rejectRun?.(err);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=service-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-runner.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/service-runner.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAMlD,OAAO,EACL,kBAAkB,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAiDvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAO,wBAAyB,SAAQ,iBAA2C;IACvF,sEAAsE;IAC7D,OAAO,CAAqB;IAE5B,UAAU,CAAY;IACtB,IAAI,CAAS;IACb,OAAO,CAAe;IACtB,gBAAgB,CAAkB;IAClC,kBAAkB,CAAoB;IACtC,gBAAgB,CAAkB;IAE3C,SAAS,CAAU;IACnB,mBAAmB,GAAG,KAAK,CAAC;IAC5B,QAAQ,GAAG,KAAK,CAAC;IACjB,WAAW,CAAuC;IAClD,UAAU,CAAwB;IAElC,YAAY,OAAwC;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,IAAI,GA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