Skip to content

Commit

Permalink
Fix and test sr25519 signing in nostd
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdw committed Nov 19, 2024
1 parent 0dbcdbd commit f12c1a4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ hmac = { workspace = true }
zeroize = { workspace = true }
bip39 = { workspace = true }
bip32 = { workspace = true, features = ["alloc", "secp256k1"], optional = true }
schnorrkel = { workspace = true, optional = true }
schnorrkel = { workspace = true, optional = true, features = ["getrandom"] }
secp256k1 = { workspace = true, optional = true, features = [
"alloc",
"recovery",
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions signer/tests/no-std/Cargo.toml
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]
51 changes: 51 additions & 0 deletions signer/tests/no-std/tests/no_std.rs
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()));
}
2 changes: 2 additions & 0 deletions signer/tests/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ console_error_panic_hook = "0.1.7"
# 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 = [
subxt-signer = { path = "../../", default-features = false, features = [
"web",
"sr25519",
"ecdsa",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
// Run the tests by calling:
//
// ```text
// wasm-pack test --firefox --headless`
// wasm-pack test --firefox --headless
// ```
//
// These are independent of any other package to ensure that nothing
Expand Down

0 comments on commit f12c1a4

Please sign in to comment.