Skip to content

Commit

Permalink
Update demo config (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec authored Oct 23, 2023
2 parents 78eece0 + 0c1b8bf commit 8fb2a83
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 69 deletions.
3 changes: 2 additions & 1 deletion demos/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# `@nucypher/*` Demos

- [`taco-demo`](./taco-demo) - A demo of the `@nucypher/taco` library.
- [`taco-nft-demo`](./taco-nft-demo) - A demo an NFT-based condition using the `@nucypher/taco` library.
- [`taco-nft-demo`](./taco-nft-demo) - A demo an NFT-based condition using the
`@nucypher/taco` library.
5 changes: 3 additions & 2 deletions demos/taco-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nucypher/taco": "0.1.0-rc.3",
"@nucypher/taco": "0.1.0-rc.5",
"@usedapp/core": "^1.2.13",
"buffer": "^6.0.3",
"ethers": "^5.7.1",
Expand All @@ -23,7 +23,8 @@
"react-spinners": "^0.13.6"
},
"peerDependencies": {
"@nucypher/taco": "workspace:*"
"@nucypher/taco": "workspace:*",
"@nucypher/shared": "workspace:*"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
Expand Down
16 changes: 14 additions & 2 deletions demos/taco-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ethers } from 'ethers';
import React, { useEffect, useState } from 'react';

import { ConditionBuilder } from './ConditionBuilder';
import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config';
import { Decrypt } from './Decrypt';
import { Encrypt } from './Encrypt';
import { Spinner } from './Spinner';
Expand All @@ -26,8 +27,8 @@ export default function App() {
useState<ThresholdMessageKit>();
const [decryptedMessage, setDecryptedMessage] = useState<string>();
const [decryptionErrors, setDecryptionErrors] = useState<string[]>([]);
const [ritualId, setRitualId] = useState<number>(2);
const [domain, setDomain] = useState<string>(domains.TESTNET);
const [ritualId, setRitualId] = useState<number>(DEFAULT_RITUAL_ID);
const [domain, setDomain] = useState<string>(DEFAULT_DOMAIN);

useEffect(() => {
initialize();
Expand Down Expand Up @@ -98,6 +99,17 @@ export default function App() {
{account && <p>Account: {account}</p>}
</div>

<h2>Notice</h2>
<p>
In order to access this demo, make sure to allow-list your wallet
address first.
</p>
<p>
Connect with us on our{' '}
<a href={'https://discord.gg/threshold'}>Discord server</a> at{' '}
<b>#taco</b> channel to get your wallet address allow-listed
</p>

<h2>Ritual ID</h2>
<p>Replace with your own ritual ID</p>
<input
Expand Down
7 changes: 7 additions & 0 deletions demos/taco-demo/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { domains } from '@nucypher/taco';

export const DEFAULT_RITUAL_ID =
(process.env.DEFAULT_RITUAL_ID && parseInt(process.env.DEFAULT_RITUAL_ID)) ||
3;

export const DEFAULT_DOMAIN = process.env.DEFAULT_DOMAIN || domains.DEV;
5 changes: 3 additions & 2 deletions demos/taco-nft-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nucypher/taco": "0.1.0-rc.3",
"@nucypher/taco": "0.1.0-rc.5",
"@usedapp/core": "^1.2.13",
"buffer": "^6.0.3",
"ethers": "^5.7.1",
Expand All @@ -23,7 +23,8 @@
"react-spinners": "^0.13.6"
},
"peerDependencies": {
"@nucypher/taco": "workspace:*"
"@nucypher/taco": "workspace:*",
"@nucypher/shared": "workspace:*"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
Expand Down
16 changes: 14 additions & 2 deletions demos/taco-nft-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Mumbai, useEthers } from '@usedapp/core';
import { ethers } from 'ethers';
import React, { useEffect, useState } from 'react';

import { DEFAULT_DOMAIN, DEFAULT_RITUAL_ID } from './config';
import { Decrypt } from './Decrypt';
import { Encrypt } from './Encrypt';
import { NFTConditionBuilder } from './NFTConditionBuilder';
Expand All @@ -26,8 +27,8 @@ export default function App() {
useState<ThresholdMessageKit>();
const [decryptedMessage, setDecryptedMessage] = useState<string>();
const [decryptionErrors, setDecryptionErrors] = useState<string[]>([]);
const [ritualId, setRitualId] = useState<number>(2);
const [domain, setDomain] = useState<string>(domains.TESTNET);
const [ritualId, setRitualId] = useState<number>(DEFAULT_RITUAL_ID);
const [domain, setDomain] = useState<string>(DEFAULT_DOMAIN);

useEffect(() => {
initialize();
Expand Down Expand Up @@ -97,6 +98,17 @@ export default function App() {
{account && <p>Account: {account}</p>}
</div>

<h2>Notice</h2>
<p>
In order to access this demo, make sure to allow-list your wallet
address first.
</p>
<p>
Connect with us on our{' '}
<a href={'https://discord.gg/threshold'}>Discord server</a> at{' '}
<b>#taco</b> channel to get your wallet address allow-listed
</p>

<h2>Ritual ID</h2>
<p>Replace with your own ritual ID</p>
<input
Expand Down
7 changes: 7 additions & 0 deletions demos/taco-nft-demo/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { domains } from '@nucypher/taco';

export const DEFAULT_RITUAL_ID =
(process.env.DEFAULT_RITUAL_ID && parseInt(process.env.DEFAULT_RITUAL_ID)) ||
3;

export const DEFAULT_DOMAIN = process.env.DEFAULT_DOMAIN || domains.DEV;
9 changes: 8 additions & 1 deletion packages/pre/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ export {
Signer,
TreasureMap,
} from '@nucypher/nucypher-core';
export { fromBytes, initialize, toBytes, toHexString, getPorterUri, domains } from '@nucypher/shared';
export {
domains,
fromBytes,
getPorterUri,
initialize,
toBytes,
toHexString,
} from '@nucypher/shared';

export { Alice, Bob, Enrico } from './characters';
export { Cohort } from './cohort';
Expand Down
6 changes: 5 additions & 1 deletion packages/pre/test/acceptance/delay-enact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ describe('story: alice creates a policy but someone else enacts it', () => {
).toBeTruthy();
expect(preEnactedPolicy.label).toBe(label);

const enacted = await preEnactedPolicy.enact(provider, fakeSigner(), domains.DEV);
const enacted = await preEnactedPolicy.enact(
provider,
fakeSigner(),
domains.DEV,
);
expect(enacted.txHash).toBeDefined();

expect(getUrsulasSpy).toHaveBeenCalled();
Expand Down
7 changes: 5 additions & 2 deletions packages/shared/src/contracts/agents/coordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@nucypher/nucypher-core';
import { BigNumberish, ethers } from 'ethers';

import {Domain} from "../../porter";
import { Domain } from '../../porter';
import { ChecksumAddress } from '../../types';
import { fromHexString } from '../../utils';
import { Coordinator__factory } from '../ethers-typechain';
Expand Down Expand Up @@ -147,7 +147,10 @@ export class DkgCoordinatorAgent {
);
}

private static async connectReadOnly(provider: ethers.providers.Provider, domain: Domain) {
private static async connectReadOnly(
provider: ethers.providers.Provider,
domain: Domain,
) {
return await this.connect(provider, domain);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/taco/src/conditions/condition-expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { ConditionContext, CustomContextParam } from './context';
const ERR_VERSION = (provided: string, current: string) =>
`Version provided, ${provided}, is incompatible with current version, ${current}`;
const ERR_CONDITION = (condition: Record<string, unknown>) =>
`Invalid condition: unrecognized condition data ${JSON.stringify(
condition,
)}`;
`Invalid condition: unrecognized condition data ${JSON.stringify(condition)}`;

export type ConditionExpressionJSON = {
version: string;
Expand Down
13 changes: 11 additions & 2 deletions packages/taco/src/dkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export class DkgClient {
reject();
}
};
DkgCoordinatorAgent.onRitualEndEvent(provider, domain, ritualId, callback);
DkgCoordinatorAgent.onRitualEndEvent(
provider,
domain,
ritualId,
callback,
);
});
};

Expand All @@ -131,7 +136,11 @@ export class DkgClient {
domain,
ritualId,
);
const ritual = await DkgCoordinatorAgent.getRitual(provider, domain, ritualId);
const ritual = await DkgCoordinatorAgent.getRitual(
provider,
domain,
ritualId,
);
const dkgPkBytes = new Uint8Array([
...fromHexString(ritual.publicKey.word0),
...fromHexString(ritual.publicKey.word1),
Expand Down
10 changes: 9 additions & 1 deletion packages/taco/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core';
export { fromBytes, initialize, toBytes, toHexString, getPorterUri, domains, Domain } from '@nucypher/shared';
export {
Domain,
domains,
fromBytes,
getPorterUri,
initialize,
toBytes,
toHexString,
} from '@nucypher/shared';

export * as conditions from './conditions';
// Expose registerEncrypters from taco API (#324)
Expand Down
20 changes: 15 additions & 5 deletions packages/taco/src/taco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { keccak256 } from 'ethers/lib/utils';
import {
Condition,
ConditionExpression,
CustomContextParam
CustomContextParam,
} from './conditions';
import { DkgClient } from './dkg';
import { retrieveAndDecrypt } from './tdec';
Expand All @@ -44,7 +44,11 @@ export const encrypt = async (
// // Given that we just initialized the ritual, this should never happen
// throw new Error('Ritual ID is undefined');
// }
const dkgRitual = await DkgClient.getFinalizedRitual(provider, domain, ritualId);
const dkgRitual = await DkgClient.getFinalizedRitual(
provider,
domain,
ritualId,
);

return await encryptWithPublicKey(
message,
Expand Down Expand Up @@ -91,7 +95,7 @@ export const decrypt = async (
customParameters?: Record<string, CustomContextParam>,
): Promise<Uint8Array> => {
if (!porterUri) {
porterUri = getPorterUri(domain)
porterUri = getPorterUri(domain);
}

const ritualId = await DkgCoordinatorAgent.getRitualIdFromPublicKey(
Expand All @@ -108,7 +112,7 @@ export const decrypt = async (
ritualId,
ritual.threshold,
signer,
customParameters
customParameters,
);
};

Expand All @@ -117,7 +121,13 @@ export const isAuthorized = async (
domain: Domain,
messageKit: ThresholdMessageKit,
ritualId: number,
) => DkgCoordinatorAgent.isEncryptionAuthorized(provider, domain, ritualId, messageKit);
) =>
DkgCoordinatorAgent.isEncryptionAuthorized(
provider,
domain,
ritualId,
messageKit,
);

export const registerEncrypters = async (
provider: ethers.providers.Provider,
Expand Down
2 changes: 1 addition & 1 deletion packages/taco/src/tdec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { arrayify, keccak256 } from 'ethers/lib/utils';
import {
ConditionContext,
ConditionExpression,
CustomContextParam
CustomContextParam,
} from './conditions';

export const encryptMessage = async (
Expand Down
13 changes: 6 additions & 7 deletions packages/taco/test/conditions/conditions.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fakeProvider, fakeSigner } from "@nucypher/test-utils";
import {beforeAll, describe, expect, it} from "vitest";
import { fakeProvider, fakeSigner } from '@nucypher/test-utils';
import { beforeAll, describe, expect, it } from 'vitest';

import { initialize } from "../../src";
import { CompoundCondition, ConditionContext } from "../../src/conditions";
import { initialize } from '../../src';
import { CompoundCondition, ConditionContext } from '../../src/conditions';

describe('conditions', () => {
beforeAll(async () => {
Expand Down Expand Up @@ -36,12 +36,11 @@ describe('conditions', () => {
expect(condition).toBeDefined();
expect(condition.requiresSigner()).toBeTruthy();


const context = new ConditionContext(
fakeProvider(),
condition,
{':time': 100},
fakeSigner()
{ ':time': 100 },
fakeSigner(),
);
expect(context).toBeDefined();

Expand Down
12 changes: 5 additions & 7 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ describe('context', () => {

describe('return value test', () => {
it('accepts on a custom context parameters', async () => {
const asObj = await context
.withCustomParams(customParams)
.toObj();
const asObj = await context.withCustomParams(customParams).toObj();
expect(asObj).toBeDefined();
expect(asObj[customParamKey]).toEqual(1234);
});
Expand All @@ -85,9 +83,7 @@ describe('context', () => {
const badCustomParams: Record<string, CustomContextParam> = {};
RESERVED_CONTEXT_PARAMS.forEach((reservedParam) => {
badCustomParams[reservedParam] = 'this-will-throw';
expect(() =>
context.withCustomParams(badCustomParams),
).toThrow(
expect(() => context.withCustomParams(badCustomParams)).toThrow(
`Cannot use reserved parameter name ${reservedParam} as custom parameter`,
);
});
Expand All @@ -98,7 +94,9 @@ describe('context', () => {
const badCustomParams: Record<string, CustomContextParam> = {};
badCustomParams[':customParam'] = 'this-is-fine';
badCustomParams[badCustomParamKey] = 'this-will-throw';
await expect(context.withCustomParams(badCustomParams).toObj()).rejects.toThrow(
await expect(
context.withCustomParams(badCustomParams).toObj(),
).rejects.toThrow(
`Unknown custom context parameter(s): ${badCustomParamKey}`,
);
});
Expand Down
Loading

0 comments on commit 8fb2a83

Please sign in to comment.