base58

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: ISC Imports: 6 Imported by: 2

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 BtcCheckDecode

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

func BtcCheckEncode

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

func CheckDecode

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

import (
	"fmt"
	"github.com/Qitmeer/qitmeer/common/encode/base58"
)

func main() {
	encoded := "1182iP79GRURMp6Rsz9X"
	decoded, version, err := base58.QitmeerCheckDecode(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/Qitmeer/qitmeer/common/encode/base58"
)

func main() {
	encoded := "DsaAKsMvZ6HrqhmbhLjV9qVbPkkzF7FnNFY"
	decoded, version, err := base58.QitmeerCheckDecode(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) ([]byte, error)
Example
package main

import (
	"fmt"
	"github.com/Qitmeer/qitmeer/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.QitmeerCheckEncode(data, ver[:])

	// Show the encoded data.
	fmt.Printf("Encoded Data: %s", encoded)

}
Output:

Encoded Data: 1182iP79GRURMp6Rsz9X
Example (Addr)
package main

import (
	"encoding/hex"
	"fmt"
	"github.com/Qitmeer/qitmeer/common/encode/base58"
)

func main() {

	data, _ := hex.DecodeString("64e20eb6075561d30c23a517c5b73badbc120f05")
	ver := [2]byte{0x0c, 0x40} //qitmeer main
	encoded, _ := base58.QitmeerCheckEncode(data, ver[:])
	fmt.Println("Address (sha256) : Nm281BTkccPTDL1CfhAAR27GAzx2bqFLQx5")
	fmt.Printf("Address (b2b)    : %s\n", encoded)
	encoded, _ = base58.DcrCheckEncode(data, ver)
	fmt.Printf("Address (b256)   : %s", 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) ([]byte, error)

func Decode

func Decode(b []byte) []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/Qitmeer/qitmeer/common/encode/base58"
)

func main() {
	// Decode example modified base58 encoded data.
	encoded := []byte("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) ([]byte, error)

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/Qitmeer/qitmeer/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.Printf("Encoded Data: %s\n", encoded)

}
Output:

Encoded Data: 25JnwSn7XKfNQ

func QitmeerCheckDecode

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

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

func QitmeerCheckEncode

func QitmeerCheckEncode(input []byte, version []byte) ([]byte, error)

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

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