Skip to content

Commit c15a9c8

Browse files
committed
chore(): check/throw on missing credentials for wsapi auth
1 parent 92bcb94 commit c15a9c8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/websocket-client.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,17 @@ export class WebsocketClient extends BaseWebsocketClient<
514514
// Once authenticated, you no longer have to specify apiKey and signature for those requests that need them. Requests will be performed on behalf of the account owning the authenticated API key.
515515

516516
// Note: You still have to specify the timestamp parameter for SIGNED requests.
517-
518-
// const recvWindow = this.options.recvWindow || 0;
519-
const timestamp = Date.now() + (this.getTimeOffsetMs() || 0); // + recvWindow;
520-
517+
const timestamp = Date.now() + (this.getTimeOffsetMs() || 0);
521518
const strictParamValidation = true;
522519
const encodeValues = true;
523520
const filterUndefinedParams = true;
524521

522+
if (!this.options.api_key || !this.options.api_secret) {
523+
throw new Error(
524+
'API key and/or secret missing, unable to prepare WS auth event without valid API keys.',
525+
);
526+
}
527+
525528
const params = {
526529
apiKey: this.options.api_key,
527530
timestamp,
@@ -535,7 +538,7 @@ export class WebsocketClient extends BaseWebsocketClient<
535538

536539
const signature = await this.signMessage(
537540
serialisedParams,
538-
this.options.api_secret!,
541+
this.options.api_secret,
539542
'base64',
540543
'SHA-256',
541544
);

0 commit comments

Comments
 (0)