-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.go
55 lines (48 loc) · 1.38 KB
/
verify.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
// Copyright 2024 NASD Inc.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
package adr36
import (
"context"
api "adr36.dev/api"
tx "cosmossdk.io/api/cosmos/tx/v1beta1"
"cosmossdk.io/x/tx/signing"
"cosmossdk.io/x/tx/signing/aminojson"
"github.com/cosmos/cosmos-proto/anyutil"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/protobuf/types/known/anypb"
)
func VerifySignature(pubkey cryptotypes.PubKey, data []byte, signature []byte) bool {
handler := aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{})
rawPubkey, _ := codectypes.NewAnyWithValue(pubkey)
msg, _ := anyutil.New(&api.MsgSignData{
Signer: sdk.AccAddress(pubkey.Address()).String(),
Data: data,
})
bz, _ := handler.GetSignBytes(
context.Background(),
signing.SignerData{
Address: sdk.AccAddress(pubkey.Address()).String(),
ChainID: "",
AccountNumber: 0,
Sequence: 0,
PubKey: &anypb.Any{
TypeUrl: rawPubkey.TypeUrl,
Value: rawPubkey.Value,
},
},
signing.TxData{
Body: &tx.TxBody{
Messages: []*anypb.Any{msg},
},
AuthInfo: &tx.AuthInfo{
Fee: &tx.Fee{},
},
},
)
return pubkey.VerifySignature(bz, signature)
}