mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-30 03:35:34 +00:00
detele everything
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
package bech32
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32
|
||||
func ConvertAndEncode(hrp string, data []byte) (string, error) {
|
||||
converted, err := bech32.ConvertBits(data, 8, 5, true)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "encoding bech32 failed")
|
||||
}
|
||||
return bech32.Encode(hrp, converted)
|
||||
|
||||
}
|
||||
|
||||
//DecodeAndConvert decodes a bech32 encoded string and converts to base64 encoded bytes
|
||||
func DecodeAndConvert(bech string) (string, []byte, error) {
|
||||
hrp, data, err := bech32.Decode(bech)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
}
|
||||
converted, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return "", nil, errors.Wrap(err, "decoding bech32 failed")
|
||||
}
|
||||
return hrp, converted, nil
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package bech32_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
|
||||
"github.com/tendermint/tendermint/libs/bech32"
|
||||
)
|
||||
|
||||
func TestEncodeAndDecode(t *testing.T) {
|
||||
|
||||
sum := sha256.Sum256([]byte("hello world\n"))
|
||||
|
||||
bech, err := bech32.ConvertAndEncode("shasum", sum[:])
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
hrp, data, err := bech32.DecodeAndConvert(bech)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if hrp != "shasum" {
|
||||
t.Error("Invalid hrp")
|
||||
}
|
||||
if !bytes.Equal(data, sum[:]) {
|
||||
t.Error("Invalid decode")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user