EthWallet (eth_wallet v0.1.1)

Documentation for EthWallet.

    1. keys operations
    1. generate signed tx

    tx generated path:

    build_tx -> hash_for_signing(serialize -> rlp encode -> kec) -> gen sig -> get signed tx

    -> to raw tx-> send tx to node

Summary

Functions

decrypt key with password.

encrypt key with password.

generate keys with/without privkey.

iex> EthWallet.generate_keys(<<21, ..., 166>>)

recover pubkey by recovcery id, generated by sign compact

sign uncompact, as sign in bitcoin.

sign compact, as sign in ethereum.

signed transaction to raw transaction

standard hash for msg signature.

verify uncompact, fit to sign()

verify by msg, sig and addr, fit to "sign_compact()"

Functions

Link to this function

build_tx(to_str, value, data, nonce, gas_price, gas_limit)

@spec build_tx(String.t(), integer(), binary(), integer(), integer(), integer()) ::
  Transction.t()

build transaction

Link to this function

decrypt_key(payload, password)

decrypt key with password.

## Examples

iex> EthWallet.decrypt_key(payload, "bbc")

"ddd"

Link to this function

encrypt_key(encrypted_key, password)

encrypt key with password.

## Examples

iex> EthWallet.encrypt_key("ddd", "abc")

<<40, 28, 220, 122, 235, 180, 216, 145, 142, 171, 53, 146, 25, 136, 47, 215>>

Link to this function

generate_keys()

generate keys with/without privkey.

## Examples

iex> EthWallet.generate_keys()

%{

addr: "0xd705f740d934acfb27df7bf71aadc00f20d03c7a",
priv: <<21, ..., 166>>,
pub: <<4, ..., 165, ...>>

}

Link to this function

generate_keys(priv)

@spec generate_keys(binary()) :: map()

iex> EthWallet.generate_keys(<<21, ..., 166>>)

%{

addr: "0xd705f740d934acfb27df7bf71aadc00f20d03c7a",
priv: <<21, ..., 166, ...>>,
pub: <<4, ..., 165, ...>>

}

Link to this function

recover(digest, signature, recovery_id_handled, chain_id \\ nil)

@spec recover(binary(), binary(), integer(), nil | integer()) ::
  {:ok, binary()} | {:error, String.t()}

recover pubkey by recovcery id, generated by sign compact

Link to this function

sign(digest, privkey)

@spec sign(binary(), binary()) :: binary()

sign uncompact, as sign in bitcoin.

Link to this function

sign_compact(digest, privkey, chain_id \\ nil)

@spec sign_compact(<<_::256>>, <<_::256>>, nil | integer()) :: %{
  v: integer(),
  r: integer(),
  s: integer(),
  sig: <<_::512>>
}

sign compact, as sign in ethereum.

Link to this function

sign_tx(tx, private_key, chain_id \\ nil)

sign transaction

Link to this function

signed_tx_to_raw_tx(signed_tx)

@spec signed_tx_to_raw_tx(EthWallet.Transaction.t()) :: String.t()

signed transaction to raw transaction

Link to this function

standard_hash(msg_unhashed)

@spec standard_hash(String.t()) :: binary()

standard hash for msg signature.

Link to this function

verify(digest, sig, pubkey)

@spec verify(binary(), binary(), binary()) :: boolean()

verify uncompact, fit to sign()

Link to this function

verify_compact(msg_unhashed, sig, addr)

@spec verify_compact(String.t(), String.t(), String.t()) :: boolean()

verify by msg, sig and addr, fit to "sign_compact()"