From 96dc7ebcaeadca0e4d4b7f83872d6b64d37cde11 Mon Sep 17 00:00:00 2001 From: Erdi Maden Date: Mon, 13 May 2024 13:27:51 -0500 Subject: [PATCH] Updating doc style and updating eslint --- .eslintrc.json | 1 + src/coinbase/authenticator.ts | 58 ++++++++++++------------ src/coinbase/tests/authenticator_test.ts | 1 + 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8d488b62..05df6a1d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -15,6 +15,7 @@ "sourceType": "module" }, "rules": { + "multiline-comment-style": ["error", "starred-block"], "prettier/prettier": "error" }, "ignorePatterns": ["src/**/__tests__/**", "src/**/*.test.ts"] diff --git a/src/coinbase/authenticator.ts b/src/coinbase/authenticator.ts index d86a451b..9d00117e 100644 --- a/src/coinbase/authenticator.ts +++ b/src/coinbase/authenticator.ts @@ -5,28 +5,28 @@ import { InternalAxiosRequestConfig } from "axios"; const pemHeader = "-----BEGIN EC PRIVATE KEY-----"; const pemFooter = "-----END EC PRIVATE KEY-----"; -// A class that builds JWTs for authenticating with the Coinbase Platform APIs. +/* A class that builds JWTs for authenticating with the Coinbase Platform APIs. */ export class CoinbaseAuthenticator { private apiKey: string; private privateKey: string; - /* - Initializes the Authenticator. - @constructor - @param {string} apiKey - The API key name. - @param {string} privateKey - The private key associated with the API key. - */ + /* + * Initializes the Authenticator. + * @constructor + * @param {string} apiKey - The API key name. + * @param {string} privateKey - The private key associated with the API key. + */ constructor(apiKey: string, privateKey: string) { this.apiKey = apiKey; this.privateKey = privateKey; } /* - Middleware to intercept requests and add JWT to the Authorization header for AxiosInterceptor - @param {MiddlewareRequestType} config - The request configuration. - @returns {MiddlewareRequestType} The request configuration with the Authorization header added. - @throws {InternalError} If there is an issue with the private key. - */ + * Middleware to intercept requests and add JWT to the Authorization header for AxiosInterceptor + * @param {MiddlewareRequestType} config - The request configuration. + * @returns {MiddlewareRequestType} The request configuration with the Authorization header added. + * @throws {InternalError} If there is an issue with the private key. + */ async authenticateRequest( config: InternalAxiosRequestConfig, ): Promise { @@ -38,13 +38,13 @@ export class CoinbaseAuthenticator { return config; } - /* - Builds the JWT for the given API endpoint URI. The JWT is signed with the API key's private key. - @param {string} url - The URI of the API endpoint. - @param {string} method - The HTTP method of the request. - @returns {string} The JWT if successful or throws an error. - @throws {InternalError} If there is an issue with the private key. - */ + /* + * Builds the JWT for the given API endpoint URI. The JWT is signed with the API key's private key. + * @param {string} url - The URI of the API endpoint. + * @param {string} method - The HTTP method of the request. + * @returns {string} The JWT if successful or throws an error. + * @throws {InternalError} If there is an issue with the private key. + */ async buildJWT(url: string, method = "GET"): Promise { const pemPrivateKey = this.extractPemKey(this.privateKey); let privateKey: JWK.Key; @@ -87,12 +87,12 @@ export class CoinbaseAuthenticator { } } - /* - Extracts the PEM key from the given private key string. - @param {string} privateKeyString - The private key string. - @returns {string} The PEM key. - @throws {InvalidAPIKeyFormat} If the private key string is not in the correct format. - */ + /* + * Extracts the PEM key from the given private key string. + * @param {string} privateKeyString - The private key string. + * @returns {string} The PEM key. + * @throws {InvalidAPIKeyFormat} If the private key string is not in the correct format. + */ private extractPemKey(privateKeyString: string): string { // Remove all newline characters privateKeyString = privateKeyString.replace(/\n/g, ""); @@ -104,10 +104,10 @@ export class CoinbaseAuthenticator { throw InvalidAPIKeyFormat; } - /* - Generates a random nonce for the JWT. - @returns {string} - */ + /* + * Generates a random nonce for the JWT. + * @returns {string} + */ private nonce(): string { const range = "0123456789"; let result = ""; diff --git a/src/coinbase/tests/authenticator_test.ts b/src/coinbase/tests/authenticator_test.ts index e9cb07e3..93f5f7ea 100644 --- a/src/coinbase/tests/authenticator_test.ts +++ b/src/coinbase/tests/authenticator_test.ts @@ -14,6 +14,7 @@ const VALID_CONFIG = { describe("Authenticator tests", () => { const authenticator = new CoinbaseAuthenticator(VALID_KEY, VALID_PRIVATE_KEY); + it("should raise InvalidConfiguration error", async () => { const invalidConfig = { method: "GET",