2024-04-23 08:31:27 +00:00
|
|
|
use core::{marker::PhantomData, fmt};
|
2024-04-23 09:25:08 +00:00
|
|
|
use std_shims::string::ToString;
|
2022-06-28 04:01:20 +00:00
|
|
|
|
Utilize zeroize (#76)
* Apply Zeroize to nonces used in Bulletproofs
Also makes bit decomposition constant time for a given amount of
outputs.
* Fix nonce reuse for single-signer CLSAG
* Attach Zeroize to most structures in Monero, and ZOnDrop to anything with private data
* Zeroize private keys and nonces
* Merge prepare_outputs and prepare_transactions
* Ensure CLSAG is constant time
* Pass by borrow where needed, bug fixes
The past few commitments have been one in-progress chunk which I've
broken up as best read.
* Add Zeroize to FROST structs
Still needs to zeroize internally, yet next step. Not quite as
aggressive as Monero, partially due to the limitations of HashMaps,
partially due to less concern about metadata, yet does still delete a
few smaller items of metadata (group key, context string...).
* Remove Zeroize from most Monero multisig structs
These structs largely didn't have private data, just fields with private
data, yet those fields implemented ZeroizeOnDrop making them already
covered. While there is still traces of the transaction left in RAM,
fully purging that was never the intent.
* Use Zeroize within dleq
bitvec doesn't offer Zeroize, so a manual zeroing has been implemented.
* Use Zeroize for random_nonce
It isn't perfect, due to the inability to zeroize the digest, and due to
kp256 requiring a few transformations. It does the best it can though.
Does move the per-curve random_nonce to a provided one, which is allowed
as of https://github.com/cfrg/draft-irtf-cfrg-frost/pull/231.
* Use Zeroize on FROST keygen/signing
* Zeroize constant time multiexp.
* Correct when FROST keygen zeroizes
* Move the FROST keys Arc into FrostKeys
Reduces amount of instances in memory.
* Manually implement Debug for FrostCore to not leak the secret share
* Misc bug fixes
* clippy + multiexp test bug fixes
* Correct FROST key gen share summation
It leaked our own share for ourself.
* Fix cross-group DLEq tests
2022-08-03 08:25:18 +00:00
|
|
|
use zeroize::Zeroize;
|
|
|
|
|
2024-02-18 04:16:16 +00:00
|
|
|
use curve25519_dalek::edwards::EdwardsPoint;
|
|
|
|
|
|
|
|
use monero_generators::decompress_point;
|
2022-06-28 04:01:20 +00:00
|
|
|
|
|
|
|
use base58_monero::base58::{encode_check, decode_check};
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
/// The network this address is for.
|
Utilize zeroize (#76)
* Apply Zeroize to nonces used in Bulletproofs
Also makes bit decomposition constant time for a given amount of
outputs.
* Fix nonce reuse for single-signer CLSAG
* Attach Zeroize to most structures in Monero, and ZOnDrop to anything with private data
* Zeroize private keys and nonces
* Merge prepare_outputs and prepare_transactions
* Ensure CLSAG is constant time
* Pass by borrow where needed, bug fixes
The past few commitments have been one in-progress chunk which I've
broken up as best read.
* Add Zeroize to FROST structs
Still needs to zeroize internally, yet next step. Not quite as
aggressive as Monero, partially due to the limitations of HashMaps,
partially due to less concern about metadata, yet does still delete a
few smaller items of metadata (group key, context string...).
* Remove Zeroize from most Monero multisig structs
These structs largely didn't have private data, just fields with private
data, yet those fields implemented ZeroizeOnDrop making them already
covered. While there is still traces of the transaction left in RAM,
fully purging that was never the intent.
* Use Zeroize within dleq
bitvec doesn't offer Zeroize, so a manual zeroing has been implemented.
* Use Zeroize for random_nonce
It isn't perfect, due to the inability to zeroize the digest, and due to
kp256 requiring a few transformations. It does the best it can though.
Does move the per-curve random_nonce to a provided one, which is allowed
as of https://github.com/cfrg/draft-irtf-cfrg-frost/pull/231.
* Use Zeroize on FROST keygen/signing
* Zeroize constant time multiexp.
* Correct when FROST keygen zeroizes
* Move the FROST keys Arc into FrostKeys
Reduces amount of instances in memory.
* Manually implement Debug for FrostCore to not leak the secret share
* Misc bug fixes
* clippy + multiexp test bug fixes
* Correct FROST key gen share summation
It leaked our own share for ourself.
* Fix cross-group DLEq tests
2022-08-03 08:25:18 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
2022-06-28 04:01:20 +00:00
|
|
|
pub enum Network {
|
|
|
|
Mainnet,
|
|
|
|
Testnet,
|
2022-07-15 05:26:07 +00:00
|
|
|
Stagenet,
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:44:49 +00:00
|
|
|
/// The address type, supporting the officially documented addresses, along with
|
|
|
|
/// [Featured Addresses](https://gist.github.com/kayabaNerve/01c50bbc35441e0bbdcee63a9d823789).
|
Utilize zeroize (#76)
* Apply Zeroize to nonces used in Bulletproofs
Also makes bit decomposition constant time for a given amount of
outputs.
* Fix nonce reuse for single-signer CLSAG
* Attach Zeroize to most structures in Monero, and ZOnDrop to anything with private data
* Zeroize private keys and nonces
* Merge prepare_outputs and prepare_transactions
* Ensure CLSAG is constant time
* Pass by borrow where needed, bug fixes
The past few commitments have been one in-progress chunk which I've
broken up as best read.
* Add Zeroize to FROST structs
Still needs to zeroize internally, yet next step. Not quite as
aggressive as Monero, partially due to the limitations of HashMaps,
partially due to less concern about metadata, yet does still delete a
few smaller items of metadata (group key, context string...).
* Remove Zeroize from most Monero multisig structs
These structs largely didn't have private data, just fields with private
data, yet those fields implemented ZeroizeOnDrop making them already
covered. While there is still traces of the transaction left in RAM,
fully purging that was never the intent.
* Use Zeroize within dleq
bitvec doesn't offer Zeroize, so a manual zeroing has been implemented.
* Use Zeroize for random_nonce
It isn't perfect, due to the inability to zeroize the digest, and due to
kp256 requiring a few transformations. It does the best it can though.
Does move the per-curve random_nonce to a provided one, which is allowed
as of https://github.com/cfrg/draft-irtf-cfrg-frost/pull/231.
* Use Zeroize on FROST keygen/signing
* Zeroize constant time multiexp.
* Correct when FROST keygen zeroizes
* Move the FROST keys Arc into FrostKeys
Reduces amount of instances in memory.
* Manually implement Debug for FrostCore to not leak the secret share
* Misc bug fixes
* clippy + multiexp test bug fixes
* Correct FROST key gen share summation
It leaked our own share for ourself.
* Fix cross-group DLEq tests
2022-08-03 08:25:18 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
2022-06-28 04:01:20 +00:00
|
|
|
pub enum AddressType {
|
|
|
|
Standard,
|
|
|
|
Integrated([u8; 8]),
|
2022-07-15 05:26:07 +00:00
|
|
|
Subaddress,
|
2023-01-07 10:37:43 +00:00
|
|
|
Featured { subaddress: bool, payment_id: Option<[u8; 8]>, guaranteed: bool },
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-07 09:44:23 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
|
|
|
pub struct SubaddressIndex {
|
|
|
|
pub(crate) account: u32,
|
|
|
|
pub(crate) address: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SubaddressIndex {
|
|
|
|
pub const fn new(account: u32, address: u32) -> Option<SubaddressIndex> {
|
|
|
|
if (account == 0) && (address == 0) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
Some(SubaddressIndex { account, address })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn account(&self) -> u32 {
|
|
|
|
self.account
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn address(&self) -> u32 {
|
|
|
|
self.address
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 09:33:17 +00:00
|
|
|
/// Address specification. Used internally to create addresses.
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Zeroize)]
|
|
|
|
pub enum AddressSpec {
|
|
|
|
Standard,
|
|
|
|
Integrated([u8; 8]),
|
2023-01-07 09:44:23 +00:00
|
|
|
Subaddress(SubaddressIndex),
|
2023-01-07 10:37:43 +00:00
|
|
|
Featured { subaddress: Option<SubaddressIndex>, payment_id: Option<[u8; 8]>, guaranteed: bool },
|
2023-01-06 09:33:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 04:01:20 +00:00
|
|
|
impl AddressType {
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_subaddress(&self) -> bool {
|
2023-01-07 10:37:43 +00:00
|
|
|
matches!(self, AddressType::Subaddress) ||
|
|
|
|
matches!(self, AddressType::Featured { subaddress: true, .. })
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn payment_id(&self) -> Option<[u8; 8]> {
|
|
|
|
if let AddressType::Integrated(id) = self {
|
|
|
|
Some(*id)
|
2023-01-07 10:37:43 +00:00
|
|
|
} else if let AddressType::Featured { payment_id, .. } = self {
|
|
|
|
*payment_id
|
2022-08-22 08:27:58 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_guaranteed(&self) -> bool {
|
2023-01-07 10:37:43 +00:00
|
|
|
matches!(self, AddressType::Featured { guaranteed: true, .. })
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
/// A type which returns the byte for a given address.
|
2024-04-23 08:31:27 +00:00
|
|
|
pub trait AddressBytes: Clone + Copy + PartialEq + Eq + fmt::Debug {
|
2022-11-15 05:06:15 +00:00
|
|
|
fn network_bytes(network: Network) -> (u8, u8, u8, u8);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Address bytes for Monero.
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
pub struct MoneroAddressBytes;
|
|
|
|
impl AddressBytes for MoneroAddressBytes {
|
|
|
|
fn network_bytes(network: Network) -> (u8, u8, u8, u8) {
|
|
|
|
match network {
|
|
|
|
Network::Mainnet => (18, 19, 42, 70),
|
|
|
|
Network::Testnet => (53, 54, 63, 111),
|
|
|
|
Network::Stagenet => (24, 25, 36, 86),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Address metadata.
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
pub struct AddressMeta<B: AddressBytes> {
|
|
|
|
_bytes: PhantomData<B>,
|
2022-06-28 04:01:20 +00:00
|
|
|
pub network: Network,
|
|
|
|
pub kind: AddressType,
|
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
impl<B: AddressBytes> Zeroize for AddressMeta<B> {
|
|
|
|
fn zeroize(&mut self) {
|
|
|
|
self.network.zeroize();
|
|
|
|
self.kind.zeroize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Error when decoding an address.
|
2023-06-29 08:14:29 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
#[cfg_attr(feature = "std", derive(thiserror::Error))]
|
2022-06-28 04:01:20 +00:00
|
|
|
pub enum AddressError {
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("invalid address byte"))]
|
2022-06-28 04:01:20 +00:00
|
|
|
InvalidByte,
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("invalid address encoding"))]
|
2022-06-28 04:01:20 +00:00
|
|
|
InvalidEncoding,
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("invalid length"))]
|
2022-06-28 04:01:20 +00:00
|
|
|
InvalidLength,
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("invalid key"))]
|
2022-07-15 05:26:07 +00:00
|
|
|
InvalidKey,
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("unknown features"))]
|
2022-08-22 08:27:58 +00:00
|
|
|
UnknownFeatures,
|
2023-06-29 08:14:29 +00:00
|
|
|
#[cfg_attr(feature = "std", error("different network than expected"))]
|
2022-08-22 08:27:58 +00:00
|
|
|
DifferentNetwork,
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
impl<B: AddressBytes> AddressMeta<B> {
|
2022-07-22 06:34:36 +00:00
|
|
|
#[allow(clippy::wrong_self_convention)]
|
2022-06-28 04:01:20 +00:00
|
|
|
fn to_byte(&self) -> u8 {
|
2022-11-15 05:06:15 +00:00
|
|
|
let bytes = B::network_bytes(self.network);
|
2022-08-22 08:27:58 +00:00
|
|
|
match self.kind {
|
2022-06-28 04:01:20 +00:00
|
|
|
AddressType::Standard => bytes.0,
|
|
|
|
AddressType::Integrated(_) => bytes.1,
|
2022-07-15 05:26:07 +00:00
|
|
|
AddressType::Subaddress => bytes.2,
|
2023-01-07 10:37:43 +00:00
|
|
|
AddressType::Featured { .. } => bytes.3,
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
/// Create an address's metadata.
|
|
|
|
pub fn new(network: Network, kind: AddressType) -> Self {
|
|
|
|
AddressMeta { _bytes: PhantomData, network, kind }
|
|
|
|
}
|
|
|
|
|
2023-01-07 10:37:43 +00:00
|
|
|
// Returns an incomplete instantiation in the case of Integrated/Featured addresses
|
2022-11-15 05:06:15 +00:00
|
|
|
fn from_byte(byte: u8) -> Result<Self, AddressError> {
|
2022-06-28 04:01:20 +00:00
|
|
|
let mut meta = None;
|
|
|
|
for network in [Network::Mainnet, Network::Testnet, Network::Stagenet] {
|
2022-11-15 05:06:15 +00:00
|
|
|
let (standard, integrated, subaddress, featured) = B::network_bytes(network);
|
2022-08-22 08:27:58 +00:00
|
|
|
if let Some(kind) = match byte {
|
|
|
|
_ if byte == standard => Some(AddressType::Standard),
|
|
|
|
_ if byte == integrated => Some(AddressType::Integrated([0; 8])),
|
|
|
|
_ if byte == subaddress => Some(AddressType::Subaddress),
|
2023-01-07 10:37:43 +00:00
|
|
|
_ if byte == featured => {
|
|
|
|
Some(AddressType::Featured { subaddress: false, payment_id: None, guaranteed: false })
|
|
|
|
}
|
2022-07-15 05:26:07 +00:00
|
|
|
_ => None,
|
2022-06-28 04:01:20 +00:00
|
|
|
} {
|
2022-11-15 05:06:15 +00:00
|
|
|
meta = Some(AddressMeta::new(network, kind));
|
2022-06-28 04:01:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.ok_or(AddressError::InvalidByte)
|
|
|
|
}
|
2022-08-22 08:27:58 +00:00
|
|
|
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_subaddress(&self) -> bool {
|
|
|
|
self.kind.is_subaddress()
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn payment_id(&self) -> Option<[u8; 8]> {
|
|
|
|
self.kind.payment_id()
|
|
|
|
}
|
|
|
|
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_guaranteed(&self) -> bool {
|
|
|
|
self.kind.is_guaranteed()
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
/// A Monero address, composed of metadata and a spend/view key.
|
2023-07-29 07:56:59 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
2022-11-15 05:06:15 +00:00
|
|
|
pub struct Address<B: AddressBytes> {
|
|
|
|
pub meta: AddressMeta<B>,
|
2022-06-28 04:01:20 +00:00
|
|
|
pub spend: EdwardsPoint,
|
2022-07-15 05:26:07 +00:00
|
|
|
pub view: EdwardsPoint,
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 08:31:27 +00:00
|
|
|
impl<B: AddressBytes> fmt::Debug for Address<B> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
2023-07-29 07:56:59 +00:00
|
|
|
fmt
|
|
|
|
.debug_struct("Address")
|
|
|
|
.field("meta", &self.meta)
|
|
|
|
.field("spend", &hex::encode(self.spend.compress().0))
|
|
|
|
.field("view", &hex::encode(self.view.compress().0))
|
|
|
|
// This is not a real field yet is the most valuable thing to know when debugging
|
|
|
|
.field("(address)", &self.to_string())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
impl<B: AddressBytes> Zeroize for Address<B> {
|
|
|
|
fn zeroize(&mut self) {
|
|
|
|
self.meta.zeroize();
|
|
|
|
self.spend.zeroize();
|
|
|
|
self.view.zeroize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 08:31:27 +00:00
|
|
|
impl<B: AddressBytes> fmt::Display for Address<B> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2022-06-28 04:01:20 +00:00
|
|
|
let mut data = vec![self.meta.to_byte()];
|
|
|
|
data.extend(self.spend.compress().to_bytes());
|
|
|
|
data.extend(self.view.compress().to_bytes());
|
2023-01-07 10:37:43 +00:00
|
|
|
if let AddressType::Featured { subaddress, payment_id, guaranteed } = self.meta.kind {
|
2022-08-22 08:27:58 +00:00
|
|
|
// Technically should be a VarInt, yet we don't have enough features it's needed
|
|
|
|
data.push(
|
2022-09-17 08:35:08 +00:00
|
|
|
u8::from(subaddress) + (u8::from(payment_id.is_some()) << 1) + (u8::from(guaranteed) << 2),
|
2022-08-22 08:27:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if let Some(id) = self.meta.kind.payment_id() {
|
2022-06-28 04:01:20 +00:00
|
|
|
data.extend(id);
|
|
|
|
}
|
2024-04-23 08:31:27 +00:00
|
|
|
write!(f, "{}", encode_check(&data).unwrap())
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
impl<B: AddressBytes> Address<B> {
|
|
|
|
pub fn new(meta: AddressMeta<B>, spend: EdwardsPoint, view: EdwardsPoint) -> Self {
|
2022-08-22 08:27:58 +00:00
|
|
|
Address { meta, spend, view }
|
|
|
|
}
|
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
pub fn from_str_raw(s: &str) -> Result<Self, AddressError> {
|
2022-06-28 04:01:20 +00:00
|
|
|
let raw = decode_check(s).map_err(|_| AddressError::InvalidEncoding)?;
|
2022-08-22 08:27:58 +00:00
|
|
|
if raw.len() < (1 + 32 + 32) {
|
2022-06-28 04:01:20 +00:00
|
|
|
Err(AddressError::InvalidLength)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut meta = AddressMeta::from_byte(raw[0])?;
|
2024-02-18 04:16:16 +00:00
|
|
|
let spend =
|
|
|
|
decompress_point(raw[1 .. 33].try_into().unwrap()).ok_or(AddressError::InvalidKey)?;
|
|
|
|
let view =
|
|
|
|
decompress_point(raw[33 .. 65].try_into().unwrap()).ok_or(AddressError::InvalidKey)?;
|
2022-08-22 08:27:58 +00:00
|
|
|
let mut read = 65;
|
|
|
|
|
2023-01-07 10:37:43 +00:00
|
|
|
if matches!(meta.kind, AddressType::Featured { .. }) {
|
2022-08-22 08:27:58 +00:00
|
|
|
if raw[read] >= (2 << 3) {
|
|
|
|
Err(AddressError::UnknownFeatures)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let subaddress = (raw[read] & 1) == 1;
|
|
|
|
let integrated = ((raw[read] >> 1) & 1) == 1;
|
|
|
|
let guaranteed = ((raw[read] >> 2) & 1) == 1;
|
|
|
|
|
2023-01-07 10:37:43 +00:00
|
|
|
meta.kind = AddressType::Featured {
|
|
|
|
subaddress,
|
|
|
|
payment_id: Some([0; 8]).filter(|_| integrated),
|
|
|
|
guaranteed,
|
|
|
|
};
|
2022-08-22 08:27:58 +00:00
|
|
|
read += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update read early so we can verify the length
|
|
|
|
if meta.kind.payment_id().is_some() {
|
|
|
|
read += 8;
|
|
|
|
}
|
|
|
|
if raw.len() != read {
|
|
|
|
Err(AddressError::InvalidLength)?;
|
|
|
|
}
|
2022-06-28 04:01:20 +00:00
|
|
|
|
2022-08-22 08:27:58 +00:00
|
|
|
if let AddressType::Integrated(ref mut id) = meta.kind {
|
|
|
|
id.copy_from_slice(&raw[(read - 8) .. read]);
|
|
|
|
}
|
2023-01-07 10:37:43 +00:00
|
|
|
if let AddressType::Featured { payment_id: Some(ref mut id), .. } = meta.kind {
|
2022-08-22 08:27:58 +00:00
|
|
|
id.copy_from_slice(&raw[(read - 8) .. read]);
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Address { meta, spend, view })
|
|
|
|
}
|
2022-08-22 08:27:58 +00:00
|
|
|
|
2022-11-15 05:06:15 +00:00
|
|
|
pub fn from_str(network: Network, s: &str) -> Result<Self, AddressError> {
|
2022-08-22 08:27:58 +00:00
|
|
|
Self::from_str_raw(s).and_then(|addr| {
|
|
|
|
if addr.meta.network == network {
|
|
|
|
Ok(addr)
|
|
|
|
} else {
|
|
|
|
Err(AddressError::DifferentNetwork)?
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn network(&self) -> Network {
|
|
|
|
self.meta.network
|
|
|
|
}
|
|
|
|
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_subaddress(&self) -> bool {
|
|
|
|
self.meta.is_subaddress()
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn payment_id(&self) -> Option<[u8; 8]> {
|
|
|
|
self.meta.payment_id()
|
|
|
|
}
|
|
|
|
|
2023-01-21 06:24:13 +00:00
|
|
|
pub fn is_guaranteed(&self) -> bool {
|
|
|
|
self.meta.is_guaranteed()
|
2022-08-22 08:27:58 +00:00
|
|
|
}
|
2022-06-28 04:01:20 +00:00
|
|
|
}
|
2022-11-15 05:06:15 +00:00
|
|
|
|
|
|
|
/// Instantiation of the Address type with Monero's network bytes.
|
|
|
|
pub type MoneroAddress = Address<MoneroAddressBytes>;
|
|
|
|
// Allow re-interpreting of an arbitrary address as a monero address so it can be used with the
|
|
|
|
// rest of this library. Doesn't use From as it was conflicting with From<T> for T.
|
|
|
|
impl MoneroAddress {
|
|
|
|
pub fn from<B: AddressBytes>(address: Address<B>) -> MoneroAddress {
|
|
|
|
MoneroAddress::new(
|
|
|
|
AddressMeta::new(address.meta.network, address.meta.kind),
|
|
|
|
address.spend,
|
|
|
|
address.view,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|