X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Ftest_utils.rs;h=b4329803016fadb395689bf696e30d78c2984e97;hb=ae0d825d89ca0ac2489737d1b413e778650b093c;hp=43664079dbd55580b224f1926e017525c85c9249;hpb=dd2ccd232234d93c482c333b20dc71d53c4b7247;p=rust-lightning diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 43664079..b4329803 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -9,43 +9,51 @@ //! Utilities for testing BOLT 12 Offers interfaces -use bitcoin::secp256k1::{KeyPair, Message, PublicKey, Secp256k1, SecretKey}; +use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey}; use bitcoin::secp256k1::schnorr::Signature; -use core::convert::Infallible; + use core::time::Duration; -use crate::chain::keysinterface::EntropySource; +use crate::blinded_path::{BlindedHop, BlindedPath}; +use crate::sign::EntropySource; use crate::ln::PaymentHash; use crate::ln::features::BlindedHopFeatures; use crate::offers::invoice::BlindedPayInfo; -use crate::onion_message::{BlindedHop, BlindedPath}; +use crate::offers::merkle::TaggedHash; + +#[allow(unused_imports)] +use crate::prelude::*; + +pub(crate) fn fail_sign>(_message: &T) -> Result { + Err(()) +} -pub(super) fn payer_keys() -> KeyPair { +pub(crate) fn payer_keys() -> KeyPair { let secp_ctx = Secp256k1::new(); KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()) } -pub(super) fn payer_sign(digest: &Message) -> Result { +pub(crate) fn payer_sign>(message: &T) -> Result { let secp_ctx = Secp256k1::new(); let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); - Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys)) + Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys)) } -pub(super) fn payer_pubkey() -> PublicKey { +pub(crate) fn payer_pubkey() -> PublicKey { payer_keys().public_key() } -pub(super) fn recipient_keys() -> KeyPair { +pub(crate) fn recipient_keys() -> KeyPair { let secp_ctx = Secp256k1::new(); KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[43; 32]).unwrap()) } -pub(super) fn recipient_sign(digest: &Message) -> Result { +pub(crate) fn recipient_sign>(message: &T) -> Result { let secp_ctx = Secp256k1::new(); let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[43; 32]).unwrap()); - Ok(secp_ctx.sign_schnorr_no_aux_rand(digest, &keys)) + Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys)) } -pub(super) fn recipient_pubkey() -> PublicKey { +pub(crate) fn recipient_pubkey() -> PublicKey { recipient_keys().public_key() } @@ -58,7 +66,7 @@ pub(super) fn privkey(byte: u8) -> SecretKey { SecretKey::from_slice(&[byte; 32]).unwrap() } -pub(super) fn payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> { +pub(crate) fn payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { let paths = vec![ BlindedPath { introduction_node_id: pubkey(40), @@ -97,20 +105,20 @@ pub(super) fn payment_paths() -> Vec<(BlindedPath, BlindedPayInfo)> { }, ]; - paths.into_iter().zip(payinfo.into_iter()).collect() + payinfo.into_iter().zip(paths.into_iter()).collect() } -pub(super) fn payment_hash() -> PaymentHash { +pub(crate) fn payment_hash() -> PaymentHash { PaymentHash([42; 32]) } -pub(super) fn now() -> Duration { +pub(crate) fn now() -> Duration { std::time::SystemTime::now() .duration_since(std::time::SystemTime::UNIX_EPOCH) .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH") } -pub(super) struct FixedEntropy; +pub(crate) struct FixedEntropy; impl EntropySource for FixedEntropy { fn get_secure_random_bytes(&self) -> [u8; 32] {