diff --git a/.gitignore b/.gitignore index 06a24b6..40322f5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ erl_crash.dump *.ez # Ignore package tarball (built via "mix hex.build"). -hexpds-*.tar +hipdster-*.tar # Temporary files, for example, from tests. /tmp/ diff --git a/README.md b/README.md index 870f0bd..e2e8769 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# hexpds +# hipdster An ATProto PDS in Elixir/Rust ## Installation If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `hexpds` to your list of dependencies in `mix.exs`: +by adding `hipdster` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:hexpds, "~> 0.1.0"} + {:hipdster, "~> 0.1.0"} ] end ``` Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at . +be found at . diff --git a/config/config.exs b/config/config.exs index 2df0ab1..38fb94d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,9 +1,9 @@ import Config # example usage: -#  Application.get_env(:hexpds, :plc_server) +#  Application.get_env(:hipdster, :plc_server) -config :hexpds, +config :hipdster, plc_server: "plc.bsky-sandbox.dev", appview_server: "api.bsky-sandbox.dev", relay_server: "bgs.bsky-sandbox.dev", diff --git a/lib/hexpds/mst.ex b/lib/hexpds/mst.ex deleted file mode 100644 index e69de29..0000000 diff --git a/lib/hexpds/cid.ex b/lib/hipdster/cid.ex similarity index 99% rename from lib/hexpds/cid.ex rename to lib/hipdster/cid.ex index d39c74b..dda0f24 100644 --- a/lib/hexpds/cid.ex +++ b/lib/hipdster/cid.ex @@ -1,4 +1,4 @@ -defmodule Hexpds.CID do +defmodule Hipdster.CID do @moduledoc """ CID - self-describing content-addressed identifiers for distributed systems. @@ -96,7 +96,7 @@ defmodule Hexpds.CID do """ - alias Hexpds.Multicodec, as: Multicodec + alias Hipdster.Multicodec, as: Multicodec alias __MODULE__, as: CID diff --git a/lib/hexpds/dagcbor.ex b/lib/hipdster/dagcbor.ex similarity index 87% rename from lib/hexpds/dagcbor.ex rename to lib/hipdster/dagcbor.ex index 9f9203f..20e6921 100644 --- a/lib/hexpds/dagcbor.ex +++ b/lib/hipdster/dagcbor.ex @@ -1,6 +1,6 @@ -defmodule Hexpds.DagCBOR do +defmodule Hipdster.DagCBOR do defmodule Internal do - use Rustler, otp_app: :hexpds, crate: "hexpds_dagcbor_internal" + use Rustler, otp_app: :hipdster, crate: "hipdster_dagcbor_internal" @spec encode_dag_cbor(binary()) :: {:ok, binary()} | {:error, String.t()} def encode_dag_cbor(_json), do: :erlang.nif_error(:nif_not_loaded) @spec decode_dag_cbor(binary()) :: {:ok, String.t()} | {:error, String.t()} @@ -13,7 +13,7 @@ defmodule Hexpds.DagCBOR do Examples: - iex> Hexpds.DagCBOR.encode(%{apple: "banana", cranberry: "dragonfruit"}) + iex> Hipdster.DagCBOR.encode(%{apple: "banana", cranberry: "dragonfruit"}) ...> |> elem(1) ...> |> Base.encode16() "A2656170706C656662616E616E61696372616E62657272796B647261676F6E6672756974" diff --git a/lib/hexpds/didgenerator.ex b/lib/hipdster/didgenerator.ex similarity index 86% rename from lib/hexpds/didgenerator.ex rename to lib/hipdster/didgenerator.ex index b8f4209..79f1d4e 100644 --- a/lib/hexpds/didgenerator.ex +++ b/lib/hipdster/didgenerator.ex @@ -1,6 +1,6 @@ -defmodule Hexpds.DidGenerator do +defmodule Hipdster.DidGenerator do require Logger - alias Hexpds.K256, as: K256 + alias Hipdster.K256, as: K256 @spec genesis_to_did(map()) :: String.t() def genesis_to_did(%{"type" => "plc_operation", "prev" => nil} = signed_genesis) do @@ -10,7 +10,7 @@ defmodule Hexpds.DidGenerator do |> Jason.encode(), {:ok, signed_genesis_cbor} <- signed_genesis_json - |> Hexpds.DagCBOR.encode(), + |> Hipdster.DagCBOR.encode(), do: :crypto.hash(:sha256, signed_genesis_cbor) |> Base.encode32(case: :lower) @@ -55,8 +55,8 @@ defmodule Hexpds.DidGenerator do def generate_did( "" <> handle, - "" <> plc_dir_url \\ "https://#{Application.get_env(:hexpds, :plc_server)}", - "" <> pds_url \\ Application.get_env(:hexpds, :pds_host) + "" <> plc_dir_url \\ "https://#{Application.get_env(:hipdster, :plc_server)}", + "" <> pds_url \\ Application.get_env(:hipdster, :pds_host) ) do rotation_key = K256.PrivateKey.create() signing_key = K256.PrivateKey.create() @@ -64,7 +64,7 @@ defmodule Hexpds.DidGenerator do Logger.info("Signing key: #{signing_key |> K256.PrivateKey.to_hex()}") genesis = - Hexpds.DidPlc.Operation.genesis( + Hipdster.DidPlc.Operation.genesis( rotation_key, signing_key, handle, @@ -72,7 +72,7 @@ defmodule Hexpds.DidGenerator do ) Logger.info("Genesis: #{inspect(genesis)}") - signed_genesis = Hexpds.DidPlc.Operation.add_sig(genesis, rotation_key) + signed_genesis = Hipdster.DidPlc.Operation.add_sig(genesis, rotation_key) did = genesis_to_did(signed_genesis) Logger.info("DID: #{did}") diff --git a/lib/hexpds/didplc.ex b/lib/hipdster/didplc.ex similarity index 71% rename from lib/hexpds/didplc.ex rename to lib/hipdster/didplc.ex index 799444f..b297b0f 100644 --- a/lib/hexpds/didplc.ex +++ b/lib/hipdster/didplc.ex @@ -1,4 +1,4 @@ -defmodule Hexpds.DidPlc do +defmodule Hipdster.DidPlc do defmodule Operation do defstruct [ :rotationKeys, @@ -10,7 +10,7 @@ defmodule Hexpds.DidPlc do ] @type t :: %__MODULE__{ - rotationKeys: [Hexpds.K256.PrivateKey.t()], + rotationKeys: [Hipdster.K256.PrivateKey.t()], prev: String.t() | nil, verificationMethods: VerificationMethods.t(), alsoKnownAs: [String.t()], @@ -20,7 +20,7 @@ defmodule Hexpds.DidPlc do defmodule VerificationMethods do defstruct([:atproto]) - @type t :: %__MODULE__{atproto: Hexpds.K256.PrivateKey.t()} + @type t :: %__MODULE__{atproto: Hipdster.K256.PrivateKey.t()} end defmodule Services do @@ -36,8 +36,8 @@ defmodule Hexpds.DidPlc do end def genesis( - %Hexpds.K256.PrivateKey{} = rotationkey, - %Hexpds.K256.PrivateKey{} = signingkey, + %Hipdster.K256.PrivateKey{} = rotationkey, + %Hipdster.K256.PrivateKey{} = signingkey, handle, pds ) do @@ -52,7 +52,7 @@ defmodule Hexpds.DidPlc do def to_json(%__MODULE__{} = operation) do encodekeys = fn k -> - k |> Hexpds.K256.PrivateKey.to_pubkey() |> Hexpds.K256.PublicKey.to_did_key() + k |> Hipdster.K256.PrivateKey.to_pubkey() |> Hipdster.K256.PublicKey.to_did_key() end Jason.encode!(%{ @@ -65,25 +65,24 @@ defmodule Hexpds.DidPlc do }) end - @spec sign(t(), Hexpds.K256.PrivateKey.t()) :: + @spec sign(t(), Hipdster.K256.PrivateKey.t()) :: {:ok, binary()} | {:error, String.t()} - def sign(%__MODULE__{} = operation, %Hexpds.K256.PrivateKey{} = privkey) do + def sign(%__MODULE__{} = operation, %Hipdster.K256.PrivateKey{} = privkey) do with {:ok, cbor} <- operation |> to_json() - |> Hexpds.DagCBOR.encode(), + |> Hipdster.DagCBOR.encode(), do: {:ok, privkey - |> Hexpds.K256.PrivateKey.sign(cbor) - |> Hexpds.K256.Signature.bytes() - |> Base.url_encode64() - |> String.replace("=", "")} + |> Hipdster.K256.PrivateKey.sign(cbor) + |> Hipdster.K256.Signature.bytes() + |> Base.url_encode64(padding: false)} end - @spec add_sig(t(), Hexpds.K256.PrivateKey.t()) :: + @spec add_sig(t(), Hipdster.K256.PrivateKey.t()) :: {:error, binary()} | map() - def add_sig(%__MODULE__{} = operation, %Hexpds.K256.PrivateKey{} = privkey) do + def add_sig(%__MODULE__{} = operation, %Hipdster.K256.PrivateKey{} = privkey) do with {:ok, sig} <- sign(operation, privkey) do operation |> to_json diff --git a/lib/hexpds/k256.ex b/lib/hipdster/k256.ex similarity index 83% rename from lib/hexpds/k256.ex rename to lib/hipdster/k256.ex index 6a839c9..9aed6e4 100644 --- a/lib/hexpds/k256.ex +++ b/lib/hipdster/k256.ex @@ -1,7 +1,7 @@ -defmodule Hexpds.K256 do +defmodule Hipdster.K256 do @moduledoc """ Secp256k1-related functions, using the `k256` Rust crate. - Includes `Hexpds.K256.PrivateKey` and `Hexpds.K256.PublicKey`, which are type-safe wrappers around + Includes `Hipdster.K256.PrivateKey` and `Hipdster.K256.PublicKey`, which are type-safe wrappers around raw bytes of keys and include wrappers around the `k256` crate's `k256::PublicKey` and `k256::SecretKey` types and some of their helper functions required for ATProto. """ @@ -21,14 +21,14 @@ defmodule Hexpds.K256 do # TODO: make this unnecessary def bytes({:error, e}), do: raise(e) - @spec verify(t(), Hexpds.K256.PublicKey.t(), binary()) :: + @spec verify(t(), Hipdster.K256.PublicKey.t(), binary()) :: {:ok, String.t()} | {:error, String.t()} def verify( %__MODULE__{sig: sig}, - %{pubkey: pubkey, __struct__: Hexpds.K256.PublicKey}, + %{pubkey: pubkey, __struct__: Hipdster.K256.PublicKey}, message ) do - case Hexpds.K256.Internal.verify_signature(pubkey, message, sig) do + case Hipdster.K256.Internal.verify_signature(pubkey, message, sig) do true -> {:ok, "Signature #{inspect(sig)} verified"} false -> {:error, "Signature #{inspect(sig)} could not be verified"} tuple -> tuple @@ -41,7 +41,7 @@ defmodule Hexpds.K256 do @typedoc """ A Secp256k1 private key. Contains the raw bytes of the key, and wraps the `k256` crate's `k256::SecretKey` type. - Should always be 32 bytes (256 bits) long. All operations on `Hexpds.K256.PrivateKey` are type-safe. + Should always be 32 bytes (256 bits) long. All operations on `Hipdster.K256.PrivateKey` are type-safe. """ @type t :: %__MODULE__{privkey: <<_::256>>} @@ -71,22 +71,22 @@ defmodule Hexpds.K256 do def to_hex(%__MODULE__{privkey: privkey}) when is_valid_key(privkey), do: Base.encode16(privkey, case: :lower) - @spec to_pubkey(t()) :: Hexpds.K256.PublicKey.t() + @spec to_pubkey(t()) :: Hipdster.K256.PublicKey.t() def to_pubkey(%__MODULE__{} = privkey) when is_valid_key(privkey.privkey), - do: Hexpds.K256.PublicKey.create(privkey) + do: Hipdster.K256.PublicKey.create(privkey) - @spec sign(t(), binary()) :: {:error, String.t()} | Hexpds.K256.Signature.t() + @spec sign(t(), binary()) :: {:error, String.t()} | Hipdster.K256.Signature.t() @doc """ Signs a binary message with a Secp256k1 private key. Returns a binary signature. """ def sign(%__MODULE__{privkey: privkey}, message) when is_binary(message) and is_valid_key(privkey) do - with {:ok, sig} <- Hexpds.K256.Internal.sign_message(privkey, message), + with {:ok, sig} <- Hipdster.K256.Internal.sign_message(privkey, message), {:ok, sig_bytes} <- Base.decode16(sig, case: :lower), - do: %Hexpds.K256.Signature{sig: sig_bytes} + do: %Hipdster.K256.Signature{sig: sig_bytes} end - @spec sign!(t(), binary()) :: Hexpds.K256.Signature.t() + @spec sign!(t(), binary()) :: Hipdster.K256.Signature.t() @doc """ Signs a binary message with a Secp256k1 private key. Returns a binary signature. Raises on error if signing fails. """ @@ -109,7 +109,7 @@ defmodule Hexpds.K256 do @spec create(PrivateKey.t()) :: t() def create(%PrivateKey{privkey: privkey}) do - case Hexpds.K256.Internal.create_public_key(privkey) do + case Hipdster.K256.Internal.create_public_key(privkey) do {:ok, pubkey} -> from_binary(pubkey) {:error, e} -> raise e end @@ -127,7 +127,7 @@ defmodule Hexpds.K256 do Wrapper around the `k256` crate's `k256::PublicKey::compress` function. """ def compress(%__MODULE__{pubkey: pubkey}) do - case Hexpds.K256.Internal.compress_public_key(pubkey) do + case Hipdster.K256.Internal.compress_public_key(pubkey) do {:ok, compressed} -> compressed {:error, e} -> raise e end @@ -150,7 +150,7 @@ defmodule Hexpds.K256 do (pubkey |> compress() |> Base.decode16!(case: :lower) - |> Hexpds.Multicodec.encode!(:"secp256k1-pub") + |> Hipdster.Multicodec.encode!(:"secp256k1-pub") |> Multibase.encode!(:base58_btc)) end end @@ -158,9 +158,9 @@ defmodule Hexpds.K256 do defmodule Internal do @moduledoc """ NIF for Rust crate k256. Raw APIs, do not use directly. Instead, use the - `Hexpds.K256.PublicKey` and `Hexpds.K256.PrivateKey` modules. + `Hipdster.K256.PublicKey` and `Hipdster.K256.PrivateKey` modules. """ - use Rustler, otp_app: :hexpds, crate: "hexpds_k256_internal" + use Rustler, otp_app: :hipdster, crate: "hipdster_k256_internal" @spec create_public_key(binary()) :: {:ok, binary()} | {:error, String.t()} def create_public_key(_private_key), do: :erlang.nif_error(:nif_not_loaded) @spec compress_public_key(binary()) :: {:ok, binary()} | {:error, String.t()} diff --git a/lib/hipdster/mst.ex b/lib/hipdster/mst.ex new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/hipdster/mst.ex @@ -0,0 +1 @@ + diff --git a/lib/hexpds/multicodec.ex b/lib/hipdster/multicodec.ex similarity index 86% rename from lib/hexpds/multicodec.ex rename to lib/hipdster/multicodec.ex index 1260282..ac47d66 100644 --- a/lib/hexpds/multicodec.ex +++ b/lib/hipdster/multicodec.ex @@ -1,14 +1,16 @@ -defmodule Hexpds.Multicodec do +defmodule Hipdster.Multicodec do use GenServer - def start_link(multicodec_csv \\ Application.get_env(:hexpds, :multicodec_csv_path)) do + def start_link(multicodec_csv \\ Application.get_env(:hipdster, :multicodec_csv_path)) do GenServer.start_link(__MODULE__, multicodec_csv, name: __MODULE__) end @impl GenServer def init(csv_path) do - {:ok, csv} = File.read(csv_path) - {:ok, read_csv(csv)} + {:ok, + csv_path + |> File.stream!() + |> read_csv()} end @impl GenServer @@ -16,9 +18,8 @@ defmodule Hexpds.Multicodec do {:reply, state, state} end - def read_csv(csv) do + def read_csv(%File.Stream{} = csv) do csv - |> String.split("\n", trim: true) |> Stream.map(&String.replace(&1, " ", "")) |> Stream.map(&String.split(&1, ",", trim: true)) |> Enum.reduce(%{}, fn [name, _tag, "0x" <> code, _status], acc -> diff --git a/lib/hexpds/recordconverter.ex b/lib/hipdster/recordconverter.ex similarity index 98% rename from lib/hexpds/recordconverter.ex rename to lib/hipdster/recordconverter.ex index a8712fe..904031c 100644 --- a/lib/hexpds/recordconverter.ex +++ b/lib/hipdster/recordconverter.ex @@ -1,5 +1,5 @@ defmodule RecordConverter do - alias Hexpds.CID, as: CID + alias Hipdster.CID, as: CID # Converts a record to a JSON-compatible format. def record_to_json(record) do diff --git a/lib/hexpds/tid.ex b/lib/hipdster/tid.ex similarity index 95% rename from lib/hexpds/tid.ex rename to lib/hipdster/tid.ex index 1b8a243..b36411a 100644 --- a/lib/hexpds/tid.ex +++ b/lib/hipdster/tid.ex @@ -1,4 +1,4 @@ -defmodule Hexpds.Tid do +defmodule Hipdster.Tid do import Bitwise defstruct [:timestamp, :clock_id] @@ -66,9 +66,9 @@ defmodule Hexpds.Tid do end end - defimpl String.Chars, for: Hexpds.Tid do - @spec to_string(Hexpds.Tid.t()) :: String.t() - defdelegate to_string(tid), to: Hexpds.Tid + defimpl String.Chars, for: Hipdster.Tid do + @spec to_string(Hipdster.Tid.t()) :: String.t() + defdelegate to_string(tid), to: Hipdster.Tid end @doc """ @@ -107,7 +107,7 @@ defmodule Hexpds.Tid do - Then, the `clock_id` `c` is combined into this value using the bitwise OR operation. - Resulting integer combines both the timestamp and clock_id in a single integer. """ - @spec to_integer(Hexpds.Tid.t()) :: integer() + @spec to_integer(Hipdster.Tid.t()) :: integer() def to_integer(%__MODULE__{timestamp: t, clock_id: c}) do t <<< 10 ||| c end diff --git a/lib/main.ex b/lib/main.ex index c56625c..0362edd 100644 --- a/lib/main.ex +++ b/lib/main.ex @@ -1,18 +1,8 @@ -defmodule Hexpds.Main do - @moduledoc """ - Documentation for `Hexpds`. - """ +defmodule Hipdster.Application do + use Application - @doc """ - Hello world. - - ## Examples - - iex> Hexpds.hello() - :world - - """ - def hello do - :world + @impl Application + def start(_type, _args) do + Hipdster.Multicodec.start_link() end end diff --git a/lib/mix/tasks/didgen.ex b/lib/mix/tasks/didgen.ex index a6c6271..79e57b0 100644 --- a/lib/mix/tasks/didgen.ex +++ b/lib/mix/tasks/didgen.ex @@ -6,13 +6,12 @@ defmodule Mix.Tasks.DidPlc.Generate do """ use Mix.Task - alias Hexpds.DidGenerator - - Application.ensure_all_started(:httpoison) + alias Hipdster.DidGenerator @shortdoc "Generate a DID:PLC: and publish it to the PLC server set in config/config.exs - pass in a handle" @impl Mix.Task def run([handle | _]) do + Application.ensure_all_started(:hipdster) handle |> DidGenerator.generate_did() |> inspect(pretty: true) diff --git a/mix.exs b/mix.exs index c08b98e..057db59 100644 --- a/mix.exs +++ b/mix.exs @@ -1,9 +1,9 @@ -defmodule Hexpds.MixProject do +defmodule Hipdster.MixProject do use Mix.Project def project do [ - app: :hexpds, + app: :hipdster, version: "0.1.0", elixir: "~> 1.15", start_permanent: Mix.env() == :prod, @@ -14,7 +14,8 @@ defmodule Hexpds.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - extra_applications: [:logger] + extra_applications: [:logger, :crypto], + mod: {Hipdster.Application, []} ] end diff --git a/native/hexpds_dagcbor_internal/.cargo/config.toml b/native/hipdster_dagcbor_internal/.cargo/config.toml similarity index 100% rename from native/hexpds_dagcbor_internal/.cargo/config.toml rename to native/hipdster_dagcbor_internal/.cargo/config.toml diff --git a/native/hexpds_dagcbor_internal/.gitignore b/native/hipdster_dagcbor_internal/.gitignore similarity index 100% rename from native/hexpds_dagcbor_internal/.gitignore rename to native/hipdster_dagcbor_internal/.gitignore diff --git a/native/hexpds_dagcbor_internal/Cargo.toml b/native/hipdster_dagcbor_internal/Cargo.toml similarity index 78% rename from native/hexpds_dagcbor_internal/Cargo.toml rename to native/hipdster_dagcbor_internal/Cargo.toml index d590924..f5a12c7 100644 --- a/native/hexpds_dagcbor_internal/Cargo.toml +++ b/native/hipdster_dagcbor_internal/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "hexpds_dagcbor_internal" +name = "hipdster_dagcbor_internal" version = "0.1.0" authors = [ "NetWatchInc" ] edition = "2021" [lib] -name = "hexpds_dagcbor_internal" +name = "hipdster_dagcbor_internal" path = "src/lib.rs" crate-type = ["cdylib"] diff --git a/native/hexpds_dagcbor_internal/README.md b/native/hipdster_dagcbor_internal/README.md similarity index 70% rename from native/hexpds_dagcbor_internal/README.md rename to native/hipdster_dagcbor_internal/README.md index cb7da22..32f9ff3 100644 --- a/native/hexpds_dagcbor_internal/README.md +++ b/native/hipdster_dagcbor_internal/README.md @@ -1,4 +1,4 @@ -# NIF for Elixir.Hexpds.DagCBOR.Internal +# NIF for Elixir.Hipdster.DagCBOR.Internal ## To build the NIF module: @@ -7,8 +7,8 @@ ## To load the NIF: ```elixir -defmodule Hexpds.DagCBOR.Internal do - use Rustler, otp_app: :hexpds, crate: "hexpds_dagcbor_internal" +defmodule Hipdster.DagCBOR.Internal do + use Rustler, otp_app: :hipdster, crate: "hipdster_dagcbor_internal" # When your NIF is loaded, it will override this function. def encode_dag_cbor(json), do: :erlang.nif_error(:nif_not_loaded) diff --git a/native/hexpds_dagcbor_internal/src/lib.rs b/native/hipdster_dagcbor_internal/src/lib.rs similarity index 97% rename from native/hexpds_dagcbor_internal/src/lib.rs rename to native/hipdster_dagcbor_internal/src/lib.rs index 2d97df3..b4dc699 100644 --- a/native/hexpds_dagcbor_internal/src/lib.rs +++ b/native/hipdster_dagcbor_internal/src/lib.rs @@ -94,4 +94,4 @@ fn decode_dag_cbor<'a>(env: Env<'a>, cbor_data: Binary<'a>) -> Term<'a> { (atoms::ok(), json).encode(env) } -rustler::init!("Elixir.Hexpds.DagCBOR.Internal", [encode_dag_cbor, decode_dag_cbor]); \ No newline at end of file +rustler::init!("Elixir.Hipdster.DagCBOR.Internal", [encode_dag_cbor, decode_dag_cbor]); diff --git a/native/hexpds_k256_internal/.cargo/config.toml b/native/hipdster_k256_internal/.cargo/config.toml similarity index 100% rename from native/hexpds_k256_internal/.cargo/config.toml rename to native/hipdster_k256_internal/.cargo/config.toml diff --git a/native/hexpds_k256_internal/.gitignore b/native/hipdster_k256_internal/.gitignore similarity index 100% rename from native/hexpds_k256_internal/.gitignore rename to native/hipdster_k256_internal/.gitignore diff --git a/native/hexpds_k256_internal/Cargo.toml b/native/hipdster_k256_internal/Cargo.toml similarity index 82% rename from native/hexpds_k256_internal/Cargo.toml rename to native/hipdster_k256_internal/Cargo.toml index 0dfbe4d..4746b48 100644 --- a/native/hexpds_k256_internal/Cargo.toml +++ b/native/hipdster_k256_internal/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "hexpds_k256_internal" +name = "hipdster_k256_internal" version = "0.1.0" authors = [ "NetWatchInc" ] edition = "2021" [lib] -name = "hexpds_k256_internal" +name = "hipdster_k256_internal" path = "src/lib.rs" crate-type = ["cdylib"] diff --git a/native/hexpds_k256_internal/README.md b/native/hipdster_k256_internal/README.md similarity index 75% rename from native/hexpds_k256_internal/README.md rename to native/hipdster_k256_internal/README.md index f6e4e06..0d7719d 100644 --- a/native/hexpds_k256_internal/README.md +++ b/native/hipdster_k256_internal/README.md @@ -1,4 +1,4 @@ -# NIF for Elixir.Hexpds.K256.Internal +# NIF for Elixir.Hipdster.K256.Internal ## To build the NIF module: @@ -7,8 +7,8 @@ ## To load the NIF: ```elixir -defmodule Hexpds.K256.Internal do - use Rustler, otp_app: :hexpds, crate: "hexpds_k256_internal" +defmodule Hipdster.K256.Internal do + use Rustler, otp_app: :hipdster, crate: "hipdster_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) diff --git a/native/hexpds_k256_internal/src/lib.rs b/native/hipdster_k256_internal/src/lib.rs similarity index 98% rename from native/hexpds_k256_internal/src/lib.rs rename to native/hipdster_k256_internal/src/lib.rs index 714a1da..bc03453 100644 --- a/native/hexpds_k256_internal/src/lib.rs +++ b/native/hipdster_k256_internal/src/lib.rs @@ -126,6 +126,6 @@ fn verify_signature<'a>( } rustler::init!( - "Elixir.Hexpds.K256.Internal", + "Elixir.Hipdster.K256.Internal", [create_public_key, compress_public_key, sign_message, verify_signature] ); diff --git a/priv/native/libhexpds_k256.so b/priv/native/libhexpds_k256.so deleted file mode 100755 index fc20197..0000000 Binary files a/priv/native/libhexpds_k256.so and /dev/null differ diff --git a/test/hexpds_test.exs b/test/hexpds_test.exs deleted file mode 100644 index 5bbb3e0..0000000 --- a/test/hexpds_test.exs +++ /dev/null @@ -1,8 +0,0 @@ -# defmodule HexpdsTest do -# use ExUnit.Case -# doctest Hexpds - -# test "greets the world" do -# assert Hexpds.hello() == :world -# end -# end diff --git a/test/hexpds_tid_test.exs b/test/hexpds_tid_test.exs deleted file mode 100644 index 1e3d522..0000000 --- a/test/hexpds_tid_test.exs +++ /dev/null @@ -1,13 +0,0 @@ -defmodule HexpdsTidTest do - use ExUnit.Case - doctest Hexpds.Tid - - test "converts to string" do - assert Hexpds.Tid.to_string(%Hexpds.Tid{timestamp: 1706732639995761, clock_id: 243}) == "3kkciofrlvlbn" - end - - test "converts from string" do - assert Hexpds.Tid.from_string("3kkciofrlvlbn") == %Hexpds.Tid{timestamp: 1706732639995761, clock_id: 243} - end - -end diff --git a/test/hexpds_cid_test.exs b/test/hipdster_cid_test.exs similarity index 99% rename from test/hexpds_cid_test.exs rename to test/hipdster_cid_test.exs index a1db3f2..776edd5 100644 --- a/test/hexpds_cid_test.exs +++ b/test/hipdster_cid_test.exs @@ -2,7 +2,7 @@ defmodule CIDTest do # Taken from nocursor/ex-cid - alias Hexpds.{CID, Multicodec} + alias Hipdster.{CID, Multicodec} use ExUnit.Case, async: true doctest CID require Multibase @@ -10,7 +10,6 @@ defmodule CIDTest do #TODO: better test setup to include more re-used data or scope the data, but the data is pretty simple so.......maybe not setup_all do - Hexpds.Multicodec.start_link() digest = :crypto.hash(:sha256, "hello world") {:ok, multihash} = Multihash.encode(:sha2_256, digest) %{multihash: multihash} diff --git a/test/hexpds_dagcbor_test.exs b/test/hipdster_dagcbor_test.exs similarity index 61% rename from test/hexpds_dagcbor_test.exs rename to test/hipdster_dagcbor_test.exs index 1cca1ee..043e395 100644 --- a/test/hexpds_dagcbor_test.exs +++ b/test/hipdster_dagcbor_test.exs @@ -1,6 +1,6 @@ -defmodule HexpdsDagcborTest do +defmodule HipdsterDagcborTest do use ExUnit.Case - doctest Hexpds.DagCBOR + doctest Hipdster.DagCBOR defp test_cases do [ @@ -14,8 +14,8 @@ defmodule HexpdsDagcborTest do test "cbor roundtrip" do for input <- test_cases() do - {:ok, cbor_encoded} = Hexpds.DagCBOR.encode(Jason.encode!(input)) - {:ok, original} = Hexpds.DagCBOR.decode(cbor_encoded) + {:ok, cbor_encoded} = Hipdster.DagCBOR.encode(Jason.encode!(input)) + {:ok, original} = Hipdster.DagCBOR.decode(cbor_encoded) assert input == original end end diff --git a/test/hexpds_k256_test.exs b/test/hipdster_k256_test.exs similarity index 91% rename from test/hexpds_k256_test.exs rename to test/hipdster_k256_test.exs index d9d5205..308b804 100644 --- a/test/hexpds_k256_test.exs +++ b/test/hipdster_k256_test.exs @@ -1,12 +1,7 @@ -defmodule HexpdsK256Test do +defmodule HipdsterK256Test do use ExUnit.Case - doctest Hexpds.K256 - alias Hexpds.K256, as: K256 - - setup_all do - Hexpds.Multicodec.start_link() - :ok - end + doctest Hipdster.K256 + alias Hipdster.K256, as: K256 defp test_cases do %{ diff --git a/test/hipdster_test.exs b/test/hipdster_test.exs new file mode 100644 index 0000000..38e5d5b --- /dev/null +++ b/test/hipdster_test.exs @@ -0,0 +1,8 @@ +# defmodule HipdsterTest do +# use ExUnit.Case +# doctest Hipdster + +# test "greets the world" do +# assert Hipdster.hello() == :world +# end +# end diff --git a/test/hipdster_tid_test.exs b/test/hipdster_tid_test.exs new file mode 100644 index 0000000..2b4ca06 --- /dev/null +++ b/test/hipdster_tid_test.exs @@ -0,0 +1,13 @@ +defmodule HipdsterTidTest do + use ExUnit.Case + doctest Hipdster.Tid + + test "converts to string" do + assert Hipdster.Tid.to_string(%Hipdster.Tid{timestamp: 1706732639995761, clock_id: 243}) == "3kkciofrlvlbn" + end + + test "converts from string" do + assert Hipdster.Tid.from_string("3kkciofrlvlbn") == %Hipdster.Tid{timestamp: 1706732639995761, clock_id: 243} + end + +end diff --git a/test/test_helper.exs b/test/test_helper.exs index 869559e..1394682 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1 +1,2 @@ +Application.ensure_all_started(:hipdster) ExUnit.start()