mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Update AccountCreationAuth & fix auth.HashToSign
- Fix AccountCreationAuth.HashToSign (was using `[]byte("0x...")`, which
uses the bytes of the string. Now uses the bytearray of the compressed
BJJ public key (compatible with js implementation))
- Update AccountCreationAuth to last specification (add to hash
parameters ChainID & HermezAddress)
- Add missing test to AccountCreationAuth
This commit is contained in:
@@ -21,7 +21,7 @@ func (a *API) postAccountCreationAuth(c *gin.Context) {
|
||||
}
|
||||
// API to common + verify signature
|
||||
commonAuth := accountCreationAuthAPIToCommon(&apiAuth)
|
||||
if !commonAuth.VerifySignature() {
|
||||
if !commonAuth.VerifySignature(a.chainID, a.hermezAddress) {
|
||||
retBadReq(errors.New("invalid signature"), c)
|
||||
return
|
||||
}
|
||||
|
||||
24
api/api.go
24
api/api.go
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db/historydb"
|
||||
@@ -31,12 +32,13 @@ type Status struct {
|
||||
|
||||
// API serves HTTP requests to allow external interaction with the Hermez node
|
||||
type API struct {
|
||||
h *historydb.HistoryDB
|
||||
cg *configAPI
|
||||
s *statedb.StateDB
|
||||
l2 *l2db.L2DB
|
||||
status Status
|
||||
chainID uint16
|
||||
h *historydb.HistoryDB
|
||||
cg *configAPI
|
||||
s *statedb.StateDB
|
||||
l2 *l2db.L2DB
|
||||
status Status
|
||||
chainID uint16
|
||||
hermezAddress ethCommon.Address
|
||||
}
|
||||
|
||||
// NewAPI sets the endpoints and the appropriate handlers, but doesn't start the server
|
||||
@@ -47,7 +49,6 @@ func NewAPI(
|
||||
sdb *statedb.StateDB,
|
||||
l2db *l2db.L2DB,
|
||||
config *Config,
|
||||
chainID uint16,
|
||||
) (*API, error) {
|
||||
// Check input
|
||||
// TODO: is stateDB only needed for explorer endpoints or for both?
|
||||
@@ -65,10 +66,11 @@ func NewAPI(
|
||||
AuctionConstants: config.AuctionConstants,
|
||||
WDelayerConstants: config.WDelayerConstants,
|
||||
},
|
||||
s: sdb,
|
||||
l2: l2db,
|
||||
status: Status{},
|
||||
chainID: chainID,
|
||||
s: sdb,
|
||||
l2: l2db,
|
||||
status: Status{},
|
||||
chainID: config.ChainID,
|
||||
hermezAddress: config.HermezAddress,
|
||||
}
|
||||
|
||||
// Add coordinator endpoints
|
||||
|
||||
@@ -221,7 +221,7 @@ func TestMain(m *testing.M) {
|
||||
test.WipeDB(l2DB.DB()) // this will clean HistoryDB and L2DB
|
||||
|
||||
// Config (smart contract constants)
|
||||
_config := getConfigTest()
|
||||
_config := getConfigTest(chainID)
|
||||
config = configAPI{
|
||||
RollupConstants: *newRollupConstants(_config.RollupConstants),
|
||||
AuctionConstants: _config.AuctionConstants,
|
||||
@@ -238,7 +238,6 @@ func TestMain(m *testing.M) {
|
||||
sdb,
|
||||
l2DB,
|
||||
&_config,
|
||||
chainID,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -423,7 +422,7 @@ func TestMain(m *testing.M) {
|
||||
exits: testExits,
|
||||
poolTxsToSend: poolTxsToSend,
|
||||
poolTxsToReceive: poolTxsToReceive,
|
||||
auths: genTestAuths(test.GenAuths(5)),
|
||||
auths: genTestAuths(test.GenAuths(5, _config.ChainID, _config.HermezAddress)),
|
||||
router: router,
|
||||
bids: testBids,
|
||||
slots: api.genTestSlots(
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"math/big"
|
||||
"net/http"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
)
|
||||
@@ -51,6 +52,8 @@ type Config struct {
|
||||
RollupConstants common.RollupConstants
|
||||
AuctionConstants common.AuctionConstants
|
||||
WDelayerConstants common.WDelayerConstants
|
||||
ChainID uint16
|
||||
HermezAddress ethCommon.Address
|
||||
}
|
||||
|
||||
type configAPI struct {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func getConfigTest() Config {
|
||||
func getConfigTest(chainID uint16) Config {
|
||||
var config Config
|
||||
|
||||
var rollupPublicConstants common.RollupConstants
|
||||
@@ -40,6 +40,9 @@ func getConfigTest() Config {
|
||||
config.AuctionConstants = auctionConstants
|
||||
config.WDelayerConstants = wdelayerConstants
|
||||
|
||||
config.ChainID = chainID
|
||||
config.HermezAddress = ethCommon.HexToAddress("0xc344E203a046Da13b0B4467EB7B3629D0C99F6E6")
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user