mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-04-18 17:13:10 +00:00
fixed cssk to use k256
This commit is contained in:
parent
900b7b8d53
commit
b53f02bf24
@ -21,7 +21,7 @@ impl ChildKeysPublic {
|
|||||||
// Non-harden.
|
// Non-harden.
|
||||||
// BIP-032 compatibility requires 1-byte header from the public_key;
|
// BIP-032 compatibility requires 1-byte header from the public_key;
|
||||||
// Not stored in `self.cpk.value()`.
|
// Not stored in `self.cpk.value()`.
|
||||||
let sk = k256::SecretKey::from_bytes(self.csk.value().into())
|
let sk = k256::SecretKey::from_bytes(self.cssk.value().into())
|
||||||
.expect("32 bytes, within curve order");
|
.expect("32 bytes, within curve order");
|
||||||
let pk = sk.public_key();
|
let pk = sk.public_key();
|
||||||
hash_input.extend_from_slice(pk.to_encoded_point(true).as_bytes());
|
hash_input.extend_from_slice(pk.to_encoded_point(true).as_bytes());
|
||||||
@ -65,42 +65,25 @@ impl KeyNode for ChildKeysPublic {
|
|||||||
fn nth_child(&self, cci: u32) -> Self {
|
fn nth_child(&self, cci: u32) -> Self {
|
||||||
let hash_value = self.compute_hash_value(cci);
|
let hash_value = self.compute_hash_value(cci);
|
||||||
|
|
||||||
let cssk = secp256k1::SecretKey::from_byte_array(
|
let cssk = nssa::PrivateKey::try_new(
|
||||||
*hash_value
|
(k256::Scalar::from_repr(
|
||||||
.first_chunk::<32>()
|
(*hash_value
|
||||||
.expect("hash_value is 64 bytes, must be safe to get first 32"),
|
.first_chunk::<32>()
|
||||||
|
.expect("hash_value is 64 bytes, must be safe to get first 32"))
|
||||||
|
.into(),
|
||||||
|
)
|
||||||
|
.expect("Expect a valid k256 scalar"))
|
||||||
|
.add(
|
||||||
|
&k256::Scalar::from_repr((*self.cssk.value()).into())
|
||||||
|
.expect("Expect a valid k256 scalar"),
|
||||||
|
)
|
||||||
|
.to_bytes()
|
||||||
|
.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
|
||||||
/*
|
|
||||||
let cssk = nssa::PrivateKey::try_new({
|
|
||||||
cssk.add_tweak(&Scalar::from_be_bytes(*self.cssk.value()).unwrap())
|
|
||||||
.expect("Expect a valid Scalar")
|
|
||||||
.secret_bytes()
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let csk = nssa::PrivateKey::tweak(cssk.value()).unwrap();
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
secp256k1::constants::CURVE_ORDER >= *csk.value(),
|
|
||||||
"Secret key cannot exceed curve order"
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
let csk = nssa::PrivateKey::try_new({
|
|
||||||
let hash_value = hash_value
|
|
||||||
.first_chunk::<32>()
|
|
||||||
.expect("hash_value is 64 bytes, must be safe to get first 32");
|
|
||||||
|
|
||||||
let value_1 =
|
|
||||||
k256::Scalar::from_repr((*hash_value).into()).expect("Expect a valid k256 scalar");
|
|
||||||
let value_2 = k256::Scalar::from_repr((*self.csk.value()).into())
|
|
||||||
.expect("Expect a valid k256 scalar");
|
|
||||||
|
|
||||||
let sum = value_1.add(&value_2);
|
|
||||||
sum.to_bytes().into()
|
|
||||||
})
|
|
||||||
.expect("Expect a valid private key");
|
.expect("Expect a valid private key");
|
||||||
|
|
||||||
|
let csk = nssa::PrivateKey::tweak(cssk.value()).expect("Expect a valid Private Key");
|
||||||
|
|
||||||
let ccc = *hash_value
|
let ccc = *hash_value
|
||||||
.last_chunk::<32>()
|
.last_chunk::<32>()
|
||||||
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
.expect("hash_value is 64 bytes, must be safe to get last 32");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user