Skip to content

Add a keypair type#51

Merged
noot merged 12 commits intomasterfrom
jimmy/createKeypairType
Jul 11, 2022
Merged

Add a keypair type#51
noot merged 12 commits intomasterfrom
jimmy/createKeypairType

Conversation

@jimjbrettj
Copy link
Contributor

@jimjbrettj jimjbrettj commented Jan 4, 2022

Created a keypair type that contains both a public and private key and a corresponding sign function.
I can further refactor to utilize the keypair if need be (ie. have GenerateKeypair return a keypair)

closes #44

@jimjbrettj jimjbrettj requested a review from noot January 4, 2022 23:25
@jimjbrettj jimjbrettj linked an issue Jan 4, 2022 that may be closed by this pull request
@jimjbrettj jimjbrettj requested a review from noot January 6, 2022 22:48
@jimjbrettj
Copy link
Contributor Author

@noot Implemented VRF sign and verify for keypair type as well as a secretKey to KeyPair method, so this should be good to go. Let me know if you want anything else!

@jimjbrettj
Copy link
Contributor Author

@EclesioMeloJunior updated!

keys.go Outdated
return &PublicKey{key: e.ScalarBaseMult(sc)}, nil
}

// Keypair Generates the keypair corresponding to this SecretKey
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Keypair Generates the keypair corresponding to this SecretKey
// Keypair returns the keypair corresponding to this SecretKey

}

// NewKeypair creates a new keypair from a public key and secret key
func NewKeypair(pk *PublicKey, sk *SecretKey) *Keypair {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a *Keypair.PublicKey() function to return the public key so that PublicKey.Verify() can be called? alternatively you can make a Verify function on Keypair

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm thinking ill make a Verify function on Keypair if that works for you!

vrf.go Outdated
Comment on lines +161 to +172
sk := kp.secretKey
p, err := sk.vrfCreateHash(t)
if err != nil {
return nil, nil, err
}

extra := merlin.NewTranscript(VRFLabel)
proof, err := sk.dleqProve(extra, p)
if err != nil {
return nil, nil, err
}
return p, proof, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

can you just call kp.secretKey.VrfSign() instead of copy pasting?

vrf.go Outdated
Comment on lines +177 to +204
if t == nil {
return false, errors.New("transcript provided is nil")
}

if out == nil {
return false, errors.New("output provided is nil")
}

if proof == nil {
return false, errors.New("proof provided is nil")
}

if kp.publicKey == nil {
return false, errors.New("publicKey is nil")
}

pk := kp.publicKey
if pk.key.Equal(publicKeyAtInfinity) == 1 {
return false, errPublicKeyAtInfinity
}

inout, err := out.AttachInput(pk, t)
if err != nil {
return false, err
}

t0 := merlin.NewTranscript(VRFLabel)
return pk.dleqVerify(t0, inout, proof)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, just call kp.publicKey.VrfVerify()

@jimjbrettj
Copy link
Contributor Author

@noot updated! Let me know if there's anything else to change

@jimjbrettj jimjbrettj requested a review from noot July 8, 2022 17:48
Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

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

heck yeah

@noot noot merged commit 027d287 into master Jul 11, 2022
@noot noot deleted the jimmy/createKeypairType branch July 11, 2022 12:20
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.

create Keypair type

3 participants