-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(adr-035): eots manager signing requests #184
Changes from 6 commits
412956e
0db0910
96d70b6
9a07632
8ad6696
94a1fb8
f53ca8b
676ecfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package eotsmanager | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
"github.com/babylonlabs-io/finality-provider/metrics" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/babylonlabs-io/finality-provider/metrics" | ||
|
||
"github.com/babylonlabs-io/babylon/crypto/eots" | ||
bbntypes "github.com/babylonlabs-io/babylon/types" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
|
@@ -29,6 +30,10 @@ const ( | |
MnemonicEntropySize = 256 | ||
) | ||
|
||
var ( | ||
ErrDoubleSign = errors.New("double sign") | ||
) | ||
|
||
var _ EOTSManager = &LocalEOTSManager{} | ||
|
||
type LocalEOTSManager struct { | ||
|
@@ -194,6 +199,20 @@ func (lm *LocalEOTSManager) CreateRandomnessPairList(fpPk []byte, chainID []byte | |
} | ||
|
||
func (lm *LocalEOTSManager) SignEOTS(fpPk []byte, chainID []byte, msg []byte, height uint64, passphrase string) (*btcec.ModNScalar, error) { | ||
record, found, err := lm.es.GetSignRecord(height) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not safe to use data directly from db. Better to have a counter part of the db type to have validated data |
||
if err != nil { | ||
return nil, fmt.Errorf("error getting sign record: %w", err) | ||
} else if found && record != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems we don't need |
||
if bytes.Equal(msg, record.BlockHash) { | ||
var s btcec.ModNScalar | ||
s.SetByteSlice(record.Signature) | ||
|
||
return &s, nil | ||
} | ||
|
||
return nil, ErrDoubleSign | ||
} | ||
|
||
privRand, _, err := lm.getRandomnessPair(fpPk, chainID, height, passphrase) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get private randomness: %w", err) | ||
|
@@ -208,7 +227,17 @@ func (lm *LocalEOTSManager) SignEOTS(fpPk []byte, chainID []byte, msg []byte, he | |
lm.metrics.IncrementEotsFpTotalEotsSignCounter(hex.EncodeToString(fpPk)) | ||
lm.metrics.SetEotsFpLastEotsSignHeight(hex.EncodeToString(fpPk), float64(height)) | ||
|
||
return eots.Sign(privKey, privRand, msg) | ||
signedBytes, err := eots.Sign(privKey, privRand, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
b := signedBytes.Bytes() | ||
if err := lm.es.SaveSignRecord(height, msg, fpPk, b[:]); err != nil { | ||
return nil, fmt.Errorf("failed to save signing record: %w", err) | ||
} | ||
|
||
return signedBytes, nil | ||
} | ||
|
||
func (lm *LocalEOTSManager) SignSchnorrSig(fpPk []byte, msg []byte, passphrase string) (*schnorr.Signature, error) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
option go_package = "github.com/babylonlabs-io/finality-provider/eotsmanager/proto"; | ||
|
||
// SigningRecord represents a record of a signing operation. | ||
message SigningRecord { | ||
bytes block_hash = 1; // The hash of the block. | ||
bytes public_key = 2; // The public key used for signing. | ||
bytes signature = 3; // The signature of the block. | ||
int64 timestamp = 4; // The timestamp of the signing operation, in Unix seconds. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move it to
eotsmanager/types/errors.go
?