Skip to main content
You are here: Passport JS SUI SDK

Passport JS SUI SDK API

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.

typescript
export enum AUTH_PROVIDERS {
  OAUTH = "OAUTH",
}


* 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:

typescript
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:

typescript
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:

typescript
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:

typescript
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:

typescript
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:

typescript
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:

typescript
await passport.destroy();

HideNavigation

The hideNavigation method hides the navigation bar.

Return Type:

The function does not return a value.

Usage Example:

typescript
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:

typescript
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:

typescript
await passport.init();

Check Membership

The checkMembership method checks whether a user owns a specific membership package.

Parameters:

- membershipOwner: string - The address of the membership owner.

- membershipPackage: string - The identifier of the membership package.

Return Type: - Promise<{ isMember: boolean, meta: object }>

Usage Example:

typescript
const membershipStatus = await passport.checkMembership("user_address",
"0xe9dee4296eadd451e6f18b4f754c0f44eefbdb821a9442af26f8a27dc1da6018");

Send Tokens

The sendTokens method sends tokens from the current user to a specified recipient.

Parameters:

- recipient: string - The address of the recipient.

- amount: number - The number of tokens to send.

-isSuiNativeCoinTransfer: boolean, defaults to false.

if isSuiNativeCoinTransfer is set to true passport will do SUI native tokens transfer. Otherwise, CRED transfer.

Return Type: - Promise<void>

Usage Example:

typescript
await passport.sendTokens({ address: 'user_address', amount: 100});

Get Address

The getAddress method retrieves the current user's blockchain address.

Parameters: - None

Return Type: - Promise<string | null>

Usage Example:

typescript
const address = await passport.getAddress();

Send NFT

The sendNft method transfers an NFT owned by the current user to a specified recipient.

Parameters:

-opts: {

packageId: string - The package identifier of the NFT.

recipient: string - The address of the recipient.

assetId?: string - Asset ID in case of asset_collection item transfer.

amount?: string - amount of Assets to transfer in case of asset_collection item transfer.

}

Return Type: - Promise<TransactionResult>

Usage Example:

typescript
await passportBlockchain.sendNft({ packageId: 'nft-package', recipient: '0x789' });

Get User assets wtih balance

The getUserCollectionAssetsWithBalances method returns an object of asset id as a key and balance as a value

Parameters:

* packageId: string The package ID.

Return Type: Promise<{ [assetId: string]: number }>

Usage Example:

typescript
await passport.getUserCollectionAssetsWithBalances(packageId)

SwitchChain Method

The switchChain method changes the blockchain network.

Parameters:

* suiNetworkName: The name of the new blockchain network.

Return Type: None

Usage Example:

typescript
await passport.switchChain({ suiNetworkName: 'testnet' });

RequestLoyaltyPoints Method

The requestLoyaltyPoints method requests loyalty points on event.

Parameters:

eventId: number

packageId: string

Return Type: None

Usage Example:

typescript
await passport.requestLoyaltyPoints(1, "packageId");

GetBalance Method

The getBalance method retrieves the user's token balance.

Parameters: None

Return Type: * Promise<string>: The user's token balance.

Usage Example:

typescript
const balance = await passport.getBalance();

RequestAirDropCoin Method

The requestAirDropCoin method requests a token airdrop.

Parameters:

*opts {

amount: The amount of tokens to request.

coinType: The type of coin (optional; defaults to CRED).

suiNetwork: 'testnet' | 'mainnet'

}

Return Type: None

Usage Example:

typescript
await passport.requestAirDropCoin({ amount: 100, suiNetwork: "testnet" });

RequestAirDropAsset Method

The requestAirDropAsset method requests an asset airdrop.

Parameters:

*opts {

amount: The amount of tokens to request.

packageId: The package id of the collection.

assetId: number. The asset id.

configId: The airdrop config id. (setup on the developers dashboard)

suiNetwork: 'testnet' | 'mainnet'

title?: String of text to represent on passport window during airdrop process.

}

Return Type: None

Usage Example:

typescript
await passport.requestAirDropAsset({ amount: 100, suiNetwork: "testnet", packageId: "", assetId: 1, configId: "" });

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:

typescript
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:

typescript
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:

typescript
const user = await passport.getUser();

Instance properties

typescript
{
  isLoggedIn: boolean
  suiPackage: string // credenza sui package
  suiNetwork: 'testnet' | 'mainnet'
  config: Config instance
  user: User instance
  accessToken: string
  networkType: 'testnet' | 'mainnet'
}

Static Properties with Expanded Options

Passport.version provides the current package version.

Passport.suiNetworks offers supported networks.

typescript
enum {
  DEVNET = 'devnet',
  TESTNET = 'testnet',
  MAINNET = 'mainnet',
}

Passport.events lists supported events.

typescript
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.

typescript
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.

typescript
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.

typescript
enum {
  WHITE = 'WHITE',
  BLACK = 'BLACK',
}

Passport.navDirections indicates available directions for the navigation bar.

typescript
enum {
  TOP = 'TOP',
  BOTTOM = 'BOTTOM'
}

Passport.navMinimizationTogglerPositions defines positions for the minimization toggle.

typescript
enum {
  LEFT = 'LEFT',
  RIGHT = 'RIGHT',
}