Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public abstract class BitcoinKey

  1. Object
  2. BitcoinKey
A secp256k1 key that signs Bitcoin inputs without necessarily exposing its private key. Psbt.sign(int, BitcoinKey) takes one, so an input can be signed by a key held in memory (fromPrivateKey), by a wallet that derives it per signature, or by a hardware device or key service that implements the two signing methods.

Constructors

public BitcoinKey()

Methods

public abstract byte[] getPublicKey()The compressed 33-byte public key.
public abstract Secp256k1.EcdsaSignature signEcdsa(byte[] sighash)An ECDSA signature over a 32-byte sighash, RFC 6979 deterministic and low-S.
public abstract byte[] signTaproot(byte[] sighash, byte[] merkleRoot)A BIP-340 signature over a 32-byte Taproot sighash, made with the key tweaked by BIP-341 for merkleRoot (null for a key-path-only output, as BIP-86 derives).
public byte[] getUncompressedPublicKey()The uncompressed 65-byte public key, which some legacy outputs pay to.
public byte[] getInternalKey()The 32-byte x-only Taproot internal key.
public void destroy()Wipes any key material the instance holds.
public static BitcoinKey fromPrivateKey(byte[] privateKey)A key over a 32-byte private key, which is copied; destroy wipes the copy.

Inherited methods

Constructor details

BitcoinKey

public BitcoinKey()

Method details

getPublicKey

public abstract byte[] getPublicKey()
The compressed 33-byte public key.

signEcdsa

public abstract Secp256k1.EcdsaSignature signEcdsa(byte[] sighash)
An ECDSA signature over a 32-byte sighash, RFC 6979 deterministic and low-S.

signTaproot

public abstract byte[] signTaproot(byte[] sighash, byte[] merkleRoot)
A BIP-340 signature over a 32-byte Taproot sighash, made with the key tweaked by BIP-341 for merkleRoot (null for a key-path-only output, as BIP-86 derives).

getUncompressedPublicKey

public byte[] getUncompressedPublicKey()
The uncompressed 65-byte public key, which some legacy outputs pay to.

getInternalKey

public byte[] getInternalKey()
The 32-byte x-only Taproot internal key.

destroy

public void destroy()
Wipes any key material the instance holds. The default holds none.

fromPrivateKey

public static BitcoinKey fromPrivateKey(byte[] privateKey)
A key over a 32-byte private key, which is copied; destroy wipes the copy.

Throws

IllegalArgumentException
if the bytes are not a valid private key