import tweetnacl from 'tweetnacl' ; import { NaclInterface } from './nacl_types' ; export const box = ( messageInBytes , nonceInBytes , convertedPublicKey , convertedPrivateKey ) => Buffer . from ( tweetnacl . box ( messageInBytes , nonceInBytes , convertedPublicKey , convertedPrivateKey ) ) ; export const openBox = ( cipherBytes , nonceBytes , convertedPublicKey , convertedPrivateKey ) => { const originalMessage = tweetnacl . box . open ( cipherBytes , nonceBytes , convertedPublicKey , convertedPrivateKey ) ; if ( originalMessage === null ) { throw new Error ( 'Failed to decrypt message' ) ; } return Buffer . from ( originalMessage ) ; } ; export const signDetached = ( messageBytes , privateKeyBytes ) => Buffer . from ( tweetnacl . sign . detached ( messageBytes , privateKeyBytes ) ) ; export const verifyDetached = tweetnacl . sign . detached . verify ; export const getRandomBytes = length => Buffer . from ( tweetnacl . randomBytes ( length ) ) ; export const getKeyPair = hashedSeed => { const { publicKey , secretKey } = tweetnacl . sign . keyPair . fromSeed ( hashedSeed ) ; return { privateKeyBytes : Buffer . from ( secretKey ) , publicKeyBytes : Buffer . from ( publicKey ) , } ; } ;