Search in sources :

Example 11 with ChildNumber

use of com.sparrowwallet.drongo.crypto.ChildNumber in project drongo by sparrowwallet.

the class KeyDerivation method writePath.

public static String writePath(List<ChildNumber> pathList, boolean useApostrophes) {
    StringBuilder path = new StringBuilder("m");
    for (ChildNumber child : pathList) {
        path.append("/");
        path.append(child.toString(useApostrophes));
    }
    return path.toString();
}
Also used : ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber)

Example 12 with ChildNumber

use of com.sparrowwallet.drongo.crypto.ChildNumber in project drongo by sparrowwallet.

the class KeyDerivation method parsePath.

public static List<ChildNumber> parsePath(String path, int wildcardReplacement) {
    List<ChildNumber> nodes = new ArrayList<>();
    if (path == null) {
        return nodes;
    }
    String[] parsedNodes = path.replace("M", "").replace("m", "").split("/");
    for (String n : parsedNodes) {
        n = n.replaceAll(" ", "");
        if (n.length() == 0)
            continue;
        boolean isHard = n.endsWith("H") || n.endsWith("h") || n.endsWith("'");
        if (isHard)
            n = n.substring(0, n.length() - 1);
        if (n.equals("*"))
            n = Integer.toString(wildcardReplacement);
        int nodeNumber = Integer.parseInt(n);
        nodes.add(new ChildNumber(nodeNumber, isHard));
    }
    return nodes;
}
Also used : ArrayList(java.util.ArrayList) ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber)

Example 13 with ChildNumber

use of com.sparrowwallet.drongo.crypto.ChildNumber in project drongo by sparrowwallet.

the class OutputDescriptor method getReceivingDerivation.

public List<ChildNumber> getReceivingDerivation(int wildCardReplacement) {
    if (isMultisig()) {
        List<ChildNumber> path = new ArrayList<>();
        path.add(new ChildNumber(0));
        path.add(new ChildNumber(wildCardReplacement));
        return path;
    }
    return getReceivingDerivation(getSingletonExtendedPublicKey(), wildCardReplacement);
}
Also used : ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber)

Example 14 with ChildNumber

use of com.sparrowwallet.drongo.crypto.ChildNumber in project drongo by sparrowwallet.

the class PaymentCode method getPaymentCode.

public static PaymentCode getPaymentCode(Transaction transaction, Keystore keystore) throws InvalidPaymentCodeException {
    try {
        TransactionInput txInput = getDesignatedInput(transaction);
        ECKey pubKey = getDesignatedPubKey(txInput);
        List<ChildNumber> derivation = keystore.getKeyDerivation().getDerivation();
        ChildNumber derivationStart = derivation.isEmpty() ? ChildNumber.ZERO_HARDENED : derivation.get(derivation.size() - 1);
        ECKey notificationPrivKey = keystore.getBip47ExtendedPrivateKey().getKey(List.of(derivationStart, new ChildNumber(0)));
        SecretPoint secretPoint = new SecretPoint(notificationPrivKey.getPrivKeyBytes(), pubKey.getPubKey());
        byte[] blindingMask = getMask(secretPoint.ECDHSecretAsBytes(), txInput.getOutpoint().bitcoinSerialize());
        byte[] blindedPaymentCode = getOpReturnData(transaction);
        return new PaymentCode(PaymentCode.blind(blindedPaymentCode, blindingMask));
    } catch (Exception e) {
        throw new InvalidPaymentCodeException("Could not determine payment code from transaction", e);
    }
}
Also used : ECKey(com.sparrowwallet.drongo.crypto.ECKey) ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber) BufferUnderflowException(java.nio.BufferUnderflowException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 15 with ChildNumber

use of com.sparrowwallet.drongo.crypto.ChildNumber 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());
}
Also used : ECKey(com.sparrowwallet.drongo.crypto.ECKey) ChildNumber(com.sparrowwallet.drongo.crypto.ChildNumber) DeterministicKey(com.sparrowwallet.drongo.crypto.DeterministicKey) Test(org.junit.Test)

Aggregations

ChildNumber (com.sparrowwallet.drongo.crypto.ChildNumber)17 ECKey (com.sparrowwallet.drongo.crypto.ECKey)4 Test (org.junit.Test)4 DeterministicKey (com.sparrowwallet.drongo.crypto.DeterministicKey)3 ArrayList (java.util.ArrayList)3 Wallet (com.sparrowwallet.drongo.wallet.Wallet)2 Insets (javafx.geometry.Insets)2 HBox (javafx.scene.layout.HBox)2 ValidationSupport (org.controlsfx.validation.ValidationSupport)2 StyleClassValidationDecoration (org.controlsfx.validation.decoration.StyleClassValidationDecoration)2 ExtendedKey (com.sparrowwallet.drongo.ExtendedKey)1 KeyDerivation (com.sparrowwallet.drongo.KeyDerivation)1 Address (com.sparrowwallet.drongo.address.Address)1 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)1 Keystore (com.sparrowwallet.drongo.wallet.Keystore)1 MnemonicException (com.sparrowwallet.drongo.wallet.MnemonicException)1 WalletImportEvent (com.sparrowwallet.sparrow.event.WalletImportEvent)1 ImportException (com.sparrowwallet.sparrow.io.ImportException)1 ElectrumServer (com.sparrowwallet.sparrow.net.ElectrumServer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1