Java Code Examples for net.bither.bitherj.crypto.hd.DeterministicKey#sign()

The following examples show how to use net.bither.bitherj.crypto.hd.DeterministicKey#sign() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HDMAddress.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password) {
    if (isInRecovery()) {
        throw new AssertionError("recovery hdm address can not sign");
    }
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
    }
    key.wipe();
    return sigs;
}
 
Example 2
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<byte[]> signWithCold(List<byte[]> unsignedHashes,
                                      CharSequence password,
                                      List<PathTypeIndex> pathTypeIndexList) {


    ArrayList<byte[]> sigs = new ArrayList<byte[]>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        PathTypeIndex pathTypeIndex = pathTypeIndexList.get(i);
        DeterministicKey key;
        if (pathTypeIndex.pathType == PathType.EXTERNAL_ROOT_PATH) {
            key = getExternalKey(pathTypeIndex.index, password);
            System.out.println("pub:" + Base58.encode(key.getPubKey()));
        } else {
            key = getInternalKey(pathTypeIndex.index, password);
        }
        ECKey.ECDSASignature signed = key.sign(unsignedHashes.get(i));
        sigs.add(signed.encodeToDER());
        key.wipe();
    }

    return sigs;
}
 
Example 3
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password,
                                                  List<PathTypeIndex> pathTypeIndexList) {


    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        PathTypeIndex pathTypeIndex = pathTypeIndexList.get(i);
        DeterministicKey key;
        if (pathTypeIndex.pathType == PathType.EXTERNAL_ROOT_PATH) {
            key = getExternalKey(pathTypeIndex.index, password);
        } else {
            key = getInternalKey(pathTypeIndex.index, password);
        }
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
        key.wipe();
    }

    return sigs;
}
 
Example 4
Source File: DesktopHDMAddress.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password) {
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
    }
    key.wipe();
    return sigs;
}
 
Example 5
Source File: SignTxDialg.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    dp = new DialogProgress();
    Thread thread = new Thread() {
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dp.pack();
                    dp.setVisible(true);
                }
            });
            List<String> strings = new ArrayList<String>();
            if (qrCodeTransport.getHdmIndex() >= 0) {
                if (!AddressManager.getInstance().hasHDMKeychain()) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                            new MessageDialog(LocaliserUtils.getString("hdm_send_with_cold_no_requested_seed"));

                        }
                    });
                    password.wipe();
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                        }
                    });
                    return;
                }
                try {
                    DeterministicKey key = AddressManager.getInstance().getHdmKeychain()
                            .getExternalKey(qrCodeTransport.getHdmIndex(), password);

                    List<String> hashes = qrCodeTransport.getHashList();
                    strings = new ArrayList<String>();
                    for (String hash : hashes) {
                        ECKey.ECDSASignature signed = key.sign(Utils.hexStringToByteArray
                                (hash));
                        strings.add(Utils.bytesToHexString(signed.encodeToDER()));
                    }
                    key.wipe();
                } catch (Exception e) {
                    e.printStackTrace();

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                            new MessageDialog(LocaliserUtils.getString("hdm_send_with_cold_no_requested_seed")).showMsg();
                        }
                    });
                    password.wipe();
                    return;
                }
            } else {
                Address address = WalletUtils.findPrivateKey(qrCodeTransport.getMyAddress());
                strings = address.signStrHashes(qrCodeTransport.getHashList(), password);
            }
            password.wipe();
            String result = "";
            for (int i = 0;
                 i < strings.size();
                 i++) {
                if (i < strings.size() - 1) {
                    result = result + strings.get(i) + QRCodeUtil.QR_CODE_SPLIT;
                } else {
                    result = result + strings.get(i);
                }
            }
            final String r = result;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dp.dispose();
                    dispose();
                    DisplayBitherQRCodePanel displayBitherQRCodePanle = new DisplayBitherQRCodePanel(r);
                    displayBitherQRCodePanle.showPanel();

                }
            });

        }

        ;
    };
    thread.start();

}
 
Example 6
Source File: SignTxDialg.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    dp = new DialogProgress();
    Thread thread = new Thread() {
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dp.pack();
                    dp.setVisible(true);
                }
            });
            List<String> strings = new ArrayList<String>();
            if (qrCodeTransport.getHdmIndex() >= 0) {
                if (!AddressManager.getInstance().hasHDMKeychain()) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                            new MessageDialog(LocaliserUtils.getString("hdm_send_with_cold_no_requested_seed"));

                        }
                    });
                    password.wipe();
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                        }
                    });
                    return;
                }
                try {
                    DeterministicKey key = AddressManager.getInstance().getHdmKeychain()
                            .getExternalKey(qrCodeTransport.getHdmIndex(), password);

                    List<String> hashes = qrCodeTransport.getHashList();
                    strings = new ArrayList<String>();
                    for (String hash : hashes) {
                        ECKey.ECDSASignature signed = key.sign(Utils.hexStringToByteArray
                                (hash));
                        strings.add(Utils.bytesToHexString(signed.encodeToDER()));
                    }
                    key.wipe();
                } catch (Exception e) {
                    e.printStackTrace();

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.dispose();
                            new MessageDialog(LocaliserUtils.getString("hdm_send_with_cold_no_requested_seed")).showMsg();
                        }
                    });
                    password.wipe();
                    return;
                }
            } else {
                Address address = WalletUtils.findPrivateKey(qrCodeTransport.getMyAddress());
                strings = address.signStrHashes(qrCodeTransport.getHashList(), password);
            }
            password.wipe();
            String result = "";
            for (int i = 0;
                 i < strings.size();
                 i++) {
                if (i < strings.size() - 1) {
                    result = result + strings.get(i) + QRCodeUtil.QR_CODE_SPLIT;
                } else {
                    result = result + strings.get(i);
                }
            }
            final String r = result;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dp.dispose();
                    dispose();
                    DisplayBitherQRCodePanel displayBitherQRCodePanle = new DisplayBitherQRCodePanel(r);
                    displayBitherQRCodePanle.showPanel();

                }
            });

        }

        ;
    };
    thread.start();

}