mirror of https://github.com/status-im/nim-abc.git
17 lines
342 B
Nim
17 lines
342 B
Nim
|
import std/hashes except Hash
|
||
|
import pkg/nimcrypto
|
||
|
|
||
|
type
|
||
|
Hash* = distinct MDigest[256]
|
||
|
|
||
|
func `==`*(a, b: Hash): bool {.borrow.}
|
||
|
|
||
|
func hash*(bytes: openArray[byte]): Hash =
|
||
|
Hash(sha256.digest(bytes))
|
||
|
|
||
|
func toBytes*(hash: Hash): array[32, byte] =
|
||
|
MDigest[256](hash).data
|
||
|
|
||
|
func hash*(hash: Hash): hashes.Hash =
|
||
|
hashes.hash(hash.toBytes)
|