eCash cashaddr address format support for Node.js and web browsers.
npm install ecashaddrjs
TypeScript implementation for CashAddr address format for eCash (XEC). Also supports Bitcoin Cash (BCH).
Compliant with the original CashAddr specification which improves upon BIP 173.
``bsh`
$ npm install --save ecashaddrjs
See tests for detailed usage. Note that conversion to and from BTC address format is not supported in this library, but is available in ecash-lib.
Examples below.
`javascript
const {
encodeCashAddress,
decodeCashAddress,
isValidCashAddress,
getOutputScriptFromAddress,
} = require('ecashaddrjs');
const bitcoincashAddress =
'bitcoincash:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmuj6vnmhp6';
const { prefix, type, hash } = decodeCashAddress(bitcoincashAddress);
console.log(prefix); // 'bitcoincash'
console.log(type); // 'p2pkh'
console.log(hash); // '7ad1e6c11691269dcf1272ddac04fb5e354aa0df'
console.log(encodeCashAddress('ecash', type, hash));
// 'ecash:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmuthccqd8d'
console.log(isValidCashAddress(bitcoincashAddress)); // true
console.log(isValidCashAddress(bitcoincashAddress), 'bitcoincash'); // true
console.log(isValidCashAddress(bitcoincashAddress), 'ecash'); // false
// getOutputScriptFromAddress
console.log(
getOutputScriptFromAddress(
'ecash:qplkmuz3rx480u6vc4xgc0qxnza42p0e7vll6p90wr',
),
); // 76a9144e532257c01b310b3b5c1fd947c79a72addf852388ac
`
`javascript
import { encodeCashAddress, decodeCashAddress } from 'ecashaddrjs';
// Note that this specific prefix conversion use case is simplified by the Address
// class availabe in ecash-lib
function convertBitcoincashToEcash(bitcoincashAddress) {
const { prefix, type, hash } = decodeCashAddress(bitcoincashAddress);
const ecashAddress = encodeCashAddress('ecash', type, hash);
return ecashAddress;
}
`
#### Change Log
- 1.1.0 - Support decoding prefixless addresses\
- 1.1.1 - Updated README to point to Bitcoin ABC monorepo\
- 1.1.2 - Updated repository field in package.json to Bitcoin ABC monorepo\hash
- 1.1.3 - Support string input and output for \getTypeAndHashFromOutputScript
- 1.2.0 - Support lowercase input and output of address types, support encoding outputScript to address, support getting type and hash from an outputScript with new exported function \toLegacy
- 1.3.0 - Add function to convert cashaddress format to legacy address\isValidCashAddress
- 1.4.0 - Add function to validate cash addresses by prefix\getOutputScriptFromAddress
- 1.4.1-6 - Fix repo README link for npmjs page\
- 1.5.0 - Add function to get outputScript from addressgetTypeAndHashFromOutputScript
- 1.5.1 - Patch to return type in lowercase (how chronik accepts it)encode
- 1.5.2 - Make input of address type case insensitive for , e.g. p2pkh and P2PKH both workisValidCashAddress
- 1.5.3 - Upgraded dependencies
- 1.5.4 - Added unit tests
- 1.5.5 - Skipped due to error in D15400
- 1.5.6 - Add types declaration for easy import by typescript apps
- 1.5.7 - Fix to allow both undefined or explicit false for no prefixes, or a user passed string as prefixBuffer
- 1.5.8 - Upgrading dependencies D16376
- 1.6.0 - Implement typescript D16744
- 1.6.1 - Replace with Uint8Array and stop using webpack to build D17170
- 1.6.2 - Lint to monorepo standards D17183
2.0.0 D17269
- Remove all dependencies
- Remove toLegacy. This is now available in ecash-libchronikReady
- Remove param and always return hash as a hex stringgetOutputScriptFromTypeAndHash`
- Remove support for uppercase address type inputs 'P2PKH' and 'P2SH'
- New function
- Remove validation against accepted prefix types