import { bufferToHex } from './buffer' ; import { getAddressFromPublicKey } from './convert' ; import { hash } from './hash' ; import { getKeyPair } from './nacl' ; export interface KeypairBytes { readonly privateKeyBytes : Buffer ; readonly publicKeyBytes : Buffer ; } export interface Keypair { readonly privateKey : string ; readonly publicKey : string ; } export const getPrivateAndPublicKeyBytesFromPassphrase = ( passphrase ) : KeypairBytes => { const hashed = hash ( passphrase , 'utf8' ) ; const { publicKeyBytes , privateKeyBytes } = getKeyPair ( hashed ) ; return { privateKeyBytes , publicKeyBytes , } ; } ; export const getPrivateAndPublicKeyFromPassphrase = ( passphrase ) : Keypair => { const { privateKeyBytes , publicKeyBytes , } = getPrivateAndPublicKeyBytesFromPassphrase ( passphrase ) ; return { privateKey : bufferToHex ( privateKeyBytes ) , publicKey : bufferToHex ( publicKeyBytes ) , } ; } ; export const getKeys = getPrivateAndPublicKeyFromPassphrase ; export const getAddressAndPublicKeyFromPassphrase = ( passphrase ) : { readonly address : string ; readonly publicKey : string ; } => { const { publicKey } = getKeys ( passphrase ) ; const address = getAddressFromPublicKey ( publicKey ) ; return { address , publicKey , } ; } ; export const getAddressFromPassphrase = ( passphrase ) : string => { const { publicKey } = getKeys ( passphrase ) ; return getAddressFromPublicKey ( publicKey ) ; } ;