19 Commits

Author SHA1 Message Date
Alekos Filini
79f73df545
Merge bitcoindevkit/bdk#582: Expose bip39::Error
c752ccbddeaa5ae441cc74a1386c1e412a447104 Expose bip39::Error (志宇)

Pull request description:

  <!-- You can erase any parts of this template not applicable to your Pull Request. -->

  ### Description

  Expose `bip39::Error` (fixes #581 )

  ### Notes to the reviewers

  I am aware that the `bip39` module plans to be rewritten (as per #561 ), however this seems like a rather straightforward and quick change that may be useful in the short/mid term.

  ### Checklists

  #### Bugfixes:

  * [x] Expose `bip39::Error`

ACKs for top commit:
  afilini:
    ACK c752ccbddeaa5ae441cc74a1386c1e412a447104

Tree-SHA512: 98b7ac1ba88aed07d9160830ee80496c32d531c15ada0e9b50a97f0883fbfced22fa83a7c7f8366aadb7e7a667d8a63dde869d31cc375206d277e55b2ec3089d
2022-04-25 16:14:46 +02:00
Alekos Filini
e4eb95fb9c
[keys] Implement DerivableKey<Ctx> for (GeneratedKey<Mnemonic, Ctx>, Option<String>)
This lets us use a tuple of (generated mnemonic, optional passphrase) as
a `DerivableKey` directly, without extracting the inner mnemonic from the
`GeneratedKey` wrapper. For BIP39 keys specifically it doesn't make much
difference because the mnemonic format doesn't encode the network, but in
general this is not the case and having a consistent API will make it
harder for people to make mistakes.

To explain why we should not extract the key: some key formats (like
BIP32 extended keys) are network-specific, meaning that if somebody
tries to use a Testnet key on a Mainnet BDK wallet, it won't work.

However, when we generate a new key we would like to be able to use that
key on any network, but we need to set some kind of placeholder for the
`network` field in the structure. This is why (or at least one of the
reasons why) we wrap the key in the `GeneratedKey` struct: we keep track
of the "valid_networks" separately, which means that even if we set our
BIP32 xprv to be a "Mainnet" key, once we go try creating a wallet with
that key BDK is smart enough to understand that `GeneratedKey`s have
their own separate set of valid networks and it will use that set to
validate whether the key can be used in the wallet or not.
2022-04-13 12:37:27 +02:00
志宇
c752ccbdde
Expose bip39::Error 2022-04-07 19:50:17 +08:00
rajarshimaitra
5922c216a1
Update WordsCount -> WordCount 2021-11-06 20:14:03 +05:30
rajarshimaitra
d2ce2714f2
Replace tiny-bip39 with rust-bip39
Use rust-bip39 for mnemonic derivation everywhere.

This requires our own WordCount enum as rust-bip39 doesn't have
explicit mnemonic type definition.
2021-11-03 11:14:05 +05:30
Alekos Filini
a348dbdcfe
[ci] Update the stable version to 1.56 2021-10-22 15:57:27 +02:00
Steve Myers
12ae1c3479
Update license to Apache 2.0 or MIT, copyright to Bitcoin Dev Kit Developers 2021-03-03 13:23:25 -08:00
Alekos Filini
fedd92c022
Properly handle the Signet network
Closes #62
2021-02-05 16:51:48 -05:00
Alekos Filini
3d9d6fee07
Update bitcoin, miniscript, electrum-client 2021-02-05 09:11:27 -05:00
Alekos Filini
ccbbad3e9e
[keys] Improve the API of DerivableKey
A new `ExtendedKey` type has been added, which is basically an enum of
`bip32::ExtendedPubKey` and `bip32::ExtendedPrivKey`, with some extra metadata
regarding the `ScriptContext`.

This type has some methods that make it very easy to extract its content as
either an `xprv` or `xpub`.

The `DerivableKey` trait has been updated so that the user now only has to
implement a method (`DerivableKey::into_extended_key()`) to perform the
conversion into an `ExtendedKey`.

The method that was previously called `add_metadata()` has now been renamed
to `into_descriptor_key()`, and it has
a blanket implementation.
2021-01-29 15:21:36 -05:00
Alekos Filini
c0a92bd084
[keys] Replace (Fingerprint, DerivationPath) with KeySource 2020-12-11 11:16:41 +01:00
Alekos Filini
9bafdfe2d4
[docs] Various fixes to the docs 2020-12-11 11:16:38 +01:00
Steve Myers
4f7355ec82
[ci] Fix all-keys and cli-utils tests 2020-10-28 21:34:04 -07:00
LLFourn
490c88934e [keys] Less convoluted entropy generation
Since const generics aren't in rust yet you have to find some awkward
workarounds. This improves the workaround for specifying entropy length.
2020-09-30 20:05:17 +10:00
Alekos Filini
82251a8de4
[keys] Fix entropy generation 2020-09-24 15:59:46 +02:00
Alekos Filini
b294b11c54
[keys] Add a trait for keys that can be generated 2020-09-24 09:53:56 +02:00
Alekos Filini
c93cd1414a
[descriptor] Add descriptor templates, add DerivableKey 2020-09-24 09:53:54 +02:00
Alekos Filini
c51ba4a99f
[keys] Add a way to restrict the networks in which keys are valid
Thanks to the `ToWalletDescriptor` trait we can also very easily validate the checksum
for descriptors that are loaded from strings, if they contain one. Fixes #20.
2020-09-24 09:53:51 +02:00
Alekos Filini
ab9d964868
[keys] Add BIP39 support 2020-09-24 09:53:46 +02:00