sui_sdk_types

Struct Address

Source
pub struct Address(/* private fields */);
Expand description

Unique identifier for an Account on the Sui blockchain.

An Address is a 32-byte pseudonymous identifier used to uniquely identify an account and asset-ownership on the Sui blockchain. Often, human-readable addresses are encoded in hexadecimal with a 0x prefix. For example, this is a valid Sui address: 0x02a212de6a9dfa3a69e22387acfbafbb1a9e591bd9d636e7895dcfc8de05f331.

use sui_sdk_types::Address;

let hex = "0x02a212de6a9dfa3a69e22387acfbafbb1a9e591bd9d636e7895dcfc8de05f331";
let address = Address::from_hex(hex).unwrap();
println!("Address: {}", address);
assert_eq!(hex, address.to_string());

§Deriving an Address

Addresses are cryptographically derived from a number of user account authenticators, the simplest of which is an Ed25519PublicKey.

Deriving an address consists of the Blake2b256 hash of the sequence of bytes of its corresponding authenticator, prefixed with a domain-separator. For each authenticator, this domain-separator is the single byte-value of its SignatureScheme flag. E.g. hash(signature schema flag || authenticator bytes).

Each authenticator includes a convince method for deriving its Address as well as documentation for the specifics of how the derivation is done. See Ed25519PublicKey::derive_address for an example.

§Relationship to ObjectIds

ObjectIds and Addresses share the same 32-byte addressable space but are derived leveraging different domain-separator values to ensure, cryptographically, that there won’t be any overlap, e.g. there can’t be a valid Object whose ObjectId is equal to that of the Address of a user account.

§BCS

An Address’s BCS serialized form is defined by the following:

address = 32OCTET

Implementations§

Source§

impl Address

Source

pub const LENGTH: usize = 32usize

Source

pub const ZERO: Self = _

Source

pub const TWO: Self = _

Source

pub const THREE: Self = _

Source

pub const fn new(bytes: [u8; 32]) -> Self

Source

pub fn generate<R>(rng: R) -> Self
where R: RngCore + CryptoRng,

Available on crate feature rand only.
Source

pub const fn into_inner(self) -> [u8; 32]

Return the underlying byte array of a Address.

Source

pub const fn inner(&self) -> &[u8; 32]

Source

pub const fn as_bytes(&self) -> &[u8]

Source

pub fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, AddressParseError>

Source

pub fn to_hex(&self) -> String

Source

pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, AddressParseError>

Trait Implementations§

Source§

impl Arbitrary for Address

Source§

type Parameters = ()

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Address>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl AsRef<[u8]> for Address

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<[u8; 32]> for Address

Source§

fn as_ref(&self) -> &[u8; 32]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Address

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[u8; 32]> for Address

Source§

fn from(address: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for [u8; 32]

Source§

fn from(address: Address) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for ObjectId

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<Address> for Vec<u8>

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<ObjectId> for Address

Source§

fn from(value: ObjectId) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Address

Source§

type Err = AddressParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Address

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Address

Source§

fn cmp(&self, other: &Address) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Address

Source§

fn partial_cmp(&self, other: &Address) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Address

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Address

Source§

impl Eq for Address

Source§

impl StructuralPartialEq for Address

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,