Methods
Login
The login method allows users to log in using OAuth providers. It accepts the following parameters:
* provider: The OAuth provider to login with.
export enum AUTH_PROVIDERS {
OAUTH = "OAUTH",
EVM = "EVM"
}
* options:
** forceEmail: Optional. An email to force during login.
** forcePhone: Optional. A phone number to force during login.
Return Type:
The function returns a promise which resolves when the user successfully logs in.
Usage Example:
await passport.login(AUTH_PROVIDERS.OAUTH, {
forceEmail: 'example@example.com'
});JWT Login
The JWT login method allows user to use his own JWT validator with his own access_token or id_token
* options:
** validatorId: required. Id of your validator.
** idToken: Optional.
** accessToken: Optional.
Either idToken Or accessToken should be used. Using both simultaneously will cause an error.
Usage Example:
await passport.jwtLogin({
validatorId: 'validatorId',
idToken: 'idToken',
accessToken: 'accessToken'
});Logout
The logout method logs the user out and optionally revokes the session. It accepts an optional parameter:
* shouldRevokeSession: Defaults to false. If set to true, the session will be revoked.
Return Type:
The function does not return a value.
Usage Example:
await passport.logout({ shouldRevokeSession: true });OpenUI
The openUI method opens the user interface. It accepts the following optional parameters:
* page: The page to display.
* pageOpts: Options for the page.
Return Type:
The function does not return a value.
Usage Example:
await passport.openUI(Passport.pages.PAYMENT, { someOption: true });Close
The close method hides the user interface.
Return Type:
The function does not return a value.
Usage Example:
passport.close();ToastAlert
The toastAlert method displays a toast notification. It accepts the following parameters:
* message: The message to display.
* type: The type of message (success, warning, failure, info). Defaults to info.
* opts: Optional settings for the toast.
Return Type:
The function does not return a value.
Usage Example:
passport.toastAlert('This is a success message', 'success', { duration: 5000 });Destroy
The destroy method cleans up UI components.
Return Type:
The function does not return a value.
Usage Example:
await passport.destroy();HideNavigation
The hideNavigation method hides the navigation bar.
Return Type:
The function does not return a value.
Usage Example:
passport.hideNavigation();ShowNavigation
The showNavigation method displays the navigation bar with optional styles and configurations. It accepts the following parameters:
* styles: Optional CSS styles for the navigation bar.
* navConfig: Optional navigation configuration.
Return Type:
The function does not return a value.
Usage Example:
await passport.showNavigation({"right":"25px","bottom":"50px"});
Init
The init method initializes the Passport using Credenza SDK settings. It configures the network type, and extensions, and retrieves access tokens if available.
Parameters: - None
Return Type: - None
Usage Example:
await passport.init();getCREDContract
The getCREDContract function retrieves details of the CRED token, such as its address and decimal values.
Parameters: - None
Return Type:
Promise<{ contract: ethers.Contract, decimals: number, address: string>
Error Conditions:
Throws an error if the address or decimals are not available for the current
chainId.
Usage Example:
await passport.getCREDContract();Check Membership
The checkMembership method checks whether a user owns a specific membership package.
Parameters:
- membershipOwner: string - The address of the membership owner.
- membershipAddress: string - Membership contract address.
Return Type: - Promise<{ isMember: boolean, meta: object }>
Usage Example:
const membershipStatus = await passport.checkMembership("user_address",
"contract_address");Send Tokens
The sendTokens method sends tokens from the current user to a specified recipient.
Parameters:
- address: string - The address of the recipient.
- amount: number | bigint - The number of tokens to send.
-instance?: ethers.Contract - if contract instance is passed, CRED transfer will be executed, otherwise, blockchain native currency transfer will be executed (MATIC/CHILLIZ, etc.)
Return Type: - Promise<void>
Usage Example:
await passport.sendTokens({address: 'user_address', amount: 100});Get Web3 Provider
The getWeb3Provider method retrieves the blockchain provider.
Parameters: - None
Return Type: - ethers.BrowserProvider
Usage Example:
const provider = await passport.getWeb3Provider();
Get Address
The getAddress method retrieves the current user's blockchain address.
Parameters: - None
Return Type: - Promise<string | null>
Usage Example:
const address = await passport.getAddress();
Send NFT
The sendNft method transfers an NFT owned by the current user to a specified recipient.
Parameters:
-opts: {
contract: ethers.Contract;
recipient: string;
tokenId: string;
amount: number;
}
Return Type: - Promise<ethers.TransactionResponse>
Usage Example:
const signer = await passport.provider.getSigner();
const signerAddress = await signer.getAddress();
const contract = await getCredenzaContract({
address: contractAddress,
signer,
name: "CredenzaERC1155Contract",
});
const result = await passport.sendNft({
contract,
recipient: recipientAddress,
tokenId,
amount: amount,
});SwitchChain Method
The switchChain method changes the blockchain network.
Parameters:
* chainId: The id of the new blockchain.
Return Type: None
Usage Example:
await passport.switchChain({ chainId: '137' });
GetBalance Method
The getBalance method retrieves the user's token balance.
Parameters: None
Return Type: * Promise<string>: The user's token balance.
Usage Example:
const balance = await passport.getBalance();
RequestAirDrop Method
The requestAirDrop method requests a token airdrop.
Parameters:
*opts {
contractAddress: string;
tokenId?: string | number;
amount?: number;
targetAddress: string;
progressVideos?: {src: string; embedded?: boolean}[]
}
Return Type: None
Usage Example:
await passport.requestAirDrop({ contractAddress: "address", amount: 100, targetAddress: "target" });
UpdateProfile Method
The updateProfile method updates the user's profile information.
Parameters: * profileDataOpts: An object containing profile data to update (name, email, phone).
Return Type: * Promise<User>: The updated user information.
Usage Example:
await passport.updateProfile({ name: 'John Doe', email: 'john@example.com' });
ConfirmAccount Method
The confirmAccount method confirms the user's account using verification codes.
Parameters: * codes: An object containing phone and/or email verification codes.
If you'd like to confirm phone change, use phoneCode field, if email change, use emailCode
Return Type: * Promise<User>: The confirmed user information.
Usage Example:
await passport.confirmAccount({ phoneCode: '123456', emailCode: 'abcdef' });
GetUser Method
The getUser method retrieves the current user's information.
Parameters: None
Return Type: * Promise<User>: The current user's information.
Usage Example:
const user = await passport.getUser();
Request Loyalty Points Method
The requestLoyaltyPoints requests loyalty points for logged in user by event Id and contractAddress.
Parameters: -
eventId: string,
contractAddress: string
Return Type: * Promise<void>.
Usage Example:
const user = await passport.requestLoyaltyPoints("event_id", "contract_address");
Get Tokens Method
The getTokens returns current user's list of tokens or nfts.
Parameters:
tokenType?: 'token' | 'nft' = token by the default
Return Type: * Promise<{
pagination: { total?: number; page: number; pageSize: number; cursor?: string; },
result: { amount: number contract_type: string // e.g. "ERC721" name: string symbol: string token_address: string token_id: string token_uri: string }[]}>.
Usage Example:
const user = await passport.getTokens();
Get NFT Method
The getNfts returns current user's list of nfts.
Parameters: - None
Return Type: * Promise<{
pagination: { total?: number; page: number; pageSize: number; cursor?: string; },
result: { amount: number contract_type: string // e.g. "ERC721" name: string symbol: string token_address: string token_id: string token_uri: string }[]
}>
Usage Example:
const user = await passport.getNfts();
Instance properties
{
isLoggedIn: boolean
provider: ethers.BrowserProvider
chainId: '137'
config: Config instance
user: User instance
accessToken: string
networkType: 'testnet' | 'mainnet'
ethers: Ethers
contracts: {
erc20Cred: {
address: string;
decimals: number;
};
membership: {
address: string;
};
}Static Properties with Expanded Options
Passport.version provides the current package version.
Passport.chains offers supported networks.
enum {
POLYGON = "137",
POLYGON_AMOY = "80002",
CHILIZ_SPICY = "88882",
CHILIZ = "88888",
}Passport.events lists supported events.
enum {
ERROR = 'ERROR',
INIT = 'INIT',
LOGIN = 'LOGIN',
LOGOUT = 'LOGOUT',
PAYMENT = 'PAYMENT',
SEND_TOKENS = 'SEND_TOKENS',
SEND_NFT = 'SEND_NFT',
RECHECK_BALANCE = 'RECHECK_BALANCE',
UPDATE_PROFILE = 'UPDATE_PROFILE',
ACCOUNT_CONFIRMED = 'ACCOUNT_CONFIRMED',
TRANSACTION = 'TRANSACTION',
RECEIPT = 'RECEIPT',
UI_CLOSED = 'UI_CLOSED',
REQUEST_AIRDROP = 'REQUEST_AIRDROP',
REQUEST_LOYALTY_POINTS = 'REQUEST_LOYALTY_POINTS',
}
Passport.scanTypes includes supported scan types.
enum {
PASSPORT_ID = 'PASSPORT_ID',
TOKENS_PURCHASE = 'TOKENS_PURCHASE',
AIR_DROP = 'AIR_DROP',
REQUEST_LOYALTY_POINTS = 'REQUEST_LOYALTY_POINTS',
PASSPORT_ID_PASS = 'PASSPORT_ID_PASS',
}
Passport.pages displays available pages for logged-in users.
enum {
PROFILE = 'profile',
LOGOUT = 'logout',
LOGIN = 'login',
PASSPORT_ID = 'passportId',
WALLET = 'wallet',
UPDATE_PROFILE = 'updateProfile',
SEND_TOKENS = 'sendTokens',
CONFIRM_ACCOUNT = 'confirmAccount',
PAYMENT = 'payment',
PAYMENT_RESULT = 'paymentResult',
SCANNER = 'scanner',
ERROR = 'error',
LOADER = 'loader',
SIGN = 'sign',
}
Passport.themes lists available color schemes.
enum {
WHITE = 'WHITE',
BLACK = 'BLACK',
}
Passport.navDirections indicates available directions for the navigation bar.
enum {
TOP = 'TOP',
BOTTOM = 'BOTTOM'
}
Passport.navMinimizationTogglerPositions defines positions for the minimization toggle.
enum {
LEFT = 'LEFT',
RIGHT = 'RIGHT',
}