-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented public key registration in case of eth style signatures
- Loading branch information
Showing
4 changed files
with
149 additions
and
60 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,37 @@ | ||
package chain | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/crypto/sha3" | ||
) | ||
|
||
// Taken from github.com/ava-labs/coreth/accounts/accounts.go to avoid dependency on coreth | ||
|
||
// TextHash is a helper function that calculates a hash for the given message that can be | ||
// safely used to calculate a signature from. | ||
// | ||
// The hash is calculated as | ||
// | ||
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). | ||
// | ||
// This gives context to the signed message and prevents signing of transactions. | ||
func TextHash(data []byte) []byte { | ||
hash, _ := TextAndHash(data) | ||
return hash | ||
} | ||
|
||
// TextAndHash is a helper function that calculates a hash for the given message that can be | ||
// safely used to calculate a signature from. | ||
// | ||
// The hash is calculated as | ||
// | ||
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). | ||
// | ||
// This gives context to the signed message and prevents signing of transactions. | ||
func TextAndHash(data []byte) ([]byte, string) { | ||
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), string(data)) | ||
hasher := sha3.NewLegacyKeccak256() | ||
hasher.Write([]byte(msg)) | ||
return hasher.Sum(nil), msg | ||
} |
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