@@ -37,7 +37,7 @@ use elements::{secp256k1_zkp as secp256k1, secp256k1_zkp, Script, TxIn};
37
37
use { bitcoin, elements} ;
38
38
39
39
use self :: checksum:: verify_checksum;
40
- use crate :: extensions:: { CovExtArgs , ExtParam , NoExtParam } ;
40
+ use crate :: extensions:: { CovExtArgs , ExtParam , ParseableExt } ;
41
41
use crate :: miniscript:: { Legacy , Miniscript , Segwitv0 } ;
42
42
use crate :: {
43
43
expression, miniscript, BareCtx , CovenantExt , Error , Extension , ExtTranslator , ForEach , ForEachKey ,
@@ -245,42 +245,42 @@ pub enum Descriptor<Pk: MiniscriptKey, T: Extension = CovenantExt<CovExtArgs>> {
245
245
LegacyCSFSCov ( LegacyCSFSCov < Pk , T > ) ,
246
246
}
247
247
248
- impl < Pk : MiniscriptKey > From < Bare < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
248
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Bare < Pk > > for Descriptor < Pk , Ext > {
249
249
#[ inline]
250
250
fn from ( inner : Bare < Pk > ) -> Self {
251
251
Descriptor :: Bare ( inner)
252
252
}
253
253
}
254
254
255
- impl < Pk : MiniscriptKey > From < Pkh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
255
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Pkh < Pk > > for Descriptor < Pk , Ext > {
256
256
#[ inline]
257
257
fn from ( inner : Pkh < Pk > ) -> Self {
258
258
Descriptor :: Pkh ( inner)
259
259
}
260
260
}
261
261
262
- impl < Pk : MiniscriptKey > From < Wpkh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
262
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Wpkh < Pk > > for Descriptor < Pk , Ext > {
263
263
#[ inline]
264
264
fn from ( inner : Wpkh < Pk > ) -> Self {
265
265
Descriptor :: Wpkh ( inner)
266
266
}
267
267
}
268
268
269
- impl < Pk : MiniscriptKey > From < Sh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
269
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Sh < Pk > > for Descriptor < Pk , Ext > {
270
270
#[ inline]
271
271
fn from ( inner : Sh < Pk > ) -> Self {
272
272
Descriptor :: Sh ( inner)
273
273
}
274
274
}
275
275
276
- impl < Pk : MiniscriptKey > From < Wsh < Pk > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
276
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Wsh < Pk > > for Descriptor < Pk , Ext > {
277
277
#[ inline]
278
278
fn from ( inner : Wsh < Pk > ) -> Self {
279
279
Descriptor :: Wsh ( inner)
280
280
}
281
281
}
282
282
283
- impl < Pk : MiniscriptKey > From < Tr < Pk , NoExt > > for Descriptor < Pk , CovenantExt < NoExtParam > > {
283
+ impl < Pk : MiniscriptKey , Ext : Extension > From < Tr < Pk , NoExt > > for Descriptor < Pk , Ext > {
284
284
#[ inline]
285
285
fn from ( inner : Tr < Pk , NoExt > ) -> Self {
286
286
Descriptor :: Tr ( inner)
@@ -313,7 +313,7 @@ impl DescriptorType {
313
313
}
314
314
}
315
315
316
- impl < Pk : MiniscriptKey , Arg : ExtParam > Descriptor < Pk , CovenantExt < Arg > > {
316
+ impl < Pk : MiniscriptKey , Ext : Extension > Descriptor < Pk , Ext > {
317
317
// Keys
318
318
319
319
/// Create a new pk descriptor
@@ -419,7 +419,7 @@ impl<Pk: MiniscriptKey, Arg: ExtParam> Descriptor<Pk, CovenantExt<Arg>> {
419
419
/// Errors when miniscript exceeds resource limits under Tap context
420
420
pub fn new_tr_ext (
421
421
key : Pk ,
422
- script : Option < tr:: TapTree < Pk , CovenantExt < Arg > > > ,
422
+ script : Option < tr:: TapTree < Pk , Ext > > ,
423
423
) -> Result < Self , Error > {
424
424
Ok ( Descriptor :: TrExt ( Tr :: new ( key, script) ?) )
425
425
}
@@ -520,7 +520,7 @@ impl<Pk: MiniscriptKey, Arg: ExtParam> Descriptor<Pk, CovenantExt<Arg>> {
520
520
}
521
521
}
522
522
523
- impl < Pk : MiniscriptKey + ToPublicKey > Descriptor < Pk , CovenantExt < CovExtArgs > > {
523
+ impl < Pk : MiniscriptKey + ToPublicKey , Ext : Extension + ParseableExt > Descriptor < Pk , Ext > {
524
524
///
525
525
/// Obtains the blinded address for this descriptor
526
526
///
@@ -774,7 +774,7 @@ impl<Pk: MiniscriptKey, T: Extension> ForEachKey<Pk> for Descriptor<Pk, T> {
774
774
}
775
775
}
776
776
777
- impl Descriptor < DescriptorPublicKey > {
777
+ impl < Ext : Extension + ParseableExt > Descriptor < DescriptorPublicKey , Ext > {
778
778
/// Whether or not the descriptor has any wildcards
779
779
pub fn is_deriveable ( & self ) -> bool {
780
780
self . for_any_key ( |key| key. as_key ( ) . is_deriveable ( ) )
@@ -786,7 +786,7 @@ impl Descriptor<DescriptorPublicKey> {
786
786
///
787
787
/// In most cases, you would want to use [`Self::derived_descriptor`] directly to obtain
788
788
/// a [`Descriptor<bitcoin::PublicKey>`]
789
- pub fn derive ( & self , index : u32 ) -> Descriptor < DerivedDescriptorKey > {
789
+ pub fn derive ( & self , index : u32 ) -> Descriptor < DerivedDescriptorKey , Ext > {
790
790
struct Derivator ( u32 ) ;
791
791
792
792
impl Translator < DescriptorPublicKey , DerivedDescriptorKey , ( ) > for Derivator {
@@ -834,7 +834,7 @@ impl Descriptor<DescriptorPublicKey> {
834
834
& self ,
835
835
secp : & secp256k1_zkp:: Secp256k1 < C > ,
836
836
index : u32 ,
837
- ) -> Result < Descriptor < bitcoin:: PublicKey > , ConversionError > {
837
+ ) -> Result < Descriptor < bitcoin:: PublicKey , Ext > , ConversionError > {
838
838
struct Derivator < ' a , C : secp256k1:: Verification > ( & ' a secp256k1:: Secp256k1 < C > ) ;
839
839
840
840
impl < ' a , C : secp256k1:: Verification >
@@ -871,7 +871,7 @@ impl Descriptor<DescriptorPublicKey> {
871
871
pub fn parse_descriptor < C : secp256k1_zkp:: Signing > (
872
872
secp : & secp256k1_zkp:: Secp256k1 < C > ,
873
873
s : & str ,
874
- ) -> Result < ( Descriptor < DescriptorPublicKey > , KeyMap ) , Error > {
874
+ ) -> Result < ( Descriptor < DescriptorPublicKey , Ext > , KeyMap ) , Error > {
875
875
fn parse_key < C : secp256k1:: Signing > (
876
876
s : & String ,
877
877
key_map : & mut KeyMap ,
@@ -919,7 +919,7 @@ impl Descriptor<DescriptorPublicKey> {
919
919
}
920
920
}
921
921
922
- let descriptor = Descriptor :: < String > :: from_str ( s) ?;
922
+ let descriptor = Descriptor :: < String , Ext > :: from_str ( s) ?;
923
923
let descriptor = descriptor
924
924
. translate_pk ( & mut keymap_pk)
925
925
. map_err ( |e| Error :: Unexpected ( e. to_string ( ) ) ) ?;
@@ -960,7 +960,7 @@ impl Descriptor<DescriptorPublicKey> {
960
960
}
961
961
}
962
962
963
- impl Descriptor < DescriptorPublicKey , CovenantExt < CovExtArgs > > {
963
+ impl < Ext : Extension + ParseableExt > Descriptor < DescriptorPublicKey , Ext > {
964
964
/// Utility method for deriving the descriptor at each index in a range to find one matching
965
965
/// `script_pubkey`.
966
966
///
@@ -973,12 +973,11 @@ impl Descriptor<DescriptorPublicKey, CovenantExt<CovExtArgs>> {
973
973
secp : & secp256k1_zkp:: Secp256k1 < C > ,
974
974
script_pubkey : & Script ,
975
975
range : Range < u32 > ,
976
- ) -> Result < Option < ( u32 , Descriptor < bitcoin:: PublicKey , CovenantExt < CovExtArgs > > ) > , ConversionError > {
976
+ ) -> Result < Option < ( u32 , Descriptor < bitcoin:: PublicKey , Ext > ) > , ConversionError > {
977
977
let range = if self . is_deriveable ( ) { range } else { 0 ..1 } ;
978
978
979
979
for i in range {
980
980
let concrete = self . derived_descriptor ( secp, i) ?;
981
- println ! ( "{} {} {}" , i, & concrete, concrete. script_pubkey( ) ) ;
982
981
if & concrete. script_pubkey ( ) == script_pubkey {
983
982
return Ok ( Some ( ( i, concrete) ) ) ;
984
983
}
@@ -1416,7 +1415,7 @@ mod tests {
1416
1415
asset_issuance : elements:: AssetIssuance :: default ( ) ,
1417
1416
witness : elements:: TxInWitness :: default ( ) ,
1418
1417
} ;
1419
- let bare = Descriptor :: new_bare ( ms. clone ( ) ) . unwrap ( ) ;
1418
+ let bare: Descriptor < _ , NoExt > = Descriptor :: new_bare ( ms. clone ( ) ) . unwrap ( ) ;
1420
1419
1421
1420
bare. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1422
1421
assert_eq ! (
@@ -1428,7 +1427,7 @@ mod tests {
1428
1427
) ;
1429
1428
assert_eq ! ( bare. unsigned_script_sig( ) , elements:: Script :: new( ) ) ;
1430
1429
1431
- let pkh = Descriptor :: new_pkh ( pk) ;
1430
+ let pkh: Descriptor < _ , NoExt > = Descriptor :: new_pkh ( pk) ;
1432
1431
pkh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1433
1432
assert_eq ! (
1434
1433
txin,
@@ -1442,15 +1441,15 @@ mod tests {
1442
1441
) ;
1443
1442
assert_eq ! ( pkh. unsigned_script_sig( ) , elements:: Script :: new( ) ) ;
1444
1443
1445
- let wpkh = Descriptor :: new_wpkh ( pk) . unwrap ( ) ;
1444
+ let wpkh: Descriptor < _ , NoExt > = Descriptor :: new_wpkh ( pk) . unwrap ( ) ;
1446
1445
wpkh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1447
1446
assert_eq ! (
1448
1447
txin,
1449
1448
elements_txin( Script :: new( ) , vec![ sigser. clone( ) , pk. to_bytes( ) , ] )
1450
1449
) ;
1451
1450
assert_eq ! ( wpkh. unsigned_script_sig( ) , elements:: Script :: new( ) ) ;
1452
1451
1453
- let shwpkh = Descriptor :: new_sh_wpkh ( pk) . unwrap ( ) ;
1452
+ let shwpkh: Descriptor < _ , NoExt > = Descriptor :: new_sh_wpkh ( pk) . unwrap ( ) ;
1454
1453
shwpkh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1455
1454
let redeem_script = script:: Builder :: new ( )
1456
1455
. push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
@@ -1468,7 +1467,7 @@ mod tests {
1468
1467
assert_eq ! ( shwpkh. unsigned_script_sig( ) , expected_ssig) ;
1469
1468
1470
1469
let ms = ms_str ! ( "c:pk_k({})" , pk) ;
1471
- let sh = Descriptor :: new_sh ( ms. clone ( ) ) . unwrap ( ) ;
1470
+ let sh: Descriptor < _ , NoExt > = Descriptor :: new_sh ( ms. clone ( ) ) . unwrap ( ) ;
1472
1471
sh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1473
1472
let expected_ssig = script:: Builder :: new ( )
1474
1473
. push_slice ( & sigser[ ..] )
@@ -1479,7 +1478,7 @@ mod tests {
1479
1478
1480
1479
let ms = ms_str ! ( "c:pk_k({})" , pk) ;
1481
1480
1482
- let wsh = Descriptor :: new_wsh ( ms. clone ( ) ) . unwrap ( ) ;
1481
+ let wsh: Descriptor < _ , NoExt > = Descriptor :: new_wsh ( ms. clone ( ) ) . unwrap ( ) ;
1483
1482
wsh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1484
1483
assert_eq ! (
1485
1484
txin,
@@ -1490,7 +1489,7 @@ mod tests {
1490
1489
) ;
1491
1490
assert_eq ! ( wsh. unsigned_script_sig( ) , Script :: new( ) ) ;
1492
1491
1493
- let shwsh = Descriptor :: new_sh_wsh ( ms. clone ( ) ) . unwrap ( ) ;
1492
+ let shwsh: Descriptor < _ , NoExt > = Descriptor :: new_sh_wsh ( ms. clone ( ) ) . unwrap ( ) ;
1494
1493
shwsh. satisfy ( & mut txin, & satisfier) . expect ( "satisfaction" ) ;
1495
1494
let expected_ssig = script:: Builder :: new ( )
1496
1495
. push_slice ( & ms. encode ( ) . to_v0_p2wsh ( ) [ ..] )
@@ -1856,15 +1855,15 @@ mod tests {
1856
1855
#[ test]
1857
1856
fn test_parse_descriptor ( ) {
1858
1857
let secp = & secp256k1_zkp:: Secp256k1 :: signing_only ( ) ;
1859
- let ( descriptor, key_map) = Descriptor :: parse_descriptor ( secp, "elwpkh(tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/44'/0'/0'/0/*)" ) . unwrap ( ) ;
1858
+ let ( descriptor, key_map) = Descriptor :: < _ , NoExt > :: parse_descriptor ( secp, "elwpkh(tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/44'/0'/0'/0/*)" ) . unwrap ( ) ;
1860
1859
assert_eq ! ( descriptor. to_string( ) , "elwpkh([2cbe2a6d/44'/0'/0']tpubDCvNhURocXGZsLNqWcqD3syHTqPXrMSTwi8feKVwAcpi29oYKsDD3Vex7x2TDneKMVN23RbLprfxB69v94iYqdaYHsVz3kPR37NQXeqouVz/0/*)#pznhhta9" ) ;
1861
1860
assert_eq ! ( key_map. len( ) , 1 ) ;
1862
1861
1863
1862
// https://github.com/bitcoin/bitcoin/blob/7ae86b3c6845873ca96650fc69beb4ae5285c801/src/test/descriptor_tests.cpp#L355-L360
1864
1863
macro_rules! check_invalid_checksum {
1865
1864
( $secp: ident, $( $desc: expr) ,* ) => {
1866
1865
$(
1867
- match Descriptor :: parse_descriptor( $secp, $desc) {
1866
+ match Descriptor :: <_ , NoExt > :: parse_descriptor( $secp, $desc) {
1868
1867
Err ( Error :: BadDescriptor ( _) ) => { } ,
1869
1868
Err ( e) => panic!( "Expected bad checksum for {}, got '{}'" , $desc, e) ,
1870
1869
_ => panic!( "Invalid checksum treated as valid: {}" , $desc) ,
@@ -1886,8 +1885,8 @@ mod tests {
1886
1885
"elsh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))##tjq09x4t"
1887
1886
) ;
1888
1887
1889
- Descriptor :: parse_descriptor ( & secp, "elsh(multi(2,[00000000/111'/222]xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L/0))#9s2ngs7u" ) . expect ( "Valid descriptor with checksum" ) ;
1890
- Descriptor :: parse_descriptor ( & secp, "elsh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))#uklept69" ) . expect ( "Valid descriptor with checksum" ) ;
1888
+ Descriptor :: < _ , NoExt > :: parse_descriptor ( & secp, "elsh(multi(2,[00000000/111'/222]xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L/0))#9s2ngs7u" ) . expect ( "Valid descriptor with checksum" ) ;
1889
+ Descriptor :: < _ , NoExt > :: parse_descriptor ( & secp, "elsh(multi(2,[00000000/111'/222]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0))#uklept69" ) . expect ( "Valid descriptor with checksum" ) ;
1891
1890
}
1892
1891
1893
1892
#[ test]
@@ -1898,7 +1897,7 @@ pk([d34db33f/44'/0'/0']xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgb
1898
1897
pk(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1),\
1899
1898
pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
1900
1899
let policy: policy:: concrete:: Policy < DescriptorPublicKey > = descriptor_str. parse ( ) . unwrap ( ) ;
1901
- let descriptor = Descriptor :: new_sh ( policy. compile ( ) . unwrap ( ) ) . unwrap ( ) ;
1900
+ let descriptor = Descriptor :: < _ , NoExt > :: new_sh ( policy. compile ( ) . unwrap ( ) ) . unwrap ( ) ;
1902
1901
let derived_descriptor = descriptor. derive ( 42 ) ;
1903
1902
1904
1903
let res_descriptor_str = "thresh(2,\
@@ -1908,7 +1907,7 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
1908
1907
let res_policy: policy:: concrete:: Policy < DescriptorPublicKey > =
1909
1908
res_descriptor_str. parse ( ) . unwrap ( ) ;
1910
1909
let res_descriptor =
1911
- Descriptor :: < DescriptorPublicKey , CovenantExt < NoExtParam > > :: new_sh ( res_policy. compile ( ) . unwrap ( ) )
1910
+ Descriptor :: < DescriptorPublicKey , NoExt > :: new_sh ( res_policy. compile ( ) . unwrap ( ) )
1912
1911
. unwrap ( ) ;
1913
1912
1914
1913
assert_eq ! ( res_descriptor. to_string( ) , derived_descriptor. to_string( ) ) ;
@@ -1958,7 +1957,7 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
1958
1957
#[ test]
1959
1958
fn test_find_derivation_index_for_spk ( ) {
1960
1959
let secp = secp256k1_zkp:: Secp256k1 :: verification_only ( ) ;
1961
- let descriptor = Descriptor :: from_str ( "eltr([73c5da0a/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/*)" ) . unwrap ( ) ;
1960
+ let descriptor = Descriptor :: < _ , NoExt > :: from_str ( "eltr([73c5da0a/86'/0'/0']xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0/*)" ) . unwrap ( ) ;
1962
1961
let script_at_0_1 = Script :: from_str (
1963
1962
"5120c73ac1b7a518499b9642aed8cfa15d5401e5bd85ad760b937b69521c297722f0" ,
1964
1963
)
0 commit comments