mirror of
https://github.com/codex-storage/nim-json-rpc.git
synced 2025-02-23 16:38:22 +00:00
Add simple validation for hex strings to web3_sha3
This commit is contained in:
parent
d789ca6fee
commit
a5467063b7
@ -1,4 +1,4 @@
|
||||
import ../rpcserver, nimcrypto, json, stint, strutils, ethtypes, stintjson
|
||||
import ../rpcserver, nimcrypto, json, stint, strutils, ethtypes, stintjson, ethutils
|
||||
|
||||
#[
|
||||
For details on available RPC calls, see: https://github.com/ethereum/wiki/wiki/JSON-RPC
|
||||
@ -38,10 +38,10 @@ proc addEthRpcs*(server: RpcServer) =
|
||||
## Returns the SHA3 result of the given string.
|
||||
# TODO: Capture error on malformed input
|
||||
var rawData: seq[byte]
|
||||
if data.len > 2 and data[0] == '0' and data[1] in ['x', 'X']:
|
||||
if data.validateHexData:
|
||||
rawData = data[2..data.high].fromHex
|
||||
else:
|
||||
rawData = data.fromHex
|
||||
raise newException(ValueError, "Invalid hex format")
|
||||
# data will have 0x prefix
|
||||
result = "0x" & $keccak_256.digest(rawData)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user