diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index cecd4d7..b44fea6 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -102,6 +102,12 @@ method getAddress*(signer: JsonRpcSigner): Future[Address] {.async.} = raiseProviderError "no address found" +method signMessage*(signer: JsonRpcSigner, + message: seq[byte]): Future[seq[byte]] {.async.} = + let client = await signer.provider.client + let address = await signer.getAddress() + return await client.eth_sign(address, message) + method sendTransaction*(signer: JsonRpcSigner, transaction: Transaction) {.async.} = let client = await signer.provider.client diff --git a/ethers/providers/rpccalls/signatures.nim b/ethers/providers/rpccalls/signatures.nim index e7eb521..457e2ef 100644 --- a/ethers/providers/rpccalls/signatures.nim +++ b/ethers/providers/rpccalls/signatures.nim @@ -7,3 +7,4 @@ proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256 proc eth_estimateGas(transaction: Transaction): UInt256 proc eth_chainId(): UInt256 proc eth_sendTransaction(transaction: Transaction): array[32, byte] +proc eth_sign(account: Address, message: seq[byte]): seq[byte] diff --git a/ethers/signer.nim b/ethers/signer.nim index 2d6156e..0b3aa3b 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -15,6 +15,10 @@ method provider*(signer: Signer): Provider {.base.} = method getAddress*(signer: Signer): Future[Address] {.base.} = doAssert false, "not implemented" +method signMessage*(signer: Signer, + message: seq[byte]): Future[seq[byte]] {.base, async.} = + doAssert false, "not implemented" + method sendTransaction*(signer: Signer, transaction: Transaction) {.base, async.} = doAssert false, "not implemented" diff --git a/testmodule/testJsonRpcSigner.nim b/testmodule/testJsonRpcSigner.nim index d424b71..1c4415a 100644 --- a/testmodule/testJsonRpcSigner.nim +++ b/testmodule/testJsonRpcSigner.nim @@ -1,5 +1,6 @@ import pkg/asynctest import pkg/ethers +import pkg/stew/byteutils import ./examples suite "JsonRpcSigner": @@ -39,6 +40,11 @@ suite "JsonRpcSigner": let chainId = await signer.getChainId() check chainId == 31337.u256 # hardhat chain id + test "can sign messages": + let signer = provider.getSigner() + let message = "hello".toBytes + check (await signer.signMessage(message)).len == 65 + test "can populate missing fields in a transaction": let signer = provider.getSigner() let transaction = Transaction.example