Skip to content

Commit

Permalink
more explicit lib.rs imports, library renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
mekaem committed Feb 4, 2024
1 parent 6ac9a27 commit b83d68f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/hexpds/didgenerator.ex
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions lib/hexpds/k256.ex
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NIF for Elixir.Hexpds.k256
# NIF for Elixir.Hexpds.K256_Internal

## To build the NIF module:

Expand All @@ -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
```

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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]);

Binary file modified priv/native/libhexpds_k256.so
Binary file not shown.
Binary file added priv/native/libhexpds_k256_internal.so
Binary file not shown.

0 comments on commit b83d68f

Please sign in to comment.