Skip to content

Commit 5bdf022

Browse files
Merge pull request #1484 from xchainjs/hippo/replace-bcjaddrjs-dependency
Replace bchaddrjs dependency
2 parents 796d5ea + 134bbbd commit 5bdf022

File tree

8 files changed

+528
-43
lines changed

8 files changed

+528
-43
lines changed

.changeset/slick-roses-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@xchainjs/xchain-bitcoincash': patch
3+
---
4+
5+
Remove bchaddr dependency

examples/do-swap/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@xchainjs/xchain-wallet": "workspace:*",
3939
"axios": "1.8.4",
4040
"axios-retry": "^3.3.1",
41-
"bchaddrjs": "^0.5.2",
4241
"bech32-buffer": "^0.2.0",
4342
"bitcoinjs-lib": "^6.1.7",
4443
"dotenv": "^16.0.0",

packages/xchain-bitcoincash/__tests__/utils.test.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Network } from '@xchainjs/xchain-client'
2-
import * as bchaddr from 'bchaddrjs'
3-
2+
import * as bchaddr from '../src/bchaddrjs'
43
import mockHaskoinApi from '../__mocks__/haskoin'
54
import * as Utils from '../src/utils'
65

@@ -14,14 +13,15 @@ describe('Bitcoin Cash Utils Test', () => {
1413

1514
const testnet_address = 'bchtest:qpd7jmj0hltgxux06v9d9u6933vq7zd0kyjlapya0g'
1615
const mainnet_address = 'bitcoincash:qp4kjpk684c3d9qjk5a37vl2xn86wxl0f5j2ru0daj'
16+
const legacy_mainnet = '1Anw7uzLwXxBykMLeKb2BPAyTKsSfVDA8A'
1717

1818
describe('stripPrefix', () => {
1919
it('should strip out the prefix from the testnet address', () => {
2020
const strip_address = Utils.stripPrefix(testnet_address)
2121
expect(strip_address).toEqual('qpd7jmj0hltgxux06v9d9u6933vq7zd0kyjlapya0g')
2222
})
2323

24-
it('should strip out the prefix from the testnet address', () => {
24+
it('should strip out the prefix from the mainnet address', () => {
2525
const strip_address = Utils.stripPrefix(mainnet_address)
2626
expect(strip_address).toEqual('qp4kjpk684c3d9qjk5a37vl2xn86wxl0f5j2ru0daj')
2727
})
@@ -40,4 +40,45 @@ describe('Bitcoin Cash Utils Test', () => {
4040
expect(Utils.toBCHAddressNetwork(Network.Testnet)).toEqual(bchaddr.Network.Testnet)
4141
})
4242
})
43+
44+
describe('toLegacyAddress', () => {
45+
it('converts cashaddr to legacy', () => {
46+
const legacy = Utils.toLegacyAddress(mainnet_address)
47+
expect(legacy).toEqual(legacy_mainnet)
48+
})
49+
})
50+
describe('toCashAddress', () => {
51+
it('converts legacy to cashaddr', () => {
52+
const cashaddr = Utils.toCashAddress(legacy_mainnet)
53+
expect(cashaddr).toEqual(mainnet_address)
54+
})
55+
})
56+
57+
describe('isCashAddress', () => {
58+
it('returns true for a valid cash address', () => {
59+
expect(Utils.isCashAddress(mainnet_address)).toBe(true)
60+
})
61+
62+
it('returns false for a legacy address', () => {
63+
expect(Utils.isCashAddress(legacy_mainnet)).toBe(false)
64+
})
65+
})
66+
67+
describe('validateAddress', () => {
68+
it('returns true for a valid testnet address and testnet network', () => {
69+
expect(Utils.validateAddress(testnet_address, Network.Testnet)).toBe(true)
70+
})
71+
72+
it('returns true for a valid mainnet address and mainnet network', () => {
73+
expect(Utils.validateAddress(mainnet_address, Network.Mainnet)).toBe(true)
74+
})
75+
76+
it('returns false if address network doesn’t match given network', () => {
77+
expect(Utils.validateAddress(mainnet_address, Network.Testnet)).toBe(false)
78+
})
79+
80+
it('throws error for invalid address', () => {
81+
expect(() => Utils.validateAddress('invalid-address', Network.Mainnet)).toThrow()
82+
})
83+
})
4384
})

packages/xchain-bitcoincash/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
"@xchainjs/xchain-util": "workspace:*",
4242
"@xchainjs/xchain-utxo": "workspace:*",
4343
"@xchainjs/xchain-utxo-providers": "workspace:*",
44-
"bchaddrjs": "0.5.2",
4544
"bitcore-lib-cash": "11.0.0",
45+
"bs58check": "^4.0.0",
46+
"cashaddrjs": "^0.4.4",
4647
"coinselect": "3.1.12"
4748
},
4849
"devDependencies": {
4950
"@ledgerhq/hw-transport-node-hid": "^6.28.6",
50-
"@types/bchaddrjs": "0.4.0",
5151
"@types/bitcore-lib-cash": "^8.23.8",
52+
"@types/cashaddrjs": "^0",
5253
"axios": "^1.8.4",
5354
"axios-mock-adapter": "^2.1.0"
5455
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 📦 Note on BCH Address Utilities
2+
3+
This project replaces the original [`bchaddrjs`](https://www.npmjs.com/package/bchaddrjs) [`code`](https://github.com/ealmansi/bchaddrjs) dependency with a direct copy of its source code included in the repository. The decision was made to avoid unnecessary bundle size inflation caused by the original package's inclusion of outdated polyfills. Functionality remains unchanged, and only the delivery method has been optimized for modern environments.

0 commit comments

Comments
 (0)