simplify method

This commit is contained in:
Iuri Matias 2020-05-21 15:59:09 -04:00
parent e65449b8de
commit de5428cc0a
2 changed files with 6 additions and 4 deletions

View File

@ -62,7 +62,6 @@ proc generateRandomAccountAndLogin*(self: AccountModel) =
proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string = proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string =
let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex] let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex]
let password = "0x" & $keccak_256.digest(password)
let multiAccounts = status_accounts.generateMultiAccounts(%account, password) let multiAccounts = status_accounts.generateMultiAccounts(%account, password)

View File

@ -3,6 +3,7 @@ import core
import json import json
import utils import utils
import accounts/constants import accounts/constants
import nimcrypto
import os import os
import uuids import uuids
@ -57,6 +58,7 @@ proc initNodeAccounts*() =
discard $libstatus.openAccounts(datadir); discard $libstatus.openAccounts(datadir);
proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: string, accountData: string, password: string, configJSON: string, settingsJSON: string): JsonNode = proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: string, accountData: string, password: string, configJSON: string, settingsJSON: string): JsonNode =
let hashedPassword = "0x" & $keccak_256.digest(password)
let subaccountData = %* [ let subaccountData = %* [
{ {
"public-key": multiAccounts[constants.PATH_DEFAULT_WALLET]["publicKey"], "public-key": multiAccounts[constants.PATH_DEFAULT_WALLET]["publicKey"],
@ -76,7 +78,7 @@ proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: str
} }
] ]
var savedResult = $libstatus.saveAccountAndLogin(accountData, password, settingsJSON, configJSON, $subaccountData) var savedResult = $libstatus.saveAccountAndLogin(accountData, hashedPassword, settingsJSON, configJSON, $subaccountData)
let parsedSavedResult = savedResult.parseJson let parsedSavedResult = savedResult.parseJson
if parsedSavedResult["error"].getStr == "": if parsedSavedResult["error"].getStr == "":
@ -84,10 +86,11 @@ proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: str
subaccountData subaccountData
proc generateMultiAccounts*(account: JsonNode, password: string): JsonNode = proc generateMultiAccounts*(account: JsonNode, password: string): JsonNode =
let hashedPassword = "0x" & $keccak_256.digest(password)
let multiAccount = %* { let multiAccount = %* {
"accountID": account["id"].getStr, "accountID": account["id"].getStr,
"paths": ["m/44'/60'/0'/0", "m/43'/60'/1581'", "m/43'/60'/1581'/0'/0", "m/44'/60'/0'/0/0"], "paths": ["m/44'/60'/0'/0", "m/43'/60'/1581'", "m/43'/60'/1581'/0'/0", "m/44'/60'/0'/0/0"],
"password": password "password": hashedPassword
} }
var response = $libstatus.multiAccountStoreDerivedAccounts($multiAccount); var response = $libstatus.multiAccountStoreDerivedAccounts($multiAccount);
result = response.parseJson result = response.parseJson
@ -131,7 +134,7 @@ proc setupRandomTestAccount*(): string =
let generatedAddresses = generateAddresses().parseJson let generatedAddresses = generateAddresses().parseJson
let account0 = generatedAddresses[0] let account0 = generatedAddresses[0]
let password = "0x2cd9bf92c5e20b1b410f5ace94d963a96e89156fbe65b70365e8596b37f1f165" #qwertyh let password = "qwerty"
let multiAccounts = generateMultiAccounts(account0, password) let multiAccounts = generateMultiAccounts(account0, password)
# let alias = $libstatus.generateAlias(whisperPubKey.toGoString) # let alias = $libstatus.generateAlias(whisperPubKey.toGoString)