Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jun 27, 2023
1 parent c2acc61 commit f682eb2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/characters/cbd-recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,21 @@ export class CbdTDecDecrypter {
provider,
this.ritualId
);
// We only need the `threshold` participants
const sufficientDkgParticipants = dkgParticipants.slice(0, this.threshold);
const contextStr = await conditionExpr.buildContext(provider).toJson();
const { sharedSecrets, encryptedRequests } = this.makeDecryptionRequests(
this.ritualId,
variant,
ciphertext,
conditionExpr,
contextStr,
sufficientDkgParticipants
dkgParticipants
);

const { encryptedResponses, errors } = await this.porter.cbdDecrypt(
encryptedRequests,
this.threshold
);

// TODO: How many errors are acceptable? Less than (threshold - shares)?
// TODO: If Porter accepts only `threshold` decryption requests, then we may not have any errors
if (Object.keys(errors).length > 0) {
throw new Error(
`CBD decryption failed with errors: ${JSON.stringify(errors)}`
Expand All @@ -120,14 +116,8 @@ export class CbdTDecDecrypter {
variant: number,
expectedRitualId: number
) {
const decryptedResponses = Object.entries(sessionSharedSecret).map(
([ursula, sharedSecret]) => {
const encryptedResponse = encryptedResponses[ursula];
if (!encryptedResponse) {
throw new Error(`Missing encrypted response from ${ursula}`);
}
return encryptedResponse.decrypt(sharedSecret);
}
const decryptedResponses = Object.entries(encryptedResponses).map(
([ursula, response]) => response.decrypt(sessionSharedSecret[ursula])
);

const ritualIds = decryptedResponses.map(({ ritualId }) => ritualId);
Expand Down

0 comments on commit f682eb2

Please sign in to comment.