Skip to content

Commit

Permalink
fix: make PrivateKey.SignTransaction() fallible
Browse files Browse the repository at this point in the history
  • Loading branch information
janaakhterov committed Nov 19, 2020
1 parent 728c00c commit 4ad5233
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 4 additions & 6 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,15 @@ func (pk PublicKey) toSignaturePairProtobuf(signature []byte) *proto.SignaturePa
}
}

func (sk PrivateKey) SignTransaction(transaction Transaction) []byte {
func (sk PrivateKey) SignTransaction(transaction Transaction) ([]byte, error) {
transaction.requireExactNode()

if len(transaction.transactions) == 0 {
return make([]byte, 0)
return make([]byte, 0), errTransactionRequiresSingleNodeAccountID
}

transactionToSign := transaction.transactions[0]
signature := sk.Sign(transactionToSign.GetBodyBytes())

signature := sk.Sign(transaction.transactions[0].GetBodyBytes())
transaction.AddSignature(sk.PublicKey(), signature)

return signature
return signature, nil
}
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var errNoClientProvided = errors.New("`client` must be provided and have an oper
var errTransactionIsNotFrozen = errors.New("transaction is not frozen")
var errFailedToDeserializeBytes = errors.New("Failed to deserialize bytes")
var errNoTransactionInBytes = errors.New("No transaction was found in bytes")
var errTransactionRequiresSingleNodeAccountID = errors.New("`PrivateKey.SignTransaction()` requires `Transaction` to have a single node `AccountID` set")

type ErrInvalidNodeAccountIDSet struct {
NodeAccountID AccountID
Expand Down

0 comments on commit 4ad5233

Please sign in to comment.