-
Notifications
You must be signed in to change notification settings - Fork 3
/
sign.go
43 lines (36 loc) · 994 Bytes
/
sign.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
package faucet
import (
"fmt"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/std"
)
// signCfg specifies the sign configuration
type signCfg struct {
chainID string // the ID of the chain
accountNumber uint64 // the account number of the signer
sequence uint64 // the sequence of the signer
}
// signTransaction signs the specified transaction using
// the provided key and config
func signTransaction(tx *std.Tx, key crypto.PrivKey, cfg signCfg) error {
// Get the sign bytes
signBytes, err := tx.GetSignBytes(
cfg.chainID,
cfg.accountNumber,
cfg.sequence,
)
if err != nil {
return fmt.Errorf("unable to get tx signature payload, %w", err)
}
// Sign the transaction
signature, err := key.Sign(signBytes)
if err != nil {
return fmt.Errorf("unable to sign transaction, %w", err)
}
// Save the signature
tx.Signatures = append(tx.Signatures, std.Signature{
PubKey: key.PubKey(),
Signature: signature,
})
return nil
}