nim-dagger/ipfs/ipfsobject.nim

15 lines
307 B
Nim
Raw Normal View History

2021-02-01 10:11:30 +00:00
import pkg/libp2p/multihash
import pkg/libp2p/multicodec
import pkg/libp2p/cid
export cid
2021-01-12 12:43:23 +00:00
type
IpfsObject* = object
data*: seq[byte]
2021-01-12 12:43:23 +00:00
proc cid*(obj: IpfsObject): Cid =
2021-01-14 12:41:54 +00:00
let codec = multiCodec("dag-pb")
let hash = MultiHash.digest("sha2-256", obj.data).get()
2021-01-14 12:41:54 +00:00
Cid.init(CIDv0, codec, hash).get()