2021-02-17 21:33:50 -05:00
|
|
|
use crate::bitcoin::Scalar;
|
2022-09-13 08:19:58 -04:00
|
|
|
use ecdsa_fun::fun::marker::{NonZero, Secret};
|
2021-02-17 21:33:50 -05:00
|
|
|
|
|
|
|
pub trait ScalarExt {
|
|
|
|
fn to_secpfun_scalar(&self) -> ecdsa_fun::fun::Scalar;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ScalarExt for crate::monero::Scalar {
|
|
|
|
fn to_secpfun_scalar(&self) -> Scalar<Secret, NonZero> {
|
|
|
|
let mut little_endian_bytes = self.to_bytes();
|
|
|
|
|
|
|
|
little_endian_bytes.reverse();
|
|
|
|
let big_endian_bytes = little_endian_bytes;
|
|
|
|
|
|
|
|
ecdsa_fun::fun::Scalar::from_bytes(big_endian_bytes)
|
|
|
|
.expect("valid scalar")
|
2022-09-13 08:19:58 -04:00
|
|
|
.non_zero()
|
2021-02-17 21:33:50 -05:00
|
|
|
.expect("non-zero scalar")
|
|
|
|
}
|
|
|
|
}
|