mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Break Ethereum Deployer into crate
This commit is contained in:
@@ -3,7 +3,7 @@ name = "ethereum-serai"
|
||||
version = "0.1.0"
|
||||
description = "An Ethereum library supporting Schnorr signing and on-chain verification"
|
||||
license = "AGPL-3.0-only"
|
||||
repository = "https://github.com/serai-dex/serai/tree/develop/networks/ethereum"
|
||||
repository = "https://github.com/serai-dex/serai/tree/develop/processor/ethereum/ethereum-serai"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>", "Elizabeth Binks <elizabethjbinks@gmail.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
@@ -15,11 +15,9 @@ use frost::{
|
||||
|
||||
pub use ethereum_schnorr_contract::*;
|
||||
|
||||
use alloy_core::primitives::{Parity, Signature as AlloySignature};
|
||||
use alloy_core::primitives::{Parity, Signature as AlloySignature, Address};
|
||||
use alloy_consensus::{SignableTransaction, Signed, TxLegacy};
|
||||
|
||||
use crate::abi::router::{Signature as AbiSignature};
|
||||
|
||||
pub(crate) fn keccak256(data: &[u8]) -> [u8; 32] {
|
||||
alloy_core::primitives::keccak256(data).into()
|
||||
}
|
||||
@@ -28,11 +26,9 @@ pub(crate) fn hash_to_scalar(data: &[u8]) -> Scalar {
|
||||
<Scalar as Reduce<KU256>>::reduce_bytes(&keccak256(data).into())
|
||||
}
|
||||
|
||||
pub fn address(point: &ProjectivePoint) -> [u8; 20] {
|
||||
pub(crate) fn address(point: &ProjectivePoint) -> [u8; 20] {
|
||||
let encoded_point = point.to_encoded_point(false);
|
||||
// Last 20 bytes of the hash of the concatenated x and y coordinates
|
||||
// We obtain the concatenated x and y coordinates via the uncompressed encoding of the point
|
||||
keccak256(&encoded_point.as_ref()[1 .. 65])[12 ..].try_into().unwrap()
|
||||
**Address::from_raw_public_key(&encoded_point.as_ref()[1 .. 65])
|
||||
}
|
||||
|
||||
/// Deterministically sign a transaction.
|
||||
@@ -64,18 +60,15 @@ pub fn deterministically_sign(tx: &TxLegacy) -> Signed<TxLegacy> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The HRAm to use for the Schnorr contract.
|
||||
/// The HRAm to use for the Schnorr Solidity library.
|
||||
///
|
||||
/// This will panic if the public key being signed for is not representable within the Schnorr
|
||||
/// Solidity library.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct EthereumHram {}
|
||||
impl Hram<Secp256k1> for EthereumHram {
|
||||
#[allow(non_snake_case)]
|
||||
fn hram(R: &ProjectivePoint, A: &ProjectivePoint, m: &[u8]) -> Scalar {
|
||||
let x_coord = A.to_affine().x();
|
||||
|
||||
let mut data = address(R).to_vec();
|
||||
data.extend(x_coord.as_slice());
|
||||
data.extend(m);
|
||||
|
||||
<Scalar as Reduce<KU256>>::reduce_bytes(&keccak256(&data).into())
|
||||
Signature::challenge(*R, &PublicKey::new(*A).unwrap(), m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub mod alloy {
|
||||
|
||||
pub mod crypto;
|
||||
|
||||
/*
|
||||
pub(crate) mod abi {
|
||||
pub use contracts::erc20;
|
||||
pub use contracts::deployer;
|
||||
@@ -37,3 +38,4 @@ pub enum Error {
|
||||
#[error("couldn't make call/send TX")]
|
||||
ConnectionError,
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,19 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
/// The HRAm to use for the Schnorr Solidity library.
|
||||
///
|
||||
/// This will panic if the public key being signed for is not representable within the Schnorr
|
||||
/// Solidity library.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct EthereumHram {}
|
||||
impl Hram<Secp256k1> for EthereumHram {
|
||||
#[allow(non_snake_case)]
|
||||
fn hram(R: &ProjectivePoint, A: &ProjectivePoint, m: &[u8]) -> Scalar {
|
||||
Signature::challenge(*R, &PublicKey::new(*A).unwrap(), m)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Call {
|
||||
pub to: [u8; 20],
|
||||
|
||||
Reference in New Issue
Block a user