A simple Bitcoin BIP66 Implementation in C++ for the ARK Ecosystem.
ANS.1 DER Encoder/Decoder based on Bitcoin BIP66.
OS: | Supported: |
---|---|
Linux | ✅ |
macOS | ✅ |
Windows | ✅ |
Environment: | Supported: |
---|---|
Arduino IDE | ✅ |
PlatformIO | ✅ |
Board: | Supported: |
---|---|
ESP8266 | ✅ |
ESP32 | ✅ |
ESP32-S2 | ✅ |
Download BIP66 from the Arduino IDE Library manager.
You can also copy this repo to the Arduino Libraries directory.
(e.g. ~/Documents/Arduino/libraries
)
- Open the
BIP66.ino
sketch in theexamples/BIP66
folder. - Select your board from the Arduino IDE
- Upload the sketch.
pio run
pio run -t test/
pio run -t test/ -e esp32 -t upload
Operating System builds like Linux, macOS, and Windows use CMake.
This build should be done out of source.
mkdir build && cd build
cmake ..
cmake --build .
mkdir build && cd build
cmake -DUNIT_TEST=ON ..
cmake --build .
./test/bip66_tests
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);
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);
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);