mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
Wallet spending key derivation path
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -511,6 +511,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_client_backend"
|
name = "zcash_client_backend"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"zcash_primitives 0.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_primitives"
|
name = "zcash_primitives"
|
||||||
|
@@ -7,3 +7,4 @@ authors = [
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
zcash_primitives = { path = "../zcash_primitives" }
|
||||||
|
4
zcash_client_backend/src/constants.rs
Normal file
4
zcash_client_backend/src/constants.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
//! Zcash global and per-network constants.
|
||||||
|
|
||||||
|
pub mod mainnet;
|
||||||
|
pub mod testnet;
|
4
zcash_client_backend/src/constants/mainnet.rs
Normal file
4
zcash_client_backend/src/constants/mainnet.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/// The mainnet coin type for ZEC, as defined by [SLIP 44].
|
||||||
|
///
|
||||||
|
/// [SLIP 44]: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
|
pub const COIN_TYPE: u32 = 133;
|
4
zcash_client_backend/src/constants/testnet.rs
Normal file
4
zcash_client_backend/src/constants/testnet.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/// The testnet coin type for ZEC, as defined by [SLIP 44].
|
||||||
|
///
|
||||||
|
/// [SLIP 44]: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
|
pub const COIN_TYPE: u32 = 1;
|
24
zcash_client_backend/src/keys.rs
Normal file
24
zcash_client_backend/src/keys.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//! Helper functions for managing light client key material.
|
||||||
|
|
||||||
|
use zcash_primitives::zip32::{ChildIndex, ExtendedSpendingKey};
|
||||||
|
|
||||||
|
/// Derives the ZIP 32 [`ExtendedSpendingKey`] for a given coin type and account from the
|
||||||
|
/// given seed.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use zcash_client_backend::{constants::testnet::COIN_TYPE, keys::spending_key};
|
||||||
|
///
|
||||||
|
/// let extsk = spending_key(&[0; 32][..], COIN_TYPE, 0);
|
||||||
|
/// ```
|
||||||
|
pub fn spending_key(seed: &[u8], coin_type: u32, account: u32) -> ExtendedSpendingKey {
|
||||||
|
ExtendedSpendingKey::from_path(
|
||||||
|
&ExtendedSpendingKey::master(&seed),
|
||||||
|
&[
|
||||||
|
ChildIndex::Hardened(32),
|
||||||
|
ChildIndex::Hardened(coin_type),
|
||||||
|
ChildIndex::Hardened(account),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
}
|
@@ -3,10 +3,5 @@
|
|||||||
//! `zcash_client_backend` contains Rust structs and traits for creating shielded Zcash
|
//! `zcash_client_backend` contains Rust structs and traits for creating shielded Zcash
|
||||||
//! light clients.
|
//! light clients.
|
||||||
|
|
||||||
#[cfg(test)]
|
pub mod constants;
|
||||||
mod tests {
|
pub mod keys;
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
assert_eq!(2 + 2, 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user