@@ -1000,6 +1000,82 @@ export abstract class Exchange {
10001000 }
10011001 }
10021002
1003+ async getAuthNonce ( walletAddress : string ) : Promise < AuthNonceResponse > {
1004+ await this . initPromise ;
1005+ try {
1006+ const args : any [ ] = [ ] ;
1007+ args . push ( walletAddress ) ;
1008+ const response = await this . fetchWithRetry ( `${ this . resolveBaseUrl ( ) } /api/${ this . exchangeName } /getAuthNonce` , {
1009+ method : 'POST' ,
1010+ headers : { 'Content-Type' : 'application/json' , ...this . getAuthHeaders ( ) } ,
1011+ body : JSON . stringify ( { args, credentials : this . getCredentials ( ) } ) ,
1012+ } ) ;
1013+ if ( ! response . ok ) {
1014+ const body = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
1015+ if ( body . error && typeof body . error === "object" ) {
1016+ throw fromServerError ( body . error ) ;
1017+ }
1018+ throw new PmxtError ( body . error ?. message || response . statusText ) ;
1019+ }
1020+ const json = await response . json ( ) ;
1021+ return this . handleResponse ( json ) ;
1022+ } catch ( error ) {
1023+ if ( error instanceof PmxtError ) throw error ;
1024+ throw new PmxtError ( `Failed to getAuthNonce: ${ error } ` ) ;
1025+ }
1026+ }
1027+
1028+ async loginWithSignature ( walletAddress : string , signature : string , nonce : string ) : Promise < SessionCredentials > {
1029+ await this . initPromise ;
1030+ try {
1031+ const args : any [ ] = [ ] ;
1032+ args . push ( walletAddress ) ;
1033+ args . push ( signature ) ;
1034+ args . push ( nonce ) ;
1035+ const response = await this . fetchWithRetry ( `${ this . resolveBaseUrl ( ) } /api/${ this . exchangeName } /loginWithSignature` , {
1036+ method : 'POST' ,
1037+ headers : { 'Content-Type' : 'application/json' , ...this . getAuthHeaders ( ) } ,
1038+ body : JSON . stringify ( { args, credentials : this . getCredentials ( ) } ) ,
1039+ } ) ;
1040+ if ( ! response . ok ) {
1041+ const body = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
1042+ if ( body . error && typeof body . error === "object" ) {
1043+ throw fromServerError ( body . error ) ;
1044+ }
1045+ throw new PmxtError ( body . error ?. message || response . statusText ) ;
1046+ }
1047+ const json = await response . json ( ) ;
1048+ return this . handleResponse ( json ) ;
1049+ } catch ( error ) {
1050+ if ( error instanceof PmxtError ) throw error ;
1051+ throw new PmxtError ( `Failed to loginWithSignature: ${ error } ` ) ;
1052+ }
1053+ }
1054+
1055+ async logout ( ) : Promise < void > {
1056+ await this . initPromise ;
1057+ try {
1058+ const args : any [ ] = [ ] ;
1059+ const response = await this . fetchWithRetry ( `${ this . resolveBaseUrl ( ) } /api/${ this . exchangeName } /logout` , {
1060+ method : 'POST' ,
1061+ headers : { 'Content-Type' : 'application/json' , ...this . getAuthHeaders ( ) } ,
1062+ body : JSON . stringify ( { args, credentials : this . getCredentials ( ) } ) ,
1063+ } ) ;
1064+ if ( ! response . ok ) {
1065+ const body = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
1066+ if ( body . error && typeof body . error === "object" ) {
1067+ throw fromServerError ( body . error ) ;
1068+ }
1069+ throw new PmxtError ( body . error ?. message || response . statusText ) ;
1070+ }
1071+ const json = await response . json ( ) ;
1072+ this . handleResponse ( json ) ;
1073+ } catch ( error ) {
1074+ if ( error instanceof PmxtError ) throw error ;
1075+ throw new PmxtError ( `Failed to logout: ${ error } ` ) ;
1076+ }
1077+ }
1078+
10031079 async fetchMarketsPaginated ( params ?: any ) : Promise < PaginatedMarketsResult > {
10041080 await this . initPromise ;
10051081 try {
0 commit comments