@psf/bch-js 6.4.1 → 6.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psf/bch-js",
3
- "version": "6.4.1",
3
+ "version": "6.4.2",
4
4
  "description": "A JavaScript library for working with Bitcoin Cash, eCash, and SLP Tokens",
5
5
  "author": "Chris Troutner <chris.troutner@gmail.com>",
6
6
  "contributors": [
package/src/address.js CHANGED
@@ -133,7 +133,7 @@ class Address {
133
133
  * @api Address.toEcashAddress() toEcashAddress()
134
134
  * @apiName toEcashAddress
135
135
  * @apiGroup Address
136
- * @apiDescription Convert legacy to cashAddress format
136
+ * @apiDescription Convert legacy to eCash (XEC) format
137
137
  *
138
138
  * @apiExample Example usage:
139
139
  * // mainnet
@@ -158,6 +158,35 @@ class Address {
158
158
  return ecashAddress.split(':')[1]
159
159
  }
160
160
 
161
+ /**
162
+ * @api Address.toEtokenAddress() toEtokenAddress()
163
+ * @apiName toEtokenAddress
164
+ * @apiGroup Address
165
+ * @apiDescription Convert legacy to eToken (XEC) format
166
+ *
167
+ * @apiExample Example usage:
168
+ * // mainnet
169
+ * bchjs.Address.toEcashAddress('bitcoincash:qq50d800hgunr8u4trz3uuppspk3mds0dy9978plt2')
170
+ * // ecash:qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da
171
+ *
172
+ * // mainnet no prefix
173
+ * bchjs.Address.toEcashAddress('bitcoincash:qq50d800hgunr8u4trz3uuppspk3mds0dy9978plt2', false)
174
+ * // qq50d800hgunr8u4trz3uuppspk3mds0dyug2v69da
175
+ *
176
+ */
177
+ toEtokenAddress (address, prefix = true) {
178
+ const decoded = this._decode(address)
179
+
180
+ const etokenAddress = cashaddr.encode(
181
+ 'etoken',
182
+ decoded.type,
183
+ decoded.hash
184
+ )
185
+
186
+ if (prefix) return etokenAddress
187
+ return etokenAddress.split(':')[1]
188
+ }
189
+
161
190
  /**
162
191
  * @api Address.ecashtoCashAddress() ecashtoCashAddress()
163
192
  * @apiName ecashtoCashAddress
@@ -935,4 +935,44 @@ describe('#address.js', () => {
935
935
  })
936
936
  })
937
937
  })
938
+
939
+ describe('#toEcashAddress', () => {
940
+ it('should convert a BCH address to an eCash address', () => {
941
+ const cashAddr = 'bitcoincash:qr24z7q6s26d9wr078lr2pxsmxg22cyn9s7yw984vk'
942
+
943
+ const result = bchjs.Address.toEcashAddress(cashAddr)
944
+ // console.log('result: ', result)
945
+
946
+ assert.equal(result, 'ecash:qr24z7q6s26d9wr078lr2pxsmxg22cyn9s8f6wu02p')
947
+ })
948
+
949
+ it('should convert a BCH address to an eCash address without a prefix', () => {
950
+ const cashAddr = 'bitcoincash:qr24z7q6s26d9wr078lr2pxsmxg22cyn9s7yw984vk'
951
+
952
+ const result = bchjs.Address.toEcashAddress(cashAddr, false)
953
+ // console.log('result: ', result)
954
+
955
+ assert.equal(result, 'qr24z7q6s26d9wr078lr2pxsmxg22cyn9s8f6wu02p')
956
+ })
957
+ })
958
+
959
+ describe('#toEtokenAddress', () => {
960
+ it('should convert a BCH address to an eToken address', () => {
961
+ const cashAddr = 'bitcoincash:qr24z7q6s26d9wr078lr2pxsmxg22cyn9s7yw984vk'
962
+
963
+ const result = bchjs.Address.toEtokenAddress(cashAddr)
964
+ // console.log('result: ', result)
965
+
966
+ assert.equal(result, 'etoken:qr24z7q6s26d9wr078lr2pxsmxg22cyn9sfhnv2gwk')
967
+ })
968
+
969
+ it('should convert a BCH address to an eToken address without a prefix', () => {
970
+ const cashAddr = 'bitcoincash:qr24z7q6s26d9wr078lr2pxsmxg22cyn9s7yw984vk'
971
+
972
+ const result = bchjs.Address.toEtokenAddress(cashAddr, false)
973
+ // console.log('result: ', result)
974
+
975
+ assert.equal(result, 'qr24z7q6s26d9wr078lr2pxsmxg22cyn9sfhnv2gwk')
976
+ })
977
+ })
938
978
  })