-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and test sr25519 signing in nostd
- Loading branch information
Showing
7 changed files
with
80 additions
and
3 deletions.
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
File renamed without changes.
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,24 @@ | ||
[package] | ||
name = "nostd-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.24" | ||
tracing-wasm = "0.2.1" | ||
console_error_panic_hook = "0.1.7" | ||
|
||
# This crate is not a part of the workspace, because we want to | ||
# enable the "web" feature here but don't want it enabled as part | ||
# of workspace builds. Also disable the "subxt" feature here because | ||
# we want to ensure it works in isolation of that. | ||
subxt-signer = { path = "../../", default-features = false, features = [ | ||
"sr25519", | ||
"ecdsa", | ||
"unstable-eth", | ||
] } | ||
|
||
# this shouldn't be needed, it's in workspace.exclude, but still | ||
# I get the complaint unless I add it... | ||
[workspace] |
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,51 @@ | ||
#[no_std] | ||
|
||
use subxt_signer::{ecdsa, eth, sr25519}; | ||
|
||
// Run the tests by calling: | ||
// | ||
// ```text | ||
// cargo test | ||
// ``` | ||
// | ||
// These are independent of any other package to ensure that nothing | ||
// else enabled the same feature flag that subxt-signer needs to work ok | ||
// (subxt seems to, for instance). | ||
|
||
#[test] | ||
fn sr25519_signing_works() { | ||
let alice = sr25519::dev::alice(); | ||
|
||
// There's some non-determinism in the signing, so this ensures that | ||
// the rand stuff is configured properly to run ok in wasm. | ||
let signature = alice.sign(b"Hello there"); | ||
assert!(sr25519::verify( | ||
&signature, | ||
b"Hello there", | ||
&alice.public_key() | ||
)); | ||
} | ||
|
||
#[test] | ||
fn ecdsa_signing_works() { | ||
let alice = ecdsa::dev::alice(); | ||
|
||
// There's some non-determinism in the signing, so this ensures that | ||
// the rand stuff is configured properly to run ok in wasm. | ||
let signature = alice.sign(b"Hello there"); | ||
assert!(ecdsa::verify( | ||
&signature, | ||
b"Hello there", | ||
&alice.public_key() | ||
)); | ||
} | ||
|
||
#[test] | ||
fn eth_signing_works() { | ||
let alice = eth::dev::alith(); | ||
|
||
// There's some non-determinism in the signing, so this ensures that | ||
// the rand stuff is configured properly to run ok in wasm. | ||
let signature = alice.sign(b"Hello there"); | ||
assert!(eth::verify(&signature, b"Hello there", &alice.public_key())); | ||
} |
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,2 @@ | ||
/target | ||
Cargo.lock |
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