-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: taco react and nextjs example (#419)
- Loading branch information
Showing
11 changed files
with
302 additions
and
127 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
conditions, | ||
decrypt, | ||
Domain, | ||
encrypt, | ||
getPorterUri, | ||
initialize, | ||
ThresholdMessageKit, | ||
} from '@nucypher/taco'; | ||
import { ethers } from 'ethers'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
export default function useTaco({ | ||
ritualId, | ||
domain, | ||
provider, | ||
}: { | ||
ritualId: number; | ||
domain: Domain; | ||
provider: ethers.providers.Provider | undefined; | ||
}) { | ||
const [isInit, setIsInit] = useState(false); | ||
|
||
useEffect(() => { | ||
initialize().then(() => setIsInit(true)); | ||
}, []); | ||
|
||
const decryptDataFromBytes = useCallback( | ||
async (encryptedBytes: Uint8Array, signer?: ethers.Signer) => { | ||
if (!isInit || !provider) return; | ||
const messageKit = ThresholdMessageKit.fromBytes(encryptedBytes); | ||
return decrypt( | ||
provider, | ||
domain, | ||
messageKit, | ||
getPorterUri(domain), | ||
signer, | ||
); | ||
}, | ||
[isInit, provider, domain], | ||
); | ||
|
||
const encryptDataToBytes = useCallback( | ||
async ( | ||
message: string, | ||
condition: conditions.Condition, | ||
encryptorSigner: ethers.Signer, | ||
) => { | ||
if (!isInit || !provider) return; | ||
const messageKit = await encrypt( | ||
provider, | ||
domain, | ||
message, | ||
condition, | ||
ritualId, | ||
encryptorSigner, | ||
); | ||
return messageKit.toBytes(); | ||
}, | ||
[isInit, provider, domain, ritualId], | ||
); | ||
|
||
return { | ||
isInit, | ||
decryptDataFromBytes, | ||
encryptDataToBytes, | ||
}; | ||
} |
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,7 @@ | ||
input { | ||
font-size: 20px; | ||
} | ||
|
||
button { | ||
font-size: 15px; | ||
} |
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.