run linter

This commit is contained in:
tiagosiebler
2022-05-12 01:23:49 +01:00
parent 1a6b4cc269
commit f0088f32c2
5 changed files with 21 additions and 22 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "2.1.10", "version": "2.2.0-beta.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bybit-api", "name": "bybit-api",
"version": "2.1.10", "version": "2.2.0-beta.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.0", "axios": "^0.21.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "2.2.0", "version": "2.2.0-beta.1",
"description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.", "description": "Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -18,5 +18,5 @@ export const DefaultLogger = {
}, },
error: (...params: LogParams): void => { error: (...params: LogParams): void => {
console.error(params); console.error(params);
} },
}; };

View File

@@ -1,5 +1,4 @@
import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios'; import axios, { AxiosRequestConfig, AxiosResponse, Method } from 'axios';
import { APIResponse, APIResponseWithTime } from '../types/shared';
import { signMessage } from './node-support'; import { signMessage } from './node-support';
import { import {
@@ -36,19 +35,12 @@ interface SignedRequest<T> {
export default abstract class BaseRestClient { export default abstract class BaseRestClient {
private timeOffset: number | null; private timeOffset: number | null;
private syncTimePromise: null | Promise<any>; private syncTimePromise: null | Promise<any>;
private options: RestClientOptions; private options: RestClientOptions;
private baseUrl: string; private baseUrl: string;
private globalRequestOptions: AxiosRequestConfig; private globalRequestOptions: AxiosRequestConfig;
private key: string | undefined; private key: string | undefined;
private secret: string | undefined; private secret: string | undefined;
private clientType: RestClientType; private clientType: RestClientType;
/** Function that calls exchange API to query & resolve server time, used by time sync */ /** Function that calls exchange API to query & resolve server time, used by time sync */

View File

@@ -1,18 +1,25 @@
export async function signMessage(
export async function signMessage(message: string, secret: string): Promise<string> { message: string,
secret: string
): Promise<string> {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const key = await window.crypto.subtle.importKey( const key = await window.crypto.subtle.importKey(
'raw', 'raw',
encoder.encode(secret), encoder.encode(secret),
{name: 'HMAC', hash: {name: 'SHA-256'}}, { name: 'HMAC', hash: { name: 'SHA-256' } },
false, false,
['sign'] ['sign']
); );
const signature = await window.crypto.subtle.sign('HMAC', key, encoder.encode(message)); const signature = await window.crypto.subtle.sign(
'HMAC',
key,
encoder.encode(message)
);
return Array.prototype.map.call( return Array.prototype.map
new Uint8Array(signature), .call(new Uint8Array(signature), (x: any) =>
(x: any) => ('00'+x.toString(16)).slice(-2) ('00' + x.toString(16)).slice(-2)
).join(''); )
}; .join('');
}