Skip to content

Commit ba3699a

Browse files
committed
chore: move signer into its own workspace module
1 parent 527bf84 commit ba3699a

13 files changed

Lines changed: 140 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"omnievent",
88
"onlyswaps-verifier",
99
"randomness-agent",
10+
"signer",
1011
"superalloy"
1112
]
1213

@@ -18,6 +19,7 @@ edition = "2024"
1819
# workspace crates
1920
dcipher-agents = { path = "./dcipher-agents" }
2021
superalloy = { path = "./superalloy" }
22+
dcipher-signer = { path = "./signer" }
2123

2224
# blockchain
2325
alloy = { version = "1.0", default-features = false }

dcipher-agents/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ edition.workspace = true
77
rayon = ["dep:rayon"]
88

99
[dependencies]
10+
# workspace crates
11+
dcipher-signer.workspace = true
12+
1013
alloy = { workspace = true, features = ["default", "provider-ws"] }
1114

1215
# crypto

dcipher-agents/src/ibe_helper.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ mod bn254 {
7373
use ark_ec::pairing::PairingOutput;
7474
use ark_ff::{BigInteger, Field, PrimeField};
7575
use ark_std::Zero;
76+
use dcipher_signer::{BlsSigner, BlsVerifier};
7677
use digest::core_api::BlockSizeUser;
7778
use pairing_utils::hash_to_curve::CustomPairingHashToCurve;
79+
use std::convert::Infallible;
7880
use std::ops::Neg;
81+
7982
/// Cipher suite for IBE w/ identity on bn254 G1.
8083
#[derive(Clone, Debug)]
8184
pub struct IbeIdentityOnBn254G1Suite<S = ()> {
@@ -152,6 +155,34 @@ mod bn254 {
152155
}
153156
}
154157

158+
/// Implementation of a BLS verifier [`IbeIdentityOnBn254G1Suite`].
159+
impl<S> BlsVerifier for IbeIdentityOnBn254G1Suite<S> {
160+
type SignatureGroup = <Self as PairingIbeCipherSuite>::IdentityGroup;
161+
type PublicKeyGroup = <Self as PairingIbeCipherSuite>::PublicKeyGroup;
162+
163+
fn verify(
164+
&self,
165+
m: impl AsRef<[u8]>,
166+
signature: Self::SignatureGroup,
167+
public_key: Self::PublicKeyGroup,
168+
) -> bool {
169+
self.verify_decryption_key(m.as_ref(), signature, public_key)
170+
}
171+
}
172+
173+
/// Implementation of a BLS signer [`IbeIdentityOnBn254G1Suite`].
174+
impl<S> BlsSigner for IbeIdentityOnBn254G1Suite<S>
175+
where
176+
Self: BlsVerifier + PairingIbeSigner<IdentityGroup = <Self as BlsVerifier>::SignatureGroup>,
177+
{
178+
type Error = Infallible;
179+
180+
fn sign(&self, m: impl AsRef<[u8]>) -> Result<Self::SignatureGroup, Self::Error> {
181+
let identity = self.h1(m.as_ref());
182+
Ok(self.decryption_key(identity))
183+
}
184+
}
185+
155186
/// Ciphertext for IBE w/ identity on bn254 G1.
156187
/// Currently, it only contains an ephemeral public key.
157188
pub struct IbeIdentityOnBn254G1Ciphertext {

dcipher-agents/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pub mod fulfiller;
44
pub mod ibe_helper;
55
pub(crate) mod ser;
66
pub mod signature_sender;
7-
pub mod signer;
7+
8+
// Re-exports
9+
pub use dcipher_signer as signer;
810

911
#[derive(
1012
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Serialize, serde::Deserialize, Debug,

signer/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "dcipher-signer"
3+
version.workspace = true
4+
edition.workspace = true
5+
6+
[features]
7+
rayon = ["dep:rayon"]
8+
9+
[dependencies]
10+
# crypto
11+
ark-bn254 = { workspace = true }
12+
ark-ec = { workspace = true }
13+
ark-ff = { workspace = true }
14+
ark-std = { workspace = true }
15+
pairing_utils = { workspace = true }
16+
17+
# hashes
18+
sha3 = { workspace = true }
19+
20+
# async
21+
futures-util = { workspace = true }
22+
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "sync"] }
23+
tokio-util = { workspace = true }
24+
25+
# logs / metrics
26+
prometheus = { workspace = true }
27+
tracing = { workspace = true }
28+
29+
# network
30+
libp2p = { workspace = true, features = ["tcp", "dns", "noise", "tokio", "ping", "yamux", "macros", "floodsub", "serde"] }
31+
32+
# serde
33+
serde = { workspace = true, features = ["derive"] }
34+
serde_cbor = "0.10"
35+
36+
# misc
37+
itertools = { workspace = true }
38+
thiserror = { workspace = true }
39+
lru = "0.14"
40+
rayon = { version = "1.10", optional = true }
Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Various traits and implementations used to sign messages.
22
3-
use crate::ibe_helper::{PairingIbeCipherSuite, PairingIbeSigner};
43
use ark_ec::pairing::Pairing;
54
use ark_ec::{AffineRepr, CurveGroup};
65
use ark_ff::Zero;
@@ -92,34 +91,3 @@ impl BlsSigner for BN254SignatureOnG1Signer {
9291
Ok(sig.into_affine())
9392
}
9493
}
95-
96-
/// Blanket implementation of a BLS verifier for all [`PairingIbeCipherSuite`].
97-
impl<CS> BlsVerifier for CS
98-
where
99-
CS: PairingIbeCipherSuite,
100-
{
101-
type SignatureGroup = CS::IdentityGroup;
102-
type PublicKeyGroup = CS::PublicKeyGroup;
103-
104-
fn verify(
105-
&self,
106-
m: impl AsRef<[u8]>,
107-
signature: Self::SignatureGroup,
108-
public_key: Self::PublicKeyGroup,
109-
) -> bool {
110-
self.verify_decryption_key(m.as_ref(), signature, public_key)
111-
}
112-
}
113-
114-
/// Blanket implementation of a BLS verifier for all [`PairingIbeSigner`].
115-
impl<CS> BlsSigner for CS
116-
where
117-
CS: PairingIbeSigner,
118-
{
119-
type Error = Infallible;
120-
121-
fn sign(&self, m: impl AsRef<[u8]>) -> Result<Self::SignatureGroup, Self::Error> {
122-
let identity = self.h1(m.as_ref());
123-
Ok(PairingIbeSigner::decryption_key(self, identity))
124-
}
125-
}

dcipher-agents/src/signer/threshold_signer.rs renamed to signer/src/threshold_signer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ pub mod metrics;
77

88
pub use aggregation::lagrange_points_interpolate_at;
99

10-
use crate::ser::EvmSerialize;
11-
use crate::signer::threshold_signer::libp2p::LibP2PNode;
12-
use crate::signer::threshold_signer::metrics::Metrics;
13-
use crate::signer::{AsynchronousSigner, BlsSigner, BlsVerifier};
10+
use crate::threshold_signer::libp2p::LibP2PNode;
11+
use crate::threshold_signer::metrics::Metrics;
12+
use crate::{AsynchronousSigner, BlsSigner, BlsVerifier};
1413
use ark_ec::{AffineRepr, CurveGroup};
1514
use itertools::Either;
1615
use lru::LruCache;
@@ -83,7 +82,7 @@ where
8382
impl<BLS> ThresholdSigner<BLS>
8483
where
8584
BLS: BlsSigner + Clone + Send + Sync + 'static,
86-
SignatureGroup<BLS>: EvmSerialize + PointSerializeCompressed + PointDeserializeCompressed,
85+
SignatureGroup<BLS>: PointSerializeCompressed + PointDeserializeCompressed,
8786
{
8887
/// Create a new threshold signer by specifying the various threshold scheme parameters.
8988
pub fn new(cs: BLS, n: u16, t: u16, id: u16, pks: Vec<BLS::PublicKeyGroup>) -> Self {
@@ -517,7 +516,6 @@ impl<BLS, M> AsynchronousSigner<M> for AsyncThresholdSigner<BLS>
517516
where
518517
BLS: BlsSigner + Send + Sync,
519518
M: AsRef<[u8]>,
520-
SignatureGroup<BLS>: EvmSerialize,
521519
for<'a> &'a SignatureGroup<BLS>: ToOwned,
522520
{
523521
type Error = AsyncThresholdSignerError;
@@ -603,7 +601,7 @@ where
603601
#[cfg(test)]
604602
mod tests {
605603
use super::*;
606-
use crate::ibe_helper::IbeIdentityOnBn254G1Suite;
604+
use crate::BN254SignatureOnG1Signer;
607605
use ark_bn254::Fr;
608606
use ark_ff::MontFp;
609607
use std::time::Duration;
@@ -628,9 +626,12 @@ mod tests {
628626
.map(|pki| pki.into_affine())
629627
.collect::<Vec<_>>();
630628

631-
let cs1 = IbeIdentityOnBn254G1Suite::new_signer(b"TEST", 31337, sk1);
632-
let cs2 = IbeIdentityOnBn254G1Suite::new_signer(b"TEST", 31337, sk2);
633-
let cs3 = IbeIdentityOnBn254G1Suite::new_signer(b"TEST", 31337, sk3);
629+
let cs1 =
630+
BN254SignatureOnG1Signer::new(sk1, b"BN254G1_XMD:KECCAK-256_SVDW_RO_H1_".to_vec());
631+
let cs2 =
632+
BN254SignatureOnG1Signer::new(sk2, b"BN254G1_XMD:KECCAK-256_SVDW_RO_H1_".to_vec());
633+
let cs3 =
634+
BN254SignatureOnG1Signer::new(sk3, b"BN254G1_XMD:KECCAK-256_SVDW_RO_H1_".to_vec());
634635

635636
let libp2p_sk1 = ::libp2p::identity::Keypair::generate_ed25519();
636637
let libp2p_sk2 = ::libp2p::identity::Keypair::generate_ed25519();
File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// use std::num::NonZeroUsize;
2+
// use std::sync::Arc;
3+
// use lru::LruCache;
4+
// use redis::aio::{ConnectionManager, ConnectionManagerConfig};
5+
//
6+
// struct RedisBackedCache<K, V> {
7+
// mem_cache: Arc<tokio::sync::Mutex<LruCache<K, V>>>,
8+
// redis: ConnectionManager,
9+
// // Arc<std::sync::Mutex<LruCache<Vec<u8>, HashMap<u16, PartialSignature<SignatureGroup<BLS>>>>>>;
10+
// }
11+
//
12+
// impl<K, V> RedisBackedCache<K, V> {
13+
// pub fn new(mem_cache_size: NonZeroUsize, redis_connection_manager: ConnectionManager) -> Self {
14+
// let config = ConnectionManagerConfig::new()
15+
// .set_push_sender()
16+
// Self {
17+
// mem_cache: Arc::new(tokio::sync::Mutex::new(LruCache::new(mem_cache_size))),
18+
// redis
19+
// }
20+
// }
21+
// }

0 commit comments

Comments
 (0)