The Soneso open source Java library to create mnemonics for the Stellar Network.
See Key Derivation Methods for Stellar Accounts
Add the current jar file from the distribution folder to your Java/Android Project.
Copy and attach source code to your project.
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.
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.
java-stellar-mnemonic is licensed under an Apache-2.0 license. See the LICENSE file for details.
Send lumens to: GANSYJ64BTHYFM6BAJEWXYLVSZVSHYZFPW4DIQDWJL5BOT6O6GUE7JM5