feat: add comprehensive input validation for token operations (#1534)#1549
Open
NETIZEN-11 wants to merge 2 commits into
Open
feat: add comprehensive input validation for token operations (#1534)#1549NETIZEN-11 wants to merge 2 commits into
NETIZEN-11 wants to merge 2 commits into
Conversation
ebbde41 to
f3d83f4
Compare
Author
|
@adecaro Would love a review on this. Thanks! |
f3d83f4 to
9416396
Compare
Contributor
|
Hi @NETIZEN-11 , sorry for this very late reply. I'm reviewing it now 🙏 |
adecaro
reviewed
Apr 29, 2026
Contributor
|
Hi @NETIZEN-11 , I'm not sure the PR achieves the goals stated in the Issue. There are many validation functions but they are not used.
Thanks for the effort 🙏 |
1545d91 to
b94f38b
Compare
- Add validation package with functions for amount, address, token type, metadata - Add custom error types for validation failures - Use validation in Issue, Transfer, and Redeem methods - Fix test compilation errors in sherdlock - Fix mutex unlock bug in cachedFetcher.update() Signed-off-by: Nitesh <nitesh@example.com>
b94f38b to
53580ce
Compare
Signed-off-by: Nitesh Kumar <niteshkumar121411@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements comprehensive input validation for token operations (Issue, Transfer, Redeem) to ensure data integrity,
security, and consistency.
Changes
New Validation Package (
token/services/validation/)ValidateAmount()- validates token amounts (non-zero, within max limit)ValidateAddress()- validates recipient addresses (non-empty, max 256 bytes)ValidateTokenType()- validates token types (non-empty)ValidateMetadata()- validates metadata fields (key presence, 10KB size limit)ValidateTransferValues()- validates transfer values and owners arraysValidateRedeemValue()- validates redeem valuesError Types with Codes
InvalidAmountErrorInvalidAddressErrorInvalidMetadataErrorInvalidTokenTypeErrorValidationErrorEnhanced
token/request.goIssue() - Added:
Transfer() - Added:
Redeem() - Added:
validateMetadata() - New helper function for metadata validation
Test Results
All unit tests pass:
PASS ok github.com/hyperledger-labs/fabric-token-sdk/token/services/validation
PASS ok github.com/hyperledger-labs/fabric-token-sdk/token
Acceptance Criteria Met
Related Issue
Fixes #1534
Test plan
go test ./token/services/validation/...go test ./token -run TestRequestgo build ./token/...