diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 02545134..84d5b8b8 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -141,9 +141,12 @@ export class AccountService { ); if (foundAccount) { - const keychain = this.cryptoService.getSubAccountKeychain( - rootUser.seedHex, - foundAccount.accountNumber + const keychain = this.cryptoService.mnemonicToKeychain( + rootUser.mnemonic, + { + extraText: rootUser.extraText, + accountNumber: foundAccount.accountNumber, + } ); const subAccountSeedHex = this.cryptoService.keychainToSeedHex(keychain); @@ -1322,10 +1325,12 @@ export class AccountService { ); } - const parentSeedHex = parentAccount.seedHex; - const childKey = this.cryptoService.getSubAccountKeychain( - parentSeedHex, - accountNumber + const childKey = this.cryptoService.mnemonicToKeychain( + parentAccount.mnemonic, + { + accountNumber, + extraText: parentAccount.extraText, + } ); const ec = new EC('secp256k1'); const keyPair = ec.keyFromPrivate(childKey.privateKey); diff --git a/src/app/auth/google/google.component.ts b/src/app/auth/google/google.component.ts index 1d2eccdd..0ce22676 100644 --- a/src/app/auth/google/google.component.ts +++ b/src/app/auth/google/google.component.ts @@ -83,10 +83,9 @@ export class GoogleComponent implements OnInit { const mnemonic = fileContents.mnemonic; const extraText = fileContents.extraText; const network = fileContents.network; - const keychain = this.cryptoService.mnemonicToKeychain( - mnemonic, - extraText - ); + const keychain = this.cryptoService.mnemonicToKeychain(mnemonic, { + extraText, + }); this.publicKey = this.accountService.addUser( keychain, @@ -139,10 +138,9 @@ export class GoogleComponent implements OnInit { this.googleDrive .uploadFile(this.fileName(), JSON.stringify(userInfo)) .subscribe(() => { - const keychain = this.cryptoService.mnemonicToKeychain( - mnemonic, - extraText - ); + const keychain = this.cryptoService.mnemonicToKeychain(mnemonic, { + extraText, + }); this.publicKey = this.accountService.addUser( keychain, mnemonic, diff --git a/src/app/crypto.service.ts b/src/app/crypto.service.ts index 07810bc0..1c451751 100644 --- a/src/app/crypto.service.ts +++ b/src/app/crypto.service.ts @@ -138,20 +138,22 @@ export class CryptoService { mnemonicToKeychain( mnemonic: string, - extraText?: string, - nonStandard?: boolean + { + extraText, + nonStandard, + accountNumber = 0, + }: { + extraText?: string; + nonStandard?: boolean; + accountNumber?: number; + } = {} ): HDNode { const seed = bip39.mnemonicToSeedSync(mnemonic, extraText); - return generateSubAccountKeys(seed, 0, { + return generateSubAccountKeys(seed, accountNumber, { nonStandard, }); } - getSubAccountKeychain(masterSeedHex: string, accountIndex: number): HDNode { - const seedBytes = Buffer.from(masterSeedHex, 'hex'); - return generateSubAccountKeys(seedBytes, accountIndex); - } - keychainToSeedHex(keychain: HDNode): string { return keychain.privateKey.toString('hex'); } diff --git a/src/app/log-in-seed/log-in-seed.component.ts b/src/app/log-in-seed/log-in-seed.component.ts index f23bd05e..0a2ff971 100644 --- a/src/app/log-in-seed/log-in-seed.component.ts +++ b/src/app/log-in-seed/log-in-seed.component.ts @@ -72,14 +72,15 @@ export class LogInSeedComponent implements OnInit { return; } - const keychain = this.cryptoService.mnemonicToKeychain( - mnemonic, - extraText - ); + const keychain = this.cryptoService.mnemonicToKeychain(mnemonic, { + extraText, + }); const keychainNonStandard = this.cryptoService.mnemonicToKeychain( mnemonic, - extraText, - true + { + extraText, + nonStandard: true, + } ); userPublicKey = this.accountService.addUser( keychain, diff --git a/src/app/sign-up/sign-up.component.ts b/src/app/sign-up/sign-up.component.ts index f808c446..4d9cdae8 100644 --- a/src/app/sign-up/sign-up.component.ts +++ b/src/app/sign-up/sign-up.component.ts @@ -111,7 +111,9 @@ export class SignUpComponent implements OnInit, OnDestroy { const network = this.globalVars.network; const mnemonic = this.mnemonicCheck; const extraText = this.extraTextCheck; - const keychain = this.cryptoService.mnemonicToKeychain(mnemonic, extraText); + const keychain = this.cryptoService.mnemonicToKeychain(mnemonic, { + extraText, + }); this.seedHex = this.cryptoService.keychainToSeedHex(keychain); this.publicKeyAdded = this.accountService.addUser( keychain,