Add NewSecretKeyFromEd25519Bytes#59
Merged
jimjbrettj merged 3 commits intoChainSafe:masterfrom May 4, 2023
Merged
Conversation
https://github.com/w3f/schnorrkel/blob/ab3e3d609cd8b9eefbe0333066f698c40fd09582/src/keys.rs#L495-L533 This is useful for working with the exported polkadot.js account JSON file.
noot
reviewed
May 2, 2023
| } | ||
| } | ||
|
|
||
| func NewSecretKeyFromEd25519Bytes(b [SecretKeySize + 32]byte) *SecretKey { |
Contributor
There was a problem hiding this comment.
Suggested change
| func NewSecretKeyFromEd25519Bytes(b [SecretKeySize + 32]byte) *SecretKey { | |
| func NewSecretKeyFromEd25519Bytes(b [SecretKeySize + NonceSize]byte) *SecretKey { |
add a const NonceSize = 32 perhaps?
Contributor
Author
There was a problem hiding this comment.
If you look at the file, you'll see the number 32 all over the place. I don't want to refactor the whole file in this pull request. In my view the refactoring (which I agree should happen) should probably bring the constants closer to the rust implementation.
noot
reviewed
May 2, 2023
keys.go
Outdated
Comment on lines
+120
to
+123
| copy(sk.key[:], b[:32]) | ||
| t := divideScalarByCofactor(sk.key[:]) | ||
|
|
||
| copy(sk.key[:], t) |
Contributor
There was a problem hiding this comment.
Suggested change
| copy(sk.key[:], b[:32]) | |
| t := divideScalarByCofactor(sk.key[:]) | |
| copy(sk.key[:], t) | |
| copy(sk.key[:], divideScalarByCofactor(b[:32])) |
Contributor
Author
There was a problem hiding this comment.
This suggested change is not correct, because divideScalarByCofactor actually changes the slice in argument. But I'll commit the following, that has one copy less. Thanks.
diff --git a/keys.go b/keys.go
index 4ebfe1d..da0cf5b 100644
--- a/keys.go
+++ b/keys.go
@@ -118,9 +118,8 @@ func NewSecretKeyFromEd25519Bytes(b [SecretKeySize + 32]byte) *SecretKey {
}
copy(sk.key[:], b[:32])
- t := divideScalarByCofactor(sk.key[:])
+ divideScalarByCofactor(sk.key[:])
- copy(sk.key[:], t)
copy(sk.nonce[:], b[32:])
return sk
Contributor
|
@oldgreen Thanks for this! All looks good to me, I believe you just still need to sign the contributor agreement |
timwu20
approved these changes
May 4, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://github.com/w3f/schnorrkel/blob/ab3e3d609cd8b9eefbe0333066f698c40fd09582/src/keys.rs#L495-L533
This is useful for working with the exported polkadot.js account JSON file.