import std/hashes, std/streams, std/strutils, std/bitops, std/unicode, std/endians import base58/bitcoin, cbor, siphash import ./blobsets/priv/hex import nimcrypto, nimcrypto/blake2 const digestLen* = 32 ## Length of a chunk digest. cidSize* = digestLen ## Size of CID object in memory blobLeafSize* = 1 shl 14 ## Size of blob leaves. blobLeafSizeMask* = not(not(0) shl 14) visualLen = 32 * 3 maxChunkSize* {.deprecated} = blobLeafSize type Blake2b256* = Blake2bContext[256] BlobId* = MDigest[Blake2b256.bits] ## Blob Identifier SetId* = MDigest[Blake2b256.bits] ## Set Identifier Cid* {.deprecated} = BlobId func `$`*(bh: BlobId): string = ## Convert a blob hash to a visual representation. const baseRune = 0x2800 result = newString(visualLen) var pos = 0 for b in bh.data.items: let r = (Rune)baseRune or b.int fastToUTF8Copy(r, result, pos, true) func toBlobId*(s: string): BlobId = ## Parse a visual blob hash to binary. if s.len == visualLen: var pos: int r: Rune for b in result.data.mitems: fastRuneAt(s, pos, r, true) b = r.byte proc `==`*(x, y: BlobId): bool = x.data == y.data ## Compare two BlobIds. proc `==`*(cbor: CborNode; cid: BlobId): bool = ## Compare a CBOR node with a BlobId. if cbor.kind == cborBytes: for i in 0..