Search in sources :

Example 1 with PaymentAddress

use of com.sparrowwallet.drongo.bip47.PaymentAddress in project drongo by sparrowwallet.

the class Keystore method getKey.

public ECKey getKey(WalletNode walletNode) throws MnemonicException {
    if (source == KeystoreSource.SW_PAYMENT_CODE) {
        try {
            if (walletNode.getKeyPurpose() != KeyPurpose.RECEIVE) {
                throw new IllegalArgumentException("Cannot get private key for non-receive chain");
            }
            PaymentAddress paymentAddress = getPaymentAddress(walletNode.getKeyPurpose(), walletNode.getIndex());
            return paymentAddress.getReceiveECKey();
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid payment code " + externalPaymentCode, e);
        } catch (Exception e) {
            log.error("Cannot get receive private key at index " + walletNode.getIndex() + " for payment code " + externalPaymentCode, e);
        }
    }
    ExtendedKey extendedPrivateKey = getExtendedPrivateKey();
    List<ChildNumber> derivation = new ArrayList<>();
    derivation.add(extendedPrivateKey.getKeyChildNumber());
    derivation.addAll(walletNode.getDerivation());
    return extendedPrivateKey.getKey(derivation);
}
Also used : ArrayList(java.util.ArrayList) PaymentAddress(com.sparrowwallet.drongo.bip47.PaymentAddress) ExtendedKey(com.sparrowwallet.drongo.ExtendedKey)

Example 2 with PaymentAddress

use of com.sparrowwallet.drongo.bip47.PaymentAddress in project drongo by sparrowwallet.

the class Keystore method getPubKey.

public ECKey getPubKey(WalletNode walletNode) {
    if (source == KeystoreSource.SW_PAYMENT_CODE) {
        try {
            PaymentAddress paymentAddress = getPaymentAddress(walletNode.getKeyPurpose(), walletNode.getIndex());
            return walletNode.getKeyPurpose() == KeyPurpose.RECEIVE ? ECKey.fromPublicOnly(paymentAddress.getReceiveECKey()) : paymentAddress.getSendECKey();
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Invalid payment code " + externalPaymentCode, e);
        } catch (Exception e) {
            log.error("Cannot get receive private key at index " + walletNode.getIndex() + " for payment code " + externalPaymentCode, e);
        }
    }
    List<ChildNumber> derivation = new ArrayList<>();
    derivation.add(extendedPublicKey.getKeyChildNumber());
    derivation.addAll(walletNode.getDerivation());
    return extendedPublicKey.getKey(derivation);
}
Also used : ArrayList(java.util.ArrayList) PaymentAddress(com.sparrowwallet.drongo.bip47.PaymentAddress)

Aggregations

PaymentAddress (com.sparrowwallet.drongo.bip47.PaymentAddress)2 ArrayList (java.util.ArrayList)2 ExtendedKey (com.sparrowwallet.drongo.ExtendedKey)1