Skip to content

Commit

Permalink
Merge pull request #48 from kommitters/v0.1
Browse files Browse the repository at this point in the history
v0.1.1 release
  • Loading branch information
juanhurtado10 committed Aug 26, 2021
2 parents bde8f60 + 52bf607 commit 99643dc
Show file tree
Hide file tree
Showing 41 changed files with 303 additions and 63 deletions.
50 changes: 40 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- 'v*.*'
- 'v*.[0-9]'
pull_request:

jobs:
Expand All @@ -18,26 +18,56 @@ jobs:
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
- name: Checkout Github repo
uses: actions/checkout@v2

- name: Sets up an Erlang/OTP environment
uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@v2

- name: Set mix file hash
id: set_vars
run: |
mix_hash="${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}"
echo "::set-output name=mix_hash::$mix_hash"
- name: Cache dependecies
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
key: ${{ runner.os }}-mix-${{ steps.set_vars.outputs.mix_hash }}
restore-keys: |
${{ runner.os }}-mix-
- name: Install Dependencies
- name: Cache PLT files
id: plt-cache
uses: actions/cache@v2
with:
path: |
_build
priv/plts
key: plt-cache-${{ steps.set_vars.outputs.mix_hash }}
restore-keys: |
plt-cache-
- name: Install dependencies
run: mix deps.get
- name: Check Formatting

- name: Check formatting
run: mix format --check-formatted
- name: Run Tests

- name: Run tests
run: mix test
- name: Run Credo

- name: Run credo
run: mix credo --strict
- name: Run Excoveralls

- name: Run dialyzer
run: mix dialyzer --no-check --ignore-exit-status

- name: Run excoveralls
run: mix coveralls.github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog

## 0.0.1 (09.08.2021)
- Ed25519 KeyPair generation.
- Transactions XDR types.
- Accounts XDR types.
- Keys XDR types.
- Base XDR types.
## 0.1.1 (26.08.2021)
* Increase test coverage.
* Integrate Dialyzer.

## 0.1.0 (09.08.2021)
* Ed25519 KeyPair generation.
* Transactions XDR types.
* Accounts XDR types.
* Keys XDR types.
* Base XDR types.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ alternatives.
## Additional resources

* Explore the Stellar API
* #get in touch: oss@kommit.co | [@kommitters_oss](https://twitter.com/kommitters_oss) on twitter.
* #get in touch: [oss@kommit.co](mailto:oss@kommit.co) | [@kommitters_oss](https://twitter.com/kommitters_oss) on twitter.

## Acknowledgements

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
![Downloads Badge](https://img.shields.io/hexpm/dt/stellar_base?style=for-the-badge)
[![License badge](https://img.shields.io/hexpm/l/stellar_base.svg?style=for-the-badge)](https://github.com/kommitters/stellar_base/blob/main/LICENSE.md)

### **⚠️ Warning! This library is under active development**. Do not use it in production environments.
### ⚠️ Warning! This library is under active development. DO NOT use it in production environments.

`stellar_base` is an **Elixir library** that provides a complete set of functions to read, write, hash, and sign XDR primitive constructs used in [stellar-core][stellar-core].

This library is aimed at developers building Elixir applications on top of the Stellar network. Transactions constructed by this library may be submitted to any Horizon instance for processing onto the ledger, using any Stellar SDK client. The recommended client for Elixir programmers is [stellar_sdk][sdk].

## stellar_base vs stellar_sdk
* `stellar_sdk` is a client library for interfacing with **Horizon** server REST endpoints to retrieve ledger information and submit transactions built with `stellar_base`.
* `stellar_base` enables the construction, signing, and encoding of Stellar transactions.
* `stellar_sdk` is a high-level library that serves as server-side API for Horizon.
* `stellar_base` is lower-level library for creating Stellar primitive constructs via XDR helpers and wrappers.
* Use the `stellar_base` library if you are planning to build on top of it.

## Installation
Expand All @@ -22,7 +22,7 @@ This library is aimed at developers building Elixir applications on top of the S
```elixir
def deps do
[
{:stellar_base, "~> 0.1.0"}
{:stellar_base, "~> 0.1.1"}
]
end
```
Expand Down
6 changes: 2 additions & 4 deletions lib/xdr/accounts/muxed_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ defmodule Stellar.XDR.MuxedAccount do
def decode_xdr!(bytes, spec \\ union_spec())

def decode_xdr!(bytes, spec) do
case XDR.Union.decode_xdr!(bytes, spec) do
{{type, account}, rest} -> {new(type, account), rest}
error -> error
end
{{type, account}, rest} = XDR.Union.decode_xdr!(bytes, spec)
{new(type, account), rest}
end

@spec union_spec() :: XDR.Union.t()
Expand Down
2 changes: 1 addition & 1 deletion lib/xdr/base/void.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Stellar.XDR.Void do
"""
@behaviour XDR.Declaration

@type t :: %__MODULE__{value: none()}
@type t :: %__MODULE__{value: nil}

defstruct [:value]

Expand Down
2 changes: 1 addition & 1 deletion lib/xdr/keys/public_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Stellar.XDR.PublicKey do

defstruct [:public_key, :type]

@spec new(public_key :: UInt256.t(), type :: PublicKeyType.t() | nil) :: t()
@spec new(public_key :: UInt256.t(), type :: PublicKeyType.t()) :: t()
def new(%UInt256{} = public_key, %PublicKeyType{} = type),
do: %__MODULE__{public_key: public_key, type: type}

Expand Down
12 changes: 6 additions & 6 deletions lib/xdr/keys/signer_key.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ defmodule Stellar.XDR.SignerKey do
SIGNER_KEY_TYPE_HASH_X: UInt256
]

@type t :: %__MODULE__{signer_key: String.t(), type: atom()}
@type t :: %__MODULE__{signer_key: UInt256.t(), type: SignerKeyType.t()}

defstruct [:signer_key, :type]

@spec new(public_key :: UInt256.t(), type :: SignerKeyType.t() | nil) :: t()
@spec new(signer_key :: UInt256.t(), type :: SignerKeyType.t()) :: t()
def new(%UInt256{} = signer_key, %SignerKeyType{} = type),
do: %__MODULE__{signer_key: signer_key, type: type}

Expand All @@ -35,7 +35,7 @@ defmodule Stellar.XDR.SignerKey do
end

@impl true
def decode_xdr(bytes, spec \\ xdr_union_spec())
def decode_xdr(bytes, spec \\ union_spec())

def decode_xdr(bytes, spec) do
case XDR.Union.decode_xdr(bytes, spec) do
Expand All @@ -45,15 +45,15 @@ defmodule Stellar.XDR.SignerKey do
end

@impl true
def decode_xdr!(bytes, spec \\ xdr_union_spec())
def decode_xdr!(bytes, spec \\ union_spec())

def decode_xdr!(bytes, spec) do
{{type, key}, rest} = XDR.Union.decode_xdr!(bytes, spec)
{new(key, type), rest}
end

@spec xdr_union_spec() :: XDR.Union.t()
defp xdr_union_spec do
@spec union_spec() :: XDR.Union.t()
defp union_spec do
:SIGNER_KEY_TYPE_ED25519
|> SignerKeyType.new()
|> XDR.Union.new(@arms)
Expand Down
2 changes: 1 addition & 1 deletion lib/xdr/transactions/memo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Stellar.XDR.Memo do

defstruct [:value, :type]

@spec new(value :: memo_value(), type :: MemoType.t() | nil) :: t()
@spec new(value :: memo_value(), type :: MemoType.t()) :: t()
def new(value, %MemoType{} = type),
do: %__MODULE__{value: value, type: type}

Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Stellar.MixProject do
use Mix.Project

@github_url "https://github.com/kommitters/stellar_base"
@version "0.1.0"
@version "0.1.1"

def project do
[
Expand Down Expand Up @@ -36,9 +36,10 @@ defmodule Stellar.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:elixir_xdr, "~> 0.1.5"},
{:elixir_xdr, "~> 0.1.6"},
{:ed25519, "~> 1.3"},
{:crc, "~> 0.10.0"},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.14", only: :test, runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.24", only: :dev, runtime: false}
Expand Down
4 changes: 3 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
"crc": {:hex, :crc, "0.10.2", "93ee6788904735d4d93f59a1e80860e4c9aa44e8d2ff7c69857eb62757454137", [:mix, :rebar3], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "6b931cfb5e7d20c3c4113adab460f29ee5a50a36b397edd81c9bede2bbdb505c"},
"credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
"ed25519": {:hex, :ed25519, "1.3.2", "e3a2d4badf57f0799279cf09925bd761ec38df6df3696e266585626280b5c0ad", [:mix], [], "hexpm", "2290e46e0e23717adbe20632c6dd29aa71a46ca6e153ef7ba41fe1204f66f859"},
"elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"},
"elixir_xdr": {:hex, :elixir_xdr, "0.1.5", "afac87943517ca9057aa0319b68bba62297af8b69655cfedee1a70eb535032ad", [:mix], [], "hexpm", "180d8e1fd3d66637acc10323562cb3c64bf7dd57cc5c9caef6b5aab6782c6a7b"},
"elixir_xdr": {:hex, :elixir_xdr, "0.1.6", "e957a52e7d3c0605121bede2afb589fa59f7ed5798b8a920752d7e7abb3e4f91", [:mix], [], "hexpm", "b604822856c38bdc1976714f352536411625b971bb4b2e31ee811aa6f985c024"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.25.1", "4b736fa38dc76488a937e5ef2944f5474f3eff921de771b25371345a8dc810bc", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3200b0a69ddb2028365281fbef3753ea9e728683863d8cdaa96580925c891f67"},
"excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
Expand Down
36 changes: 36 additions & 0 deletions test/ed25519/public_key_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Stellar.Ed25519.PublicKeyTest do
use ExUnit.Case

alias Stellar.Ed25519.PublicKey

describe "PublicKey" do
setup do
%{
public_key: "GCGCSNUKFLG4O27V667FKJAPD2UEGPZUW7DGCOESEJ7VUFPGACWFT6CB",
public_key_binary:
<<140, 41, 54, 138, 42, 205, 199, 107, 245, 247, 190, 85, 36, 15, 30, 168, 67, 63, 52,
183, 198, 97, 56, 146, 34, 127, 90, 21, 230, 0, 172, 89>>
}
end

test "encode!/2 with nil data" do
assert_raise ArgumentError, "cannot encode nil data", fn ->
PublicKey.encode!(nil)
end
end

test "encode!/2", %{public_key: public_key, public_key_binary: public_key_binary} do
^public_key = PublicKey.encode!(public_key_binary)
end

test "decode!/2 with nil data" do
assert_raise ArgumentError, "cannot decode nil data", fn ->
PublicKey.decode!(nil)
end
end

test "decode!/2", %{public_key: public_key, public_key_binary: public_key_binary} do
^public_key_binary = PublicKey.decode!(public_key)
end
end
end
36 changes: 36 additions & 0 deletions test/ed25519/secret_key_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Stellar.Ed25519.SecretSeedTest do
use ExUnit.Case

alias Stellar.Ed25519.SecretSeed

describe "PublicKey" do
setup do
%{
secret_seed: "SB72G7VGRAH2LAMX3WOIPSRNFW4TI35NAVNGOHSWLP6C4HSYOE3FLMOS",
secret_seed_binary:
<<127, 163, 126, 166, 136, 15, 165, 129, 151, 221, 156, 135, 202, 45, 45, 185, 52, 111,
173, 5, 90, 103, 30, 86, 91, 252, 46, 30, 88, 113, 54, 85>>
}
end

test "encode!/2 with nil data" do
assert_raise ArgumentError, "cannot encode nil data", fn ->
SecretSeed.encode!(nil)
end
end

test "encode!/2", %{secret_seed: secret_seed, secret_seed_binary: secret_seed_binary} do
^secret_seed = SecretSeed.encode!(secret_seed_binary)
end

test "decode!/2 with nil data" do
assert_raise ArgumentError, "cannot decode nil data", fn ->
SecretSeed.decode!(nil)
end
end

test "decode!/2", %{secret_seed: secret_seed, secret_seed_binary: secret_seed_binary} do
^secret_seed_binary = SecretSeed.decode!(secret_seed)
end
end
end
6 changes: 6 additions & 0 deletions test/ed25519/str_key_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ defmodule Stellar.Ed25519.StrKeyTest do
end

describe "decode/2" do
test "nil data" do
assert_raise ArgumentError, "cannot decode nil data", fn ->
StrKey.decode!(nil, @pk_version_bytes)
end
end

test "public key", %{public_key: public_key, public_key_binary: public_key_binary} do
^public_key_binary = StrKey.decode!(public_key, @pk_version_bytes)
end
Expand Down
4 changes: 4 additions & 0 deletions test/xdr/accounts/account_id_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ defmodule Stellar.XDR.AccountIDTest do
{:ok, {^account_id, ""}} = AccountID.decode_xdr(binary)
end

test "decode_xdr/2 with an invalid binary" do
{:error, :not_binary} = AccountID.decode_xdr(123)
end

test "decode_xdr!/2", %{account_id: account_id, encoded_binary: binary} do
{^account_id, ^binary} = AccountID.decode_xdr!(binary <> binary)
end
Expand Down
4 changes: 4 additions & 0 deletions test/xdr/accounts/muxed_account_med25519_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ defmodule Stellar.XDR.MuxedAccountMed25519Test do
{:ok, {^muxed_account, ""}} = MuxedAccountMed25519.decode_xdr(binary)
end

test "decode_xdr/2 with an invalid binary" do
{:error, :not_binary} = MuxedAccountMed25519.decode_xdr(123)
end

test "decode_xdr!/2", %{muxed_account: muxed_account, encoded_binary: binary} do
{^muxed_account, ^binary} = MuxedAccountMed25519.decode_xdr!(binary <> binary)
end
Expand Down
22 changes: 17 additions & 5 deletions test/xdr/accounts/muxed_account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ defmodule Stellar.XDR.MuxedAccountTest do
%MuxedAccount{account: ^ed25519_account} = MuxedAccount.new(type, ed25519_account)
end

test "new/1 with an invalid account", %{ed25519_account: ed25519_account} do
type = CryptoKeyType.new(:KEY_TYPE_HASH_X)
{:error, :invalid_key_type} = MuxedAccount.new(type, ed25519_account)
end

test "encode_xdr/1", %{muxed_account: muxed_account, encoded_binary: binary} do
{:ok, ^binary} = MuxedAccount.encode_xdr(muxed_account)
end
Expand All @@ -39,13 +44,20 @@ defmodule Stellar.XDR.MuxedAccountTest do
{:ok, {^muxed_account, ""}} = MuxedAccount.decode_xdr(binary)
end

test "decode_xdr!/2", %{muxed_account: muxed_account, encoded_binary: binary} do
{^muxed_account, ^binary} = MuxedAccount.decode_xdr!(binary <> binary)
test "decode_xdr/2 with an invalid binary" do
{:error, :not_binary} = MuxedAccount.decode_xdr(123)
end

test "invalid ", %{ed25519_account: ed25519_account} do
type = CryptoKeyType.new(:KEY_TYPE_HASH_X)
{:error, :invalid_key_type} = MuxedAccount.new(type, ed25519_account)
test "decode_xdr!/2 with an invalid binary" do
assert_raise XDR.Error.Union,
"The :identifier received by parameter must be a binary value, for example: <<0, 0, 0, 5>>",
fn ->
MuxedAccount.decode_xdr!(123)
end
end

test "decode_xdr!/2", %{muxed_account: muxed_account, encoded_binary: binary} do
{^muxed_account, ^binary} = MuxedAccount.decode_xdr!(binary <> binary)
end
end

Expand Down
Loading

0 comments on commit 99643dc

Please sign in to comment.