Class Taproot

java.lang.Object
com.codename1.crypto.bitcoin.Taproot

public final class Taproot extends Object

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(byte[], byte[]) gives it. BIP-86 wallets use no script tree.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The leaf version of a Tapscript leaf.
  • Method Summary

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

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LEAF_VERSION_TAPSCRIPT

      public static final int LEAF_VERSION_TAPSCRIPT
      The leaf version of a Tapscript leaf.
      See Also:
  • 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(byte[], byte[]) 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.