Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"prebuild": "yarn typechain"
},
"dependencies": {
"@nucypher/nucypher-core": "^0.11.0",
"@nucypher/nucypher-core": "file:../nucypher-core/nucypher-core-wasm/pkg",

Copy link
Copy Markdown

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?

Copy link
Copy Markdown
Contributor Author

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.

"axios": "^0.21.1",
"deep-equal": "^2.2.1",
"ethers": "^5.4.1",
Expand Down
49 changes: 37 additions & 12 deletions src/characters/cbd-recipient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
AccessControlPolicy,
AuthenticatedData,
Ciphertext,
combineDecryptionSharesSimple,
Context,
Expand All @@ -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;
Expand All @@ -26,8 +29,6 @@ export type ThresholdDecrypterJSON = {
};

export class ThresholdDecrypter {
// private readonly verifyingKey: Keyring;

private constructor(
private readonly porter: PorterClient,
private readonly ritualId: number,
Expand All @@ -48,10 +49,13 @@ export class ThresholdDecrypter {
conditionExpr: ConditionExpression,
ciphertext: Ciphertext

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be ThresholdMessageKit and not Ciphertext...?

): Promise<Uint8Array> {
const acp = await this.makeAcp(provider, conditionExpr, ciphertext);

const decryptionShares = await this.retrieve(
provider,
conditionExpr,
ciphertext
ciphertext,
acp
);

const sharedSecret = combineDecryptionSharesSimple(decryptionShares);
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piotr-roslaniec Should this just be ThreshodlMessageKit? It has the ciphertext and the acp in it...?

): Promise<DecryptionShareSimple[]> {
const dkgParticipants = await DkgCoordinatorAgent.getParticipants(
provider,
Expand All @@ -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(
Expand Down Expand Up @@ -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)
);

Expand Down
4 changes: 4 additions & 0 deletions src/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { toBytes } from './utils';
export class Keyring {
constructor(public readonly secretKey: SecretKey) {}

public static random(): Keyring {
return new Keyring(SecretKey.random());
}

public get signer(): Signer {
return new Signer(this.secretKey);
}
Expand Down
3 changes: 2 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const fakeWeb3Provider = (
...new Wallet(secretKeyBytes),
provider,
_signTypedData: () => Promise.resolve('fake-typed-signature'),
signMessage: () => Promise.resolve('fake-signature'),
getAddress: () =>
Promise.resolve('0x0000000000000000000000000000000000000000'),
} as unknown as ethers.providers.JsonRpcSigner;
Expand Down Expand Up @@ -318,7 +319,7 @@ export const fakeTDecFlow = ({

const decryptionShare = aggregate.createDecryptionShareSimple(
dkg,
ciphertext,
ciphertext.header,
aad,
keypair
);
Expand Down
Loading