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 final class Taproot

  1. Object
  2. Taproot

Taproot (BIP-341) key tweaking and script trees.

A Taproot output commits to an internal key and, optionally, the Merkle root of a tree of scripts: Q = P + H_TapTweak(P || root) * G. A key-path spend signs with the tweaked private key; tweakPrivateKey gives it. BIP-86 wallets use no script tree.

Fields

public static final int LEAF_VERSION_TAPSCRIPT = 192The leaf version of a Tapscript leaf.

Methods

public static byte[] taggedHash(String tag, byte[] data)SHA256(SHA256(tag) || SHA256(tag) || data), BIP-340’s tagged hash.
public static byte[] tweak(byte[] internalKey32, byte[] merkleRoot)The tweak H_TapTweak(internalKey || merkleRoot); pass null for a key-only output.
public static byte[] outputKey(byte[] internalKey32, byte[] merkleRoot)The x-only output key of an internal key and an optional Merkle root.
public static byte[][] tweakPublicKey(byte[] internalKey32, byte[] merkleRoot)The output key and its parity: {x-only key, {0 or 1}}.
public static byte[] tweakPrivateKey(byte[] privateKey, byte[] merkleRoot)The private key that signs for outputKey on the key path.
public static byte[] internalKey(byte[] privateKey)The x-only internal key of a private key, as BIP-86 derives it.
public static byte[] leafHash(int leafVersion, Script script)The hash of a script leaf: H_TapLeaf(version || compactSize(len) || script).
public static byte[] branchHash(byte[] a, byte[] b)The hash of a branch: H_TapBranch of the two children in byte order.
public static Script outputScript(byte[] internalKey32, byte[] merkleRoot)The P2TR output script of an internal key and optional Merkle root.

Inherited methods

Field details

LEAF_VERSION_TAPSCRIPT

public static final int LEAF_VERSION_TAPSCRIPT = 192
The leaf version of a Tapscript leaf.

Method details

taggedHash

public static byte[] taggedHash(String tag, byte[] data)
SHA256(SHA256(tag) || SHA256(tag) || data), BIP-340’s tagged hash.

tweak

public static byte[] tweak(byte[] internalKey32, byte[] merkleRoot)
The tweak H_TapTweak(internalKey || merkleRoot); pass null for a key-only output.

outputKey

public static byte[] outputKey(byte[] internalKey32, byte[] merkleRoot)
The x-only output key of an internal key and an optional Merkle root.

tweakPublicKey

public static byte[][] tweakPublicKey(byte[] internalKey32, byte[] merkleRoot)
The output key and its parity: {x-only key, {0 or 1}}. The parity goes into the control block of a script-path spend.

tweakPrivateKey

public static byte[] tweakPrivateKey(byte[] privateKey, byte[] merkleRoot)
The private key that signs for outputKey on the key path.

internalKey

public static byte[] internalKey(byte[] privateKey)
The x-only internal key of a private key, as BIP-86 derives it.

leafHash

public static byte[] leafHash(int leafVersion, Script script)
The hash of a script leaf: H_TapLeaf(version || compactSize(len) || script).

branchHash

public static byte[] branchHash(byte[] a, byte[] b)
The hash of a branch: H_TapBranch of the two children in byte order.

outputScript

public static Script outputScript(byte[] internalKey32, byte[] merkleRoot)
The P2TR output script of an internal key and optional Merkle root.