ZkLoginPublicIdentifier

Struct ZkLoginPublicIdentifier 

Source
pub struct ZkLoginPublicIdentifier { /* private fields */ }
Expand description

Public Key equivalent for Zklogin authenticators

A ZkLoginPublicIdentifier is the equivalent of a public key for other account authenticators, and contains the information required to derive the onchain account Address for a Zklogin authenticator.

§Note

Due to a historical bug that was introduced in the Sui Typescript SDK when the zklogin authenticator was first introduced, there are now possibly two “valid” addresses for each zklogin authenticator depending on the bit-pattern of the address_seed value.

The original bug incorrectly derived a zklogin’s address by stripping any leading zero-bytes that could have been present in the 32-byte length address_seed value prior to hashing, leading to a different derived address. This incorrectly derived address was presented to users of various wallets, leading them to sending funds to these addresses that they couldn’t access. Instead of letting these users lose any assets that were sent to these addresses, the Sui network decided to change the protocol to allow for a zklogin authenticator who’s address_seed value had leading zero-bytes be authorized to sign for both the addresses derived from both the unpadded and padded address_seed value.

§BCS

The BCS serialized form for this type is defined by the following ABNF:

zklogin-public-identifier-bcs = bytes ; where the contents are defined by
                                      ; <zklogin-public-identifier>

zklogin-public-identifier = zklogin-public-identifier-iss
                            address-seed

zklogin-public-identifier-unpadded = zklogin-public-identifier-iss
                                     address-seed-unpadded

; The iss, or issuer, is a utf8 string that is less than 255 bytes long
; and is serialized with the iss's length in bytes as a u8 followed by
; the bytes of the iss
zklogin-public-identifier-iss = u8 *255(OCTET)

; A Bn254FieldElement serialized as a 32-byte big-endian value
address-seed = 32(OCTET)

; A Bn254FieldElement serialized as a 32-byte big-endian value
; with any leading zero bytes stripped
address-seed-unpadded = %x00 / %x01-ff *31(OCTET)

Implementations§

Source§

impl ZkLoginPublicIdentifier

Source

pub fn scheme(&self) -> SignatureScheme

Return the flag for this signature scheme

Source§

impl ZkLoginPublicIdentifier

Source

pub fn new(iss: String, address_seed: Bn254FieldElement) -> Option<Self>

Source

pub fn iss(&self) -> &str

Source

pub fn address_seed(&self) -> &Bn254FieldElement

Source§

impl ZkLoginPublicIdentifier

Source

pub fn derive_address_padded(&self) -> Address

Available on crate feature hash only.

Derive an Address from this ZkLoginPublicIdentifier by hashing the byte length of the iss followed by the iss bytes themselves and the full 32 byte address_seed value, all prefixed with the zklogin SignatureScheme flag (0x05).

hash( 0x05 || iss_bytes_len || iss_bytes || 32_byte_address_seed )

Source

pub fn derive_address_unpadded(&self) -> Address

Available on crate feature hash only.

Derive an Address from this ZkLoginPublicIdentifier by hashing the byte length of the iss followed by the iss bytes themselves and the address_seed bytes with any leading zero-bytes stripped, all prefixed with the zklogin SignatureScheme flag (0x05).

hash( 0x05 || iss_bytes_len || iss_bytes || unpadded_32_byte_address_seed )

Source

pub fn derive_address(&self) -> impl ExactSizeIterator<Item = Address>

Available on crate feature hash only.

Provides an iterator over the addresses that correspond to this zklogin authenticator.

In the majority of instances this will only yield a single address, except for the instances where the address_seed value has a leading zero-byte, in such cases the returned iterator will yield two addresses.

Trait Implementations§

Source§

impl Arbitrary for ZkLoginPublicIdentifier

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<ZkLoginPublicIdentifier>

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 Clone for ZkLoginPublicIdentifier

Source§

fn clone(&self) -> ZkLoginPublicIdentifier

Returns a duplicate 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 ZkLoginPublicIdentifier

Source§

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

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

impl<'de> Deserialize<'de> for ZkLoginPublicIdentifier

Available on crate feature serde only.
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 PartialEq for ZkLoginPublicIdentifier

Source§

fn eq(&self, other: &ZkLoginPublicIdentifier) -> 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 Serialize for ZkLoginPublicIdentifier

Available on crate feature serde only.
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 Eq for ZkLoginPublicIdentifier

Source§

impl StructuralPartialEq for ZkLoginPublicIdentifier

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_bcs<'de>(bytes: &'de [u8]) -> Result<Self, Error>
where Self: Deserialize<'de>,

Available on crate feature serde only.
Source§

fn from_bcs_base64(base64: &str) -> Result<Self, Error>
where Self: DeserializeOwned,

Available on crate feature serde only.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToBcs for T
where T: Serialize,

Source§

fn to_bcs(&self) -> Result<Vec<u8>, Error>

Available on crate feature serde only.
Source§

fn to_bcs_base64(&self) -> Result<String, Error>

Available on crate feature serde only.
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, 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>,