1
1
//! Transparent key components.
2
2
3
- use alloc:: string:: ToString ;
4
- use alloc:: vec:: Vec ;
5
- use bip32:: {
6
- ChildNumber , ExtendedKey , ExtendedKeyAttrs , ExtendedPrivateKey , ExtendedPublicKey , Prefix ,
7
- } ;
8
- use secp256k1:: PublicKey ;
9
- use sha2:: { Digest , Sha256 } ;
3
+ use bip32:: ChildNumber ;
10
4
use subtle:: { Choice , ConstantTimeEq } ;
11
5
12
- use zcash_protocol:: consensus:: { self , NetworkConstants } ;
13
- use zcash_spec:: PrfExpand ;
14
- use zip32:: AccountId ;
15
-
16
- use crate :: address:: TransparentAddress ;
6
+ #[ cfg( feature = "transparent-inputs" ) ]
7
+ use {
8
+ crate :: address:: TransparentAddress ,
9
+ alloc:: string:: ToString ,
10
+ alloc:: vec:: Vec ,
11
+ bip32:: { ExtendedKey , ExtendedKeyAttrs , ExtendedPrivateKey , ExtendedPublicKey , Prefix } ,
12
+ secp256k1:: PublicKey ,
13
+ sha2:: { Digest , Sha256 } ,
14
+ zcash_protocol:: consensus:: { self , NetworkConstants } ,
15
+ zcash_spec:: PrfExpand ,
16
+ zip32:: AccountId ,
17
+ } ;
17
18
18
19
/// The scope of a transparent key.
19
20
///
@@ -123,8 +124,10 @@ impl From<NonHardenedChildIndex> for ChildNumber {
123
124
///
124
125
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
125
126
#[ derive( Clone , Debug ) ]
127
+ #[ cfg( feature = "transparent-inputs" ) ]
126
128
pub struct AccountPrivKey ( ExtendedPrivateKey < secp256k1:: SecretKey > ) ;
127
129
130
+ #[ cfg( feature = "transparent-inputs" ) ]
128
131
impl AccountPrivKey {
129
132
/// Performs derivation of the extended private key for the BIP44 path:
130
133
/// `m/44'/<coin_type>'/<account>'`.
@@ -221,9 +224,11 @@ impl AccountPrivKey {
221
224
/// full viewing key.
222
225
///
223
226
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
227
+ #[ cfg( feature = "transparent-inputs" ) ]
224
228
#[ derive( Clone , Debug ) ]
225
229
pub struct AccountPubKey ( ExtendedPublicKey < PublicKey > ) ;
226
230
231
+ #[ cfg( feature = "transparent-inputs" ) ]
227
232
impl AccountPubKey {
228
233
/// Derives the BIP44 public key at the external "change level" path
229
234
/// `m/44'/<coin_type>'/<account>'/0`.
@@ -344,13 +349,15 @@ impl AccountPubKey {
344
349
}
345
350
346
351
/// Derives the P2PKH transparent address corresponding to the given pubkey.
352
+ #[ cfg( feature = "transparent-inputs" ) ]
347
353
#[ deprecated( note = "This function will be removed from the public API in an upcoming refactor." ) ]
348
354
pub fn pubkey_to_address ( pubkey : & secp256k1:: PublicKey ) -> TransparentAddress {
349
355
TransparentAddress :: PublicKeyHash (
350
356
* ripemd:: Ripemd160 :: digest ( Sha256 :: digest ( pubkey. serialize ( ) ) ) . as_ref ( ) ,
351
357
)
352
358
}
353
359
360
+ #[ cfg( feature = "transparent-inputs" ) ]
354
361
pub ( crate ) mod private {
355
362
use super :: TransparentKeyScope ;
356
363
use bip32:: ExtendedPublicKey ;
@@ -377,6 +384,7 @@ pub(crate) mod private {
377
384
///
378
385
/// [BIP32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
379
386
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
387
+ #[ cfg( feature = "transparent-inputs" ) ]
380
388
pub trait IncomingViewingKey : private:: SealedChangeLevelKey + core:: marker:: Sized {
381
389
/// Derives a transparent address at the provided child index.
382
390
#[ allow( deprecated) ]
@@ -438,9 +446,11 @@ pub trait IncomingViewingKey: private::SealedChangeLevelKey + core::marker::Size
438
446
/// This allows derivation of child addresses that may be provided to external parties.
439
447
///
440
448
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
449
+ #[ cfg( feature = "transparent-inputs" ) ]
441
450
#[ derive( Clone , Debug ) ]
442
451
pub struct ExternalIvk ( ExtendedPublicKey < PublicKey > ) ;
443
452
453
+ #[ cfg( feature = "transparent-inputs" ) ]
444
454
impl private:: SealedChangeLevelKey for ExternalIvk {
445
455
const SCOPE : TransparentKeyScope = TransparentKeyScope ( 0 ) ;
446
456
@@ -453,6 +463,7 @@ impl private::SealedChangeLevelKey for ExternalIvk {
453
463
}
454
464
}
455
465
466
+ #[ cfg( feature = "transparent-inputs" ) ]
456
467
impl IncomingViewingKey for ExternalIvk { }
457
468
458
469
/// An incoming viewing key at the [BIP44] "internal" path
@@ -462,9 +473,11 @@ impl IncomingViewingKey for ExternalIvk {}
462
473
/// not be shared with external parties.
463
474
///
464
475
/// [BIP44]: https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
476
+ #[ cfg( feature = "transparent-inputs" ) ]
465
477
#[ derive( Clone , Debug ) ]
466
478
pub struct InternalIvk ( ExtendedPublicKey < PublicKey > ) ;
467
479
480
+ #[ cfg( feature = "transparent-inputs" ) ]
468
481
impl private:: SealedChangeLevelKey for InternalIvk {
469
482
const SCOPE : TransparentKeyScope = TransparentKeyScope ( 1 ) ;
470
483
@@ -477,12 +490,14 @@ impl private::SealedChangeLevelKey for InternalIvk {
477
490
}
478
491
}
479
492
493
+ #[ cfg( feature = "transparent-inputs" ) ]
480
494
impl IncomingViewingKey for InternalIvk { }
481
495
482
496
/// An incoming viewing key at the "ephemeral" path
483
497
/// `m/44'/<coin_type>'/<account>'/2`.
484
498
///
485
499
/// This allows derivation of ephemeral addresses for use within the wallet.
500
+ #[ cfg( feature = "transparent-inputs" ) ]
486
501
#[ derive( Clone , Debug ) ]
487
502
pub struct EphemeralIvk ( ExtendedPublicKey < PublicKey > ) ;
488
503
0 commit comments