@psf/bch-js 7.0.2 → 7.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "7.0.2",
3
+ "version": "7.1.0",
4
4
  "type": "module",
5
5
  "description": "A JavaScript library for working with Bitcoin Cash, eCash, and SLP Tokens",
6
6
  "author": "Chris Troutner <chris.troutner@gmail.com>",
@@ -10,14 +10,13 @@
10
10
  ],
11
11
  "main": "src/bch-js.js",
12
12
  "scripts": {
13
- "test": "c8 mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
13
+ "test": "export RESTURL=http://localhost:5942/v6 && c8 mocha --trace-warnings --unhandled-rejections=strict --timeout 30000 test/unit/",
14
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
15
  "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/",
16
+ "test:integration:local:noauth": "export RESTURL=http://localhost:5942/v6 && mocha --timeout 30000 test/integration/",
17
+ "test:integration:local:auth": "export RESTURL=http://5.78.147.3:5942/v6 && export BCHJSBEARERTOKEN=temp01 && mocha --timeout 30000 test/integration/",
18
+ "test:integration:decatur": "export RESTURL=http://192.168.2.127:5942/v6 && mocha --timeout 30000 test/integration/",
19
+ "test:integration:x402": "export RESTURL=http://localhost:5942/v6 && export BCHJSWIF=L1eYaneXDDXy8VDig4Arwe8wYHbhtsA5wuQvwsKwhaYeneoZuKG4 && mocha --timeout 30000 test/integration/",
21
20
  "coverage": "nyc --reporter=html mocha --timeout 25000 test/unit/",
22
21
  "docs": "./node_modules/.bin/apidoc -i src/ -o docs && ./fix-docs-contrast.sh",
23
22
  "lint": "standard --env mocha --fix"
@@ -31,7 +30,6 @@
31
30
  "dependencies": {
32
31
  "@chris.troutner/bip32-utils": "1.0.5",
33
32
  "@psf/bip21": "2.0.1",
34
- "@psf/bitcoincash-ops": "2.0.0",
35
33
  "@psf/bitcoincashjs-lib": "4.0.3",
36
34
  "@psf/coininfo": "4.0.0",
37
35
  "axios": "1.13.2",
package/src/bch-js.js CHANGED
@@ -45,7 +45,6 @@ import Ecash from './ecash.js'
45
45
  // Indexers
46
46
  import Electrumx from './electrumx.js'
47
47
  import PsfSlpIndexer from './psf-slp-indexer.js'
48
- const DEFAULT_REST_API = 'https://api.fullstack.cash/v6/'
49
48
 
50
49
  class BCHJS {
51
50
  constructor (config) {
@@ -54,7 +53,16 @@ class BCHJS {
54
53
  this.restURL = config.restURL
55
54
  } else if (process.env.RESTURL && process.env.RESTURL !== '') {
56
55
  this.restURL = process.env.RESTURL
57
- } else this.restURL = DEFAULT_REST_API
56
+ } else {
57
+ throw new Error(
58
+ 'REST API URL is required. Provide config.restURL or set the RESTURL environment variable.'
59
+ )
60
+ }
61
+
62
+ // Normalize restURL to always have a trailing slash
63
+ if (!this.restURL.endsWith('/')) {
64
+ this.restURL = this.restURL + '/'
65
+ }
58
66
 
59
67
  // Retrieve the Bearer token for simple token authentication.
60
68
  this.bearerToken = '' // default value.
package/src/price.js CHANGED
@@ -40,7 +40,7 @@ class Price {
40
40
  async getUsd () {
41
41
  try {
42
42
  const response = await this.axios.get(
43
- `${this.restURL}price/usd`,
43
+ `${this.restURL}price/bchusd`,
44
44
  this.axiosOptions
45
45
  )
46
46
  // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
package/src/script.js CHANGED
@@ -1,7 +1,130 @@
1
1
  import Bitcoin from '@psf/bitcoincashjs-lib'
2
- import { createRequire } from 'module'
3
- const require = createRequire(import.meta.url)
4
- const opcodes = require('@psf/bitcoincash-ops')
2
+
3
+ // Inline opcodes data to avoid fs/import.meta issues in browser builds.
4
+ // This data is from @psf/bitcoincash-ops/index.json
5
+ const opcodes = {
6
+ OP_FALSE: 0,
7
+ OP_0: 0,
8
+ OP_PUSHDATA1: 76,
9
+ OP_PUSHDATA2: 77,
10
+ OP_PUSHDATA4: 78,
11
+ OP_1NEGATE: 79,
12
+ OP_RESERVED: 80,
13
+ OP_TRUE: 81,
14
+ OP_1: 81,
15
+ OP_2: 82,
16
+ OP_3: 83,
17
+ OP_4: 84,
18
+ OP_5: 85,
19
+ OP_6: 86,
20
+ OP_7: 87,
21
+ OP_8: 88,
22
+ OP_9: 89,
23
+ OP_10: 90,
24
+ OP_11: 91,
25
+ OP_12: 92,
26
+ OP_13: 93,
27
+ OP_14: 94,
28
+ OP_15: 95,
29
+ OP_16: 96,
30
+ OP_NOP: 97,
31
+ OP_VER: 98,
32
+ OP_IF: 99,
33
+ OP_NOTIF: 100,
34
+ OP_VERIF: 101,
35
+ OP_VERNOTIF: 102,
36
+ OP_ELSE: 103,
37
+ OP_ENDIF: 104,
38
+ OP_VERIFY: 105,
39
+ OP_RETURN: 106,
40
+ OP_TOALTSTACK: 107,
41
+ OP_FROMALTSTACK: 108,
42
+ OP_2DROP: 109,
43
+ OP_2DUP: 110,
44
+ OP_3DUP: 111,
45
+ OP_2OVER: 112,
46
+ OP_2ROT: 113,
47
+ OP_2SWAP: 114,
48
+ OP_IFDUP: 115,
49
+ OP_DEPTH: 116,
50
+ OP_DROP: 117,
51
+ OP_DUP: 118,
52
+ OP_NIP: 119,
53
+ OP_OVER: 120,
54
+ OP_PICK: 121,
55
+ OP_ROLL: 122,
56
+ OP_ROT: 123,
57
+ OP_SWAP: 124,
58
+ OP_TUCK: 125,
59
+ OP_CAT: 126,
60
+ OP_SPLIT: 127,
61
+ OP_NUM2BIN: 128,
62
+ OP_BIN2NUM: 129,
63
+ OP_SIZE: 130,
64
+ OP_INVERT: 131,
65
+ OP_AND: 132,
66
+ OP_OR: 133,
67
+ OP_XOR: 134,
68
+ OP_EQUAL: 135,
69
+ OP_EQUALVERIFY: 136,
70
+ OP_RESERVED1: 137,
71
+ OP_RESERVED2: 138,
72
+ OP_1ADD: 139,
73
+ OP_1SUB: 140,
74
+ OP_2MUL: 141,
75
+ OP_2DIV: 142,
76
+ OP_NEGATE: 143,
77
+ OP_ABS: 144,
78
+ OP_NOT: 145,
79
+ OP_0NOTEQUAL: 146,
80
+ OP_ADD: 147,
81
+ OP_SUB: 148,
82
+ OP_MUL: 149,
83
+ OP_DIV: 150,
84
+ OP_MOD: 151,
85
+ OP_LSHIFT: 152,
86
+ OP_RSHIFT: 153,
87
+ OP_BOOLAND: 154,
88
+ OP_BOOLOR: 155,
89
+ OP_NUMEQUAL: 156,
90
+ OP_NUMEQUALVERIFY: 157,
91
+ OP_NUMNOTEQUAL: 158,
92
+ OP_LESSTHAN: 159,
93
+ OP_GREATERTHAN: 160,
94
+ OP_LESSTHANOREQUAL: 161,
95
+ OP_GREATERTHANOREQUAL: 162,
96
+ OP_MIN: 163,
97
+ OP_MAX: 164,
98
+ OP_WITHIN: 165,
99
+ OP_RIPEMD160: 166,
100
+ OP_SHA1: 167,
101
+ OP_SHA256: 168,
102
+ OP_HASH160: 169,
103
+ OP_HASH256: 170,
104
+ OP_CODESEPARATOR: 171,
105
+ OP_CHECKSIG: 172,
106
+ OP_CHECKSIGVERIFY: 173,
107
+ OP_CHECKMULTISIG: 174,
108
+ OP_CHECKMULTISIGVERIFY: 175,
109
+ OP_NOP1: 176,
110
+ OP_NOP2: 177,
111
+ OP_CHECKLOCKTIMEVERIFY: 177,
112
+ OP_NOP3: 178,
113
+ OP_CHECKSEQUENCEVERIFY: 178,
114
+ OP_NOP4: 179,
115
+ OP_NOP5: 180,
116
+ OP_NOP6: 181,
117
+ OP_NOP7: 182,
118
+ OP_NOP8: 183,
119
+ OP_NOP9: 184,
120
+ OP_NOP10: 185,
121
+ OP_CHECKDATASIG: 186,
122
+ OP_CHECKDATASIGVERIFY: 187,
123
+ OP_REVERSEBYTES: 188,
124
+ OP_PUBKEYHASH: 253,
125
+ OP_PUBKEY: 254,
126
+ OP_INVALIDOPCODE: 255
127
+ }
5
128
 
6
129
  class Script {
7
130
  constructor () {