myria-core-sdk
Version:
Latest version SDK
176 lines (160 loc) • 8.67 kB
TypeScript
import { RegisteredUserData, UserDataResponse, UserDataV2Response, UserType } from "../types";
import { EnvTypes } from "../typesBundle";
/**
* Create WalletManager instance object
* @class WalletManager
* @param {EnvTypes} env Environment types enum params (Ex: EnvTypes.DEV / EnvTypes.STAGING / EnvTypes.PREPROD / EnvTypes.PROD)
*/
export declare class WalletManager {
private rawProvider;
private web3Provider;
private userApi;
private web3;
private commonApi;
accounts: string[];
currentAccount: string;
constructor(env: EnvTypes);
/**
* @private
* @description Allow to generate the signature for registration process with server time
* @param {string} serverTime milliseconds as string
* @returns {string} a string as the message for metamask's signing
*/
private generateSignatureAccount;
/**
* @private
* @description Perform the register account through account services
* @param walletAddress
* @returns {UserWalletApi} Return user's wallet API response
*/
private registerAccount;
/**
* @private
* @description Register user in L2 system
* @param
* userType: Partner/Customer
* referrerID: starkKey/projectID-gameID
* @returns User data information in L2
*/
private registerL2User;
/**
* @description Perform the connection with current connected metamask account with browser's web session
* @returns {RegisteredUserData} Return the new users (wallet address, details info for wallet)
* @throws {string} Exception: Need to select and connect to metamask accounts
* @example <caption>Sample code</caption>
*
// Sample code on staging:
const walletManager = new WalletManager(EnvTypes.STAGING);
const data = await walletManager.connect();
console.log('Data ->', data);
// Sample code on Production:
const walletManager = new WalletManager(EnvTypes.PRODUCTION);
const data = await walletManager.connect();
console.log('Data ->', data);
*/
connect(): Promise<RegisteredUserData>;
/**
* @description The function required the wallet, and it performs full registration and normal login to get the user info data
* @param {string} walletAddress Required metamask wallet address of user
* @param {UserType=} userType Type of user for B2B (PARTNER) and B2C (CUSTOMER)
* @param {string=} referrerId Referrer users to onboard to myria system.
* In case the type is partner, then the referrerID is PARTNER_GAME_NAME_ID or PROJECT_ID
* If type is customer, then the referrerID is stark key of referred's user
* @throws {string} Exception: Wallet address is required!
* @throws {string} Exception: ReferrerId is required!
* @throws {string} Exception: Wallet registration failed: ${INTERNAL_SERVER_ERROR}
* @throws {string} Exception: Can't register the user with error: ${INTERNAL_SERVER_ERROR}
* @example <caption>Sample code</caption>
*
// Sample code on staging:
const walletManager = new WalletManager(EnvTypes.STAGING);
const data = await walletManager.registerAndLoginWithWalletAddress(
'0xfb.....', // wallet address
UserType.PARTNER, // User type as partner
'110', // Testnet (Staging) Project ID for the partner game
);
console.log('Testnet Data ->', data);
// Sample code on Production:
const walletManager = new WalletManager(EnvTypes.PRODUCTION);
const data = await walletManager.registerAndLoginWithWalletAddress(
'0xfb.....', // wallet address
UserType.PARTNER, // User type as partner
'10', // Production Project ID for the partner game
);
console.log('Production Data ->', data);
* @returns {UserDataResponse|undefined} User data response (such as stark key, wallet address, registered signature)
*/
registerAndLoginWithWalletAddress(walletAddress: string, userType?: UserType, referrerId?: string): Promise<UserDataResponse | undefined>;
/**
* @description Perform end to end registration process with metamask connection , connect wallet action and register user in Myria's system
* @param {UserType=} userType Type of user (PARTNER / CUSTOMER)
* @param {string=} referrerId Game_ID / Project_ID / References Stark Key of another users if userType is customer
* @example <caption>Sample code</caption>
*
// Sample code on staging:
const walletManager = new WalletManager(EnvTypes.STAGING);
const registerUserData = await walletManager.connectAndLogin(
UserType.PARTNER,
'110', // Testnet (Staging) Project ID for the partner game
);
console.log('Testnet Data ->', registerUserData);
// Sample code on Production:
const walletManager = new WalletManager(EnvTypes.PRODUCTION);
const registerUserData = await walletManager.connectAndLogin(
UserType.PARTNER,
'10', // Production Project ID for the partner game
);
console.log('Production Data ->', registerUserData);
* @returns {UserDataResponse|undefined} The details user data response for registration progress (including signature, stark key, wallet address)
* @throws {string} Exception: ReferrerId is required!
* @throws {string} Exception: Wallet registration failed: ${INTERNAL_SERVER_ERROR}
* @throws {string} Exception: Register user failed: ${INTERNAL_SERVER_ERROR}
* @throws {string} Exception: Cannot get user information with error: ${INTERNAL_SERVER_ERROR}
*/
connectAndLogin(userType?: UserType, referrerId?: string): Promise<UserDataResponse | undefined>;
connectAndLoginV2(userType?: UserType, referrerId?: string): Promise<UserDataV2Response | undefined>;
/**
* @description Perform the retrieve user wallet by the Stark Key
* @param {string} starkKey Stark Key of user in L2 system of Myria
* @example <caption>Sample code</caption>
*
// Sample code on staging:
const walletManager = new WalletManager(EnvTypes.STAGING);
const starkKey = '0x.....';
const userWalletData = await walletManager.getUserWalletByStarkKey(starkKey);
console.log('Testnet Data ->', userWalletData);
// Sample code on Production:
const walletManager = new WalletManager(EnvTypes.PRODUCTION);
const starkKey = '0x.....';
const userWalletData = await walletManager.getUserWalletByStarkKey(starkKey);
console.log('Production Data ->', userWalletData);
* @returns {UserDataResponse | undefined} The details user data response for registration progress (including signature, stark key, wallet address)
* @throws {string} Exception: Stark Key is required!
* @throws {string} Http Status Code 404: User 0x... is not registered
* @throws {string} Http Status Code 500: Get user data failed - unexpected with internal server error
* @throws {string} Http Status Code 500: Internal Server Error with ${Exception}
*/
getUserWalletByStarkKey(starkKey: string): Promise<UserDataResponse | undefined>;
/**
* @description Perform the retrieve full user information by the Wallet address
* @param {string} ethAddress The ether wallet address of user (such as Metamask wallet address)
* @example <caption>Sample code</caption>
*
// Sample code on staging:
const walletManager = new WalletManager(EnvTypes.STAGING);
const ethWalletAddress = '0x.....';
const userWalletData = await walletManager.getUserInfoByWalletAddress(ethWalletAddress);
console.log('Testnet Data ->', userWalletData);
// Sample code on Production:
const walletManager = new WalletManager(EnvTypes.PRODUCTION);
const ethWalletAddress = '0x.....';
const userWalletData = await walletManager.getUserInfoByWalletAddress(ethWalletAddress);
console.log('Production Data ->', userWalletData);
* @returns {UserDataResponse | undefined} The details user data response for registration progress (including signature, stark key, wallet address)
* @throws {string} Exception: Eth address is required!
* @throws {string} Http Status Code 404: User 0x... is not registered
* @throws {string} Http Status Code 500: Get user data failed - unexpected with internal server error
* @throws {string} Http Status Code 500: Internal Server Error with ${Exception}
*/
getUserInfoByWalletAddress(ethAddress: string): Promise<UserDataResponse | undefined>;
}