@did-btcr2/method 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +460 -223
- package/dist/browser.mjs +460 -223
- package/dist/cjs/index.js +461 -223
- package/dist/esm/core/aggregation/cohort.js +3 -1
- package/dist/esm/core/aggregation/cohort.js.map +1 -1
- package/dist/esm/core/aggregation/conditions.js +75 -0
- package/dist/esm/core/aggregation/conditions.js.map +1 -0
- package/dist/esm/core/aggregation/messages/base.js.map +1 -1
- package/dist/esm/core/aggregation/messages/bodies.js +16 -2
- package/dist/esm/core/aggregation/messages/bodies.js.map +1 -1
- package/dist/esm/core/aggregation/messages/factories.js.map +1 -1
- package/dist/esm/core/aggregation/participant.js +20 -7
- package/dist/esm/core/aggregation/participant.js.map +1 -1
- package/dist/esm/core/aggregation/runner/participant-runner.js +37 -2
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
- package/dist/esm/core/aggregation/runner/service-runner.js +323 -189
- package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -1
- package/dist/esm/core/aggregation/service.js +23 -3
- package/dist/esm/core/aggregation/service.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/aggregation/cohort.d.ts.map +1 -1
- package/dist/types/core/aggregation/conditions.d.ts +58 -0
- package/dist/types/core/aggregation/conditions.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/base.d.ts +2 -3
- package/dist/types/core/aggregation/messages/base.d.ts.map +1 -1
- package/dist/types/core/aggregation/messages/bodies.d.ts +2 -3
- package/dist/types/core/aggregation/messages/bodies.d.ts.map +1 -1
- package/dist/types/core/aggregation/messages/factories.d.ts +2 -3
- package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -1
- package/dist/types/core/aggregation/participant.d.ts +16 -4
- package/dist/types/core/aggregation/participant.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/events.d.ts +22 -11
- package/dist/types/core/aggregation/runner/events.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +21 -12
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/service-runner.d.ts +76 -22
- package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -1
- package/dist/types/core/aggregation/service.d.ts +8 -4
- package/dist/types/core/aggregation/service.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/aggregation/cohort.ts +3 -1
- package/src/core/aggregation/conditions.ts +116 -0
- package/src/core/aggregation/messages/base.ts +6 -3
- package/src/core/aggregation/messages/bodies.ts +18 -6
- package/src/core/aggregation/messages/factories.ts +2 -3
- package/src/core/aggregation/participant.ts +28 -11
- package/src/core/aggregation/runner/events.ts +23 -14
- package/src/core/aggregation/runner/participant-runner.ts +43 -13
- package/src/core/aggregation/runner/service-runner.ts +375 -195
- package/src/core/aggregation/service.ts +39 -7
- package/src/index.ts +1 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
2
2
|
import type { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
|
-
import type { SerializedSMTProof } from '@did-btcr2/smt';
|
|
4
3
|
import type { BaseMessage } from '../messages/base.js';
|
|
5
4
|
import {
|
|
6
5
|
AGGREGATED_NONCE,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
import { ParticipantCohortPhase } from '../phases.js';
|
|
21
20
|
import { KeyPairAggregationSigner } from '../signer.js';
|
|
22
21
|
import type { Transport } from '../transport/transport.js';
|
|
23
|
-
import type { AggregationParticipantEvents } from './events.js';
|
|
22
|
+
import type { AggregationParticipantEvents, CohortCompleteInfo } from './events.js';
|
|
24
23
|
import { TypedEventEmitter } from './typed-emitter.js';
|
|
25
24
|
|
|
26
25
|
/** Decision callback: filter discovered cohorts. Default rejects all. */
|
|
@@ -175,19 +174,12 @@ export class AggregationParticipantRunner extends TypedEventEmitter<AggregationP
|
|
|
175
174
|
|
|
176
175
|
/**
|
|
177
176
|
* Single-shot helper: start, join the first cohort that passes `shouldJoin`,
|
|
178
|
-
* drive it to completion, and resolve. Convenient for tests and demos.
|
|
177
|
+
* drive it to completion, and resolve. Convenient for tests and demos. The
|
|
178
|
+
* single-cohort special case of {@link joinMatching} (count = 1).
|
|
179
179
|
*/
|
|
180
180
|
static async joinFirst(
|
|
181
181
|
options: AggregationParticipantRunnerOptions
|
|
182
|
-
): Promise<{
|
|
183
|
-
cohortId: string;
|
|
184
|
-
beaconAddress: string;
|
|
185
|
-
beaconType: string;
|
|
186
|
-
/** DID → base64url update hash. Populated only for CAS beacons. */
|
|
187
|
-
casAnnouncement?: Record<string, string>;
|
|
188
|
-
/** Merkle inclusion proof for this participant's slot. Populated only for SMT beacons. */
|
|
189
|
-
smtProof?: SerializedSMTProof;
|
|
190
|
-
}> {
|
|
182
|
+
): Promise<CohortCompleteInfo> {
|
|
191
183
|
return new Promise((resolve, reject) => {
|
|
192
184
|
const runner = new AggregationParticipantRunner(options);
|
|
193
185
|
runner.once('cohort-complete', (info) => {
|
|
@@ -199,6 +191,41 @@ export class AggregationParticipantRunner extends TypedEventEmitter<AggregationP
|
|
|
199
191
|
});
|
|
200
192
|
}
|
|
201
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Multi-cohort helper: start, join EVERY cohort whose advert passes
|
|
196
|
+
* `shouldJoin`, drive each to completion in parallel, and resolve once
|
|
197
|
+
* `count` cohorts have completed (the runner stops at that point). The
|
|
198
|
+
* N-cohort generalization of {@link joinFirst}, for a participant that joins
|
|
199
|
+
* several cohorts advertised by one service.
|
|
200
|
+
*
|
|
201
|
+
* For an open-ended, long-lived subscriber (no fixed count), construct an
|
|
202
|
+
* {@link AggregationParticipantRunner} directly, set `shouldJoin`, call
|
|
203
|
+
* `start()`, and listen for `cohort-complete` — the runner already drives
|
|
204
|
+
* any number of cohorts concurrently.
|
|
205
|
+
*
|
|
206
|
+
* @param options Participant runner options (set `shouldJoin` to select cohorts).
|
|
207
|
+
* @param count Number of completed cohorts to collect before resolving.
|
|
208
|
+
* @returns The {@link CohortCompleteInfo} for each completed cohort, in completion order.
|
|
209
|
+
*/
|
|
210
|
+
static async joinMatching(
|
|
211
|
+
options: AggregationParticipantRunnerOptions,
|
|
212
|
+
count: number,
|
|
213
|
+
): Promise<CohortCompleteInfo[]> {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
const runner = new AggregationParticipantRunner(options);
|
|
216
|
+
const completed: CohortCompleteInfo[] = [];
|
|
217
|
+
runner.on('cohort-complete', (info) => {
|
|
218
|
+
completed.push(info);
|
|
219
|
+
if(completed.length >= count) {
|
|
220
|
+
runner.stop();
|
|
221
|
+
resolve(completed);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
runner.on('error', reject);
|
|
225
|
+
runner.start().catch(reject);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
202
229
|
/**
|
|
203
230
|
* Internal: handler registration with the transport. Idempotent and safe to call multiple times,
|
|
204
231
|
* but only registers handlers once.
|
|
@@ -376,7 +403,10 @@ export class AggregationParticipantRunner extends TypedEventEmitter<AggregationP
|
|
|
376
403
|
if (info) {
|
|
377
404
|
// Surface the sidecar data the participant will need for future resolutions:
|
|
378
405
|
// the CAS Announcement map (CAS beacons) or their SMT inclusion proof.
|
|
379
|
-
|
|
406
|
+
// Read via getValidation (not pendingValidations, which lists only the
|
|
407
|
+
// AwaitingValidation phase) so the sidecar is still available now that
|
|
408
|
+
// the cohort has reached Complete.
|
|
409
|
+
const validation = this.session.getValidation(cohortId);
|
|
380
410
|
this.emit('cohort-complete', {
|
|
381
411
|
cohortId,
|
|
382
412
|
beaconAddress : info.beaconAddress,
|