Giter Site home page Giter Site logo

bip3x's Introduction

bip3x (with java bindings)

Bip39 mnemonic C++ implementation. Contains java bindings.

build status

Description

Logic almost completely taken from bitcoin-js library for generating mnemonic phrases. Site and github

Features

  • Generate random mnemonic (PCG generator)
  • Create root and extended bip* standard keys using derivation path
  • Get ETH-like address from private key (requires exactly private key, because it requires to get uncompressed public key)
  • Simple message signing with private key (verify method is not implemented yet)

Build native JNI libs

  • Install cmake (if not installed yet)
  • Install Oracle JDK or OpenJDK (not tested yet)
  • Set environment variable: JAVA_HOME=/path/to/jdk OR cmake prefix path like this: -DCMAKE_PREFIX_PATH="/Users/JohnDoe/.sdkman/candidates/java/17.0.6-amzn"
  • Build
mkdir build && cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release -Dbip3x_BUILD_SHARED_LIBS=On -Dbip3x_BUILD_JNI_BINDINGS=On -Dbip3x_BUILD_C_BINDINGS=Off -Dbip3x_BUILD_TESTS=Off

make -j 4
  • Pickup lib files:
    • libbip3x.[a | so | dylib]
    • libbip3x_jni.[so | dylib]

Cross-compile for Windows under mingw64

  • Setup mingw64 for linux or macOS
  • Setup Windows JDK (or just copy from windows machine to somewhere path)
  • IMPORTANT: using c++ (mt19937, and PCGRand not works properly too) random generator is not secure. Use -Dbip3x_USE_OPENSSL_RANDOM=On while configuring to use OpenSSL random generator.
  • Build
mkdir build && cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64.cmake \
-DCMAKE_SYSROOT=/path/to/mingw \
-DCROSS_ARCH=[choose i686 or x86_64] \
-DJAVA_HOME=/path/to/extracted/windows/jdk

make
  • Pickup lib files:
    • libbip3x.dll
    • libbip3x.dll.a
    • libbip3x_jni.dll
    • libbip3x_jni.dll.a

Examples

see exmaple.cpp file

Java

tbd

Android and java bindings (todo: separate android library with included java bindings)

  • Add this project as submodule (or just copy as sources) to your android module:
cd /path/to/project/app/src/main
mkdir cpp && cd cpp
git submodule add https://github.com/edwardstock/bip3x.git bip39
  • Create root cmake project in /path/to/project/[moduleName]/src/main/cpp
project(moduleName-cbip3x)
cmake_minimum_required(VERSION 3.24)
    
# include bip39
include_directories(bip39)
    
# add library
add_subdirectory(bip39)
android {
    ...
    sourceSets {
        main {
            jni.srcDirs = ['src/main/cpp/bip39/src/java']
            java.srcDirs = ['src/main/cpp/bip39/src/java']
        }
    }
    
    externalNativeBuild {
        cmake {
            path 'src/main/cpp/CMakeLists.txt'
        }
    }
    ...
}
  • Initialize it
import com.edwardstock.bip3x.BIP3X

class Main {
    public static int main(String[] args) {
        BIP3X.init();

        if (!BIP3X.isEnabled()) {
            throw new RuntimeException(BIP3X.getError());
        }
    }
}
  • Done!

Add to CMake project

  • Just add it
# include bip39
include_directories(bip39)
    
# add library
add_subdirectory(bip39)

and

target_link_libraries(bip39)
  • Done!

bip3x's People

Contributors

edwardstock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bip3x's Issues

Unable to create solution on VSC 2019

Hi there, and sorry beforehand if my problem happens to be basic!

I'm trying to clone this and have already tried following the steps mentioned in the readme, but here is some bump:

Using conan by running "conanfile.py" I get this in the process:

toolbox/3.2.3@edwardstock/latest: Not found in local cache, looking in remotes...
toolbox/3.2.3@edwardstock/latest: Trying with 'conancenter'...
ERROR: Failed requirement 'toolbox/3.2.3@edwardstock/latest' from 'conanfile.py (bip39/2.2.0)'
ERROR: Permission denied for user: 'None'. [Remote: conancenter]

And trying to directly use CMake will result in:

Error		CMake Error at modules/ConanBuild.cmake:370 (message):
  Conan install failed='1'		C:\Users\user0\Source\Repos\bip3x\modules/ConanBuild.cmake	370	

I'd be very happy if you could kindly point me at a direction, like if I should search anything specific on documentations maybe?

Thanks in advance!

Error when bip3x::HDKeyEncoder::makeExtendedKey

`
#include "bip3x/Bip39Mnemonic.h"
#include "bip3x/HDKeyEncoder.h"
#include

using namespace std;
using namespace bip3x;
using namespace toolbox;

int main(int argc, char **argv) {

cout << "start" << endl;

auto mnemonic = bip3x::Bip39Mnemonic::generate();
auto root = HDKeyEncoder::makeBip32RootKey(mnemonic.raw);

Derivation derivation("m’/44’/60’/0’/0");
bip3x::HDKeyEncoder::makeExtendedKey(root, derivation); //here<<<<<<<<<<<<<<<<

return 0;
}

`

utils.h row 34:
BIP39_CORE_API uint32_t str_to_uint32_t(std::string const& str, size_t* idx = 0, int base = 10); //idx = 0

utils.cpp row 17:
unsigned long result = std::stoul(str, idx, base); - here idx = NULL.
error: terminate called after throwing an instance of 'std::invalid_argument'
what(): stoul

about examples in readme.md

"ethereumKey.privateKey.toString()" - how did you do it?
toolbox installed, bot there is no such method (.toString()), the error pops up.
is it some third party library?

integration to conda environment

bip3x was added to the conda-forge package repository. Conda-forge provides pre-built packages that can be readily added to a given conda environment, maintaining self-consistency of packages within that environment
No actions are needed, at this time - If you wish to be added as a maintainer, just let me know
Thank you

can't install on windows (even w/ -DENABLE_CONAN=OFF)

The commands I'm running are:

git clone [email protected]:edwardstock/bip3x
cd bip3x
git submodule update --init --recursive
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_CONAN=OFF -DCMAKE_INSTALL_PREFIX="C:\Users\phild\projects\bipinst" 

and I'm getting

CMake Error at modules/ConanInit.cmake:1 (find_program):                                                                                                                      Could not find CONAN_BIN using the following names: conan 

as a result.

(This probably isn't helpful, but some additional info:
Just on a whim, I went in and commented out #find_program(CONAN_BIN conan REQUIRED) in modules\ConanInit.cmake, and now I'm getting an error that FindToolbox.cmake isn't found.)

build error, 2.2.0 release

windows

i unpack .zip of last release

when i do in console in bip3x-2.2.0 directory: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="C:\Users\Araba\Desktop\bip\inst"

CMake Error at modules/ConanInit.cmake:1 (find_program): Could not find CONAN_BIN using the following names: conan Call Stack (most recent call first): CMakeLists.txt:72 (include)

why?

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.