Skip to content

Commit

Permalink
Use @nucypher/nucypher-contracts contract registry (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec authored Oct 17, 2023
2 parents 9c172be + ed55e6b commit d52f9e6
Show file tree
Hide file tree
Showing 58 changed files with 3,686 additions and 25,854 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Test
run: pnpm test

- name: Check examples
- name: Check examples & demos
run: pnpm check-examples

- name: Upload coverage to Codecov
Expand Down
5 changes: 4 additions & 1 deletion demos/taco-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"author": "Piotr Rosłaniec <p.roslaniec@gmail.com>",
"scripts": {
"start": "webpack serve --mode development",
"build": "tsc --noEmit && rimraf build && webpack --mode production --progress"
"build": "pnpm clean && webpack --mode production --progress",
"clean": "rimraf build",
"check": "pnpm typecheck && pnpm build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nucypher/taco": "workspace:*",
Expand Down
6 changes: 4 additions & 2 deletions demos/taco-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
conditions,
decrypt,
domains,
encrypt,
getPorterUri,
initialize,
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function App() {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const encryptedMessage = await encrypt(
provider,
domains.TESTNET,
message,
condition,
ritualId,
Expand All @@ -62,12 +64,12 @@ export default function App() {
setDecryptionErrors([]);

const provider = new ethers.providers.Web3Provider(window.ethereum);
const porterUri = getPorterUri('lynx');
const decryptedMessage = await decrypt(
provider,
domains.TESTNET,
encryptedMessage,
getPorterUri(domains.TESTNET),
provider.getSigner(),
porterUri,
);

setDecryptedMessage(new TextDecoder().decode(decryptedMessage));
Expand Down
5 changes: 4 additions & 1 deletion demos/taco-nft-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"author": "Piotr Rosłaniec <p.roslaniec@gmail.com>",
"scripts": {
"start": "webpack serve --mode development",
"build": "tsc --noEmit && rimraf build && webpack --mode production --progress"
"build": "pnpm clean && webpack --mode production --progress",
"clean": "rimraf build",
"check": "pnpm typecheck && pnpm build",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nucypher/taco": "workspace:*",
Expand Down
6 changes: 4 additions & 2 deletions demos/taco-nft-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
conditions,
decrypt,
domains,
encrypt,
getPorterUri,
initialize,
Expand Down Expand Up @@ -42,6 +43,7 @@ export default function App() {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const encryptedMessage = await encrypt(
provider,
domains.TESTNET,
message,
condition,
ritualId,
Expand All @@ -61,12 +63,12 @@ export default function App() {
setDecryptionErrors([]);

const provider = new ethers.providers.Web3Provider(window.ethereum);
const porterUri = getPorterUri('lynx');
const decryptedMessage = await decrypt(
provider,
domains.TESTNET,
encryptedMessage,
getPorterUri(domains.TESTNET),
provider.getSigner(),
porterUri,
);

setDecryptedMessage(new TextDecoder().decode(decryptedMessage));
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
This directory contains a set of examples showing how to integrate `@nucypher/*`
into your application.

Refer to `./taco` for examples of how to use the `@nucypher/taco` package.
Refer to `./pre` for examples of how to use the `@nucypher/pre` package.
Refer to `./taco` for examples of how to use the `@nucypher/taco` package. Refer
to `./pre` for examples of how to use the `@nucypher/pre` package.
13 changes: 7 additions & 6 deletions examples/pre/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SecretKey,
toHexString,
} from '@nucypher/pre';
import {ethers} from 'ethers';
import {useEffect, useState} from 'react';
import { ethers } from 'ethers';
import { useEffect, useState } from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const window: any;
Expand All @@ -35,12 +35,12 @@ function App() {
}
const provider = new ethers.providers.Web3Provider(window.ethereum, 'any');

const {chainId} = await provider.getNetwork();
const { chainId } = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{chainId: '0x13881'}],
params: [{ chainId: '0x13881' }],
});
}

Expand Down Expand Up @@ -68,8 +68,8 @@ function App() {
};

const makeRemoteBob = (bob: Bob) => {
const {decryptingKey, verifyingKey} = bob;
return {decryptingKey, verifyingKey};
const { decryptingKey, verifyingKey } = bob;
return { decryptingKey, verifyingKey };
};

const makeCharacters = () => {
Expand Down Expand Up @@ -107,6 +107,7 @@ function App() {
const policy = await alice.grant(
provider,
provider.getSigner(),
domains.TESTNET,
getPorterUri(domains.TESTNET),
policyParams,
);
Expand Down
9 changes: 7 additions & 2 deletions examples/pre/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ const runExample = async () => {
startDate: new Date(),
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30), // In 30 days,
};
const porterUri = getPorterUri(domains.TESTNET);
const alice = makeAlice();

console.log('Creating policy...');
const policy = await alice.grant(provider, signer, porterUri, policyParams);
const policy = await alice.grant(
provider,
signer,
domains.TESTNET,
getPorterUri(domains.TESTNET),
policyParams,
);

console.log('Policy created:');
console.log({ policy });
Expand Down
3 changes: 2 additions & 1 deletion examples/pre/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getPorterUri,
initialize,
SecretKey,
toHexString
toHexString,
} from '@nucypher/pre';
import { ethers } from 'ethers';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -98,6 +98,7 @@ function App() {
const policy = await alice.grant(
provider,
provider.getSigner(),
domains.TESTNET,
getPorterUri(domains.TESTNET),
policyParams,
);
Expand Down
3 changes: 2 additions & 1 deletion examples/pre/webpack-5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pnpm install
pnpm start
```

Go to [localhost:8080](http://localhost:8080/) in your browser and look in the JS console.
Go to [localhost:8080](http://localhost:8080/) in your browser and look in the
JS console.
4 changes: 2 additions & 2 deletions examples/pre/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ const runExample = async () => {
startDate,
endDate,
};
const porterUri = getPorterUri(domains.TESTNET);

const alice = makeAlice();
const policy = await alice.grant(
provider,
provider.getSigner(),
porterUri,
domains.TESTNET,
getPorterUri(domains.TESTNET),
policyParams,
);

Expand Down
38 changes: 26 additions & 12 deletions examples/taco/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
encrypt,
fromBytes,
getPorterUri,
initialize
initialize,
} from '@nucypher/taco';
import {ethers} from 'ethers';
import {useEffect, useState} from 'react';
import { ethers } from 'ethers';
import { useEffect, useState } from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const window: any;
Expand All @@ -21,7 +21,9 @@ function App() {
const [provider, setProvider] = useState<
ethers.providers.Web3Provider | undefined
>();
const [decryptedMessage, setDecryptedMessage] = useState<string | undefined>("");
const [decryptedMessage, setDecryptedMessage] = useState<string | undefined>(
'',
);

const initNucypher = async () => {
await initialize();
Expand All @@ -34,12 +36,12 @@ function App() {
}
const provider = new ethers.providers.Web3Provider(window.ethereum, 'any');

const {chainId} = await provider.getNetwork();
const { chainId } = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{chainId: '0x13881'}],
params: [{ chainId: '0x13881' }],
});
}

Expand Down Expand Up @@ -67,12 +69,12 @@ function App() {
await provider.send('eth_requestAccounts', []);
const signer = provider.getSigner();

const {chainId} = await provider.getNetwork();
const { chainId } = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum!.request!({
method: 'wallet_switchEthereumChain',
params: [{chainId: '0x13881'}],
params: [{ chainId: '0x13881' }],
});
}

Expand All @@ -88,19 +90,31 @@ function App() {
},
});
const ritualId = 2; // Replace with your own ritual ID
const messageKit = await encrypt(provider, message, hasPositiveBalance, ritualId, signer);
const messageKit = await encrypt(
provider,
domains.TESTNET,
message,
hasPositiveBalance,
ritualId,
signer,
);

console.log('Decrypting message...');
const porterUri = getPorterUri(domains.DEV);
const decryptedMessage = await decrypt(provider, messageKit,porterUri,signer);
const decryptedMessage = await decrypt(
provider,
domains.TESTNET,
messageKit,
getPorterUri(domains.TESTNET),
signer,
);

setDecryptedMessage(fromBytes(decryptedMessage));
};

return (
<div>
<h1>Secret message: {message}</h1>
{(decryptedMessage && <h1>Decrypted message: {decryptedMessage}</h1>)}
{decryptedMessage && <h1>Decrypted message: {decryptedMessage}</h1>}
<button onClick={runExample}>Run example</button>
</div>
);
Expand Down
14 changes: 10 additions & 4 deletions examples/taco/nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
conditions,
decrypt,
domains,
encrypt,
fromBytes,
getPorterUri,
initialize,
domains,
toBytes,
} from '@nucypher/taco';
import * as dotenv from 'dotenv';
Expand Down Expand Up @@ -48,18 +48,24 @@ const runExample = async () => {
hasPositiveBalance.requiresSigner(),
'Condition requires signer',
);
const ritualId = 1; // Replace with your own ritual ID
const ritualId = 2; // Replace with your own ritual ID
const messageKit = await encrypt(
provider,
domains.TESTNET,
message,
hasPositiveBalance,
ritualId,
signer,
);

console.log('Decrypting message...');
const porterUri = getPorterUri(domains.DEV);
const decryptedBytes = await decrypt(provider, messageKit, porterUri, signer);
const decryptedBytes = await decrypt(
provider,
domains.TESTNET,
messageKit,
getPorterUri(domains.TESTNET),
signer,
);
const decryptedMessageString = fromBytes(decryptedBytes);
console.log('Decrypted message:', decryptedMessageString);
console.assert(
Expand Down
5 changes: 3 additions & 2 deletions examples/taco/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

Shows how to integrate `@nucypher/taco` into a React application.

In order to load WASM dependencies of `@nucypher/taco`, we override the `react-scripts` configuration with `craco`. For
more details, see the `craco.config.js` file.
In order to load WASM dependencies of `@nucypher/taco`, we override the
`react-scripts` configuration with `craco`. For more details, see the
`craco.config.js` file.

## Usage

Expand Down
Loading

0 comments on commit d52f9e6

Please sign in to comment.