-
-
Notifications
You must be signed in to change notification settings - Fork 51
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: sr25519 #360
feat: sr25519 #360
Conversation
b684305
to
7674149
Compare
ae7d99e
to
b629749
Compare
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.
Hi @developerfred this is a difficult issue and this looks like a promising start :) I have added some comments to the PR and also expanded the issue to clarify the scope a bit more.
I also added the prefered keys to use for sofia
and charlotte
this way its easier to reliably test the PR.
Thank you for your initial work on this.
23fe085
to
d6207c2
Compare
c4ab1a6
to
48e688e
Compare
48e688e
to
24e95be
Compare
crypto/sr25519/private.go
Outdated
func (pk PrivateKey) Bytes() []byte { | ||
b := pk.key | ||
|
||
return b[:] |
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.
unslice: could simplify b[:] to b (from gocritic
)
c408023
to
9fb5149
Compare
86afdc7
to
a0a714f
Compare
crypto/sr25519/sr25519test/keys.go
Outdated
) | ||
|
||
// SofiaPrivateKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var SofiaPrivateKey crypto.PrivateKey //nolint: gochecknoglobals |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
crypto/sr25519/sr25519test/keys.go
Outdated
// SofiaPrivateKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var SofiaPrivateKey crypto.PrivateKey //nolint: gochecknoglobals | ||
// SofiaPublicKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var SofiaPublicKey crypto.PublicKey //nolint: gochecknoglobals |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
crypto/sr25519/sr25519test/keys.go
Outdated
// SofiaPublicKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var SofiaPublicKey crypto.PublicKey //nolint: gochecknoglobals | ||
// CharlottePrivateKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var CharlottePrivateKey crypto.PrivateKey //nolint: gochecknoglobals |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
return k.FromUniformBytes(b) | ||
} | ||
|
||
func witness(nonce []byte) (*ristretto255.Scalar, error) { |
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.
witness
- nonce
is unused (from unparam
)
h := sha512.Sum512(seed[:]) | ||
key := [32]byte{} | ||
nonce := [32]byte{} | ||
copy(key[:], h[:32]) |
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.
only cuddled expressions if assigning variable or using from line above (from wsl
)
if err := a.Decode(pk.key); err != nil { | ||
return false | ||
} | ||
Rp := ristretto255.NewElement() |
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.
assignments should only be cuddled with other assignments (from wsl
)
|
||
// https://github.com/w3f/schnorrkel/blob/718678e51006d84c7d8e4b6cde758906172e74f8/src/scalars.rs#L18 | ||
func divideScalarByCofactor(s []byte) []byte { | ||
l := len(s) - 1 |
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.
mnd: Magic number: 1, in detected (from gomnd
)
l := len(s) - 1 | ||
low := byte(0) | ||
for i := range s { | ||
r := s[l-i] & 0b00000111 // remainder |
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.
mnd: Magic number: 0b00000111, in detected (from gomnd
)
r := s[l-i] & 0b00000111 // remainder | ||
s[l-i] >>= 3 | ||
s[l-i] += low | ||
low = r << 5 |
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.
mnd: Magic number: 5, in detected (from gomnd
)
crypto/sr25519/sign.go
Outdated
} | ||
|
||
func (s *signature) Decode(sig []byte) error { // https://github.com/w3f/schnorrkel/blob/4112f6e8cb684a1cc6574f9097497e1e302ab9a8/src/sign.rs#L114 | ||
if len(sig) != 64 { |
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.
mnd: Magic number: 64, in detected (from gomnd
)
crypto/sr25519/sr25519test/keys.go
Outdated
// CharlottePublicKey sr25519 key for testing purposes. Key is compromised do not use on mainnet's. | ||
var CharlottePublicKey crypto.PublicKey //nolint: gochecknoglobals test key | ||
|
||
//nolint: gochecknoinits |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
crypto/sr25519/sr25519test/keys.go
Outdated
//nolint: gochecknoinits | ||
func init() { | ||
var err error | ||
SofiaPrivateKey, err = sr25519.PrivateKeyFromBytes(encodingtest.MustDecodeHex("5c6d7adf75bda1180c225d25f3aa8dc174bbfb3cddee11ae9a85982f6faf791a")) //nolint: lll |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
crypto/sr25519/sr25519test/keys.go
Outdated
|
||
SofiaPublicKey = SofiaPrivateKey.PublicKey() | ||
|
||
CharlottePrivateKey, err = sr25519.PrivateKeyFromBytes(encodingtest.MustDecodeHex("23b063a581fd8e5e847c4e2b9c494247298791530f5293be369e8bf23a45d2bd")) //nolint: lll |
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.
whyNoLint: include an explanation for nolint directive (from gocritic
)
// form k | ||
b := c.ExtractBytes(label, 64) | ||
k := ristretto255.NewScalar() | ||
return k.FromUniformBytes(b) |
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.
return statements should not be cuddled if block has more than two lines (from wsl
)
copy(out[:32], s.R.Encode([]byte{})) | ||
copy(out[32:], s.S.Encode([]byte{})) | ||
out[63] |= 128 | ||
return out |
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.
return statements should not be cuddled if block has more than two lines (from wsl
)
sig[63] &= 127 | ||
|
||
s.S = ristretto255.NewScalar() | ||
return s.S.Decode(sig[32:]) |
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.
return statements should not be cuddled if block has more than two lines (from wsl
)
|
||
// https://github.com/w3f/schnorrkel/blob/718678e51006d84c7d8e4b6cde758906172e74f8/src/scalars.rs#L18 | ||
func divideScalarByCofactor(s []byte) []byte { | ||
l := len(s) - 1 |
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.
mnd: Magic number: 1, in detected (from gomnd
)
low := byte(0) | ||
|
||
for i := range s { | ||
r := s[l-i] & 0b00000111 // remainder |
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.
mnd: Magic number: 0b00000111, in detected (from gomnd
)
r := s[l-i] & 0b00000111 // remainder | ||
s[l-i] >>= 3 | ||
s[l-i] += low | ||
low = r << 5 |
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.
mnd: Magic number: 5, in detected (from gomnd
)
crypto/sr25519/sign.go
Outdated
} | ||
|
||
func (s *signature) Decode(sig []byte) error { // https://github.com/w3f/schnorrkel/blob/4112f6e8cb684a1cc6574f9097497e1e302ab9a8/src/sign.rs#L114 | ||
if len(sig) != 64 { |
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.
mnd: Magic number: 64, in detected (from gomnd
)
if err != nil { | ||
return nil, ErrSharedSecretGenerate | ||
} | ||
return sharedSecret[:], nil |
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.
return statements should not be cuddled if block has more than two lines (from wsl
)
crypto/sr25519/sign.go
Outdated
} | ||
|
||
func (s *signature) Decode(sig []byte) error { // https://github.com/w3f/schnorrkel/blob/4112f6e8cb684a1cc6574f9097497e1e302ab9a8/src/sign.rs#L114 | ||
if len(sig) != 64 { |
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.
mnd: Magic number: 64, in detected (from gomnd
)
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.
Thanks @developerfred for all your contributions to this PR 😄 change look good, its ready to merge 👍
sr25519 - Module
Struct files: Package sr25519 schnorrkel
Default Functions
Nacl
fixes #327
fixes #505