import { secretbox } from 'tweetnacl' ; export const encrypt = ( { nonce , key , } ) => ( plaintext ) : Uint8Array => { return secretbox ( plaintext , nonce , key ) ; } ; export const decrypt = ( { nonce , key , } ) => ( ciphertext ) : Uint8Array => { const plaintext = secretbox . open ( ciphertext , nonce , key ) ; if ( ! plaintext ) { throw new Error ( 'Failed to decrypt message' ) ; } return plaintext ; } ;