https://github.com/bitsofproof/supernode/blob/master/api/src/main/java/com/bitsofproof/supernode/wallet/BIP39.java
Added Shamir's secret shares algorithm
https://github.com/bitsofproof/supernode/blob/master/api/src/main/java/com/bitsofproof/supernode/wallet/ShamirsSecretSharing.java
You can create a random word list e.g.:
Code:
SecureRandom random = new SecureRandom ();
byte[] seed = new byte[16];
random.nextBytes (seed);
System.out.println (BIP39.encode (seed, ""));
// assume it prints:
// mind evil language crouch legal brave insane bid speed notice material scheme
You may now create a BIP32 master out of a word list as e.g.
Code:
String mnemonic = "mind evil language crouch legal brave insane bid speed notice material scheme";
ExtendedKey key = ExtendedKey.create (BIP39.decode (mnemonic, ""));
System.out.println (key.serialize (true));
// prints: xprv9s21ZrQH143K2uwgrphL7P5ePDPBp8ukjVT3CspHyvdHigHY9DAYQX6D6dkBThQCgmJskkzTbHFy6ZGvz3Vm8GzkGuDAWmvqsKrityeTW5W
Instead of storing the secret word list you could create 3 backups of which 2 is needed to recreate the list (and one is useless alone).
Code:
List<String> backups = ShamirsSecretSharing.issueMnemonicShares (BIP39.decode (mnemonic, ""), 3, 2, "");
for ( String b : backups )
{
System.out.println (b);
}
// prints:
// find worry owner drill category cancel error stock inspire place bullet blind wood course spend gather response fat
// huge bulk human envelope theory van cricket cattle reopen divorce alley upper pig afford spy mass design reduce
// noodle predict ancient tuition still result garbage melt wise angle island peace rate cereal outside actual more lock
Now take any two of the three to reconstruct the key:
Code:
List<String> pick = new ArrayList<> ();
pick.add (backups.get (0));
pick.add (backups.get (2));
ExtendedKey recreated = ExtendedKey.create (ShamirsSecretSharing.reconstructFromMnemonicShares (pick, ""));
System.out.println (recreated.serialize (true));
// prints again:
// prints: xprv9s21ZrQH143K2uwgrphL7P5ePDPBp8ukjVT3CspHyvdHigHY9DAYQX6D6dkBThQCgmJskkzTbHFy6ZGvz3Vm8GzkGuDAWmvqsKrityeTW5W
Use the passphrase option (the "" in parameters) to get plausible deniability of the wallet, since you may fund more than one passphrase.