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
|
|
|
|
2021-01-12 10:48:26 +00:00
|
|
|
type
|
2021-01-14 13:21:07 +00:00
|
|
|
IpfsObject* = object
|
2021-01-12 10:48:26 +00:00
|
|
|
data*: seq[byte]
|
2021-01-12 12:43:23 +00:00
|
|
|
|
2021-01-14 13:21:07 +00:00
|
|
|
proc cid*(obj: IpfsObject): Cid =
|
2021-01-14 12:41:54 +00:00
|
|
|
let codec = multiCodec("dag-pb")
|
2021-01-14 13:21:07 +00:00
|
|
|
let hash = MultiHash.digest("sha2-256", obj.data).get()
|
2021-01-14 12:41:54 +00:00
|
|
|
Cid.init(CIDv0, codec, hash).get()
|