-
Notifications
You must be signed in to change notification settings - Fork 179
/
txVerifier.go
104 lines (93 loc) · 3.12 KB
/
txVerifier.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package errors
import (
"github.com/onflow/flow-go/model/flow"
)
// NewInvalidProposalSignatureError constructs a new CodedError which indicates
// that no valid signature is provided for the proposal key.
func NewInvalidProposalSignatureError(
proposal flow.ProposalKey,
err error,
) CodedError {
return WrapCodedError(
ErrCodeInvalidProposalSignatureError,
err,
"invalid proposal key: public key %d on account %s does not have a "+
"valid signature",
proposal.KeyIndex,
proposal.Address)
}
// InvalidProposalSeqNumberError indicates that proposal key sequence number does not match the on-chain value.
type InvalidProposalSeqNumberError struct {
currentSeqNumber uint64
providedSeqNumber uint64
CodedError
}
// NewInvalidProposalSeqNumberError constructs a new InvalidProposalSeqNumberError
func NewInvalidProposalSeqNumberError(
proposal flow.ProposalKey,
currentSeqNumber uint64,
) CodedError {
return InvalidProposalSeqNumberError{
currentSeqNumber: currentSeqNumber,
providedSeqNumber: proposal.SequenceNumber,
CodedError: NewCodedError(
ErrCodeInvalidProposalSeqNumberError,
"invalid proposal key: public key %d on account %s has sequence "+
"number %d, but given %d",
proposal.KeyIndex,
proposal.Address,
currentSeqNumber,
proposal.SequenceNumber),
}
}
// CurrentSeqNumber returns the current sequence number
func (e InvalidProposalSeqNumberError) CurrentSeqNumber() uint64 {
return e.currentSeqNumber
}
// ProvidedSeqNumber returns the provided sequence number
func (e InvalidProposalSeqNumberError) ProvidedSeqNumber() uint64 {
return e.providedSeqNumber
}
// NewInvalidPayloadSignatureError constructs a new CodedError which indicates
// that signature verification for a key in this transaction has failed. This
// error is the result of failure in any of the following conditions:
// - provided hashing method is not supported
// - signature size or format is invalid
// - signature verification failed
func NewInvalidPayloadSignatureError(
txnSig flow.TransactionSignature,
err error,
) CodedError {
return WrapCodedError(
ErrCodeInvalidPayloadSignatureError,
err,
"invalid payload signature: public key %d on account %s does not have"+
" a valid signature",
txnSig.KeyIndex,
txnSig.Address)
}
func IsInvalidPayloadSignatureError(err error) bool {
return HasErrorCode(err, ErrCodeInvalidPayloadSignatureError)
}
// NewInvalidEnvelopeSignatureError constructs a new CodedError which indicates
// that signature verification for a envelope key in this transaction has
// failed. Tthis error is the result of failure in any of the following
// conditions:
// - provided hashing method is not supported
// - signature size or format is invalid
// - signature verification failed
func NewInvalidEnvelopeSignatureError(
txnSig flow.TransactionSignature,
err error,
) CodedError {
return WrapCodedError(
ErrCodeInvalidEnvelopeSignatureError,
err,
"invalid envelope key: public key %d on account %s does not have a "+
"valid signature",
txnSig.KeyIndex,
txnSig.Address)
}
func IsInvalidEnvelopeSignatureError(err error) bool {
return HasErrorCode(err, ErrCodeInvalidEnvelopeSignatureError)
}