@did-btcr2/aggregation 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +14 -14
- package/dist/browser.mjs +14 -14
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/service/index.js +1 -1
- package/dist/esm/core/cohort.js.map +1 -1
- package/dist/esm/participant/participant.js.map +1 -1
- package/dist/esm/service/service.js +1 -1
- package/dist/esm/service/service.js.map +1 -1
- package/dist/types/core/beacon-strategy.d.ts +2 -2
- package/dist/types/core/beacon-strategy.d.ts.map +1 -1
- package/dist/types/core/cohort.d.ts +3 -3
- package/dist/types/core/cohort.d.ts.map +1 -1
- package/dist/types/participant/participant-runner.d.ts +2 -2
- package/dist/types/participant/participant-runner.d.ts.map +1 -1
- package/dist/types/participant/participant.d.ts +2 -2
- package/dist/types/participant/participant.d.ts.map +1 -1
- package/dist/types/service/service.d.ts +2 -2
- package/dist/types/service/service.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/core/beacon-strategy.ts +2 -2
- package/src/core/cohort.ts +3 -3
- package/src/participant/participant-runner.ts +2 -2
- package/src/participant/participant.ts +3 -3
- package/src/service/service.ts +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SecuredDocument } from '@did-btcr2/cryptosuite';
|
|
2
2
|
import type { SchnorrKeyPair } from '@did-btcr2/keypair';
|
|
3
3
|
import type { BaseMessage } from '../core/messages/base.js';
|
|
4
4
|
import {
|
|
@@ -30,7 +30,7 @@ export type ShouldJoin = (advert: CohortAdvert) => Promise<boolean>;
|
|
|
30
30
|
export type OnProvideUpdate = (info: {
|
|
31
31
|
cohortId: string;
|
|
32
32
|
beaconAddress: string;
|
|
33
|
-
}) => Promise<
|
|
33
|
+
}) => Promise<SecuredDocument | null>;
|
|
34
34
|
|
|
35
35
|
/** Decision callback: approve or reject aggregated data. */
|
|
36
36
|
export type OnValidateData = (info: PendingValidation) => Promise<{ approved: boolean }>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { canonicalHash } from '@did-btcr2/common';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SecuredDocument } from '@did-btcr2/cryptosuite';
|
|
3
3
|
import type { SerializedSMTProof} from '@did-btcr2/smt';
|
|
4
4
|
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
5
5
|
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
@@ -126,7 +126,7 @@ interface ParticipantCohortState {
|
|
|
126
126
|
serviceDid: string;
|
|
127
127
|
advert?: CohortAdvert;
|
|
128
128
|
cohort?: AggregationCohort;
|
|
129
|
-
submittedUpdate?:
|
|
129
|
+
submittedUpdate?: SecuredDocument;
|
|
130
130
|
/**
|
|
131
131
|
* This round's intent, persisted because the phase advances past
|
|
132
132
|
* NonIncluded/UpdateSubmitted into validation/signing. true = submitted an
|
|
@@ -339,7 +339,7 @@ export class AggregationParticipant {
|
|
|
339
339
|
* User action: submit a signed BTCR2 update for inclusion in the cohort's
|
|
340
340
|
* aggregated signal.
|
|
341
341
|
*/
|
|
342
|
-
public submitUpdate(cohortId: string, signedUpdate:
|
|
342
|
+
public submitUpdate(cohortId: string, signedUpdate: SecuredDocument): BaseMessage[] {
|
|
343
343
|
const state = this.#cohortStates.get(cohortId);
|
|
344
344
|
if(!state || state.phase !== ParticipantCohortPhase.CohortReady) {
|
|
345
345
|
throw new AggregationParticipantError(
|
package/src/service/service.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { canonicalize } from '@did-btcr2/common';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SecuredDocument } from '@did-btcr2/cryptosuite';
|
|
3
3
|
import { BIP340Cryptosuite, SchnorrMultikey } from '@did-btcr2/cryptosuite';
|
|
4
4
|
import type { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
5
5
|
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
@@ -429,7 +429,7 @@ export class AggregationService {
|
|
|
429
429
|
|
|
430
430
|
|
|
431
431
|
/** Updates collected so far for a cohort. */
|
|
432
|
-
collectedUpdates(cohortId: string): ReadonlyMap<string,
|
|
432
|
+
collectedUpdates(cohortId: string): ReadonlyMap<string, SecuredDocument> {
|
|
433
433
|
const state = this.#cohortStates.get(cohortId);
|
|
434
434
|
if(!state) return new Map();
|
|
435
435
|
return state.cohort.pendingUpdates;
|
|
@@ -449,7 +449,7 @@ export class AggregationService {
|
|
|
449
449
|
if(!state) return;
|
|
450
450
|
if(state.phase !== ServiceCohortPhase.CohortSet && state.phase !== ServiceCohortPhase.CollectingUpdates) return;
|
|
451
451
|
|
|
452
|
-
const signedUpdate = message.body?.signedUpdate as
|
|
452
|
+
const signedUpdate = message.body?.signedUpdate as SecuredDocument | undefined;
|
|
453
453
|
if(!signedUpdate) {
|
|
454
454
|
state.rejections.push({
|
|
455
455
|
from : message.from,
|
|
@@ -572,13 +572,13 @@ export class AggregationService {
|
|
|
572
572
|
* signature fails verification.
|
|
573
573
|
* @param {ServiceCohortState} state - the current state of the cohort to which the update was submitted
|
|
574
574
|
* @param {string} sender - the DID of the participant who submitted the update
|
|
575
|
-
* @param {
|
|
575
|
+
* @param {SecuredDocument} signedUpdate - the signed update containing the proof to verify
|
|
576
576
|
* @returns {boolean} - `true` if the proof is valid and the update can be accepted; `false` otherwise
|
|
577
577
|
*/
|
|
578
578
|
#verifySubmittedUpdate(
|
|
579
579
|
state: ServiceCohortState,
|
|
580
580
|
sender: string,
|
|
581
|
-
signedUpdate:
|
|
581
|
+
signedUpdate: SecuredDocument,
|
|
582
582
|
): boolean {
|
|
583
583
|
const proof = signedUpdate.proof;
|
|
584
584
|
if(!proof?.verificationMethod || !proof.proofValue) return false;
|