Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

p2tr

alexbosworth4.7kMIT2.0.0

Utilities for working with P2TR outputs

bitcoin, taproot

readme

P2TR

Utility methods for working with Pay to Taproot outputs

Methods

controlBlock

Assemble a control block for a leaf script spend

{
  external_key: <External Public Key Hex String>
  [internal_key]: <Internal Public Key Hex String>
  leaf_script: <Leaf Script Hex String>
  [leaf_version]: <Leaf Script Version Number>
  script_branches: <Script Branches Object>
}

@returns
{
  block: <Control Block Hex String>
}

hashForTree

Hash a tree of scripts

{
  branches: [{
    script: <Hex Encoded Script String>
    [version]: <Leaf Version Number>
  }]
}

@returns
{
  hash: <Hash of Tree Hex Encoded String>
}

leafHash

Hash for leaf script

{
  script: <Script Hex String>
  [version]: <Leaf Version Number>
}

@returns
{
  hash: <Hash Hex String>
}

signHash

Sign with a tweaked private key

{
  [hash]: <Tweak Hash Hex String>
  private_key: <Internal Private Key Hex String>
  public_key: <Internal Public Key Hex String>
  sign_hash: <Hash to Sign Hex String>
}

@returns
{
  signature: <Tweaked Private Key Hex String>
}

tweakHash

Tweak hash

{
  hash: <Hash Hex String>
  public_key: <Public Key Hex String>
}

@returns
{
  hash: <Tagged Tweak Hash Hex String>
}

v1OutputScript

Create a SegWit V1 Output Script

{
  [hash]: <Hash Hex String>
  internal_key: <Internal Public Key Hex String>
}

@returns
{
  external_key: <External Public Key Hex String>
  script: <Output Script Hex String>
}

changelog

Versions

2.0.0

Breaking Changes

  • Node 16 or higher is now required

1.3.3

  • tweakHash: Add support for passing an already x-only public key
  • v1OutputScript: Add support for passing an already x-only public key

1.3.1

  • v1OutputScript: Add external_key to return the external public key

1.2.0

  • signHash: Add method to sign using the tweaked key
  • v1OutputScript: Add method to derive an output script

1.1.0

  • controlBlock: Add method to derive control block for a script spend witness

1.0.0

  • hashForTree: Add method to calculate a root hash for a tree of scripts
  • leafHash: Add method to calculate hash for a leaf script
  • tweakHash: Add method to tweak a public key with a hash