Skip to content

Commit

Permalink
Update taco demo to use latest released version of taco, `taco-auth…
Browse files Browse the repository at this point in the history
…` and update code accordingly.
  • Loading branch information
derekpierre committed Sep 4, 2024
1 parent 9aa013e commit 60cf051
Show file tree
Hide file tree
Showing 4 changed files with 929 additions and 213 deletions.
25 changes: 13 additions & 12 deletions demos/taco-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@irys/sdk": "^0.1.16",
"@nucypher/taco": "^0.3.0",
"@usedapp/core": "^1.2.13",
"@irys/sdk": "^0.1.24",
"@nucypher/taco": "^0.5.0",
"@nucypher/taco-auth": "^0.2.0",
"@usedapp/core": "^1.2.16",
"buffer": "^6.0.3",
"ethers": "^5.7.1",
"ethers": "^5.7.2",
"file-loader": "^6.2.0",
"react": "^18.3.1",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.3.1",
"react-spinners": "^0.14.1"
},
"devDependencies": {
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@types/react": "^18.3.5",
"@types/react-copy-to-clipboard": "^5.0.7",
"@types/react-dom": "^18.3.0",
"copy-webpack-plugin": "^12.0.2",
"crypto-browserify": "^3.12.0",
"esbuild-loader": "^2.20.0",
"html-webpack-plugin": "^5.5.0",
"esbuild-loader": "^2.21.0",
"html-webpack-plugin": "^5.6.0",
"process": "^0.11.10",
"react-refresh": "^0.14.0",
"rimraf": "^5.0.5",
"react-refresh": "^0.14.2",
"rimraf": "^5.0.10",
"stream-browserify": "^3.0.0",
"typescript": "^4.8.3",
"typescript": "^4.9.5",
"vm-browserify": "^1.1.2",
"webpack": "^5.93.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.11.1"
"webpack-dev-server": "^4.15.2"
}
}
22 changes: 20 additions & 2 deletions demos/taco-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
ThresholdMessageKit,
toHexString,
} from '@nucypher/taco';
import {
EIP4361AuthProvider,
USER_ADDRESS_PARAM_DEFAULT,
} from '@nucypher/taco-auth';
import { useEthers } from '@usedapp/core';
import { ethers } from 'ethers';
import React, { useEffect, useState } from 'react';
Expand Down Expand Up @@ -84,12 +88,26 @@ export default function App() {
Buffer.from(encryptedMessageHex, 'hex'),
);

// create condition context
const conditionContext = conditions.context.ConditionContext.fromMessageKit(encryptedMessage);

// illustrative optional example of checking what context parameters are required
if (
conditionContext.requestedContextParameters.has(USER_ADDRESS_PARAM_DEFAULT)
) {
// add authentication for ":userAddress" in condition
const authProvider = new EIP4361AuthProvider(
provider,
provider.getSigner()
);
conditionContext.addAuthProvider(USER_ADDRESS_PARAM_DEFAULT, authProvider);
}

const decryptedMessage = await decrypt(
provider,
domain,
encryptedMessage,
undefined,
provider.getSigner(),
conditionContext,
);

setDecryptedMessage(new TextDecoder().decode(decryptedMessage));
Expand Down
7 changes: 2 additions & 5 deletions demos/taco-demo/src/irys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ export const getWebIrys = async (provider: providers.Provider) => {
return webIrys;
};

export const uploadData = async (
webIrys: WebIrys,
data: unknown,
): Promise<string> => {
export const uploadData = async (webIrys: WebIrys, data: unknown): Promise => {
const dataToUpload = JSON.stringify(data);
const receipt = await webIrys.upload(dataToUpload);
console.log(`Data uploaded ==> https://gateway.irys.xyz/${receipt.id}`);
return receipt.id;
};

export const downloadData = async (receiptId: string): Promise<unknown> => {
export const downloadData = async (receiptId: string): Promise => {
const response = await fetch(`https://gateway.irys.xyz/${receiptId}`);
const dataJson = await response.text();
return JSON.parse(dataJson);
Expand Down
Loading

0 comments on commit 60cf051

Please sign in to comment.