-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): add a nodejs-taco example
- Loading branch information
1 parent
0a71684
commit 3d564b6
Showing
30 changed files
with
301 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ examples/*/pnpm-lock.yaml | |
pnpm-debug.log | ||
docs-json | ||
./docs | ||
.env |
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 |
---|---|---|
@@ -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. |
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,2 @@ | ||
RPC_PROVIDER_URL= | ||
PRIVATE_KEY= |
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,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 | ||
``` |
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
File renamed without changes.
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,2 @@ | ||
RPC_PROVIDER_URL= | ||
PRIVATE_KEY= |
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,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 | ||
``` |
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,18 @@ | ||
{ | ||
"version": "0.1.0", | ||
"private": true, | ||
"license": "GPL-3.0-only", | ||
"author": "Piotr Rosłaniec <p.roslaniec@gmail.com>", | ||
"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" | ||
} | ||
} |
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,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); | ||
}); |
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,14 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"noEmit": true | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../../packages/shared/tsconfig.cjs.json" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.