-
-
Notifications
You must be signed in to change notification settings - Fork 6
Update input validation #110
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
Changes from all commits
e3cbffc
ba3df1a
9aee59a
3de6872
224d805
4fda865
d5c8750
5042b31
ff5bf94
c701b29
71687e2
e69e2dd
fbeafdf
cb46e47
ef7f7ca
52bc0d5
8902b09
8e806b4
5f74eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,15 @@ import { zErc20TokenStreamPermission } from './types'; | |
| /** | ||
| * Validates a permission object data specific to the permission type. | ||
| * @param permission - The ERC20 token stream permission object to validate. | ||
| * @param expiry - The expiry time of permission request. | ||
| * @returns True if the permission data is valid, throws an error otherwise. | ||
| * @throws {Error} If any validation check fails. | ||
| */ | ||
| function validatePermissionData(permission: Erc20TokenStreamPermission): true { | ||
| const { initialAmount, maxAmount, amountPerSecond, startTime, tokenAddress } = | ||
| function validatePermissionData( | ||
| permission: Erc20TokenStreamPermission, | ||
| expiry: number, | ||
| ): true { | ||
| const { initialAmount, maxAmount, amountPerSecond, startTime } = | ||
| permission.data; | ||
|
|
||
| validateHexInteger({ | ||
|
|
@@ -29,7 +33,7 @@ function validatePermissionData(permission: Erc20TokenStreamPermission): true { | |
| name: 'initialAmount', | ||
| value: initialAmount, | ||
| required: false, | ||
| allowZero: false, | ||
| allowZero: true, | ||
| }); | ||
|
|
||
| validateHexInteger({ | ||
|
|
@@ -43,18 +47,9 @@ function validatePermissionData(permission: Erc20TokenStreamPermission): true { | |
| throw new Error('Invalid maxAmount: must be greater than initialAmount'); | ||
| } | ||
|
|
||
| if (startTime <= 0) { | ||
| throw new Error('Invalid startTime: must be a positive number'); | ||
| } | ||
|
|
||
| if (startTime !== Math.floor(startTime)) { | ||
| throw new Error('Invalid startTime: must be an integer'); | ||
| } | ||
|
|
||
| if (!tokenAddress || tokenAddress === '0x') { | ||
| throw new Error( | ||
| 'Invalid tokenAddress: must be a valid ERC20 token address', | ||
| ); | ||
| // If startTime is not provided it default to Date.now(), expiry is always in the future so no need to check. | ||
| if (startTime && startTime >= expiry) { | ||
| throw new Error('Invalid startTime: must be before expiry'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Default
|
||
| } | ||
|
|
||
| return true; | ||
|
|
@@ -79,7 +74,7 @@ export function parseAndValidatePermission( | |
| throw new Error(extractZodError(validationError.errors)); | ||
| } | ||
|
|
||
| validatePermissionData(validationResult); | ||
| validatePermissionData(validationResult, permissionRequest.expiry); | ||
|
|
||
| return { | ||
| ...permissionRequest, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.