assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), None);
let res = tree.increment_last_index(ScriptType::External).unwrap();
- assert_eq!(res, 1337);
+ assert_eq!(res, 1338);
let res = tree.increment_last_index(ScriptType::Internal).unwrap();
assert_eq!(res, 0);
tree.get_last_index(ScriptType::External).unwrap(),
Some(1338)
);
- assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), Some(1));
+ assert_eq!(tree.get_last_index(ScriptType::Internal).unwrap(), Some(0));
}
// TODO: more tests...
let path_as_vec: Vec<ChildNumber> = path.clone().into();
final_path.extend_from_slice(&path_as_vec);
}
+ let our_path: Vec<ChildNumber> = self.path_with_index(index).into();
+ final_path.extend_from_slice(&our_path);
+
+ final_path.into()
+ }
+
+ pub fn path_with_index(&self, index: u32) -> DerivationPath {
+ let mut final_path: Vec<ChildNumber> = Vec::new();
let our_path: Vec<ChildNumber> = self.path.clone().into();
final_path.extend_from_slice(&our_path);
let other_path: Vec<ChildNumber> = self.final_index.as_path(index).into();
final_path.into()
}
+
pub fn derive<C: secp256k1::Verification + secp256k1::Signing>(
&self,
ctx: &secp256k1::Secp256k1<C>,
index: u32,
) -> Result<ExtendedPubKey, super::Error> {
if let Some(xprv) = self.secret {
- let derive_priv = xprv.derive_priv(ctx, &self.full_path(index))?;
+ let derive_priv = xprv.derive_priv(ctx, &self.path_with_index(index))?;
Ok(ExtendedPubKey::from_private(ctx, &derive_priv))
} else {
- Ok(self.pubkey.derive_pub(ctx, &self.full_path(index))?)
+ Ok(self.pubkey.derive_pub(ctx, &self.path_with_index(index))?)
}
}
.to_string(),
"mqwpxxvfv3QbM8PU8uBx2jaNt9btQqvQNx"
);
- assert_eq!(desc.get_secret_keys().len(), 1);
+ assert_eq!(desc.get_secret_keys().into_iter().collect::<Vec<_>>().len(), 1);
}
#[test]
.to_string(),
"mqwpxxvfv3QbM8PU8uBx2jaNt9btQqvQNx"
);
- assert_eq!(desc.get_secret_keys().len(), 0);
+ assert_eq!(desc.get_secret_keys().into_iter().collect::<Vec<_>>().len(), 0);
}
#[test]
.to_string(),
"mhtuS1QaEV4HPcK4bWk4Wvpd64SUjiC5Zt"
);
- assert_eq!(desc.get_xprv().len(), 0);
+ assert_eq!(desc.get_xprv().into_iter().collect::<Vec<_>>().len(), 0);
}
#[test]