diff --git a/lib/hexpds/didgenerator.ex b/lib/hexpds/didgenerator.ex index 12478db..7eaa11c 100644 --- a/lib/hexpds/didgenerator.ex +++ b/lib/hexpds/didgenerator.ex @@ -1,7 +1,7 @@ defmodule Hexpds.DidGenerator do require Logger alias :crypto, as: Crypto - alias Hexpds.K256, as: K256 + alias Hexpds.K256_Internal, as: K256 def generate_private_key(), do: Crypto.strong_rand_bytes(32) diff --git a/lib/hexpds/k256.ex b/lib/hexpds/k256.ex index da8277f..00ab44d 100644 --- a/lib/hexpds/k256.ex +++ b/lib/hexpds/k256.ex @@ -1,5 +1,5 @@ -defmodule Hexpds.K256 do - use Rustler, otp_app: :hexpds, crate: "hexpds_k256" +defmodule Hexpds.K256_Internal do + use Rustler, otp_app: :hexpds, crate: "hexpds_k256_internal" def create_public_key(private_key), do: :erlang.nif_error(:nif_not_loaded) def compress_public_key(public_key), do: :erlang.nif_error(:nif_not_loaded) end diff --git a/native/hexpds_k256/.cargo/config.toml b/native/hexpds_k256_internal/.cargo/config.toml similarity index 100% rename from native/hexpds_k256/.cargo/config.toml rename to native/hexpds_k256_internal/.cargo/config.toml diff --git a/native/hexpds_k256/.gitignore b/native/hexpds_k256_internal/.gitignore similarity index 100% rename from native/hexpds_k256/.gitignore rename to native/hexpds_k256_internal/.gitignore diff --git a/native/hexpds_k256/Cargo.toml b/native/hexpds_k256_internal/Cargo.toml similarity index 79% rename from native/hexpds_k256/Cargo.toml rename to native/hexpds_k256_internal/Cargo.toml index 69e6a10..ffc2e85 100644 --- a/native/hexpds_k256/Cargo.toml +++ b/native/hexpds_k256_internal/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "hexpds_k256" +name = "hexpds_k256_internal" version = "0.1.0" authors = [ "NetWatchInc" ] edition = "2021" [lib] -name = "hexpds_k256" +name = "hexpds_k256_internal" path = "src/lib.rs" crate-type = ["cdylib"] diff --git a/native/hexpds_k256/README.md b/native/hexpds_k256_internal/README.md similarity index 63% rename from native/hexpds_k256/README.md rename to native/hexpds_k256_internal/README.md index a193f5c..4c03636 100644 --- a/native/hexpds_k256/README.md +++ b/native/hexpds_k256_internal/README.md @@ -1,4 +1,4 @@ -# NIF for Elixir.Hexpds.k256 +# NIF for Elixir.Hexpds.K256_Internal ## To build the NIF module: @@ -7,11 +7,12 @@ ## To load the NIF: ```elixir -defmodule Hexpds.K256 do - use Rustler, otp_app: :hexpds, crate: "hexpds_k256" +defmodule Hexpds.K256_Internal do + use Rustler, otp_app: :hexpds, crate: "hexpds_k256_internal" # When your NIF is loaded, it will override this function. def create_public_key(private_key), do: :erlang.nif_error(:nif_not_loaded) + def compress_public_key(private_key), do: :erlang.nif_error(:nif_not_loaded) end ``` diff --git a/native/hexpds_k256/src/lib.rs b/native/hexpds_k256_internal/src/lib.rs similarity index 82% rename from native/hexpds_k256/src/lib.rs rename to native/hexpds_k256_internal/src/lib.rs index e9586fb..3f75245 100644 --- a/native/hexpds_k256/src/lib.rs +++ b/native/hexpds_k256_internal/src/lib.rs @@ -1,5 +1,10 @@ -use rustler::{Binary, Encoder, Env, Term}; -use k256::{elliptic_curve::sec1::ToEncodedPoint, PublicKey, SecretKey}; +use rustler::Binary; +use rustler::Encoder; +use rustler::Env; +use rustler::Term; +use k256::elliptic_curve::sec1::ToEncodedPoint; +use k256::PublicKey; +use k256::SecretKey; use hex; mod atoms { @@ -40,5 +45,5 @@ fn compress_public_key<'a>(env: Env<'a>, public_key: Binary<'a>) -> Term<'a> { (atoms::ok(), compressed_key).encode(env) } -rustler::init!("Elixir.Hexpds.K256", [create_public_key, compress_public_key]); +rustler::init!("Elixir.Hexpds.K256_Internal", [create_public_key, compress_public_key]); diff --git a/priv/native/libhexpds_k256.so b/priv/native/libhexpds_k256.so index b5ae9f1..fc20197 100755 Binary files a/priv/native/libhexpds_k256.so and b/priv/native/libhexpds_k256.so differ diff --git a/priv/native/libhexpds_k256_internal.so b/priv/native/libhexpds_k256_internal.so new file mode 100755 index 0000000..ce5006e Binary files /dev/null and b/priv/native/libhexpds_k256_internal.so differ