-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (53 loc) · 1.49 KB
/
main.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"bufio"
"encoding/hex"
"fmt"
"log"
"os"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cKeys "github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/joho/godotenv"
)
// ModuleBasics is a mock module basic manager for testing
var ModuleBasics = module.NewBasicManager()
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
// Key added to your test keyring
user := os.Getenv("WALLET_KEY")
// Message to be signed
msg := os.Getenv("MSG")
appName := os.Getenv("APP_NAME")
appRootDir := os.Getenv("APP_ROOT_DIR")
backend := os.Getenv("BACKEND")
interfaceRegistry := codectypes.NewInterfaceRegistry()
std.RegisterInterfaces(interfaceRegistry)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
types.RegisterInterfaces(interfaceRegistry)
cdc := codec.NewProtoCodec(interfaceRegistry)
buf := bufio.NewReader(os.Stdin)
kb, err := cKeys.New(appName, backend, appRootDir, buf, cdc)
if err != nil {
log.Fatalf("%v", err)
}
bites := []byte(msg)
signature, pk, err := kb.Sign(user, bites)
if err != nil {
log.Fatalf("%v", err)
}
// Verify signature
if !pk.VerifySignature(bites, signature) {
log.Fatal("bad signature")
}
// Print signature
fmt.Println("Signature: ", hex.EncodeToString(signature[:]))
// Print public key
fmt.Println("Public Key: ", pk)
}