By default, it will generate a 12-word phrase.
Create a new phrase using generatePhrase()
Check phrase validity using validatePhrase()
Encrypt to keystore using encryptToKeyStore() > takes two arguements (phrase, password)\
// Imports
import { generatePhrase, validatePhrase, encryptToKeyStore, decryptFromKeystore } from "@xchainjs/xchain-crypto"
require('dotenv').config();
const keystore1 = JSON.parse(fs.readFileSync('keystore.json', 'utf8'))
const password = process.env.PASSWORD
// Generate Keystore and save it to a keystore file
const GenerateKeystore = async () => {
const phrase = generatePhrase()
console.log(`phrase ${phrase}`)
const isCorrect = validatePhrase(phrase) //validate phrase if needed returns Boolean
console.log(`Phrase valid?: ${isCorrect}`)
const keystore = await encryptToKeyStore(phrase, password)
fs.writeFileSync(`./keystore.json`, JSON.stringify(keystore, null, 4), 'utf8')
}
Decrypt Keystore to Retrieve a Phrase
Retrieve the phrase by calling decryptFromKeystore()\