@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.
@@ -1,4 +1,4 @@
1
- import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
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<SignedBTCR2Update | null>;
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 { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
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?: SignedBTCR2Update;
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: SignedBTCR2Update): BaseMessage[] {
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(
@@ -1,5 +1,5 @@
1
1
  import { canonicalize } from '@did-btcr2/common';
2
- import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
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, SignedBTCR2Update> {
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 SignedBTCR2Update | undefined;
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 {SignedBTCR2Update} signedUpdate - the signed update containing the proof to verify
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: SignedBTCR2Update,
581
+ signedUpdate: SecuredDocument,
582
582
  ): boolean {
583
583
  const proof = signedUpdate.proof;
584
584
  if(!proof?.verificationMethod || !proof.proofValue) return false;