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 account Address
Account 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.
§Usage as ObjectIds
Address
es are also used as a way to uniquely identify an Object
. When an Address
is
used as an object identifierit can also be referred to as an ObjectId
. ObjectId
s and
account Address
es 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
impl Address
pub const LENGTH: usize = 32usize
pub const ZERO: Address
pub const TWO: Address
pub const THREE: Address
pub const fn new(bytes: [u8; 32]) -> Address
Sourcepub const fn into_inner(self) -> [u8; 32]
pub const fn into_inner(self) -> [u8; 32]
Return the underlying byte array of a Address.
pub const fn inner(&self) -> &[u8; 32]
pub const fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn from_hex<T>(hex: T) -> Result<Address, AddressParseError>
pub fn from_hex<T>(hex: T) -> Result<Address, AddressParseError>
Decodes an address from a hex encoded string.
Sourcepub const fn from_hex_unwrap(hex: &[u8]) -> Address
pub const fn from_hex_unwrap(hex: &[u8]) -> Address
Decodes an address from a hex encoded string.
Similar to from_hex
except any errors are unwrapped, turning them into panics.
pub fn to_hex(&self) -> String
pub fn from_bytes<T>(bytes: T) -> Result<Address, AddressParseError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Address
impl<'de> Deserialize<'de> for Address
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Address, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Address, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl MoveType for Address
impl MoveType for Address
Source§impl Ord for Address
impl Ord for Address
Source§impl PartialOrd for Address
impl PartialOrd for Address
Source§impl Serialize for Address
impl Serialize for Address
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl StaticTypeTag for Address
impl StaticTypeTag for Address
impl Copy for Address
impl Eq for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)