pub struct Secp256r1PublicKey(/* private fields */);
Expand description
A secp256r1 public key.
§BCS
The BCS serialized form for this type is defined by the following ABNF:
secp256r1-public-key = 33OCTECT
Implementations§
Source§impl Secp256r1PublicKey
impl Secp256r1PublicKey
pub const fn new(bytes: [u8; 33]) -> Self
pub fn generate<R>(rng: R) -> Self
Available on crate feature
rand
only.Sourcepub const fn into_inner(self) -> [u8; 33]
pub const fn into_inner(self) -> [u8; 33]
Return the underlying byte array of an Secp256r1PublicKey.
pub const fn inner(&self) -> &[u8; 33]
pub const fn as_bytes(&self) -> &[u8] ⓘ
pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self, TryFromSliceError>
Source§impl Secp256r1PublicKey
impl Secp256r1PublicKey
Sourcepub fn scheme(&self) -> SignatureScheme
pub fn scheme(&self) -> SignatureScheme
Return the flag for this signature scheme
Source§impl Secp256r1PublicKey
impl Secp256r1PublicKey
Sourcepub fn derive_address(&self) -> Address
Available on crate feature hash
only.
pub fn derive_address(&self) -> Address
hash
only.Derive an Address
from this Public Key
An Address
can be derived from a Secp256r1PublicKey
by hashing the bytes of the public
key prefixed with the Secp256r1 SignatureScheme
flag (0x02
).
hash( 0x02 || 33-byte secp256r1 public key)
use sui_sdk_types::hash::Hasher;
use sui_sdk_types::Address;
use sui_sdk_types::Secp256r1PublicKey;
let public_key_bytes = [0; 33];
let mut hasher = Hasher::new();
hasher.update([0x02]); // The SignatureScheme flag for Secp256r1 is `2`
hasher.update(public_key_bytes);
let address = Address::new(hasher.finalize().into_inner());
println!("Address: {}", address);
let public_key = Secp256r1PublicKey::new(public_key_bytes);
assert_eq!(address, public_key.derive_address());
Trait Implementations§
Source§impl Arbitrary for Secp256r1PublicKey
impl Arbitrary for Secp256r1PublicKey
Source§type Parameters = ()
type Parameters = ()
The type of parameters that
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.Source§type Strategy = BoxedStrategy<Secp256r1PublicKey>
type Strategy = BoxedStrategy<Secp256r1PublicKey>
The type of
Strategy
used to generate values of type Self
.Source§fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> Self::Strategy
fn arbitrary_with(args: <Self as Arbitrary>::Parameters) -> Self::Strategy
Source§impl AsRef<[u8]> for Secp256r1PublicKey
impl AsRef<[u8]> for Secp256r1PublicKey
Source§impl Clone for Secp256r1PublicKey
impl Clone for Secp256r1PublicKey
Source§fn clone(&self) -> Secp256r1PublicKey
fn clone(&self) -> Secp256r1PublicKey
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Secp256r1PublicKey
impl Debug for Secp256r1PublicKey
Source§impl<'de> Deserialize<'de> for Secp256r1PublicKey
impl<'de> Deserialize<'de> for Secp256r1PublicKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 Secp256r1PublicKey
impl Display for Secp256r1PublicKey
Source§impl From<Secp256r1PublicKey> for [u8; 33]
impl From<Secp256r1PublicKey> for [u8; 33]
Source§fn from(public_key: Secp256r1PublicKey) -> Self
fn from(public_key: Secp256r1PublicKey) -> Self
Converts to this type from the input type.
Source§impl FromStr for Secp256r1PublicKey
impl FromStr for Secp256r1PublicKey
Source§impl Hash for Secp256r1PublicKey
impl Hash for Secp256r1PublicKey
Source§impl Ord for Secp256r1PublicKey
impl Ord for Secp256r1PublicKey
Source§fn cmp(&self, other: &Secp256r1PublicKey) -> Ordering
fn cmp(&self, other: &Secp256r1PublicKey) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for Secp256r1PublicKey
impl PartialEq for Secp256r1PublicKey
Source§impl PartialOrd for Secp256r1PublicKey
impl PartialOrd for Secp256r1PublicKey
Source§impl Serialize for Secp256r1PublicKey
impl Serialize for Secp256r1PublicKey
impl Copy for Secp256r1PublicKey
impl Eq for Secp256r1PublicKey
impl StructuralPartialEq for Secp256r1PublicKey
Auto Trait Implementations§
impl Freeze for Secp256r1PublicKey
impl RefUnwindSafe for Secp256r1PublicKey
impl Send for Secp256r1PublicKey
impl Sync for Secp256r1PublicKey
impl Unpin for Secp256r1PublicKey
impl UnwindSafe for Secp256r1PublicKey
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
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 moreSource§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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§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>,
Encode the hex strict representing
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>,
Encode the hex strict representing
self
into the result. Upper case
letters are used (e.g. F9B4CA
)