feat: add MultihashFromBytes

This commit is contained in:
Derrick Hammer 2024-01-17 11:25:45 -05:00
parent c95a953ca2
commit 5a6c322524
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 0 deletions

View File

@ -41,6 +41,10 @@ func (m *Multihash) HashBytes() []byte {
return m.fullBytes[1:] return m.fullBytes[1:]
} }
func MultihashFromBytes(bytes []byte, kind types.HashType) *Multihash {
return NewMultihash(append([]byte{byte(kind)}, bytes...))
}
func MultihashFromBase64Url(hash string) (*Multihash, error) { func MultihashFromBase64Url(hash string) (*Multihash, error) {
encoder, _ := multibase.EncoderByName("base64url") encoder, _ := multibase.EncoderByName("base64url")
encoding, err := getEncoding(hash) encoding, err := getEncoding(hash)