-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add chain id in API body * add chain id in payload signature * use chain id in sign for direct operation * add fallback buildnet chain id * update go.sum * fix canonization of chain id * add the chain id in the fallback network infos * improve error handling * rename a variable for unit test * rename defaultChainId * refactor prepare sign data * add unit test for PrepareSignData * format code
- Loading branch information
Showing
14 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,29 @@ | ||
package network | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/massalabs/station/pkg/node" | ||
) | ||
|
||
var ErrChainIDNotInStatus = errors.New("chain id not in status") | ||
|
||
func getChainID() (uint64, error) { | ||
client, err := NewMassaClient() | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
status, err := node.Status(client) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
chainID := status.ChainID | ||
|
||
if chainID == nil { | ||
return 0, ErrChainIDNotInStatus | ||
} | ||
|
||
return uint64(*chainID), nil | ||
} |
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
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,10 @@ | ||
package utils | ||
|
||
import "encoding/binary" | ||
|
||
func PrepareSignData(chainID uint64, data []byte) []byte { | ||
buf := make([]byte, 8) | ||
binary.BigEndian.PutUint64(buf, uint64(chainID)) | ||
|
||
return append(buf, data...) | ||
} |
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,18 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSign(t *testing.T) { | ||
chainID := uint64(1) | ||
data := []byte("test") | ||
|
||
expected := []byte{0, 0, 0, 0, 0, 0, 0, 1, 116, 101, 115, 116} | ||
actual := PrepareSignData(chainID, data) | ||
|
||
assert.Equal(t, len(expected), len(actual)) | ||
assert.Equal(t, expected, actual) | ||
} |