Skip to content

Commit

Permalink
Updating doc style and updating eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
erdimaden committed May 13, 2024
1 parent 83db197 commit 96dc7eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"sourceType": "module"
},
"rules": {
"multiline-comment-style": ["error", "starred-block"],
"prettier/prettier": "error"
},
"ignorePatterns": ["src/**/__tests__/**", "src/**/*.test.ts"]
Expand Down
58 changes: 29 additions & 29 deletions src/coinbase/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InternalAxiosRequestConfig> {
Expand All @@ -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<string> {
const pemPrivateKey = this.extractPemKey(this.privateKey);
let privateKey: JWK.Key;
Expand Down Expand Up @@ -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, "");
Expand All @@ -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 = "";
Expand Down
1 change: 1 addition & 0 deletions src/coinbase/tests/authenticator_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 96dc7eb

Please sign in to comment.