Skip to content

Commit

Permalink
Rename EIP-712 signature type
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jul 12, 2024
1 parent 384ddd3 commit 987252d
Show file tree
Hide file tree
Showing 14 changed files with 450 additions and 449 deletions.
4 changes: 2 additions & 2 deletions internal/core/execute/v2/block/sig_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
func(ctx *SignatureContext) bool { return ctx.GetActiveGlobals().ExecutorVersion.V2VandenbergEnabled() },
protocol.SignatureTypeRsaSha256,
protocol.SignatureTypeEcdsaSha256,
protocol.SignatureTypeEip712TypedData,
protocol.SignatureTypeTypedData,
)
}

Expand Down Expand Up @@ -184,7 +184,7 @@ func (UserSignature) unwrapDelegated(ctx *userSigContext) error {
}

func (UserSignature) checkChainID(ctx *userSigContext) error {
sig, ok := ctx.keySig.(*protocol.Eip712TypedDataSignature)
sig, ok := ctx.keySig.(*protocol.TypedDataSignature)
if !ok {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/signing/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (s *Builder) prepare(init bool) (protocol.KeySignature, error) {
protocol.SignatureTypeETH,
protocol.SignatureTypeRsaSha256,
protocol.SignatureTypeEcdsaSha256,
protocol.SignatureTypeEip712TypedData,
protocol.SignatureTypeTypedData,
protocol.SignatureTypeBTCLegacy:

case protocol.SignatureTypeReceipt, protocol.SignatureTypePartition:
Expand Down Expand Up @@ -320,8 +320,8 @@ func (s *Builder) prepare(init bool) (protocol.KeySignature, error) {
sig.Data = s.Data
return sig, s.Signer.SetPublicKey(sig)

case protocol.SignatureTypeEip712TypedData:
sig := new(protocol.Eip712TypedDataSignature)
case protocol.SignatureTypeTypedData:
sig := new(protocol.TypedDataSignature)
sig.Signer = s.Url
sig.SignerVersion = s.Version
sig.Timestamp = timestamp
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (p *PrivateKey) String() string {
case protocol.SignatureTypeRCD1:
return FormatFs(p.Key[:32])

case protocol.SignatureTypeETH, protocol.SignatureTypeEip712TypedData:
case protocol.SignatureTypeETH, protocol.SignatureTypeTypedData:
return hex.EncodeToString(p.Key)

case protocol.SignatureTypeBTCLegacy, protocol.SignatureTypeBTC:
Expand Down Expand Up @@ -164,7 +164,7 @@ func formatAddr(typ protocol.SignatureType, hash []byte) string {
protocol.SignatureTypeBTCLegacy:
return FormatBTC(hash)

case protocol.SignatureTypeETH, protocol.SignatureTypeEip712TypedData:
case protocol.SignatureTypeETH, protocol.SignatureTypeTypedData:
return FormatETH(hash)

case protocol.SignatureTypeEcdsaSha256:
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/address/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func FromPrivateKeyBytes(priv []byte, typ protocol.SignatureType) (*PrivateKey,

case protocol.SignatureTypeETH,
protocol.SignatureTypeBTCLegacy,
protocol.SignatureTypeEip712TypedData:
protocol.SignatureTypeTypedData:
_, pk := btc.PrivKeyFromBytes(btc.S256(), priv)
pub = pk.SerializeUncompressed()

Expand Down
2 changes: 1 addition & 1 deletion pkg/types/encoding/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestEIP712Arrays(t *testing.T) {
for _, txn := range cases {
t.Run(hex.EncodeToString(txn.GetHash()), func(t *testing.T) {
priv := acctesting.NewSECP256K1(t.Name())
sig := &protocol.Eip712TypedDataSignature{
sig := &protocol.TypedDataSignature{
ChainID: protocol.EthChainID("Kermit"),
PublicKey: eth.FromECDSAPub(&priv.PublicKey),
Signer: url.MustParse("acc://adi.acme/book/1"),
Expand Down
2 changes: 1 addition & 1 deletion protocol/enums.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SignatureType:
EcdsaSha256:
value: 15
description: represents a signature of SHA256 hashed data from an ecdsa algorithm with supported standard curves from NIST, SECG, and Brainpool typically (SEC, ANS.1 enocding)
Eip712TypedData:
TypedData:
value: 16
description: implements EIP-712 sign typed data specification

Expand Down
14 changes: 7 additions & 7 deletions protocol/enums_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ const SignatureTypeRsaSha256 SignatureType = 14
// SignatureTypeEcdsaSha256 represents a signature of SHA256 hashed data from an ecdsa algorithm with supported standard curves from NIST, SECG, and Brainpool typically (SEC, ANS.1 enocding).
const SignatureTypeEcdsaSha256 SignatureType = 15

// SignatureTypeEip712TypedData implements EIP-712 sign typed data specification.
const SignatureTypeEip712TypedData SignatureType = 16
// SignatureTypeTypedData implements EIP-712 sign typed data specification.
const SignatureTypeTypedData SignatureType = 16

// TransactionMaxUser is the highest number reserved for user transactions.
const TransactionMaxUser TransactionMax = 48
Expand Down Expand Up @@ -1163,7 +1163,7 @@ func (v SignatureType) GetEnumValue() uint64 { return uint64(v) }
func (v *SignatureType) SetEnumValue(id uint64) bool {
u := SignatureType(id)
switch u {
case SignatureTypeUnknown, SignatureTypeLegacyED25519, SignatureTypeED25519, SignatureTypeRCD1, SignatureTypeReceipt, SignatureTypePartition, SignatureTypeSet, SignatureTypeRemote, SignatureTypeBTC, SignatureTypeBTCLegacy, SignatureTypeETH, SignatureTypeDelegated, SignatureTypeInternal, SignatureTypeAuthority, SignatureTypeRsaSha256, SignatureTypeEcdsaSha256, SignatureTypeEip712TypedData:
case SignatureTypeUnknown, SignatureTypeLegacyED25519, SignatureTypeED25519, SignatureTypeRCD1, SignatureTypeReceipt, SignatureTypePartition, SignatureTypeSet, SignatureTypeRemote, SignatureTypeBTC, SignatureTypeBTCLegacy, SignatureTypeETH, SignatureTypeDelegated, SignatureTypeInternal, SignatureTypeAuthority, SignatureTypeRsaSha256, SignatureTypeEcdsaSha256, SignatureTypeTypedData:
*v = u
return true
}
Expand Down Expand Up @@ -1205,8 +1205,8 @@ func (v SignatureType) String() string {
return "rsaSha256"
case SignatureTypeEcdsaSha256:
return "ecdsaSha256"
case SignatureTypeEip712TypedData:
return "eip712TypedData"
case SignatureTypeTypedData:
return "typedData"
}
return fmt.Sprintf("SignatureType:%d", v)
}
Expand Down Expand Up @@ -1248,8 +1248,8 @@ func SignatureTypeByName(name string) (SignatureType, bool) {
return SignatureTypeRsaSha256, true
case "ecdsasha256":
return SignatureTypeEcdsaSha256, true
case "eip712typeddata":
return SignatureTypeEip712TypedData, true
case "typeddata":
return SignatureTypeTypedData, true
}
return 0, false
}
Expand Down
30 changes: 15 additions & 15 deletions protocol/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func PublicKeyHash(key []byte, typ SignatureType) ([]byte, error) {
return BTCHash(key), nil

case SignatureTypeETH,
SignatureTypeEip712TypedData:
SignatureTypeTypedData:
return ETHhash(key), nil

case SignatureTypeReceipt,
Expand Down Expand Up @@ -1193,7 +1193,7 @@ func (e *EcdsaSha256Signature) Verify(sig Signature, msg Signable) bool {
* EIP-712 Typed Data Signature
* privateKey must be ecdsa
*/
func SignEip712TypedData(sig *Eip712TypedDataSignature, privateKey []byte, outer Signature, txn *Transaction) error {
func SignEip712TypedData(sig *TypedDataSignature, privateKey []byte, outer Signature, txn *Transaction) error {
if outer == nil {
outer = sig
}
Expand All @@ -1213,42 +1213,42 @@ func SignEip712TypedData(sig *Eip712TypedDataSignature, privateKey []byte, outer
}

// GetSigner returns Signer.
func (s *Eip712TypedDataSignature) GetSigner() *url.URL { return s.Signer }
func (s *TypedDataSignature) GetSigner() *url.URL { return s.Signer }

// RoutingLocation returns Signer.
func (s *Eip712TypedDataSignature) RoutingLocation() *url.URL { return s.Signer }
func (s *TypedDataSignature) RoutingLocation() *url.URL { return s.Signer }

// GetSignerVersion returns SignerVersion.
func (s *Eip712TypedDataSignature) GetSignerVersion() uint64 { return s.SignerVersion }
func (s *TypedDataSignature) GetSignerVersion() uint64 { return s.SignerVersion }

// GetTimestamp returns Timestamp.
func (s *Eip712TypedDataSignature) GetTimestamp() uint64 { return s.Timestamp }
func (s *TypedDataSignature) GetTimestamp() uint64 { return s.Timestamp }

// GetPublicKeyHash returns the hash of PublicKey.
func (s *Eip712TypedDataSignature) GetPublicKeyHash() []byte { return ETHhash(s.PublicKey) }
func (s *TypedDataSignature) GetPublicKeyHash() []byte { return ETHhash(s.PublicKey) }

// GetPublicKey returns PublicKey.
func (s *Eip712TypedDataSignature) GetPublicKey() []byte { return s.PublicKey }
func (s *TypedDataSignature) GetPublicKey() []byte { return s.PublicKey }

// GetSignature returns Signature.
func (s *Eip712TypedDataSignature) GetSignature() []byte { return s.Signature }
func (s *TypedDataSignature) GetSignature() []byte { return s.Signature }

// GetTransactionHash returns TransactionHash.
func (s *Eip712TypedDataSignature) GetTransactionHash() [32]byte { return s.TransactionHash }
func (s *TypedDataSignature) GetTransactionHash() [32]byte { return s.TransactionHash }

// Hash returns the hash of the signature.
func (s *Eip712TypedDataSignature) Hash() []byte { return signatureHash(s) }
func (s *TypedDataSignature) Hash() []byte { return signatureHash(s) }

// Metadata returns the signature's metadata.
func (s *Eip712TypedDataSignature) Metadata() Signature {
func (s *TypedDataSignature) Metadata() Signature {
r := s.Copy() // Copy the struct
r.Signature = nil // Clear the signature
r.TransactionHash = [32]byte{} // And the transaction hash
return r
}

// Initiator returns a Hasher that calculates the Merkle hash of the signature.
func (s *Eip712TypedDataSignature) Initiator() (hash.Hasher, error) {
func (s *TypedDataSignature) Initiator() (hash.Hasher, error) {
if len(s.PublicKey) == 0 || s.Signer == nil || s.SignerVersion == 0 || s.Timestamp == 0 {
return nil, ErrCannotInitiate
}
Expand All @@ -1262,13 +1262,13 @@ func (s *Eip712TypedDataSignature) Initiator() (hash.Hasher, error) {
}

// GetVote returns how the signer votes on a particular transaction
func (s *Eip712TypedDataSignature) GetVote() VoteType {
func (s *TypedDataSignature) GetVote() VoteType {
return s.Vote
}

// Verify returns true if this signature is a valid EIP-712 signature following
// the spec.
func (e *Eip712TypedDataSignature) Verify(sig Signature, msg Signable) bool {
func (e *TypedDataSignature) Verify(sig Signature, msg Signable) bool {
txn, ok := msg.(*Transaction)
if !ok {
// EIP-712 cannot be used to sign something that isn't a transaction
Expand Down
4 changes: 2 additions & 2 deletions protocol/signature_eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func EIP712Hash(txn *Transaction, sig Signature) ([]byte, error) {
// newEIP712Call converts the transaction and signature to an EIP-712 message.
func newEIP712Call(txn *Transaction, sig Signature) (*encoding.EIP712Call, error) {
var delegators []any
var inner *Eip712TypedDataSignature
var inner *TypedDataSignature
for inner == nil {
switch s := sig.(type) {
case *DelegatedSignature:
delegators = append(delegators, s.Delegator.String())
sig = s.Signature
case *Eip712TypedDataSignature:
case *TypedDataSignature:
inner = s
default:
return nil, fmt.Errorf("unsupported signature type %v", s.Type())
Expand Down
6 changes: 3 additions & 3 deletions protocol/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func TestEip712TypedDataSignature(t *testing.T) {
require.NoError(t, err)

priv := acctesting.NewSECP256K1(t.Name())
eip712sig := &Eip712TypedDataSignature{
eip712sig := &TypedDataSignature{
ChainID: protocol.EthChainID("MainNet"),
PublicKey: eth.FromECDSAPub(&priv.PublicKey),
Signer: url.MustParse("acc://adi.acme/book/1"),
Expand All @@ -530,7 +530,7 @@ func TestEIP712DelegatedKeyPageUpdate(t *testing.T) {
require.NoError(t, err)

priv := acctesting.NewSECP256K1(t.Name())
inner := &Eip712TypedDataSignature{
inner := &TypedDataSignature{
ChainID: protocol.EthChainID("MainNet"),
PublicKey: eth.FromECDSAPub(&priv.PublicKey),
Signer: url.MustParse("acc://adi.acme/book/1"),
Expand Down Expand Up @@ -570,7 +570,7 @@ func TestEIP712MessageForWallet(t *testing.T) {
require.NoError(t, err)

priv := acctesting.NewSECP256K1(t.Name())
sig := &Eip712TypedDataSignature{
sig := &TypedDataSignature{
ChainID: protocol.EthChainID("MainNet"),
PublicKey: eth.FromECDSAPub(&priv.PublicKey),
Signer: url.MustParse("acc://adi.acme/book/1"),
Expand Down
2 changes: 1 addition & 1 deletion protocol/signatures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ EcdsaSha256Signature:
type: bytes
optional: true

Eip712TypedDataSignature:
TypedDataSignature:
description: is an EIP-712 compliant typed data signature for an Accumulate transaction
union: { type: signature }
fields:
Expand Down
Loading

0 comments on commit 987252d

Please sign in to comment.