From e702c5f05e1186c21149c6ca1f27c4c38094fc77 Mon Sep 17 00:00:00 2001 From: pfeairheller Date: Thu, 12 Sep 2024 17:16:19 -0700 Subject: [PATCH] Remove dependence on Codex from KERIpy --- setup.py | 2 +- src/kerkle/core/helping.py | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 8bd1af4..46fdb64 100644 --- a/setup.py +++ b/setup.py @@ -77,7 +77,7 @@ ], python_requires='>=3.12.2', install_requires=[ - 'keri>=1.2.0-dev10', + 'keri>=1.2.0-rc1', 'lmdb>=1.4.1', 'pysodium>=0.7.17', 'blake3>=0.4.1' diff --git a/src/kerkle/core/helping.py b/src/kerkle/core/helping.py index c8fc202..86a1db7 100644 --- a/src/kerkle/core/helping.py +++ b/src/kerkle/core/helping.py @@ -3,9 +3,12 @@ kerkle.helping module """ +import hashlib +import blake3 from keri import core -from keri.core import coring +from keri.core import MtrDex +from keri.core.coring import Digestage LEAF = b"\x00" NODE = b"\x01" @@ -16,6 +19,18 @@ PLACEHOLDER = bytes(32) DEFAULTVALUE = b"" +Digests = { + MtrDex.Blake3_256: Digestage(klas=blake3.blake3, size=None, length=None), + MtrDex.Blake2b_256: Digestage(klas=hashlib.blake2b, size=32, length=None), + MtrDex.Blake2s_256: Digestage(klas=hashlib.blake2s, size=None, length=None), + MtrDex.SHA3_256: Digestage(klas=hashlib.sha3_256, size=None, length=None), + MtrDex.SHA2_256: Digestage(klas=hashlib.sha256, size=None, length=None), + MtrDex.Blake3_512: Digestage(klas=blake3.blake3, size=None, length=64), + MtrDex.Blake2b_512: Digestage(klas=hashlib.blake2b, size=None, length=None), + MtrDex.SHA3_512: Digestage(klas=hashlib.sha3_512, size=None, length=None), + MtrDex.SHA2_512: Digestage(klas=hashlib.sha512, size=None, length=None), +} + def create_leaf(path, code=core.MtrDex.SHA3_256): value = b"".join([LEAF, path]) @@ -44,12 +59,12 @@ def parse_node(data): def digest(data, code=core.MtrDex.Blake3_256): # we have to create a new instance has hashlib doesn't # have a 'reset' for updates - if code not in core.DigDex or code not in coring.Saider.Digests: + if code not in core.DigDex: raise ValueError("Unsupported digest code = {}.".format(code)) # string now has # correct size - klas, size, length = coring.Saider.Digests[code] + klas, size, length = Digests[code] # sad as 'v' verision string then use its kind otherwise passed in kind ckwa = dict() # class keyword args if size: