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();
}
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;
}
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);
}
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);
}
}
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());
}
Aggregations