Very rough versioning of TreasureMaps

We will transition to a better serialization approach (e.g., protobuf) so versioning is simpler to manage
pull/2687/head
David Núñez 2021-01-18 15:52:59 +01:00 committed by Kieran R. Prasch
parent 11052a6124
commit 8f31b17f3e
1 changed files with 12 additions and 11 deletions

View File

@ -47,6 +47,7 @@ from nucypher.network.middleware import RestMiddleware
class TreasureMap:
ID_LENGTH = 32
version = bytes.fromhex("42") # FIXME: This is a placeholder versioning, while we devise a better data serialization format
class NowhereToBeFound(RestMiddleware.NotFound):
"""
@ -59,7 +60,7 @@ class TreasureMap:
leaves Bob disoriented.
"""
node_id_splitter = BytestringSplitter((to_checksum_address, ETH_ADDRESS_BYTE_LENGTH), ID_LENGTH)
node_id_splitter = BytestringSplitter((to_checksum_address, ETH_ADDRESS_BYTE_LENGTH), ID_LENGTH) # FIXME: The latter is supposed to be arrangement ID length
from nucypher.crypto.signing import \
InvalidSignature # Raised when the public signature (typically intended for Ursula) is not valid.
@ -69,7 +70,11 @@ class TreasureMap:
destinations=None,
message_kit: UmbralMessageKit = None,
public_signature: Signature = None,
hrac: Optional[bytes] = None) -> None:
hrac: Optional[bytes] = None,
version: bytes = None) -> None:
if version is not None:
self.version = version
if m is not None:
if m > 255:
@ -97,16 +102,17 @@ class TreasureMap:
@classmethod
def splitter(cls):
return BytestringKwargifier(cls,
version=(bytes, 1),
public_signature=signature_splitter,
hrac=(bytes, HRAC_LENGTH),
message_kit=(UmbralMessageKit, VariableLengthBytestring)
message_kit=(UmbralMessageKit, VariableLengthBytestring),
)
def prepare_for_publication(self,
bob_encrypting_key,
bob_verifying_key,
alice_stamp,
label):
label: bytes):
plaintext = self._m.to_bytes(1, "big") + self.nodes_as_bytes()
@ -135,7 +141,7 @@ class TreasureMap:
self._id = keccak_digest(bytes(self._verifying_key) + bytes(self._hrac)).hex()
def _set_payload(self):
self._payload = bytes(self._public_signature) + self._hrac + bytes(
self._payload = self.version + bytes(self._public_signature) + self._hrac + bytes(
VariableLengthBytestring(self.message_kit.to_bytes()))
def __bytes__(self):
@ -249,12 +255,7 @@ class SignedTreasureMap(TreasureMap):
@classmethod
def splitter(cls):
return BytestringKwargifier(cls,
blockchain_signature=65,
public_signature=signature_splitter,
hrac=(bytes, HRAC_LENGTH),
message_kit=(UmbralMessageKit, VariableLengthBytestring)
)
return super().splitter() + BytestringKwargifier(cls, blockchain_signature=65)
def include_blockchain_signature(self, blockchain_signer):
self._blockchain_signature = blockchain_signer(super().__bytes__())