Skip to content

Commit

Permalink
fix: smart rollup address validation (#352)
Browse files Browse the repository at this point in the history
Co-authored-by: Lev Gorodetskiy <github@droserasprout.space>
  • Loading branch information
m-kus and droserasprout authored Nov 28, 2023
1 parent c28b1e4 commit 0e69169
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/pytezos/crypto/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/pytezos/michelson/types/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e69169

Please sign in to comment.