Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forge/unforge/pack full implementation #12

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for Tezex

## v2.0.0

- [BREAKING]: `Tezex.Micheline` now only takes care of `PACK`ing and `UNPACK`ing, forging and unforging is now in `Tezex.Forge`
- [BREAKING]: `Tezex.Micheline.Zarith` is replaced with `Tezex.Zarith`

## v1.2.0

Expand Down
8 changes: 4 additions & 4 deletions lib/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Tezex.Crypto do
end
end

defp extract_pubkey(pubkey) do
def extract_pubkey(pubkey) do
case Base58Check.decode58(pubkey) do
{:ok, <<@prefix_edpk, public_key::binary-size(32)>> <> _} -> {:ok, public_key}
{:ok, <<@prefix_sppk, public_key::binary-size(33)>> <> _} -> {:ok, public_key}
Expand Down Expand Up @@ -255,8 +255,8 @@ defmodule Tezex.Crypto do
iex> encoded_private_key = "spsk24EJohZHJkZnWEzj3w9wE7BFARpFmq5WAo9oTtqjdJ2t4pyoB3"
iex> Tezex.Crypto.sign_message(encoded_private_key, "foo")
"sigm9uJiGjdk2DpuqTmHcjzpAdTSQfqKxFuDKodyNT8JP3UvrfoPFTNkFbFgDP1WfAi2PjJ3dcpZFLTagD7gUBmwVWbPr5mk"
iex> msg = Tezex.Micheline.string_to_micheline_hex("foo")
"050100000003666F6F"
iex> msg = Tezex.Micheline.pack("foo", :string)
"050100000003666f6f"
iex> Tezex.Crypto.sign_message(encoded_private_key, msg)
"sigm9uJiGjdk2DpuqTmHcjzpAdTSQfqKxFuDKodyNT8JP3UvrfoPFTNkFbFgDP1WfAi2PjJ3dcpZFLTagD7gUBmwVWbPr5mk"
"""
Expand All @@ -266,7 +266,7 @@ defmodule Tezex.Crypto do
end

def sign_message(privkey_param, bytes) do
sign(privkey_param, Micheline.string_to_micheline_hex(bytes))
sign(privkey_param, Micheline.pack(bytes, :string))
end

@spec sign(privkey_param(), binary(), binary()) :: nonempty_binary()
Expand Down
3 changes: 3 additions & 0 deletions lib/crypto/base58_check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ defmodule Tezex.Crypto.Base58Check do
"""
@spec decode58!(binary) :: binary
defdelegate decode58!(encoded), to: Base58Check

@spec decode58check!(binary) :: binary
defdelegate decode58check!(encoded), to: Base58Check
end
Loading
Loading