1 import { base64StringToUint8Array } from '../../lib/helpers/encoding';
3 generateMnemonicBase64RandomBytes,
4 generateMnemonicFromBase64RandomBytes,
5 mnemonicToBase64RandomBytes,
7 } from '../../lib/mnemonic';
9 describe('generateMnemonicBase64RandomBytes', () => {
10 it('should return base64 string', () => {
11 const base64RandomBytes = generateMnemonicBase64RandomBytes();
14 base64StringToUint8Array(base64RandomBytes);
18 it('should return base64 string of length 16', () => {
19 const base64RandomBytes = generateMnemonicBase64RandomBytes();
21 const randomBytes = base64StringToUint8Array(base64RandomBytes);
23 expect(randomBytes.length).toBe(16);
27 describe('generateMnemonicFromBase64RandomBytes', () => {
28 it('should generate mnemonic', async () => {
29 const base64RandomBytes = 'yNbY5xQk5N8ROW0Ci7Yg4g==';
31 const result = await generateMnemonicFromBase64RandomBytes(base64RandomBytes);
33 expect(result).toBe('silver replace degree choose exact hurdle eager color action frozen market series');
37 describe('mnemonicToBase64RandomBytes', () => {
38 it('should recover base 64 random bytes from mnemonic', async () => {
39 const mnemonic = 'frozen craft abuse human property drama dutch frame carpet giant orange aim';
41 const result = await mnemonicToBase64RandomBytes(mnemonic);
43 expect(result).toBe('XaZABLdqxoRRGuQizDZvAg==');
47 describe('validateMnemonic', () => {
48 it('should return false for an invalid mnemonic', async () => {
49 const invaldMnemonic = 'this is definitely an invalid mnemonic';
51 const result = await validateMnemonic(invaldMnemonic);
53 expect(result).toBeFalse();
56 it('should return true for a valid mnemonic', async () => {
57 const validMnemonic = 'frozen craft abuse human property drama dutch frame carpet giant orange aim';
59 const result = await validateMnemonic(validMnemonic);
61 expect(result).toBeTrue();