use of com.sparrowwallet.drongo.crypto.DeterministicKey in project drongo by sparrowwallet.
the class Wallet method addChildWallet.
public Wallet addChildWallet(PaymentCode externalPaymentCode, ScriptType childScriptType, String label) {
if (policyType != PolicyType.SINGLE) {
throw new IllegalStateException("Cannot add payment code wallet to " + policyType.getName() + " wallet");
}
if (scriptType != P2PKH && scriptType != P2SH_P2WPKH && scriptType != P2WPKH) {
throw new IllegalStateException("Cannot add payment code wallet to " + scriptType.getName() + " wallet");
}
Keystore masterKeystore = getKeystores().get(0);
if (masterKeystore.getBip47ExtendedPrivateKey() == null) {
throw new IllegalStateException("Cannot add payment code wallet, BIP47 extended private key not present");
}
Wallet childWallet = new Wallet(childScriptType + "-" + externalPaymentCode.toString());
childWallet.setLabel(label);
childWallet.setPolicyType(PolicyType.SINGLE);
childWallet.setScriptType(childScriptType);
childWallet.setGapLimit(5);
Keystore keystore = new Keystore("BIP47");
keystore.setSource(KeystoreSource.SW_PAYMENT_CODE);
keystore.setWalletModel(WalletModel.SPARROW);
List<ChildNumber> derivation = KeyDerivation.getBip47Derivation(getAccountIndex());
keystore.setKeyDerivation(new KeyDerivation(masterKeystore.getKeyDerivation().getMasterFingerprint(), derivation));
keystore.setExternalPaymentCode(externalPaymentCode);
keystore.setBip47ExtendedPrivateKey(masterKeystore.getBip47ExtendedPrivateKey());
DeterministicKey pubKey = keystore.getBip47ExtendedPrivateKey().getKey().dropPrivateBytes().dropParent();
keystore.setExtendedPublicKey(new ExtendedKey(pubKey, keystore.getBip47ExtendedPrivateKey().getParentFingerprint(), derivation.get(derivation.size() - 1)));
childWallet.getKeystores().add(keystore);
childWallet.setDefaultPolicy(Policy.getPolicy(PolicyType.SINGLE, scriptType, childWallet.getKeystores(), 1));
childWallet.setMasterWallet(this);
getChildWallets().add(childWallet);
return childWallet;
}
use of com.sparrowwallet.drongo.crypto.DeterministicKey in project drongo by sparrowwallet.
the class PaymentCodeTest method testPaymentAddress.
@Test
public void testPaymentAddress() throws MnemonicException, InvalidPaymentCodeException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, NoSuchProviderException, NotSecp256k1Exception {
DeterministicSeed seed = new DeterministicSeed("response seminar brave tip suit recall often sound stick owner lottery motion", "", 0, DeterministicSeed.Type.BIP39);
Keystore keystore = Keystore.fromSeed(seed, List.of(new ChildNumber(47, true), ChildNumber.ZERO_HARDENED, ChildNumber.ZERO_HARDENED));
DeterministicKey privateKey = keystore.getExtendedPrivateKey().getKey(List.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO));
PaymentCode paymentCodeBob = new PaymentCode("PM8TJS2JxQ5ztXUpBBRnpTbcUXbUHy2T1abfrb3KkAAtMEGNbey4oumH7Hc578WgQJhPjBxteQ5GHHToTYHE3A1w6p7tU6KSoFmWBVbFGjKPisZDbP97");
PaymentAddress paymentAddress0 = new PaymentAddress(paymentCodeBob, 0, privateKey.getPrivKeyBytes());
ECKey sendKey0 = paymentAddress0.getSendECKey();
Assert.assertEquals("141fi7TY3h936vRUKh1qfUZr8rSBuYbVBK", ScriptType.P2PKH.getAddress(sendKey0).toString());
PaymentAddress paymentAddress1 = new PaymentAddress(paymentCodeBob, 1, privateKey.getPrivKeyBytes());
ECKey sendKey1 = paymentAddress1.getSendECKey();
Assert.assertEquals("12u3Uued2fuko2nY4SoSFGCoGLCBUGPkk6", ScriptType.P2PKH.getAddress(sendKey1).toString());
}
use of com.sparrowwallet.drongo.crypto.DeterministicKey in project drongo by sparrowwallet.
the class PaymentCodeTest method testFromSeed.
@Test
public void testFromSeed() throws MnemonicException {
DeterministicSeed aliceSeed = new DeterministicSeed("response seminar brave tip suit recall often sound stick owner lottery motion", "", 0, DeterministicSeed.Type.BIP39);
Keystore aliceKeystore = Keystore.fromSeed(aliceSeed, List.of(new ChildNumber(47, true), ChildNumber.ZERO_HARDENED, ChildNumber.ZERO_HARDENED));
DeterministicKey bip47PubKey = aliceKeystore.getExtendedPublicKey().getKey();
PaymentCode alicePaymentCode = new PaymentCode(bip47PubKey.getPubKey(), bip47PubKey.getChainCode());
Assert.assertEquals("PM8TJTLJbPRGxSbc8EJi42Wrr6QbNSaSSVJ5Y3E4pbCYiTHUskHg13935Ubb7q8tx9GVbh2UuRnBc3WSyJHhUrw8KhprKnn9eDznYGieTzFcwQRya4GA", alicePaymentCode.toString());
}
Aggregations