@celo/utils › "packages/sdk/utils/src/account"
Module: "packages/sdk/utils/src/account"
Index
References
Functions
- detectMnemonicLanguage
- formatNonAccentedCharacters
- generateDeterministicInviteCode
- generateKeys
- generateKeysFromSeed
- generateMnemonic
- generateSeed
- getAllLanguages
- invalidMnemonicWords
- mnemonicLengthFromStrength
- normalizeMnemonic
- suggestMnemonicCorrections
- validateMnemonic
Object literals
References
Bip39
• Bip39:
CELO_DERIVATION_PATH_BASE
• CELO_DERIVATION_PATH_BASE:
MnemonicLanguages
• MnemonicLanguages:
MnemonicStrength
• MnemonicStrength:
RandomNumberGenerator
• RandomNumberGenerator:
Functions
detectMnemonicLanguage
▸ detectMnemonicLanguage(words
: string[], candidates?
: MnemonicLanguages[]): MnemonicLanguages | undefined
Defined in packages/sdk/utils/src/account.ts:230
Detects the language of tokenized mnemonic phrase by applying a heuristic.
remarks
Uses a heuristic of returning the language with the most matching words. In practice, we
expect all words to come from a single language, also some may be misspelled or otherwise
malformed. It may occasionally occur that a typo results in word from another language (e.g. bag
-> bagr) but this should occur at most once or twice per phrase.
Parameters:
Name | Type |
---|---|
words |
string[] |
candidates? |
MnemonicLanguages[] |
Returns: MnemonicLanguages | undefined
formatNonAccentedCharacters
▸ formatNonAccentedCharacters(mnemonic
: string): string
Defined in packages/sdk/utils/src/account.ts:156
deprecated
now an alias for normalizeMnemonic.
Parameters:
Name | Type |
---|---|
mnemonic |
string |
Returns: string
generateDeterministicInviteCode
▸ generateDeterministicInviteCode(recipientPhoneHash
: string, recipientPepper
: string, addressIndex
: number, changeIndex
: number, derivationPath
: string): object
Defined in packages/sdk/utils/src/account.ts:412
Parameters:
Name | Type | Default |
---|---|---|
recipientPhoneHash |
string | - |
recipientPepper |
string | - |
addressIndex |
number | 0 |
changeIndex |
number | 0 |
derivationPath |
string | CELO_DERIVATION_PATH_BASE |
Returns: object
-
privateKey: string
-
publicKey: string
generateKeys
▸ generateKeys(mnemonic
: string, password?
: undefined | string, changeIndex
: number, addressIndex
: number, bip39ToUse
: Bip39, derivationPath
: string): Promise‹object›
Defined in packages/sdk/utils/src/account.ts:400
Parameters:
Name | Type | Default |
---|---|---|
mnemonic |
string | - |
password? |
undefined | string | - |
changeIndex |
number | 0 |
addressIndex |
number | 0 |
bip39ToUse |
Bip39 | bip39Wrapper |
derivationPath |
string | CELO_DERIVATION_PATH_BASE |
Returns: Promise‹object›
generateKeysFromSeed
▸ generateKeysFromSeed(seed
: Buffer, changeIndex
: number, addressIndex
: number, derivationPath
: string): object
Defined in packages/sdk/utils/src/account.ts:440
Parameters:
Name | Type | Default |
---|---|---|
seed |
Buffer | - |
changeIndex |
number | 0 |
addressIndex |
number | 0 |
derivationPath |
string | CELO_DERIVATION_PATH_BASE |
Returns: object
-
address: string
-
privateKey: string
-
publicKey: string
generateMnemonic
▸ generateMnemonic(strength
: MnemonicStrength, language?
: MnemonicLanguages, bip39ToUse
: Bip39): Promise‹string›
Defined in packages/sdk/utils/src/account.ts:51
Parameters:
Name | Type | Default |
---|---|---|
strength |
MnemonicStrength | MnemonicStrength.s256_24words |
language? |
MnemonicLanguages | - |
bip39ToUse |
Bip39 | bip39Wrapper |
Returns: Promise‹string›
generateSeed
▸ generateSeed(mnemonic
: string, password?
: undefined | string, bip39ToUse
: Bip39, keyByteLength
: number): Promise‹Buffer›
Defined in packages/sdk/utils/src/account.ts:425
Parameters:
Name | Type | Default |
---|---|---|
mnemonic |
string | - |
password? |
undefined | string | - |
bip39ToUse |
Bip39 | bip39Wrapper |
keyByteLength |
number | 64 |
Returns: Promise‹Buffer›
getAllLanguages
▸ getAllLanguages(): MnemonicLanguages[]
Defined in packages/sdk/utils/src/account.ts:185
Returns: MnemonicLanguages[]
invalidMnemonicWords
▸ invalidMnemonicWords(mnemonic
: string, language?
: MnemonicLanguages): string[] | undefined
Defined in packages/sdk/utils/src/account.ts:85
Return a list of the words in the mnemonic that are not in the list of valid BIP-39 words for the specified or detected language.
remarks
Will return undefined if the language cannot be detected (e.g. all the words are
invalid, or half of the valid words are from one language and the other half from another.)
Parameters:
Name | Type |
---|---|
mnemonic |
string |
language? |
MnemonicLanguages |
Returns: string[] | undefined
mnemonicLengthFromStrength
▸ mnemonicLengthFromStrength(strength
: MnemonicStrength): number
Defined in packages/sdk/utils/src/account.ts:199
Parameters:
Name | Type |
---|---|
strength |
MnemonicStrength |
Returns: number
normalizeMnemonic
▸ normalizeMnemonic(mnemonic
: string, language?
: MnemonicLanguages): string
Defined in packages/sdk/utils/src/account.ts:106
Normalize the mnemonic phrase to eliminate a number of inconsistencies with standard BIP-39 phrases that are likely to arise when a user manually enters a phrase.
remarks
Note that this does not guarantee that the output is a valid mnemonic phrase, or even
that all the words in the phrase are contained in a valid wordlist.
Parameters:
Name | Type |
---|---|
mnemonic |
string |
language? |
MnemonicLanguages |
Returns: string
suggestMnemonicCorrections
▸ suggestMnemonicCorrections(mnemonic
: string, language?
: MnemonicLanguages, strength?
: MnemonicStrength): Generator‹string›
Defined in packages/sdk/utils/src/account.ts:285
Generates a list of suggested corrections to the mnemonic phrase based on a set of heuristics.
remarks
Each yielded suggestion represents an attempt to correct the seed phrase by replacing any invalid
words with the most likely valid words. Returned suggestions phrases are ordered by probability
based on a noisy channel model, described in detail in CIP-39.
The generated list of suggestions is exponential in size, and effectively infinite. One should not attempt to generate the entire list.
All yielded suggestions will have a valid checksum, but are not guaranteed to correspond to any given wallet. If the phrase is being used to recover a wallet with non-zero balance, it is suggested that the caller check the balance of the derived wallet address. If the balance is non-zero, they can be sure that the phrase is correct. If it is zero, then they should continue and try the next suggestion.
It is recommended to normalize the mnemonic phrase before inputting to this function.
privateremarks
TODO(victor): Include a heuristic rule for phrase-level corrections, such as word ordering swaps.
Parameters:
Name | Type |
---|---|
mnemonic |
string |
language? |
MnemonicLanguages |
strength? |
MnemonicStrength |
Returns: Generator‹string›
validateMnemonic
▸ validateMnemonic(mnemonic
: string, bip39ToUse
: Bip39, language?
: MnemonicLanguages): boolean
Defined in packages/sdk/utils/src/account.ts:59
Parameters:
Name | Type | Default |
---|---|---|
mnemonic |
string | - |
bip39ToUse |
Bip39 | bip39Wrapper |
language? |
MnemonicLanguages | - |
Returns: boolean
Object literals
Const
AccountUtils
▪ AccountUtils: object
Defined in packages/sdk/utils/src/account.ts:461
detectMnemonicLanguage
• detectMnemonicLanguage: detectMnemonicLanguage
Defined in packages/sdk/utils/src/account.ts:462
generateKeys
• generateKeys: generateKeys
Defined in packages/sdk/utils/src/account.ts:468
generateKeysFromSeed
• generateKeysFromSeed: generateKeysFromSeed
Defined in packages/sdk/utils/src/account.ts:470
generateMnemonic
• generateMnemonic: generateMnemonic
Defined in packages/sdk/utils/src/account.ts:463
generateSeed
• generateSeed: generateSeed
Defined in packages/sdk/utils/src/account.ts:469
invalidMnemonicWords
• invalidMnemonicWords: invalidMnemonicWords
Defined in packages/sdk/utils/src/account.ts:466
normalizeMnemonic
• normalizeMnemonic: normalizeMnemonic
Defined in packages/sdk/utils/src/account.ts:464
suggestMnemonicCorrections
• suggestMnemonicCorrections: suggestMnemonicCorrections
Defined in packages/sdk/utils/src/account.ts:467
validateMnemonic
• validateMnemonic: validateMnemonic
Defined in packages/sdk/utils/src/account.ts:465