npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ensdomains/address-encoder

v1.1.2

Published

Encodes and decodes address formats for various cryptocurrencies

Downloads

119,120

Readme

@ensdomains/address-encoder

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

Installation

bun add @ensdomains/address-encoder

Getting Started

// 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

Hex String Encoding

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

Supported Cryptocurrencies

To view all the supported cryptocurrencies of this library, see here.

Additional Functionality

Async Coder Getter

import { getCoderByCoinNameAsync } from "@ensdomains/address-encoder/async";

const btcCoder = await getCoderByCoinNameAsync("btc");

Individual Coin Imports

import { btc } from "@ensdomains/address-encoder/coins";

const decodedAddress = btc.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = btc.encode(decodedAddress);

Individual Coder Function Imports

import {
  decodeBtcAddress,
  encodeBtcAddress,
} from "@ensdomains/address-encoder/coders";

const decodedAddress = decodeBtcAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = encodeBtcAddress(decodedAddress);

EVM Chains

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.

Contribution Guide

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.