- 
                Notifications
    You must be signed in to change notification settings 
- Fork 24
Implement the TACo API module #263
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
Changes from all 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 | 
|---|---|---|
| @@ -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.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.