From 681869562d5de4d434a8d7dcfc6620a0d8180d4a Mon Sep 17 00:00:00 2001 From: Michael Zaikin Date: Mon, 27 Nov 2023 18:31:34 +0200 Subject: [PATCH] fix: smart rollup address validation --- CHANGELOG.md | 8 +++++++- src/pytezos/crypto/encoding.py | 11 ++++++++++- src/pytezos/michelson/types/domain.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95221513f..7d0fa2acf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## [3.10.1](https://github.com/baking-bad/pytezos/compare/3.10.1...3.10.2) (2023-07-05) +## [3.10.3](https://github.com/baking-bad/pytezos/compare/3.10.2...3.10.3) (2023-11-27) + +### Fixed + +* Smart rollup address validation + +## [3.10.2](https://github.com/baking-bad/pytezos/compare/3.10.1...3.10.2) (2023-07-05) ### Fixed diff --git a/src/pytezos/crypto/encoding.py b/src/pytezos/crypto/encoding.py index d1632d5dd..43894cd1d 100644 --- a/src/pytezos/crypto/encoding.py +++ b/src/pytezos/crypto/encoding.py @@ -201,6 +201,15 @@ def is_kt(v: Union[str, bytes]) -> bool: return True +def is_sr(v: Union[str, bytes]) -> bool: + """Check if value is a smart rollup address.""" + try: + _validate(v, prefixes=[b'sr1']) + except (ValueError, TypeError): + return False + return True + + def is_public_key(v: Union[str, bytes]) -> bool: """Check if value is a public key.""" try: @@ -224,7 +233,7 @@ def is_address(v: Union[str, bytes]) -> bool: if isinstance(v, bytes): v = v.decode() address = v.split('%')[0] - return is_kt(address) or is_pkh(address) + return is_kt(address) or is_pkh(address) or is_sr(address) def is_txr_address(v: Union[str, bytes]) -> bool: diff --git a/src/pytezos/michelson/types/domain.py b/src/pytezos/michelson/types/domain.py index 2e87bc00b..641a37a7c 100644 --- a/src/pytezos/michelson/types/domain.py +++ b/src/pytezos/michelson/types/domain.py @@ -110,7 +110,7 @@ def dummy(cls, context: AbstractContext) -> 'AddressType': def from_value(cls, value: str) -> 'AddressType': if value.endswith('%default'): value = value.split('%')[0] - assert is_address(value), f'expected tz/KT address, got {value}' + assert is_address(value), f'expected tz/KT/sr address, got {value}' return cls(value) @classmethod