
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@ensdomains/address-encoder
Advanced tools
Encodes and decodes address formats for various cryptocurrencies
This typescript library encodes and decodes address formats for various cryptocurrencies.
Text-format addresses are decoded into their native binary representations, and vice-versa. In the case of Bitcoin-derived chains, this means their scriptPubKey; for Ethereum-derived chains this is their hash.
This library was written for use with EIP 2304, but may be useful for anyone looking for a general purpose cryptocurrency address codec.
EVM compatible chains are either specified using SLIP44 coinType or 0x800000000 | chainId
where 0x800000000 is msb (most significant bit) reserved at SLIP44 and no coin types exist in that range. This is to avoid number colision with th existing coin types.
For example, cointype of ARB1 is 2147441487(0x80000000 | 42161
).
npm install --save @ensdomains/address-encoder
import { formatsByName, formatsByCoinType } from '@ensdomains/address-encoder';
const data = formatsByName['BTC'].decoder('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa');
console.log(data.toString('hex')); // 76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac
const addr = formatsByCoinType[0].encoder(data);
console.log(addr); // 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
This library currently supports the following cryptocurrencies and address formats (ordered alphabetically):
We welcome PRs to add additional chains and address types.
The hardest part of adding new cointype is to find out the address format of each coin. Many coins derived from and share the same attributes as Bitcoin, Ethereum, and other popular blockchains. In that case, adding these coins can be as easy as a few lines of code. However, if the address format is unique and no js libraries available (or existing library file size too big), then you may have to port the encoding/verification from other languages into js by yourself, which could become time-consuming with lots of effort.
In either case, please follow the following guides and best practices.
When we review your pull request, we conduct the following checks.
Please make sure that you include all the reference information so that we don't have to spend hours googling the relevant info which you must have done already.
If there are reusable components, please reuse the function rather than duplicating the similar code.
This library will be used in many mobile wallets where size bloat impacts the performance of the wallet. If your solution simply imports existing libraries, it may
Some specifications simply use base58 encoding without specific checksum. However, if there are any extra address format (such as address prefix or address length) exists, please also add that check so that we can prevent users from adding wrong coin address.
FAQs
Encodes and decodes address formats for various cryptocurrencies
The npm package @ensdomains/address-encoder receives a total of 28,192 weekly downloads. As such, @ensdomains/address-encoder popularity was classified as popular.
We found that @ensdomains/address-encoder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.