Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinMeier committed Jan 24, 2024
2 parents 009f578 + b9f6482 commit 2c0fde6
Show file tree
Hide file tree
Showing 47 changed files with 9,067 additions and 1,291 deletions.
39 changes: 34 additions & 5 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,47 @@ name: Elixir CI
on: [push, pull_request]

jobs:
build:

name: Build and test
build_with_opt_24:
name: Build and test older versions ${{matrix.elixir}}-otp-${{matrix.otp}}
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['24.0']
elixir: ['1.12.0', '1.13.0', '1.14.0']
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
- name: format and lint
run: mix lint.all

build_with_opt_25:
name: Build and test ${{matrix.elixir}}-otp-${{matrix.otp}}
runs-on: ubuntu-latest
strategy:
matrix:
otp: ['25.0']
elixir: ['1.13.0', '1.14.0']
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-elixir@v1
with:
elixir-version: '1.10.4' # Define the elixir version [required]
otp-version: '22.3' # Define the OTP version [required]
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ bitcoinex-*.tar

# dialyzer plt
/_plts/*.plt
/_plts/*.plt.hash
/_plts/*.plt.hash

# idea
.idea/

# bitcoin related files
**/*.psbt
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.10.4-otp-22
erlang 22.3.4.1
elixir 1.15.6-otp-26
erlang 26.1.2
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.1.7] - 2023-01-16
### Added
- Support for Schnorr signature creation and validation
- Fixed bug which would not correctly parse a BOLT11 invoice with amount explicitly set to 0.
- Bump Elixir & Erlang Requirements & dependencies

## [0.1.4] - 2021-05-19
### Added
- BIP32 support with new modules for extended keys and derivation paths.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Documentation is available on [hexdocs.pm](https://hexdocs.pm/bitcoinex/api-refe

With [Hex](https://hex.pm/packages/bitcoinex):

{:bitcoinex, "~> 0.1.0"}
{:bitcoinex, "~> 0.1.7"}

Local:

Expand Down
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ The following keys may be used to communicate sensitive information to developer
| Name | Fingerprint |
|------|-------------|
| Philip Glazman | 1DED 561A 828F 6542 9FA9 7B08 C31B DE21 A1C0 170D |
| bruteforcecat | 741C B8EC 98F6 8979 1125 0488 5FEF C5A8 B4A2 E122 |
| bruteforcecat | 741C B8EC 98F6 8979 1125 0488 5FEF C5A8 B4A2 E122 |
| Sachin Meier | 9AA7 515C 4818 C98C 0792  F074 C599 15FE 4B6D 6276 |
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand Down
21 changes: 7 additions & 14 deletions lib/base58.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Bitcoinex.Base58 do
alias Bitcoinex.Utils

@typedoc """
Base58 encoding is only supported for p2sh and p2pkh address types.
Base58 encoding is only supported for p2sh and p2pkh address types.
"""
@type address_type :: :p2sh | :p2pkh
@base58_encode_list ~c(123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz)
Expand Down Expand Up @@ -69,9 +69,10 @@ defmodule Bitcoinex.Base58 do
|> Tuple.to_list()
|> Enum.map(&:binary.list_to_bin(&1))

case checksum == binary_slice(Utils.double_sha256(decoded_body), 0..3) do
false -> {:error, :invalid_checksum}
true -> {:ok, decoded_body}
if checksum == checksum(decoded_body) do
{:ok, decoded_body}
else
{:error, :invalid_checksum}
end
end

Expand Down Expand Up @@ -117,16 +118,8 @@ defmodule Bitcoinex.Base58 do

@spec checksum(binary) :: binary
defp checksum(body) do
body
|> Utils.double_sha256()
|> binary_slice(0..3)
end
<<checksum::binary-4, _rest::binary>> = Utils.double_sha256(body)

@spec binary_slice(binary, Range.t()) :: binary
defp binary_slice(data, range) do
data
|> :binary.bin_to_list()
|> Enum.slice(range)
|> :binary.list_to_bin()
checksum
end
end
10 changes: 6 additions & 4 deletions lib/bech32.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Bitcoinex.Bech32 do
Reference: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32
"""

use Bitwise
import Bitwise

@gen [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3]
@data_charset_list 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
Expand Down Expand Up @@ -185,7 +185,7 @@ defmodule Bitcoinex.Bech32 do

defp create_checksum(hrp, data, encoding_type) do
values = bech32_hrp_expand(hrp) ++ data ++ [0, 0, 0, 0, 0, 0]
mod = bech32_polymod(values) ^^^ @encoding_constant_map[encoding_type]
mod = Bitwise.bxor(bech32_polymod(values), @encoding_constant_map[encoding_type])
for p <- 0..5, do: mod >>> (5 * (5 - p)) &&& 31
end

Expand All @@ -195,15 +195,17 @@ defmodule Bitcoinex.Bech32 do
1,
fn value, acc ->
b = acc >>> 25
acc = ((acc &&& 0x1FFFFFF) <<< 5) ^^^ value
acc = Bitwise.bxor((acc &&& 0x1FFFFFF) <<< 5, value)

Enum.reduce(0..length(@gen), acc, fn i, in_acc ->
in_acc ^^^
right_side =
if (b >>> i &&& 1) != 0 do
Enum.at(@gen, i)
else
0
end

Bitwise.bxor(in_acc, right_side)
end)
end
)
Expand Down
Loading

0 comments on commit 2c0fde6

Please sign in to comment.