
Research
/Security News
Popular Tinycolor npm Package Compromised in Supply Chain Attack Affecting 40+ Packages
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
@ensdomains/address-encoder
Advanced tools
Encodes and decodes address formats for various cryptocurrencies
A cryptocurrency address encoder/decoder in TypeScript
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 0x80000000 | chainId
where 0x80000000 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.
Please read the specification page for the more detail
bun add @ensdomains/address-encoder
// Import coder getter
import { getCoderByCoinName } from "@ensdomains/address-encoder";
// Get the coder for the address you want to encode/decode
const btcCoder = getCoderByCoinName("btc");
// Decode the address
const decodedAddress = btcCoder.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ]
// Encode the address
const encodedAddress = btcCoder.encode(decodedAddress);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
If the data you are encoding is a hex string rather than Uint8Array
, you can use the included hexToBytes()
to convert it to the correct type.
import { getCoderByCoinName } from "@ensdomains/address-encoder";
import { hexToBytes } from "@ensdomains/address-encoder/utils";
const btcCoder = getCoderByCoinName("btc");
// Convert hex encoded data to bytes
const dataAsBytes = hexToBytes(
"0x76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac"
);
// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ]
// Pass bytes to encoder
const encodedAddress = btcCoder.encode(dataAsBytes);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
To view all the supported cryptocurrencies of this library, see here.
import { getCoderByCoinNameAsync } from "@ensdomains/address-encoder/async";
const btcCoder = await getCoderByCoinNameAsync("btc");
import { btc } from "@ensdomains/address-encoder/coins";
const decodedAddress = btc.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = btc.encode(decodedAddress);
import {
decodeBtcAddress,
encodeBtcAddress,
} from "@ensdomains/address-encoder/coders";
const decodedAddress = decodeBtcAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = encodeBtcAddress(decodedAddress);
There are a variety of EVM chains supported, however none of them (except for ETH) are exported from coins
or coders
. If you want to individually import for an EVM chain, you can just use the eth
import as a replacement.
To add a coin to this library, or if you're interested in contributing in any other way, read the contribution guide before submitting a PR.
FAQs
Encodes and decodes address formats for various cryptocurrencies
The npm package @ensdomains/address-encoder receives a total of 27,203 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.
Research
/Security News
Malicious update to @ctrl/tinycolor on npm is part of a supply-chain attack hitting 40+ packages across maintainers
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.