-
Notifications
You must be signed in to change notification settings - Fork 18
Add support for sr25519 signatures #171
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
Open
green-jay
wants to merge
17
commits into
near:main
Choose a base branch
from
green-jay:add-sr25519
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.
+478
−3
Open
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2cc4251
Add support for sr25519 signatures
green-jay 75bc40c
Merge branch 'main' into add-sr25519
green-jay 3768596
fmt
green-jay 2213361
Merge branch 'main' into add-sr25519
green-jay 924742b
Merge branch 'near:main' into add-sr25519
green-jay dea3adf
update fn comment
green-jay 375db8e
Merge branch 'main' into feat/sr25519
mitinarseny 48a291b
chore
mitinarseny 658e317
chore
mitinarseny c967214
chore
mitinarseny 4cdfa3d
Add real wallet signature test
green-jay a1ce794
refactor
mitinarseny bc17786
chore
mitinarseny eced429
chore: make clippy happy
mitinarseny 012d0b8
move wrapping to verification
green-jay ca7d188
chore: remove unused deps
mitinarseny a377475
Merge branch 'main' into add-sr25519
mitinarseny 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| use defuse_sr25519::SignedSr25519Payload; | ||
| use near_sdk::serde::{Deserialize, Serialize, de::DeserializeOwned}; | ||
|
|
||
| use super::{DefusePayload, ExtractDefusePayload}; | ||
|
|
||
| impl<T> ExtractDefusePayload<T> for SignedSr25519Payload | ||
| where | ||
| T: DeserializeOwned, | ||
| { | ||
| type Error = near_sdk::serde_json::Error; | ||
|
|
||
| fn extract_defuse_payload(self) -> Result<DefusePayload<T>, Self::Error> { | ||
| near_sdk::serde_json::from_str(&self.message) | ||
| } | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use schnorrkel::{PublicKey as SchnorrkelPublicKey, Signature as SchnorrkelSignature}; | ||
|
|
||
| use super::{Curve, CurveType, TypedCurve}; | ||
|
|
||
| pub struct Sr25519; | ||
|
|
||
| impl Curve for Sr25519 { | ||
| type PublicKey = [u8; 32]; | ||
| type Signature = [u8; 64]; | ||
|
|
||
| type Message = [u8]; | ||
| type VerifyingKey = Self::PublicKey; | ||
|
|
||
| #[inline] | ||
| fn verify( | ||
| signature: &Self::Signature, | ||
| message: &Self::Message, | ||
| public_key: &Self::VerifyingKey, | ||
| ) -> Option<Self::PublicKey> { | ||
| let public_key_parsed = SchnorrkelPublicKey::from_bytes(public_key).ok()?; | ||
| let signature_parsed = SchnorrkelSignature::from_bytes(signature).ok()?; | ||
|
|
||
| // verify_simple in schnorrkel 0.11 signature is: | ||
| // pub fn verify_simple(&self, ctx: &[u8], msg: &[u8], signature: &Signature) | ||
| // Using "substrate" as the default context following Substrate/Polkadot convention | ||
| public_key_parsed | ||
| .verify_simple(b"substrate", message, &signature_parsed) | ||
mitinarseny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .ok()?; | ||
|
|
||
| Some(*public_key) | ||
| } | ||
| } | ||
|
|
||
| impl TypedCurve for Sr25519 { | ||
| const CURVE_TYPE: CurveType = CurveType::Sr25519; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.