Skip to content

Commit

Permalink
chore(deps): update to nucypher-core@0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 13, 2023
1 parent 49fa8ab commit 7132cab
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 278 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"prebuild": "yarn typechain"
},
"dependencies": {
"@nucypher/nucypher-core": "^0.10.0",
"@nucypher/nucypher-core": "file:../nucypher-core/nucypher-core-wasm/pkg",
"axios": "^0.21.1",
"deep-equal": "^2.2.1",
"ethers": "^5.4.1",
Expand Down
8 changes: 4 additions & 4 deletions src/characters/cbd-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
decryptWithSharedSecret,
EncryptedThresholdDecryptionRequest,
EncryptedThresholdDecryptionResponse,
FerveoVariant,
SessionSharedSecret,
SessionStaticSecret,
ThresholdDecryptionRequest,
Expand All @@ -21,7 +22,6 @@ import { ConditionExpression } from '../conditions';
import {
DkgClient,
DkgRitual,
FerveoVariant,
getCombineDecryptionSharesFunction,
getVariantClass,
} from '../dkg';
Expand Down Expand Up @@ -82,7 +82,7 @@ export class CbdTDecDecrypter {
public async retrieve(
web3Provider: ethers.providers.Web3Provider,
conditionExpr: ConditionExpression,
variant: number,
variant: FerveoVariant,
ciphertext: Ciphertext,
verifyRitual = true
): Promise<DecryptionSharePrecomputed[] | DecryptionShareSimple[]> {
Expand Down Expand Up @@ -145,7 +145,7 @@ export class CbdTDecDecrypter {
private makeDecryptionShares(
encryptedResponses: Record<string, EncryptedThresholdDecryptionResponse>,
sessionSharedSecret: Record<string, SessionSharedSecret>,
variant: number,
variant: FerveoVariant,
expectedRitualId: number
) {
const decryptedResponses = Object.entries(encryptedResponses).map(
Expand All @@ -171,7 +171,7 @@ export class CbdTDecDecrypter {

private makeDecryptionRequests(
ritualId: number,
variant: number,
variant: FerveoVariant,
ciphertext: Ciphertext,
conditionExpr: ConditionExpression,
contextStr: string,
Expand Down
33 changes: 13 additions & 20 deletions src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DecryptionShareSimple,
DkgPublicKey,
EthereumAddress,
FerveoVariant,
FerveoPublicKey,
SharedSecret,
Validator,
Expand All @@ -17,22 +18,15 @@ import { DkgCoordinatorAgent, DkgRitualState } from './agents/coordinator';
import { ChecksumAddress } from './types';
import { bytesEquals, fromHexString, objectEquals } from './utils';

// TODO: Expose from @nucypher/nucypher-core
export enum FerveoVariant {
Simple = 0,
Precomputed = 1,
}

export function getVariantClass(
variant: FerveoVariant
): typeof DecryptionShareSimple | typeof DecryptionSharePrecomputed {
switch (variant) {
case FerveoVariant.Simple:
return DecryptionShareSimple;
case FerveoVariant.Precomputed:
return DecryptionSharePrecomputed;
default:
throw new Error(`Invalid FerveoVariant: ${variant}`);
if (variant.equals(FerveoVariant.simple)) {
return DecryptionShareSimple;
} else if (variant.equals(FerveoVariant.precomputed)) {
return DecryptionSharePrecomputed;
} else {
throw new Error(`Invalid FerveoVariant: ${variant}`);
}
}

Expand All @@ -41,13 +35,12 @@ export function getCombineDecryptionSharesFunction(
): (
shares: DecryptionShareSimple[] | DecryptionSharePrecomputed[]
) => SharedSecret {
switch (variant) {
case FerveoVariant.Simple:
return combineDecryptionSharesSimple;
case FerveoVariant.Precomputed:
return combineDecryptionSharesPrecomputed;
default:
throw new Error(`Invalid FerveoVariant: ${variant}`);
if (variant.equals(FerveoVariant.simple)) {
return combineDecryptionSharesSimple;
} else if (variant.equals(FerveoVariant.precomputed)) {
return combineDecryptionSharesPrecomputed;
} else {
throw new Error(`Invalid FerveoVariant: ${variant}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as conditions from './conditions';
export { conditions, CustomContextParam };

// DKG
export { FerveoVariant } from './dkg';
export { FerveoVariant } from '@nucypher/nucypher-core';

// SDK
export { Cohort } from './sdk/cohort';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cbd-strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ownsNFT = new ERC721Ownership({
});
const conditionExpr = new ConditionExpression(ownsNFT);
const ursulas = fakeUrsulas();
const variant = FerveoVariant.Precomputed;
const variant = FerveoVariant.precomputed;
const ritualId = 0;

const makeCbdStrategy = async () => {
Expand Down
25 changes: 15 additions & 10 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EncryptedTreasureMap,
EthereumAddress,
ferveoEncrypt,
FerveoVariant,
FerveoPublicKey,
Keypair,
PublicKey,
Expand Down Expand Up @@ -51,7 +52,7 @@ import {
RetrieveCFragsResult,
Ursula,
} from '../src/characters/porter';
import { DkgClient, DkgRitual, FerveoVariant } from '../src/dkg';
import { DkgClient, DkgRitual } from '../src/dkg';
import { BlockchainPolicy, PreEnactedPolicy } from '../src/policies/policy';
import { ChecksumAddress } from '../src/types';
import { toBytes, toHexString, zip } from '../src/utils';
Expand Down Expand Up @@ -219,14 +220,14 @@ export const mockDetectEthereumProvider = () => {
};

export const fakeDkgFlow = (
variant: FerveoVariant | FerveoVariant.Precomputed,
variant: FerveoVariant,
ritualId: number,
sharesNum: number,
threshold: number
) => {
if (
variant !== FerveoVariant.Simple &&
variant !== FerveoVariant.Precomputed
!variant.equals(FerveoVariant.simple) &&
!variant.equals(FerveoVariant.precomputed)
) {
throw new Error(`Invalid variant: ${variant}`);
}
Expand Down Expand Up @@ -323,20 +324,22 @@ export const fakeTDecFlow = ({
}

let decryptionShare;
if (variant === FerveoVariant.Precomputed) {
if (variant.equals(FerveoVariant.precomputed)) {
decryptionShare = aggregate.createDecryptionSharePrecomputed(
dkg,
ciphertext,
aad,
keypair
);
} else {
} else if (variant.equals(FerveoVariant.simple)) {
decryptionShare = aggregate.createDecryptionShareSimple(
dkg,
ciphertext,
aad,
keypair
);
} else {
throw new Error(`Invalid variant: ${variant}`);
}
decryptionShares.push(decryptionShare);
});
Expand All @@ -345,10 +348,12 @@ export const fakeTDecFlow = ({
// This part is in the client API

let sharedSecret;
if (variant === FerveoVariant.Precomputed) {
if (variant.equals(FerveoVariant.precomputed)) {
sharedSecret = combineDecryptionSharesPrecomputed(decryptionShares);
} else {
} else if (variant.equals(FerveoVariant.simple)) {
sharedSecret = combineDecryptionSharesSimple(decryptionShares);
} else {
throw new Error(`Invalid variant: ${variant}`);
}

// The client should have access to the public parameters of the DKG
Expand Down Expand Up @@ -403,7 +408,7 @@ export const fakeCoordinatorRitual = (
publicKeyHash: string;
totalAggregations: number;
} => {
const ritual = fakeDkgTDecFlowE2e(FerveoVariant.Precomputed);
const ritual = fakeDkgTDecFlowE2e(FerveoVariant.precomputed);
const dkgPkBytes = ritual.dkg.publicKey().toBytes();
return {
id: ritualId,
Expand All @@ -425,7 +430,7 @@ export const fakeCoordinatorRitual = (

export const fakeDkgParticipants = (
ritualId: number,
variant = FerveoVariant.Precomputed
variant = FerveoVariant.precomputed
): {
participants: DkgParticipant[];
participantSecrets: Record<string, SessionStaticSecret>;
Expand Down
Loading

0 comments on commit 7132cab

Please sign in to comment.