X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Ftest_utils.rs;h=701eb69c3e15b6a96db097859dde46d0072fa953;hb=407762446cd4abaab5ea9c1c96e8c181a0f63b86;hp=26c0d051223a6c26787055257a187fdfd95f1da7;hpb=56b0c9683864d6860aa117b80470eda64e104854;p=rust-lightning diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index 26c0d051..701eb69c 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -9,43 +9,48 @@ //! 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::convert::{AsRef, Infallible}; use core::time::Duration; 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::offers::merkle::TaggedHash; -pub(super) fn payer_keys() -> KeyPair { +pub(crate) fn fail_sign>(_message: &T) -> Result { + Err(()) +} + +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 +63,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 +102,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] {