Documentation
¶
Index ¶
- Variables
- func BtcCheckDecode(input string) (result []byte, version byte, err error)
- func BtcCheckEncode(input []byte, version byte) ([]byte, error)
- func CheckDecode(input []byte, version_size, cksum_size int, cksumfunc func([]byte) []byte) (result []byte, version []byte, err error)
- func CheckEncode(input []byte, version []byte, cksum_size int, cksumfunc func([]byte) []byte) ([]byte, error)
- func DcrCheckDecode(input string) (result []byte, version [2]byte, err error)
- func DcrCheckEncode(input []byte, version [2]byte) ([]byte, error)
- func Decode(b []byte) []byte
- func DoubleHashChecksumFunc(hasher hash.Hasher, cksum_size int) func([]byte) []byte
- func Encode(b []byte) ([]byte, error)
- func QitmeerCheckDecode(input string) (result []byte, version [2]byte, err error)
- func QitmeerCheckEncode(input []byte, version []byte) ([]byte, error)
- func SingleHashChecksumFunc(hasher hash.Hasher, cksum_size int) func([]byte) []byte
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrChecksum = errors.New("checksum error")
ErrChecksum indicates that the checksum of a check-encoded string does not verify against the checksum.
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 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/qng/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/qng/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/qng/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/qng/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 Decode ¶
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/qng/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 Encode ¶
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/qng/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 ¶
QitmeerCheckDecode decodes a string that was encoded with 2 bytes version and verifies the checksum using blake2b-256 hash.
func QitmeerCheckEncode ¶
CheckEncode prepends two version bytes and appends a four byte checksum.
Types ¶
This section is empty.