Skip to content

Commit

Permalink
Remove redundant comment
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Oct 21, 2024
1 parent 9393d4f commit f920ae6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/wallet/mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const BIP44_DERIVATION_PREFIX = "m/44'/508'/0'/0'";

let bip39: any;

// Load bip39 when needed
function loadBip39() {
if (!bip39) {
try {
Expand All @@ -25,21 +26,21 @@ export class Mnemonic {
}

static generate(): Mnemonic {
loadBip39(); // Load bip39 when needed
loadBip39();
const text = bip39.generateMnemonic(MNEMONIC_STRENGTH);
return new Mnemonic(text);
}

static fromString(text: string) {
loadBip39(); // Load bip39 when needed
loadBip39();
text = text.trim();

Mnemonic.assertTextIsValid(text);
return new Mnemonic(text);
}

static fromEntropy(entropy: Uint8Array): Mnemonic {
loadBip39(); // Load bip39 when needed
loadBip39();
try {
const text = bip39.entropyToMnemonic(Buffer.from(entropy));
return new Mnemonic(text);
Expand All @@ -49,7 +50,7 @@ export class Mnemonic {
}

public static assertTextIsValid(text: string) {
loadBip39(); // Load bip39 when needed
loadBip39();
let isValid = bip39.validateMnemonic(text);

if (!isValid) {
Expand All @@ -58,7 +59,7 @@ export class Mnemonic {
}

deriveKey(addressIndex: number = 0, password: string = ""): UserSecretKey {
loadBip39(); // Load bip39 when needed
loadBip39();
let seed = bip39.mnemonicToSeedSync(this.text, password);
let derivationPath = `${BIP44_DERIVATION_PREFIX}/${addressIndex}'`;
let derivationResult = derivePath(derivationPath, seed.toString("hex"));
Expand All @@ -71,7 +72,7 @@ export class Mnemonic {
}

getEntropy(): Uint8Array {
loadBip39(); // Load bip39 when needed
loadBip39();
const entropy = bip39.mnemonicToEntropy(this.text);
return Buffer.from(entropy, "hex");
}
Expand Down

0 comments on commit f920ae6

Please sign in to comment.