Skip to content
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: signer abstraction #395

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

shrimalmadhur
Copy link
Collaborator

Fixes # .

What Changed?

Reviewer Checklist

  • Code is well-documented
  • Code adheres to Go naming conventions
  • Code deprecates any old functionality before removing it

type Signer interface {
SignMessage(ctx context.Context, message [32]byte) ([]byte, error)

GetOperatorId() (string, error)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be context.Context here? it's a pure operation - as in it doesn't depend on network in any case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then no. Unless you think some implementation in the future might need to make this call over the network, for eg calling a contract?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait how does cerberus get operatorId? Doesn't it have to ask the remote signer over the network?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operatorId is just extracted out of public key. so that call just not need to go over the network since public key is provided by the caller when initializing the client.

}

func New(path, password string) (*Signer, error) {
keyPair, err := bls.ReadPrivateKeyFromFile(path, password)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need to be updated to handle the new format from https://github.com/Layr-Labs/bn254-keystore-go - will add that.

@@ -0,0 +1,9 @@
package bn254
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this all live in bn254? shouldnt signer interface be independent of signing scheme?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm you are right actually - although I just want the signer to be for BLS signer - the ethereum signer will have different interfaces. We can have this signer support bn254 or bls12381. would that be okay?

type Signer interface {
SignMessage(ctx context.Context, message [32]byte) ([]byte, error)

GetOperatorId() (string, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait how does cerberus get operatorId? Doesn't it have to ask the remote signer over the network?

type Signer struct {
}

func New(signerUrl, pubKeyHex, password string) *Signer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is password for here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

password to encrypt the keystore file stored in remote signer.

keyPair *bls.KeyPair
}

func New(path, password string) (*Signer, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewFromFile and NewFromHex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always from File that's why keystore. maybe I can create another implementation for plaintext? but I don't want anyone to use plaintext 😅

Comment on lines +24 to +26
signatureBytes := s.keyPair.SignMessage(message).Bytes()
var signature []byte
copy(signature[:], signatureBytes[:])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you have to copy like this? signatureBytes is a fixed array [32]byte or something?

Copy link
Collaborator Author

@shrimalmadhur shrimalmadhur Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signatureBytes is a fixed array [32]byte

Yep that's exactly why I need to copy.

@shrimalmadhur shrimalmadhur changed the title feat: bls signer abstraction feat: signer abstraction Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants