Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

fix(time): Remove polynomial regular expression #769

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CoinbasePro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class CoinbasePro {
*/
if (this.clockSkew === -1) {
const time = await this.rest.time.getTime();
this.clockSkew = await this.rest.time.getClockSkew(time);
this.clockSkew = this.rest.time.getClockSkew(time);
}

return RequestSigner.signRequest(auth, setup, this.clockSkew);
Expand Down
19 changes: 0 additions & 19 deletions src/time/TimeAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,4 @@ describe('TimeAPI', () => {
expect(time).toEqual(expected);
});
});

describe('getClockSkew', () => {
beforeEach(() => jasmine.clock().install());

afterEach(() => jasmine.clock().uninstall());

it('handles epochs sent as string', async () => {
const mockDate = new Date(1610486424105);
jasmine.clock().mockDate(mockDate);

const mockPayload = '{"iso":"2021-01-12T21:20:24Z","epoch":1610486424.}';

const timeApi = new TimeAPI(global.REST_URL);

const clockSkew = await timeApi.getClockSkew(mockPayload);

expect(clockSkew).toBe(-0.10500001907348633);
});
});
});
6 changes: 2 additions & 4 deletions src/time/TimeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export class TimeAPI {
/**
* Get the absolute difference between server time and local time.
*/
async getClockSkew(time: TimeSkew | string): Promise<number> {
/** @see https://github.com/bennycode/coinbase-pro-node/issues/354 */
const epoch = typeof time === 'string' ? parseFloat(time.match(/epoch":(.*)\./i)![1]) : time.epoch;
getClockSkew(time: TimeSkew): number {
const now = Date.now() / 1000;
return epoch - now;
return time.epoch - now;
}
}