Skip to content

Commit 8afb166

Browse files
committed
Update documentation to incude origin information
1 parent ff37459 commit 8afb166

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

doc/descriptors.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Output descriptors currently support:
3434
- `sh(wsh(multi(1,03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8,03499fdf9e895e719cfd64e67f07d38e3226aa7b63678949e6e49b241a60e823e4,02d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e)))` describes a P2SH-P2WSH *1-of-3* multisig output with keys in the specified order.
3535
- `pk(xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8)` describes a P2PK output with the public key of the specified xpub.
3636
- `pkh(xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw/1'/2)` describes a P2PKH output with child key *1'/2* of the specified xpub.
37+
- `pkh([d34db33f/44'/0'/0']xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1/*)` describes a set of P2PKH outputs, but additionally specifies that the specified xpub is a child of a master with fingerprint `d34db33f`, and derived using path `44'/0'/0'`.
3738
- `wsh(multi(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*))` describes a set of *1-of-2* P2WSH multisig outputs where the first multisig key is the *1/0/`i`* child of the first specified xpub and the second multisig key is the *0/0/`i`* child of the second specified xpub, and `i` is any number in a configurable range (`0-1000` by default).
3839

3940
## Reference
@@ -52,14 +53,20 @@ Descriptors consist of several types of expressions. The top level expression is
5253
- `raw(HEX)` (top level only): the script whose hex encoding is HEX.
5354

5455
`KEY` expressions:
55-
- Hex encoded public keys (66 characters starting with `02` or `03`, or 130 characters starting with `04`).
56-
- Inside `wpkh` and `wsh`, only compressed public keys are permitted.
57-
- [WIF](https://en.bitcoin.it/wiki/Wallet_import_format) encoded private keys may be specified instead of the corresponding public key, with the same meaning.
58-
-`xpub` encoded extended public key or `xprv` encoded private key (as defined in [BIP 32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)).
59-
- Followed by zero or more `/NUM` unhardened and `/NUM'` hardened BIP32 derivation steps.
60-
- Optionally followed by a single `/*` or `/*'` final step to denote all (direct) unhardened or hardened children.
61-
- The usage of hardened derivation steps requires providing the private key.
62-
- Instead of a `'`, the suffix `h` can be used to denote hardened derivation.
56+
- Optionally, key origin information, consisting of:
57+
- An open bracket `[`
58+
- Exactly 8 hex characters for the fingerprint of the key where the derivation starts (see BIP32 for details)
59+
- Followed by zero or more `/NUM` or `/NUM'` path elements to indicate unhardened or hardened derivation steps between the fingerprint and the key or xpub/xprv root that follows
60+
- A closing bracket `]`
61+
- Followed by the actual key, which is either:
62+
- Hex encoded public keys (66 characters starting with `02` or `03`, or 130 characters starting with `04`).
63+
- Inside `wpkh` and `wsh`, only compressed public keys are permitted.
64+
- [WIF](https://en.bitcoin.it/wiki/Wallet_import_format) encoded private keys may be specified instead of the corresponding public key, with the same meaning.
65+
-`xpub` encoded extended public key or `xprv` encoded private key (as defined in [BIP 32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)).
66+
- Followed by zero or more `/NUM` unhardened and `/NUM'` hardened BIP32 derivation steps.
67+
- Optionally followed by a single `/*` or `/*'` final step to denote all (direct) unhardened or hardened children.
68+
- The usage of hardened derivation steps requires providing the private key.
69+
- Anywhere a `'` suffix is permitted to denote hardened derivation, the suffix `h` can be used instead.
6370

6471
`ADDR` expressions are any type of supported address:
6572
- P2PKH addresses (base58, of the form `1...`). Note that P2PKH addresses in descriptors cannot be used for P2PK outputs (use the `pk` function instead).
@@ -116,6 +123,33 @@ Whenever a public key is described using a hardened derivation step, the
116123
script cannot be computed without access to the corresponding private
117124
key.
118125

126+
### Key origin identification
127+
128+
In order to describe scripts whose signing keys reside on another device,
129+
it may be necessary to identify the master key and derivation path an
130+
xpub was derived with.
131+
132+
For example, when following BIP44, it would be useful to describe a
133+
change chain directly as `xpub.../44'/0'/0'/1/*` where `xpub...`
134+
corresponds with the master key `m`. Unfortunately, since there are
135+
hardened derivation steps that follow the xpub, this descriptor does not
136+
let you compute scripts without access to the corresponding private keys.
137+
Instead, it should be written as `xpub.../1/*`, where xpub corresponds to
138+
`m/44'/0'/0'`.
139+
140+
When interacting with a hardware device, it may be necessary to include
141+
the entire path from the master down. BIP174 standardizes this by
142+
providing the master key *fingerprint* (first 32 bit of the Hash160 of
143+
the master pubkey), plus all derivation steps. To support constructing
144+
these, we permit providing this key origin information inside the
145+
descriptor language, even though it does not affect the actual
146+
scriptPubKeys it refers to.
147+
148+
Every public key can be prefixed by an 8-character hexadecimal
149+
fingerprint plus optional derivation steps (hardened and unhardened)
150+
surrounded by brackets, identifying the master and derivation path the key or xpub
151+
that follows was derived with.
152+
119153
### Including private keys
120154

121155
Often it is useful to communicate a description of scripts along with the
@@ -130,4 +164,4 @@ In order to easily represent the sets of scripts currently supported by
130164
existing Bitcoin Core wallets, a convenience function `combo` is
131165
provided, which takes as input a public key, and describes a set of P2PK,
132166
P2PKH, P2WPKH, and P2SH-P2WPH scripts for that key. In case the key is
133-
uncompressed, the set only includes P2PK and P2PKH scripts.
167+
uncompressed, the set only includes P2PK and P2PKH scripts.

0 commit comments

Comments
 (0)