Skip to content

Commit

Permalink
remove redundant DkgRitualParameters struct
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Sep 12, 2023
1 parent 1dba09f commit e1a0cd1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
31 changes: 15 additions & 16 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@ import { BigNumberish, ethers } from 'ethers';

import { DkgCoordinatorAgent, DkgRitualState } from './agents/coordinator';
import { ChecksumAddress } from './types';
import { fromHexString, objectEquals } from './utils';

export type DkgRitualParameters = {
sharesNum: number;
threshold: number;
};
import { fromHexString } from './utils';

export interface DkgRitualJSON {
id: number;
dkgPublicKey: Uint8Array;
dkgParams: DkgRitualParameters;
sharesNum: number;
threshold: number;
state: DkgRitualState;
}

export class DkgRitual {
constructor(
public readonly id: number,
public readonly dkgPublicKey: DkgPublicKey,
public readonly dkgParams: DkgRitualParameters,
public readonly sharesNum: number,
public readonly threshold: number,
public readonly state: DkgRitualState
) {}

public toObj(): DkgRitualJSON {
return {
id: this.id,
dkgPublicKey: this.dkgPublicKey.toBytes(),
dkgParams: this.dkgParams,
sharesNum: this.sharesNum,
threshold: this.threshold,
state: this.state,
};
}

public static fromObj({
id,
dkgPublicKey,
dkgParams,
sharesNum,
threshold,
state,
}: DkgRitualJSON): DkgRitual {
return new DkgRitual(
id,
DkgPublicKey.fromBytes(dkgPublicKey),
dkgParams,
sharesNum,
threshold,
state
);
}
Expand All @@ -52,7 +52,8 @@ export class DkgRitual {
return [
this.id === other.id,
this.dkgPublicKey.equals(other.dkgPublicKey),
objectEquals(this.dkgParams, other.dkgParams),
this.sharesNum === other.sharesNum,
this.threshold === other.threshold,
this.state === other.state,
].every(Boolean);
}
Expand Down Expand Up @@ -128,10 +129,8 @@ export class DkgClient {
return new DkgRitual(
ritualId,
DkgPublicKey.fromBytes(dkgPkBytes),
{
sharesNum: ritual.dkgSize,
threshold: ritual.threshold,
},
ritual.dkgSize,
ritual.threshold,
ritualState
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/strategy/cbd-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class DeployedCbdStrategy {
const decrypter = ThresholdDecrypter.create(
porterUri,
dkgRitual.id,
dkgRitual.dkgParams.threshold
dkgRitual.threshold
);
return new DeployedCbdStrategy(decrypter, dkgRitual.dkgPublicKey);
}
Expand Down
2 changes: 1 addition & 1 deletion src/taco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const decrypt = async (
const decrypter = ThresholdDecrypter.create(
porterUri,
ritualId,
ritual.dkgParams.threshold
ritual.threshold
);
return decrypter.retrieveAndDecrypt(provider, messageKit, signer);
};
Expand Down
6 changes: 2 additions & 4 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,8 @@ export const fakeDkgRitual = (ritual: {
return new DkgRitual(
fakeRitualId,
ritual.dkg.publicKey(),
{
sharesNum: ritual.sharesNum,
threshold: ritual.threshold,
},
ritual.sharesNum,
ritual.threshold,
DkgRitualState.FINALIZED
);
};
Expand Down

0 comments on commit e1a0cd1

Please sign in to comment.