mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-03 05:43:08 +00:00
fix: suggestions 2
This commit is contained in:
parent
fc531021fb
commit
77570c48e9
@ -49,9 +49,15 @@ impl Display for ChainIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ChainIndex {
|
||||
fn default() -> Self {
|
||||
ChainIndex::from_str("/").expect("Root parsing failure")
|
||||
}
|
||||
}
|
||||
|
||||
impl ChainIndex {
|
||||
pub fn root() -> Self {
|
||||
ChainIndex::from_str("/").unwrap()
|
||||
ChainIndex::default()
|
||||
}
|
||||
|
||||
pub fn chain(&self) -> &[u32] {
|
||||
@ -95,6 +101,23 @@ mod tests {
|
||||
assert_eq!(chain_id.chain(), &[257]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chain_id_deser_failure_no_root() {
|
||||
let chain_index_error = ChainIndex::from_str("257").err().unwrap();
|
||||
|
||||
assert!(matches!(chain_index_error, ChainIndexError::NoRootFound));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chain_id_deser_failure_int_parsing_failure() {
|
||||
let chain_index_error = ChainIndex::from_str("/hello").err().unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
chain_index_error,
|
||||
ChainIndexError::ParseIntError(_)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chain_id_next_in_line_correct() {
|
||||
let chain_id = ChainIndex::from_str("/257").unwrap();
|
||||
|
||||
@ -20,8 +20,14 @@ impl KeyNode for ChildKeysPrivate {
|
||||
fn root(seed: [u8; 64]) -> Self {
|
||||
let hash_value = hmac_sha512::HMAC::mac(seed, "NSSA_master_priv");
|
||||
|
||||
let ssk = SecretSpendingKey(*hash_value.first_chunk::<32>().unwrap());
|
||||
let ccc = *hash_value.last_chunk::<32>().unwrap();
|
||||
let ssk = SecretSpendingKey(
|
||||
*hash_value
|
||||
.first_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get first 32"),
|
||||
);
|
||||
let ccc = *hash_value
|
||||
.last_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
||||
|
||||
let nsk = ssk.generate_nullifier_secret_key();
|
||||
let isk = ssk.generate_incoming_viewing_secret_key();
|
||||
@ -57,9 +63,9 @@ impl KeyNode for ChildKeysPrivate {
|
||||
.outgoing_viewing_secret_key
|
||||
.into(),
|
||||
)
|
||||
.unwrap()
|
||||
.expect("Key generated as scalar, must be valid representation")
|
||||
+ Scalar::from_repr(self.value.0.private_key_holder.nullifier_secret_key.into())
|
||||
.unwrap()
|
||||
.expect("Key generated as scalar, must be valid representation")
|
||||
* Scalar::from_repr(
|
||||
self.value
|
||||
.0
|
||||
@ -67,7 +73,7 @@ impl KeyNode for ChildKeysPrivate {
|
||||
.incoming_viewing_secret_key
|
||||
.into(),
|
||||
)
|
||||
.unwrap();
|
||||
.expect("Key generated as scalar, must be valid representation");
|
||||
let mut input = vec![];
|
||||
|
||||
input.extend_from_slice(b"NSSA_seed_priv");
|
||||
@ -76,8 +82,14 @@ impl KeyNode for ChildKeysPrivate {
|
||||
|
||||
let hash_value = hmac_sha512::HMAC::mac(input, self.ccc);
|
||||
|
||||
let ssk = SecretSpendingKey(*hash_value.first_chunk::<32>().unwrap());
|
||||
let ccc = *hash_value.last_chunk::<32>().unwrap();
|
||||
let ssk = SecretSpendingKey(
|
||||
*hash_value
|
||||
.first_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get first 32"),
|
||||
);
|
||||
let ccc = *hash_value
|
||||
.last_chunk::<32>()
|
||||
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
||||
|
||||
let nsk = ssk.generate_nullifier_secret_key();
|
||||
let isk = ssk.generate_incoming_viewing_secret_key();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user