@Test public void privateChild() { Mnemonic mnemonic = Mnemonic.fromString(TEST_MNEMONIC); Seed seed = new Seed(mnemonic, "LIBRA"); LibraKeyFactory libraKeyFactory = new LibraKeyFactory(seed); ExtendedPrivKey childPrivate0 = libraKeyFactory.privateChild(new ChildNumber(0)); assertEquals( "3051020101300506032b657004220420358a375f36d74c30b7f3299b62d712b307725938f8cc931100fbd10a434fc8b9812100b1894672e853ee6d2f1c094b0db2c2644edd4736f46c4357c709fdded5797c44", Hex.toHexString(childPrivate0.privateKey.getEncoded())); ExtendedPrivKey childPrivate0_again = libraKeyFactory.privateChild(new ChildNumber(0)); assertEquals( Hex.toHexString(childPrivate0.privateKey.getEncoded()), Hex.toHexString(childPrivate0_again.privateKey.getEncoded())); ExtendedPrivKey childPrivate1 = libraKeyFactory.privateChild(new ChildNumber(1)); assertEquals( "3051020101300506032b657004220420a325fe7d27b1b49f191cc03525951fec41b6ffa2d4b3007bb1d9dd353b7e56a6812100c66551332920eda683a977292305ef6c10c34b27d9fef331bbd851f5c74d09ee", Hex.toHexString(childPrivate1.privateKey.getEncoded())); ChildNumber child1Again = new ChildNumber(0).increment(); assertEquals(new ChildNumber(1).data, child1Again.data); ExtendedPrivKey childPrivate1FromIncrement = libraKeyFactory.privateChild(child1Again); assertEquals( "3051020101300506032b657004220420a325fe7d27b1b49f191cc03525951fec41b6ffa2d4b3007bb1d9dd353b7e56a6812100c66551332920eda683a977292305ef6c10c34b27d9fef331bbd851f5c74d09ee", Hex.toHexString(childPrivate1FromIncrement.privateKey.getEncoded())); }
public ExtendedPrivKey privateChild(ChildNumber childNumber) { byte[] secretKey = new byte[32]; byte[] info = createInfo(childNumber); SHA3Digest sha3 = new SHA3Digest(256); HKDFBytesGenerator hkdf = new HKDFBytesGenerator(sha3); hkdf.init(HKDFParameters.skipExtractParameters(master.getData(), info)); hkdf.generateBytes(secretKey, 0, 32); return new ExtendedPrivKey(new SecretKey(ByteArray.from(secretKey))); }
LibraKeyFactory { public ExtendedPrivKey privateChild(ChildNumber childNumber) { byte[] secretKey = new byte[32]; byte[] info = createInfo(childNumber); SHA3Digest sha3 = new SHA3Digest(256); HKDFBytesGenerator hkdf = new HKDFBytesGenerator(sha3); hkdf.init(HKDFParameters.skipExtractParameters(master.getData(), info)); hkdf.generateBytes(secretKey, 0, 32); return new ExtendedPrivKey(new SecretKey(ByteArray.from(secretKey))); } }
LibraKeyFactory { public ExtendedPrivKey privateChild(ChildNumber childNumber) { byte[] secretKey = new byte[32]; byte[] info = createInfo(childNumber); SHA3Digest sha3 = new SHA3Digest(256); HKDFBytesGenerator hkdf = new HKDFBytesGenerator(sha3); hkdf.init(HKDFParameters.skipExtractParameters(master.getData(), info)); hkdf.generateBytes(secretKey, 0, 32); return new ExtendedPrivKey(new SecretKey(ByteArray.from(secretKey))); } LibraKeyFactory(Seed seed); }
LibraKeyFactory { public ExtendedPrivKey privateChild(ChildNumber childNumber) { byte[] secretKey = new byte[32]; byte[] info = createInfo(childNumber); SHA3Digest sha3 = new SHA3Digest(256); HKDFBytesGenerator hkdf = new HKDFBytesGenerator(sha3); hkdf.init(HKDFParameters.skipExtractParameters(master.getData(), info)); hkdf.generateBytes(secretKey, 0, 32); return new ExtendedPrivKey(new SecretKey(ByteArray.from(secretKey))); } LibraKeyFactory(Seed seed); Master getMaster(); ExtendedPrivKey privateChild(ChildNumber childNumber); }
LibraKeyFactory { public ExtendedPrivKey privateChild(ChildNumber childNumber) { byte[] secretKey = new byte[32]; byte[] info = createInfo(childNumber); SHA3Digest sha3 = new SHA3Digest(256); HKDFBytesGenerator hkdf = new HKDFBytesGenerator(sha3); hkdf.init(HKDFParameters.skipExtractParameters(master.getData(), info)); hkdf.generateBytes(secretKey, 0, 32); return new ExtendedPrivKey(new SecretKey(ByteArray.from(secretKey))); } LibraKeyFactory(Seed seed); Master getMaster(); ExtendedPrivKey privateChild(ChildNumber childNumber);  }