-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add runtime validation for string fields #766
Comments
Copying this sample code from @coderabbitai's comment:
If this type of validation can be done at the typing level, that would be really useful for e.g. ensuring that XRP amounts are valid and that blobs are in hex. |
Tip For best results, initiate chat on the files or code changes. @mvadari, that's a great idea! Implementing validation at the typing level can indeed help ensure that fields like XRP amounts are valid and blobs are in hex format. Here's how you might define custom types and validators for XRP amounts and hex blobs: from typing import NewType
from typing_extensions import Annotated
AmountStr = NewType('AmountStr', str)
HexBlobStr = NewType('HexBlobStr', str)
def validate_amount(value: str) -> AmountStr:
if not is_valid_amount(value): # implement validation logic
raise ValueError("Invalid XRP amount format")
return AmountStr(value)
def validate_hex_blob(value: str) -> HexBlobStr:
if not is_valid_hex_blob(value): # implement validation logic
raise ValueError("Invalid hex blob format")
return HexBlobStr(value)
# Then in your class:
amount: Annotated[AmountStr, REQUIRED]
blob: Annotated[HexBlobStr, REQUIRED] You'll need to implement the Let me know if you need any further assistance! |
As discussed in PR #765 comment, we should consider adding runtime validation for cryptographic fields such as
public_key
andsignature
in theXChainAddClaimAttestation
class to ensure they meet specific format requirements.\n\nOriginally suggested by @coderabbitai[bot] and agreed upon by @mvadari.The text was updated successfully, but these errors were encountered: