useDecrypt
For decrypting a ciphertext
Hook parameters:
interface IUseDecryptArguments {
cipherText: string // Encrypted text
tpk?: string // Transaction public key
programId?: string // Program ID
functionName?: string // Function name
index?: number // Account index м/44'/0'/<account_index>'/0'
enabled?: boolean // auto decrypt
}
Return values:
// useDecrypt hook returns next fields
decryptedText: string // Decrypted text
loading: boolean // loading state
error: any // error message if something went wrong
decrypt: () => Promise<void> // a function to force decryption
Example (live demo https://aleo-react-boilerplate.vercel.app/):
import { FC } from 'react'
import { useDecrypt } from 'aleo-hooks'
export const UseDecrypt: FC = () => {
const { decryptedText, loading, error } = useDecrypt({
cipherText: 'ciphertext1qgqtzwpwj2r0rw0md3zxlnnj9h7azun02f6tdm27u8ywxcsuw4pssp7xsp7edm749l4pd9s47wksc475dkhmjnl7yrzzylgnfyx2kfwkpqlsynj2'
})
return (
<div>
{loading && <p>Loading...</p>}
{error && <p>Something went wrong {JSON.stringify(error)}</p>}
{decryptedText && <p>Decrypted text: {decryptedText}</p>}
</div>
)
}
Last updated