import # std libs atomics, json, tables, sequtils, httpclient, net from strutils import parseHexInt, parseInt import # vendor libs json_serialization, chronicles, libp2p/[multihash, multicodec, cid], stint, web3/[ethtypes, conversions] from nimcrypto import fromHex import # status-desktop libs ./core as status, ../types/[sticker, setting, rpc_response], ./eth/contracts, ./settings, ./edn_helpers proc decodeContentHash*(value: string): string = if value == "": return "" # eg encoded sticker multihash cid: # e30101701220eab9a8ef4eac6c3e5836a3768d8e04935c10c67d9a700436a0e53199e9b64d29 # e3017012205c531b83da9dd91529a4cf8ecd01cb62c399139e6f767e397d2f038b820c139f (testnet) # e3011220c04c617170b1f5725070428c01280b4c19ae9083b7e6d71b7a0d2a1b5ae3ce30 (testnet) # # The first 4 bytes (in hex) represent: # e3 = codec identifier "ipfs-ns" for content-hash # 01 = unused - sometimes this is NOT included (ie ropsten) # 01 = CID version (effectively unused, as we will decode with CIDv0 regardless) # 70 = codec identifier "dag-pb" # ipfs-ns if value[0..1] != "e3": warn "Could not decode sticker. It may still be valid, but requires a different codec to be used", hash=value return "" try: # dag-pb let defaultCodec = parseHexInt("70") #dag-pb var codec = defaultCodec # no codec specified var codecStartIdx = 2 # idx of where codec would start if it was specified # handle the case when starts with 0xe30170 instead of 0xe3010170 if value[2..5] == "0101": codecStartIdx = 6 codec = parseHexInt(value[6..7]) elif value[2..3] == "01" and value[4..5] != "12": codecStartIdx = 4 codec = parseHexInt(value[4..5]) # strip the info we no longer need var multiHashStr = value[codecStartIdx + 2..