feat: base helpers

This commit is contained in:
Derrick Hammer 2024-01-03 03:47:16 -05:00
parent ce45d8863f
commit 7f502187e6
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 30 additions and 0 deletions

30
internal/bases/bases.go Normal file
View File

@ -0,0 +1,30 @@
package bases
import "github.com/multiformats/go-multibase"
func ToBase64Url(data []byte) (string, error) {
return ToBase(data, "base64url")
}
func ToBase58BTC(data []byte) (string, error) {
return ToBase(data, "base58btc")
}
func ToBase32(data []byte) (string, error) {
return ToBase(data, "base32")
}
func ToHex(data []byte) (string, error) {
return ToBase(data, "base16")
}
func ToBase(data []byte, base string) (string, error) {
baseEncoder, _ := multibase.EncoderByName(base)
ret, err := multibase.Encode(baseEncoder.Encoding(), data)
if err != nil {
return "", err
}
return ret, nil
}