mirror of https://github.com/zcash/zip32.git
Enforce documentation and no unsafe code
This commit is contained in:
parent
feea7316ea
commit
ea3e731868
|
@ -1,18 +1,21 @@
|
|||
//! Seed Fingerprints according to ZIP 32
|
||||
//!
|
||||
//! Implements section `Seed Fingerprints` of Shielded Hierarchical Deterministic Wallets (ZIP 32)
|
||||
//! Implements section [Seed Fingerprints] of Shielded Hierarchical Deterministic Wallets (ZIP 32).
|
||||
//!
|
||||
//! [Section Seed Fingerprints]: https://zips.z.cash/zip-0032#seed-fingerprints
|
||||
//! [Seed Fingerprints]: https://zips.z.cash/zip-0032#seed-fingerprints
|
||||
use blake2b_simd::Params as Blake2bParams;
|
||||
|
||||
pub const ZIP32_SEED_FP_PERSONALIZATION: &[u8; 16] = b"Zcash_HD_Seed_FP";
|
||||
const ZIP32_SEED_FP_PERSONALIZATION: &[u8; 16] = b"Zcash_HD_Seed_FP";
|
||||
|
||||
/// The fingerprint for a wallet's seed bytes, as defined in [ZIP 32].
|
||||
///
|
||||
/// [ZIP 32]: https://zips.z.cash/zip-0032#seed-fingerprints
|
||||
pub struct SeedFingerprint([u8; 32]);
|
||||
|
||||
impl SeedFingerprint {
|
||||
/// Return the seed fingerprint of the wallet as defined in
|
||||
/// <https://zips.z.cash/zip-0032#seed-fingerprints> or None
|
||||
/// if the length of `seed_bytes` is less than 32 or
|
||||
/// greater than 252.
|
||||
/// Derives the fingerprint of the given seed bytes.
|
||||
///
|
||||
/// Returns `None` if the length of `seed_bytes` is less than 32 or greater than 252.
|
||||
pub fn from_seed(seed_bytes: &[u8]) -> Option<SeedFingerprint> {
|
||||
let seed_len = seed_bytes.len();
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
//!
|
||||
//! [ZIP 32]: https://zips.z.cash/zip-0032
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(rustdoc::broken_intra_doc_links)]
|
||||
|
||||
use memuse::{self, DynamicUsage};
|
||||
|
@ -94,6 +96,7 @@ impl ChainCode {
|
|||
}
|
||||
}
|
||||
|
||||
/// The index for a particular diversifier.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct DiversifierIndex(pub [u8; 11]);
|
||||
|
||||
|
@ -128,10 +131,12 @@ impl TryFrom<DiversifierIndex> for u32 {
|
|||
}
|
||||
|
||||
impl DiversifierIndex {
|
||||
/// Constructs the zero index.
|
||||
pub fn new() -> Self {
|
||||
DiversifierIndex([0; 11])
|
||||
}
|
||||
|
||||
/// Increments this index, failing on overflow.
|
||||
pub fn increment(&mut self) -> Result<(), ()> {
|
||||
for k in 0..11 {
|
||||
self.0[k] = self.0[k].wrapping_add(1);
|
||||
|
|
Loading…
Reference in New Issue