feat: add EncodeString function

This commit is contained in:
Derrick Hammer 2023-05-10 14:17:50 -04:00
parent 8f3af2084c
commit 488f8737c0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package cid
import (
"bytes"
"encoding/binary"
"encoding/hex"
"errors"
"github.com/multiformats/go-multibase"
)
@ -31,6 +32,15 @@ func EncodeFixed(hash [32]byte, size uint64) (string, error) {
return multibase.Encode(multibase.Base58BTC, prefixedHash)
}
func EncodeString(hash string, size uint64) (string, error) {
hashBytes, err := hex.DecodeString(hash)
if err != nil {
return "", err
}
return Encode(hashBytes, size)
}
func Valid(cid string) (bool, error) {
_, err := maybeDecode(cid)
if err != nil {