Skip to content

Commit

Permalink
feat: forge/unforge/pack full implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Apr 29, 2024
1 parent 29cfb8c commit b4657c2
Show file tree
Hide file tree
Showing 13 changed files with 1,617 additions and 477 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for Tezex

## v2.0.0

- [forge]: TODO
- [BREAKING]: `Tezex.Micheline` is replaced with `Tezex.Forge`
- [BREAKING]: `Tezex.Micheline.Zarith` is replaced with `Tezex.Zarith`

## v1.2.0

Expand Down
10 changes: 5 additions & 5 deletions lib/crypto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Tezex.Crypto do
alias Tezex.Crypto.PrivateKey
alias Tezex.Crypto.Signature
alias Tezex.Crypto.Utils
alias Tezex.Micheline
alias Tezex.Forge

# public key
@prefix_edpk <<13, 15, 37, 217>>
Expand Down 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.Forge.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, Forge.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

0 comments on commit b4657c2

Please sign in to comment.