-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to nucypher-core@0.12.0
#273
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { | ||
AccessControlPolicy, | ||
AuthenticatedData, | ||
Ciphertext, | ||
combineDecryptionSharesSimple, | ||
Context, | ||
|
@@ -12,12 +14,13 @@ import { | |
ThresholdDecryptionRequest, | ||
} from '@nucypher/nucypher-core'; | ||
import { ethers } from 'ethers'; | ||
import { keccak256 } from 'ethers/lib/utils'; | ||
|
||
import { DkgCoordinatorAgent, DkgParticipant } from '../agents/coordinator'; | ||
import { ConditionExpression } from '../conditions'; | ||
import { DkgRitual } from '../dkg'; | ||
import { DkgClient, DkgRitual } from '../dkg'; | ||
import { PorterClient } from '../porter'; | ||
import { fromJSON, toJSON } from '../utils'; | ||
import { fromJSON, toBytes, toJSON } from '../utils'; | ||
|
||
export type ThresholdDecrypterJSON = { | ||
porterUri: string; | ||
|
@@ -26,8 +29,6 @@ export type ThresholdDecrypterJSON = { | |
}; | ||
|
||
export class ThresholdDecrypter { | ||
// private readonly verifyingKey: Keyring; | ||
|
||
private constructor( | ||
private readonly porter: PorterClient, | ||
private readonly ritualId: number, | ||
|
@@ -48,10 +49,13 @@ export class ThresholdDecrypter { | |
conditionExpr: ConditionExpression, | ||
ciphertext: Ciphertext | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this instead be |
||
): Promise<Uint8Array> { | ||
const acp = await this.makeAcp(provider, conditionExpr, ciphertext); | ||
|
||
const decryptionShares = await this.retrieve( | ||
provider, | ||
conditionExpr, | ||
ciphertext | ||
ciphertext, | ||
acp | ||
); | ||
|
||
const sharedSecret = combineDecryptionSharesSimple(decryptionShares); | ||
|
@@ -62,11 +66,32 @@ export class ThresholdDecrypter { | |
); | ||
} | ||
|
||
private async makeAcp( | ||
provider: ethers.providers.Web3Provider, | ||
conditionExpr: ConditionExpression, | ||
ciphertext: Ciphertext | ||
) { | ||
const dkgRitual = await DkgClient.getExistingRitual( | ||
provider, | ||
this.ritualId | ||
); | ||
const authData = new AuthenticatedData( | ||
dkgRitual.dkgPublicKey, | ||
conditionExpr.toWASMConditions() | ||
); | ||
|
||
const headerHash = keccak256(ciphertext.header.toBytes()); | ||
const authorization = await provider.getSigner().signMessage(headerHash); | ||
|
||
return new AccessControlPolicy(authData, toBytes(authorization)); | ||
} | ||
|
||
// Retrieve decryption shares | ||
public async retrieve( | ||
provider: ethers.providers.Web3Provider, | ||
conditionExpr: ConditionExpression, | ||
ciphertext: Ciphertext | ||
ciphertext: Ciphertext, | ||
acp: AccessControlPolicy | ||
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @piotr-roslaniec Should this just be |
||
): Promise<DecryptionShareSimple[]> { | ||
const dkgParticipants = await DkgCoordinatorAgent.getParticipants( | ||
provider, | ||
|
@@ -76,9 +101,9 @@ export class ThresholdDecrypter { | |
const { sharedSecrets, encryptedRequests } = this.makeDecryptionRequests( | ||
this.ritualId, | ||
ciphertext, | ||
conditionExpr, | ||
contextStr, | ||
dkgParticipants | ||
dkgParticipants, | ||
acp | ||
); | ||
|
||
const { encryptedResponses, errors } = await this.porter.cbdDecrypt( | ||
|
@@ -124,18 +149,18 @@ export class ThresholdDecrypter { | |
private makeDecryptionRequests( | ||
ritualId: number, | ||
ciphertext: Ciphertext, | ||
conditionExpr: ConditionExpression, | ||
contextStr: string, | ||
dkgParticipants: Array<DkgParticipant> | ||
dkgParticipants: Array<DkgParticipant>, | ||
acp: AccessControlPolicy | ||
): { | ||
sharedSecrets: Record<string, SessionSharedSecret>; | ||
encryptedRequests: Record<string, EncryptedThresholdDecryptionRequest>; | ||
} { | ||
const decryptionRequest = new ThresholdDecryptionRequest( | ||
ritualId, | ||
FerveoVariant.simple, | ||
ciphertext, | ||
conditionExpr.toWASMConditions(), | ||
ciphertext.header, | ||
acp, | ||
new Context(contextStr) | ||
); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this line will be changed when nucypher/nucypher-core#77 is merged, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but specifically when we release
@nucypher/nucypher-core@0.12.0
on npm.