New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ftx-api

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ftx-api - npm Package Compare versions

Comparing version 1.0.12 to 1.0.13

lib/util/browser-support.d.ts

2

lib/util/requestUtils.d.ts

@@ -31,4 +31,2 @@ import { AxiosRequestConfig } from 'axios';

export declare type GenericAPIResponse = Promise<any>;
export declare function signMessage(message: string, secret: string): string;
export declare function signWsAuthenticate(timestamp: number, secret: string): string;
export declare function serializeParams(params?: object, strict_validation?: boolean): string;

@@ -35,0 +33,0 @@ export declare function serializeParamPayload(isGetRequest: boolean, params?: string | object, strictParamValidation?: boolean): string | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPublicEndpoint = exports.getWsUrl = exports.getRestBaseUrl = exports.programKey = exports.programId = exports.serializeParamPayload = exports.serializeParams = exports.signWsAuthenticate = exports.signMessage = void 0;
const crypto_1 = require("crypto");
exports.isPublicEndpoint = exports.getWsUrl = exports.getRestBaseUrl = exports.programKey = exports.programId = exports.serializeParamPayload = exports.serializeParams = void 0;
;
;
function signMessage(message, secret) {
return crypto_1.createHmac('sha256', secret)
.update(message)
.digest('hex');
}
exports.signMessage = signMessage;
;
function signWsAuthenticate(timestamp, secret) {
return crypto_1.createHmac('sha256', secret)
.update(timestamp + 'websocket_login')
.digest('hex');
}
exports.signWsAuthenticate = signWsAuthenticate;
;
function serializeParams(params = {}, strict_validation = false) {

@@ -22,0 +7,0 @@ return Object.keys(params)

@@ -27,3 +27,3 @@ import { AxiosRequestConfig, Method } from 'axios';

*/
signRequest(data: any): any;
signRequest(data: any): Promise<any>;
/**

@@ -30,0 +30,0 @@ * @private trigger time sync and store promise

@@ -16,2 +16,3 @@ "use strict";

const axios_1 = __importDefault(require("axios"));
const node_support_1 = require("./node-support");
const requestUtils_1 = require("./requestUtils");

@@ -98,3 +99,3 @@ const getHeader = (headerId, domain = 'ftxcom') => {

}
const { timestamp, sign } = this.getRequestSignature(method, endpoint, this.secret, serialisedParams);
const { timestamp, sign } = yield this.getRequestSignature(method, endpoint, this.secret, serialisedParams);
options.headers[getHeader('ts', this.options.domain)] = String(timestamp);

@@ -144,14 +145,16 @@ options.headers[getHeader('sign', this.options.domain)] = sign;

getRequestSignature(method, endpoint, secret, serialisedParams = '') {
const timestamp = Date.now() + (this.timeOffset || 0);
if (!secret) {
return __awaiter(this, void 0, void 0, function* () {
const timestamp = Date.now() + (this.timeOffset || 0);
if (!secret) {
return {
timestamp,
sign: ''
};
}
const signature_payload = `${timestamp}${method}/api/${endpoint}${serialisedParams}`;
return {
timestamp,
sign: ''
sign: yield node_support_1.signMessage(signature_payload, secret)
};
}
const signature_payload = `${timestamp}${method}/api/${endpoint}${serialisedParams}`;
return {
timestamp,
sign: requestUtils_1.signMessage(signature_payload, secret)
};
});
}

@@ -169,3 +172,3 @@ /**

const serializedParams = requestUtils_1.serializeParams(params, this.options.strict_param_validation);
params.sign = requestUtils_1.signMessage(serializedParams, this.secret);
params.sign = node_support_1.signMessage(serializedParams, this.secret);
}

@@ -172,0 +175,0 @@ return params;

@@ -23,2 +23,3 @@ "use strict";

const wsMessages_1 = require("./util/wsMessages");
const node_support_1 = require("./util/node-support");
const loggerCategory = { category: 'ftx-ws' };

@@ -134,10 +135,12 @@ const READY_STATE_INITIAL = 0;

requestTryAuthenticate(wsKey) {
const { key, secret, subAccountName } = this.options;
if (!key || !secret) {
this.logger.debug(`Connection "${wsKey}" will remain unauthenticated due to missing key/secret`);
return;
}
const timestamp = new Date().getTime();
const authMsg = wsMessages_1.getWsAuthMessage(key, requestUtils_1.signWsAuthenticate(timestamp, secret), timestamp, subAccountName);
this.tryWsSend(wsKey, JSON.stringify(authMsg));
return __awaiter(this, void 0, void 0, function* () {
const { key, secret, subAccountName } = this.options;
if (!key || !secret) {
this.logger.debug(`Connection "${wsKey}" will remain unauthenticated due to missing key/secret`);
return;
}
const timestamp = new Date().getTime();
const authMsg = wsMessages_1.getWsAuthMessage(key, yield node_support_1.signWsAuthenticate(timestamp, secret), timestamp, subAccountName);
this.tryWsSend(wsKey, JSON.stringify(authMsg));
});
}

@@ -171,3 +174,3 @@ parseWsError(context, error, wsKey) {

};
params.signature = requestUtils_1.signMessage('GET/realtime' + params.expires, secret);
params.signature = node_support_1.signMessage('GET/realtime' + params.expires, secret);
return params;

@@ -265,14 +268,16 @@ }

onWsOpen(event, wsKey) {
if (this.wsStore.isConnectionState(wsKey, READY_STATE_CONNECTING)) {
this.logger.info('Websocket connected', Object.assign(Object.assign({}, loggerCategory), { wsKey, livenet: this.isLivenet() }));
this.emit('open', { wsKey, event });
}
else if (this.wsStore.isConnectionState(wsKey, READY_STATE_RECONNECTING)) {
this.logger.info('Websocket reconnected', Object.assign(Object.assign({}, loggerCategory), { wsKey }));
this.emit('reconnected', { wsKey, event });
}
this.setWsState(wsKey, READY_STATE_CONNECTED);
this.requestTryAuthenticate(wsKey);
this.requestSubscribeTopics(wsKey, [...this.wsStore.getTopics(wsKey)]);
this.wsStore.get(wsKey, true).activePingTimer = setInterval(() => this.ping(wsKey), this.options.pingInterval);
return __awaiter(this, void 0, void 0, function* () {
if (this.wsStore.isConnectionState(wsKey, READY_STATE_CONNECTING)) {
this.logger.info('Websocket connected', Object.assign(Object.assign({}, loggerCategory), { wsKey, livenet: this.isLivenet() }));
this.emit('open', { wsKey, event });
}
else if (this.wsStore.isConnectionState(wsKey, READY_STATE_RECONNECTING)) {
this.logger.info('Websocket reconnected', Object.assign(Object.assign({}, loggerCategory), { wsKey }));
this.emit('reconnected', { wsKey, event });
}
this.setWsState(wsKey, READY_STATE_CONNECTED);
yield this.requestTryAuthenticate(wsKey);
this.requestSubscribeTopics(wsKey, [...this.wsStore.getTopics(wsKey)]);
this.wsStore.get(wsKey, true).activePingTimer = setInterval(() => this.ping(wsKey), this.options.pingInterval);
});
}

@@ -279,0 +284,0 @@ onWsMessage(event, wsKey) {

{
"name": "ftx-api",
"version": "1.0.12",
"version": "1.0.13",
"description": "Node.js connector for FTX's REST APIs and WebSockets",

@@ -12,3 +12,4 @@ "main": "lib/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"test:watch": "jest --watch",
"clean": "rm -rf lib dist",

@@ -30,8 +31,8 @@ "build": "tsc",

"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^14.14.7",
"buffer": "^6.0.2",
"crypto-browserify": "^3.12.0",
"eslint": "^7.10.0",
"jest": "^27.0.4",
"source-map-loader": "^2.0.0",
"stream-browserify": "^3.0.0",
"ts-jest": "^27.0.3",
"ts-loader": "^8.0.11",

@@ -38,0 +39,0 @@ "typescript": "^4.0.5",

# ftx-api
[![Tests](https://circleci.com/gh/tiagosiebler/ftx-api.svg?style=shield)](https://circleci.com/gh/tiagosiebler/ftx-api)
[![npm version](https://img.shields.io/npm/v/ftx-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/ftx-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/ftx-api)][1]

@@ -6,2 +7,3 @@ [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/ftx-api)][1]

[1]: https://www.npmjs.com/package/ftx-api

@@ -8,0 +10,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc