Skip to content

Commit 36fd43e

Browse files
feat!: replace variant parameter with a default simple variant
1 parent e4f824d commit 36fd43e

File tree

4 files changed

+15
-93
lines changed

4 files changed

+15
-93
lines changed

src/characters/cbd-recipient.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Ciphertext,
3+
combineDecryptionSharesSimple,
34
Context,
4-
DecryptionSharePrecomputed,
55
DecryptionShareSimple,
66
decryptWithSharedSecret,
77
EncryptedThresholdDecryptionRequest,
@@ -15,11 +15,7 @@ import { ethers } from 'ethers';
1515

1616
import { DkgCoordinatorAgent, DkgParticipant } from '../agents/coordinator';
1717
import { ConditionExpression } from '../conditions';
18-
import {
19-
DkgRitual,
20-
getCombineDecryptionSharesFunction,
21-
getVariantClass,
22-
} from '../dkg';
18+
import { DkgRitual } from '../dkg';
2319
import { PorterClient } from '../porter';
2420
import { fromJSON, toJSON } from '../utils';
2521

@@ -50,19 +46,15 @@ export class ThresholdDecrypter {
5046
public async retrieveAndDecrypt(
5147
provider: ethers.providers.Web3Provider,
5248
conditionExpr: ConditionExpression,
53-
variant: FerveoVariant,
5449
ciphertext: Ciphertext
5550
): Promise<Uint8Array> {
5651
const decryptionShares = await this.retrieve(
5752
provider,
5853
conditionExpr,
59-
variant,
6054
ciphertext
6155
);
6256

63-
const combineDecryptionSharesFn =
64-
getCombineDecryptionSharesFunction(variant);
65-
const sharedSecret = combineDecryptionSharesFn(decryptionShares);
57+
const sharedSecret = combineDecryptionSharesSimple(decryptionShares);
6658
return decryptWithSharedSecret(
6759
ciphertext,
6860
conditionExpr.asAad(),
@@ -74,17 +66,15 @@ export class ThresholdDecrypter {
7466
public async retrieve(
7567
provider: ethers.providers.Web3Provider,
7668
conditionExpr: ConditionExpression,
77-
variant: FerveoVariant,
7869
ciphertext: Ciphertext
79-
): Promise<DecryptionSharePrecomputed[] | DecryptionShareSimple[]> {
70+
): Promise<DecryptionShareSimple[]> {
8071
const dkgParticipants = await DkgCoordinatorAgent.getParticipants(
8172
provider,
8273
this.ritualId
8374
);
8475
const contextStr = await conditionExpr.buildContext(provider).toJson();
8576
const { sharedSecrets, encryptedRequests } = this.makeDecryptionRequests(
8677
this.ritualId,
87-
variant,
8878
ciphertext,
8979
conditionExpr,
9080
contextStr,
@@ -106,15 +96,13 @@ export class ThresholdDecrypter {
10696
return this.makeDecryptionShares(
10797
encryptedResponses,
10898
sharedSecrets,
109-
variant,
11099
this.ritualId
111100
);
112101
}
113102

114103
private makeDecryptionShares(
115104
encryptedResponses: Record<string, EncryptedThresholdDecryptionResponse>,
116105
sessionSharedSecret: Record<string, SessionSharedSecret>,
117-
variant: FerveoVariant,
118106
expectedRitualId: number
119107
) {
120108
const decryptedResponses = Object.entries(encryptedResponses).map(
@@ -128,19 +116,13 @@ export class ThresholdDecrypter {
128116
);
129117
}
130118

131-
const decryptionShares = decryptedResponses.map(
132-
({ decryptionShare }) => decryptionShare
133-
);
134-
135-
const DecryptionShareType = getVariantClass(variant);
136-
return decryptionShares.map((share) =>
137-
DecryptionShareType.fromBytes(share)
119+
return decryptedResponses.map(({ decryptionShare }) =>
120+
DecryptionShareSimple.fromBytes(decryptionShare)
138121
);
139122
}
140123

141124
private makeDecryptionRequests(
142125
ritualId: number,
143-
variant: FerveoVariant,
144126
ciphertext: Ciphertext,
145127
conditionExpr: ConditionExpression,
146128
contextStr: string,
@@ -151,7 +133,7 @@ export class ThresholdDecrypter {
151133
} {
152134
const decryptionRequest = new ThresholdDecryptionRequest(
153135
ritualId,
154-
variant,
136+
FerveoVariant.simple,
155137
ciphertext,
156138
conditionExpr.toWASMConditions(),
157139
new Context(contextStr)

src/dkg.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,10 @@
1-
import {
2-
combineDecryptionSharesPrecomputed,
3-
combineDecryptionSharesSimple,
4-
DecryptionSharePrecomputed,
5-
DecryptionShareSimple,
6-
DkgPublicKey,
7-
FerveoVariant,
8-
SharedSecret,
9-
} from '@nucypher/nucypher-core';
1+
import { DkgPublicKey } from '@nucypher/nucypher-core';
102
import { ethers } from 'ethers';
113

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

16-
export function getVariantClass(
17-
variant: FerveoVariant
18-
): typeof DecryptionShareSimple | typeof DecryptionSharePrecomputed {
19-
if (variant.equals(FerveoVariant.simple)) {
20-
return DecryptionShareSimple;
21-
} else if (variant.equals(FerveoVariant.precomputed)) {
22-
return DecryptionSharePrecomputed;
23-
} else {
24-
throw new Error(`Invalid FerveoVariant: ${variant}`);
25-
}
26-
}
27-
28-
export function getCombineDecryptionSharesFunction(
29-
variant: FerveoVariant
30-
): (
31-
shares: DecryptionShareSimple[] | DecryptionSharePrecomputed[]
32-
) => SharedSecret {
33-
if (variant.equals(FerveoVariant.simple)) {
34-
return combineDecryptionSharesSimple;
35-
} else if (variant.equals(FerveoVariant.precomputed)) {
36-
return combineDecryptionSharesPrecomputed;
37-
} else {
38-
throw new Error(`Invalid FerveoVariant: ${variant}`);
39-
}
40-
}
41-
428
export type DkgRitualParameters = {
439
sharesNum: number;
4410
threshold: number;

test/unit/cbd-strategy.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ describe('CbdDeployedStrategy', () => {
112112
// Setup mocks for `retrieveAndDecrypt`
113113
const { decryptionShares } = fakeTDecFlow({
114114
...mockedDkg,
115-
variant,
116115
message: toBytes(message),
117116
aad,
118117
ciphertext,
@@ -136,7 +135,6 @@ describe('CbdDeployedStrategy', () => {
136135
await deployedStrategy.decrypter.retrieveAndDecrypt(
137136
aliceProvider,
138137
conditionExpr,
139-
variant,
140138
ciphertext
141139
);
142140
expect(getUrsulasSpy).toHaveBeenCalled();

test/utils.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Capsule,
99
CapsuleFrag,
1010
Ciphertext,
11-
combineDecryptionSharesPrecomputed,
1211
combineDecryptionSharesSimple,
1312
DecryptionSharePrecomputed,
1413
DecryptionShareSimple,
@@ -287,7 +286,6 @@ interface FakeDkgRitualFlow {
287286
sharesNum: number;
288287
threshold: number;
289288
receivedMessages: ValidatorMessage[];
290-
variant: FerveoVariant;
291289
ciphertext: Ciphertext;
292290
aad: Uint8Array;
293291
dkg: Dkg;
@@ -301,7 +299,6 @@ export const fakeTDecFlow = ({
301299
sharesNum,
302300
threshold,
303301
receivedMessages,
304-
variant,
305302
ciphertext,
306303
aad,
307304
message,
@@ -319,38 +316,18 @@ export const fakeTDecFlow = ({
319316
throw new Error('Transcript is invalid');
320317
}
321318

322-
let decryptionShare;
323-
if (variant.equals(FerveoVariant.precomputed)) {
324-
decryptionShare = aggregate.createDecryptionSharePrecomputed(
325-
dkg,
326-
ciphertext,
327-
aad,
328-
keypair
329-
);
330-
} else if (variant.equals(FerveoVariant.simple)) {
331-
decryptionShare = aggregate.createDecryptionShareSimple(
332-
dkg,
333-
ciphertext,
334-
aad,
335-
keypair
336-
);
337-
} else {
338-
throw new Error(`Invalid variant: ${variant}`);
339-
}
319+
const decryptionShare = aggregate.createDecryptionShareSimple(
320+
dkg,
321+
ciphertext,
322+
aad,
323+
keypair
324+
);
340325
decryptionShares.push(decryptionShare);
341326
});
342327

343328
// Now, the decryption share can be used to decrypt the ciphertext
344329
// This part is in the client API
345-
346-
let sharedSecret;
347-
if (variant.equals(FerveoVariant.precomputed)) {
348-
sharedSecret = combineDecryptionSharesPrecomputed(decryptionShares);
349-
} else if (variant.equals(FerveoVariant.simple)) {
350-
sharedSecret = combineDecryptionSharesSimple(decryptionShares);
351-
} else {
352-
throw new Error(`Invalid variant: ${variant}`);
353-
}
330+
const sharedSecret = combineDecryptionSharesSimple(decryptionShares);
354331

355332
// The client should have access to the public parameters of the DKG
356333
const plaintext = decryptWithSharedSecret(ciphertext, aad, sharedSecret);
@@ -374,7 +351,6 @@ export const fakeDkgTDecFlowE2e = (
374351
const ciphertext = ferveoEncrypt(message, aad, ritual.dkg.publicKey());
375352
const { decryptionShares } = fakeTDecFlow({
376353
...ritual,
377-
variant,
378354
ciphertext,
379355
aad,
380356
message,

0 commit comments

Comments
 (0)