mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
Merge pull request #57 from Permissionless-Software-Foundation/ct-unstable
fix(basic auth): Fixing some bugs around basic auth
This commit is contained in:
+1
-1
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
+15
-4
@@ -18,17 +18,28 @@ class TokenType1 {
|
||||
constructor(config) {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.authToken = config.authToken
|
||||
|
||||
addy = new Address(config)
|
||||
this.Script = new Script()
|
||||
|
||||
this.axios = axios
|
||||
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
|
||||
|
||||
// Instantiate the transaction builder.
|
||||
TransactionBuilder.setAddress(addy)
|
||||
|
||||
@@ -13,13 +13,23 @@ class Utils {
|
||||
this.restURL = config.restURL
|
||||
this.apiToken = config.apiToken
|
||||
this.slpParser = slpParser
|
||||
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}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_this = this
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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}`)
|
||||
|
||||
Reference in New Issue
Block a user