Skip to content

Commit 1ab082e

Browse files
committed
feat(auth): add AuthNonceResponse and SessionCredentials to TYPE_MAP
- Add auth types to generator TYPE_MAP - Regenerate client.ts with auth methods Fixes #1606 #1589
1 parent c17665e commit 1ab082e

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

core/src/router/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ export interface FetchMarketMatchesParams {
9292
sort?: 'confidence' | 'volume' | 'priceDifference';
9393
}
9494

95+
export interface AuthNonceResponse {
96+
nonce: string;
97+
messageToSign: string;
98+
expiresAt?: number;
99+
}
100+
101+
export interface SessionCredentials {
102+
apiKey: string;
103+
apiSecret: string;
104+
passphrase?: string;
105+
expiresAt?: number;
106+
active?: boolean;
107+
}
108+
95109
/** @deprecated Use {@link FetchMarketMatchesParams} instead. */
96110
export type FetchMatchesParams = FetchMarketMatchesParams;
97111

sdks/typescript/pmxt/client.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

sdks/typescript/pmxt/models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ export interface ExecutionPriceResult {
208208
fullyFilled: boolean;
209209
}
210210

211+
212+
211213
/**
212214
* A trade made by the authenticated user.
213215
*/

sdks/typescript/scripts/generate-client-methods.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ const TYPE_MAP = {
8888
// Pagination wrapper — gets its own response handler
8989
PaginatedMarketsResult: { converter: null, pattern: 'paginatedMarkets' },
9090
PaginatedEventsResult: { converter: null, pattern: 'paginatedEvents' },
91+
92+
AuthNonceResponse: { converter: null, pattern: 'single' },
93+
SessionCredentials: { converter: null, pattern: 'single' },
9194
};
9295

9396
// SDK types that can appear in generated signatures without extra imports
@@ -101,6 +104,9 @@ const SDK_PARAM_TYPES = new Set([
101104
'MyTradesParams', 'OrderHistoryParams', 'CreateOrderParams',
102105
'MarketFilterCriteria', 'EventFilterCriteria',
103106
'SubscriptionOption',
107+
108+
'AuthNonceResponse',
109+
'SessionCredentials',
104110
]);
105111

106112
// Parameter names that represent outcome IDs and should accept MarketOutcome.

0 commit comments

Comments
 (0)