Skip to main content

Module 0x2::zklogin_verified_issuer

use 0x1::string;
use 0x2::object;
use 0x2::transfer;
use 0x2::tx_context;

Resource VerifiedIssuer

Possession of a VerifiedIssuer proves that the user's address was created using zklogin and with the given issuer (identity provider).

struct VerifiedIssuer has key
Fields
id: object::UID
The ID of this VerifiedIssuer
owner: address
The address this VerifiedID is associated with
issuer: string::String
The issuer

Constants

Error if the proof consisting of the inputs provided to the verification function is invalid.

const EInvalidInput: u64 = 0;

Error if the proof consisting of the inputs provided to the verification function is invalid.

const EInvalidProof: u64 = 1;

Function owner

Returns the address associated with the given VerifiedIssuer

public fun owner(verified_issuer: &zklogin_verified_issuer::VerifiedIssuer): address
Implementation
public fun owner(verified_issuer: &VerifiedIssuer): address {
    verified_issuer.owner
}

Function issuer

Returns the issuer associated with the given VerifiedIssuer

public fun issuer(verified_issuer: &zklogin_verified_issuer::VerifiedIssuer): &string::String
Implementation
public fun issuer(verified_issuer: &VerifiedIssuer): &String {
    &verified_issuer.issuer
}

Function delete

Delete a VerifiedIssuer

public fun delete(verified_issuer: zklogin_verified_issuer::VerifiedIssuer)
Implementation
public fun delete(verified_issuer: VerifiedIssuer) {
    let VerifiedIssuer { id, owner: _, issuer: _ } = verified_issuer;
    id.delete();
}

Function verify_zklogin_issuer

Verify that the caller's address was created using zklogin with the given issuer. If so, a VerifiedIssuer object with the issuers id transferred to the caller.

Aborts with EInvalidProof if the verification fails.

public fun verify_zklogin_issuer(address_seed: u256, issuer: string::String, ctx: &mut tx_context::TxContext)
Implementation
public fun verify_zklogin_issuer(address_seed: u256, issuer: String, ctx: &mut TxContext) {
    let sender = ctx.sender();
    assert!(check_zklogin_issuer(sender, address_seed, &issuer), EInvalidProof);
    transfer::transfer(
        VerifiedIssuer {
            id: object::new(ctx),
            owner: sender,
            issuer,
        },
        sender,
    )
}

Function check_zklogin_issuer

Returns true if address was created using zklogin with the given issuer and address seed.

public fun check_zklogin_issuer(address: address, address_seed: u256, issuer: &string::String): bool
Implementation
public fun check_zklogin_issuer(address: address, address_seed: u256, issuer: &String): bool {
    check_zklogin_issuer_internal(address, address_seed, issuer.as_bytes())
}

Function check_zklogin_issuer_internal

Returns true if address was created using zklogin with the given issuer and address seed.

Aborts with EInvalidInput if the iss input is not a valid UTF-8 string.

fun check_zklogin_issuer_internal(address: address, address_seed: u256, issuer: &vector<u8>): bool
Implementation
native fun check_zklogin_issuer_internal(
    address: address,
    address_seed: u256,
    issuer: &vector<u8>,
): bool;