Add basic key management to the processor

This commit is contained in:
Luke Parker
2022-05-28 19:56:59 -04:00
parent e982908690
commit b5bdb545cc
5 changed files with 118 additions and 19 deletions

View File

@@ -1,11 +1,15 @@
use async_trait::async_trait;
use rand_core::{RngCore, CryptoRng};
use curve25519_dalek::{traits::Identity, scalar::Scalar, edwards::EdwardsPoint};
use curve25519_dalek::scalar::Scalar;
use dalek_ff_group as dfg;
use frost::MultisigKeys;
use monero::util::address::Address;
use monero_serai::{/*transaction::Output, */ rpc::Rpc, wallet::SpendableOutput};
use monero_serai::{frost::Ed25519, rpc::Rpc, wallet::{SpendableOutput, SignableTransaction}};
use crate::{Output as OutputTrait, CoinError, Coin};
use crate::{Output as OutputTrait, CoinError, Coin, view_key};
pub struct Output(SpendableOutput);
impl OutputTrait for Output {
@@ -38,25 +42,28 @@ impl From<SpendableOutput> for Output {
pub struct Monero {
rpc: Rpc,
view: Scalar,
spend: EdwardsPoint
view: Scalar
}
impl Monero {
pub fn new(url: String) -> Monero {
Monero {
rpc: Rpc::new(url),
view: Scalar::zero(),
spend: EdwardsPoint::identity()
view: dfg::Scalar::from_hash(view_key::<Monero>(0)).0
}
}
}
#[async_trait]
impl Coin for Monero {
type Curve = Ed25519;
type Output = Output;
type SignableTransaction = SignableTransaction;
type Address = Address;
fn id() -> &'static [u8] { b"Monero" }
async fn confirmations() -> usize { 10 }
// Testnet TX bb4d188a4c571f2f0de70dca9d475abc19078c10ffa8def26dd4f63ce1bcfd79 uses 146 inputs
// while using less than 100kb of space, albeit with just 2 outputs (though outputs share a BP)
@@ -71,17 +78,34 @@ impl Coin for Monero {
self.rpc.get_height().await.map_err(|_| CoinError::ConnectionError)
}
async fn get_outputs_in_block(&self, height: usize) -> Result<Vec<Self::Output>, CoinError> {
async fn get_outputs_in_block(
&self,
height: usize,
key: dfg::EdwardsPoint
) -> Result<Vec<Self::Output>, CoinError> {
Ok(
self.rpc.get_block_transactions_possible(height).await.map_err(|_| CoinError::ConnectionError)?
.iter().flat_map(|tx| tx.scan(self.view, self.spend)).map(Output::from).collect()
.iter().flat_map(|tx| tx.scan(self.view, key.0)).map(Output::from).collect()
)
}
async fn send(
async fn prepare_send<R: RngCore + CryptoRng>(
&self,
_keys: MultisigKeys<Ed25519>,
_label: Vec<u8>,
_height: usize,
_inputs: Vec<Output>,
_payments: &[(Address, u64)]
) -> Result<Vec<<Self::Output as OutputTrait>::Id>, CoinError> {
) -> Result<SignableTransaction, CoinError> {
todo!()
}
async fn attempt_send<R: RngCore + CryptoRng + std::marker::Send>(
&self,
_rng: &mut R,
_transaction: SignableTransaction,
_included: &[u16]
) -> Result<(Vec<u8>, Vec<<Self::Output as OutputTrait>::Id>), CoinError> {
todo!()
}
}