Creating a segwit address and private key with bitcoin (paper wallet)

You can create a valid pair of old bitcoins with the following code that uses the bitcoinj master branch :

import org.bitcoinj.core.Address;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;

public class GeneratePrivateKeyBulk {

    public static void main(String[] args) {
        ECKey key = new ECKey();
        Address pubAddress = new Address(NetworkParameters.prodNet(), key.getPubKeyHash());
        DumpedPrivateKey privKey = key.getPrivateKeyEncoded(NetworkParameters.prodNet());
        System.out.println("Public address: " + pubAddress.toBase58() + "; Private key: " + privKey.toBase58());
    }
}

This creates a useful legacy base58 public address and private key, for example. for example 1ERzRYYdbibaQt2kuNfgH8spuoqQxYkwQb, L3AuZ2vNt11ac2xSi6AYwzXyftqSVPcSuHNdTsSuRfknXvoRtWzFrespectively.

The question is, how can I perform the same operation to get a segwit key pair ?

I looked at bitcoinj docs , but could not find the API for generating addresses directly as segwit.

segwit , ( ) segwit (.. , 3, 31uLnxKteEYa2u1vgWyVPkTpVfUGduCV82)

Script script = ScriptBuilder.createP2SHOutputScript(1, Collections.singletonList(key));
Address segwitAddress = Address.fromP2SHScript(NetworkParameters.prodNet(), script);
System.out.println("Segwit address: " + segwitAddress.toBase58());

, , , segwit . // ?

, BIP38 bitcoinj? BIP38PrivateKey BIP38 base58, BIP38.

+4

Source: https://habr.com/ru/post/1692436/


All Articles