• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Encodes and decodes address formats for various cryptocurrencies

address-encoder

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

Using NPM

npm install --save @ensdomains/address-encoder

Usage

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

Supported cryptocurrencies

This library currently supports the following cryptocurrencies and address formats (ordered alphabetically):

  • ABBC (base58 + ripemd160-checksum)
  • ADA (base58, no check + crc32-checksum and bech32)
  • AE (base58check)
  • AIB (base58check P2PKH and P2SH)
  • AION (hex)
  • ALGO (checksummed-base32)
  • AR (base64url)
  • ARB1 (checksummed-hex)
  • ARDR
  • ARK (base58check)
  • ATOM (bech32)
  • AVAX (bech32)
  • AVAXC (checksummed-hex)
  • BCD (base58check P2PKH and P2SH, and bech32 segwit)
  • BCH (base58check and cashAddr; decodes to cashAddr)
  • BCN (base58xmr)
  • BDX (base58xmr)
  • BNB (bech32)
  • BPS (base58check P2PKH and P2SH)
  • BSC (checksummed-hex)
  • BSV (base58check)
  • BTC (base58check P2PKH and P2SH, and bech32 segwit)
  • BTG (base58check P2PKH and P2SH, and bech32 segwit)
  • BTM (bech32 segwit)
  • BTS (base58 + ripemd160-checksum)
  • CCA (base58check P2PKH and P2SH)
  • CCXX (base58check P2PKH and P2SH, and bech32 segwit)
  • CELO (checksummed-hex)
  • CKB (bech32)
  • CLO (checksummed-hex)
  • CRO (checksummed-hex)
  • DASH (base58check P2PKH and P2SH)
  • DCR (base58, no check)
  • DGB (base58check P2PKH and P2SH, and bech32 segwit)
  • DIVI (base58check P2PKH and P2SH)
  • DOGE (base58check P2PKH and P2SH)
  • DOT (ss58)
  • EGLD (bech32)
  • ELA (base58)
  • EOS (base58 + ripemd160-checksum)
  • ETC (checksummed-hex)
  • ETH (checksummed-hex)
  • ETN (base58xmr)
  • EWT (checksummed-hex)
  • FIL (base10 + leb128 and base32 + blake2b checksum)
  • FIO (base58 + ripemd160-checksum)
  • FIRO (base58check P2PKH and P2SH)
  • FLOW (hex)
  • FTM (checksummed-hex)
  • GNO (checksummed-hex)
  • GO (checksummed-hex)
  • GRIN (base58check)
  • GRS (base58check P2PKH and P2SH, and bech32 segwit)
  • GXC (base58 + ripemd160-checksum)
  • HBAR
  • HIVE (base58 + ripemd160-checksum)
  • HNS
  • HNT (base58check)
  • ICX
  • IOST (base58, no check)
  • IOTA (iotaBech32)
  • IOTX (bech32)
  • IRIS (bech32)
  • KAVA (bech32)
  • KMD (base58check)
  • KSM (ss58)
  • LCC (base58check P2PKH and P2SH, and bech32 segwit)
  • LRG (base58check P2PKH and P2SH)
  • LSK (hex with suffix)
  • LTC (base58check P2PHK and P2SH, and bech32 segwit)
  • LUNA (bech32)
  • MATIC (checksummed-hex)
  • MONA (base58check P2PKH and P2SH, and bech32 segwit)
  • MRX (base58check)
  • NANO (nano-base32)
  • NAS(base58 + sha3-256-checksum)
  • NEAR
  • NEM(XEM) (base32)
  • NEO (base58check)
  • NMC (base58check)
  • NRG (checksummed-hex)
  • NULS (base58)
  • ONE (bech32)
  • ONT (base58check)
  • OP (checksummed-hex)
  • POA (checksummed-hex)
  • PPC (base58check P2PKH and P2SH)
  • QTUM (base58check)
  • RDD (base58check P2PKH and P2SH)
  • RSK (checksummed-hex)
  • RUNE (bech32)
  • RVN (base58check P2PKH and P2SH)
  • SC (blake2b checksum)
  • SERO (base58, no check)
  • SOL (base58, no check)
  • SRM (base58, no check)
  • STEEM (base58 + ripemd160-checksum)
  • STRAT (base58check P2PKH and P2SH)
  • STRK (keccak256-checksumed-hex)
  • STX (crockford base32 P2PKH and P2SH + ripemd160-checksum)
  • SYS (base58check P2PKH and P2SH, and bech32 segwit)
  • TFUEL (checksummed-hex)
  • THETA (base58check)
  • TOMO (checksummed-hex)
  • TRX (base58check)
  • TT (checksummed-hex)
  • VET (checksummed-hex)
  • VIA (base58check P2PKH and P2SH)
  • VLX (base58, no check)
  • VSYS
  • WAN (checksummed-hex)
  • WAVES (base58)
  • WICC (base58check P2PKH and P2SH)
  • XCH (bech32m)
  • XHV (base58xmr)
  • XLM (ed25519 public key)
  • XMR (base58xmr)
  • XRP (base58check-ripple)
  • Nostr (bech32)
  • XTZ (base58check)
  • XVG (base58check P2PKH and P2SH)
  • ZEC (transparent addresses: base58check P2PKH and P2SH, and Sapling shielded payment addresses: bech32; doesn't support Sprout shielded payment addresses)
  • ZEL (transparent addresses: base58check P2PKH and P2SH, and Sapling shielded payment addresses: bech32; doesn't support Sprout shielded payment addresses)
  • ZEN (base58 check)
  • ZIL (bech32)

Development guide

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.

Reference where the address format is specified.

When we review your pull request, we conduct the following checks.

  • The cointype correctly came from SLIP 44 (unless you add EVM chains). If you don't find your coin in the list, raise PR to add it (example)
  • Check coin address from block explorer and compare that the test addresses are in a similar format
  • Read the reference code to see the pull request matches with the specification.

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.

Reuse existing functions where necessary.

If there are reusable components, please reuse the function rather than duplicating the similar code.

Avoid requiring big encoding/encryption library.

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

Validate address format, not just encode/decode

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.

More Repositories

1

ens

Implementations for ENS core functionality: The registry, registrars, and public resolvers.
JavaScript
1,159
star
2

ens-contracts

The core contracts of the ENS protocol
TypeScript
576
star
3

ens-app

Legacy ENS manager app
JavaScript
223
star
4

ensjs-v2

Javascript bindings for the Ethereum Name Service
JavaScript
206
star
5

subdomain-registrar

A registrar that sells subdomains to users on behalf of their owners
CSS
185
star
6

governance-contracts

Governance contracts for the ENS DAO
JavaScript
160
star
7

offchain-resolver

TypeScript
142
star
8

docs

Main documentation site for the ENS protocol
TypeScript
136
star
9

evmgateway

This repository implements a generic CCIP-Read gateway for fetching state proofs of data on other EVM chains. The intended use is for contracts on L1 to be able to fetch and verify data from contracts on L2 in a read context.
TypeScript
132
star
10

ens-app-v3

The official ENS manager app. Register and manage your ENS names here.
TypeScript
126
star
11

ensjs

ENS javascript library for contract interaction
TypeScript
123
star
12

ensdomains-landing

ENS Homepage V2, the main homepage of the ENS protocol.
TypeScript
105
star
13

ethregistrar

Solidity
92
star
14

thorin

A web3 native design system.
TypeScript
81
star
15

ens-metadata-service

TypeScript
71
star
16

resolvers

A collection of resolvers for ENS domains
JavaScript
69
star
17

dnssec-oracle

A DNSSEC oracle for Ethereum
Solidity
57
star
18

react-ens-address

React Component to resolve ENS names or reverse resolve addresses
JavaScript
57
star
19

ui

UI components and reusable functions
JavaScript
55
star
20

l2gateway-demo

A simple demonstration of a proposed L2 gateway specification
JavaScript
52
star
21

name-wrapper

JavaScript
45
star
22

ens-avatar

ENS Avatar resolver library for both nodejs and browser.
TypeScript
40
star
23

solsha1

Pure-solidity implementation of the SHA1 hash function.
Solidity
39
star
24

ens.domains

JavaScript
31
star
25

reverse-records

JavaScript
27
star
26

dnsprovejs

A tool to convince an Ethereum DNSSEC oracle of the contents of DNS records
TypeScript
25
star
27

buffer

A library for working with mutable byte buffers in Solidity.
Solidity
25
star
28

governance-web-react

JavaScript
23
star
29

governance-docs

Governance documentation for the ENS DAO
22
star
30

offchain-resolver-example

CCIP Offchain ENS Resolver example implementation
TypeScript
21
star
31

dnsregistrar

DNS registrar for ENS
Solidity
21
star
32

ens-manager

JavaScript
19
star
33

ethers-ccip-read

Ethers-rs CCIP-Read Middleware
Rust
19
star
34

media-kit

ens media kit resources
CSS
17
star
35

ens-validation

TypeScript
17
star
36

root

New ENS root contract
JavaScript
16
star
37

op-resolver

JavaScript
15
star
38

ens-twitter-api

TypeScript
14
star
39

ens-avatar-worker

Cloudflare worker that facilitates gasless avatar record updates via the ENS manager app
TypeScript
13
star
40

dnssecoraclejs

TypeScript/JavaScript library for generating DNSSEC proofs for the ENS DNSSEC oracle contract
TypeScript
11
star
41

court

Basic smart contracts for the arbitration processes.
Solidity
11
star
42

docs-v2

The Ethereum Name Service (ENS) is a distributed, open, and extensible naming system based on the Ethereum blockchain. This repository contains documentation, examples, and much more.
HTML
11
star
43

blacklist

Blacklisting tools for ENS
Solidity
10
star
44

optimistic-dnssec

Optimistic Implementation of the DNSSEC Registrar
Solidity
10
star
45

ens-archived-contracts

Collection of compiled ENS smart contracts
Solidity
10
star
46

hackathon-registrar

A simple ENS registrar for Hackathons
Solidity
9
star
47

gas-estimate-worker

Cloudflare worker for estimating registration gas costs with tenderly
TypeScript
9
star
48

name-reservations

Repository for 3-6 character name reservations in .eth.
CSS
9
star
49

enschain

Solidity
9
star
50

frontend-template

Starter web app for web3 developers
TypeScript
8
star
51

offchain-gateway-rs

Offchain CCIP Gateway Resolver implementation in Rust
Rust
7
star
52

learn-docs

Documentation for learning about ENS domains
7
star
53

renewal-widget

ENS Renewal widget displays a popup window if there are any expiring ENS names.
JavaScript
7
star
54

arb-resolver

JavaScript
7
star
55

ensips

ENS Improvement Proposals
TypeScript
7
star
56

hack.ens.domains

JavaScript
7
star
57

k-ens

ENS formally verified
6
star
58

auction

An auction contract for a one-off vickery style auction of 3-6 character names
JavaScript
6
star
59

my-ens-app

HTML
6
star
60

ccip-read-dns-gateway

ENS CCIP-Read DNSSEC Gateway
TypeScript
5
star
61

dnssectool

JavaScript
5
star
62

short-name-claims-app

A webapp for submitting claims for ENS short names (3-6 characters)
TypeScript
5
star
63

blog

Official Ethereum Name Service Blog
TypeScript
5
star
64

hack2018

5
star
65

research

ENS relevant research.
5
star
66

ccip-tools

CCIP Multitool for testing your offchain resolver!
TypeScript
5
star
67

ens-support-docs

ENS Support Docs
CSS
4
star
68

ens-reclaim-deposit-subgraph

TypeScript
4
star
69

hackathon-registrar-app

JavaScript
4
star
70

renewal

JavaScript
4
star
71

ens-print

Micro App for printing ENS stickers
JavaScript
4
star
72

ethlink-request

It fetches newly created subdomain and send request to eth.link to add to the DoH proxy
TypeScript
4
star
73

mock

Module for mocking ENS locally
JavaScript
4
star
74

integrations

List of integrations for ENS
TypeScript
4
star
75

reclaim

TypeScript
3
star
76

moonpay-worker

JavaScript
3
star
77

normalise-refund

JavaScript
3
star
78

test-utils

ENS test utilities
JavaScript
3
star
79

tldclaims

JavaScript
3
star
80

verify-ratification

Code to verify the votes ratifying the ENS constitution
JavaScript
3
star
81

usd-oracle

USD oracle research
3
star
82

batch-gateway

3
star
83

short-name-claims-subgraph

A subgraph for indexing ENS .eth short name claims
TypeScript
3
star
84

migration-scripts

Python
3
star
85

ens-faucet-worker

Cloudflare worker to help distribute testnet ETH to ENS manager app users
TypeScript
3
star
86

ens-bigquery-udf

JavaScript
3
star
87

ens-evmgateway

TypeScript
3
star
88

crypto-addr-serialize

Encode/Decode various cryptocurrency addresses
JavaScript
3
star
89

ens-og-image

TypeScript
2
star
90

enscluster

Config files for the ensdomains Kubernetes clusters
Python
2
star
91

dnssec-oracle-anchors

JavaScript
2
star
92

dao-pm

Project management repository for the ENS DAO
2
star
93

context-resolver

TypeScript
2
star
94

constitution-book-claim

ENS DAO constitution book claim site
TypeScript
2
star
95

ens-avatar-fallback

JavaScript
2
star
96

arbitrum-resolver

JavaScript
1
star
97

pm

an place to hold ENS project issues which cannot be assigned to any existing repos
1
star
98

ens-cfw

TypeScript
1
star
99

rasterize-gcp

ENS NFT Rasterization Service
JavaScript
1
star
100

punycode

Solidity
1
star