From 3d564b6c3d0766f4a5c3830ab94a61a128e3aaea Mon Sep 17 00:00:00 2001 From: Piotr Roslaniec Date: Mon, 25 Sep 2023 11:05:16 +0200 Subject: [PATCH] chore(examples): add a nodejs-taco example --- .gitignore | 1 + examples/README.md | 15 ++++- examples/nodejs-pre/.env.example | 2 + examples/nodejs-pre/README.md | 20 +++++++ examples/{nodejs => nodejs-pre}/package.json | 3 +- examples/{nodejs => nodejs-pre}/src/index.ts | 42 +++++++------- examples/{nodejs => nodejs-pre}/tsconfig.json | 0 examples/nodejs-taco/.env.example | 2 + examples/nodejs-taco/README.md | 20 +++++++ examples/nodejs-taco/package.json | 18 ++++++ examples/nodejs-taco/src/index.ts | 57 +++++++++++++++++++ examples/nodejs-taco/tsconfig.json | 14 +++++ examples/nodejs/README.md | 10 ---- .../pre/test/acceptance/alice-grants.test.ts | 17 +++--- .../pre/test/acceptance/delay-enact.test.ts | 3 +- packages/pre/test/docs.test.ts | 24 ++++---- packages/pre/test/enrico.test.ts | 17 +++--- packages/pre/test/message-kit.test.ts | 3 +- packages/pre/test/pre-strategy.test.ts | 24 ++++---- packages/pre/test/pre.test.ts | 17 +++--- packages/pre/test/test-utils.ts | 11 +++- packages/shared/src/index.ts | 2 - packages/taco/src/index.ts | 10 +++- packages/taco/src/taco.ts | 10 +++- packages/taco/test/cbd-strategy.test.ts | 22 +++---- packages/taco/test/dkg-client.test.ts | 3 +- packages/taco/test/docs.test..ts | 24 ++++---- packages/taco/test/ritual.test.ts | 3 +- packages/taco/test/taco.test.ts | 8 +-- pnpm-lock.yaml | 22 ++++++- 30 files changed, 301 insertions(+), 123 deletions(-) create mode 100644 examples/nodejs-pre/.env.example create mode 100644 examples/nodejs-pre/README.md rename examples/{nodejs => nodejs-pre}/package.json (84%) rename examples/{nodejs => nodejs-pre}/src/index.ts (64%) rename examples/{nodejs => nodejs-pre}/tsconfig.json (100%) create mode 100644 examples/nodejs-taco/.env.example create mode 100644 examples/nodejs-taco/README.md create mode 100644 examples/nodejs-taco/package.json create mode 100644 examples/nodejs-taco/src/index.ts create mode 100644 examples/nodejs-taco/tsconfig.json delete mode 100644 examples/nodejs/README.md diff --git a/.gitignore b/.gitignore index 421b9b5ba..aa9ae68a6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ examples/*/pnpm-lock.yaml pnpm-debug.log docs-json ./docs +.env diff --git a/examples/README.md b/examples/README.md index 494a92beb..9da516ca7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,4 +1,17 @@ -# `integration-examples` +# `examples` This directory contains a set of examples showing how to integrate `@nucypher/*` into your application. + +## Examples + +- [**`nextjs`**](./nextjs): A Next.js application that uses `@nucypher/pre` to + encrypt and decrypt data. +- [**`nodejs-pre`**](./nodejs-pre): A Node.js application that uses `@nucypher/pre` to + encrypt and decrypt data. +- [**`nodejs-taco`**](./nodejs-taco): A Node.js application that uses `@nucypher/taco` to + encrypt and decrypt data. +- [**`react`**](./react): A React application that uses `@nucypher/pre` to + encrypt and decrypt data. +- [**`webpack`**](./webpack): A Webpack application that uses `@nucypher/pre` to + encrypt and decrypt data. diff --git a/examples/nodejs-pre/.env.example b/examples/nodejs-pre/.env.example new file mode 100644 index 000000000..5c9041014 --- /dev/null +++ b/examples/nodejs-pre/.env.example @@ -0,0 +1,2 @@ +RPC_PROVIDER_URL= +PRIVATE_KEY= diff --git a/examples/nodejs-pre/README.md b/examples/nodejs-pre/README.md new file mode 100644 index 000000000..3bce6d079 --- /dev/null +++ b/examples/nodejs-pre/README.md @@ -0,0 +1,20 @@ +# `nodejs-pre` integration example + +Shows how to use `@nucypher/pre in Node.js. + +## Setup + +Setup environment variables: + +```bash +cp .env.example .env +``` + +Update `.env` with your values. + +## Usage + +```bash +pnpm install +pnpm start +``` diff --git a/examples/nodejs/package.json b/examples/nodejs-pre/package.json similarity index 84% rename from examples/nodejs/package.json rename to examples/nodejs-pre/package.json index a7d3826e9..2516c1e6f 100644 --- a/examples/nodejs/package.json +++ b/examples/nodejs-pre/package.json @@ -9,7 +9,8 @@ "type-check": "tsc" }, "dependencies": { - "@nucypher/pre": "workspace:*" + "@nucypher/pre": "workspace:*", + "dotenv": "^16.3.1" }, "peerDependencies": { "ethers": "^5.7.2" diff --git a/examples/nodejs/src/index.ts b/examples/nodejs-pre/src/index.ts similarity index 64% rename from examples/nodejs/src/index.ts rename to examples/nodejs-pre/src/index.ts index 7320e2269..7cb42d360 100644 --- a/examples/nodejs/src/index.ts +++ b/examples/nodejs-pre/src/index.ts @@ -6,8 +6,21 @@ import { SecretKey, toBytes, } from '@nucypher/pre'; +import * as dotenv from 'dotenv'; import { ethers } from 'ethers'; +dotenv.config(); + +const rpcProviderUrl = process.env.RPC_PROVIDER_URL; +if (!rpcProviderUrl) { + throw new Error('RPC_PROVIDER_URL is not set.'); +} + +const privateKey = process.env.PRIVATE_KEY; +if (!privateKey) { + throw new Error('PRIVATE_KEY is not set.'); +} + const makeAlice = () => { const secretKey = SecretKey.fromBEBytes( toBytes('fake-secret-key-32-bytes-alice-x'), @@ -35,30 +48,21 @@ const getRandomLabel = () => `label-${new Date().getTime()}`; const runExample = async () => { await initialize(); - const provider = ethers.Wallet.createRandom(); - - const remoteBob = makeRemoteBob(); - const threshold = 2; - const shares = 3; - const startDate = new Date(); - const endDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 30); // In 30 days + const provider = new ethers.providers.JsonRpcProvider(rpcProviderUrl); + const signer = new ethers.Wallet(privateKey); const policyParams = { - bob: remoteBob, + bob: makeRemoteBob(), label: getRandomLabel(), - threshold, - shares, - startDate, - endDate, + threshold: 2, + shares: 3, + startDate: new Date(), + endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30), // In 30 days, }; const porterUri = getPorterUri('tapir'); // Test network - const alice = makeAlice(); - const policy = await alice.grant( - provider.provider, - provider, - porterUri, - policyParams, - ); + + console.log('Creating policy...'); + const policy = await alice.grant(provider, signer, porterUri, policyParams); console.log('Policy created:'); console.log({ policy }); diff --git a/examples/nodejs/tsconfig.json b/examples/nodejs-pre/tsconfig.json similarity index 100% rename from examples/nodejs/tsconfig.json rename to examples/nodejs-pre/tsconfig.json diff --git a/examples/nodejs-taco/.env.example b/examples/nodejs-taco/.env.example new file mode 100644 index 000000000..5c9041014 --- /dev/null +++ b/examples/nodejs-taco/.env.example @@ -0,0 +1,2 @@ +RPC_PROVIDER_URL= +PRIVATE_KEY= diff --git a/examples/nodejs-taco/README.md b/examples/nodejs-taco/README.md new file mode 100644 index 000000000..a1fd6843e --- /dev/null +++ b/examples/nodejs-taco/README.md @@ -0,0 +1,20 @@ +# `nodejs-taco` integration example + +Shows how to use `@nucypher/taco` in Node.js. + +## Setup + +Setup environment variables: + +```bash +cp .env.example .env +``` + +Update `.env` with your values. + +## Usage + +```bash +pnpm install +pnpm start +``` diff --git a/examples/nodejs-taco/package.json b/examples/nodejs-taco/package.json new file mode 100644 index 000000000..8c4ba4a73 --- /dev/null +++ b/examples/nodejs-taco/package.json @@ -0,0 +1,18 @@ +{ + "version": "0.1.0", + "private": true, + "license": "GPL-3.0-only", + "author": "Piotr Rosłaniec ", + "scripts": { + "check": "pnpm type-check", + "start": "ts-node src/index.ts", + "type-check": "tsc" + }, + "dependencies": { + "@nucypher/taco": "workspace:*", + "dotenv": "^16.3.1" + }, + "peerDependencies": { + "ethers": "^5.7.2" + } +} diff --git a/examples/nodejs-taco/src/index.ts b/examples/nodejs-taco/src/index.ts new file mode 100644 index 000000000..1c422cb30 --- /dev/null +++ b/examples/nodejs-taco/src/index.ts @@ -0,0 +1,57 @@ +import { + conditions, + decrypt, + encrypt, + getPorterUri, + initialize, + toBytes, +} from '@nucypher/taco'; +import * as dotenv from 'dotenv'; +import { ethers } from 'ethers'; + +dotenv.config(); + +const rpcProviderUrl = process.env.RPC_PROVIDER_URL; +if (!rpcProviderUrl) { + throw new Error('RPC_PROVIDER_URL is not set.'); +} + +const privateKey = process.env.PRIVATE_KEY; +if (!privateKey) { + throw new Error('PRIVATE_KEY is not set.'); +} + +const runExample = async () => { + await initialize(); + + console.log('Encrypting message...'); + const provider = new ethers.providers.JsonRpcProvider(rpcProviderUrl); + const message = toBytes('this is a secret'); + const ownsNFT = new conditions.ERC721Ownership({ + contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', + parameters: [3591], + chain: 5, + }); + const ritualId = 91; // Replace with your own ritual ID + const messageKit = await encrypt(provider, message, ownsNFT, ritualId); + + console.log('Decrypting message...'); + const porterUri = getPorterUri('tapir'); // Test network + const signer = new ethers.Wallet(privateKey); + const decryptedMessage = await decrypt( + provider, + messageKit, + signer, + porterUri, + ); + + console.assert(decryptedMessage === message); +}; + +runExample() + .then(() => { + console.log('Example finished.'); + }) + .catch((err) => { + console.error('Example failed:', err); + }); diff --git a/examples/nodejs-taco/tsconfig.json b/examples/nodejs-taco/tsconfig.json new file mode 100644 index 000000000..681ec7de2 --- /dev/null +++ b/examples/nodejs-taco/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src"], + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "noEmit": true + }, + "references": [ + { + "path": "../../packages/shared/tsconfig.cjs.json" + } + ] +} diff --git a/examples/nodejs/README.md b/examples/nodejs/README.md deleted file mode 100644 index 3a0a4278c..000000000 --- a/examples/nodejs/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# `nodejs` integration example - -Shows how to use `@nucypher/*` in NodeJS. - -## Usage - -```bash -pnpm install -pnpm start -``` diff --git a/packages/pre/test/acceptance/alice-grants.test.ts b/packages/pre/test/acceptance/alice-grants.test.ts index dda171e6a..324d6fc03 100644 --- a/packages/pre/test/acceptance/alice-grants.test.ts +++ b/packages/pre/test/acceptance/alice-grants.test.ts @@ -5,14 +5,6 @@ import { PublicKey, VerifiedKeyFrag, } from '@nucypher/nucypher-core'; -import { - ChecksumAddress, - EnactedPolicy, - Enrico, - initialize, - toBytes, - Ursula, -} from '@nucypher/shared'; import { bytesEqual, fakeAlice, @@ -32,6 +24,15 @@ import { } from '@nucypher/test-utils'; import { beforeAll, expect, test } from 'vitest'; +import { + ChecksumAddress, + EnactedPolicy, + Enrico, + initialize, + toBytes, + Ursula, +} from '../../src'; + test('story: alice shares message with bob through policy', () => { const message = 'secret-message-from-alice'; const threshold = 2; diff --git a/packages/pre/test/acceptance/delay-enact.test.ts b/packages/pre/test/acceptance/delay-enact.test.ts index 52271d2f5..7c2ef6428 100644 --- a/packages/pre/test/acceptance/delay-enact.test.ts +++ b/packages/pre/test/acceptance/delay-enact.test.ts @@ -1,4 +1,3 @@ -import { initialize } from '@nucypher/shared'; import { bytesEqual, fakeAlice, @@ -13,6 +12,8 @@ import { } from '@nucypher/test-utils'; import { beforeAll, expect, test } from 'vitest'; +import { initialize } from '../../src'; + test('story: alice creates a policy but someone else enacts it', () => { const threshold = 2; const shares = 3; diff --git a/packages/pre/test/docs.test.ts b/packages/pre/test/docs.test.ts index 3db288075..98af9386b 100644 --- a/packages/pre/test/docs.test.ts +++ b/packages/pre/test/docs.test.ts @@ -1,14 +1,3 @@ -import { - Cohort, - ConditionExpression, - ContractCondition, - ContractConditionProps, - ERC721Ownership, - getPorterUri, - initialize, - SecretKey, - toBytes, -} from '@nucypher/shared'; import { fakeProvider, fakeUrsulas, @@ -23,7 +12,18 @@ import { import { providers } from 'ethers'; import { beforeAll, expect, test, vi } from 'vitest'; -import { PreStrategy } from '../src'; +import { + Cohort, + ConditionExpression, + ContractCondition, + ContractConditionProps, + ERC721Ownership, + getPorterUri, + initialize, + PreStrategy, + SecretKey, + toBytes, +} from '../src'; test('doc tests', async () => { beforeAll(async () => { diff --git a/packages/pre/test/enrico.test.ts b/packages/pre/test/enrico.test.ts index 42dfe924f..41fa7c5a6 100644 --- a/packages/pre/test/enrico.test.ts +++ b/packages/pre/test/enrico.test.ts @@ -1,13 +1,5 @@ // Disabling because we want to access Alice.keyring which is a private property /* eslint-disable @typescript-eslint/no-explicit-any */ -import { - ConditionExpression, - Enrico, - ERC721Ownership, - PolicyMessageKit, - RetrievalResult, - toBytes, -} from '@nucypher/shared'; import { bytesEqual, fakeAlice, @@ -17,6 +9,15 @@ import { } from '@nucypher/test-utils'; import { expect, test } from 'vitest'; +import { + ConditionExpression, + Enrico, + ERC721Ownership, + PolicyMessageKit, + RetrievalResult, + toBytes, +} from '../src'; + test('enrico', () => { test('alice decrypts message encrypted by enrico', async () => { const label = 'fake-label'; diff --git a/packages/pre/test/message-kit.test.ts b/packages/pre/test/message-kit.test.ts index 885450920..7b6bea004 100644 --- a/packages/pre/test/message-kit.test.ts +++ b/packages/pre/test/message-kit.test.ts @@ -1,7 +1,8 @@ -import { MessageKit, toBytes } from '@nucypher/shared'; import { fakeBob } from '@nucypher/test-utils'; import { expect, test } from 'vitest'; +import { MessageKit, toBytes } from '../src'; + test('message kit', () => { test('bob decrypts', () => { const bob = fakeBob(); diff --git a/packages/pre/test/pre-strategy.test.ts b/packages/pre/test/pre-strategy.test.ts index f3cc334f3..09af8e0c9 100644 --- a/packages/pre/test/pre-strategy.test.ts +++ b/packages/pre/test/pre-strategy.test.ts @@ -1,14 +1,4 @@ import { SecretKey, VerifiedKeyFrag } from '@nucypher/nucypher-core'; -import { - ConditionExpression, - DeployedPreStrategy, - ERC721Ownership, - initialize, - PreDecrypter, - PreStrategy, - toBytes, - Ursula, -} from '@nucypher/shared'; import { aliceSecretKeyBytes, bobSecretKeyBytes, @@ -25,13 +15,23 @@ import { } from '@nucypher/test-utils'; import { afterEach, beforeAll, expect, test, vi } from 'vitest'; +import { + conditions, + DeployedPreStrategy, + initialize, + PreDecrypter, + PreStrategy, + toBytes, + Ursula, +} from '../src'; + // Shared test variables -const ownsNFT = new ERC721Ownership({ +const ownsNFT = new conditions.ERC721Ownership({ contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', parameters: [3591], chain: 5, }); -const conditionExpr = new ConditionExpression(ownsNFT); +const conditionExpr = new conditions.ConditionExpression(ownsNFT); const makePreStrategy = async () => { const aliceSecretKey = SecretKey.fromBEBytes(aliceSecretKeyBytes); diff --git a/packages/pre/test/pre.test.ts b/packages/pre/test/pre.test.ts index 9591b38cb..4b24873d9 100644 --- a/packages/pre/test/pre.test.ts +++ b/packages/pre/test/pre.test.ts @@ -1,4 +1,12 @@ import { CapsuleFrag, reencrypt } from '@nucypher/nucypher-core'; +import { + fakeAlice, + fakeBob, + fakeUrsulas, + reencryptKFrags, +} from '@nucypher/test-utils'; +import { beforeAll, expect, test } from 'vitest'; + import { Alice, Bob, @@ -12,14 +20,7 @@ import { RetrievalResult, toBytes, zip, -} from '@nucypher/shared'; -import { - fakeAlice, - fakeBob, - fakeUrsulas, - reencryptKFrags, -} from '@nucypher/test-utils'; -import { beforeAll, expect, test } from 'vitest'; +} from '../src'; test('proxy reencryption', () => { let alice: Alice; diff --git a/packages/pre/test/test-utils.ts b/packages/pre/test/test-utils.ts index c21d428e5..e957a500c 100644 --- a/packages/pre/test/test-utils.ts +++ b/packages/pre/test/test-utils.ts @@ -12,11 +12,16 @@ import { VerifiedCapsuleFrag, VerifiedKeyFrag, } from '@nucypher/nucypher-core'; -import { toBytes } from '@nucypher/shared'; import { SpyInstance, vi } from 'vitest'; -import { Alice, Bob, RemoteBob } from '../src/characters'; -import { BlockchainPolicy, PreEnactedPolicy } from '../src/policy'; +import { + Alice, + BlockchainPolicy, + Bob, + PreEnactedPolicy, + RemoteBob, + toBytes, +} from '../src'; export const fakeBob = (): Bob => { const secretKey = SecretKey.fromBEBytes( diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 08b6bfa4c..1e1650de2 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -6,8 +6,6 @@ export * from './types'; export * from './utils'; export * from './web3'; -// Forming modules for convenience -// TODO: Should we structure shared exports like this? import * as conditions from './conditions'; export { conditions }; diff --git a/packages/taco/src/index.ts b/packages/taco/src/index.ts index 449c45865..be362ac9d 100644 --- a/packages/taco/src/index.ts +++ b/packages/taco/src/index.ts @@ -1,6 +1,10 @@ export { DkgPublicKey, ThresholdMessageKit } from '@nucypher/nucypher-core'; -// TODO: Re-xport condition types from @nucypher/shared -export { Condition, getPorterUri } from '@nucypher/shared'; +export { + conditions, + getPorterUri, + initialize, + toBytes, +} from '@nucypher/shared'; -export { taco } from './taco'; +export { decrypt, encrypt } from './taco'; diff --git a/packages/taco/src/taco.ts b/packages/taco/src/taco.ts index 2208928b8..fe99b32a9 100644 --- a/packages/taco/src/taco.ts +++ b/packages/taco/src/taco.ts @@ -21,7 +21,7 @@ import { retrieveAndDecrypt } from './tdec'; export const encrypt = async ( provider: ethers.providers.Provider, - message: string, + message: Uint8Array | string, condition: Condition, ritualId: number, ): Promise => { @@ -42,18 +42,22 @@ export const encrypt = async ( }; export const encryptWithPublicKey = async ( - message: string, + message: Uint8Array | string, condition: Condition, dkgPublicKey: DkgPublicKey, authSigner?: Signer, ): Promise => { + if (typeof message === 'string') { + message = toBytes(message); + } + const conditionExpr = new ConditionExpression(condition); if (!authSigner) { authSigner = new Signer(SecretKey.random()); } const [ciphertext, authenticatedData] = encryptForDkg( - toBytes(message), + message, dkgPublicKey, conditionExpr.toWASMConditions(), ); diff --git a/packages/taco/test/cbd-strategy.test.ts b/packages/taco/test/cbd-strategy.test.ts index e17cf11c6..d17033402 100644 --- a/packages/taco/test/cbd-strategy.test.ts +++ b/packages/taco/test/cbd-strategy.test.ts @@ -3,15 +3,6 @@ import { SecretKey, SessionStaticSecret, } from '@nucypher/nucypher-core'; -import { - CbdStrategy, - ConditionExpression, - DeployedCbdStrategy, - ERC721Ownership, - initialize, - ThresholdDecrypter, - toBytes, -} from '@nucypher/shared'; import { aliceSecretKeyBytes, fakeDkgFlow, @@ -31,13 +22,22 @@ import { import { ethers } from 'ethers'; import { afterEach, beforeAll, expect, test, vi } from 'vitest'; +import { + CbdStrategy, + conditions, + DeployedCbdStrategy, + initialize, + ThresholdDecrypter, + toBytes, +} from '../src'; + // Shared test variables -const ownsNFT = new ERC721Ownership({ +const ownsNFT = new conditions.ERC721Ownership({ contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', parameters: [3591], chain: 5, }); -const conditionExpr = new ConditionExpression(ownsNFT); +const conditionExpr = new conditions.ConditionExpression(ownsNFT); const ritualId = 0; const makeCbdStrategy = async () => { diff --git a/packages/taco/test/dkg-client.test.ts b/packages/taco/test/dkg-client.test.ts index ba0454c45..ea8ee5a24 100644 --- a/packages/taco/test/dkg-client.test.ts +++ b/packages/taco/test/dkg-client.test.ts @@ -1,4 +1,3 @@ -import { DkgCoordinatorAgent, SecretKey } from '@nucypher/shared'; import { fakeProvider, mockCoordinatorRitual, @@ -8,6 +7,8 @@ import { } from '@nucypher/test-utils'; import { afterEach, expect, test, vi } from 'vitest'; +import { DkgCoordinatorAgent, SecretKey } from '../src'; + vi.mock('../../src/contracts/agents/coordinator', () => ({ DkgCoordinatorAgent: { getRitual: () => Promise.resolve(mockCoordinatorRitual(mockRitualId)), diff --git a/packages/taco/test/docs.test..ts b/packages/taco/test/docs.test..ts index e9695f831..26ecc0006 100644 --- a/packages/taco/test/docs.test..ts +++ b/packages/taco/test/docs.test..ts @@ -1,14 +1,3 @@ -import { - Cohort, - ConditionExpression, - ContractCondition, - ContractConditionProps, - ERC721Ownership, - getPorterUri, - initialize, - SecretKey, - toBytes, -} from '@nucypher/shared'; import { fakeProvider, fakeUrsulas, @@ -23,7 +12,18 @@ import { import { providers } from 'ethers'; import { beforeAll, expect, test, vi } from 'vitest'; -import { CbdStrategy } from '../src'; +import { + CbdStrategy, + Cohort, + ConditionExpression, + ContractCondition, + ContractConditionProps, + ERC721Ownership, + getPorterUri, + initialize, + SecretKey, + toBytes, +} from '../src'; test('doc tests', async () => { beforeAll(async () => { diff --git a/packages/taco/test/ritual.test.ts b/packages/taco/test/ritual.test.ts index 572aa657c..71fbb2109 100644 --- a/packages/taco/test/ritual.test.ts +++ b/packages/taco/test/ritual.test.ts @@ -1,7 +1,8 @@ import { DkgPublicKey } from '@nucypher/nucypher-core'; -import { fromHexString } from '@nucypher/shared'; import { expect, test } from 'vitest'; +import { fromHexString } from '../src'; + test('Ritual', () => { test('deserializes pre-made dkg ritual', async () => { const pkWord1 = fromHexString( diff --git a/packages/taco/test/taco.test.ts b/packages/taco/test/taco.test.ts index 7d8470bac..e72fe55e0 100644 --- a/packages/taco/test/taco.test.ts +++ b/packages/taco/test/taco.test.ts @@ -3,7 +3,6 @@ import { initialize, SessionStaticSecret, } from '@nucypher/nucypher-core'; -import { predefined, toBytes } from '@nucypher/shared'; import { aliceSecretKeyBytes, fakeDkgFlow, @@ -22,11 +21,11 @@ import { import { beforeAll, expect, test } from 'vitest'; import * as taco from '../src'; +import { conditions, toBytes } from '../src'; // Shared test variables -let variant: FerveoVariant; const message = 'this is a secret'; -const ownsNFT = new predefined.ERC721Ownership({ +const ownsNFT = new conditions.ERC721Ownership({ contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77', parameters: [3591], chain: 5, @@ -35,11 +34,10 @@ const ownsNFT = new predefined.ERC721Ownership({ test('taco', () => { beforeAll(async () => { await initialize(); - variant = FerveoVariant.precomputed; }); test('encrypts and decrypts', async () => { - const mockedDkg = fakeDkgFlow(variant, 0, 4, 4); + const mockedDkg = fakeDkgFlow(FerveoVariant.precomputed, 0, 4, 4); const mockedDkgRitual = fakeDkgRitual(mockedDkg); const provider = fakeProvider(aliceSecretKeyBytes); const signer = fakeSigner(aliceSecretKeyBytes); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b2225788b..20ca092b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,11 +132,26 @@ importers: specifier: 5.2.2 version: 5.2.2 - examples/nodejs: + examples/nodejs-pre: dependencies: '@nucypher/pre': specifier: workspace:* version: link:../../packages/pre + dotenv: + specifier: ^16.3.1 + version: 16.3.1 + ethers: + specifier: ^5.7.2 + version: 5.7.2 + + examples/nodejs-taco: + dependencies: + '@nucypher/taco': + specifier: workspace:* + version: link:../../packages/taco + dotenv: + specifier: ^16.3.1 + version: 16.3.1 ethers: specifier: ^5.7.2 version: 5.7.2 @@ -6331,6 +6346,11 @@ packages: engines: {node: '>=10'} dev: true + /dotenv@16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: false + /dotgitignore@2.1.0: resolution: {integrity: sha512-sCm11ak2oY6DglEPpCB8TixLjWAxd3kJTs6UIcSasNYxXdFPV+YKlye92c8H4kKFqV5qYMIh7d+cYecEg0dIkA==} engines: {node: '>=6'}