-
Notifications
You must be signed in to change notification settings - Fork 25
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
[DRAFT] feat: Composable Validation #82
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c817ead
feat: [v0.8-develop, experimental] composable validation
jaypaik 50e2f44
feat: add three basic stateless validators and update singleOwnerPlugin
fangting-alchemy 10ac17d
fix tests with new validation system
fangting-alchemy ae7bacb
fix signer not set errors
fangting-alchemy 085bc78
fix single owner plugin events tests
fangting-alchemy 8026eec
fix remaining tests and clean up interface function overrides
fangting-alchemy 9aee83b
add tests for validators
fangting-alchemy 03f49ae
add tests for validators
fangting-alchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Submodule FreshCryptoLib
added at
fd2a0e
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol"; | ||
|
||
/// TODO this library is not necessary once Openzeppelin 5.0.2 Base64 is supported | ||
library Base64URL { | ||
function encode(bytes memory data) internal pure returns (string memory) { | ||
string memory strb64 = Base64.encode(data); | ||
bytes memory b64 = bytes(strb64); | ||
|
||
// Base64 can end with "=" or "=="; Base64URL has no padding. | ||
uint256 equalsCount = 0; | ||
if (b64.length > 2 && b64[b64.length - 2] == "=") equalsCount = 2; | ||
else if (b64.length > 1 && b64[b64.length - 1] == "=") equalsCount = 1; | ||
|
||
uint256 len = b64.length - equalsCount; | ||
bytes memory result = new bytes(len); | ||
|
||
for (uint256 i = 0; i < len; i++) { | ||
if (b64[i] == "+") { | ||
result[i] = "-"; | ||
} else if (b64[i] == "/") { | ||
result[i] = "_"; | ||
} else { | ||
result[i] = b64[i]; | ||
} | ||
} | ||
|
||
return string(result); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.25; | ||
|
||
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
|
||
import {IStatelessValidator} from "./IStatelessValidator.sol"; | ||
|
||
contract EcdsaValidator is IStatelessValidator { | ||
using ECDSA for bytes32; | ||
|
||
/// @dev result always returns the correct singer of the signature. | ||
function validate(bytes memory signerData, bytes32 hash, bytes memory signature) | ||
external | ||
view | ||
override | ||
returns (bool isValid, bytes memory result) | ||
{ | ||
if (signerData.length == 0) { | ||
isValid = false; | ||
} else { | ||
address expectedSigner = abi.decode(signerData, (address)); | ||
|
||
address signer = hash.recover(signature); | ||
isValid = signer == expectedSigner; | ||
result = abi.encode(signer); | ||
} | ||
} | ||
|
||
function encodeSignerData(address signer) external pure returns (bytes memory data) { | ||
data = abi.encode(signer); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.25; | ||
|
||
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; | ||
|
||
import {IStatelessValidator} from "./IStatelessValidator.sol"; | ||
|
||
contract Erc1271Validator is IStatelessValidator { | ||
function validate(bytes memory signerData, bytes32 hash, bytes memory signature) | ||
external | ||
view | ||
override | ||
returns (bool isValid, bytes memory) | ||
{ | ||
if (signerData.length == 0) { | ||
isValid = false; | ||
} else { | ||
address expectedSigner = abi.decode(signerData, (address)); | ||
|
||
isValid = SignatureChecker.isValidERC1271SignatureNow(expectedSigner, hash, signature); | ||
} | ||
} | ||
|
||
function encodeSignerData(address signer) external pure returns (bytes memory data) { | ||
data = abi.encode(signer); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.25; | ||
|
||
struct Signer { | ||
IStatelessValidator validator; | ||
/// data is passed as signedData to the validator | ||
bytes data; | ||
} | ||
|
||
interface IStatelessValidator { | ||
function validate(bytes memory signerData, bytes32 hash, bytes memory signature) | ||
external | ||
view | ||
returns (bool isValid, bytes memory result); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not guaranteed to have this abi encoding though, right? For example for WebAuthnValidator has a different encoding to ECDSA one which is assumed here