Documentation
¶
Index ¶
- Variables
- func BitcoinpayCheckDecode(input string) (result []byte, version [2]byte, err error)
- func BitcoinpayCheckEncode(input []byte, version []byte) string
- func BtcCheckDecode(input string) (result []byte, version byte, err error)
- func BtcCheckEncode(input []byte, version byte) string
- func CheckDecode(input string, 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) string
- func DcrCheckDecode(input string) (result []byte, version [2]byte, err error)
- func DcrCheckEncode(input []byte, version [2]byte) string
- func Decode(b string) []byte
- func DoubleHashChecksumFunc(hasher hash.Hasher, cksum_size int) func([]byte) []byte
- func Encode(b []byte) string
- 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 BitcoinpayCheckDecode ¶
BitcoinpayCheckDecode decodes a string that was encoded with 2 bytes version and verifies the checksum using blake2b-256 hash.
func BitcoinpayCheckEncode ¶
CheckEncode prepends two version bytes and appends a four byte checksum.
func BtcCheckEncode ¶
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 DcrCheckEncode ¶
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/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 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/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
Types ¶
This section is empty.