Total Complexity | 1 |
Total Lines | 19 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | """Encode module for Swarm.""" |
||
2 | |||
3 | from multiformats import CID, multihash |
||
4 | from content_hash.utils import raw_cid_value |
||
5 | |||
6 | def encode(value): |
||
7 | """ |
||
8 | Encode Swarm. |
||
9 | |||
10 | :param bytes value: a decoded content |
||
11 | |||
12 | :return: the encoded content |
||
13 | :rtype: bytes |
||
14 | """ |
||
15 | |||
16 | mhash = multihash.wrap(bytes.fromhex(value), 'keccak-256') |
||
17 | cid = CID(base='base58btc', codec='swarm-manifest', version=1, digest=mhash) |
||
18 | return raw_cid_value(cid) |
||
19 |