Skip to content

Commit 5e98182

Browse files
author
Mark A. Greenslade
committed
1. New how-to. 2. Version bump.
1 parent 58b2318 commit 5e98182

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ How To: Create Key Pairs ?
7171

7272
See [here](how_tos/how_to_create_key_pairs.py).
7373

74+
How To: Apply a checksum ?
75+
------------------------------------------------------
76+
77+
See [here](how_tos/how_to_apply_a_checksum.py).
78+
7479
How To: Run unit tests against an NCTL network ?
7580
------------------------------------------------------
7681

how_tos/how_to_apply_a_checksum.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import argparse
2+
import typing
3+
4+
import pycspr
5+
from pycspr.crypto import HashAlgorithm
6+
from pycspr.crypto import KeyAlgorithm
7+
8+
9+
# CLI argument parser.
10+
_ARGS = argparse.ArgumentParser("Demo illustrating how to obtain a checksummed account key using pycspr.")
11+
12+
13+
def _main(args: argparse.Namespace):
14+
"""Main entry point.
15+
16+
:param args: Parsed command line arguments.
17+
18+
"""
19+
# Create new key pair & destructure raw public key.
20+
key_pair: typing.Tuple[bytes, bytes] = pycspr.crypto.get_key_pair(algo=KeyAlgorithm.ED25519)
21+
pbk: bytes = key_pair[1]
22+
23+
# Map raw public key to account key.
24+
account_key: bytes = pycspr.crypto.get_account_key(KeyAlgorithm.ED25519, pbk)
25+
26+
# Map account key to checksummed hexadecimal.
27+
account_key_checksum: str = pycspr.crypto.cl_checksum.encode_account_key(account_key)
28+
29+
print("Account Key Hexadecimal:")
30+
print(f" ... raw: {account_key.hex()}")
31+
print(f" ... checksummed: {account_key_checksum}")
32+
33+
34+
# Entry point.
35+
if __name__ == "__main__":
36+
_main(_ARGS.parse_args())

pycspr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# 88 d8' 88
88

99
__title__ = "pycspr"
10-
__version__ = "0.11.1"
10+
__version__ = "0.11.2"
1111
__author__ = "Mark A. Greenslade et al"
1212
__license__ = "Apache 2.0"
1313

pycspr/serialisation/cl_type_to_bytes.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ def encode(entity: cl_types.CL_Type) -> bytes:
1212
1313
"""
1414
if entity.type_key in _ENCODERS_SIMPLE:
15-
return bytes([entity.type_key.value])
16-
elif entity.type_key in _ENCODERS_COMPLEX:
17-
return bytes([entity.type_key.value]) + _ENCODERS_COMPLEX[entity.type_key](entity)
15+
encoded = bytes([])
1816
else:
19-
raise ValueError("Unrecognized cl type")
17+
try:
18+
encoder = _ENCODERS_COMPLEX[entity.type_key]
19+
except KeyError:
20+
raise ValueError("Unrecognized cl type")
21+
else:
22+
encoded = encoder(entity)
23+
24+
return bytes([entity.type_key.value]) + encoded
2025

2126

2227
def _encode_byte_array(entity: cl_types.CL_Type_ByteArray):

tests/test_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _has_member(mod, member):
101101

102102

103103
def test_version_of_library():
104-
assert pycspr.__version__ == "0.11.1"
104+
assert pycspr.__version__ == "0.11.2"
105105

106106

107107
def test_exports_of_library():

0 commit comments

Comments
 (0)