Skip to content

Commit

Permalink
Merge pull request #6 from BP-WG/v0.11
Browse files Browse the repository at this point in the history
Release v0.11 beta 2
  • Loading branch information
dr-orlovsky committed Nov 19, 2023
2 parents 3b2227a + 210f991 commit a200597
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 135 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["std", "descriptors", "psbt", "."]
resolver = "2"

[workspace.package]
version = "0.11.0-beta.1"
version = "0.11.0-beta.2"
keywords = ["bitcoin", "wallet", "descriptors", "psbt", "taproot"]
categories = ["cryptography::cryptocurrencies"]
authors = ["Dr Maxim Orlovsky <orlovsky@lnp-bp.org>"]
Expand All @@ -18,7 +18,7 @@ amplify = "4.5.0"
bitcoin_hashes = "0.13.0" # TODO: Remove and replace with commit_verify
bech32 = "0.9.1"
bp-consensus = "0.11.0-beta.2"
bp-std = { version = "0.11.0-beta.1", path = "std" }
descriptors = { version = "0.11.0-beta.1", path = "descriptors" }
bp-std = { version = "0.11.0-beta.2", path = "std" }
descriptors = { version = "0.11.0-beta.2", path = "descriptors" }
indexmap = "2.0.0"
serde_crate = { package = "serde", version = "1", features = ["derive"] }
50 changes: 30 additions & 20 deletions descriptors/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::ops::Range;
use std::collections::BTreeSet;
use std::{iter, vec};

use bpstd::{
CompressedPk, Derive, DeriveCompr, DeriveScripts, DeriveSet, DeriveXOnly, DerivedScript,
KeyOrigin, NormalIndex, TapDerivation, Terminal, XOnlyPk, XpubDerivable, XpubSpec,
KeyOrigin, Keychain, NormalIndex, TapDerivation, Terminal, XOnlyPk, XpubDerivable, XpubSpec,
};
use indexmap::IndexMap;

Expand Down Expand Up @@ -67,7 +67,7 @@ pub trait Descriptor<K = XpubDerivable, V = ()>: DeriveScripts {
)
)]
#[non_exhaustive]
pub enum DescriptorStd<S: DeriveSet = XpubDerivable> {
pub enum StdDescr<S: DeriveSet = XpubDerivable> {
/*
#[from]
Bare(Bare<S::Legacy>),
Expand Down Expand Up @@ -139,24 +139,34 @@ pub enum DescriptorStd<S: DeriveSet = XpubDerivable> {
*/
}

impl<S: DeriveSet> Derive<DerivedScript> for DescriptorStd<S> {
fn keychains(&self) -> Range<u8> {
impl<S: DeriveSet> Derive<DerivedScript> for StdDescr<S> {
fn default_keychain(&self) -> Keychain {
match self {
DescriptorStd::Wpkh(d) => d.keychains(),
DescriptorStd::TrKey(d) => d.keychains(),
StdDescr::Wpkh(d) => d.default_keychain(),
StdDescr::TrKey(d) => d.default_keychain(),
}
}

fn derive(&self, keychain: u8, index: impl Into<NormalIndex>) -> DerivedScript {
fn keychains(&self) -> BTreeSet<Keychain> {
match self {
DescriptorStd::Wpkh(d) => d.derive(keychain, index),
DescriptorStd::TrKey(d) => d.derive(keychain, index),
StdDescr::Wpkh(d) => d.keychains(),
StdDescr::TrKey(d) => d.keychains(),
}
}

fn derive(
&self,
keychain: impl Into<Keychain>,
index: impl Into<NormalIndex>,
) -> DerivedScript {
match self {
StdDescr::Wpkh(d) => d.derive(keychain, index),
StdDescr::TrKey(d) => d.derive(keychain, index),
}
}
}

impl<K: DeriveSet<Compr = K, XOnly = K> + DeriveCompr + DeriveXOnly> Descriptor<K>
for DescriptorStd<K>
impl<K: DeriveSet<Compr = K, XOnly = K> + DeriveCompr + DeriveXOnly> Descriptor<K> for StdDescr<K>
where Self: Derive<DerivedScript>
{
type KeyIter<'k> = vec::IntoIter<&'k K> where Self: 'k, K: 'k;
Expand All @@ -165,8 +175,8 @@ where Self: Derive<DerivedScript>

fn keys(&self) -> Self::KeyIter<'_> {
match self {
DescriptorStd::Wpkh(d) => d.keys().collect::<Vec<_>>(),
DescriptorStd::TrKey(d) => d.keys().collect::<Vec<_>>(),
StdDescr::Wpkh(d) => d.keys().collect::<Vec<_>>(),
StdDescr::TrKey(d) => d.keys().collect::<Vec<_>>(),
}
.into_iter()
}
Expand All @@ -175,23 +185,23 @@ where Self: Derive<DerivedScript>

fn xpubs(&self) -> Self::XpubIter<'_> {
match self {
DescriptorStd::Wpkh(d) => d.xpubs().collect::<Vec<_>>(),
DescriptorStd::TrKey(d) => d.xpubs().collect::<Vec<_>>(),
StdDescr::Wpkh(d) => d.xpubs().collect::<Vec<_>>(),
StdDescr::TrKey(d) => d.xpubs().collect::<Vec<_>>(),
}
.into_iter()
}

fn compr_keyset(&self, terminal: Terminal) -> IndexMap<CompressedPk, KeyOrigin> {
match self {
DescriptorStd::Wpkh(d) => d.compr_keyset(terminal),
DescriptorStd::TrKey(d) => d.compr_keyset(terminal),
StdDescr::Wpkh(d) => d.compr_keyset(terminal),
StdDescr::TrKey(d) => d.compr_keyset(terminal),
}
}

fn xonly_keyset(&self, terminal: Terminal) -> IndexMap<XOnlyPk, TapDerivation> {
match self {
DescriptorStd::Wpkh(d) => d.xonly_keyset(terminal),
DescriptorStd::TrKey(d) => d.xonly_keyset(terminal),
StdDescr::Wpkh(d) => d.xonly_keyset(terminal),
StdDescr::TrKey(d) => d.xonly_keyset(terminal),
}
}
}
4 changes: 2 additions & 2 deletions descriptors/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use bpstd::{Address, AddressError, AddressNetwork, DeriveScripts, Idx, NormalIndex};
use bpstd::{Address, AddressError, AddressNetwork, DeriveScripts, Idx, Keychain, NormalIndex};

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct AddressFactory<D: DeriveScripts> {
pub descriptor: D,
pub network: AddressNetwork,
pub keychain: u8,
pub keychain: Keychain,
pub unused_tip: NormalIndex,
}

Expand Down
2 changes: 1 addition & 1 deletion descriptors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod multisig;
mod segwit;
mod taproot;

pub use descriptor::{Descriptor, DescriptorStd};
pub use descriptor::{Descriptor, StdDescr};
pub use factory::AddressFactory;
pub use segwit::Wpkh;
pub use taproot::TrKey;
17 changes: 12 additions & 5 deletions descriptors/src/segwit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeSet;
use std::iter;
use std::ops::Range;

use bpstd::{
CompressedPk, Derive, DeriveCompr, DerivedScript, KeyOrigin, NormalIndex, ScriptPubkey,
TapDerivation, Terminal, WPubkeyHash, XOnlyPk, XpubDerivable, XpubSpec,
CompressedPk, Derive, DeriveCompr, DerivedScript, KeyOrigin, Keychain, NormalIndex,
ScriptPubkey, TapDerivation, Terminal, WPubkeyHash, XOnlyPk, XpubDerivable, XpubSpec,
};
use indexmap::IndexMap;

Expand All @@ -42,9 +42,16 @@ impl<K: DeriveCompr> Wpkh<K> {

impl<K: DeriveCompr> Derive<DerivedScript> for Wpkh<K> {
#[inline]
fn keychains(&self) -> Range<u8> { self.0.keychains() }
fn default_keychain(&self) -> Keychain { self.0.default_keychain() }

fn derive(&self, keychain: u8, index: impl Into<NormalIndex>) -> DerivedScript {
#[inline]
fn keychains(&self) -> BTreeSet<Keychain> { self.0.keychains() }

fn derive(
&self,
keychain: impl Into<Keychain>,
index: impl Into<NormalIndex>,
) -> DerivedScript {
let key = self.0.derive(keychain, index);
DerivedScript::Bare(ScriptPubkey::p2wpkh(WPubkeyHash::from(key)))
}
Expand Down
15 changes: 11 additions & 4 deletions descriptors/src/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeSet;
use std::iter;
use std::ops::Range;

use bpstd::{
CompressedPk, Derive, DeriveXOnly, DerivedScript, InternalPk, KeyOrigin, NormalIndex,
CompressedPk, Derive, DeriveXOnly, DerivedScript, InternalPk, KeyOrigin, Keychain, NormalIndex,
TapDerivation, Terminal, XOnlyPk, XpubDerivable, XpubSpec,
};
use indexmap::IndexMap;
Expand All @@ -42,9 +42,16 @@ impl<K: DeriveXOnly> TrKey<K> {

impl<K: DeriveXOnly> Derive<DerivedScript> for TrKey<K> {
#[inline]
fn keychains(&self) -> Range<u8> { self.0.keychains() }
fn default_keychain(&self) -> Keychain { self.0.default_keychain() }

fn derive(&self, keychain: u8, index: impl Into<NormalIndex>) -> DerivedScript {
#[inline]
fn keychains(&self) -> BTreeSet<Keychain> { self.0.keychains() }

fn derive(
&self,
keychain: impl Into<Keychain>,
index: impl Into<NormalIndex>,
) -> DerivedScript {
let internal_key = self.0.derive(keychain, index);
DerivedScript::TaprootKeyOnly(InternalPk::from_unchecked(internal_key))
}
Expand Down
2 changes: 1 addition & 1 deletion psbt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ amplify = { workspace = true }
bp-std = { workspace = true }
descriptors = { workspace = true }
indexmap = { workspace = true }
base64 = "0.21.4"
base64 = "0.21.5"
chrono = "0.4.31"
serde_crate = { workspace = true, optional = true }

Expand Down
Loading

0 comments on commit a200597

Please sign in to comment.