Skip to content

Commit 752320c

Browse files
feat!: replace variant parameter with a default simple variant
1 parent ff16c06 commit 752320c

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,
@@ -19,11 +19,7 @@ import {
1919
DkgRitualState,
2020
} from '../agents/coordinator';
2121
import { ConditionExpression } from '../conditions';
22-
import {
23-
DkgRitual,
24-
getCombineDecryptionSharesFunction,
25-
getVariantClass,
26-
} from '../dkg';
22+
import { DkgRitual } from '../dkg';
2723
import { PorterClient } from '../porter';
2824
import { fromJSON, toJSON } from '../utils';
2925

@@ -54,19 +50,15 @@ export class ThresholdDecrypter {
5450
public async retrieveAndDecrypt(
5551
provider: ethers.providers.Web3Provider,
5652
conditionExpr: ConditionExpression,
57-
variant: FerveoVariant,
5853
ciphertext: Ciphertext
5954
): Promise<Uint8Array> {
6055
const decryptionShares = await this.retrieve(
6156
provider,
6257
conditionExpr,
63-
variant,
6458
ciphertext
6559
);
6660

67-
const combineDecryptionSharesFn =
68-
getCombineDecryptionSharesFunction(variant);
69-
const sharedSecret = combineDecryptionSharesFn(decryptionShares);
61+
const sharedSecret = combineDecryptionSharesSimple(decryptionShares);
7062
return decryptWithSharedSecret(
7163
ciphertext,
7264
conditionExpr.asAad(),
@@ -78,9 +70,8 @@ export class ThresholdDecrypter {
7870
public async retrieve(
7971
web3Provider: ethers.providers.Web3Provider,
8072
conditionExpr: ConditionExpression,
81-
variant: FerveoVariant,
8273
ciphertext: Ciphertext
83-
): Promise<DecryptionSharePrecomputed[] | DecryptionShareSimple[]> {
74+
): Promise<DecryptionShareSimple[]> {
8475
const ritualState = await DkgCoordinatorAgent.getRitualState(
8576
web3Provider,
8677
this.ritualId
@@ -98,7 +89,6 @@ export class ThresholdDecrypter {
9889
const contextStr = await conditionExpr.buildContext(web3Provider).toJson();
9990
const { sharedSecrets, encryptedRequests } = this.makeDecryptionRequests(
10091
this.ritualId,
101-
variant,
10292
ciphertext,
10393
conditionExpr,
10494
contextStr,
@@ -120,15 +110,13 @@ export class ThresholdDecrypter {
120110
return this.makeDecryptionShares(
121111
encryptedResponses,
122112
sharedSecrets,
123-
variant,
124113
this.ritualId
125114
);
126115
}
127116

128117
private makeDecryptionShares(
129118
encryptedResponses: Record<string, EncryptedThresholdDecryptionResponse>,
130119
sessionSharedSecret: Record<string, SessionSharedSecret>,
131-
variant: FerveoVariant,
132120
expectedRitualId: number
133121
) {
134122
const decryptedResponses = Object.entries(encryptedResponses).map(
@@ -142,19 +130,13 @@ export class ThresholdDecrypter {
142130
);
143131
}
144132

145-
const decryptionShares = decryptedResponses.map(
146-
({ decryptionShare }) => decryptionShare
147-
);
148-
149-
const DecryptionShareType = getVariantClass(variant);
150-
return decryptionShares.map((share) =>
151-
DecryptionShareType.fromBytes(share)
133+
return decryptedResponses.map(({ decryptionShare }) =>
134+
DecryptionShareSimple.fromBytes(decryptionShare)
152135
);
153136
}
154137

155138
private makeDecryptionRequests(
156139
ritualId: number,
157-
variant: FerveoVariant,
158140
ciphertext: Ciphertext,
159141
conditionExpr: ConditionExpression,
160142
contextStr: string,
@@ -165,7 +147,7 @@ export class ThresholdDecrypter {
165147
} {
166148
const decryptionRequest = new ThresholdDecryptionRequest(
167149
ritualId,
168-
variant,
150+
FerveoVariant.simple,
169151
ciphertext,
170152
conditionExpr.toWASMConditions(),
171153
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
@@ -113,7 +113,6 @@ describe('CbdDeployedStrategy', () => {
113113
// Setup mocks for `retrieveAndDecrypt`
114114
const { decryptionShares } = fakeTDecFlow({
115115
...mockedDkg,
116-
variant,
117116
message: toBytes(message),
118117
aad,
119118
ciphertext,
@@ -138,7 +137,6 @@ describe('CbdDeployedStrategy', () => {
138137
await deployedStrategy.decrypter.retrieveAndDecrypt(
139138
aliceProvider,
140139
conditionExpr,
141-
variant,
142140
ciphertext
143141
);
144142
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)