2023-05-04 08:14:47 +00:00
|
|
|
package cid
|
|
|
|
|
|
|
|
import (
|
2023-05-04 12:16:44 +00:00
|
|
|
"encoding/binary"
|
2023-05-04 08:14:47 +00:00
|
|
|
"github.com/multiformats/go-multibase"
|
|
|
|
)
|
|
|
|
|
2023-05-06 08:38:09 +00:00
|
|
|
func Encode(hash [32]byte, size uint64) (string, error) {
|
2023-05-04 12:16:44 +00:00
|
|
|
sizeBytes := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(sizeBytes, size)
|
|
|
|
|
2023-05-04 08:14:47 +00:00
|
|
|
prefixedHash := append([]byte{0x26, 0x1f}, hash[:]...)
|
2023-05-04 12:16:44 +00:00
|
|
|
prefixedHash = append(prefixedHash, sizeBytes...)
|
2023-05-04 08:14:47 +00:00
|
|
|
|
|
|
|
return multibase.Encode(multibase.Base58BTC, prefixedHash)
|
|
|
|
}
|