Clean and document monero-address

This commit is contained in:
Luke Parker
2024-07-01 17:58:35 -04:00
parent 8319d219d7
commit 69e077bf7a
13 changed files with 489 additions and 292 deletions

View File

@@ -24,7 +24,7 @@ pub mod extra;
pub(crate) use extra::{PaymentId, Extra};
pub use monero_address as address;
use address::{Network, AddressType, SubaddressIndex, AddressSpec, AddressMeta, MoneroAddress};
use address::{Network, AddressType, SubaddressIndex, AddressSpec, MoneroAddress};
pub mod scan;
@@ -88,28 +88,23 @@ impl ViewPair {
let mut spend = self.spend;
let mut view: EdwardsPoint = self.view.deref() * ED25519_BASEPOINT_TABLE;
// construct the address meta
let meta = match spec {
AddressSpec::Standard => AddressMeta::new(network, AddressType::Standard),
AddressSpec::Integrated(payment_id) => {
AddressMeta::new(network, AddressType::Integrated(payment_id))
}
// construct the address type
let kind = match spec {
AddressSpec::Legacy => AddressType::Legacy,
AddressSpec::LegacyIntegrated(payment_id) => AddressType::LegacyIntegrated(payment_id),
AddressSpec::Subaddress(index) => {
(spend, view) = self.subaddress_keys(index);
AddressMeta::new(network, AddressType::Subaddress)
AddressType::Subaddress
}
AddressSpec::Featured { subaddress, payment_id, guaranteed } => {
if let Some(index) = subaddress {
(spend, view) = self.subaddress_keys(index);
}
AddressMeta::new(
network,
AddressType::Featured { subaddress: subaddress.is_some(), payment_id, guaranteed },
)
AddressType::Featured { subaddress: subaddress.is_some(), payment_id, guaranteed }
}
};
MoneroAddress::new(meta, spend, view)
MoneroAddress::new(network, kind, spend, view)
}
}

View File

@@ -75,7 +75,7 @@ impl Change {
// Which network doesn't matter as the derivations will all be the same
Network::Mainnet,
if !guaranteed {
AddressSpec::Standard
AddressSpec::Legacy
} else {
AddressSpec::Featured { subaddress: None, payment_id: None, guaranteed: true }
},
@@ -390,7 +390,7 @@ impl SignableTransaction {
fn read_address<R: io::Read>(r: &mut R) -> io::Result<MoneroAddress> {
String::from_utf8(read_vec(read_byte, r)?)
.ok()
.and_then(|str| MoneroAddress::from_str_raw(&str).ok())
.and_then(|str| MoneroAddress::from_str_with_unchecked_network(&str).ok())
.ok_or_else(|| io::Error::other("invalid address"))
}

View File

@@ -42,7 +42,7 @@ impl SignableTransaction {
let mut res = Vec::with_capacity(self.payments.len());
for (payment, shared_key_derivations) in self.payments.iter().zip(&shared_key_derivations) {
let key =
(&shared_key_derivations.shared_key * ED25519_BASEPOINT_TABLE) + payment.address().spend;
(&shared_key_derivations.shared_key * ED25519_BASEPOINT_TABLE) + payment.address().spend();
res.push(Output {
key: key.compress(),
amount: None,

View File

@@ -106,7 +106,7 @@ impl SignableTransaction {
let ecdh = match payment {
// If we don't have the view key, use the key dedicated for this address (r A)
InternalPayment::Payment(_, _) | InternalPayment::Change(_, None) => {
Zeroizing::new(key_to_use.deref() * addr.view)
Zeroizing::new(key_to_use.deref() * addr.view())
}
// If we do have the view key, use the commitment to the key (a R)
InternalPayment::Change(_, Some(view)) => Zeroizing::new(view.deref() * tx_key_pub),
@@ -173,7 +173,7 @@ impl SignableTransaction {
// TODO: Support subaddresses as change?
debug_assert!(addr.is_subaddress());
return (tx_key.deref() * addr.spend, vec![]);
return (tx_key.deref() * addr.spend(), vec![]);
}
if should_use_additional_keys {
@@ -182,7 +182,7 @@ impl SignableTransaction {
let addr = payment.address();
// TODO: Double check this against wallet2
if addr.is_subaddress() {
additional_keys_pub.push(additional_key.deref() * addr.spend);
additional_keys_pub.push(additional_key.deref() * addr.spend());
} else {
additional_keys_pub.push(additional_key.deref() * ED25519_BASEPOINT_TABLE)
}