@lunch-money/coinbase-to-lunch-money
Version:
A wrapper around the coinbase API for enabling Lunch Money to gather information about a user's account.
62 lines (61 loc) • 2.22 kB
TypeScript
import { Method } from 'axios';
import { CoinbaseAccount, CoinbaseConfig, CoinbaseData, CoinbaseResult } from './types';
import { CryptoBalance } from './shared-types';
declare const BASE_URL = "https://api.coinbase.com";
declare const ENDPOINTS: {
accounts: string;
};
/**
* Coinbase Client
*
* Coinbase doesn't have an official node client, so a basic one is provided.
*
* There are two authentication methods: API key and OAuth2. Coinbase
* discourages the use of API Keys except when writing your own software, so
* OAuth2 is preferred.
*/
export declare class CoinbaseClient {
config: CoinbaseConfig;
/**
* Create the client instance with baseUrl and scopes
*/
constructor(config: CoinbaseConfig);
/**
* Execute a request and handle the response
*/
request(method: Method, path: string, query?: Record<string, unknown>, data?: CoinbaseData): Promise<CoinbaseResult['accounts']>;
/**
* Generate a JWT for the current request.
*
* Detects the key type from the PEM header when present. For raw base64 keys
* (no header), attempts Ed25519 first (the newer Coinbase default) then falls
* back to ECDSA.
*/
private generateSignedJwt;
/**
* Determine key type and return a PEM-formatted key ready for signing.
*
* Priority:
* 1. PEM header present → use it directly (ECDSA or Ed25519)
* 2. No header + ≤64 bytes → must be raw Ed25519 material; construct PKCS#8 PEM
* 3. No header + >64 bytes → ECDSA P-256 DER content; re-wrap with EC PEM headers
*/
private prepareKey;
/**
* Sign a JWT using Ed25519 via Node's built-in crypto module.
* jsonwebtoken's jws sub-dependency does not support EdDSA, so we sign
* the token directly here.
*/
private signJwtEdDSA;
/**
* Returns current coinbase accounts
*
* @see https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_getaccounts
*/
getAccounts(): Promise<CoinbaseAccount[]>;
/**
* Returns current coinbase holdings
*/
getBalances(): Promise<CryptoBalance[]>;
}
export { BASE_URL as coinbaseAPIBaseUrl, ENDPOINTS as coinbaseEndpoints };