Coder Social home page Coder Social logo

bip66's Introduction

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

bip66's People

Contributors

per1234 avatar sleepdefic1t avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ciband

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.