multihash key gen func
This commit is contained in:
parent
91a1287974
commit
f5f253aa81
19
pkg/shared/functions.go
Normal file
19
pkg/shared/functions.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package shared
|
||||||
|
|
||||||
|
import (
|
||||||
|
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
|
dshelp "github.com/ipfs/go-ipfs-ds-help"
|
||||||
|
"github.com/multiformats/go-multihash"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SSZ_SHA2_256_PREFIX int = 0xb501
|
||||||
|
|
||||||
|
// MultihashKeyFromSSZRoot converts a SSZ-SHA2-256 root hash into a blockstore prefixed multihash key
|
||||||
|
func MultihashKeyFromSSZRoot(root []byte) (string, error) {
|
||||||
|
mh, err := multihash.Encode(root, SSZ_SHA2_256_PREFIX)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
dbKey := dshelp.MultihashToDsKey(mh)
|
||||||
|
return blockstore.BlockPrefix.String() + dbKey.String(), nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user