mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 22:42:35 -04:00
Update to latest monero-rs
This commit is contained in:
parent
642f1d8318
commit
ec1916161e
13 changed files with 59 additions and 83 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -848,8 +848,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curve25519-dalek"
|
name = "curve25519-dalek"
|
||||||
version = "3.1.0"
|
version = "3.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/thomaseizinger/curve25519-dalek?rev=8cc9ad36bd30ceab6073ff64655473c6b5aa4aab#8cc9ad36bd30ceab6073ff64655473c6b5aa4aab"
|
||||||
checksum = "639891fde0dbea823fc3d798a0fdf9d2f9440a42d64a78ab3488b0ca025117b3"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"digest 0.9.0",
|
"digest 0.9.0",
|
||||||
|
@ -2265,10 +2264,11 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "monero"
|
name = "monero"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/comit-network/monero-rs?branch=fix-bulletproofs#fae784dabbbc7c759334a031a2802813fffec792"
|
source = "git+https://github.com/comit-network/monero-rs?rev=fee1f7054a4b8500dcf7867ebd1b9e7f693cd566#fee1f7054a4b8500dcf7867ebd1b9e7f693cd566"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base58-monero",
|
"base58-monero",
|
||||||
"clear_on_drop",
|
"clear_on_drop",
|
||||||
|
"conquer-once",
|
||||||
"curve25519-dalek",
|
"curve25519-dalek",
|
||||||
"fixed-hash",
|
"fixed-hash",
|
||||||
"hash_edwards_to_edwards",
|
"hash_edwards_to_edwards",
|
||||||
|
@ -2277,7 +2277,6 @@ dependencies = [
|
||||||
"integer-encoding",
|
"integer-encoding",
|
||||||
"itertools 0.10.0",
|
"itertools 0.10.0",
|
||||||
"keccak-hash",
|
"keccak-hash",
|
||||||
"lazy_static",
|
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"serde",
|
"serde",
|
||||||
"serde-big-array",
|
"serde-big-array",
|
||||||
|
@ -2309,8 +2308,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "monero-epee-bin-serde"
|
name = "monero-epee-bin-serde"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/comit-network/monero-epee-bin-serde#f2c8baa39f04ac4e7a71c76a16c2c6f9a5ee3e3b"
|
||||||
checksum = "13be5b525af150f294b98d4291b0ec01e5bc157db740de2822827c17561d3960"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -2322,6 +2320,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"futures",
|
"futures",
|
||||||
|
"monero",
|
||||||
"monero-rpc",
|
"monero-rpc",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"spectral",
|
"spectral",
|
||||||
|
|
|
@ -3,4 +3,6 @@ members = ["monero-adaptor", "monero-harness", "monero-rpc", "swap", "monero-wal
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
torut = { git = "https://github.com/bonomat/torut/", branch = "feature-flag-tor-secret-keys", default-features = false, features = [ "v3", "control" ] }
|
torut = { git = "https://github.com/bonomat/torut/", branch = "feature-flag-tor-secret-keys", default-features = false, features = [ "v3", "control" ] }
|
||||||
monero = { git = "https://github.com/comit-network/monero-rs", branch = "fix-bulletproofs" }
|
monero = { git = "https://github.com/comit-network/monero-rs", rev = "fee1f7054a4b8500dcf7867ebd1b9e7f693cd566" }
|
||||||
|
monero-epee-bin-serde = { git = "https://github.com/comit-network/monero-epee-bin-serde" }
|
||||||
|
curve25519-dalek = { git = "https://github.com/thomaseizinger/curve25519-dalek", rev = "8cc9ad36bd30ceab6073ff64655473c6b5aa4aab" }
|
||||||
|
|
|
@ -18,10 +18,9 @@ async fn monerod_integration_test() {
|
||||||
let (monero, _monerod_container, _monero_wallet_rpc_containers) =
|
let (monero, _monerod_container, _monero_wallet_rpc_containers) =
|
||||||
Monero::new(&cli, vec![]).await.unwrap();
|
Monero::new(&cli, vec![]).await.unwrap();
|
||||||
|
|
||||||
let signing_key = curve25519_dalek::scalar::Scalar::random(&mut rng);
|
|
||||||
let lock_kp = monero::KeyPair {
|
let lock_kp = monero::KeyPair {
|
||||||
view: monero::PrivateKey::from_scalar(curve25519_dalek::scalar::Scalar::random(&mut rng)),
|
view: monero::PrivateKey::random(&mut rng),
|
||||||
spend: monero::PrivateKey::from_scalar(signing_key),
|
spend: monero::PrivateKey::random(&mut rng),
|
||||||
};
|
};
|
||||||
|
|
||||||
let spend_amount = 999600000000;
|
let spend_amount = 999600000000;
|
||||||
|
|
|
@ -14,3 +14,4 @@ testcontainers = "0.12"
|
||||||
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "macros" ] }
|
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "macros" ] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
|
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
|
||||||
|
monero = "0.12"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use monero::util::key::ScalarExt;
|
||||||
use monero_harness::{Monero, MoneroWalletRpc};
|
use monero_harness::{Monero, MoneroWalletRpc};
|
||||||
use monero_rpc::wallet::MoneroWalletRpc as _;
|
use monero_rpc::wallet::MoneroWalletRpc as _;
|
||||||
use spectral::prelude::*;
|
use spectral::prelude::*;
|
||||||
|
@ -45,7 +46,7 @@ async fn fund_transfer_and_check_tx_key() {
|
||||||
|
|
||||||
// check if tx was actually seen
|
// check if tx was actually seen
|
||||||
let tx_id = transfer.tx_hash;
|
let tx_id = transfer.tx_hash;
|
||||||
let tx_key = transfer.tx_key.unwrap().to_string();
|
let tx_key = transfer.tx_key.unwrap().display_hex().to_string();
|
||||||
let res = bob_wallet
|
let res = bob_wallet
|
||||||
.client()
|
.client()
|
||||||
.check_tx_key(tx_id, tx_key, bob_address)
|
.check_tx_key(tx_id, tx_key, bob_address)
|
||||||
|
|
|
@ -233,7 +233,7 @@ pub struct OutKey {
|
||||||
#[serde(with = "byte_array")]
|
#[serde(with = "byte_array")]
|
||||||
pub key: PublicKey,
|
pub key: PublicKey,
|
||||||
#[serde(with = "byte_array")]
|
#[serde(with = "byte_array")]
|
||||||
pub mask: ringct::Key,
|
pub mask: PublicKey,
|
||||||
#[serde(with = "byte_array")]
|
#[serde(with = "byte_array")]
|
||||||
pub txid: Hash,
|
pub txid: Hash,
|
||||||
pub unlocked: bool,
|
pub unlocked: bool,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use monero::util::key::ScalarExt;
|
||||||
use serde::{de::Error, Deserialize, Deserializer, Serialize};
|
use serde::{de::Error, Deserialize, Deserializer, Serialize};
|
||||||
|
|
||||||
#[jsonrpc_client::api(version = "2.0")]
|
#[jsonrpc_client::api(version = "2.0")]
|
||||||
|
@ -220,7 +221,9 @@ where
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some(string.parse().map_err(D::Error::custom)?))
|
Ok(Some(
|
||||||
|
monero::PrivateKey::from_str(&string).map_err(D::Error::custom)?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -2,15 +2,15 @@ mod v2;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
|
||||||
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use hash_edwards_to_edwards::hash_point_to_point;
|
use hash_edwards_to_edwards::hash_point_to_point;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use monero::blockdata::transaction::{ExtraField, KeyImage, SubField, TxOutTarget};
|
use monero::blockdata::transaction::{ExtraField, KeyImage, SubField, TxOutTarget};
|
||||||
use monero::cryptonote::hash::Hashable;
|
use monero::cryptonote::hash::Hashable;
|
||||||
use monero::cryptonote::onetime_key::KeyGenerator;
|
use monero::cryptonote::onetime_key::KeyGenerator;
|
||||||
use monero::util::key::H;
|
use monero::util::key::{EdwardsPointExt, H};
|
||||||
use monero::util::ringct::{CtKey, EcdhInfo, Key, RctSig, RctSigBase, RctSigPrunable, RctType};
|
use monero::util::ringct::{EcdhInfo, RctSig, RctSigBase, RctSigPrunable, RctType};
|
||||||
use monero::{
|
use monero::{
|
||||||
Address, KeyPair, OwnedTxOut, PrivateKey, PublicKey, Transaction, TransactionPrefix, TxIn,
|
Address, KeyPair, OwnedTxOut, PrivateKey, PublicKey, Transaction, TransactionPrefix, TxIn,
|
||||||
TxOut, VarInt,
|
TxOut, VarInt,
|
||||||
|
@ -47,7 +47,7 @@ impl ConfidentialTransactionBuilder {
|
||||||
decoy_inputs: [DecoyInput; 10],
|
decoy_inputs: [DecoyInput; 10],
|
||||||
keys: KeyPair,
|
keys: KeyPair,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let actual_signing_key = input_to_spend.recover_key(&keys).scalar;
|
let actual_signing_key = input_to_spend.recover_key(&keys);
|
||||||
let signing_pk = actual_signing_key * ED25519_BASEPOINT_POINT;
|
let signing_pk = actual_signing_key * ED25519_BASEPOINT_POINT;
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -77,13 +77,17 @@ impl ConfidentialTransactionBuilder {
|
||||||
let next_index = self.outputs.len();
|
let next_index = self.outputs.len();
|
||||||
|
|
||||||
let ecdh_key = PrivateKey::random(rng);
|
let ecdh_key = PrivateKey::random(rng);
|
||||||
let (ecdh_info, blinding_factor) = EcdhInfo::new_bulletproof(amount, ecdh_key.scalar);
|
let (ecdh_info, blinding_factor) = EcdhInfo::new_bulletproof(amount, ecdh_key);
|
||||||
|
|
||||||
let out = TxOut {
|
let out = TxOut {
|
||||||
amount: VarInt(0),
|
amount: VarInt(0),
|
||||||
target: TxOutTarget::ToKey {
|
target: TxOutTarget::ToKey {
|
||||||
key: KeyGenerator::from_random(to.public_view, to.public_spend, ecdh_key)
|
key: KeyGenerator::from_random(
|
||||||
.one_time_key(dbg!(next_index)),
|
to.public_view.decompress().unwrap(),
|
||||||
|
to.public_spend.decompress().unwrap(),
|
||||||
|
ecdh_key,
|
||||||
|
)
|
||||||
|
.one_time_key(dbg!(next_index)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +118,7 @@ impl ConfidentialTransactionBuilder {
|
||||||
|
|
||||||
let fee = self.compute_fee();
|
let fee = self.compute_fee();
|
||||||
|
|
||||||
let fee_key = Scalar::from(fee) * H.point.decompress().unwrap();
|
let fee_key = Scalar::from(fee) * *H;
|
||||||
|
|
||||||
fee_key + sum_commitments
|
fee_key + sum_commitments
|
||||||
}
|
}
|
||||||
|
@ -196,14 +200,7 @@ impl ConfidentialTransactionBuilder {
|
||||||
let rct_sig_base = RctSigBase {
|
let rct_sig_base = RctSigBase {
|
||||||
rct_type: RctType::Clsag,
|
rct_type: RctType::Clsag,
|
||||||
txn_fee: VarInt(fee),
|
txn_fee: VarInt(fee),
|
||||||
out_pk: output_commitments
|
out_pk: output_commitments,
|
||||||
.iter()
|
|
||||||
.map(|p| CtKey {
|
|
||||||
mask: Key {
|
|
||||||
key: p.compress().0,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
ecdh_info: self.ecdh_info,
|
ecdh_info: self.ecdh_info,
|
||||||
pseudo_outs: vec![], // legacy
|
pseudo_outs: vec![], // legacy
|
||||||
};
|
};
|
||||||
|
@ -212,9 +209,7 @@ impl ConfidentialTransactionBuilder {
|
||||||
bulletproofs: vec![bulletproof],
|
bulletproofs: vec![bulletproof],
|
||||||
MGs: vec![], // legacy
|
MGs: vec![], // legacy
|
||||||
Clsags: vec![],
|
Clsags: vec![],
|
||||||
pseudo_outs: vec![Key {
|
pseudo_outs: vec![pseudo_out],
|
||||||
key: pseudo_out.compress().to_bytes(),
|
|
||||||
}],
|
|
||||||
};
|
};
|
||||||
let mut transaction = Transaction {
|
let mut transaction = Transaction {
|
||||||
prefix,
|
prefix,
|
||||||
|
@ -339,13 +334,10 @@ impl FetchDecoyInputs for monerod::Client {
|
||||||
.outs
|
.outs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(indices.iter())
|
.zip(indices.iter())
|
||||||
.map(|(out_key, index)| {
|
.map(|(out_key, index)| DecoyInput {
|
||||||
DecoyInput {
|
global_output_index: *index,
|
||||||
global_output_index: *index,
|
key: out_key.key,
|
||||||
key: out_key.key.point.decompress().unwrap(), /* TODO: should decompress on
|
commitment: out_key.mask,
|
||||||
* deserialization */
|
|
||||||
commitment: CompressedEdwardsY(out_key.mask.key).decompress().unwrap(),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
|
@ -84,8 +84,6 @@ impl TxRefund {
|
||||||
a: bitcoin::SecretKey,
|
a: bitcoin::SecretKey,
|
||||||
S_b_bitcoin: bitcoin::PublicKey,
|
S_b_bitcoin: bitcoin::PublicKey,
|
||||||
) -> Result<monero::PrivateKey> {
|
) -> Result<monero::PrivateKey> {
|
||||||
let s_a = monero::PrivateKey { scalar: s_a };
|
|
||||||
|
|
||||||
let tx_refund_sig = self
|
let tx_refund_sig = self
|
||||||
.extract_signature_by_key(published_refund_tx, a.public())
|
.extract_signature_by_key(published_refund_tx, a.public())
|
||||||
.context("Failed to extract signature from Bitcoin refund tx")?;
|
.context("Failed to extract signature from Bitcoin refund tx")?;
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub use wallet_rpc::{WalletRpc, WalletRpcProcess};
|
||||||
|
|
||||||
use crate::bitcoin;
|
use crate::bitcoin;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use monero::util::key::EdwardsPointExt;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use rust_decimal::prelude::*;
|
use rust_decimal::prelude::*;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
|
@ -26,7 +27,7 @@ pub fn private_key_from_secp256k1_scalar(scalar: bitcoin::Scalar) -> PrivateKey
|
||||||
// ed25519 scalar is little endian
|
// ed25519 scalar is little endian
|
||||||
bytes.reverse();
|
bytes.reverse();
|
||||||
|
|
||||||
PrivateKey::from_scalar(Scalar::from_bytes_mod_order(bytes))
|
Scalar::from_bytes_mod_order(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
|
@ -34,10 +35,7 @@ pub struct PrivateViewKey(#[serde(with = "monero_private_key")] PrivateKey);
|
||||||
|
|
||||||
impl PrivateViewKey {
|
impl PrivateViewKey {
|
||||||
pub fn new_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
|
pub fn new_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
|
||||||
let scalar = Scalar::random(rng);
|
Self(Scalar::random(rng))
|
||||||
let private_key = PrivateKey::from_scalar(scalar);
|
|
||||||
|
|
||||||
Self(private_key)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn public(&self) -> PublicViewKey {
|
pub fn public(&self) -> PublicViewKey {
|
||||||
|
@ -345,9 +343,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serde_monero_private_key() {
|
fn serde_monero_private_key() {
|
||||||
let key = MoneroPrivateKey(monero::PrivateKey::from_scalar(
|
let key = MoneroPrivateKey(crate::monero::Scalar::random(&mut OsRng));
|
||||||
crate::monero::Scalar::random(&mut OsRng),
|
|
||||||
));
|
|
||||||
let encoded = serde_cbor::to_vec(&key).unwrap();
|
let encoded = serde_cbor::to_vec(&key).unwrap();
|
||||||
let decoded: MoneroPrivateKey = serde_cbor::from_slice(&encoded).unwrap();
|
let decoded: MoneroPrivateKey = serde_cbor::from_slice(&encoded).unwrap();
|
||||||
assert_eq!(key, decoded);
|
assert_eq!(key, decoded);
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::monero::{
|
||||||
};
|
};
|
||||||
use ::monero::{Address, Network, PrivateKey, PublicKey};
|
use ::monero::{Address, Network, PrivateKey, PublicKey};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use monero::util::key::{EdwardsPointExt, ScalarExt};
|
||||||
use monero_rpc::wallet;
|
use monero_rpc::wallet;
|
||||||
use monero_rpc::wallet::{BlockHeight, CheckTxKey, MoneroWalletRpc as _, Refreshed};
|
use monero_rpc::wallet::{BlockHeight, CheckTxKey, MoneroWalletRpc as _, Refreshed};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
@ -96,8 +97,8 @@ impl Wallet {
|
||||||
.generate_from_keys(
|
.generate_from_keys(
|
||||||
file_name,
|
file_name,
|
||||||
address.to_string(),
|
address.to_string(),
|
||||||
private_spend_key.to_string(),
|
private_spend_key.display_hex().to_string(),
|
||||||
PrivateKey::from(private_view_key).to_string(),
|
PrivateKey::from(private_view_key).display_hex().to_string(),
|
||||||
restore_height.height,
|
restore_height.height,
|
||||||
String::from(""),
|
String::from(""),
|
||||||
true,
|
true,
|
||||||
|
@ -135,8 +136,8 @@ impl Wallet {
|
||||||
.generate_from_keys(
|
.generate_from_keys(
|
||||||
file_name,
|
file_name,
|
||||||
temp_wallet_address.to_string(),
|
temp_wallet_address.to_string(),
|
||||||
private_spend_key.to_string(),
|
private_spend_key.display_hex().to_string(),
|
||||||
PrivateKey::from(private_view_key).to_string(),
|
PrivateKey::from(private_view_key).display_hex().to_string(),
|
||||||
restore_height.height,
|
restore_height.height,
|
||||||
String::from(""),
|
String::from(""),
|
||||||
true,
|
true,
|
||||||
|
@ -189,7 +190,7 @@ impl Wallet {
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
"sent transfer of {} to {} in {}",
|
"sent transfer of {} to {} in {}",
|
||||||
amount,
|
amount,
|
||||||
public_spend_key,
|
public_spend_key.display_hex(),
|
||||||
res.tx_hash
|
res.tx_hash
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ impl Wallet {
|
||||||
let address = Address::standard(self.network, public_spend_key, public_view_key.into());
|
let address = Address::standard(self.network, public_spend_key, public_view_key.into());
|
||||||
|
|
||||||
let check_interval = tokio::time::interval(self.sync_interval);
|
let check_interval = tokio::time::interval(self.sync_interval);
|
||||||
let key = transfer_proof.tx_key().to_string();
|
let key = transfer_proof.tx_key().display_hex().to_string();
|
||||||
|
|
||||||
wait_for_confirmations(
|
wait_for_confirmations(
|
||||||
txid.0,
|
txid.0,
|
||||||
|
|
|
@ -7,7 +7,8 @@ use crate::monero::TransferProof;
|
||||||
use crate::monero_ext::ScalarExt;
|
use crate::monero_ext::ScalarExt;
|
||||||
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
|
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
|
||||||
use crate::{bitcoin, monero};
|
use crate::{bitcoin, monero};
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use ::monero::util::key::EdwardsPointExt;
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
use monero_rpc::wallet::BlockHeight;
|
use monero_rpc::wallet::BlockHeight;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -134,9 +135,7 @@ impl State0 {
|
||||||
s_a,
|
s_a,
|
||||||
v_a,
|
v_a,
|
||||||
S_a_bitcoin: S_a_bitcoin.into(),
|
S_a_bitcoin: S_a_bitcoin.into(),
|
||||||
S_a_monero: monero::PublicKey {
|
S_a_monero,
|
||||||
point: S_a_monero.compress(),
|
|
||||||
},
|
|
||||||
dleq_proof_s_a,
|
dleq_proof_s_a,
|
||||||
redeem_address,
|
redeem_address,
|
||||||
punish_address,
|
punish_address,
|
||||||
|
@ -150,13 +149,7 @@ impl State0 {
|
||||||
pub fn receive(self, msg: Message0) -> Result<(Uuid, State1)> {
|
pub fn receive(self, msg: Message0) -> Result<(Uuid, State1)> {
|
||||||
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
|
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
|
||||||
&msg.dleq_proof_s_b,
|
&msg.dleq_proof_s_b,
|
||||||
(
|
(msg.S_b_bitcoin.into(), msg.S_b_monero),
|
||||||
msg.S_b_bitcoin.into(),
|
|
||||||
msg.S_b_monero
|
|
||||||
.point
|
|
||||||
.decompress()
|
|
||||||
.ok_or_else(|| anyhow!("S_b is not a monero curve point"))?,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if !valid {
|
if !valid {
|
||||||
|
@ -353,7 +346,7 @@ impl State3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lock_xmr_transfer_request(&self) -> TransferRequest {
|
pub fn lock_xmr_transfer_request(&self) -> TransferRequest {
|
||||||
let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a });
|
let S_a = monero::PublicKey::from_private_key(&self.s_a);
|
||||||
|
|
||||||
let public_spend_key = S_a + self.S_b_monero;
|
let public_spend_key = S_a + self.S_b_monero;
|
||||||
let public_view_key = self.v.public();
|
let public_view_key = self.v.public();
|
||||||
|
@ -370,7 +363,7 @@ impl State3 {
|
||||||
transfer_proof: TransferProof,
|
transfer_proof: TransferProof,
|
||||||
conf_target: u64,
|
conf_target: u64,
|
||||||
) -> WatchRequest {
|
) -> WatchRequest {
|
||||||
let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a });
|
let S_a = monero::PublicKey::from_private_key(&self.s_a);
|
||||||
|
|
||||||
let public_spend_key = S_a + self.S_b_monero;
|
let public_spend_key = S_a + self.S_b_monero;
|
||||||
let public_view_key = self.v.public();
|
let public_view_key = self.v.public();
|
||||||
|
|
|
@ -7,7 +7,8 @@ use crate::monero::wallet::WatchRequest;
|
||||||
use crate::monero::{monero_private_key, TransferProof};
|
use crate::monero::{monero_private_key, TransferProof};
|
||||||
use crate::monero_ext::ScalarExt;
|
use crate::monero_ext::ScalarExt;
|
||||||
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
|
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use ::monero::util::key::EdwardsPointExt;
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
|
||||||
use ecdsa_fun::nonce::Deterministic;
|
use ecdsa_fun::nonce::Deterministic;
|
||||||
use ecdsa_fun::Signature;
|
use ecdsa_fun::Signature;
|
||||||
|
@ -110,9 +111,7 @@ impl State0 {
|
||||||
s_b,
|
s_b,
|
||||||
v_b,
|
v_b,
|
||||||
S_b_bitcoin: bitcoin::PublicKey::from(S_b_bitcoin),
|
S_b_bitcoin: bitcoin::PublicKey::from(S_b_bitcoin),
|
||||||
S_b_monero: monero::PublicKey {
|
S_b_monero,
|
||||||
point: S_b_monero.compress(),
|
|
||||||
},
|
|
||||||
btc,
|
btc,
|
||||||
xmr,
|
xmr,
|
||||||
dleq_proof_s_b,
|
dleq_proof_s_b,
|
||||||
|
@ -138,13 +137,7 @@ impl State0 {
|
||||||
pub async fn receive(self, wallet: &bitcoin::Wallet, msg: Message1) -> Result<State1> {
|
pub async fn receive(self, wallet: &bitcoin::Wallet, msg: Message1) -> Result<State1> {
|
||||||
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
|
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
|
||||||
&msg.dleq_proof_s_a,
|
&msg.dleq_proof_s_a,
|
||||||
(
|
(msg.S_a_bitcoin.into(), msg.S_a_monero),
|
||||||
msg.S_a_bitcoin.into(),
|
|
||||||
msg.S_a_monero
|
|
||||||
.point
|
|
||||||
.decompress()
|
|
||||||
.ok_or_else(|| anyhow!("S_a is not a monero curve point"))?,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if !valid {
|
if !valid {
|
||||||
|
@ -310,8 +303,7 @@ pub struct State3 {
|
||||||
|
|
||||||
impl State3 {
|
impl State3 {
|
||||||
pub fn lock_xmr_watch_request(&self, transfer_proof: TransferProof) -> WatchRequest {
|
pub fn lock_xmr_watch_request(&self, transfer_proof: TransferProof) -> WatchRequest {
|
||||||
let S_b_monero =
|
let S_b_monero = monero::PublicKey::from_private_key(&self.s_b);
|
||||||
monero::PublicKey::from_private_key(&monero::PrivateKey::from_scalar(self.s_b));
|
|
||||||
let S = self.S_a_monero + S_b_monero;
|
let S = self.S_a_monero + S_b_monero;
|
||||||
|
|
||||||
WatchRequest {
|
WatchRequest {
|
||||||
|
@ -470,8 +462,7 @@ pub struct State5 {
|
||||||
|
|
||||||
impl State5 {
|
impl State5 {
|
||||||
pub fn xmr_keys(&self) -> (monero::PrivateKey, monero::PrivateViewKey) {
|
pub fn xmr_keys(&self) -> (monero::PrivateKey, monero::PrivateViewKey) {
|
||||||
let s_b = monero::PrivateKey { scalar: self.s_b };
|
let s = self.s_a + self.s_b;
|
||||||
let s = self.s_a + s_b;
|
|
||||||
|
|
||||||
(s, self.v)
|
(s, self.v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue