Cómo crear una billetera sin conexión en Android solo para firmar la transacción

Soy nuevo en bitcoins, quiero crear una billetera fuera de línea en Android, escanear el código QR de la transacción desde la billetera de escritorio en línea, firmar esa transacción con clave privada en mi billetera fuera de línea.

1 Creación de billetera fuera de línea. 2. Firma de transacción fuera de línea con clave privada.

Quiero firmar la transacción y generar un código QR a partir de esa transacción de firma. Pero después de firmar, obtengo un sha256 de esta forma "MEQCIGBVDN/PkbESZdWkG6/KzrDRAEpDXVdsjKMzErBfFIWYAiA8JJOv97Dlp8Acg/L8JHI3RzoW eYNxPW1Lx4wQaORNNQ==", entonces, ¿qué haré con esto? Así que por favor ayuda y revisa mi código. ¿Está bien mi proceso de firma o, si no, por favor, proporcione algún código? Gracias.

Así que hice lo siguiente.

// Para crear billetera

vacío privado InitilizeWallet()

lanza IOException {

    BriefLogFormatter.init();

    params = TestNet3Params.get();

    filePrefix = "forwarding-service-testnet";

    walletAppKit = new WalletAppKit(params, getCacheDir(), filePrefix) {
        @Override
        protected void onSetupCompleted() {

           if (wallet().getKeyChainGroupSize() < 1)
                wallet().importKey(new ECKey());

            deterministicKey = wallet().getWatchingKey().dropPrivateBytes();
            deterministicKey = HDKeyDerivation.createMasterPubKeyFromBytes(deterministicKey.getPubKey(), deterministicKey.getChainCode());
            xPublicKey = deterministicKey.serializePubB58(params);    privateKey=wallet().getKeyByPath(DeterministicKeyChain.ACCOUNT_ZERO_PATH).getPrivateKeyAsWiF(params);
            Log.e("key", xPublicKey.toString());
            Log.e("privatekey", privateKey.toString());

        }
    };


    if (params == RegTestParams.get()) {
        // Regression test mode is designed for testing and development only, so there's no public network for it.
        // If you pick this mode, you're expected to be running a local "bitcoind -regtest" instance.
        walletAppKit.connectToLocalHost();
    }
    // Download the block chain and wait until it's done.


    walletAppKit.startAsync();
    walletAppKit.awaitRunning();

}

Y para firmar la transacción, hago lo siguiente.

public void Createtransictionhash(String destinatarioAddress, String cantidad) {

    try {

          // i am getting address and coins from QR code

        SendRequest request = SendRequest.to(Address.fromBase58(params, 
        recipientAddress), Coin.parseCoin(amount));
            Signingtrasaction(MainActivity.privateKey,request.tx.getHashAsString());

        Log.e("txhash", request.tx.getHashAsString());

    } catch (Exception e) {
        Log.e("msgError", e.getMessage().toString());
        Toast.makeText(getApplicationContext(), " Version code of address did not match", Toast.LENGTH_SHORT).show();

    }
}

public void Signingtrasaction(String wif, String msg) {
    try {


        // message (hash) to be signed with private key
        //String msg = "15953935a135031bfec37d36a9d662aea43e1deb0ea463d6932ac6e537cb3e81";
        //my hash = 09b14f746bd0a93b71907ba0070a103adbee7b1a260e053a21aa0b660ad8de57
        // an example of WiF for private key (taken from 'Mastering Bitcoin')
       // wif ="KxFC1jmwwCoACiCAWZ3eXa96mBM6tb3TYzGmf6YwgdGWZgawvrtJ";

        // creating a key object from WiF
        DumpedPrivateKey dpk = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dpk.getKey();

        // checking our key object
       // NetworkParameters main = MainNetParams.get();
        String check = key.getPrivateKeyAsWiF(params);
        System.out.println(wif.equals(check));  // true
        Log.e("wif check", String.valueOf(wif.equals(check)));
        // creating Sha object from string
        Sha256Hash hash = Sha256Hash.wrap(msg);

        // creating signature
        ECKey.ECDSASignature sig = key.sign(hash);

        // encoding
        byte[] res = sig.encodeToDER();

        // converting to hex
        //String hex = DatatypeConverter.printHexBinary(res);
        // String hex = new String(res);
        String hex = android.util.Base64.encodeToString(res, 16);

        Log.e("sigendTransiction", hex.toString());

        Log.e("decrypttx",""+ Hex.decode(sig.encodeToDER()));

    } catch (Exception e) {   //signingkey = ecdsa.from_string(privateKey.decode('hex'), curve=ecdsa.SECP256k1)
        Log.e("signing exception", e.getMessage().toString());
    }
}

Respuestas (1)

está haciendo todo mal desde el principio, no use WalletAppKit, use la clase Wallet simple, su billetera fuera de línea no está en línea, WalletAppKit necesita Internet para sincronizarse con la cadena de bloques

public void wallet()
{
    wallet = new Wallet(params);
    try
    {
        if(isDirCreated())
        {
            System.out.print("New Wallet");
            wallet.saveToFile(walletPath);
            System.out.println(wallet.currentReceiveAddress());
        }
        else
        {
            System.out.println("Load Wallet");
            // do something here
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}