Java Code Examples for net.bither.bitherj.utils.Base58#hexToBase58WithAddress()

The following examples show how to use net.bither.bitherj.utils.Base58#hexToBase58WithAddress() . These examples are extracted from open source projects. 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 Project: bitherj   File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport noChangeFormatDesktopHDMQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        if (Utils.validBicoinAddress(strArray[0])) {
            return oldFormatQRCodeTransport(str);
        }
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
        String address = Base58.hexToBase58WithAddress(strArray[0]);

        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        qrCodeTransport.setFee(Long.parseLong(strArray[1], 16));
        qrCodeTransport.setToAddress(Base58.hexToBase58WithAddress(strArray[2]));
        qrCodeTransport.setTo(Long.parseLong(strArray[3], 16));
        List<String> hashList = new ArrayList<String>();
        List<AbstractHD.PathTypeIndex> pathTypeIndexList = new ArrayList<AbstractHD.PathTypeIndex>();
        for (int i = 4;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                String[] hashPathTypeIndex = text.split(QRCodeUtil.QR_CODE_SECONDARY_SPLIT_ESCAPE);
                AbstractHD.PathTypeIndex pathTypeIndex = new AbstractHD.PathTypeIndex();
                pathTypeIndex.pathType = AbstractHD.getTernalRootType(Integer.valueOf(hashPathTypeIndex[0]));
                pathTypeIndex.index = Integer.valueOf(hashPathTypeIndex[1]);
                pathTypeIndexList.add(pathTypeIndex);
                hashList.add(hashPathTypeIndex[2]);
            }
        }
        qrCodeTransport.setHashList(hashList);
        qrCodeTransport.setPathTypeIndexes(pathTypeIndexList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 2
Source Project: bitherj   File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport changeFormatQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();

        String address = Base58.hexToBase58WithAddress(strArray[0]);
        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        String changeAddress = Base58.hexToBase58WithAddress(strArray[1]);
        if (!Utils.validBicoinAddress(changeAddress)) {
            return null;
        }
        qrCodeTransport.setChangeAddress(changeAddress);
        qrCodeTransport.setChangeAmt(Long.parseLong(strArray[2], 16));
        qrCodeTransport.setFee(Long.parseLong(strArray[3], 16));
        String toAddress = Base58.hexToBase58WithAddress(strArray[4]);
        if (!Utils.validBicoinAddress(toAddress)) {
            return null;
        }
        qrCodeTransport.setToAddress(toAddress);
        qrCodeTransport.setTo(Long.parseLong(strArray[5], 16));
        List<String> hashList = new ArrayList<String>();
        for (int i = 6;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                hashList.add(text);
            }
        }
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 3
Source Project: bitherj   File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
private static QRCodeTxTransport noChangeFormatQRCodeTransport(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        if (Utils.validBicoinAddress(strArray[0])) {
            return oldFormatQRCodeTransport(str);
        }
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();
        String address = Base58.hexToBase58WithAddress(strArray[0]);

        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        qrCodeTransport.setFee(Long.parseLong(strArray[1], 16));
        qrCodeTransport.setToAddress(Base58.hexToBase58WithAddress(strArray[2]));
        qrCodeTransport.setTo(Long.parseLong(strArray[3], 16));
        List<String> hashList = new ArrayList<String>();
        for (int i = 4;
             i < strArray.length;
             i++) {
            String text = strArray[i];
            if (!Utils.isEmpty(text)) {
                hashList.add(text);
            }
        }
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 4
Source Project: bitherj   File: QRCodeTxTransport.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isAddressHex(String str) {
    boolean isAddress = false;
    if (str.length() % 2 == 0) {
        try {
            String address = Base58.hexToBase58WithAddress(str);
            isAddress = Utils.validBicoinAddress(address);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return isAddress;
}
 
Example 5
Source Project: bitherj   File: DesktopHDMKeychain.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean checkPassword(String keysString, CharSequence password) throws
        MnemonicException.MnemonicLengthException {
    String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString);
    String address = Base58.hexToBase58WithAddress(passwordSeeds[0]);
    String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2],
            passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT);
    byte[] seed = new EncryptedData(encreyptString).decrypt(password);
    MnemonicCode mnemonic = MnemonicCode.instance();

    byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), "");

    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s);

    DeterministicKey purpose = master.deriveHardened(44);

    DeterministicKey coinType = purpose.deriveHardened(0);

    DeterministicKey account = coinType.deriveHardened(0);

    DeterministicKey external = account.deriveSoftened(0);

    external.clearPrivateKey();

    DeterministicKey key = external.deriveSoftened(0);
    boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash()));
    key.wipe();

    return result;
}
 
Example 6
Source Project: bitherj   File: HDMKeychain.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean checkPassword(String keysString, CharSequence password) throws
        MnemonicException.MnemonicLengthException {
    String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString);
    String address = Base58.hexToBase58WithAddress(passwordSeeds[0]);
    String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2],
            passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT);
    byte[] seed = new EncryptedData(encreyptString).decrypt(password);
    MnemonicCode mnemonic = MnemonicCode.instance();

    byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), "");

    DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s);

    DeterministicKey purpose = master.deriveHardened(44);

    DeterministicKey coinType = purpose.deriveHardened(0);

    DeterministicKey account = coinType.deriveHardened(0);

    DeterministicKey external = account.deriveSoftened(0);

    external.clearPrivateKey();

    DeterministicKey key = external.deriveSoftened(0);
    boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash()));
    key.wipe();

    return result;
}
 
Example 7
Source Project: bitherj   File: QRCodeTxTransport.java    License: Apache License 2.0 4 votes vote down vote up
private static QRCodeTxTransport changeFormatQRCodeTransportOfDesktopHDM(String str) {
    try {
        String[] strArray = QRCodeUtil.splitString(str);
        QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport();

        String address = Base58.hexToBase58WithAddress(strArray[0]);
        if (!Utils.validBicoinAddress(address)) {
            return null;
        }
        qrCodeTransport.setMyAddress(address);
        String changeAddress = Base58.hexToBase58WithAddress(strArray[1]);
        if (!Utils.validBicoinAddress(changeAddress)) {
            return null;
        }
        qrCodeTransport.setChangeAddress(changeAddress);
        qrCodeTransport.setChangeAmt(Long.parseLong(strArray[2], 16));
        qrCodeTransport.setFee(Long.parseLong(strArray[3], 16));
        String toAddress = Base58.hexToBase58WithAddress(strArray[4]);
        if (!Utils.validBicoinAddress(toAddress)) {
            return null;
        }
        qrCodeTransport.setToAddress(toAddress);
        qrCodeTransport.setTo(Long.parseLong(strArray[5], 16));
        List<AbstractHD.PathTypeIndex> pathTypeIndexList = new ArrayList<AbstractHD.PathTypeIndex>();
        List<String> hashList = new ArrayList<String>();
        for (int i = 6;
             i < strArray.length;
             i++) {
            String text = strArray[i];

            if (!Utils.isEmpty(text)) {
                String[] hashPathTypeIndex = text.split(QRCodeUtil.QR_CODE_SECONDARY_SPLIT_ESCAPE);
                AbstractHD.PathTypeIndex pathTypeIndex = new AbstractHD.PathTypeIndex();
                pathTypeIndex.pathType = AbstractHD.getTernalRootType(Integer.valueOf(hashPathTypeIndex[0]));
                pathTypeIndex.index = Integer.valueOf(hashPathTypeIndex[1]);
                pathTypeIndexList.add(pathTypeIndex);
                hashList.add(hashPathTypeIndex[2]);
            }
        }
        qrCodeTransport.setPathTypeIndexes(pathTypeIndexList);
        qrCodeTransport.setHashList(hashList);
        return qrCodeTransport;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}