refactor: privacy methods added
- methods `changeDatabasePassword` and `getLinkPreviewWhitelist` added to `privacy.nim` - `hashPassword` moved to `utils.nim` since it's used from multiple paces - `getEthAccounts` added to `eth.nim` - `verifyAccountPassword` method updated so it returns `RpcResponse` now
This commit is contained in:
parent
2585f9418f
commit
2be8bb55ee
|
@ -252,15 +252,16 @@ proc multiAccountImportPrivateKey*(privateKey: string): RpcResponse[JsonNode] =
|
|||
error "error doing rpc request", methodName = "multiAccountImportPrivateKey", exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
|
||||
proc verifyAccountPassword*(address: string, password: string, keystoreDir: string): bool =
|
||||
let hashedPassword = hashPassword(password)
|
||||
let verifyResult = status_go.verifyAccountPassword(keystoreDir, address, hashedPassword)
|
||||
let error = parseJson(verifyResult)["error"].getStr
|
||||
proc verifyAccountPassword*(address: string, password: string, keystoreDir: string):
|
||||
RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
try:
|
||||
let hashedPassword = hashPassword(password)
|
||||
let response = status_go.verifyAccountPassword(keystoreDir, address, hashedPassword)
|
||||
result.result = Json.decode(response, JsonNode)
|
||||
|
||||
if error == "":
|
||||
return true
|
||||
|
||||
return false
|
||||
except RpcException as e:
|
||||
error "error doing rpc request", methodName = "verifyAccountPassword", exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
|
||||
proc storeIdentityImage*(keyUID: string, imagePath: string, aX, aY, bX, bY: int):
|
||||
RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
|
|
|
@ -30,4 +30,7 @@ proc doEthCall*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].}
|
|||
core.callPrivateRPC("eth_call", payload)
|
||||
|
||||
proc estimateGas*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
core.callPrivateRPC("eth_estimateGas", payload)
|
||||
core.callPrivateRPC("eth_estimateGas", payload)
|
||||
|
||||
proc getEthAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
return core.callPrivateRPC("eth_accounts")
|
|
@ -0,0 +1,25 @@
|
|||
import json, json_serialization, chronicles
|
||||
import core, utils
|
||||
import response_type
|
||||
|
||||
import status_go
|
||||
|
||||
export response_type
|
||||
|
||||
logScope:
|
||||
topics = "rpc-privacy"
|
||||
|
||||
proc changeDatabasePassword*(keyUID: string, password: string, newPassword: string): RpcResponse[JsonNode]
|
||||
{.raises: [Exception].} =
|
||||
try:
|
||||
let hashedPassword = hashPassword(password)
|
||||
let hashedNewPassword = hashPassword(newPassword)
|
||||
let response = status_go.changeDatabasePassword(keyUID, hashedPassword, hashedNewPassword)
|
||||
result.result = Json.decode(response, JsonNode)
|
||||
except RpcException as e:
|
||||
error "error", methodName = "changeDatabasePassword", exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
|
||||
proc getLinkPreviewWhitelist*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
let payload = %* []
|
||||
result = callPrivateRPC("getLinkPreviewWhitelist".prefix, payload)
|
|
@ -8,6 +8,5 @@ proc prefix*(methodName: string, isExt:bool = true): string =
|
|||
result = result & (if isExt: "ext_" else: "_")
|
||||
result = result & methodName
|
||||
|
||||
|
||||
proc hashPassword*(password: string): string =
|
||||
result = "0x" & $keccak_256.digest(password)
|
Loading…
Reference in New Issue