-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add secp256k1 verify and pubKey recovery function #583
Open
heliuchuan
wants to merge
15
commits into
main
Choose a base branch
from
addsecpverify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−4
Open
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
84bbbdb
Add secp256k1 verify and pubKey recovery function
heliuchuan 4da2524
update CL
heliuchuan 6f421b9
add docstring
heliuchuan 55f8fa6
add docstring
heliuchuan c428573
update
heliuchuan c855a31
update
heliuchuan 677894c
Merge branch 'main' into addsecpverify
heliuchuan 1410d0a
fix cycle
heliuchuan dca4159
add whitespace
heliuchuan a1dba8a
run fmt
heliuchuan b1e3654
change bcsBytes to toUint8Array
heliuchuan c7d0f07
address comments
heliuchuan deab85a
use anypubkey static func
heliuchuan b764949
Merge branch 'main' into addsecpverify
heliuchuan 3b45a87
fix lint
heliuchuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { HexInput, isHexInput } from "../../types"; | ||
import { Secp256k1Signature } from "./secp256k1"; | ||
import { AnySignature } from "./singleKey"; | ||
|
||
export function toSecp256k1Signature(signature: HexInput | Secp256k1Signature | AnySignature): Secp256k1Signature { | ||
if (isHexInput(signature)) { | ||
return new Secp256k1Signature(signature); | ||
} | ||
if (AnySignature.isInstance(signature)) { | ||
if (Secp256k1Signature.isInstance(signature.signature)) { | ||
return signature.signature; | ||
} | ||
throw new Error("AnySignature variant is not Secp256k1"); | ||
} | ||
return signature; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
why do we accept
AnySignature
if we only verify forSecp256k1Account
? why isSecp256k1Signature
is not part ofAnySignature
? Also, why do we acceptHexInput
as a signature? dont we want to make sure the function accepts a valid signature?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.
I agree, public key recovery should be in the signature to return. I don't think it belongs at the account level given you can't recover the private key
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.
Because Secp256k1Account does not exist. SingleKeyAccount exists which returns AnySignature when it signs something. You can get the inner Secp256k1Signature via signature.signature, but you would still have to type check it into Secp256k1Signature. Having the function handle it seems better DevX
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.
@gregnazario not sure what you are suggesting
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.
Oh and HexInput is again for convenience. The function will check signature validity.
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.
I also would expect this function to be in a different place than
Account
.I think
Secp256k1PublicKey.fromMessageAndSignature
makes total sense (fromSignedMessage
could be even more concise).Ideally that's all the devs would need, and they could do the following:
now.. how can we make this even easier / more concise?
Secp256k1PublicKey
toAnyPublicKey
is a bit annoying, maybe we can have the constructor there instead:AnyPublicKey.fromSecp256k1SignedMessage({ message, signature })
verifyAuthenticationKey({ authKey, accountAddress })
which could live in theapi
to avoid dependency cyclesThere 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.
I really hate the
AnyPublicKey
name ughThere 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.
So the problem is you need to look up the auth key with the address, and only via the auth key can you figure out which public key is correct. If a recovery is provided 2 public keys would be returned.
I'm down for AnyPublicKey.fromSecp256k1SignedMessage({ message, signature }) though
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.
Yeah I re-evaluated it and did similar here aptos-labs/aptos-go-sdk#108
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.
Oh I see, gotcha makes sense