Create an account (privatKey, public address pairt) from celo utils generateKeys. #229
Answered
by
Allen-Muhani
Allen-Muhani
asked this question in
Help (Q&A)
-
Herre is the logic import { MnemonicLanguages, generateMnemonic, MnemonicStrength, generateKeys } from '@celo/utils/lib/account';
import * as bip39 from 'react-native-bip39';
const MNEMONIC_BIT_LENGTH = MnemonicStrength.s256_24words
const checkDuplicate = (someString: string) => {
return new Set(someString.split(' ')).size !== someString.split(' ').length
}
export function getMnemonicLanguage(language: string | null) {
switch (language?.slice(0, 2)) {
case 'es': {
return MnemonicLanguages.spanish
}
case 'pt': {
return MnemonicLanguages.portuguese
}
default: {
return MnemonicLanguages.english
}
}
}
export async function generateNewMnemonic(): Promise<string> {
const mnemonicLanguage = getMnemonicLanguage("");
let mnemonic = await generateMnemonic(MNEMONIC_BIT_LENGTH, mnemonicLanguage, bip39)
let isDuplicateInMnemonic = checkDuplicate(mnemonic);
while (isDuplicateInMnemonic) {
let mnemonic = await generateMnemonic(MNEMONIC_BIT_LENGTH, mnemonicLanguage, bip39)
isDuplicateInMnemonic = checkDuplicate(mnemonic)
}
return mnemonic;
}
export async function createNewAccountWithMnemonic() {
const mnemonic = await generateNewMnemonic();
const keys = generateKeys(mnemonic, undefined, undefined, undefined, bip39);
console.log("=======================> keys", keys, mnemonic)
} calling the method createNewAccountWithMenmonic() produces the following output =======================> keys Promise {
"_U": 0,
"_V": 0,
"_W": null,
"_X": null,
} magic shock horror mail give slab way flat salt common spin scale armor barrel weird cactus stomach cotton punch sudden flash good slab marriage I can`t figure out why the result is null. |
Beta Was this translation helpful? Give feedback.
Answered by
Allen-Muhani
May 26, 2022
Replies: 0 comments 3 replies
-
Got it. It missed an await. Thanks |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Allen-Muhani
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it. It missed an await. Thanks