Giter Club home page Giter Club logo

stellar-java-mnemonic's Introduction

stellar-java-mnemonic

The Soneso open source Java library to create mnemonics for the Stellar Network.

See Key Derivation Methods for Stellar Accounts

Installation

Jar file

Add the current jar file from the distribution folder to your Java/Android Project.

Source code

Copy and attach source code to your project.

Dependencies

The library needs the Stellar Java SDK

If you add the library to a project running Java 1.7 or lower, then you need Bouncy Castle as well, because some of the security algorithms used within the library are supported starting with Java 1.8 only. After adding that dependency, add the following lines of code at your project entry point.

Security.removeProvider("BC");
Security.insertProviderAt(new BouncyCastleProvider(), 1);

In that way you are adding Bouncy Castle as the main provider for security algorthms.

Quick Start

Deterministic generation

Generate mnemonic

char[] mnemonic = Wallet.generate24WordMnemonic();
String[] words = String.valueOf(mnemonic).split(" ");
// bench hurt jump file august wise shallow faculty impulse spring exact slush thunder author capable act festival slice deposit sauce coconut afford frown better

Generate key pairs

char[] mnemonic = "bench hurt jump file august wise shallow faculty impulse spring exact slush thunder author capable act festival slice deposit sauce coconut afford frown better".toCharArray();
KeyPair keyPair0 = Wallet.createKeyPair(mnemonic, null, 0);
KeyPair keyPair1 = Wallet.createKeyPair(mnemonic, null, 1);

Generate key pairs with passphrase

char[] mnemonic = "cable spray genius state float twenty onion head street palace net private method loan turn phrase state blanket interest dry amazing dress blast tube".toCharArray();
char[] passphrase = "p4ssphr4se".toCharArray();
KeyPair keyPair0 = Wallet.createKeyPair(mnemonic, passphrase, 0);

BIP and master key generation

char[] mnemonic = "bench hurt jump file august wise shallow faculty impulse spring exact slush thunder author capable act festival slice deposit sauce coconut afford frown better".toCharArray();
byte[] bip39Seed = Mnemonic.createSeed(mnemonic, null);

Ed25519Derivation masterPrivateKey = Ed25519Derivation.fromSecretSeed(bip39Seed);
Ed25519Derivation purpose = masterPrivateKey.derived(44);
Ed25519Derivation coinType = purpose.derived(148);

Ed25519Derivation account0 = coinType.derived(0);
KeyPair keyPair0 = KeyPair.fromSecretSeed(account0.getPrivateKey());

Ed25519Derivation account4 = coinType.derived(4);
KeyPair keyPair4 = KeyPair.fromSecretSeed(account4.getPrivateKey());

Please also see test classes for more examples.

License

java-stellar-mnemonic is licensed under an Apache-2.0 license. See the LICENSE file for details.

Donations

Send lumens to: GANSYJ64BTHYFM6BAJEWXYLVSZVSHYZFPW4DIQDWJL5BOT6O6GUE7JM5

stellar-java-mnemonic's People

Contributors

christian-rogobete avatar cristipaval avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

stellar-java-mnemonic's Issues

Firebase SDK https requests on Android Pie stop working at some point

Hi everyone. We use your library in our product which is Wallet based on Stellar network and I faced an issue working with Firebase SDK.

These lines cause problems on Android P in our case:

Security.removeProvider("BC");
Security.insertProviderAt(new BouncyCastleProvider(), 1);

Https requests get stuck when Firebase API updates certificates or something.
I cannot have control over requests inside of Firebase SDK. And this bug happens at some point after use of app & all Firebase requests not working after this point.

This is the exception I get from Firebase when this issue appears:

error sending network request POST https://firebasestorage.googleapis.com
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: AndroidOpenSSL, class: com.android.org.conscrypt.DefaultSSLContextImpl)
at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:284)
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:306)
at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:181)
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)

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.