mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
libs: remove bech32
## Description bech32 is only used in the sdk. I moved Bech32 to the sdk and we can remove it here. Don't think this needs to go into a minor release Closes: #XXX
This commit is contained in:
@@ -25,6 +25,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
|
||||
- [privval] [\#4744](https://github.com/tendermint/tendermint/pull/4744) Remove deprecated `OldFilePV` (@melekes)
|
||||
- [mempool] [\#4759](https://github.com/tendermint/tendermint/pull/4759) Modify `Mempool#InitWAL` to return an error (@melekes)
|
||||
- [types] \#4798 Simplify `VerifyCommitTrusting` func + remove extra validation (@melekes)
|
||||
- [libs] \#4831 Remove `Bech32` pkg from Tendermint. This pkg now lives in the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk/tree/4173ea5ebad906dd9b45325bed69b9c655504867/types/bech32)
|
||||
|
||||
- Blockchain Protocol
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package bech32
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcutil/bech32"
|
||||
)
|
||||
|
||||
//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 "", fmt.Errorf("encoding bech32 failed: %w", err)
|
||||
}
|
||||
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, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
converted, err := bech32.ConvertBits(data, 5, 8, false)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("decoding bech32 failed: %w", err)
|
||||
}
|
||||
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