coincodec

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-coincodec

Tag License GoDoc Build Status codecov.io Go Report

Go utility library to provide movement between string and binary representation of multpile different cryptocurrency coin formats, mainly for ENS.

Table of Contents

Install

go-coincodec is a standard Go module which can be installed with:

go get github.com/hewigovens/go-coincodec

Usage

Example
import (
    "bytes"
    "encoding/hex"
    "errors"

    slip44 "github.com/wealdtech/go-slip44"
    cc "github.com/hewigovens/go-coincodec"
)

func main() {
    bytes, err := cc.ToBytes("0x0102030405060708090A0b0c0d0e0f1011121314", slip44.ETHER)
    if err != nil {
        panic(err)
    }

    str, err := cc.ToString(bytes, slip44.ETHER)
    if err != nil {
        panic(err)
    }

    fmt.Printf("%s\n", str)
}

Maintainers

Jim McDonald: @mcdee Trust Wallet: https://github.com/TrustWallet

Contribute

Contributions welcome. Please check out the issues.

If you are adding a new coin type please try to follow the following rules:

  • use the existing ether.go and ether_test.go as templates
  • ensure you have 100% code coverage with your tests
  • try not to import large amounts of code; consider copying the relevant code rather than bringing in an entire project to use the address conversion functions

License

Apache-2.0 © 2019 Weald Technology Trading Ltd

Documentation

Index

Constants

View Source
const (
	OP_DUP         = 0x76
	OP_HASH160     = 0xa9
	OP_EQUALVERIFY = 0x88
	OP_CHECKSIG    = 0xac
	OP_EQUAL       = 0x87
)

Variables

View Source
var (
	P2PKH_SCRIPT_PREFIX = []byte{OP_DUP, OP_HASH160, btcKeyHashLenght}
	P2SH_SCRIPT_PREFIX  = []byte{OP_HASH160, btcKeyHashLenght}
)

Functions

func BNBDecodeToBytes

func BNBDecodeToBytes(input string) ([]byte, error)

BNBDecodeToBytes converts the input string to a byte array

func BNBEncodeToString

func BNBEncodeToString(bytes []byte) (string, error)

BNBEncodeToString converts the input byte array to a string representation of the BNB address.

func Base58Decode added in v1.0.4

func Base58Decode(b, alphabet string) ([]byte, error)

Base58Decode decodes a modified base58 string to a byte slice and checks checksum.

func Base58Encode added in v1.0.4

func Base58Encode(b []byte, alphabet string) string

Base58Encode encodes a byte slice to a modified base58 string.

func Bech32AddressDecodeToBytes added in v1.0.4

func Bech32AddressDecodeToBytes(hrp string, input string) ([]byte, error)

Bech32AddressDecodeToBytes converts the input string to a byte array

func Bech32AddressEncodeToString added in v1.0.4

func Bech32AddressEncodeToString(hrp string, bytes []byte) (string, error)

Bech32AddressEncodeToString converts the input byte array to a string representation of the bech32 address.

func Bech32DecodeToBytes

func Bech32DecodeToBytes(input string, hrp string) ([]byte, error)

func Bech32EncodeToString

func Bech32EncodeToString(bytes []byte, hrp string) (string, error)

func BitcoinCashDecodeToBytes added in v1.0.3

func BitcoinCashDecodeToBytes(input string) ([]byte, error)

BitcoinCashDecodeToBytes converts the input string to a byte array

func BitcoinCashEncodeToString added in v1.0.3

func BitcoinCashEncodeToString(input []byte) (string, error)

BitcoinCashEncodeToString converts the input byte array to a string representation of the Bitcoin address.

func BitcoinDecodeToBytes

func BitcoinDecodeToBytes(input string) ([]byte, error)

BitcoinDecodeToBytes converts the input string to a byte array

func BitcoinEncodeToString

func BitcoinEncodeToString(input []byte) (string, error)

BitcoinEncodeToString converts the input byte array to a string representation of the Bitcoin address.

func CosmosDecodeToBytes added in v1.0.4

func CosmosDecodeToBytes(input string) ([]byte, error)

CosmosDecodeToBytes converts the input string to a byte array

func CosmosEncodeToString added in v1.0.4

func CosmosEncodeToString(bytes []byte) (string, error)

CosmosEncodeToString converts the input byte array to a string representation of the Cosmos address.

func EtherToBytes

func EtherToBytes(input string) ([]byte, error)

EtherToBytes converts the input string to a byte array.

func EtherToString

func EtherToString(input []byte) (string, error)

EtherToString converts the input byte array to a string representation of the Ethereum address.

func IoTexDecodeToBytes added in v1.0.4

func IoTexDecodeToBytes(input string) ([]byte, error)

IoTexDecodeToBytes converts the input string to a byte array

func IoTexEncodeToString added in v1.0.4

func IoTexEncodeToString(bytes []byte) (string, error)

IoTexEncodeToString converts the input byte array to a string representation of the Cosmos address.

func MakeBitcoinDecodeToBytes added in v1.0.3

func MakeBitcoinDecodeToBytes(config *CoinConfig) func(string) ([]byte, error)

MakeBitcoinDecodeToBytes takes a CoinConfig and returns a func to decode string to bytes

func MakeBitcoinEncodeToString added in v1.0.3

func MakeBitcoinEncodeToString(config *CoinConfig) func([]byte) (string, error)

MakeBitcoinEncodeToString takes a CoinConfig and returns a func to encode bytes to string

func StellarDecodeToBytes added in v1.0.4

func StellarDecodeToBytes(input string) ([]byte, error)

StellarDecodeToBytes converts the input string to a byte array

func StellarEncodeToString added in v1.0.4

func StellarEncodeToString(bytes []byte) (string, error)

StellarEncodeToString converts the input byte array to a string representation of the Cosmos address.

func ToBytes

func ToBytes(input string, coinType uint32) ([]byte, error)

ToBytes converts the input string to a byte array for the given coin type.

func ToString

func ToString(input []byte, coinType uint32) (string, error)

ToString converts the input byte array to a string representation of the given coin type.

func XRPDecodeToBytes added in v1.0.4

func XRPDecodeToBytes(input string) ([]byte, error)

XRPDecodeToBytes converts the input string to a byte array

func XRPEncodeToString added in v1.0.4

func XRPEncodeToString(bytes []byte) (string, error)

XRPEncodeToString converts the input byte array to a string representation of the XRP address.

func ZilliqaDecodeToBytes added in v1.0.4

func ZilliqaDecodeToBytes(input string) ([]byte, error)

ZilliqaDecodeToBytes converts the input string to a byte array

func ZilliqaEncodeToString added in v1.0.4

func ZilliqaEncodeToString(bytes []byte) (string, error)

ZilliqaEncodeToString converts the input byte array to a string representation of the Zilliqa address.

Types

type CoinConfig added in v1.0.3

type CoinConfig struct {
	P2PKHPrefix byte
	P2SHPPrefix byte
	HRP         string
}

CoinConfig for Bitcoin and its forks

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL