-
Notifications
You must be signed in to change notification settings - Fork 19
/
signer.ex
59 lines (46 loc) · 1.99 KB
/
signer.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
defmodule Ethers.Signer do
@moduledoc """
Signer behaviour.
A signer module is (at least) capable of signing transactions and listing accounts in the signer.
## Builtin Signers
Ethers ships with some default signers that you can use.
- `Ethers.Signer.JsonRPC`: Can be used with most wallets, geth, web3signer or any other platform
which exposes a JsonRPC endpoint and implements `eth_signTransaction` and `eth_accounts`
functions.
- `Ethers.Signer.Local`: This signs transactions locally but is highly discouraged to use in
a production environment as it does not have any security measures built in.
## Custom Signers
Custom signers can also be implemented which must adhere to this behvaviour.
For signing transactions in custom signers the functions in `Ethers.Transaction` module might
become handy. Check out the source code of built in signers for in depth info.
## Globally Default Signer
If desired, a signer can be configured to be used for all operations in Ethers using elixir
config.
```elixir
config :ethers,
default_signer: Ethers.Signer.JsonRPC,
default_signer_opts: [url: "..."]
```
"""
alias Ethers.Types
@doc """
Signs a binary and returns the signature
## Parameters
- tx: The transaction object. (An `Ethers.Transaction` struct)
- opts: Other options passed to the signer as `signer_opts`.
"""
@callback sign_transaction(
tx :: Ethers.Transaction.t(),
opts :: Keyword.t()
) ::
{:ok, encoded_signed_transaction :: binary()} | {:error, reason :: term()}
@doc """
Returns the available signer account addresses.
This method might not be supported by all signers. If a signer does not support this function
it should return `{:error, :not_supported}`.
## Parameters
- opts: Other options passed to the signer as `signer_opts`
"""
@callback accounts(opts :: Keyword.t()) ::
{:ok, [Types.t_address()]} | {:error, reason :: :not_supported | term()}
end