diff --git a/cid/cid.go b/cid/cid.go index 111b7a9..a675328 100644 --- a/cid/cid.go +++ b/cid/cid.go @@ -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 {