@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/slp/nft1.js CHANGED
@@ -9,18 +9,18 @@
9
9
  */
10
10
 
11
11
  // Public npm libraries
12
- // const axios = require('axios')
12
+ // import axios from 'axios'
13
13
 
14
14
  // Local libraries.
15
- const Address = require('./address')
15
+ import Address from './address.js'
16
16
 
17
- // const BigNumber = require('bignumber.js')
18
- const slpMdm = require('slp-mdm')
17
+ // import BigNumber from 'bignumber.js'
18
+ import slpMdm from 'slp-mdm'
19
+ import TransactionBuilder from '../transaction-builder.js'
19
20
 
20
21
  // let _this
21
22
  // const addy = new Address()
22
23
  let addy
23
- const TransactionBuilder = require('../transaction-builder')
24
24
 
25
25
  class Nft1 {
26
26
  constructor (config) {
@@ -421,4 +421,4 @@ class Nft1 {
421
421
  }
422
422
  }
423
423
 
424
- module.exports = Nft1
424
+ export default Nft1
package/src/slp/slp.js CHANGED
@@ -7,34 +7,23 @@
7
7
 
8
8
  // imports
9
9
  // require deps
10
- // const BCHJS = require("../bch-js")
11
- const Address = require('./address')
12
- const ECPair = require('./ecpair')
13
- // const HDNode = require("./hdnode")
14
- const TokenType1 = require('./tokentype1')
15
- const NFT1 = require('./nft1')
16
- const Utils = require('./utils')
10
+ // import BCHJS from "../bch-js.js"
11
+ import Address from './address.js'
12
+ import ECPair from './ecpair.js'
13
+ // import HDNode from "./hdnode.js"
14
+ import TokenType1 from './tokentype1.js'
15
+ import NFT1 from './nft1.js'
16
+ import Utils from './utils.js'
17
17
 
18
18
  // SLP is a superset of BITBOX
19
19
  class SLP {
20
20
  constructor (config) {
21
21
  this.restURL = config.restURL
22
- this.apiToken = config.apiToken
23
22
  this.authToken = config.authToken
24
23
 
25
- if (this.authToken) {
26
- // Add Basic Authentication token to the authorization header.
27
- this.axiosOptions = {
28
- headers: {
29
- authorization: this.authToken
30
- }
31
- }
32
- } else {
33
- // Add JWT token to the authorization header.
34
- this.axiosOptions = {
35
- headers: {
36
- authorization: `Token ${this.apiToken}`
37
- }
24
+ this.axiosOptions = {
25
+ headers: {
26
+ authorization: this.authToken
38
27
  }
39
28
  }
40
29
 
@@ -46,4 +35,4 @@ class SLP {
46
35
  }
47
36
  }
48
37
 
49
- module.exports = SLP
38
+ export default SLP
@@ -2,41 +2,30 @@
2
2
  This library handles the OP_RETURN of SLP TokenType1 transactions.
3
3
  */
4
4
 
5
- // const BCHJS = require("../bch-js")
5
+ // import BCHJS from "../bch-js.js"
6
6
  // const bchjs = new BCHJS()
7
7
 
8
- const Address = require('./address')
9
- const Script = require('../script')
8
+ import Address from './address.js'
9
+ import Script from '../script.js'
10
10
 
11
- const BigNumber = require('bignumber.js')
12
- const slpMdm = require('slp-mdm')
13
- const axios = require('axios')
11
+ import BigNumber from 'bignumber.js'
12
+ import slpMdm from 'slp-mdm'
13
+ import axios from 'axios'
14
+ import TransactionBuilder from '../transaction-builder.js'
14
15
 
15
16
  // const addy = new Address()
16
17
  let addy
17
- const TransactionBuilder = require('../transaction-builder')
18
18
 
19
19
  let _this // local global
20
20
 
21
21
  class TokenType1 {
22
22
  constructor (config) {
23
23
  this.restURL = config.restURL
24
- this.apiToken = config.apiToken
25
24
  this.authToken = config.authToken
26
25
 
27
- if (this.authToken) {
28
- // Add Basic Authentication token to the authorization header.
29
- this.axiosOptions = {
30
- headers: {
31
- authorization: this.authToken
32
- }
33
- }
34
- } else {
35
- // Add JWT token to the authorization header.
36
- this.axiosOptions = {
37
- headers: {
38
- authorization: `Token ${this.apiToken}`
39
- }
26
+ this.axiosOptions = {
27
+ headers: {
28
+ authorization: this.authToken
40
29
  }
41
30
  }
42
31
 
@@ -483,4 +472,4 @@ class TokenType1 {
483
472
  }
484
473
  }
485
474
 
486
- module.exports = TokenType1
475
+ export default TokenType1
package/src/slp/utils.js CHANGED
@@ -1,35 +1,25 @@
1
1
  /* eslint-disable no-useless-catch */
2
2
 
3
3
  // Public npm libraries
4
- const axios = require('axios')
5
- const slpParser = require('slp-parser')
4
+ import axios from 'axios'
5
+ import slpParser from 'slp-parser'
6
6
 
7
7
  // Local libraries
8
- const Util = require('../util')
8
+ import Util from '../util.js'
9
9
 
10
10
  let _this
11
11
 
12
12
  class Utils {
13
13
  constructor (config = {}) {
14
14
  this.restURL = config.restURL
15
- this.apiToken = config.apiToken
16
15
  this.slpParser = slpParser
17
16
  this.authToken = config.authToken
18
- this.axios = axios
17
+ // Use the shared axios instance if provided, otherwise fall back to axios
18
+ this.axios = config.axios || axios
19
19
 
20
- if (this.authToken) {
21
- // Add Basic Authentication token to the authorization header.
22
- this.axiosOptions = {
23
- headers: {
24
- authorization: this.authToken
25
- }
26
- }
27
- } else {
28
- // Add JWT token to the authorization header.
29
- this.axiosOptions = {
30
- headers: {
31
- authorization: `Token ${this.apiToken}`
32
- }
20
+ this.axiosOptions = {
21
+ headers: {
22
+ authorization: this.authToken
33
23
  }
34
24
  }
35
25
 
@@ -184,4 +174,4 @@ class Utils {
184
174
  }
185
175
  }
186
176
 
187
- module.exports = Utils
177
+ export default Utils
@@ -1,7 +1,7 @@
1
- const Bitcoin = require('@psf/bitcoincashjs-lib')
2
- const coininfo = require('@psf/coininfo')
3
- const bip66 = require('bip66')
4
- const bip68 = require('bc-bip68')
1
+ import Bitcoin from '@psf/bitcoincashjs-lib'
2
+ import coininfo from '@psf/coininfo'
3
+ import bip66 from 'bip66'
4
+ import bip68 from 'bc-bip68'
5
5
 
6
6
  class TransactionBuilder {
7
7
  static setAddress (address) {
@@ -163,4 +163,4 @@ class TransactionBuilder {
163
163
  }
164
164
  }
165
165
 
166
- module.exports = TransactionBuilder
166
+ export default TransactionBuilder
@@ -6,10 +6,10 @@
6
6
  // const BigNumber = require('bignumber.js')
7
7
 
8
8
  // Local libraries
9
- const RawTransaction = require('./raw-transactions')
10
- const SlpUtils = require('./slp/utils')
11
- const Blockchain = require('./blockchain')
12
- const PsfSlpIndexer = require('./psf-slp-indexer')
9
+ import RawTransaction from './raw-transactions.js'
10
+ import SlpUtils from './slp/utils.js'
11
+ import Blockchain from './blockchain.js'
12
+ import PsfSlpIndexer from './psf-slp-indexer.js'
13
13
 
14
14
  class Transaction {
15
15
  constructor (config = {}) {
@@ -77,4 +77,4 @@ class Transaction {
77
77
  }
78
78
  }
79
79
 
80
- module.exports = Transaction
80
+ export default Transaction
package/src/util.js CHANGED
@@ -1,30 +1,17 @@
1
- const axios = require('axios')
1
+ // import axios from 'axios'
2
2
 
3
3
  // let _this
4
4
 
5
5
  class Util {
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
-
27
- // _this = this
28
15
  }
29
16
 
30
17
  /**
@@ -223,86 +210,6 @@ class Util {
223
210
  sleep (ms) {
224
211
  return new Promise(resolve => setTimeout(resolve, ms))
225
212
  }
226
-
227
- /**
228
- * @api Util.validateAddress() validateAddress()
229
- * @apiName Validate Address.
230
- * @apiGroup Util
231
- * @apiDescription Return information about the given bitcoin address.
232
- *
233
- * @apiExample Example usage:
234
- * (async () => {
235
- * try {
236
- * let validateAddress = await bchjs.Util.validateAddress("bitcoincash:qzc86hrdufhcwlyzk7k82x77kfs2myekn57nv9cw5f");
237
- * console.log(validateAddress);
238
- * } catch(error) {
239
- * console.error(error)
240
- * }
241
- * })()
242
- *
243
- * // { isvalid: true,
244
- * // address: '17fshh33qUze2yifiJ2sXgijSMzJ2KNEwu',
245
- * // scriptPubKey: '76a914492ae280d70af33acf0ae7cd329b961e65e9cbd888ac',
246
- * // ismine: true,
247
- * // iswatchonly: false,
248
- * // isscript: false,
249
- * // pubkey: '0312eeb9ae5f14c3cf43cece11134af860c2ef7d775060e3a578ceec888acada31',
250
- * // iscompressed: true,
251
- * // account: 'Test' }
252
- *
253
- * (async () => {
254
- * try {
255
- * let validateAddress = await bchjs.Util.validateAddress(["bitcoincash:qzc86hrdufhcwlyzk7k82x77kfs2myekn57nv9cw5f"]);
256
- * console.log(validateAddress);
257
- * } catch(error) {
258
- * console.error(error)
259
- * }
260
- * })()
261
- *
262
- * // [{ isvalid: true,
263
- * // address: '17fshh33qUze2yifiJ2sXgijSMzJ2KNEwu',
264
- * // scriptPubKey: '76a914492ae280d70af33acf0ae7cd329b961e65e9cbd888ac',
265
- * // ismine: true,
266
- * // iswatchonly: false,
267
- * // isscript: false,
268
- * // pubkey: '0312eeb9ae5f14c3cf43cece11134af860c2ef7d775060e3a578ceec888acada31',
269
- * // iscompressed: true,
270
- * // account: 'Test' }]
271
- */
272
- async validateAddress (address) {
273
- try {
274
- // Single block
275
- if (typeof address === 'string') {
276
- const response = await axios.get(
277
- `${this.restURL}util/validateAddress/${address}`,
278
- this.axiosOptions
279
- )
280
- return response.data
281
-
282
- // Array of blocks.
283
- } else if (Array.isArray(address)) {
284
- const options1 = {
285
- method: 'POST',
286
- url: `${this.restURL}util/validateAddress`,
287
- data: {
288
- addresses: address
289
- }
290
- // headers: {
291
- // authorization: `Token ${this.apiToken}`
292
- // }
293
- }
294
- const options = Object.assign({}, options1, this.axiosOptions)
295
- const response = await axios(options)
296
-
297
- return response.data
298
- }
299
-
300
- throw new Error('Input must be a string or array of strings.')
301
- } catch (error) {
302
- if (error.response && error.response.data) throw error.response.data
303
- else throw error
304
- }
305
- }
306
213
  }
307
214
 
308
- module.exports = Util
215
+ export default Util
package/src/utxo.js CHANGED
@@ -6,11 +6,11 @@
6
6
  */
7
7
 
8
8
  // Local libraries
9
- const Electrumx = require('./electrumx')
10
- const Slp = require('./slp/slp')
11
- const PsfSlpIndexer = require('./psf-slp-indexer')
12
- const BigNumber = require('bignumber.js')
13
- const Blockchain = require('./blockchain')
9
+ import Electrumx from './electrumx.js'
10
+ import Slp from './slp/slp.js'
11
+ import PsfSlpIndexer from './psf-slp-indexer.js'
12
+ import BigNumber from 'bignumber.js'
13
+ import Blockchain from './blockchain.js'
14
14
 
15
15
  class UTXO {
16
16
  constructor (config = {}) {
@@ -420,4 +420,4 @@ class UTXO {
420
420
  }
421
421
  }
422
422
 
423
- module.exports = UTXO
423
+ export default UTXO
@@ -2,10 +2,11 @@
2
2
  A Mocha test file for running end-to-end (e2e) tests.
3
3
  */
4
4
 
5
- // const mocha = require("mocha")
6
- const assert = require('chai').assert
5
+ // import mocha from "mocha"
6
+ import chai from 'chai'
7
7
 
8
- const sendToken = require('./send-token/send-token')
8
+ import sendToken from './send-token/send-token.js'
9
+ const { assert } = chai
9
10
 
10
11
  describe('#end-to-end tests', () => {
11
12
  describe('#send-tokens', () => {
@@ -3,12 +3,18 @@
3
3
  IPFS is working.
4
4
  */
5
5
 
6
- process.env.IPFS_API = 'http://localhost:5001'
6
+ import { fileURLToPath } from 'url'
7
+ import { dirname } from 'path'
7
8
  // process.env.IPFS_API = `https://ipfs-api.fullstack.cash`
8
9
 
9
- const BCHJS = require('../../../src/bch-js')
10
+ import BCHJS from '../../../src/bch-js.js'
11
+
12
+ process.env.IPFS_API = 'http://localhost:5001'
10
13
  const bchjs = new BCHJS()
11
14
 
15
+ const __filename = fileURLToPath(import.meta.url)
16
+ const __dirname = dirname(__filename)
17
+
12
18
  describe('#IPFS', () => {
13
19
  it('should upload a file to the server', async () => {
14
20
  const path = `${__dirname.toString()}/ipfs-e2e.js`
@@ -12,13 +12,14 @@
12
12
  mocha --timeout=30000 anonymous-rate-limits.js
13
13
  */
14
14
 
15
- const assert = require('chai').assert
15
+ import chai from 'chai'
16
+ // const RESTURL = `http://localhost:3000/v5/`
17
+
18
+ import BCHJS from '../../../src/bch-js.js'
19
+ const { assert } = chai
16
20
 
17
21
  // const RESTURL = `https://abc.fullstack.cash/v5/`
18
22
  const RESTURL = 'https://bchn.fullstack.cash/v5/'
19
- // const RESTURL = `http://localhost:3000/v5/`
20
-
21
- const BCHJS = require('../../../src/bch-js')
22
23
  const bchjs = new BCHJS({ restURL: RESTURL })
23
24
 
24
25
  describe('#anonymous rate limits', () => {
@@ -7,11 +7,12 @@
7
7
  - Update the PRO_PASS value with a current PRO_PASSES string used by bch-api.
8
8
  */
9
9
 
10
- const assert = require('chai').assert
10
+ import chai from 'chai'
11
11
 
12
- const PRO_PASS = 'testpassword'
12
+ import BCHJS from '../../../src/bch-js.js'
13
+ const { assert } = chai
13
14
 
14
- const BCHJS = require('../../../src/bch-js')
15
+ const PRO_PASS = 'testpassword'
15
16
  const bchjs = new BCHJS({
16
17
  // restURL: `https://bchn.fullstack.cash/v5/`,
17
18
  restURL: 'https://abc.fullstack.cash/v5/',
@@ -11,12 +11,13 @@
11
11
  - Update the JWT_TOKEN value with a current free-level JWT token.
12
12
  */
13
13
 
14
- const assert = require('chai').assert
14
+ import chai from 'chai'
15
+
16
+ import BCHJS from '../../../src/bch-js.js'
17
+ const { assert } = chai
15
18
 
16
19
  const JWT_TOKEN =
17
20
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2YyMDIyMWMxMDAxMmFkOTQwMSIsImVtYWlsIjoiZGVtb0BkZW1vLmNvbSIsImFwaUxldmVsIjoxMCwicmF0ZUxpbWl0IjozLCJpYXQiOjE2MDQ4NTQ2OTEsImV4cCI6MTYwNzQ0NjY5MX0.iwse0z0KDKHx9graCxcOwj6lSlfKQAb1zLhmjvygvts'
18
-
19
- const BCHJS = require('../../../src/bch-js')
20
21
  const bchjs = new BCHJS({
21
22
  restURL: 'https://api.fullstack.cash/v5/',
22
23
  // restURL: `http://localhost:3000/v5/`,
@@ -11,12 +11,13 @@
11
11
  - Update the JWT_TOKEN value with a paid tier JWT token.
12
12
  */
13
13
 
14
- const assert = require('chai').assert
14
+ import chai from 'chai'
15
+
16
+ import BCHJS from '../../../src/bch-js.js'
17
+ const { assert } = chai
15
18
 
16
19
  const JWT_TOKEN =
17
20
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M'
18
-
19
- const BCHJS = require('../../../src/bch-js')
20
21
  const bchjs = new BCHJS({
21
22
  // restURL: `https://bchn.fullstack.cash/v5/`,
22
23
  restURL: 'https:/abc.fullstack.cash/v5/',
@@ -7,12 +7,13 @@
7
7
  - Update the JWT_TOKEN value with a current indexer-level JWT token.
8
8
  */
9
9
 
10
- const assert = require('chai').assert
10
+ import chai from 'chai'
11
+
12
+ import BCHJS from '../../../src/bch-js.js'
13
+ const { assert } = chai
11
14
 
12
15
  const JWT_TOKEN =
13
16
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlODhhY2JmMDIyMWMxMDAxMmFkOTNmZiIsImVtYWlsIjoiY2hyaXMudHJvdXRuZXJAZ21haWwuY29tIiwiYXBpTGV2ZWwiOjQwLCJyYXRlTGltaXQiOjMsImlhdCI6MTYwMzIyNzEwNCwiZXhwIjoxNjA1ODE5MTA0fQ.CV36grzdD36Ht3BwZGHG4XU40CVDzMRw9Ars1x1r27M'
14
-
15
- const BCHJS = require('../../../src/bch-js')
16
17
  const bchjs = new BCHJS({
17
18
  // restURL: `https://bchn.fullstack.cash/v5/`,
18
19
  restURL: 'https://abc.fullstack.cash/v5/',
@@ -18,26 +18,33 @@ const RECV_ADDR2 = 'bchtest:qz6yw0kqgfkknfy6jh2jvlfnkzmre3lt2u0pgcckdk'
18
18
  const SATOSHIS_TO_SEND = 1000
19
19
 
20
20
  // Instantiate BITBOX.
21
- const bitboxLib = '../../../lib/BITBOX'
22
- const BITBOXSDK = require(bitboxLib)
23
- const BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' })
24
- // const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" })
25
-
26
- // const util = require('util')
21
+ // Note: Dynamic require with variable - use dynamic import in ESM
22
+ const bitboxLib = '../../../lib/BITBOX.js'
23
+ let BITBOXSDK, BITBOX, walletInfo
27
24
 
28
25
  // Open the wallet generated with create-wallet.
29
- let walletInfo = {}
30
- try {
31
- walletInfo = require('./wallet.json')
32
- } catch (err) {
33
- console.log(
34
- 'Could not open wallet.json. Generate a wallet with create-wallet first.'
35
- )
36
- process.exit(0)
37
- }
26
+ let SEND_ADDR, SEND_MNEMONIC
27
+
28
+ // Load dependencies asynchronously
29
+ async function loadDependencies () {
30
+ BITBOXSDK = (await import(bitboxLib)).default
31
+ BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' })
32
+ // const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" })
38
33
 
39
- const SEND_ADDR = walletInfo.cashAddress
40
- const SEND_MNEMONIC = walletInfo.mnemonic
34
+ try {
35
+ const { createRequire } = await import('module')
36
+ const require = createRequire(import.meta.url)
37
+ walletInfo = require('./wallet.json')
38
+ } catch (err) {
39
+ console.log(
40
+ 'Could not open wallet.json. Generate a wallet with create-wallet first.'
41
+ )
42
+ process.exit(0)
43
+ }
44
+
45
+ SEND_ADDR = walletInfo.cashAddress
46
+ SEND_MNEMONIC = walletInfo.mnemonic
47
+ }
41
48
 
42
49
  async function testSend () {
43
50
  try {
@@ -57,7 +64,10 @@ async function testSend () {
57
64
  console.log('Error in testSend: ', err)
58
65
  }
59
66
  }
60
- testSend()
67
+ // Load dependencies then run test
68
+ loadDependencies().then(() => {
69
+ testSend()
70
+ })
61
71
 
62
72
  // Build a TX hex with the largest UTXO.
63
73
  async function buildTx1 (recAddr) {
@@ -17,26 +17,33 @@ const RECV_ADDR1 = 'bchtest:qzfn2mly05t6fjsh5kjj0dqq0jjtct27ng089dgg05'
17
17
  const SATOSHIS_TO_SEND = 1000
18
18
 
19
19
  // Instantiate BITBOX.
20
- const bitboxLib = '../../../lib/BITBOX'
21
- const BITBOXSDK = require(bitboxLib)
22
- const BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' })
23
- // const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" })
24
-
25
- // const util = require('util')
20
+ // Note: Dynamic require with variable - use dynamic import in ESM
21
+ const bitboxLib = '../../../lib/BITBOX.js'
22
+ let BITBOXSDK, BITBOX, walletInfo
26
23
 
27
24
  // Open the wallet generated with create-wallet.
28
- let walletInfo = {}
29
- try {
30
- walletInfo = require('./wallet.json')
31
- } catch (err) {
32
- console.log(
33
- 'Could not open wallet.json. Generate a wallet with create-wallet first.'
34
- )
35
- process.exit(0)
36
- }
25
+ let SEND_ADDR, SEND_MNEMONIC
26
+
27
+ // Load dependencies asynchronously
28
+ async function loadDependencies () {
29
+ BITBOXSDK = (await import(bitboxLib)).default
30
+ BITBOX = new BITBOXSDK({ restURL: 'https://trest.bitcoin.com/v2/' })
31
+ // const BITBOX = new BITBOXSDK({ restURL: "http://localhost:3000/v2/" })
37
32
 
38
- const SEND_ADDR = walletInfo.cashAddress
39
- const SEND_MNEMONIC = walletInfo.mnemonic
33
+ try {
34
+ const { createRequire } = await import('module')
35
+ const require = createRequire(import.meta.url)
36
+ walletInfo = require('./wallet.json')
37
+ } catch (err) {
38
+ console.log(
39
+ 'Could not open wallet.json. Generate a wallet with create-wallet first.'
40
+ )
41
+ process.exit(0)
42
+ }
43
+
44
+ SEND_ADDR = walletInfo.cashAddress
45
+ SEND_MNEMONIC = walletInfo.mnemonic
46
+ }
40
47
 
41
48
  async function testSend () {
42
49
  try {
@@ -54,7 +61,10 @@ async function testSend () {
54
61
  console.log('Error in testSend: ', err)
55
62
  }
56
63
  }
57
- testSend()
64
+ // Load dependencies then run test
65
+ loadDependencies().then(() => {
66
+ testSend()
67
+ })
58
68
 
59
69
  // Build a TX hex with the largest UTXO.
60
70
  async function buildTx1 (recAddr) {
@@ -8,7 +8,9 @@
8
8
  */
9
9
 
10
10
  // Inspect utility used for debugging.
11
- const util = require('util')
11
+ import util from 'util'
12
+
13
+ import lib from '../util/e2e-util.js'
12
14
  util.inspect.defaultOptions = {
13
15
  showHidden: true,
14
16
  colors: true,
@@ -21,8 +23,6 @@ util.inspect.defaultOptions = {
21
23
  const WALLET1 = '../wallet1.json'
22
24
  const WALLET2 = '../wallet2.json'
23
25
 
24
- const lib = require('../util/e2e-util')
25
-
26
26
  // The main test function.
27
27
  // Sends a token and reports on how long it takes to show up in SLPDB production.
28
28
  async function sendTokenTest () {
@@ -95,6 +95,6 @@ function sleep (ms) {
95
95
  return new Promise(resolve => setTimeout(resolve, ms))
96
96
  }
97
97
 
98
- module.exports = {
98
+ export default {
99
99
  sendTokenTest
100
100
  }