diff --git a/src/lib/BaseRestClient.ts b/src/lib/BaseRestClient.ts index 7d917d3..64579f3 100644 --- a/src/lib/BaseRestClient.ts +++ b/src/lib/BaseRestClient.ts @@ -386,6 +386,7 @@ export abstract class BaseRestClient { const apiKey = this.apiKey; const apiSecret = this.apiSecret; + const apiPassphrase = this.apiPassphrase; const jwtExpiresSeconds = this.options.jwtExpiresSeconds || 120; if (!apiKey) { @@ -449,8 +450,11 @@ export abstract class BaseRestClient { // See: https://github.com/tiagosiebler/coinbase-api/issues/24 } - case REST_CLIENT_TYPE_ENUM.exchange: { - // Docs: https://docs.cdp.coinbase.com/exchange/docs/rest-auth + // Docs: https://docs.cdp.coinbase.com/exchange/docs/rest-auth + case REST_CLIENT_TYPE_ENUM.exchange: + + // Docs: https://docs.cdp.coinbase.com/intx/docs/rest-auth + case REST_CLIENT_TYPE_ENUM.international: { const timestampInSeconds = timestampInMs / 1000; // decimals are OK const signInput = @@ -460,7 +464,7 @@ export abstract class BaseRestClient { throw new Error(`No API secret provided, cannot sign request.`); } - if (!this.apiPassphrase) { + if (!apiPassphrase) { throw new Error(`No API passphrase provided, cannot sign request.`); } @@ -476,7 +480,7 @@ export abstract class BaseRestClient { 'CB-ACCESS-KEY': apiKey, 'CB-ACCESS-SIGN': sign, 'CB-ACCESS-TIMESTAMP': timestampInSeconds, - 'CB-ACCESS-PASSPHRASE': this.apiPassphrase, + 'CB-ACCESS-PASSPHRASE': apiPassphrase, }; return { @@ -488,56 +492,16 @@ export abstract class BaseRestClient { }, }; - // TODO: is there demand for FIX + // For CB Exchange, is there demand for FIX // Docs, FIX: https://docs.cdp.coinbase.com/exchange/docs/fix-connectivity - } - - // Docs: https://docs.cdp.coinbase.com/intx/docs/rest-auth - case REST_CLIENT_TYPE_ENUM.international: { - const timestampInSeconds = String(Math.floor(timestampInMs / 1000)); - - const signInput = - timestampInSeconds + method + endpoint + requestBodyString; - - if (!apiSecret) { - throw new Error(`No API secret provided, cannot sign request.`); - } - - if (!this.apiPassphrase) { - throw new Error(`No API passphrase provided, cannot sign request.`); - } - - const sign = await signMessage( - signInput, - apiSecret, - 'base64', - 'SHA-256', - 'base64:web', - ); - - const headers = { - 'CB-ACCESS-TIMESTAMP': timestampInSeconds, - 'CB-ACCESS-SIGN': sign, - 'CB-ACCESS-PASSPHRASE': this.apiPassphrase, - 'CB-ACCESS-KEY': apiKey, - }; // For CB International, is there demand for FIX // Docs, FIX: https://docs.cdp.coinbase.com/intx/docs/fix-overview - - return { - ...res, - sign: sign, - queryParamsWithSign: signRequestParams, - headers: { - ...headers, - }, - }; } // Docs: https://docs.cdp.coinbase.com/prime/docs/rest-authentication case REST_CLIENT_TYPE_ENUM.prime: { - const timestampInSeconds = String(Math.floor(timestampInMs / 1000)); + const timestampInSeconds = Math.floor(timestampInMs / 1000); // decimal not allowed const signInput = timestampInSeconds + method + endpoint + requestBodyString; @@ -546,7 +510,7 @@ export abstract class BaseRestClient { throw new Error(`No API secret provided, cannot sign request.`); } - if (!this.apiPassphrase) { + if (!apiPassphrase) { throw new Error(`No API passphrase provided, cannot sign request.`); } @@ -555,18 +519,14 @@ export abstract class BaseRestClient { apiSecret, 'base64', 'SHA-256', - 'utf', + 'base64:web', ); const headers = { - // 'CB-ACCESS-TIMESTAMP': timestampInSeconds, - // 'CB-ACCESS-SIGN': sign, - // 'CB-ACCESS-PASSPHRASE': this.apiPassphrase, - // 'CB-ACCESS-KEY': apiKey, - 'X-CB-ACCESS-TIMESTAMP': timestampInSeconds, - 'X-CB-ACCESS-SIGNATURE': sign, - 'X-CB-ACCESS-PASSPHRASE': this.apiPassphrase, 'X-CB-ACCESS-KEY': apiKey, + 'X-CB-ACCESS-PASSPHRASE': apiPassphrase, + 'X-CB-ACCESS-SIGNATURE': sign, + 'X-CB-ACCESS-TIMESTAMP': timestampInSeconds, }; // For CB Prime, is there demand for FIX