@psf/bch-js 6.8.3 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +10 -28
  3. package/fix-docs-contrast.sh +38 -0
  4. package/package.json +38 -47
  5. package/src/address.js +12 -23
  6. package/src/bch-js.js +81 -48
  7. package/src/bitcoincash.js +10 -11
  8. package/src/blockchain.js +57 -68
  9. package/src/control.js +11 -22
  10. package/src/crypto.js +3 -3
  11. package/src/dsproof.js +6 -17
  12. package/src/ecash.js +1 -1
  13. package/src/ecpair.js +3 -3
  14. package/src/electrumx.js +32 -44
  15. package/src/encryption.js +8 -17
  16. package/src/generating.js +8 -19
  17. package/src/hdnode.js +5 -5
  18. package/src/mining.js +11 -22
  19. package/src/mnemonic.js +8 -11
  20. package/src/price.js +7 -108
  21. package/src/psf-slp-indexer.js +21 -32
  22. package/src/raw-transactions.js +22 -35
  23. package/src/schnorr.js +5 -16
  24. package/src/script.js +4 -2
  25. package/src/slp/address.js +4 -4
  26. package/src/slp/ecpair.js +4 -4
  27. package/src/slp/nft1.js +6 -6
  28. package/src/slp/slp.js +11 -22
  29. package/src/slp/tokentype1.js +11 -22
  30. package/src/slp/utils.js +9 -19
  31. package/src/transaction-builder.js +5 -5
  32. package/src/transaction.js +5 -5
  33. package/src/util.js +5 -98
  34. package/src/utxo.js +6 -6
  35. package/test/e2e/bch-js-e2e-tests.js +4 -3
  36. package/test/e2e/ipfs/ipfs-e2e.js +8 -2
  37. package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
  38. package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
  39. package/test/e2e/rate-limits/free-rate-limits.js +4 -3
  40. package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
  41. package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
  42. package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
  43. package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
  44. package/test/e2e/send-token/send-token.js +4 -4
  45. package/test/e2e/util/e2e-util.js +6 -3
  46. package/test/e2e/utxo/unsynced-indexer.js +1 -1
  47. package/test/integration/blockchain.js +5 -5
  48. package/test/integration/control.js +2 -2
  49. package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
  50. package/test/integration/electrumx.js +5 -12
  51. package/test/integration/price.js +3 -39
  52. package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
  53. package/test/integration/rawtransaction.js +39 -5
  54. package/test/integration/slp.js +147 -5
  55. package/test/integration/transaction-integration.js +27 -2
  56. package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
  57. package/test/unit/address.js +7 -4
  58. package/test/unit/bitcoin-cash.js +5 -3
  59. package/test/unit/blockchain.js +23 -22
  60. package/test/unit/control.js +6 -6
  61. package/test/unit/crypto.js +5 -3
  62. package/test/unit/dsproof.js +5 -4
  63. package/test/unit/ecash.js +3 -2
  64. package/test/unit/ecpairs.js +6 -4
  65. package/test/unit/electrumx.js +7 -7
  66. package/test/unit/encryption.js +6 -5
  67. package/test/unit/fixtures/bitcore-mock.js +1 -1
  68. package/test/unit/fixtures/block-mock.js +1 -1
  69. package/test/unit/fixtures/blockchain-mock.js +1 -1
  70. package/test/unit/fixtures/dsproof-mock.js +1 -1
  71. package/test/unit/fixtures/electrumx-mock.js +1 -1
  72. package/test/unit/fixtures/encryption-mock.js +1 -1
  73. package/test/unit/fixtures/ipfs-mock.js +1 -1
  74. package/test/unit/fixtures/openbazaar-mock.js +1 -1
  75. package/test/unit/fixtures/price-mocks.js +1 -1
  76. package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
  77. package/test/unit/fixtures/rawtransaction-mock.js +1 -1
  78. package/test/unit/fixtures/slp/mock-utils.js +1 -1
  79. package/test/unit/fixtures/transaction-mock.js +1 -1
  80. package/test/unit/fixtures/utxo-mocks.js +1 -1
  81. package/test/unit/generating.js +5 -5
  82. package/test/unit/hdnode.js +6 -4
  83. package/test/unit/mining.js +8 -8
  84. package/test/unit/mnemonic.js +4 -2
  85. package/test/unit/price.js +5 -14
  86. package/test/unit/psf-slp-indexer.js +7 -7
  87. package/test/unit/raw-tranactions.js +14 -13
  88. package/test/unit/scripts.js +8 -6
  89. package/test/unit/slp-address.js +6 -4
  90. package/test/unit/slp-ecpair.js +5 -3
  91. package/test/unit/slp-nft1.js +7 -6
  92. package/test/unit/slp-tokentype1.js +7 -6
  93. package/test/unit/slp-utils.js +8 -7
  94. package/test/unit/transaction-builder.js +7 -4
  95. package/test/unit/transaction-unit.js +5 -4
  96. package/test/unit/util.js +11 -32
  97. package/test/unit/utxo-unit.js +6 -5
  98. package/test/unit/x402.js +193 -0
  99. package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
  100. package/test/integration/chains/abc/rawtransaction.js +0 -73
  101. package/test/integration/chains/abc/utxo-integration.js +0 -38
  102. package/test/integration/chains/bchn/rawtransaction.js +0 -71
  103. package/test/integration/chains/bchn/slp.js +0 -301
  104. package/test/integration/chains/bchn/transaction-integration.js +0 -37
  105. package/test/integration/chains/bchn/util.js +0 -103
  106. package/test/integration/chains/testnet/blockchain.js +0 -260
  107. package/test/integration/chains/testnet/control.js +0 -32
  108. package/test/integration/chains/testnet/electrumx.js +0 -376
  109. package/test/integration/chains/testnet/rawtransaction.js +0 -296
  110. package/test/integration/chains/testnet/slp.js +0 -172
  111. package/test/integration/chains/testnet/test-free-tier.sh +0 -9
  112. package/test/integration/chains/testnet/util.js +0 -109
package/src/generating.js CHANGED
@@ -1,35 +1,24 @@
1
- const axios = require('axios')
1
+ import axios from 'axios'
2
2
 
3
3
  // let _this
4
4
 
5
5
  class Generating {
6
6
  constructor (config) {
7
7
  this.restURL = config.restURL
8
- this.apiToken = config.apiToken
9
8
  this.authToken = config.authToken
9
+ // Use the shared axios instance if provided, otherwise fall back to axios
10
+ this.axios = config.axios || axios
10
11
 
11
- if (this.authToken) {
12
- // Add Basic Authentication token to the authorization header.
13
- this.axiosOptions = {
14
- headers: {
15
- authorization: this.authToken
16
- }
17
- }
18
- } else {
19
- // Add JWT token to the authorization header.
20
- this.axiosOptions = {
21
- headers: {
22
- authorization: `Token ${this.apiToken}`
23
- }
12
+ this.axiosOptions = {
13
+ headers: {
14
+ authorization: this.authToken
24
15
  }
25
16
  }
26
-
27
- // _this = this
28
17
  }
29
18
 
30
19
  async generateToAddress (blocks, address, maxtries = 1000000) {
31
20
  try {
32
- const response = await axios.post(
21
+ const response = await this.axios.post(
33
22
  `${this.restURL}generating/generateToAddress/${blocks}/${address}?maxtries=${maxtries}`,
34
23
  this.axiosOptions
35
24
  )
@@ -41,4 +30,4 @@ class Generating {
41
30
  }
42
31
  }
43
32
 
44
- module.exports = Generating
33
+ export default Generating
package/src/hdnode.js CHANGED
@@ -1,7 +1,7 @@
1
- const Bitcoin = require('@psf/bitcoincashjs-lib')
2
- const coininfo = require('@psf/coininfo')
3
- const bip32utils = require('@chris.troutner/bip32-utils')
4
- const bchaddrjs = require('bchaddrjs-slp')
1
+ import Bitcoin from '@psf/bitcoincashjs-lib'
2
+ import coininfo from '@psf/coininfo'
3
+ import bip32utils from '@chris.troutner/bip32-utils'
4
+ import bchaddrjs from 'bchaddrjs-slp'
5
5
 
6
6
  class HDNode {
7
7
  constructor (address) {
@@ -637,4 +637,4 @@ class HDNode {
637
637
  }
638
638
  }
639
639
 
640
- module.exports = HDNode
640
+ export default HDNode
package/src/mining.js CHANGED
@@ -1,35 +1,24 @@
1
- const axios = require('axios')
1
+ import axios from 'axios'
2
2
 
3
3
  // let _this
4
4
 
5
5
  class Mining {
6
6
  constructor (config) {
7
7
  this.restURL = config.restURL
8
- this.apiToken = config.apiToken
9
8
  this.authToken = config.authToken
9
+ // Use the shared axios instance if provided, otherwise fall back to axios
10
+ this.axios = config.axios || axios
10
11
 
11
- if (this.authToken) {
12
- // Add Basic Authentication token to the authorization header.
13
- this.axiosOptions = {
14
- headers: {
15
- authorization: this.authToken
16
- }
17
- }
18
- } else {
19
- // Add JWT token to the authorization header.
20
- this.axiosOptions = {
21
- headers: {
22
- authorization: `Token ${this.apiToken}`
23
- }
12
+ this.axiosOptions = {
13
+ headers: {
14
+ authorization: this.authToken
24
15
  }
25
16
  }
26
-
27
- // _this = this
28
17
  }
29
18
 
30
19
  async getBlockTemplate (templateRequest) {
31
20
  try {
32
- const response = await axios.get(
21
+ const response = await this.axios.get(
33
22
  `${this.restURL}mining/getBlockTemplate/${templateRequest}`,
34
23
  this.axiosOptions
35
24
  )
@@ -42,7 +31,7 @@ class Mining {
42
31
 
43
32
  async getMiningInfo () {
44
33
  try {
45
- const response = await axios.get(
34
+ const response = await this.axios.get(
46
35
  `${this.restURL}mining/getMiningInfo`,
47
36
  this.axiosOptions
48
37
  )
@@ -55,7 +44,7 @@ class Mining {
55
44
 
56
45
  async getNetworkHashps (nblocks = 120, height = 1) {
57
46
  try {
58
- const response = await axios.get(
47
+ const response = await this.axios.get(
59
48
  `${this.restURL}mining/getNetworkHashps?nblocks=${nblocks}&height=${height}`,
60
49
  this.axiosOptions
61
50
  )
@@ -71,7 +60,7 @@ class Mining {
71
60
  if (parameters) path = `${path}?parameters=${parameters}`
72
61
 
73
62
  try {
74
- const response = await axios.post(path, this.axiosOptions)
63
+ const response = await this.axios.post(path, this.axiosOptions)
75
64
  return response.data
76
65
  } catch (error) {
77
66
  if (error.response && error.response.data) throw error.response.data
@@ -80,4 +69,4 @@ class Mining {
80
69
  }
81
70
  }
82
71
 
83
- module.exports = Mining
72
+ export default Mining
package/src/mnemonic.js CHANGED
@@ -1,11 +1,8 @@
1
- /* eslint no-prototype-builtins: "off" */
2
- /* eslint node/no-callback-literal: "off" */
3
-
4
- const BIP39 = require('bip39')
5
- const randomBytes = require('randombytes')
6
- const Bitcoin = require('@psf/bitcoincashjs-lib')
7
- const Buffer = require('safe-buffer').Buffer
8
- const wif = require('wif')
1
+ import BIP39 from 'bip39'
2
+ import randomBytes from 'randombytes'
3
+ import Bitcoin from '@psf/bitcoincashjs-lib'
4
+ import { Buffer } from 'safe-buffer'
5
+ import wif from 'wif'
9
6
 
10
7
  class Mnemonic {
11
8
  constructor (address) {
@@ -338,7 +335,7 @@ class Mnemonic {
338
335
  }
339
336
  }
340
337
 
341
- module.exports = Mnemonic
338
+ export default Mnemonic
342
339
 
343
340
  // The following code is from: https://raw.githubusercontent.com/iancoleman/bip39/7ff86d4c983f1e8c80b87b31acfd69fcf98c1b82/src/js/levenshtein.js
344
341
 
@@ -356,7 +353,7 @@ const _extend = function (dst) {
356
353
  const sources = Array.prototype.slice.call(arguments, 1)
357
354
  for (let i = 0; i < sources.length; ++i) {
358
355
  const src = sources[i]
359
- for (const p in src) if (src.hasOwnProperty(p)) dst[p] = src[p]
356
+ for (const p in src) if (Object.prototype.hasOwnProperty.call(src, p)) dst[p] = src[p]
360
357
  }
361
358
  return dst
362
359
  }
@@ -503,7 +500,7 @@ const Levenshtein = {
503
500
  try {
504
501
  options.progress.call(null, (i * 100.0) / str1.length)
505
502
  } catch (err) {
506
- return cb(`Progress callback: ${err.toString()}`)
503
+ return cb(new Error(`Progress callback: ${err.toString()}`))
507
504
  }
508
505
  }
509
506
 
package/src/price.js CHANGED
@@ -1,49 +1,22 @@
1
- const axios = require('axios')
1
+ import axios from 'axios'
2
2
 
3
3
  // let _this
4
4
 
5
5
  class Price {
6
6
  constructor (config) {
7
- // _this = this
8
-
9
7
  this.restURL = config.restURL
10
- this.apiToken = config.apiToken
11
8
  this.authToken = config.authToken
12
9
 
13
- if (this.authToken) {
14
- // Add Basic Authentication token to the authorization header.
15
- this.axiosOptions = {
16
- headers: {
17
- authorization: this.authToken
18
- }
19
- }
20
- } else {
21
- // Add JWT token to the authorization header.
22
- this.axiosOptions = {
23
- headers: {
24
- authorization: `Token ${this.apiToken}`
25
- }
10
+ this.axiosOptions = {
11
+ headers: {
12
+ authorization: this.authToken
26
13
  }
27
14
  }
28
15
 
29
- this.axios = axios
16
+ // Use the shared axios instance if provided, otherwise fall back to axios
17
+ this.axios = config.axios || axios
30
18
  }
31
19
 
32
- // This endpoint is deprecated. Documentation removed.
33
- // async current (currency = 'usd') {
34
- // try {
35
- // const response = await this.axios.get(
36
- // `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
37
- // )
38
- // // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
39
- //
40
- // return response.data.price
41
- // } catch (err) {
42
- // if (err.response && err.response.data) throw err.response.data
43
- // else throw err
44
- // }
45
- // }
46
-
47
20
  /**
48
21
  * @api price.getUsd() getUsd()
49
22
  * @apiName Price getUsd()
@@ -122,80 +95,6 @@ class Price {
122
95
  }
123
96
  }
124
97
 
125
- /**
126
- * @api price.getBchaUsd() getBchaUsd()
127
- * @apiName Price getBchaUsd()
128
- * @apiGroup Price
129
- * @apiDescription Return current price of BCHA in USD.
130
- * This endpoint gets the USD price of XEC from the Coinex API. The price
131
- * denominated in BCHA comes from bch-api, so it has a better chance of
132
- * working in Tor.
133
- *
134
- * @apiExample Example usage:
135
- *(async () => {
136
- * try {
137
- * let current = await bchjs.Price.getBchaUsd();
138
- * console.log(current);
139
- * } catch(err) {
140
- * console.error(err)
141
- * }
142
- *})()
143
- *
144
- * // 212.34
145
- */
146
- async getBchaUsd () {
147
- try {
148
- const response = await this.axios.get(
149
- `${this.restURL}price/bchausd`,
150
- this.axiosOptions
151
- )
152
- // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
153
-
154
- const bchaPrice = response.data.usd * 1000000
155
- // Convert XEC denomination to BCHA denomination
156
-
157
- return bchaPrice
158
- } catch (err) {
159
- if (err.response && err.response.data) throw err.response.data
160
- else throw err
161
- }
162
- }
163
-
164
- /**
165
- * @api price.getXecUsd() getXecUsd()
166
- * @apiName Price getXecUsd()
167
- * @apiGroup Price
168
- * @apiDescription Return current price of XEC in USD.
169
- * This endpoint gets the USD price of XEC from the Coinex API. The price
170
- * comes from bch-api, so it has a better chance of working in Tor.
171
- *
172
- * @apiExample Example usage:
173
- *(async () => {
174
- * try {
175
- * let current = await bchjs.Price.getXecUsd();
176
- * console.log(current);
177
- * } catch(err) {
178
- * console.error(err)
179
- * }
180
- *})()
181
- *
182
- * // 0.00021234
183
- */
184
- async getXecUsd () {
185
- try {
186
- const response = await this.axios.get(
187
- `${this.restURL}price/bchausd`,
188
- this.axiosOptions
189
- )
190
- // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
191
-
192
- return response.data.usd
193
- } catch (err) {
194
- if (err.response && err.response.data) throw err.response.data
195
- else throw err
196
- }
197
- }
198
-
199
98
  /**
200
99
  * @api price.getBchUsd() getBchUsd()
201
100
  * @apiName Price getBchUsd()
@@ -268,4 +167,4 @@ class Price {
268
167
  }
269
168
  }
270
169
 
271
- module.exports = Price
170
+ export default Price
@@ -7,41 +7,30 @@
7
7
  */
8
8
 
9
9
  // Public npm libraries
10
- const axios = require('axios')
10
+ import axios from 'axios'
11
11
 
12
12
  // Local libraries
13
- const RawTransaction = require('./raw-transactions')
14
- const SlpUtils = require('./slp/utils')
13
+ import RawTransaction from './raw-transactions.js'
14
+ import SlpUtils from './slp/utils.js'
15
15
 
16
16
  // let _this
17
17
 
18
18
  class PsfSlpIndexer {
19
19
  constructor (config = {}) {
20
20
  this.restURL = config.restURL
21
- this.apiToken = config.apiToken
22
21
  this.authToken = config.authToken
22
+ // Use the shared axios instance if provided, otherwise fall back to axios
23
+ this.axios = config.axios || axios
23
24
 
24
- if (this.authToken) {
25
- // Add Basic Authentication token to the authorization header.
26
- this.axiosOptions = {
27
- headers: {
28
- authorization: this.authToken
29
- }
30
- }
31
- } else {
32
- // Add JWT token to the authorization header.
33
- this.axiosOptions = {
34
- headers: {
35
- authorization: `Token ${this.apiToken}`
36
- }
25
+ this.axiosOptions = {
26
+ headers: {
27
+ authorization: this.authToken
37
28
  }
38
29
  }
39
30
 
40
31
  // Encapsulate dependencies
41
32
  this.rawTransaction = new RawTransaction(config)
42
33
  this.slpUtils = new SlpUtils(config)
43
-
44
- // _this = this
45
34
  }
46
35
 
47
36
  /**
@@ -71,8 +60,8 @@ class PsfSlpIndexer {
71
60
  */
72
61
  async status () {
73
62
  try {
74
- const response = await axios.get(
75
- `${this.restURL}psf/slp/status`,
63
+ const response = await this.axios.get(
64
+ `${this.restURL}slp/status`,
76
65
  this.axiosOptions
77
66
  )
78
67
  return response.data
@@ -136,8 +125,8 @@ class PsfSlpIndexer {
136
125
 
137
126
  // Handle single address.
138
127
  if (typeof address === 'string') {
139
- const response = await axios.post(
140
- `${this.restURL}psf/slp/address`,
128
+ const response = await this.axios.post(
129
+ `${this.restURL}slp/address`,
141
130
  { address },
142
131
  this.axiosOptions
143
132
  )
@@ -201,8 +190,8 @@ class PsfSlpIndexer {
201
190
  try {
202
191
  // Handle single address.
203
192
  if (typeof tokenId === 'string') {
204
- const response = await axios.post(
205
- `${this.restURL}psf/slp/token`,
193
+ const response = await this.axios.post(
194
+ `${this.restURL}slp/token`,
206
195
  { tokenId, withTxHistory },
207
196
  this.axiosOptions
208
197
  )
@@ -293,8 +282,8 @@ class PsfSlpIndexer {
293
282
 
294
283
  // Handle single address.
295
284
  if (typeof txid === 'string') {
296
- const response = await axios.post(
297
- `${this.restURL}psf/slp/txid`,
285
+ const response = await this.axios.post(
286
+ `${this.restURL}slp/txid`,
298
287
  { txid },
299
288
  this.axiosOptions
300
289
  )
@@ -423,12 +412,12 @@ class PsfSlpIndexer {
423
412
  */
424
413
  async getTokenData (tokenId, withTxHistory = false) {
425
414
  try {
426
- const url = `${this.restURL}psf/slp/token/data`
415
+ const url = `${this.restURL}slp/token/data`
427
416
  // console.log(`url: ${url}`)
428
417
 
429
418
  // Handle single address.
430
419
  if (typeof tokenId === 'string') {
431
- const response = await axios.post(
420
+ const response = await this.axios.post(
432
421
  // 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
433
422
  url,
434
423
  { tokenId, withTxHistory },
@@ -516,12 +505,12 @@ class PsfSlpIndexer {
516
505
  */
517
506
  async getTokenData2 (tokenId, updateCache = false) {
518
507
  try {
519
- const url = `${this.restURL}psf/slp/token/data2`
508
+ const url = `${this.restURL}slp/token/data2`
520
509
  // console.log(`url: ${url}`)
521
510
 
522
511
  // Handle single address.
523
512
  if (typeof tokenId === 'string') {
524
- const response = await axios.post(
513
+ const response = await this.axios.post(
525
514
  // 'https://bchn.fullstack.cash/v5/psf/slp/token/data/',
526
515
  url,
527
516
  { tokenId, updateCache },
@@ -539,4 +528,4 @@ class PsfSlpIndexer {
539
528
  }
540
529
  }
541
530
 
542
- module.exports = PsfSlpIndexer
531
+ export default PsfSlpIndexer
@@ -1,33 +1,20 @@
1
- const axios = require('axios')
1
+ import axios from 'axios'
2
2
 
3
3
  // let _this
4
4
 
5
5
  class RawTransactions {
6
6
  constructor (config) {
7
7
  this.restURL = config.restURL
8
- this.apiToken = config.apiToken
9
8
  this.authToken = config.authToken
10
9
 
11
- if (this.authToken) {
12
- // Add Basic Authentication token to the authorization header.
13
- this.axiosOptions = {
14
- headers: {
15
- authorization: this.authToken
16
- }
17
- }
18
- } else {
19
- // Add JWT token to the authorization header.
20
- this.axiosOptions = {
21
- headers: {
22
- authorization: `Token ${this.apiToken}`
23
- }
10
+ this.axiosOptions = {
11
+ headers: {
12
+ authorization: this.authToken
24
13
  }
25
14
  }
26
15
 
27
- // Encapsulate dependencies
28
- this.axios = axios
29
-
30
- // this = this
16
+ // Use the shared axios instance if provided, otherwise fall back to axios
17
+ this.axios = config.axios || axios
31
18
  }
32
19
 
33
20
  /**
@@ -96,8 +83,8 @@ class RawTransactions {
96
83
  try {
97
84
  // Single hex
98
85
  if (typeof hex === 'string') {
99
- const response = await axios.get(
100
- `${this.restURL}rawtransactions/decodeRawTransaction/${hex}`,
86
+ const response = await this.axios.get(
87
+ `${this.restURL}full-node/rawtransactions/decodeRawTransaction/${hex}`,
101
88
  this.axiosOptions
102
89
  )
103
90
 
@@ -107,13 +94,13 @@ class RawTransactions {
107
94
  } else if (Array.isArray(hex)) {
108
95
  const options = {
109
96
  method: 'POST',
110
- url: `${this.restURL}rawtransactions/decodeRawTransaction`,
97
+ url: `${this.restURL}full-node/rawtransactions/decodeRawTransaction`,
111
98
  data: {
112
99
  hexes: hex
113
100
  },
114
101
  headers: this.axiosOptions.headers
115
102
  }
116
- const response = await axios(options)
103
+ const response = await this.axios(options)
117
104
 
118
105
  return response.data
119
106
  }
@@ -164,8 +151,8 @@ class RawTransactions {
164
151
 
165
152
  try {
166
153
  if (typeof script === 'string') {
167
- const response = await axios.get(
168
- `${this.restURL}rawtransactions/decodeScript/${script}`,
154
+ const response = await this.axios.get(
155
+ `${this.restURL}full-node/rawtransactions/decodeScript/${script}`,
169
156
  this.axiosOptions
170
157
  )
171
158
 
@@ -173,13 +160,13 @@ class RawTransactions {
173
160
  } else if (Array.isArray(script)) {
174
161
  const options = {
175
162
  method: 'POST',
176
- url: `${this.restURL}rawtransactions/decodeScript`,
163
+ url: `${this.restURL}full-node/rawtransactions/decodeScript`,
177
164
  data: {
178
165
  hexes: script
179
166
  },
180
167
  headers: this.axiosOptions.headers
181
168
  }
182
- const response = await axios(options)
169
+ const response = await this.axios(options)
183
170
 
184
171
  return response.data
185
172
  }
@@ -263,8 +250,8 @@ class RawTransactions {
263
250
  // 'getRawTransaction() this.axiosOptions: ',
264
251
  // this.axiosOptions
265
252
  // )
266
- const response = await axios.get(
267
- `${this.restURL}rawtransactions/getRawTransaction/${txid}?verbose=${verbose}`,
253
+ const response = await this.axios.get(
254
+ `${this.restURL}full-node/rawtransactions/getRawTransaction/${txid}?verbose=${verbose}`,
268
255
  this.axiosOptions
269
256
  )
270
257
 
@@ -272,15 +259,15 @@ class RawTransactions {
272
259
  } else if (Array.isArray(txid)) {
273
260
  const options = {
274
261
  method: 'POST',
275
- url: `${this.restURL}rawtransactions/getRawTransaction`,
262
+ url: `${this.restURL}full-node/rawtransactions/getRawTransaction`,
276
263
  data: {
277
264
  txids: txid,
278
- verbose: verbose,
265
+ verbose,
279
266
  usrObj // pass user data when making an internal call.
280
267
  },
281
268
  headers: this.axiosOptions.headers
282
269
  }
283
- const response = await axios(options)
270
+ const response = await this.axios(options)
284
271
 
285
272
  return response.data
286
273
  }
@@ -460,7 +447,7 @@ class RawTransactions {
460
447
  // Single tx hex.
461
448
  if (typeof hex === 'string') {
462
449
  const response = await this.axios.get(
463
- `${this.restURL}rawtransactions/sendRawTransaction/${hex}`,
450
+ `${this.restURL}full-node/rawtransactions/sendRawTransaction/${hex}`,
464
451
  this.axiosOptions
465
452
  )
466
453
 
@@ -478,7 +465,7 @@ class RawTransactions {
478
465
  } else if (Array.isArray(hex)) {
479
466
  const options = {
480
467
  method: 'POST',
481
- url: `${this.restURL}rawtransactions/sendRawTransaction`,
468
+ url: `${this.restURL}full-node/rawtransactions/sendRawTransaction`,
482
469
  data: {
483
470
  hexes: hex
484
471
  },
@@ -498,4 +485,4 @@ class RawTransactions {
498
485
  }
499
486
  }
500
487
 
501
- module.exports = RawTransactions
488
+ export default RawTransactions
package/src/schnorr.js CHANGED
@@ -1,24 +1,13 @@
1
- const schnorr = require('bip-schnorr')
1
+ import schnorr from 'bip-schnorr'
2
2
 
3
3
  class Schnorr {
4
4
  constructor (config) {
5
5
  this.restURL = config.restURL
6
- this.apiToken = config.apiToken
7
6
  this.authToken = config.authToken
8
7
 
9
- if (this.authToken) {
10
- // Add Basic Authentication token to the authorization header.
11
- this.axiosOptions = {
12
- headers: {
13
- authorization: this.authToken
14
- }
15
- }
16
- } else {
17
- // Add JWT token to the authorization header.
18
- this.axiosOptions = {
19
- headers: {
20
- authorization: `Token ${this.apiToken}`
21
- }
8
+ this.axiosOptions = {
9
+ headers: {
10
+ authorization: this.authToken
22
11
  }
23
12
  }
24
13
  }
@@ -509,4 +498,4 @@ class Schnorr {
509
498
  }
510
499
  }
511
500
 
512
- module.exports = Schnorr
501
+ export default Schnorr
package/src/script.js CHANGED
@@ -1,4 +1,6 @@
1
- const Bitcoin = require('@psf/bitcoincashjs-lib')
1
+ import Bitcoin from '@psf/bitcoincashjs-lib'
2
+ import { createRequire } from 'module'
3
+ const require = createRequire(import.meta.url)
2
4
  const opcodes = require('@psf/bitcoincash-ops')
3
5
 
4
6
  class Script {
@@ -240,4 +242,4 @@ class Script {
240
242
  }
241
243
  }
242
244
 
243
- module.exports = Script
245
+ export default Script
@@ -1,9 +1,9 @@
1
- const BCHJSAddress = require('../address')
1
+ import BCHJSAddress from '../address.js'
2
+
3
+ import bchaddrjs from 'bchaddrjs-slp'
2
4
  // const bchAddress = new BCHJSAddress()
3
5
  let bchAddress
4
6
 
5
- const bchaddrjs = require('bchaddrjs-slp')
6
-
7
7
  class Address extends BCHJSAddress {
8
8
  constructor (config) {
9
9
  super(config)
@@ -661,4 +661,4 @@ class Address extends BCHJSAddress {
661
661
  }
662
662
  }
663
663
 
664
- module.exports = Address
664
+ export default Address
package/src/slp/ecpair.js CHANGED
@@ -1,9 +1,9 @@
1
- // const BCHJS = require("../bch-js")
1
+ // import BCHJS from "../bch-js.js"
2
2
  // const bchjs = new BCHJS()
3
3
 
4
- const BCHJSECPair = require('../ecpair')
4
+ import BCHJSECPair from '../ecpair.js'
5
5
 
6
- const bchaddrjs = require('bchaddrjs-slp')
6
+ import bchaddrjs from 'bchaddrjs-slp'
7
7
 
8
8
  class ECPair extends BCHJSECPair {
9
9
  /*
@@ -31,4 +31,4 @@ class ECPair extends BCHJSECPair {
31
31
  }
32
32
  }
33
33
 
34
- module.exports = ECPair
34
+ export default ECPair