-
Notifications
You must be signed in to change notification settings - Fork 22
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
Implement the TACo API module #263
Changes from 8 commits
050bd60
3c6f0de
6ad6130
0319e0f
9f974c0
26a54e6
19a73b7
1dba09f
e1a0cd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ export class CbdStrategy { | |
// // Given that we just initialized the ritual, this should never happen | ||
// throw new Error('Ritual ID is undefined'); | ||
// } | ||
const dkgRitual = await DkgClient.getExistingRitual(provider, ritualId); | ||
const dkgRitual = await DkgClient.getRitual(provider, ritualId); | ||
return DeployedCbdStrategy.create(dkgRitual, this.cohort.porterUri); | ||
} | ||
|
||
|
@@ -78,7 +78,11 @@ export class DeployedCbdStrategy { | |
) {} | ||
|
||
public static create(dkgRitual: DkgRitual, porterUri: string) { | ||
const decrypter = ThresholdDecrypter.create(porterUri, dkgRitual); | ||
const decrypter = ThresholdDecrypter.create( | ||
porterUri, | ||
dkgRitual.id, | ||
dkgRitual.dkgParams.threshold | ||
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. Is threshold still needed, even though it is now part of the ritual struct? 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. The client needs to know how many shares to fetch from the nodes ( 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. Yes, but now if you have the ritual id, you can get the value of the 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. If you inspect the usage of 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. Right 👍 . I mixed up my layers. Side question: any reason we need the const decrypter = ThresholdDecrypter.create(
porterUri,
dkgRitual.id,
dkgRitual.threshold ? Anyways, just something to think about. |
||
); | ||
return new DeployedCbdStrategy(decrypter, dkgRitual.dkgPublicKey); | ||
} | ||
|
||
|
@@ -88,7 +92,7 @@ export class DeployedCbdStrategy { | |
porterUri: string, | ||
ritualId: number | ||
): Promise<DeployedCbdStrategy> { | ||
const dkgRitual = await DkgClient.getExistingRitual(provider, ritualId); | ||
const dkgRitual = await DkgClient.getRitual(provider, ritualId); | ||
return DeployedCbdStrategy.create(dkgRitual, porterUri); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core'; | ||
import { ethers } from 'ethers'; | ||
|
||
import { DkgCoordinatorAgent } from './agents/coordinator'; | ||
import { ThresholdDecrypter } from './characters/cbd-recipient'; | ||
import { Enrico } from './characters/enrico'; | ||
import { Condition, ConditionExpression } from './conditions'; | ||
import { DkgClient } from './dkg'; | ||
import { getPorterUri } from './porter'; | ||
import { toBytes } from './utils'; | ||
|
||
export const encrypt = async ( | ||
provider: ethers.providers.Provider, | ||
message: string, | ||
condition: Condition, | ||
ritualId: number | ||
): Promise<ThresholdMessageKit> => { | ||
const dkgRitual = await DkgClient.getFinalizedRitual(provider, ritualId); | ||
return await encryptLight(message, condition, dkgRitual.dkgPublicKey); | ||
}; | ||
|
||
export const encryptLight = async ( | ||
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. Not sure how I feel about 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. There is no support function overloading in JS/TS. I didn't have better ideas for an appropriate name, maybe we could use the 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. 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. I don't have a good name for it, but I would prefer something like export const encryptWithDKG = async ( than the original one |
||
message: string, | ||
condition: Condition, | ||
dkgPublicKey: DkgPublicKey | ||
): Promise<ThresholdMessageKit> => { | ||
const encrypter = new Enrico(dkgPublicKey); | ||
const conditionExpr = new ConditionExpression(condition); | ||
return encrypter.encryptMessageCbd(toBytes(message), conditionExpr); | ||
}; | ||
|
||
export const decrypt = async ( | ||
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. This simplicity is great! |
||
provider: ethers.providers.Provider, | ||
messageKit: ThresholdMessageKit, | ||
signer?: ethers.Signer, | ||
porterUri = getPorterUri('tapir') | ||
): Promise<Uint8Array> => { | ||
const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey( | ||
provider, | ||
messageKit.acp.publicKey | ||
); | ||
const ritual = await DkgClient.getFinalizedRitual(provider, ritualId); | ||
const decrypter = ThresholdDecrypter.create( | ||
porterUri, | ||
ritualId, | ||
ritual.dkgParams.threshold | ||
); | ||
return decrypter.retrieveAndDecrypt(provider, messageKit, signer); | ||
}; | ||
|
||
export const taco = { | ||
encrypt, | ||
encryptLight, | ||
decrypt, | ||
}; |
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.
Are participants not stored in this struct? I guess maybe not needed...?
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.
The contents of this struct are taken from types generated from contracts by
typechain
. I can trim them down to a size.