Skip to content

sleepdefic1t/BIP66

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

BIP66

A simple Bitcoin BIP66 Implementation in C++ for the ARK Ecosystem.

ANS.1 DER Encoder/Decoder based on Bitcoin BIP66.

GitHub Actions CodeFactor Codacy Badge Latest Version License: MIT

Supported Platforms

OS: Supported:
Linux
macOS
Windows
Environment: Supported:
Arduino IDE
PlatformIO
Board: Supported:
ESP8266
ESP32
ESP32-S2

Installation

Arduino IDE

Download BIP66 from the Arduino IDE Library manager.
You can also copy this repo to the Arduino Libraries directory.
(e.g. ~/Documents/Arduino/libraries)

  1. Open the BIP66.ino sketch in the examples/BIP66 folder.
  2. Select your board from the Arduino IDE
  3. Upload the sketch.

PlatformIO

Building BIP66 with PIO

pio run

Building BIP66 and Tests with PIO

pio run -t test/

Flashing and Running Tests with PIO

pio run -t test/ -e esp32 -t upload


CMake

Operating System builds like Linux, macOS, and Windows use CMake.
This build should be done out of source.

Building BIP66 with CMake

  1. mkdir build && cd build
  2. cmake ..
  3. cmake --build .

Building BIP66 and Tests with CMake

  1. mkdir build && cd build
  2. cmake -DUNIT_TEST=ON ..
  3. cmake --build .

Running BIP66 Tests with CMake

./test/bip66_tests


Usage

Encoding a Signature

From the raw R & S elements:

uint8_t r[32] = {
    33, 112, 79, 42, 219, 46, 74, 16, 163, 221, 193, 215, 214, 69, 82, 184, 6, 28, 5, 246, 209, 42, 22, 140, 105, 9, 28, 117, 88, 29, 97, 20
};

uint8_t s[32] = {
    14, 223, 55, 104, 157, 39, 134, 252, 105, 10, 249, 240, 246, 250, 31, 98, 156, 149, 105, 80, 57, 246, 72, 166, 212, 85, 72, 67, 2, 64, 46, 147
};

uint8_t signature[72];

const bool success = bip66::encode(r, 32, s, 32, signature);

Decoding a Signature

From a DER-encoded signature to raw R & S elements:

uint8_t derEncodedSignature[70] = {
    48, 68, 2, 32, 33, 112, 79, 42, 219, 46, 74, 16, 163, 221, 193, 215, 214, 69, 82, 184, 6, 28, 5, 246, 209, 42, 22, 140, 105, 9, 28, 117, 88, 29, 97, 20, 2, 32, 14, 223, 55, 104, 157, 39, 134, 252, 105, 10, 249, 240, 246, 250, 31, 98, 156, 149, 105, 80, 57, 246, 72, 166, 212, 85, 72, 67, 2, 64, 46, 147
};

uint8_t r[32];
uint8_t s[32];

const bool success = bip66::decode(derEncodedSignature, 70, r, s);

Checking an Encoded Signature

From a DER-encoded signature:

const uint8_t derEncodedSignature[70] = {
    48, 68, 2, 32, 33, 112, 79, 42, 219, 46, 74, 16, 163, 221, 193, 215, 214, 69, 82, 184, 6, 28, 5, 246, 209, 42, 22, 140, 105, 9, 28, 117, 88, 29, 97, 20, 2, 32, 14, 223, 55, 104, 157, 39, 134, 252, 105, 10, 249, 240, 246, 250, 31, 98, 156, 149, 105, 80, 57, 246, 72, 166, 212, 85, 72, 67, 2, 64, 46, 147
};

const bool success = bip66::check(derEncodedSignature, 70);

License

MIT © Simon Downey

About

A simple Bitcoin BIP66 Implementation in C++ for the ARK Blockchain.

Resources

License

Stars

Watchers

Forks

Packages

No packages published