Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Aug 2, 2023
1 parent 6d513bb commit 300696b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
69 changes: 33 additions & 36 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { ethers } from 'ethers';

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

export function getVariantClass(
variant: FerveoVariant,
variant: FerveoVariant
): typeof DecryptionShareSimple | typeof DecryptionSharePrecomputed {
if (variant.equals(FerveoVariant.simple)) {
return DecryptionShareSimple;
Expand All @@ -31,9 +31,9 @@ export function getVariantClass(
}

export function getCombineDecryptionSharesFunction(
variant: FerveoVariant,
variant: FerveoVariant
): (
shares: DecryptionShareSimple[] | DecryptionSharePrecomputed[],
shares: DecryptionShareSimple[] | DecryptionSharePrecomputed[]
) => SharedSecret {
if (variant.equals(FerveoVariant.simple)) {
return combineDecryptionSharesSimple;
Expand Down Expand Up @@ -61,9 +61,8 @@ export class DkgRitual {
public readonly id: number,
public readonly dkgPublicKey: DkgPublicKey,
public readonly dkgParams: DkgRitualParameters,
public readonly state: DkgRitualState,
) {
}
public readonly state: DkgRitualState
) {}

public toObj(): DkgRitualJSON {
return {
Expand All @@ -75,27 +74,26 @@ export class DkgRitual {
}

public static fromObj({
id,
dkgPublicKey,
dkgParams,
state,
}: DkgRitualJSON): DkgRitual {
id,
dkgPublicKey,
dkgParams,
state,
}: DkgRitualJSON): DkgRitual {
return new DkgRitual(
id,
DkgPublicKey.fromBytes(dkgPublicKey),
dkgParams,
state,
state
);
}

public equals(other: DkgRitual): boolean {
return (
this.id === other.id &&
// TODO: Replace with `equals` after https://github.com/nucypher/nucypher-core/issues/56 is fixed
bytesEquals(this.dkgPublicKey.toBytes(), other.dkgPublicKey.toBytes()) &&
objectEquals(this.dkgParams, other.dkgParams) &&
this.state === other.state
);
return [
this.id === other.id,
this.dkgPublicKey.equals(other.dkgPublicKey),
objectEquals(this.dkgParams, other.dkgParams),
this.state === other.state,
].every(Boolean);
}
}

Expand All @@ -108,25 +106,25 @@ export class DkgClient {
public static async initializeRitual(
web3Provider: ethers.providers.Web3Provider,
ursulas: ChecksumAddress[],
waitUntilEnd = false,
waitUntilEnd = false
): Promise<number | undefined> {
const ritualId = await DkgCoordinatorAgent.initializeRitual(
web3Provider,
ursulas.sort(),
ursulas.sort()
);

if (waitUntilEnd) {
const isSuccessful = await DkgClient.waitUntilRitualEnd(
web3Provider,
ritualId,
ritualId
);
if (!isSuccessful) {
const ritualState = await DkgCoordinatorAgent.getRitualState(
web3Provider,
ritualId,
ritualId
);
throw new Error(
`Ritual initialization failed. Ritual id ${ritualId} is in state ${ritualState}`,
`Ritual initialization failed. Ritual id ${ritualId} is in state ${ritualState}`
);
}
}
Expand All @@ -136,7 +134,7 @@ export class DkgClient {

private static waitUntilRitualEnd = async (
web3Provider: ethers.providers.Web3Provider,
ritualId: number,
ritualId: number
): Promise<boolean> => {
return new Promise((resolve, reject) => {
const callback = (successful: boolean) => {
Expand All @@ -152,11 +150,11 @@ export class DkgClient {

public static async getExistingRitual(
web3Provider: ethers.providers.Web3Provider,
ritualId: number,
ritualId: number
): Promise<DkgRitual> {
const ritualState = await DkgCoordinatorAgent.getRitualState(
web3Provider,
ritualId,
ritualId
);
const ritual = await DkgCoordinatorAgent.getRitual(web3Provider, ritualId);
const dkgPkBytes = new Uint8Array([
Expand All @@ -170,19 +168,18 @@ export class DkgClient {
sharesNum: ritual.dkgSize,
threshold: assumedThreshold(ritual.dkgSize),
},
ritualState,
ritualState
);
}


public static async verifyRitual(
web3Provider: ethers.providers.Web3Provider,
ritualId: number,
ritualId: number
): Promise<boolean> {
const ritual = await DkgCoordinatorAgent.getRitual(web3Provider, ritualId);
const participants = await DkgCoordinatorAgent.getParticipants(
web3Provider,
ritualId,
ritualId
);

const validatorMessages = participants.map((p) => {
Expand All @@ -204,13 +201,13 @@ export class DkgClient {
const participantPublicKeys: Record<string, FerveoPublicKey> = {
'0x210eeAC07542F815ebB6FD6689637D8cA2689392': FerveoPublicKey.fromBytes(
fromHexString(
'ace9d7567b26dafc512b2303cfdaa872850c62b100078ddeaabf8408c7308b3a43dfeb88375c21ef63230fb4008ce7e908764463c6765e556f9b03009eb1757d179eaa26bf875332807cc070d62a385ed2e66e09f4f4766451da12779a09036e',
),
'ace9d7567b26dafc512b2303cfdaa872850c62b100078ddeaabf8408c7308b3a43dfeb88375c21ef63230fb4008ce7e908764463c6765e556f9b03009eb1757d179eaa26bf875332807cc070d62a385ed2e66e09f4f4766451da12779a09036e'
)
),
'0xb15d5A4e2be34f4bE154A1b08a94Ab920FfD8A41': FerveoPublicKey.fromBytes(
fromHexString(
'8b373fdb6b43e9dca028bd603c2bf90f0e008ec83ff217a8d7bc006b585570e6ab1ce761bad0e21c1aed1363286145f61134ed0ab53f4ebaa05036396c57f6e587f33d49667c1003cd03b71ad651b09dd4791bc631eaef93f1b313bbee7bd63a',
),
'8b373fdb6b43e9dca028bd603c2bf90f0e008ec83ff217a8d7bc006b585570e6ab1ce761bad0e21c1aed1363286145f61134ed0ab53f4ebaa05036396c57f6e587f33d49667c1003cd03b71ad651b09dd4791bc631eaef93f1b313bbee7bd63a'
)
),
};

Expand Down
4 changes: 2 additions & 2 deletions src/porter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
import axios, { AxiosResponse } from 'axios';
import qs from 'qs';

import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from '../types';
import { fromBase64, fromHexString, toBase64, toHexString } from '../utils';
import { Base64EncodedBytes, ChecksumAddress, HexEncodedBytes } from './types';
import { fromBase64, fromHexString, toBase64, toHexString } from './utils';

type Network = 'mainnet' | 'tapir' | 'oryx' | 'lynx';

Expand Down
3 changes: 1 addition & 2 deletions src/sdk/strategy/cbd-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ export class DeployedCbdStrategy {
porterUri: string,
ritualId: number
): Promise<DeployedCbdStrategy> {
const dkgClient = new DkgClient(provider);
const dkgRitual = await dkgClient.getExistingRitual(ritualId);
const dkgRitual = await DkgClient.getExistingRitual(provider, ritualId);
return DeployedCbdStrategy.create(dkgRitual, porterUri);
}

Expand Down
13 changes: 3 additions & 10 deletions src/sdk/strategy/pre-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Enrico } from '../../characters/enrico';
import { PreDecrypter, PreDecrypterJSON } from '../../characters/pre-recipient';
import { ConditionExpression } from '../../conditions';
import { EnactedPolicy } from '../../policies/policy';
import { base64ToU8Receiver, bytesEquals, toJSON } from '../../utils';
import { base64ToU8Receiver, toJSON } from '../../utils';
import { Cohort, CohortJSON } from '../cohort';

export type PreStrategyJSON = {
Expand Down Expand Up @@ -133,15 +133,8 @@ export class PreStrategy {
public equals(other: PreStrategy) {
return [
this.cohort.equals(other.cohort),
// TODO: Replace with `equals` after https://github.com/nucypher/rust-umbral/pull/125 is released
bytesEquals(
this.aliceSecretKey.toBEBytes(),
other.aliceSecretKey.toBEBytes()
),
bytesEquals(
this.bobSecretKey.toBEBytes(),
other.bobSecretKey.toBEBytes()
),
this.aliceSecretKey.equals(other.aliceSecretKey),
this.bobSecretKey.equals(other.bobSecretKey),
this.startDate.toString() === other.startDate.toString(),
this.endDate.toString() === other.endDate.toString(),
].every(Boolean);
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
DkgRitualState,
} from '../src/agents/coordinator';
import { ThresholdDecrypter } from '../src/characters/cbd-recipient';
import { DkgClient, DkgRitual, FerveoVariant } from '../src/dkg';
import { DkgClient, DkgRitual } from '../src/dkg';
import { BlockchainPolicy, PreEnactedPolicy } from '../src/policies/policy';
import {
CbdDecryptResult,
Expand Down

2 comments on commit 300696b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled size for the package is listed below:

build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module/src/policies: 19.53 KB
build/module/src/characters: 78.13 KB
build/module/src/agents: 39.06 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 42.97 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions: 156.25 KB
build/module/src/kits: 19.53 KB
build/module/src: 437.50 KB
build/module: 648.44 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main/src/policies: 19.53 KB
build/main/src/characters: 78.13 KB
build/main/src/agents: 39.06 KB
build/main/src/sdk/strategy: 35.16 KB
build/main/src/sdk: 46.88 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions: 156.25 KB
build/main/src/kits: 19.53 KB
build/main/src: 445.31 KB
build/main: 656.25 KB
build: 1.28 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled size for the package is listed below:

build/module/src/kits: 19.53 KB
build/module/src/characters: 78.13 KB
build/module/src/policies: 19.53 KB
build/module/src/agents: 39.06 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions: 156.25 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 42.97 KB
build/module/src: 437.50 KB
build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module: 648.44 KB
build/main/src/kits: 19.53 KB
build/main/src/characters: 78.13 KB
build/main/src/policies: 19.53 KB
build/main/src/agents: 39.06 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions: 156.25 KB
build/main/src/sdk/strategy: 35.16 KB
build/main/src/sdk: 46.88 KB
build/main/src: 445.31 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main: 656.25 KB
build: 1.28 MB

Please sign in to comment.