Attempted fix for publishing
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
export type MnemonicRaw = {
|
||||
words: string[];
|
||||
passphrase?: string;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Class representing a BIP39 Mnemonic phrase.
|
||||
@@ -32,7 +32,10 @@ export class Mnemonic {
|
||||
* @throws {Error} If mnemonic could not be generated.
|
||||
* @returns Instance of Mnemonic.
|
||||
*/
|
||||
public static from(phraseOrWords: string | Array<string>, wordList: Array<string> = bip39WordListEnglish) {
|
||||
public static from(
|
||||
phraseOrWords: string | Array<string>,
|
||||
wordList: Array<string> = bip39WordListEnglish,
|
||||
) {
|
||||
// If this is a list of words...
|
||||
if (Array.isArray(phraseOrWords)) {
|
||||
return this.fromWords(phraseOrWords, wordList);
|
||||
@@ -49,7 +52,10 @@ export class Mnemonic {
|
||||
* @throws {Error} If mnemonic could not be generated.
|
||||
* @returns Instance of Mnemonic.
|
||||
*/
|
||||
public static fromString(phrase: string, wordList: Array<string> = bip39WordListEnglish) {
|
||||
public static fromString(
|
||||
phrase: string,
|
||||
wordList: Array<string> = bip39WordListEnglish,
|
||||
) {
|
||||
// Split into words and remove any whitespace.
|
||||
const allWords = phrase
|
||||
.trim()
|
||||
@@ -67,7 +73,10 @@ export class Mnemonic {
|
||||
* @throws {Error} If mnemonic could not be generated.
|
||||
* @returns Instance of Mnemonic.
|
||||
*/
|
||||
public static fromWords(words: Array<string>, wordList: Array<string> = bip39WordListEnglish) {
|
||||
public static fromWords(
|
||||
words: Array<string>,
|
||||
wordList: Array<string> = bip39WordListEnglish,
|
||||
) {
|
||||
// Check if last word is a passphrase by looking at total count
|
||||
const hasPassphrase =
|
||||
words.length === 13 ||
|
||||
@@ -79,10 +88,10 @@ export class Mnemonic {
|
||||
// Parse words and optional passphrase
|
||||
const mnemonicRaw: MnemonicRaw = {
|
||||
words: hasPassphrase ? words.slice(0, -1) : words,
|
||||
}
|
||||
};
|
||||
|
||||
if(hasPassphrase) {
|
||||
mnemonicRaw.passphrase = words[words.length - 1]
|
||||
if (hasPassphrase) {
|
||||
mnemonicRaw.passphrase = words[words.length - 1];
|
||||
}
|
||||
|
||||
// Validate word count
|
||||
@@ -226,9 +235,9 @@ export class Mnemonic {
|
||||
* @returns Number of words.
|
||||
*/
|
||||
public toWords(includePassphrase: boolean = true): Array<string> {
|
||||
const words = [ ...this.mnemonic.words ];
|
||||
const words = [...this.mnemonic.words];
|
||||
|
||||
if(this.mnemonic.passphrase && includePassphrase) {
|
||||
if (this.mnemonic.passphrase && includePassphrase) {
|
||||
words.push(this.mnemonic.passphrase);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user