Skip to content

Commit

Permalink
Merge pull request #1 from pfeairheller/feat-codex
Browse files Browse the repository at this point in the history
Remove dependence on Codex from KERIpy
  • Loading branch information
pfeairheller authored Sep 13, 2024
2 parents 78b68be + e702c5f commit 083a6e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 083a6e4

Please sign in to comment.