@ -58,7 +58,7 @@ type SetCodeTx struct {
Value * uint256 . Int
Data [ ] byte
AccessList AccessList
AuthList [ ] Authorization
AuthList [ ] SetCode Authorization
// Signature values
V * uint256 . Int ` json:"v" gencodec:"required" `
@ -66,10 +66,10 @@ type SetCodeTx struct {
S * uint256 . Int ` json:"s" gencodec:"required" `
}
//go:generate go run github.com/fjl/gencodec -type Authorization -field-override authorizationMarshaling -out gen_authorization.go
//go:generate go run github.com/fjl/gencodec -type SetCode Authorization -field-override authorizationMarshaling -out gen_authorization.go
// Authorization is an authorization from an account to deploy code at its address.
type Authorization struct {
// SetCode Authorization is an authorization from an account to deploy code at its address.
type SetCode Authorization struct {
ChainID uint64 ` json:"chainId" gencodec:"required" `
Address common . Address ` json:"address" gencodec:"required" `
Nonce uint64 ` json:"nonce" gencodec:"required" `
@ -87,31 +87,25 @@ type authorizationMarshaling struct {
S hexutil . U256
}
// SignAuth signs the provided authorization.
func SignAuth ( auth Authorization , prv * ecdsa . PrivateKey ) ( Authorization , error ) {
// SignSetCode creates a signed the SetCode authorization.
func SignSetCode ( prv * ecdsa . PrivateKey , auth SetCodeAuthorization ) ( SetCode Authorization, error ) {
sighash := auth . sigHash ( )
sig , err := crypto . Sign ( sighash [ : ] , prv )
if err != nil {
return Authorization { } , err
return SetCode Authorization{ } , err
}
return auth . withSignature ( sig ) , nil
}
// withSignature updates the signature of an Authorization to be equal the
// decoded signature provided in sig.
func ( a * Authorization ) withSignature ( sig [ ] byte ) Authorization {
r , s , _ := decodeSignature ( sig )
return Authorization {
ChainID : a . ChainID ,
Address : a . Address ,
Nonce : a . Nonce ,
return SetCodeAuthorization {
ChainID : auth . ChainID ,
Address : auth . Address ,
Nonce : auth . Nonce ,
V : sig [ 64 ] ,
R : * uint256 . MustFromBig ( r ) ,
S : * uint256 . MustFromBig ( s ) ,
}
} , nil
}
func ( a * Authorization ) sigHash ( ) common . Hash {
func ( a * SetCode Authorization) sigHash ( ) common . Hash {
return prefixedRlpHash ( 0x05 , [ ] any {
a . ChainID ,
a . Address ,
@ -120,7 +114,7 @@ func (a *Authorization) sigHash() common.Hash {
}
// Authority recovers the the authorizing account of an authorization.
func ( a * Authorization ) Authority ( ) ( common . Address , error ) {
func ( a * SetCode Authorization) Authority ( ) ( common . Address , error ) {
sighash := a . sigHash ( )
if ! crypto . ValidateSignatureValues ( a . V , a . R . ToBig ( ) , a . S . ToBig ( ) , true ) {
return common . Address { } , ErrInvalidSig
@ -152,7 +146,7 @@ func (tx *SetCodeTx) copy() TxData {
Gas : tx . Gas ,
// These are copied below.
AccessList : make ( AccessList , len ( tx . AccessList ) ) ,
AuthList : make ( [ ] Authorization , len ( tx . AuthList ) ) ,
AuthList : make ( [ ] SetCode Authorization, len ( tx . AuthList ) ) ,
Value : new ( uint256 . Int ) ,
ChainID : tx . ChainID ,
GasTipCap : new ( uint256 . Int ) ,