Skip to content
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 test for sign typed data with bytes #28

Conversation

rmeissner
Copy link
Contributor

Added test that contain bytes for signing typed data.

The test values have been calculated with the following smart contract:

pragma solidity 0.4.24;

contract Test {
    
    function personData()
        public
        pure
        returns (bytes) 
    {
        bytes32 personSchemaHash = keccak256("Person(string name,address wallet)");
        return abi.encode(
            personSchemaHash,
            keccak256('Bob'),
            address(0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB)
        );
    }
    
    function signData()
        public
        pure
        returns (bytes) 
    {
        bytes32 personSchemaHash = keccak256("Person(string name,address wallet)");
        return abi.encode(
            mailSchemaHash(),
            keccak256(
                abi.encode(
                    personSchemaHash,
                    keccak256('Cow'),
                    address(0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826)
                )
            ),
            keccak256(personData()),
            keccak256("Hello, Bob!"),
            keccak256(hex"25192142931f380985072cdd991e37f65cf8253ba7a0e675b54163a1d133b8ca")
        );
    }
    
    function signHash()
        public
        pure
        returns (bytes32) 
    {
        return keccak256(signData());
    }
    
    function sign()
        public
        pure
        returns (bytes32) 
    {
        return keccak256(abi.encodePacked(
            byte(0x19), 
            byte(1), 
            0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f, 
            signHash()
        ));
    }
    
    
    function mailSchemaHash() 
        public
        pure
        returns (bytes32) 
    {
        return keccak256("Mail(Person from,Person to,string contents,bytes payload)Person(string name,address wallet)");
    }
}

@rmeissner
Copy link
Contributor Author

would it be possible to confirm these test vectors and merge them?

@Gudahtt
Copy link
Member

Gudahtt commented Jul 12, 2021

Thanks for the contribution @rmeissner ! Unfortunately we left this unreviewed for too long so it had gone quite stale. I've rebased this and updated it to match our current test style in this PR: #146, which can supersede this PR. I'll try to get it reviewed and merged ASAP.

@Gudahtt Gudahtt closed this Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants