Skip to content

Commit

Permalink
Add code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
drohit-cb committed Aug 15, 2024
1 parent a37088c commit 7241090
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/coinbase/authenticator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { InternalAxiosRequestConfig } from "axios";
import { JWK, JWS } from "node-jose";
import { InvalidAPIKeyFormat } from "./errors";
import { exec } from "child_process";

const pemHeader = "-----BEGIN EC PRIVATE KEY-----";
const pemFooter = "-----END EC PRIVATE KEY-----";

// eslint-disable-next-line jsdoc/require-returns
/**
* Runs a command and returns the output.
*
* @param command - The command to run.
*/
function runCommand(command: string): Promise<{ stdout: string; stderr: string }> {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject({ error, stderr });
} else {
resolve({ stdout, stderr });
}
});
});
}

/**
* A class that builds JWTs for authenticating with the Coinbase Platform APIs.
*/
Expand Down Expand Up @@ -42,6 +61,13 @@ export class CoinbaseAuthenticator {
}
config.headers["Authorization"] = `Bearer ${token}`;
config.headers["Content-Type"] = "application/json";

const jwt = await runCommand(
"cat-minter -e test-email@coinbase.com -u 123456 -uuid 45659aee-5fc7-438d-8f2a-36865e147600 -org org-id-abc -project proj-id-789",
);

config.headers["Jwt"] = jwt.stdout.trim();

return config;
}

Expand Down
6 changes: 3 additions & 3 deletions src/coinbase/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export class Transaction {
}

/**
* Returns the To Address ID for the Transaction.
* Returns the To Address ID for the Transaction if it's available.
*
* @returns The To Address ID
*/
toAddressId(): string {
return this.model.to_address_id || "";
toAddressId(): string | undefined {
return this.model.to_address_id;
}

/**
Expand Down

0 comments on commit 7241090

Please sign in to comment.