Skip to content

Commit

Permalink
decodes are always mixed case now
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Sep 2, 2017
1 parent 926b38f commit 1433eb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/eth/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule ETH.Transaction do
to: _to, value: _value, data: _data, gas_price: _gas_price, gas_limit: _gas_limit,
nonce: _nonce, chain_id: _chain_id
}, << encoded_private_key :: binary-size(64) >>) do
decoded_private_key = Base.decode16!(encoded_private_key, case: :lower)
decoded_private_key = Base.decode16!(encoded_private_key, case: :mixed)
sign_transaction(transaction, decoded_private_key)
end

Expand Down Expand Up @@ -61,7 +61,7 @@ defmodule ETH.Transaction do
transaction
|> Map.merge(%{v: encode16(<<chain_id>>), r: <<>>, s: <<>>})
|> to_list
|> Enum.map(fn(x) -> Base.decode16!(x, case: :lower) end)
|> Enum.map(fn(x) -> Base.decode16!(x, case: :mixed) end)
|> hash
end

Expand All @@ -84,7 +84,7 @@ defmodule ETH.Transaction do
|> Map.merge(%{r: encode16(r), s: encode16(s), v: encode16(<<recovery + 27>>)})
|> adjust_v_for_chain_id
|> to_list
|> Enum.map(fn(x) -> Base.decode16!(x, case: :lower) end)
|> Enum.map(fn(x) -> Base.decode16!(x, case: :mixed) end)
|> ExRLP.encode
end

Expand All @@ -93,7 +93,7 @@ defmodule ETH.Transaction do
nonce: _nonce, chain_id: chain_id, v: v, r: r, s: s
}) do
if chain_id > 0 do
current_v_bytes = Base.decode16!(v, case: :lower) |> :binary.decode_unsigned
current_v_bytes = Base.decode16!(v, case: :mixed) |> :binary.decode_unsigned
target_v_bytes = current_v_bytes + (chain_id * 2 + 8)
transaction |> Map.merge(%{v: encode16(<< target_v_bytes >>)})
else
Expand All @@ -109,4 +109,6 @@ defmodule ETH.Transaction do
s = Map.get(transaction, :s, "")
[nonce, gas_price, gas_limit, to, value, data, v, r, s]
end

def to_hex(value), do: Hexate.encode(value)
end
4 changes: 2 additions & 2 deletions lib/eth/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule ETH.Utils do
"0x#{Base.encode16(eth_address)}"
end
def get_address(<< encoded_private_key :: binary-size(64) >>) do
public_key = Base.decode16!(encoded_private_key) |> get_public_key()
public_key = Base.decode16!(encoded_private_key, case: :mixed) |> get_public_key()
<< 4 :: size(8), key :: binary-size(64) >> = public_key
<< _ :: binary-size(12), eth_address :: binary-size(20) >> = keccak256(key)
"0x#{Base.encode16(eth_address)}"
Expand All @@ -28,7 +28,7 @@ defmodule ETH.Utils do
"0x#{Base.encode16(eth_address)}"
end
def get_address(<< encoded_public_key :: binary-size(130) >>) do
<< 4 :: size(8), key :: binary-size(64) >> = Base.decode16!(encoded_public_key)
<< 4 :: size(8), key :: binary-size(64) >> = Base.decode16!(encoded_public_key, case: :mixed)
<< _ :: binary-size(12), eth_address :: binary-size(20) >> = keccak256(key)
"0x#{Base.encode16(eth_address)}"
end
Expand Down

0 comments on commit 1433eb6

Please # to comment.