Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependence on Codex from KERIpy #1

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 18 additions & 3 deletions src/kerkle/core/helping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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])
Expand Down Expand Up @@ -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:
Expand Down
Loading