bitcoin-scripting-0.3.0: Resources for working with miniscript, and script descriptors
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Bitcoin.Script.Descriptors

Description

A library for working with bitcoin script descriptors. Documentation taken from https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md.

Synopsis

Descriptors

data OutputDescriptor Source #

High level description for a bitcoin output

Constructors

ScriptPubKey ScriptDescriptor

The output is secured by the given script.

P2SH ScriptDescriptor

P2SH embed the argument.

P2WPKH KeyDescriptor

P2WPKH output for the given compressed pubkey.

P2WSH ScriptDescriptor

P2WSH embed the argument.

WrappedWPkh KeyDescriptor

P2SH-P2WPKH the given compressed pubkey.

WrappedWSh ScriptDescriptor

P2SH-P2WSH the given script

Combo KeyDescriptor

An alias for the collection of pk(KEY) and pkh(KEY). If the key is compressed, it also includes wpkh(KEY) and sh(wpkh(KEY)).

Addr Address

The script which ADDR expands to.

outputDescriptorAtIndex :: KeyIndex -> OutputDescriptor -> OutputDescriptor Source #

Specialize key families occurring in the descriptor to the given index

Since: 0.2.1

data ScriptDescriptor Source #

High level description of a bitcoin script

Constructors

Pk KeyDescriptor

Require a signature for this key

Pkh KeyDescriptor

Require a key matching this hash and a signature for that key

Multi Int [KeyDescriptor]

k-of-n multisig script.

SortedMulti Int [KeyDescriptor]

k-of-n multisig script with keys sorted lexicographically in the resulting script.

Raw ByteString

the script whose hex encoding is HEX.

scriptDescriptorAtIndex :: KeyIndex -> ScriptDescriptor -> ScriptDescriptor Source #

Specialize key families occurring in the descriptor to the given index

Since: 0.2.1

Keys

data Origin Source #

Constructors

Origin 

Fields

Instances

Instances details
Show Origin Source # 
Instance details

Defined in Language.Bitcoin.Script.Descriptors.Syntax

Eq Origin Source # 
Instance details

Defined in Language.Bitcoin.Script.Descriptors.Syntax

Methods

(==) :: Origin -> Origin -> Bool #

(/=) :: Origin -> Origin -> Bool #

Ord Origin Source # 
Instance details

Defined in Language.Bitcoin.Script.Descriptors.Syntax

data Key Source #

Constructors

Pubkey PubKeyI

DER-hex encoded secp256k1 public key

SecretKey SecKeyI

(de)serialized as WIF

XPub XPubKey DerivPath KeyCollection 

Instances

Instances details
Show Key Source # 
Instance details

Defined in Language.Bitcoin.Script.Descriptors.Syntax

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String #

showList :: [Key] -> ShowS #

Eq Key Source # 
Instance details

Defined in Language.Bitcoin.Script.Descriptors.Syntax

Methods

(==) :: Key -> Key -> Bool #

(/=) :: Key -> Key -> Bool #

data KeyCollection Source #

Represent whether the key corresponds to a collection (and how) or a single key.

Constructors

Single 
HardKeys

immediate hardened children

SoftKeys

immediate non-hardened children

isDefinite :: KeyDescriptor -> Bool Source #

Test whether the key descriptor corresponds to a single key

keyAtIndex :: Word32 -> Key -> Key Source #

For key families, get the key at the given index. Otherwise, return the input key.

Since: 0.2.1

keyDescriptorAtIndex :: KeyIndex -> KeyDescriptor -> KeyDescriptor Source #

Specialize key families occurring in the descriptor to the given index

Since: 0.2.1

keyDescPubKey :: KeyDescriptor -> Maybe PubKeyI Source #

Produce a pubkey if possible

pubKey :: PubKeyI -> KeyDescriptor Source #

Simple explicit public key with no origin information

secKey :: SecKeyI -> KeyDescriptor Source #

Simple explicit secret key with no origin information

keyBytes :: KeyDescriptor -> Maybe ByteString Source #

Produce a key literal if possible

outputDescriptorPubKeys :: OutputDescriptor -> [PubKeyI] Source #

Extract pubkeys from an OutputDescriptor where possible

scriptDescriptorPubKeys :: ScriptDescriptor -> [PubKeyI] Source #

Extract pubkeys from a ScriptDescriptor where possible

Text representation

Parsing

data ChecksumDescriptor Source #

An OutputDescriptor with checksum details

Constructors

ChecksumDescriptor 

Fields

data ChecksumStatus Source #

The status of an output descriptor's checksum

Constructors

Valid

Checksum provided is valid

Invalid

Checksum provided is invalid

Fields

  • Text

    The invalid checksum

Absent

Checksum is not provided

Conversions

descriptorAddresses :: OutputDescriptor -> [Address] Source #

Get the set of addresses associated with an output descriptor. The list will be empty if:

  • any keys are indefinite
  • the output is p2pk
  • the output has a non-standard script

The list can contain more than one address in the case of the "combo" construct.

compile :: ScriptDescriptor -> Maybe Script Source #

Produce the script described by the descriptor. Fails when any keys in the descriptor are indeterminate.

PSBT

toPsbtInput Source #

Arguments

:: Tx

Transaction being spent

-> Int

Output being spent

-> OutputDescriptor

Descriptor for output being spent

-> Either PsbtInputError Input 

Produce the psbt input parameters needed to spend an output from the descriptor. Caveat: This construction fails on Combo and Addr outputs.

Since: 0.2.1

Checksums

descriptorChecksum :: Text -> Maybe Text Source #

Compute the checksum of the textual representation of an output descriptor if possible.

validDescriptorChecksum :: Text -> Text -> Bool Source #

Test whether the textual representation of an output descriptor has the given checksum.