@@ -12,7 +12,7 @@ import {
1212} from "@toruslabs/openlogin-utils" ;
1313import log from "loglevel" ;
1414
15- import { InitializationError , LoginError } from "./errors" ;
15+ import { InitializationError , LoginError , RequestError } from "./errors" ;
1616import KeyStore from "./session/KeyStore" ;
1717import { EncryptedStorage } from "./types/IEncryptedStorage" ;
1818import { SecureStore } from "./types/IExpoSecureStore" ;
@@ -284,7 +284,7 @@ class Web3Auth implements IWeb3Auth {
284284 const configParams : WalletLoginParams = {
285285 loginId,
286286 sessionId,
287- isReactNative : true ,
287+ platform : "react-native" ,
288288 } ;
289289
290290 const loginUrl = constructURL ( {
@@ -295,6 +295,52 @@ class Web3Auth implements IWeb3Auth {
295295 this . webBrowser . openAuthSessionAsync ( loginUrl , dataObject . params . redirectUrl ) ;
296296 }
297297
298+ async request ( chainConfig : ChainConfig , method : string , params : unknown [ ] , path : string | null = "wallet/request" ) : Promise < string > {
299+ if ( ! this . ready ) throw InitializationError . notInitialized ( "Please call init first." ) ;
300+ if ( ! this . sessionManager . sessionId ) {
301+ throw LoginError . userNotLoggedIn ( ) ;
302+ }
303+
304+ const dataObject : Omit < OpenloginSessionConfig , "options" > & { options : SdkInitParams & { chainConfig : ChainConfig } } = {
305+ actionType : OPENLOGIN_ACTIONS . LOGIN ,
306+ options : { ...this . options , chainConfig } ,
307+ params : { } ,
308+ } ;
309+
310+ const url = `${ this . walletSdkUrl } /${ path } ` ;
311+ const loginId = OpenloginSessionManager . generateRandomSessionKey ( ) ;
312+ await this . createLoginSession ( loginId , dataObject ) ;
313+
314+ const { sessionId } = this . sessionManager ;
315+ const configParams : WalletLoginParams = {
316+ loginId,
317+ sessionId,
318+ request : {
319+ method,
320+ params,
321+ } ,
322+ platform : "react-native" ,
323+ } ;
324+
325+ const loginUrl = constructURL ( {
326+ baseURL : url ,
327+ hash : { b64Params : jsonToBase64 ( configParams ) } ,
328+ } ) ;
329+
330+ const result = await this . webBrowser . openAuthSessionAsync ( loginUrl , dataObject . params . redirectUrl ) ;
331+
332+ if ( result . type !== "success" || ! result . url ) {
333+ log . error ( `[Web3Auth] login flow failed with error type ${ result . type } ` ) ;
334+ throw LoginError . loginFailed ( `login flow failed with error type ${ result . type } ` ) ;
335+ }
336+
337+ const { success, result : requestResult , error } = getHashQueryParams ( result . url ) ;
338+ if ( error || success === "false" ) {
339+ throw RequestError . fromCode ( 5000 , error ) ;
340+ }
341+ return requestResult ;
342+ }
343+
298344 async enableMFA ( ) : Promise < boolean > {
299345 if ( ! this . ready ) throw InitializationError . notInitialized ( "Please call init first." ) ;
300346 if ( ! this . sessionManager . sessionId ) {
0 commit comments