Skip to content

A Java library that can be used to create mnemonics for the Stellar Network (e.g. for your Android app)

License

Notifications You must be signed in to change notification settings

Soneso/stellar-java-mnemonic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages