blob: 32963f1f764cc1132888f6fb15b99a03293abe6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package main
import (
"fmt"
"log"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func main() {
privateKey, err := crypto.HexToECDSA("fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19")
if err != nil {
log.Fatal(err)
}
data := []byte("decartography")
hash := crypto.Keccak256Hash(data)
fmt.Println(hash.Hex()) // 0xfe2b8f0bae0d344e95a421b9cc1a32ef07083cc85d007146259221fece9264a7
signature, err := crypto.Sign(hash.Bytes(), privateKey)
if err != nil {
log.Fatal(err)
}
fmt.Println(hexutil.Encode(signature))
}
|