diff --git a/src/bch-js.js b/src/bch-js.js index 23517ba..8777ba5 100644 --- a/src/bch-js.js +++ b/src/bch-js.js @@ -65,7 +65,7 @@ class BCHJS { // Generate a Basic Authentication token from an auth password this.authToken = "" if (this.authPass) { - console.log(`bch-js initialized with authPass: ${this.authPass}`) + // console.log(`bch-js initialized with authPass: ${this.authPass}`) // Generate the header for Basic Authentication. const combined = `fullstackcash:${this.authPass}` var base64Credential = Buffer.from(combined).toString("base64") diff --git a/src/raw-transactions.js b/src/raw-transactions.js index 636d903..31a02b3 100644 --- a/src/raw-transactions.js +++ b/src/raw-transactions.js @@ -272,9 +272,7 @@ class RawTransactions { txids: txid, verbose: verbose }, - headers: { - authorization: `Token ${this.apiToken}` - } + headers: _this.axiosOptions.headers } const response = await axios(options) @@ -347,9 +345,7 @@ class RawTransactions { data: { hexes: hex }, - headers: { - authorization: `Token ${this.apiToken}` - } + headers: _this.axiosOptions.headers } const response = await axios(options) diff --git a/src/slp/tokentype1.js b/src/slp/tokentype1.js index d6392f2..733df8d 100644 --- a/src/slp/tokentype1.js +++ b/src/slp/tokentype1.js @@ -18,17 +18,28 @@ class TokenType1 { constructor(config) { this.restURL = config.restURL this.apiToken = config.apiToken + this.authToken = config.authToken + + if (this.authToken) { + // Add Basic Authentication token to the authorization header. + this.axiosOptions = { + headers: { + authorization: this.authToken + } + } + } else { + // Add JWT token to the authorization header. + this.axiosOptions = { + headers: { + authorization: `Token ${this.apiToken}` + } + } + } addy = new Address(config) this.Script = new Script() this.axios = axios - // Add JWT token to the authorization header. - this.axiosOptions = { - headers: { - authorization: `Token ${this.apiToken}` - } - } // Instantiate the transaction builder. TransactionBuilder.setAddress(addy) diff --git a/src/slp/utils.js b/src/slp/utils.js index 6889526..f8a6bfb 100644 --- a/src/slp/utils.js +++ b/src/slp/utils.js @@ -13,11 +13,21 @@ class Utils { this.restURL = config.restURL this.apiToken = config.apiToken this.slpParser = slpParser + this.authToken = config.authToken - // Add JWT token to the authorization header. - this.axiosOptions = { - headers: { - authorization: `Token ${this.apiToken}` + if (this.authToken) { + // Add Basic Authentication token to the authorization header. + this.axiosOptions = { + headers: { + authorization: this.authToken + } + } + } else { + // Add JWT token to the authorization header. + this.axiosOptions = { + headers: { + authorization: `Token ${this.apiToken}` + } } } diff --git a/test/e2e/rate-limits/anonymous-rate-limits.js b/test/e2e/rate-limits/anonymous-rate-limits.js index c11f15b..462dd98 100644 --- a/test/e2e/rate-limits/anonymous-rate-limits.js +++ b/test/e2e/rate-limits/anonymous-rate-limits.js @@ -15,7 +15,8 @@ const assert = require("chai").assert // const RESTURL = `https://abc.fullstack.cash/v3/` -const RESTURL = `http://localhost:3000/v3/` +const RESTURL = `https://bchn.fullstack.cash/v3/` +// const RESTURL = `http://localhost:3000/v3/` const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ restURL: RESTURL }) @@ -29,7 +30,7 @@ describe("#anonymous rate limits", () => { it("should allow an anonymous call to an indexer", async () => { const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" - const result = await bchjs.Blockbook.balance(addr) + const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.property(result, "balance") diff --git a/test/e2e/rate-limits/basic-auth-rate-limits.js b/test/e2e/rate-limits/basic-auth-rate-limits.js index 6bcb1c5..c311e11 100644 --- a/test/e2e/rate-limits/basic-auth-rate-limits.js +++ b/test/e2e/rate-limits/basic-auth-rate-limits.js @@ -13,12 +13,13 @@ const PRO_PASS = "testpassword" const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ - // restURL: `https://api.fullstack.cash/v3/`, - restURL: `http://localhost:3000/v3/`, + // restURL: `https://bchn.fullstack.cash/v3/`, + restURL: `https://abc.fullstack.cash/v3/`, + // restURL: `http://localhost:3000/v3/`, authPass: PRO_PASS }) -describe("#full node rate limits", () => { +describe("#Basic Authentication rate limits", () => { it("should allow more than 20 RPM to full node", async () => { for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() diff --git a/test/e2e/rate-limits/full-node-rate-limits.js b/test/e2e/rate-limits/full-node-rate-limits.js index 5996b3d..98b69fa 100644 --- a/test/e2e/rate-limits/full-node-rate-limits.js +++ b/test/e2e/rate-limits/full-node-rate-limits.js @@ -18,7 +18,8 @@ const JWT_TOKEN = const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ - restURL: `https://api.fullstack.cash/v3/`, + // restURL: `https://bchn.fullstack.cash/v3/`, + restURL: `https:/abc.fullstack.cash/v3/`, // restURL: `http://localhost:3000/v3/`, apiToken: JWT_TOKEN }) @@ -26,7 +27,7 @@ const bchjs = new BCHJS({ describe("#full node rate limits", () => { it("should allow an free call to an indexer", async () => { const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" - const result = await bchjs.Blockbook.balance(addr) + const result = await bchjs.Electrumx.balance(addr) // console.log(`result: ${JSON.stringify(result, null, 2)}`) assert.property(result, "balance") diff --git a/test/e2e/rate-limits/indexer-rate-limits.js b/test/e2e/rate-limits/indexer-rate-limits.js index a7262fd..7bee43e 100644 --- a/test/e2e/rate-limits/indexer-rate-limits.js +++ b/test/e2e/rate-limits/indexer-rate-limits.js @@ -14,12 +14,13 @@ const JWT_TOKEN = const BCHJS = require("../../../src/bch-js") const bchjs = new BCHJS({ - restURL: `https://api.fullstack.cash/v3/`, + // restURL: `https://bchn.fullstack.cash/v3/`, + restURL: `https://abc.fullstack.cash/v3/`, // restURL: `http://localhost:3000/v3/`, apiToken: JWT_TOKEN }) -describe("#full node rate limits", () => { +describe("#Indexer rate limits", () => { it("should allow more than 20 RPM to full node", async () => { for (let i = 0; i < 22; i++) { const result = await bchjs.Control.getNetworkInfo() @@ -40,7 +41,7 @@ describe("#full node rate limits", () => { const addr = "bitcoincash:qrdka2205f4hyukutc2g0s6lykperc8nsu5u2ddpqf" for (let i = 0; i < 22; i++) { - const result = await bchjs.Blockbook.balance(addr) + const result = await bchjs.Electrumx.balance(addr) if (i === 5) { // console.log(`validating 5th call: ${i}`)