Replace erlang-libsodium with enacl

parent 4339375e
Pipeline #24878212 failed with stages
in 1 minute and 40 seconds
......@@ -4,7 +4,7 @@ WORKDIR /app
COPY . /app
RUN apk add --no-cache make git curl build-base libtool autoconf automake
RUN apk add --no-cache make git curl build-base libtool autoconf automake libsodium-dev
RUN make rel
......
......@@ -14,13 +14,13 @@ PROJECT = ercoin
PROJECT_DESCRIPTION = A simple cryptocurrency using Tendermint
PROJECT_VERSION = 0.1.0
DEPS = abci_server dynarec erlsha2 gb_merkle_trees jiffy libsodium nist_beacon
DEPS = abci_server dynarec enacl erlsha2 gb_merkle_trees jiffy nist_beacon
dep_abci_server = git https://github.com/KrzysiekJ/abci_server.git 2f38de3b21dfb463ec33f54f6c08b7ce63c27f56
dep_dynarec = git https://github.com/dieswaytoofast/dynarec.git 1f477
dep_enacl = git https://github.com/jlouis/enacl.git f650c72b028e46dbbed35f94e33ebe1e8db5d7eb
dep_erlsha2 = git https://github.com/vinoski/erlsha2 e3434b33cfeea02609bbf877954d856d895b9e1d
dep_gb_merkle_trees = git https://github.com/KrzysiekJ/gb_merkle_trees.git 1687f8be1187cf0964e63012b175b286af69c21a
dep_jiffy = git https://github.com/davisp/jiffy.git 0.14.11
dep_libsodium = git https://github.com/potatosalad/erlang-libsodium.git 0.0.10
dep_nist_beacon = git https://gitlab.com/KrzysiekJ/nist_beacon v0.1.1
LOCAL_DEPS = crypto
......
......@@ -20,10 +20,11 @@ For support and other ephemeral discussions, see [the #ercoin IRC channel on irc
1. Install [Tendermint](https://tendermint.com) (version 0.20.0).
2. Install [Erlang](https://www.erlang.org) (19 is the minimum version).
3. Clone the Ercoin’s repository and enter the created directory.
4. `dev/bootstrap.sh`
5. `make run`
6. In another window, run `tendermint node --home ~/.ercoin/`
3. Install [libsodium](https://libsodium.org) (when using a package manager, you may need to install a separate package containing development files).
4. Clone the Ercoin’s repository and enter the created directory.
5. `dev/bootstrap.sh`
6. `make run`
7. In another window, run `tendermint node --home ~/.ercoin/`
You can play with the node using [`ercoin_wallet`](https://gitlab.com/Ercoin/ercoin_wallet).
......
......@@ -64,8 +64,7 @@ hexstr_to_bin([X,Y|Tail], Acc) ->
hexstr_to_bin(Tail, <<Acc/binary, Byte>>).
%% In version 0.19.0 Tendermint changed the serialization format used for genesis.json and priv_validator.json.
%% This is not resembled below. To create files compatible with the newer format, use scripts/wire2amino.go from Tendermint.
%% This is not resembled below. To create file compatible with the newer format, use scripts/wire2amino.go from Tendermint.
%% @doc Convert data to a genesis.json file for Tendermint.
-spec data_to_genesis_json(data()) -> binary().
data_to_genesis_json(Genesis) ->
......@@ -85,20 +84,18 @@ data_to_genesis_json(Genesis) ->
{<<"validators">>, Validators}]},
jiffy:encode(ToEncode, Options).
%% This doesn’t seem to work.
sk_to_priv_validator_json(SK) ->
PK = libsodium_crypto_sign_ed25519:sk_to_pk(SK),
Options = [pretty],
<<_:32/binary, PK:32/binary>> = SK,
Address = binary:part(crypto:hash(sha256, PK), 0, 20),
ToEncode =
{[{<<"address">>, binary_to_hex(crypto:hash(ripemd160, PK))},
{[{<<"address">>, binary_to_hex(Address)},
{<<"last_height">>, 0},
{<<"last_round">>, 0},
{<<"last_signature">>, null},
{<<"last_signbytes">>, <<"">>},
{<<"last_step">>, 0},
%% Outdated format below.
{<<"priv_key">>, [1, binary_to_hex(SK)]},
{<<"pub_key">>, [1, binary_to_hex(PK)]}]},
{<<"priv_key">>,
[{<<"type">>, <<"954568A3288910">>},
{<<"value">>, base64:encode(SK)}]}]},
jiffy:encode(ToEncode, Options).
%% Functions for generating initial data below.
......
......@@ -38,9 +38,9 @@ verify_detached(_, _, _) ->
-spec verify_ed25519(Sig :: binary(), Msg :: binary(), PK :: binary()) -> boolean().
verify_ed25519(Signature, Msg, PK) ->
case libsodium_crypto_sign_ed25519:verify_detached(Signature, Msg, PK) of
0 ->
case enacl:sign_verify_detached(Signature, Msg, PK) of
{ok, _} ->
true;
-1 ->
{error, failed_verification} ->
false
end.
......@@ -155,7 +155,10 @@ data() ->
pk_sk() ->
domain(
pk_sk,
fun (Self, _) -> {Self, libsodium_crypto_sign_ed25519:keypair()} end,
fun (Self, _) ->
#{public := Public, secret := Private} = enacl:sign_keypair(),
{Self, {Public, Private}}
end,
fun (Self, Value) -> {Self, Value} end).
address_secret() ->
......
......@@ -86,7 +86,7 @@ to_sign(
-spec sign_detached(binary(), secret()) -> binary().
sign_detached(Msg, {SK, Proof}) ->
RawSig = libsodium_crypto_sign_ed25519:detached(Msg, SK),
RawSig = enacl:sign_detached(Msg, SK),
ProofBin =
case Proof of
none ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment