@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.
- package/LICENSE.md +1 -1
- package/README.md +10 -28
- package/fix-docs-contrast.sh +38 -0
- package/package.json +38 -47
- package/src/address.js +12 -23
- package/src/bch-js.js +81 -48
- package/src/bitcoincash.js +10 -11
- package/src/blockchain.js +57 -68
- package/src/control.js +11 -22
- package/src/crypto.js +3 -3
- package/src/dsproof.js +6 -17
- package/src/ecash.js +1 -1
- package/src/ecpair.js +3 -3
- package/src/electrumx.js +32 -44
- package/src/encryption.js +8 -17
- package/src/generating.js +8 -19
- package/src/hdnode.js +5 -5
- package/src/mining.js +11 -22
- package/src/mnemonic.js +8 -11
- package/src/price.js +7 -108
- package/src/psf-slp-indexer.js +21 -32
- package/src/raw-transactions.js +22 -35
- package/src/schnorr.js +5 -16
- package/src/script.js +4 -2
- package/src/slp/address.js +4 -4
- package/src/slp/ecpair.js +4 -4
- package/src/slp/nft1.js +6 -6
- package/src/slp/slp.js +11 -22
- package/src/slp/tokentype1.js +11 -22
- package/src/slp/utils.js +9 -19
- package/src/transaction-builder.js +5 -5
- package/src/transaction.js +5 -5
- package/src/util.js +5 -98
- package/src/utxo.js +6 -6
- package/test/e2e/bch-js-e2e-tests.js +4 -3
- package/test/e2e/ipfs/ipfs-e2e.js +8 -2
- package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
- package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
- package/test/e2e/rate-limits/free-rate-limits.js +4 -3
- package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
- package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
- package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
- package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
- package/test/e2e/send-token/send-token.js +4 -4
- package/test/e2e/util/e2e-util.js +6 -3
- package/test/e2e/utxo/unsynced-indexer.js +1 -1
- package/test/integration/blockchain.js +5 -5
- package/test/integration/control.js +2 -2
- package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
- package/test/integration/electrumx.js +5 -12
- package/test/integration/price.js +3 -39
- package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
- package/test/integration/rawtransaction.js +39 -5
- package/test/integration/slp.js +147 -5
- package/test/integration/transaction-integration.js +27 -2
- package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
- package/test/unit/address.js +7 -4
- package/test/unit/bitcoin-cash.js +5 -3
- package/test/unit/blockchain.js +23 -22
- package/test/unit/control.js +6 -6
- package/test/unit/crypto.js +5 -3
- package/test/unit/dsproof.js +5 -4
- package/test/unit/ecash.js +3 -2
- package/test/unit/ecpairs.js +6 -4
- package/test/unit/electrumx.js +7 -7
- package/test/unit/encryption.js +6 -5
- package/test/unit/fixtures/bitcore-mock.js +1 -1
- package/test/unit/fixtures/block-mock.js +1 -1
- package/test/unit/fixtures/blockchain-mock.js +1 -1
- package/test/unit/fixtures/dsproof-mock.js +1 -1
- package/test/unit/fixtures/electrumx-mock.js +1 -1
- package/test/unit/fixtures/encryption-mock.js +1 -1
- package/test/unit/fixtures/ipfs-mock.js +1 -1
- package/test/unit/fixtures/openbazaar-mock.js +1 -1
- package/test/unit/fixtures/price-mocks.js +1 -1
- package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
- package/test/unit/fixtures/rawtransaction-mock.js +1 -1
- package/test/unit/fixtures/slp/mock-utils.js +1 -1
- package/test/unit/fixtures/transaction-mock.js +1 -1
- package/test/unit/fixtures/utxo-mocks.js +1 -1
- package/test/unit/generating.js +5 -5
- package/test/unit/hdnode.js +6 -4
- package/test/unit/mining.js +8 -8
- package/test/unit/mnemonic.js +4 -2
- package/test/unit/price.js +5 -14
- package/test/unit/psf-slp-indexer.js +7 -7
- package/test/unit/raw-tranactions.js +14 -13
- package/test/unit/scripts.js +8 -6
- package/test/unit/slp-address.js +6 -4
- package/test/unit/slp-ecpair.js +5 -3
- package/test/unit/slp-nft1.js +7 -6
- package/test/unit/slp-tokentype1.js +7 -6
- package/test/unit/slp-utils.js +8 -7
- package/test/unit/transaction-builder.js +7 -4
- package/test/unit/transaction-unit.js +5 -4
- package/test/unit/util.js +11 -32
- package/test/unit/utxo-unit.js +6 -5
- package/test/unit/x402.js +193 -0
- package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
- package/test/integration/chains/abc/rawtransaction.js +0 -73
- package/test/integration/chains/abc/utxo-integration.js +0 -38
- package/test/integration/chains/bchn/rawtransaction.js +0 -71
- package/test/integration/chains/bchn/slp.js +0 -301
- package/test/integration/chains/bchn/transaction-integration.js +0 -37
- package/test/integration/chains/bchn/util.js +0 -103
- package/test/integration/chains/testnet/blockchain.js +0 -260
- package/test/integration/chains/testnet/control.js +0 -32
- package/test/integration/chains/testnet/electrumx.js +0 -376
- package/test/integration/chains/testnet/rawtransaction.js +0 -296
- package/test/integration/chains/testnet/slp.js +0 -172
- package/test/integration/chains/testnet/test-free-tier.sh +0 -9
- package/test/integration/chains/testnet/util.js +0 -109
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2022 Permissionless Software Foundation contributors
|
|
1
|
+
Copyright 2022-2026 Permissionless Software Foundation contributors
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -5,23 +5,21 @@
|
|
|
5
5
|
[](https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/LICENSE.md)
|
|
6
6
|
[](https://github.com/feross/standard) [](https://gitter.im/Permissionless-Software-Foundation/bch-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
7
7
|
|
|
8
|
-
[bch-js](https://www.npmjs.com/package/@psf/bch-js) is a JavaScript npm library for creating web and mobile apps that can interact with the Bitcoin Cash (BCH)
|
|
8
|
+
[bch-js](https://www.npmjs.com/package/@psf/bch-js) is a JavaScript npm library for creating web and mobile apps that can interact with the Bitcoin Cash (BCH) blockchain. bch-js contains a toolbox of handy tools, and an easy API for talking with [psf-bch-api REST API](https://github.com/Permissionless-Software-Foundation/psf-bch-api). [FullStack.cash](https://fullstack.cash) offers paid cloud access to psf-bch-api. You can run your own infrastructure by following documentation on [CashStack.info](https://cashstack.info).
|
|
9
9
|
|
|
10
10
|
### Quick Start Videos:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
YouTube walk-through videos to help you get started:
|
|
13
13
|
|
|
14
14
|
- [Introduction to bch-js and the bch-js-examples repository](https://youtu.be/GD2i1ZUiyrk)
|
|
15
|
-
- [Working with the FullStack.cash JWT token](https://youtu.be/GD2i1ZUiyrk)
|
|
16
15
|
|
|
17
16
|
### Quick Links
|
|
18
17
|
|
|
19
18
|
- [npm Library](https://www.npmjs.com/package/@psf/bch-js)
|
|
20
19
|
- [Documentation](https://bchjs.fullstack.cash/)
|
|
21
20
|
- [Examples](https://github.com/Permissionless-Software-Foundation/bch-js-examples)
|
|
22
|
-
- [
|
|
21
|
+
- [x402-bch.fullstack.cash](https://x402-bch.fullstack.cash) - The REST API this library talks to by default.
|
|
23
22
|
- [FullStack.cash](https://fullstack.cash) - cloud-based infrastructure for application developers.
|
|
24
|
-
- [FullStack.cash Account](https://fullstack.cash/login) - Get your API key to unlock increased rate limits.
|
|
25
23
|
- [Permissionless Software Foundation](https://psfoundation.cash) - The organization that maintains this library.
|
|
26
24
|
- [CashStack.info](https://cashstack.info) - bch-js is part of the Cash Stack, a JavaScript framework for writing web 2 and web 3 business applications.
|
|
27
25
|
|
|
@@ -31,42 +29,26 @@ Here are two YouTube walk-through videos to help you get started:
|
|
|
31
29
|
|
|
32
30
|
- Instantiate the library in your code:
|
|
33
31
|
|
|
34
|
-
```
|
|
35
|
-
|
|
32
|
+
```javascript
|
|
33
|
+
import BCHJS from "@psf/bch-js"
|
|
36
34
|
let bchjs = new BCHJS() // Defaults to BCHN network.
|
|
37
35
|
```
|
|
38
36
|
|
|
39
37
|
This library is intended to be paired with
|
|
40
|
-
the [bch-api](https://github.com/Permissionless-Software-Foundation/bch-api) REST API, and the infrastructure provided by [FullStack.cash](https://fullstack.cash). The `restURL` property can be changed to work with different Bitcoin Cash networks:
|
|
38
|
+
the [psf-bch-api](https://github.com/Permissionless-Software-Foundation/psf-bch-api) REST API, and the infrastructure provided by [FullStack.cash](https://fullstack.cash). The `restURL` property can be changed to work with different Bitcoin Cash networks:
|
|
41
39
|
|
|
42
|
-
- BCHN Mainnet REST API server: https://
|
|
43
|
-
- ABC Mainnet REST API server: https://abc.fullstack.cash/v5/
|
|
40
|
+
- BCHN Mainnet REST API server: https://x402-bch.fullstack.cash/v7/
|
|
44
41
|
- Check server status: https://metrics.fullstack.cash
|
|
45
42
|
|
|
46
|
-
### API Key (JWT Token)
|
|
47
|
-
|
|
48
|
-
The [bch-api](https://github.com/Permissionless-Software-Foundation/bch-api) REST API hosted by [FullStack.cash](https://fullstack.cash) uses JWT tokens to pay for increased
|
|
49
|
-
rate limits when interacting with the back end server. See [this article](https://cashstack.info) if you want to understand the system-as-a-whole. The JWT token can be fed to bch-js _implicitly_ or _explicitly_.
|
|
50
|
-
|
|
51
|
-
- Implicitly: bch-js will detect your JWT token if you set the `BCHJSTOKEN` environment variable.
|
|
52
|
-
- Explicitly: You can directly feed in the JWT token with the `apiToken` property when instantiating the library. Here is an example:
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
const BCHJS = require("@psf/bch-js")
|
|
56
|
-
let bchjs = new BCHJS({
|
|
57
|
-
restURL: 'https://bchn.fullstack.cash/v5/',
|
|
58
|
-
apiToken: 'eyJhbGciO...' // Your JWT token here.
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
43
|
|
|
62
|
-
###
|
|
44
|
+
### Web Apps
|
|
63
45
|
|
|
64
46
|
[minimal-slp-wallet](https://www.npmjs.com/package/minimal-slp-wallet) is a minimal wallet 'engine' that incorporates bch-js. It's compiled with Browserify for front end apps.
|
|
65
47
|
|
|
66
|
-
[gatsby-theme-bch-wallet](https://github.com/Permissionless-Software-Foundation/gatsby-theme-bch-wallet) is a Gatsby Theme and [bch-wallet-starter](https://github.com/Permissionless-Software-Foundation/bch-wallet-starter) is a Gatsby Starter for building web wallets using minimal-slp-wallet.
|
|
67
|
-
|
|
68
48
|
[This gist](https://gist.github.com/christroutner/6cb9d1b615f3f9363af79723157bc434) shows how to include minimal-slp-wallet into a basic web page without using a framework.
|
|
69
49
|
|
|
50
|
+
[bch-wallet-web3-spa](https://github.com/Permissionless-Software-Foundation/bch-wallet-web3-spa) is a React web app template using bch-js and minimal-slp-wallet.
|
|
51
|
+
|
|
70
52
|
## Features
|
|
71
53
|
|
|
72
54
|
- [ECMAScript 2017 standard JavaScript](https://en.wikipedia.org/wiki/ECMAScript#8th_Edition_-_ECMAScript_2017) used instead of TypeScript. Works
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Script to improve contrast in auto-generated API documentation
|
|
4
|
+
# The code examples in api-doc use grey-on-grey colors that are hard to read.
|
|
5
|
+
# This fixes that issue by improving text contrast for better readability.
|
|
6
|
+
# Run this script *after* running 'npm run docs'
|
|
7
|
+
|
|
8
|
+
FILE="./docs/assets/prism.css"
|
|
9
|
+
|
|
10
|
+
# Check if file exists
|
|
11
|
+
if [ ! -f "$FILE" ]; then
|
|
12
|
+
echo "Error: $FILE not found. Make sure to run 'npm run docs' first."
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
# Create a backup
|
|
17
|
+
#cp "$FILE" "$FILE.bak"
|
|
18
|
+
|
|
19
|
+
# Improve contrast:
|
|
20
|
+
# - Change default text color from #ccc to #e8e8e8 (brighter light gray)
|
|
21
|
+
# - Change comment color from #999 to #b5b5b5 (lighter for better visibility)
|
|
22
|
+
# - Change punctuation color from #ccc to #e8e8e8 (consistent with text)
|
|
23
|
+
|
|
24
|
+
# Replace default text color in code[class*="language-"] and pre[class*="language-"]
|
|
25
|
+
sed -i 's/color: #ccc;/color: #000000;/g' "$FILE"
|
|
26
|
+
|
|
27
|
+
# Replace comment color
|
|
28
|
+
sed -i 's/color: #999;/color: #b5b5b5;/g' "$FILE"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Replace punctuation color (already handled by first sed, but explicit for clarity)
|
|
32
|
+
# The punctuation token also uses #ccc, so the first sed command handles it
|
|
33
|
+
|
|
34
|
+
echo "✓ Improved contrast in prism.css:"
|
|
35
|
+
echo " - Default text: #ccc → #e8e8e8"
|
|
36
|
+
echo " - Comments: #999 → #b5b5b5"
|
|
37
|
+
echo " - Punctuation: #ccc → #e8e8e8"
|
|
38
|
+
|
package/package.json
CHANGED
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psf/bch-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.2",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "A JavaScript library for working with Bitcoin Cash, eCash, and SLP Tokens",
|
|
5
6
|
"author": "Chris Troutner <chris.troutner@gmail.com>",
|
|
6
7
|
"contributors": [
|
|
7
8
|
"Gabriel Cardona <gabriel@bitcoin.com>",
|
|
8
9
|
"Stoyan Zhekov <zh@zhware.net>"
|
|
9
10
|
],
|
|
10
|
-
"main": "src/bch-js",
|
|
11
|
+
"main": "src/bch-js.js",
|
|
11
12
|
"scripts": {
|
|
12
|
-
"test": "
|
|
13
|
-
"test:integration": "npm run test:integration:
|
|
14
|
-
"test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/
|
|
15
|
-
"test:integration:
|
|
16
|
-
"test:integration:
|
|
17
|
-
"test:integration:
|
|
18
|
-
"test:integration:
|
|
19
|
-
"test:integration:
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"test:integration:decatur:abc": "export RESTURL=http://192.168.2.142:3000/v5/ && mocha --timeout 30000 test/integration && mocha --timeout 30000 test/integration/chains/abc/",
|
|
23
|
-
"test:integration:temp:bchn": "export RESTURL=http://157.90.174.219:3000/v5/ && mocha --timeout 30000 test/integration/",
|
|
24
|
-
"test:temp": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 -g '#Encryption' test/integration/",
|
|
25
|
-
"test:temp2": "mocha --timeout=30000 -g '#TransactionLib' test/unit/",
|
|
26
|
-
"test:temp3": "export RESTURL=https://bchn.fullstack.cash/v5/ && mocha --timeout 30000 -g '#DSProof' test/integration/chains/",
|
|
27
|
-
"test:temp4": "export RESTURL=http://localhost:3000/v5/ && mocha --timeout 30000 -g '#decodeOpReturn' test/integration/",
|
|
28
|
-
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
|
29
|
-
"coverage:report": "nyc --reporter=html mocha --timeout 25000 test/unit/",
|
|
30
|
-
"docs": "./node_modules/.bin/apidoc -i src/ -o docs",
|
|
13
|
+
"test": "c8 mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
|
|
14
|
+
"test:integration": "npm run test:integration:local:noauth",
|
|
15
|
+
"test:integration:nft": "export RESTURL=https://bchn.fullstack.cash/v6/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 -g '#nft1' test/integration/slp.js",
|
|
16
|
+
"test:integration:bchn": "export RESTURL=https://bchn.fullstack.cash/v6/ && export IS_USING_FREE_TIER=true && mocha --timeout 30000 test/integration/",
|
|
17
|
+
"test:integration:local:noauth": "export RESTURL=http://localhost:5942/v6/ && mocha --timeout 30000 test/integration/",
|
|
18
|
+
"test:integration:local:auth": "export RESTURL=http://5.78.147.3:5942/v6/ && export BCHJSBEARERTOKEN=temp01 && mocha --timeout 30000 test/integration/",
|
|
19
|
+
"test:integration:decatur": "export RESTURL=http://192.168.2.127:5942/v6/ && mocha --timeout 30000 test/integration/",
|
|
20
|
+
"test:integration:x402": "export RESTURL=http://localhost:5942/v6/ && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 30000 test/integration/",
|
|
21
|
+
"coverage": "nyc --reporter=html mocha --timeout 25000 test/unit/",
|
|
22
|
+
"docs": "./node_modules/.bin/apidoc -i src/ -o docs && ./fix-docs-contrast.sh",
|
|
31
23
|
"lint": "standard --env mocha --fix"
|
|
32
24
|
},
|
|
33
25
|
"license": "MIT",
|
|
@@ -42,45 +34,39 @@
|
|
|
42
34
|
"@psf/bitcoincash-ops": "2.0.0",
|
|
43
35
|
"@psf/bitcoincashjs-lib": "4.0.3",
|
|
44
36
|
"@psf/coininfo": "4.0.0",
|
|
45
|
-
"axios": "1.
|
|
37
|
+
"axios": "1.13.2",
|
|
46
38
|
"bc-bip68": "1.0.5",
|
|
47
|
-
"bchaddrjs-slp": "0.2.
|
|
39
|
+
"bchaddrjs-slp": "0.2.14",
|
|
48
40
|
"bigi": "1.4.2",
|
|
49
|
-
"bignumber.js": "9.
|
|
50
|
-
"bip-schnorr": "0.
|
|
51
|
-
"bip38": "
|
|
52
|
-
"bip39": "3.0
|
|
41
|
+
"bignumber.js": "9.3.1",
|
|
42
|
+
"bip-schnorr": "0.6.7",
|
|
43
|
+
"bip38": "3.1.1",
|
|
44
|
+
"bip39": "3.1.0",
|
|
53
45
|
"bip66": "1.1.5",
|
|
54
|
-
"bitcoinjs-message": "2.
|
|
46
|
+
"bitcoinjs-message": "2.2.0",
|
|
55
47
|
"bs58": "4.0.1",
|
|
56
48
|
"ecashaddrjs": "1.0.7",
|
|
57
|
-
"ini": "
|
|
58
|
-
"randombytes": "2.0
|
|
59
|
-
"safe-buffer": "5.1
|
|
60
|
-
"satoshi-bitcoin": "1.0.
|
|
61
|
-
"slp-mdm": "0.0.
|
|
49
|
+
"ini": "6.0.0",
|
|
50
|
+
"randombytes": "2.1.0",
|
|
51
|
+
"safe-buffer": "5.2.1",
|
|
52
|
+
"satoshi-bitcoin": "1.0.5",
|
|
53
|
+
"slp-mdm": "0.0.7",
|
|
62
54
|
"slp-parser": "0.0.4",
|
|
63
|
-
"wif": "2.0.6"
|
|
55
|
+
"wif": "2.0.6",
|
|
56
|
+
"x402-bch-axios": "1.1.1"
|
|
64
57
|
},
|
|
65
58
|
"devDependencies": {
|
|
66
|
-
"apidoc": "
|
|
67
|
-
"assert": "2.
|
|
59
|
+
"apidoc": "1.2.0",
|
|
60
|
+
"assert": "2.1.0",
|
|
61
|
+
"c8": "10.1.3",
|
|
68
62
|
"chai": "4.1.2",
|
|
69
|
-
"coveralls": "3.0.2",
|
|
70
|
-
"eslint": "7.17.0",
|
|
71
|
-
"eslint-config-prettier": "7.1.0",
|
|
72
|
-
"eslint-config-standard": "16.0.3",
|
|
73
|
-
"eslint-plugin-node": "11.1.0",
|
|
74
|
-
"eslint-plugin-prettier": "3.3.1",
|
|
75
|
-
"eslint-plugin-standard": "4.0.0",
|
|
76
63
|
"husky": "4.3.8",
|
|
77
64
|
"lodash.clonedeep": "4.5.0",
|
|
78
|
-
"mocha": "
|
|
79
|
-
"node-mocks-http": "1.7.0",
|
|
65
|
+
"mocha": "11.7.5",
|
|
80
66
|
"nyc": "15.1.0",
|
|
81
|
-
"semantic-release": "
|
|
67
|
+
"semantic-release": "24.2.9",
|
|
82
68
|
"sinon": "9.2.2",
|
|
83
|
-
"standard": "
|
|
69
|
+
"standard": "17.1.2"
|
|
84
70
|
},
|
|
85
71
|
"apidoc": {
|
|
86
72
|
"title": "bch-js",
|
|
@@ -90,5 +76,10 @@
|
|
|
90
76
|
"hooks": {
|
|
91
77
|
"pre-commit": "npm run lint"
|
|
92
78
|
}
|
|
79
|
+
},
|
|
80
|
+
"standard": {
|
|
81
|
+
"parserOptions": {
|
|
82
|
+
"ecmaVersion": "latest"
|
|
83
|
+
}
|
|
93
84
|
}
|
|
94
85
|
}
|
package/src/address.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// import axios from "axios"
|
|
2
|
+
import Bitcoin from '@psf/bitcoincashjs-lib'
|
|
3
|
+
import cashaddr from 'ecashaddrjs'
|
|
4
|
+
import coininfo from '@psf/coininfo'
|
|
5
5
|
|
|
6
6
|
class Address {
|
|
7
7
|
constructor (config) {
|
|
@@ -10,22 +10,11 @@ class Address {
|
|
|
10
10
|
else tmp.restURL = config.restURL
|
|
11
11
|
|
|
12
12
|
this.restURL = tmp.restURL
|
|
13
|
-
this.apiToken = tmp.apiToken
|
|
14
13
|
this.authToken = config.authToken
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
headers: {
|
|
20
|
-
authorization: this.authToken
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
} else {
|
|
24
|
-
// Add JWT token to the authorization header.
|
|
25
|
-
this.axiosOptions = {
|
|
26
|
-
headers: {
|
|
27
|
-
authorization: `Token ${this.apiToken}`
|
|
28
|
-
}
|
|
15
|
+
this.axiosOptions = {
|
|
16
|
+
headers: {
|
|
17
|
+
authorization: this.authToken
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
20
|
}
|
|
@@ -312,28 +301,28 @@ class Address {
|
|
|
312
301
|
return {
|
|
313
302
|
prefix: 'bitcoincash',
|
|
314
303
|
type: 'P2PKH',
|
|
315
|
-
hash
|
|
304
|
+
hash,
|
|
316
305
|
format: 'legacy'
|
|
317
306
|
}
|
|
318
307
|
case info.main.versions.scripthash:
|
|
319
308
|
return {
|
|
320
309
|
prefix: 'bitcoincash',
|
|
321
310
|
type: 'P2SH',
|
|
322
|
-
hash
|
|
311
|
+
hash,
|
|
323
312
|
format: 'legacy'
|
|
324
313
|
}
|
|
325
314
|
case info.test.versions.public:
|
|
326
315
|
return {
|
|
327
316
|
prefix: 'bchtest',
|
|
328
317
|
type: 'P2PKH',
|
|
329
|
-
hash
|
|
318
|
+
hash,
|
|
330
319
|
format: 'legacy'
|
|
331
320
|
}
|
|
332
321
|
case info.test.versions.scripthash:
|
|
333
322
|
return {
|
|
334
323
|
prefix: 'bchtest',
|
|
335
324
|
type: 'P2SH',
|
|
336
|
-
hash
|
|
325
|
+
hash,
|
|
337
326
|
format: 'legacy'
|
|
338
327
|
}
|
|
339
328
|
default:
|
|
@@ -871,4 +860,4 @@ class Address {
|
|
|
871
860
|
}
|
|
872
861
|
}
|
|
873
862
|
|
|
874
|
-
|
|
863
|
+
export default Address
|
package/src/bch-js.js
CHANGED
|
@@ -7,36 +7,45 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
// bch-api mainnet.
|
|
10
|
-
const DEFAULT_REST_API = 'https://api.fullstack.cash/v5/'
|
|
11
10
|
// const DEFAULT_REST_API = "http://localhost:3000/v5/"
|
|
12
11
|
|
|
12
|
+
// Global npm libraries
|
|
13
|
+
import axios from 'axios'
|
|
14
|
+
import {
|
|
15
|
+
createSigner,
|
|
16
|
+
withPaymentInterceptor,
|
|
17
|
+
createPaymentHeader,
|
|
18
|
+
selectPaymentRequirements
|
|
19
|
+
} from 'x402-bch-axios'
|
|
20
|
+
|
|
13
21
|
// local deps
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
import BitcoinCash from './bitcoincash.js'
|
|
23
|
+
import Crypto from './crypto.js'
|
|
24
|
+
import Util from './util.js'
|
|
25
|
+
import Blockchain from './blockchain.js'
|
|
26
|
+
import Control from './control.js'
|
|
27
|
+
import Generating from './generating.js'
|
|
28
|
+
import Mining from './mining.js'
|
|
29
|
+
import RawTransactions from './raw-transactions.js'
|
|
30
|
+
import Mnemonic from './mnemonic.js'
|
|
31
|
+
import Address from './address.js'
|
|
32
|
+
import HDNode from './hdnode.js'
|
|
33
|
+
import TransactionBuilder from './transaction-builder.js'
|
|
34
|
+
import ECPair from './ecpair.js'
|
|
35
|
+
import Script from './script.js'
|
|
36
|
+
import Price from './price.js'
|
|
37
|
+
import Schnorr from './schnorr.js'
|
|
38
|
+
import SLP from './slp/slp.js'
|
|
39
|
+
import Encryption from './encryption.js'
|
|
40
|
+
import Utxo from './utxo.js'
|
|
41
|
+
import Transaction from './transaction.js'
|
|
42
|
+
import DSProof from './dsproof.js'
|
|
43
|
+
import Ecash from './ecash.js'
|
|
36
44
|
|
|
37
45
|
// Indexers
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
import Electrumx from './electrumx.js'
|
|
47
|
+
import PsfSlpIndexer from './psf-slp-indexer.js'
|
|
48
|
+
const DEFAULT_REST_API = 'https://api.fullstack.cash/v6/'
|
|
40
49
|
|
|
41
50
|
class BCHJS {
|
|
42
51
|
constructor (config) {
|
|
@@ -47,39 +56,55 @@ class BCHJS {
|
|
|
47
56
|
this.restURL = process.env.RESTURL
|
|
48
57
|
} else this.restURL = DEFAULT_REST_API
|
|
49
58
|
|
|
50
|
-
// Retrieve the
|
|
51
|
-
this.
|
|
52
|
-
if (config && config.
|
|
53
|
-
this.
|
|
54
|
-
} else if (process.env.
|
|
55
|
-
this.
|
|
59
|
+
// Retrieve the Bearer token for simple token authentication.
|
|
60
|
+
this.bearerToken = '' // default value.
|
|
61
|
+
if (config && config.bearerToken && config.bearerToken !== '') {
|
|
62
|
+
this.bearerToken = config.bearerToken
|
|
63
|
+
} else if (process.env.BCHJSBEARERTOKEN && process.env.BCHJSBEARERTOKEN !== '') {
|
|
64
|
+
this.bearerToken = process.env.BCHJSBEARERTOKEN
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
//
|
|
59
|
-
this.
|
|
60
|
-
if (
|
|
61
|
-
this.
|
|
62
|
-
} else if (process.env.BCHJSAUTHPASS && process.env.BCHJSAUTHPASS !== '') {
|
|
63
|
-
this.authPass = process.env.BCHJSAUTHPASS
|
|
67
|
+
// Generate the authentication token for the authorization header.
|
|
68
|
+
this.authToken = ''
|
|
69
|
+
if (this.bearerToken) {
|
|
70
|
+
this.authToken = `Bearer ${this.bearerToken}`
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.authToken = `Basic ${base64Credential}`
|
|
73
|
+
// x402 payment configuration
|
|
74
|
+
// If a WIF private key is provided, enable x402 automatic payment handling
|
|
75
|
+
this.wif = ''
|
|
76
|
+
if (config && config.wif && config.wif !== '') {
|
|
77
|
+
this.wif = config.wif
|
|
78
|
+
} else if (process.env.BCHJSWIF && process.env.BCHJSWIF !== '') {
|
|
79
|
+
this.wif = process.env.BCHJSWIF
|
|
74
80
|
}
|
|
81
|
+
this.paymentAmountSats = (config && config.paymentAmountSats) || 2000 * 10
|
|
82
|
+
this.bchServerURL = (config && config.bchServerURL) || 'https://free-bch.fullstack.cash'
|
|
75
83
|
|
|
76
84
|
const libConfig = {
|
|
77
85
|
restURL: this.restURL,
|
|
78
|
-
apiToken: this.apiToken,
|
|
79
86
|
authToken: this.authToken
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
//
|
|
89
|
+
// If WIF is provided, create an axios instance with x402 payment interceptor
|
|
90
|
+
// Otherwise, let sub-modules use their own axios import for backwards compatibility
|
|
91
|
+
if (this.wif) {
|
|
92
|
+
let axiosInstance = axios.create({
|
|
93
|
+
baseURL: this.restURL,
|
|
94
|
+
headers: {
|
|
95
|
+
authorization: this.authToken
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const signer = createSigner(this.wif, this.paymentAmountSats)
|
|
100
|
+
axiosInstance = withPaymentInterceptor(
|
|
101
|
+
axiosInstance,
|
|
102
|
+
signer,
|
|
103
|
+
{ bchServerURL: this.bchServerURL }
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
libConfig.axios = axiosInstance
|
|
107
|
+
}
|
|
83
108
|
|
|
84
109
|
// ElectrumX indexer
|
|
85
110
|
this.Electrumx = new Electrumx(libConfig)
|
|
@@ -117,7 +142,15 @@ class BCHJS {
|
|
|
117
142
|
this.eCash = new Ecash()
|
|
118
143
|
|
|
119
144
|
this.PsfSlpIndexer = new PsfSlpIndexer(libConfig)
|
|
145
|
+
|
|
146
|
+
// Expose x402 helper functions for advanced use cases
|
|
147
|
+
this.x402 = {
|
|
148
|
+
createSigner,
|
|
149
|
+
withPaymentInterceptor,
|
|
150
|
+
createPaymentHeader,
|
|
151
|
+
selectPaymentRequirements
|
|
152
|
+
}
|
|
120
153
|
}
|
|
121
154
|
}
|
|
122
155
|
|
|
123
|
-
|
|
156
|
+
export default BCHJS
|
package/src/bitcoincash.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Buffer = require('safe-buffer').Buffer
|
|
1
|
+
import Bitcoin from '@psf/bitcoincashjs-lib'
|
|
2
|
+
import sb from 'satoshi-bitcoin'
|
|
3
|
+
import bitcoinMessage from 'bitcoinjs-message'
|
|
4
|
+
import bs58 from 'bs58'
|
|
5
|
+
import bip21 from '@psf/bip21'
|
|
6
|
+
import coininfo from '@psf/coininfo'
|
|
7
|
+
import bip38 from 'bip38'
|
|
8
|
+
import wif from 'wif'
|
|
9
|
+
import { Buffer } from 'safe-buffer'
|
|
11
10
|
|
|
12
11
|
class BitcoinCash {
|
|
13
12
|
constructor (address) {
|
|
@@ -519,4 +518,4 @@ class BitcoinCash {
|
|
|
519
518
|
}
|
|
520
519
|
}
|
|
521
520
|
|
|
522
|
-
|
|
521
|
+
export default BitcoinCash
|