base58

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: ISC Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrChecksum = errors.New("checksum error")

ErrChecksum indicates that the checksum of a check-encoded string does not verify against the checksum.

View Source
var ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing")

ErrInvalidFormat indicates that the check-encoded string has an invalid format.

Functions

func BitcoinpayCheckDecode

func BitcoinpayCheckDecode(input string) (result []byte, version [2]byte, err error)

BitcoinpayCheckDecode decodes a string that was encoded with 2 bytes version and verifies the checksum using blake2b-256 hash.

func BitcoinpayCheckEncode

func BitcoinpayCheckEncode(input []byte, version []byte) string

CheckEncode prepends two version bytes and appends a four byte checksum.

func BtcCheckDecode

func BtcCheckDecode(input string) (result []byte, version byte, err error)

func BtcCheckEncode

func BtcCheckEncode(input []byte, version byte) string

func CheckDecode

func CheckDecode(input string, version_size, cksum_size int, cksumfunc func([]byte) []byte) (result []byte, version []byte, err error)
Example
package main

import (
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {
	encoded := "1182iP79GRURMp6Rsz9X"
	decoded, version, err := base58.BitcoinpayCheckDecode(encoded)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Show the decoded data.
	fmt.Printf("Decoded data: %x\n", decoded)
	fmt.Println("Version Byte:", version)
}
Output:

Decoded data: 546573742064617461
Version Byte: [0 0]
Example (Ds_addr)
package main

import (
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {
	encoded := "DsaAKsMvZ6HrqhmbhLjV9qVbPkkzF7FnNFY"
	decoded, version, err := base58.BitcoinpayCheckDecode(encoded)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Show the decoded data.
	fmt.Printf("Decoded data: %x\n", decoded)
	fmt.Println("Version Byte:", version)
}
Output:

Decoded data: 64e20eb6075561d30c23a517c5b73badbc120f05
Version Byte: [7 63]

func CheckEncode

func CheckEncode(input []byte, version []byte, cksum_size int, cksumfunc func([]byte) []byte) string
Example
package main

import (
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {
	// Encode example data with the Base58Check encoding scheme.
	data := []byte("Test data")
	var ver [2]byte
	ver[0] = 0
	ver[1] = 0

	encoded := base58.BitcoinpayCheckEncode(data, ver[:])

	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)

}
Output:

Encoded Data: 1182iP79GRURMp6Rsz9X
Example (Addr)
package main

import (
	"encoding/hex"
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {

	data, _ := hex.DecodeString("64e20eb6075561d30c23a517c5b73badbc120f05")
	ver := [2]byte{0x0c, 0x40} //bitcoinpay main
	encoded := base58.BitcoinpayCheckEncode(data, ver[:])
	fmt.Println("Address (sha256) : Nm281BTkccPTDL1CfhAAR27GAzx2bqFLQx5")
	fmt.Println("Address (b2b)    :", encoded)
	encoded = base58.DcrCheckEncode(data, ver)
	fmt.Println("Address (b256)   :", encoded)
}
Output:

Address (sha256) : Nm281BTkccPTDL1CfhAAR27GAzx2bqFLQx5
Address (b2b)    : Nm281BTkccPTDL1CfhAAR27GAzx2bnKjZdM
Address (b256)   : Nm281BTkccPTDL1CfhAAR27GAzx2br4Aebi

func DcrCheckDecode

func DcrCheckDecode(input string) (result []byte, version [2]byte, err error)

func DcrCheckEncode

func DcrCheckEncode(input []byte, version [2]byte) string

func Decode

func Decode(b string) []byte

Decode decodes a modified base58 string to a byte slice.

Example

This example demonstrates how to decode modified base58 encoded data.

package main

import (
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {
	// Decode example modified base58 encoded data.
	encoded := "25JnwSn7XKfNQ"
	decoded := base58.Decode(encoded)

	// Show the decoded data.
	fmt.Println("Decoded Data:", string(decoded))

}
Output:

Decoded Data: Test data

func DoubleHashChecksumFunc

func DoubleHashChecksumFunc(hasher hash.Hasher, cksum_size int) func([]byte) []byte

func Encode

func Encode(b []byte) string

Encode encodes a byte slice to a modified base58 string.

Example

This example demonstrates how to encode data using the modified base58 encoding scheme.

package main

import (
	"fmt"
	"github.com/btceasypay/bitcoinpay/common/encode/base58"
)

func main() {
	// Encode example data with the modified base58 encoding scheme.
	data := []byte("Test data")
	encoded := base58.Encode(data)

	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)

}
Output:

Encoded Data: 25JnwSn7XKfNQ

func SingleHashChecksumFunc

func SingleHashChecksumFunc(hasher hash.Hasher, cksum_size int) func([]byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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