Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/stratum-mining/stratum into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGab19 committed Jan 24, 2024
2 parents 583d23a + 2f034b3 commit 9eaf6d2
Show file tree
Hide file tree
Showing 76 changed files with 2,982 additions and 836 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ lcov.info
*.py
**/conf/**
cobertura.xml
/roles/*/*-config.toml
2 changes: 1 addition & 1 deletion protocols/v2/noise-sv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
secp256k1 = { version = "0.27.0", default-features = false, features =["bitcoin_hashes","alloc","rand","rand-std"] }
secp256k1 = { version = "0.28.1", default-features = false, features =["hashes", "alloc","rand","rand-std"] }
rand = {version = "0.8.5", default-features = false, features = ["std","std_rng"] }
aes-gcm = "0.10.2"
chacha20poly1305 = "0.10.1"
Expand Down
16 changes: 8 additions & 8 deletions protocols/v2/noise-sv2/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chacha20poly1305::ChaCha20Poly1305;
use secp256k1::{
ecdh::SharedSecret,
hashes::{sha256::Hash as Sha256Hash, Hash},
rand, KeyPair, Secp256k1, SecretKey, XOnlyPublicKey,
rand, Keypair, Secp256k1, SecretKey, XOnlyPublicKey,
};

pub trait HandshakeOp<Cipher: AeadCipher>: CipherState<Cipher> {
Expand All @@ -24,10 +24,10 @@ pub trait HandshakeOp<Cipher: AeadCipher>: CipherState<Cipher> {
*h = Sha256Hash::hash(&to_hash).to_byte_array();
}

fn generate_key() -> KeyPair {
fn generate_key() -> Keypair {
let secp = Secp256k1::new();
let (secret_key, _) = secp.generate_keypair(&mut rand::thread_rng());
let kp = KeyPair::from_secret_key(&secp, &secret_key);
let kp = Keypair::from_secret_key(&secp, &secret_key);
if kp.x_only_public_key().1 == crate::PARITY {
kp
} else {
Expand Down Expand Up @@ -348,9 +348,9 @@ mod test {
}

#[derive(Clone, Debug)]
struct KeyPairWrapper(pub Option<KeyPair>);
struct KeypairWrapper(pub Option<Keypair>);

impl Arbitrary for KeyPairWrapper {
impl Arbitrary for KeypairWrapper {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let secp = Secp256k1::new();
let mut secret = Vec::<u8>::arbitrary(g);
Expand All @@ -365,14 +365,14 @@ mod test {
assert!(secret.len() == 32);
let secret: [u8; 32] = secret.try_into().unwrap();
match SecretKey::from_slice(&secret) {
Ok(secret) => KeyPairWrapper(Some(KeyPair::from_secret_key(&secp, &secret))),
Err(_) => KeyPairWrapper(None),
Ok(secret) => KeypairWrapper(Some(Keypair::from_secret_key(&secp, &secret))),
Err(_) => KeypairWrapper(None),
}
}
}

#[quickcheck_macros::quickcheck]
fn test_ecdh_1(kp1: KeyPairWrapper, kp2: KeyPairWrapper) -> TestResult {
fn test_ecdh_1(kp1: KeypairWrapper, kp2: KeypairWrapper) -> TestResult {
let (kp1, kp2) = match (kp1.0, kp2.0) {
(Some(kp1), Some(kp2)) => (kp1, kp2),
_ => return TestResult::discard(),
Expand Down
4 changes: 2 additions & 2 deletions protocols/v2/noise-sv2/src/initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use aes_gcm::KeyInit;
use chacha20poly1305::ChaCha20Poly1305;
use secp256k1::{KeyPair, XOnlyPublicKey};
use secp256k1::{Keypair, XOnlyPublicKey};

pub struct Initiator {
handshake_cipher: Option<ChaCha20Poly1305>,
Expand All @@ -20,7 +20,7 @@ pub struct Initiator {
// Handshake hash
h: [u8; 32],
// ephemeral keypair
e: KeyPair,
e: Keypair,
// upstream pub key
#[allow(unused)]
pk: XOnlyPublicKey,
Expand Down
10 changes: 5 additions & 5 deletions protocols/v2/noise-sv2/src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use aes_gcm::KeyInit;
use chacha20poly1305::ChaCha20Poly1305;
use secp256k1::{KeyPair, Secp256k1, SecretKey};
use secp256k1::{Keypair, Secp256k1, SecretKey};

const VERSION: u16 = 0;

Expand All @@ -22,9 +22,9 @@ pub struct Responder {
// Handshake hash
h: [u8; 32],
// ephemeral keypair
e: KeyPair,
e: Keypair,
// Static pub keypair
s: KeyPair,
s: Keypair,
c1: Option<GenericCipher>,
c2: Option<GenericCipher>,
cert_validity: u32,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Responder {
) -> Result<Box<Self>, Error> {
let secp = Secp256k1::new();
let secret = SecretKey::from_slice(private).map_err(|_| Error::InvalidRawPrivateKey)?;
let kp = KeyPair::from_secret_key(&secp, &secret);
let kp = Keypair::from_secret_key(&secp, &secret);
let pub_ = kp.x_only_public_key().0.serialize();
if public == &pub_[..] {
Ok(Self::new(kp, cert_validity.as_secs() as u32))
Expand All @@ -103,7 +103,7 @@ impl Responder {
}
}

pub fn new(s: KeyPair, cert_validity: u32) -> Box<Self> {
pub fn new(s: Keypair, cert_validity: u32) -> Box<Self> {
let mut self_ = Self {
handshake_cipher: None,
k: None,
Expand Down
4 changes: 2 additions & 2 deletions protocols/v2/noise-sv2/src/signature_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use secp256k1::{hashes::sha256, schnorr::Signature, KeyPair, Message, Secp256k1, XOnlyPublicKey};
use secp256k1::{hashes::sha256, schnorr::Signature, Keypair, Message, Secp256k1, XOnlyPublicKey};
use std::{convert::TryInto, time::SystemTime};

pub struct SignatureNoiseMessage {
Expand Down Expand Up @@ -42,7 +42,7 @@ impl SignatureNoiseMessage {
false
}
}
pub fn sign(msg: &mut [u8; 74], kp: &KeyPair) {
pub fn sign(msg: &mut [u8; 74], kp: &Keypair) {
let secp = Secp256k1::signing_only();
let m = Message::from_hashed_data::<sha256::Hash>(&msg[0..10]);
let signature = secp.sign_schnorr(&m, kp);
Expand Down
13 changes: 7 additions & 6 deletions protocols/v2/roles-logic-sv2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use stratum_common::{
uint::{Uint128, Uint256},
BitArray,
},
PublicKey, Script, Transaction,
PublicKey, Script, Transaction, XOnlyPublicKey,
},
};
use tracing::error;
Expand Down Expand Up @@ -237,12 +237,13 @@ impl TryFrom<CoinbaseOutput> for Script {
// Conceptually, every Taproot output corresponds to a combination of
// a single public key condition (the internal key),
// and zero or more general conditions encoded in scripts organized in a tree.
let pub_key = PublicKey::from_str(&value.output_script_value)
let pub_key = XOnlyPublicKey::from_str(&value.output_script_value)
.map_err(|_| Error::InvalidOutputScript)?;
Ok({
let (pubkey_only, _) = pub_key.inner.x_only_public_key();
Script::new_v1_p2tr::<All>(&Secp256k1::<All>::new(), pubkey_only, None)
})
Ok(Script::new_v1_p2tr::<All>(
&Secp256k1::<All>::new(),
pub_key,
None,
))
}
_ => Err(Error::UnknownOutputScriptType),
}
Expand Down
Loading

0 comments on commit 9eaf6d2

Please sign in to comment.