-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sign CCRs as EIP-712 messages (#247)
* Sign CCRs as EIP-712 messages * Revert some changes * brock/eip712 ccr mod (#250) * remove chainId from EIP712 msg domain * use verifyingContract in eip712 domain * Rename field --------- Co-authored-by: brock smedley <[email protected]>
- Loading branch information
1 parent
3ccb353
commit cc52b54
Showing
10 changed files
with
1,137 additions
and
11 deletions.
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
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,51 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/signer/core/eip712" | ||
) | ||
|
||
func (msg *ConfidentialComputeRecord) EIP712Hash() (common.Hash, error) { | ||
hash, _, err := eip712.TypedDataAndHash(CCREIP712Envelope(msg)) | ||
|
||
hash32 := common.Hash{} | ||
copy(hash32[:], hash[:]) | ||
|
||
return hash32, err | ||
} | ||
|
||
func CCREIP712Envelope(msg *ConfidentialComputeRecord) eip712.TypedData { | ||
return eip712.TypedData{ | ||
Types: eip712.Types{ | ||
"EIP712Domain": []eip712.Type{ | ||
{Name: "name", Type: "string"}, | ||
{Name: "verifyingContract", Type: "address"}, | ||
}, | ||
"ConfidentialRecord": []eip712.Type{ | ||
{Name: "nonce", Type: "uint64"}, | ||
{Name: "gasPrice", Type: "uint256"}, | ||
{Name: "gas", Type: "uint64"}, | ||
{Name: "to", Type: "address"}, | ||
{Name: "value", Type: "uint256"}, | ||
{Name: "data", Type: "bytes"}, | ||
{Name: "kettleAddress", Type: "address"}, | ||
{Name: "confidentialInputsHash", Type: "bytes32"}, | ||
}, | ||
}, | ||
Domain: eip712.TypedDataDomain{ | ||
Name: "ConfidentialRecord", | ||
VerifyingContract: msg.KettleAddress.Hex(), | ||
}, | ||
PrimaryType: "ConfidentialRecord", | ||
Message: eip712.TypedDataMessage{ | ||
"nonce": msg.Nonce, | ||
"gasPrice": msg.GasPrice, | ||
"gas": msg.Gas, | ||
"to": msg.To, | ||
"value": msg.Value, | ||
"data": msg.Data, | ||
"kettleAddress": msg.KettleAddress, | ||
"confidentialInputsHash": msg.ConfidentialInputsHash, | ||
}, | ||
} | ||
} |
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,23 @@ | ||
package types | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCCREIP712(t *testing.T) { | ||
to := common.Address{0x2} | ||
|
||
ccr := &ConfidentialComputeRecord{ | ||
GasPrice: big.NewInt(0), | ||
To: &to, | ||
Value: big.NewInt(0), | ||
ChainID: big.NewInt(0), | ||
} | ||
|
||
_, err := ccr.EIP712Hash() | ||
require.NoError(t, err) | ||
} |
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
Oops, something went wrong.