From 17619ca073a64f20674a2c125d6cbe7a43b2d420 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Sun, 24 Dec 2017 15:16:39 -0700 Subject: [PATCH] Simplify auth object to key, secret, passphrase (#151) This more consistent usage allows an AuthenticatedClient instance to be used in place of an auth object --- README.md | 4 ++-- index.d.ts | 2 +- lib/clients/authenticated.js | 11 +++-------- lib/orderbook_sync.js | 11 +---------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 33ef5b5e..282437a2 100644 --- a/README.md +++ b/README.md @@ -219,13 +219,13 @@ the API URI (defaults to `https://api.gdax.com`). ```js const key = 'your_api_key'; -const b64secret = 'your_b64_secret'; +const secret = 'your_b64_secret'; const passphrase = 'your_passphrase'; const apiURI = 'https://api.gdax.com'; const sandboxURI = 'https://api-public.sandbox.gdax.com'; -const authedClient = new Gdax.AuthenticatedClient(key, b64secret, passphrase, apiURI); +const authedClient = new Gdax.AuthenticatedClient(key, secret, passphrase, apiURI); ``` Like `PublicClient`, all API methods can be used with either callbacks or will diff --git a/index.d.ts b/index.d.ts index 87c6d855..fb5fe675 100644 --- a/index.d.ts +++ b/index.d.ts @@ -164,7 +164,7 @@ declare module 'gdax' { } export class AuthenticatedClient { - constructor(key: string, b64secret: string, passphrase: string, apiURI: string); + constructor(key: string, secret: string, passphrase: string, apiURI: string); getCoinbaseAccounts(callback: callback) getCoinbaseAccounts(): Promise; diff --git a/lib/clients/authenticated.js b/lib/clients/authenticated.js index 59c2cde8..148eb880 100644 --- a/lib/clients/authenticated.js +++ b/lib/clients/authenticated.js @@ -3,10 +3,10 @@ const { signRequest } = require('../../lib/request_signer'); const PublicClient = require('./public.js'); class AuthenticatedClient extends PublicClient { - constructor(key, b64secret, passphrase, apiURI) { + constructor(key, secret, passphrase, apiURI) { super('', apiURI); this.key = key; - this.b64secret = b64secret; + this.secret = secret; this.passphrase = passphrase; } @@ -29,12 +29,7 @@ class AuthenticatedClient extends PublicClient { } _getSignature(method, relativeURI, opts) { - const auth = { - key: this.key, - secret: this.b64secret, - passphrase: this.passphrase, - }; - const sig = signRequest(auth, method, relativeURI, opts); + const sig = signRequest(this, method, relativeURI, opts); if (opts.body) { opts.body = JSON.stringify(opts.body); diff --git a/lib/orderbook_sync.js b/lib/orderbook_sync.js index 04fbf46f..ff688a03 100644 --- a/lib/orderbook_sync.js +++ b/lib/orderbook_sync.js @@ -11,16 +11,7 @@ class OrderbookSync extends WebsocketClient { authenticatedClient = null, { heartbeat = false } = {} ) { - let auth = null; - if (authenticatedClient) { - auth = { - key: authenticatedClient.key, - secret: authenticatedClient.b64secret, - passphrase: authenticatedClient.passphrase, - }; - } - - super(productIDs, websocketURI, auth, { heartbeat }); + super(productIDs, websocketURI, authenticatedClient, { heartbeat }); this.apiURI = apiURI; this.authenticatedClient = authenticatedClient;