Add Signer.signMessage()
This commit is contained in:
parent
e833c08303
commit
1e767b2107
|
@ -102,6 +102,12 @@ method getAddress*(signer: JsonRpcSigner): Future[Address] {.async.} =
|
||||||
|
|
||||||
raiseProviderError "no address found"
|
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,
|
method sendTransaction*(signer: JsonRpcSigner,
|
||||||
transaction: Transaction) {.async.} =
|
transaction: Transaction) {.async.} =
|
||||||
let client = await signer.provider.client
|
let client = await signer.provider.client
|
||||||
|
|
|
@ -7,3 +7,4 @@ proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256
|
||||||
proc eth_estimateGas(transaction: Transaction): UInt256
|
proc eth_estimateGas(transaction: Transaction): UInt256
|
||||||
proc eth_chainId(): UInt256
|
proc eth_chainId(): UInt256
|
||||||
proc eth_sendTransaction(transaction: Transaction): array[32, byte]
|
proc eth_sendTransaction(transaction: Transaction): array[32, byte]
|
||||||
|
proc eth_sign(account: Address, message: seq[byte]): seq[byte]
|
||||||
|
|
|
@ -15,6 +15,10 @@ method provider*(signer: Signer): Provider {.base.} =
|
||||||
method getAddress*(signer: Signer): Future[Address] {.base.} =
|
method getAddress*(signer: Signer): Future[Address] {.base.} =
|
||||||
doAssert false, "not implemented"
|
doAssert false, "not implemented"
|
||||||
|
|
||||||
|
method signMessage*(signer: Signer,
|
||||||
|
message: seq[byte]): Future[seq[byte]] {.base, async.} =
|
||||||
|
doAssert false, "not implemented"
|
||||||
|
|
||||||
method sendTransaction*(signer: Signer,
|
method sendTransaction*(signer: Signer,
|
||||||
transaction: Transaction) {.base, async.} =
|
transaction: Transaction) {.base, async.} =
|
||||||
doAssert false, "not implemented"
|
doAssert false, "not implemented"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pkg/asynctest
|
import pkg/asynctest
|
||||||
import pkg/ethers
|
import pkg/ethers
|
||||||
|
import pkg/stew/byteutils
|
||||||
import ./examples
|
import ./examples
|
||||||
|
|
||||||
suite "JsonRpcSigner":
|
suite "JsonRpcSigner":
|
||||||
|
@ -39,6 +40,11 @@ suite "JsonRpcSigner":
|
||||||
let chainId = await signer.getChainId()
|
let chainId = await signer.getChainId()
|
||||||
check chainId == 31337.u256 # hardhat chain id
|
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":
|
test "can populate missing fields in a transaction":
|
||||||
let signer = provider.getSigner()
|
let signer = provider.getSigner()
|
||||||
let transaction = Transaction.example
|
let transaction = Transaction.example
|
||||||
|
|
Loading…
Reference in New Issue