Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
refacto: move NUT-00 related stuffs in a dedicated folder (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdelabro authored Oct 14, 2024
1 parent d678574 commit db8197a
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Cashubrew.Crypto.BDHKE do
defmodule Cashubrew.Nuts.Nut00.BDHKE do
@moduledoc """
Cryptographic functions for the Cashubrew mint, including BDHKE implementation.
Check [NUT-00](https://cashubtc.github.io/nuts/00/) for more information.
Expand Down
21 changes: 21 additions & 0 deletions lib/cashubrew/NUTs/NUT-00/errors.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Cashubrew.Nuts.Nut00.Error do
@moduledoc """
An error to be return by the API endpoints
"""

@derive Jason.Encoder
defstruct [:detail, :code]

@type t :: %__MODULE__{
code: non_neg_integer(),
detail: String.t()
}

@doc """
Creates a new error struct.
"""
@spec new_error(non_neg_integer(), String.t()) :: t()
def new_error(code, detail) do
%__MODULE__{code: code, detail: detail}
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Cashubrew.Cashu.BlindedMessage do
defmodule Cashubrew.Nuts.Nut00.BlindedMessage do
@moduledoc """
Represents a BlindedMessage in the Cashu protocol.
"""
Expand All @@ -21,7 +21,7 @@ defmodule Cashubrew.Cashu.BlindedMessage do
end
end

defmodule Cashubrew.Cashu.BlindSignature do
defmodule Cashubrew.Nuts.Nut00.BlindSignature do
@moduledoc """
Represents a BlindSignature in the Cashu protocol.
"""
Expand All @@ -44,7 +44,7 @@ defmodule Cashubrew.Cashu.BlindSignature do
end
end

defmodule Cashubrew.Cashu.Proof do
defmodule Cashubrew.Nuts.Nut00.Proof do
@moduledoc """
Represents a Proof in the Cashu protocol.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Cashubrew.Cashu.Token do
defmodule Cashubrew.Nuts.Nut00.Token do
@moduledoc """
Handles the serialization and deserialization of Cashu tokens.
"""
Expand Down Expand Up @@ -41,7 +41,7 @@ defmodule Cashubrew.Cashu.Token do
def deserialize_v3(_), do: {:error, "Invalid token format"}
end

defmodule Cashubrew.Cashu.TokenV4 do
defmodule Cashubrew.Nuts.Nut00.TokenV4 do
@moduledoc """
Handles the serialization and deserialization of Cashu V4 tokens.
"""
Expand Down
3 changes: 1 addition & 2 deletions lib/cashubrew/core/mint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ defmodule Cashubrew.Mint do
"""

use GenServer
alias Cashubrew.Cashu.BlindSignature
alias Cashubrew.Crypto.BDHKE
alias Cashubrew.Lightning.LightningNetworkService
alias Cashubrew.Lightning.MockLightningNetworkService
alias Cashubrew.Nuts.Nut00.{BDHKE, BlindSignature}
alias Cashubrew.Query.MeltTokens

alias Cashubrew.Schema.{
Expand Down
2 changes: 1 addition & 1 deletion lib/cashubrew/mix/tasks/bench.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Mix.Tasks.Bench do
"""
use Mix.Task

alias Cashubrew.Crypto.BDHKE
alias Cashubrew.Nuts.Nut00.BDHKE

@shortdoc "Runs the BDHKE benchmark"

Expand Down
3 changes: 2 additions & 1 deletion lib/cashubrew/schema/keyset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ defmodule Cashubrew.Schema.Keyset do
"""
use Ecto.Schema
import Ecto.Changeset
alias Cashubrew.{Crypto.BDHKE, Schema}
alias Cashubrew.Nuts.Nut00.BDHKE
alias Cashubrew.Schema

import Bitwise

Expand Down
3 changes: 1 addition & 2 deletions lib/cashubrew/wallet/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ defmodule Cashubrew.Wallet.CLI do
A simple CLI wallet for interacting with the Cashubrew mint.
"""

alias Cashubrew.Crypto.BDHKE
alias Cashubrew.Cashu.{BlindedMessage, Proof}
alias Cashubrew.Nuts.Nut00.{BDHKE, BlindedMessage, Proof}
alias Cashubrew.Wallet
require Logger

Expand Down
2 changes: 1 addition & 1 deletion lib/cashubrew/wallet/wallet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Cashubrew.Wallet do
Handles wallet-related operations for the Cashubrew CLI.
"""

alias Cashubrew.Crypto.BDHKE
alias Cashubrew.Nuts.Nut00.BDHKE

defp data_dir do
"./_build/.cashubrew/data"
Expand Down
2 changes: 1 addition & 1 deletion lib/cashubrew/web/controllers/mint_controller.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Cashubrew.Web.MintController do
use Cashubrew.Web, :controller
alias Cashubrew.Cashu.BlindedMessage
alias Cashubrew.Mint
alias Cashubrew.Nuts.Nut00.BlindedMessage
alias Cashubrew.Nuts.Nut06
alias Cashubrew.Web.{Keys, KeysetResponse}

Expand Down
2 changes: 1 addition & 1 deletion test/bdhke_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule BDHKETest do
"""
use ExUnit.Case
require Logger
alias Cashubrew.Crypto.BDHKE
alias Cashubrew.Crypto.Secp256k1Utils
alias Cashubrew.Nuts.Nut00.BDHKE

test "end-to-end BDHKE test" do
Logger.info("\nStarting end-to-end test for Blind Diffie-Hellman Key Exchange (BDHKE)")
Expand Down
2 changes: 1 addition & 1 deletion test/cashu_token_serde_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Cashubrew.Cashu.TokenTest do
use ExUnit.Case, async: true
alias Cashubrew.Cashu.TokenV4
alias Cashubrew.Nuts.Nut00.TokenV4

describe "V4 Token" do
@tag :v4_token
Expand Down

0 comments on commit db8197a

Please sign in to comment.