BIP draft: BIP39 Descriptor Key Expression #2361

pull polespinasa wants to merge 1 commits into bitcoin:master from polespinasa:2026-11-23-bip39descriptorkeyexpression changing 2 files +312 −0
  1. polespinasa commented at 5:38 PM on November 23, 2026: member

    Adds a new key expression to define a a bip39 English mnemonics phrase + optional passphrase within a descriptor.

    ML Post: https://groups.google.com/g/bitcoindev/c/o0uh9VhrpkU/m/Pf1YaFV3AAAJ Previous discussions while drafting this BIP: https://github.com/polespinasa/bips/pull/1

  2. jonatack renamed this:
    bip39 Descriptor Key Expression
    BIP draft: BIP39 Descriptor Key Expression
    on Nov 23, 2026
  3. jonatack added the label New BIP on Nov 23, 2026
  4. in bip-xxxx.md:66 in d85cae9af9 outdated
      61 | +
      62 | +```
      63 | +"correct horse battery staple"
      64 | +"say \"hello\""
      65 | +"C:\\wallet"
      66 | +"caf\u{e9}"
    


    jonatack commented at 5:50 PM on November 23, 2026:

    Need to add something ~like this to appease the typos CI

    --- a/.typos.toml
    +++ b/.typos.toml
    @@ -8,6 +8,7 @@ extend-ignore-re = [
         "private_key .*",
         "privkey .*",
         "tt.*", # <tt> tags
    +    "caf",
         "code.*", # <code> tags
    

    polespinasa commented at 5:55 PM on November 23, 2026:

    oh nice, done thanks :)

  5. polespinasa force-pushed on Nov 23, 2026
  6. jeanpablojp commented at 1:31 PM on November 24, 2026: contributor

    Every xprv and descriptor checksum in the draft matches what I get from the text alone. I left 3 small inlines, but in general all looks good to me.

  7. BIP draft: BIP39 Descriptor key Expressions cbf5ea5385
  8. in bip-xxxx.md:186 in c6fc392572
     181 | +
     182 | +Going from a `bip39()` key expression to an `xprv` is the same process as going from a BIP 39 mnemonic sentence (seedphrase) to an `xprv`; for that reason the same [test vectors][BIP39testvectors] as the ones defined in BIP 39 can be used.
     183 | +
     184 | +The following valid descriptors exercise edge cases introduced by the quoted passphrase encoding. All use the mnemonic `legal winner thank year wave sausage worth useful legal winner thank yellow`. Each is shown with its descriptor checksum and is equivalent to the `xprv` descriptor shown alongside it.
     185 | +
     186 | +- `#` in passphrase — the `#` inside the passphrase is not a checksum separator; the descriptor checksum separator is the final `#`:
    


    jeanpablojp commented at 1:31 PM on November 24, 2026:

    A parser splitting at the final #, as this note says, passes every vector but rejects the foo#bar descriptor without its checksum.

    Could the note say only a # outside the quoted passphrase starts the checksum, and this vector be added?

    wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "foo#bar"))
    

    polespinasa commented at 8:10 PM on November 25, 2026:

    Done

  9. in bip-xxxx.md:236 in c6fc392572 outdated
     231 | +
     232 | +    `wpkh(xprv9s21ZrQH143K3MWGZi36HpsEZ3SC7J9tPBjUmQYQ5sJqh8qyzuGgE3f1WgzDzHo47SneixuX9oVeqB5k2kdVUuQMVc1QiUGdq22gaBAbfuC)#5z32wesl`
     233 | +
     234 | +- Unicode escape (`\u{e9}`) — the `\u{e9}` sequence encodes U+00E9, so the passphrase decodes to `café`:
     235 | +
     236 | +    `wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "caf\u{e9}"))#05l5g328`
    


    jeanpablojp commented at 1:31 PM on November 24, 2026:

    An implementation that applies NFD instead of NFKD passes every vector here, this one included.

    Could the vector below be added?

    wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "\u{ff33}\u{ff21}\u{ff34}\u{ff2f}\u{ff33}\u{ff28}\u{ff29}"))#ufmqx3tc
    wpkh(xprv9s21ZrQH143K3WhtFPeEmTRQbQckSDMbuAn4hxGs4zLkD4N8b9fBpWDCPENoVq83vrML4fYwhKZPtgG5XR1vnSbwGs79FvQ4dET1KsB8P4q)#v99927rr
    

    polespinasa commented at 8:10 PM on November 25, 2026:

    I've added the test and and a small explanation with a visual example.

  10. in bip-xxxx.md:259 in c6fc392572 outdated
     254 | +- Passphrase with an invalid `\u{HEX}` escape (a surrogate code point):
     255 | +    `wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "\u{D800}"))`
     256 | +- Passphrase with an unterminated quoted string (an unescaped `"` ends the passphrase and leaves trailing garbage; the `"` character must instead be written as `\"`):
     257 | +    `wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "SATO"SHI"))`
     258 | +- Nested `bip39()` (its arguments are a word list and a passphrase, not key expressions):
     259 | +    `wpkh(bip39(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "SATOSHI")))`
    


    jeanpablojp commented at 1:31 PM on November 24, 2026:

    A parser that accepts the seven-digit \u{0000041}, \u{110000}, the word Legal or a missing closing quote passes every vector here.

    Could the four vectors below go in the list of invalid descriptors?

    wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "\u{0000041}"))
    wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "\u{110000}"))
    wpkh(bip39([Legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "SATOSHI"))
    wpkh(bip39([legal, winner, thank, year, wave, sausage, worth, useful, legal, winner, thank, yellow], "SATOSHI))
    

    polespinasa commented at 8:11 PM on November 25, 2026:

    Done

  11. polespinasa force-pushed on Nov 25, 2026
  12. polespinasa commented at 8:11 PM on November 25, 2026: member

    Thanks for the comments jeanpablojp Force pushed to address all three comments

  13. in bip-xxxx.md:27 in cbf5ea5385
      22 | +
      23 | +- [bitcoin/bitcoin#16393][Core16393]: a contributor requested partial (import) BIP 39 support for Bitcoin Core, for interoperability with existing wallets that use BIP 39 seeds.
      24 | +
      25 | +- [bitcoin/bitcoin#17748][Core17748]: users discussed mnemonic-based backups and wallet interoperability.
      26 | +
      27 | +- [bitcoin/bitcoin#32115][Core32115]: a contributor proposed a standalone Rust utility to import BIP 39 mnemonics. The discussion raised concerns about dependency review and requiring users to compile the utility themselves.
    


    edilmedeiros commented at 1:28 PM on December 2, 2026:

    some descriptor wallets lack a standardized way to import them. This gap has been documented for years

    It then follows a list of discussions on the Core Wallet. Not sure that counts as supportive for "some" descriptor wallets. Don't have a specific suggestion here, just thinking how the motivation that started as a problem in the Bitcoin Core Wallet (and probably others) could be better generalized in the text to a general problem the proposal addresses.

  14. in bip-xxxx.md:31 in cbf5ea5385
      26 | +
      27 | +- [bitcoin/bitcoin#32115][Core32115]: a contributor proposed a standalone Rust utility to import BIP 39 mnemonics. The discussion raised concerns about dependency review and requiring users to compile the utility themselves.
      28 | +
      29 | +Users may need wallet-specific import workflows or a separate tool to convert a mnemonic and passphrase into an extended private key and descriptor.
      30 | +
      31 | +A standardized key expression would allow supporting wallets to import a mnemonic and passphrase directly, without requiring a separate conversion workflow. This document specifies `bip39()` for that purpose. A `bip39()` expression is functionally equivalent to an `xprv` key expression and does not enable any new spending capability.
    


    edilmedeiros commented at 1:32 PM on December 2, 2026:
    A standardized key expression would allow supporting wallets to import a mnemonic and passphrase directly, without requiring a separate conversion workflow. This document specifies `bip39()` for that purpose. A `bip39()` key fragment is functionally equivalent to an `xprv` key fragment and does not enable any new spending capability.
    

    Pedantic: As per BIP380, there's no xprv key expression, there are "key expressions" that can contain an xprv as part of the construction.

    BIP380 talks about descriptor fragments and functions.

    Why I think this matters: you are introducing a new function (in my understanding) that is to be used to build key expressions. In that way, I'm not sure calling bip39() a key expression is correct in how I conceptualize output descriptors as a (somewhat formal) language.

    I would prefer to call bip39() a function and xprv a fragment, following language established in BIP380 itself and in BIP379. Potential problem is that, different from other descriptor bips that introduce new functions in the context of script expressions, you are introducing a function in the context of key expressions and I think that's something new (which I think is good, but probably will deserve some explanation on the rationale section).

    This comment applies to all the text, I'll not point it out in every place it happens to not pollute the review too much.


    edilmedeiros commented at 1:46 PM on December 2, 2026:

    Second point, well, you are introducing "new spending capabilities", to say, from a key that could not be described before. Probably better prose would be something in the lines of "is functionally equivalent to an xprv key fragment and does not introduce any new script expression".

    I would try to stick to the semantics of BIP380 as much as possible: fragments and functions are what descriptors are made of, script expressions translate to scripts, key expressions translate to keys. Later, we introduced other stuff like tree expressions (BIP386).

  15. in bip-xxxx.md:35 in cbf5ea5385
      30 | +
      31 | +A standardized key expression would allow supporting wallets to import a mnemonic and passphrase directly, without requiring a separate conversion workflow. This document specifies `bip39()` for that purpose. A `bip39()` expression is functionally equivalent to an `xprv` key expression and does not enable any new spending capability.
      32 | +
      33 | +## Specification
      34 | +
      35 | +A new key expression is defined: `bip39()`.
    


    edilmedeiros commented at 1:53 PM on December 2, 2026:
    A new key function is defined: `bip39()`.
    
  16. in bip-xxxx.md:37 in cbf5ea5385
      32 | +
      33 | +## Specification
      34 | +
      35 | +A new key expression is defined: `bip39()`.
      36 | +
      37 | +For descriptor evaluation, a `bip39()` expression produces the BIP 32 master extended private key (`xprv`) derived from its mnemonic and passphrase. It follows the same derivation and serialization rules as an `xprv` key expression and is valid in the same script-expression contexts.
    


    edilmedeiros commented at 2:00 PM on December 2, 2026:
    For descriptor evaluation, a `bip39()` expression produces the BIP 32 master extended private key (`xprv`) derived from its mnemonic and passphrase. It follows the same derivation and serialization rules as an `xprv` key expression and is valid in the same key expression contexts.
    

    xprvs can be used in script expressions, but only incidentally. E.g. pk(KEY) (BIP381) is a script expression that's composed by a function and a key expression. That key expression can be an xpriv.

    But I think there's no context in which we accept and xprv by itself instead of a key expression. So, bip39() is probably better described as valid in all key expressions where xprv is valid.


    edilmedeiros commented at 2:01 PM on December 2, 2026:

    It follows the same derivation and serialization rules

    Which rules, where are they defined? Better prose for specifications is to say something like "It follows the derivation and serialization rules defined in BIPxxx" or other equivalent document.

  17. in bip-xxxx.md:39 in cbf5ea5385
      34 | +
      35 | +A new key expression is defined: `bip39()`.
      36 | +
      37 | +For descriptor evaluation, a `bip39()` expression produces the BIP 32 master extended private key (`xprv`) derived from its mnemonic and passphrase. It follows the same derivation and serialization rules as an `xprv` key expression and is valid in the same script-expression contexts.
      38 | +
      39 | +A `bip39()` expression is self-contained: within the balanced parentheses of `bip39(...)`, the characters `[`, `]` and `,` delimit the word list and separate its two arguments, and are not interpreted as the BIP 380 key-origin brackets or key-separator tokens. A parser must switch to the `bip39()` sub-grammar upon encountering `bip39(` and resume ordinary BIP 380 parsing only after the matching `)`.
    


    edilmedeiros commented at 2:08 PM on December 2, 2026:

    A bip39() expression is self-contained

    Not sure what that means… Better to just describe the arguments list as in other BIPs.

    Examples (from script expressions since you are introducing the first function for keys):

    • pk(KEY), where KEY is a key expression.
    • tr(KEY, TREE), where TREE is itself defined in the specification (see BIP386).

    Since you talk about a sub-grammar in the text that follows, I think formally introducing (maybe) a MNEMONIC expression would be healthy. Then, your expression would be bip39(MNEMONIC).

    See BIP386 where it introduces TREE expressions, it will be similar to you case here.

  18. in bip-xxxx.md:45 in cbf5ea5385
      40 | +
      41 | +It takes a list of 12, 15, 18, 21 or 24 BIP 39 English words, in lowercase as they appear in the BIP 39 wordlist, and an optional passphrase enclosed in double quotes and encoded as specified in the Passphrase Encoding subsection below, following the BIP 39 specification:
      42 | +
      43 | +`bip39([word1, word2, ..., wordN], "passphrase")`
      44 | +
      45 | +If no passphrase is provided, an empty string `""` is used instead, as BIP 39 states; its presence in the descriptor is optional and can be skipped:
    


    edilmedeiros commented at 2:10 PM on December 2, 2026:

    See how BIP386 deals with this. It defines:

    • tr(KEY)
    • tr(KEY, TREE).

    I think that's better pattern than having a default argument, it forces one to define exactly what to do in each case (as patter matching) and I think is way less prone to implementation errors.

    You could have, say:

    • bip39(MNEMONIC)
    • bip30(MNEMONIC, PASS)
  19. edilmedeiros commented at 2:34 PM on December 2, 2026: contributor

    Thanks for proposing this, I think that adds to the toolkit of output descriptors.

    Left some conceptual comments as inliners. Conceptual in the sense of how I feel this would:

    1. be more formal;
    2. make better use of the (somewhat implicit) formalism of output descriptors as a language.

    For the record.

    Output descriptors establish a kind of formal language to talk about bitcoin scripts (or spending conditions). This language is composed of fragments and functions (see BIP380), but those fragments and functions are not properly defined anywhere, so one have to infer from the specific buildings blocks defined in a series of BIPs (to which this proposal will add).

    My understanding is that fragments are ad hoc (loose) pieces of syntax, like and xprv or a derivation path. A function is something in the form f() that takes arguments.

    Those are used to create KEY expressions, SCRIPT expressions (BIP380), TREE expressions (BIP386).

    You are introducing a new function for creating KEY expressions and I think the proposal should be precise about that. In my inline comments I thought this would be the first case of a function being used in a KEY expression, but BIP390 already does that and I think your description should follow that pattern more closely.

    Your proposal is more complex than BIP390 though because you need to describe how mnemonics and passphrases are built and encoded. My suggestion is to define something like a MNEMONIC (or a better name of your choice) expression in the same style as the TREE expression in BIP 386. Maybe the same thing for passphrases because they can't be arbitrary strings of text. That way, you abstract the main construction as something like bip39(MNEMONIC) and bip39(MNEMONIC, PASSPHRASE) and modularize the complexity in the specific constructions that are probably only useful in this specific context so that an implementor can grasp what exactly they have to implement.

    This probably involves a big rewrite, so I'll defer checking the encodings review for a later pass of review.

    PS: since I'm proposing bigger changes, you might feel like waiting for an actual editor to review you proposal before reacting to this review.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bips. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-12-03 01:42 UTC