-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4f824d
commit 60af38b
Showing
9 changed files
with
216 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Ciphertext, ferveoEncrypt } from '@nucypher/nucypher-core'; | ||
import { ethers } from 'ethers'; | ||
|
||
import { ThresholdDecrypter } from './characters/cbd-recipient'; | ||
import { ConditionExpression } from './conditions'; | ||
import { DkgClient } from './dkg'; | ||
import { toBytes } from './utils'; | ||
|
||
export interface TacoMessageKit { | ||
ciphertext: Ciphertext; | ||
aad: Uint8Array; | ||
ritualId: number; | ||
threshold: number; | ||
} | ||
|
||
export const encrypt = async ( | ||
web3Provider: ethers.providers.Web3Provider, | ||
message: string, | ||
conditions: ConditionExpression, | ||
ritualId: number | ||
): Promise<TacoMessageKit> => { | ||
const dkgRitual = await DkgClient.getFinalizedRitual(web3Provider, ritualId); | ||
const aad = conditions.asAad(); | ||
const ciphertext = ferveoEncrypt( | ||
toBytes(message), | ||
aad, | ||
dkgRitual.dkgPublicKey | ||
); | ||
return { | ||
ciphertext, | ||
aad, | ||
ritualId, | ||
threshold: dkgRitual.dkgParams.threshold, | ||
}; | ||
}; | ||
|
||
export const decrypt = async ( | ||
web3Provider: ethers.providers.Web3Provider, | ||
messageKit: TacoMessageKit, | ||
porterUri: string | ||
): Promise<Uint8Array> => { | ||
const decrypter = ThresholdDecrypter.create( | ||
porterUri, | ||
messageKit.ritualId, | ||
messageKit.threshold | ||
); | ||
const condExpr = ConditionExpression.fromAad(messageKit.aad); | ||
// TODO: Need web3Provider to fetch participants from Coordinator to make decryption requests. | ||
// Should we put them into the message kit instead? | ||
// Consider case where participants are changing over time. Is that an issue we should consider now? | ||
return decrypter.retrieveAndDecrypt( | ||
web3Provider, | ||
condExpr, | ||
messageKit.ciphertext | ||
); | ||
}; | ||
|
||
export const taco = { | ||
encrypt, | ||
decrypt, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
60af38b
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.
Bundled size for the package is listed below:
build/module/src/kits: 19.53 KB
build/module/src/characters: 74.22 KB
build/module/src/policies: 19.53 KB
build/module/src/agents: 39.06 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions: 156.25 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 42.97 KB
build/module/src: 437.50 KB
build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module/test: 42.97 KB
build/module: 691.41 KB
build/main/src/kits: 19.53 KB
build/main/src/characters: 74.22 KB
build/main/src/policies: 19.53 KB
build/main/src/agents: 39.06 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions: 156.25 KB
build/main/src/sdk/strategy: 35.16 KB
build/main/src/sdk: 46.88 KB
build/main/src: 445.31 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main/test: 46.88 KB
build/main: 703.13 KB
build: 1.37 MB