-
Notifications
You must be signed in to change notification settings - Fork 290
Add ECIES encryption support to subxt-signer #2198
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ std = [ | |
| # ecdsa compiling to WASM on my mac; following this comment helped: | ||
| # https://github.com/rust-bitcoin/rust-bitcoin/issues/930#issuecomment-1215538699 | ||
| sr25519 = ["schnorrkel"] | ||
| ecies = ["sr25519", "schnorrkel/ecies"] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether this feature would be better called "sr25519-ecies" since it seems specific to that (and then it would be a stronger hint that this enables some feature in the sr25519 module) |
||
| ecdsa = ["secp256k1"] | ||
| unstable-eth = ["keccak-hash", "ecdsa", "secp256k1", "bip32"] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright 2019-2026 Parity Technologies (UK) Ltd. | ||
| // This file is dual-licensed as Apache-2.0 or GPL-3.0. | ||
| // see LICENSE for license details. | ||
|
|
||
| //! ECIES encryption/decryption example using sr25519 dev accounts. | ||
|
|
||
| use subxt_signer::sr25519; | ||
|
|
||
| fn main() { | ||
| let alice = sr25519::dev::alice(); | ||
| let bob = sr25519::dev::bob(); | ||
|
|
||
| let plaintext = b"The quick brown fox jumps over the lazy dog"; | ||
| let ctx = b"example-ecies-v1"; | ||
|
|
||
| // Alice encrypts a message for Bob | ||
| let encrypted = alice | ||
| .encrypt(plaintext, &bob.public_key(), ctx) | ||
| .expect("encryption failed"); | ||
|
|
||
| println!("Plaintext: {} bytes", plaintext.len()); | ||
| println!("Ciphertext: {} bytes (overhead: {} bytes)", encrypted.len(), encrypted.len() - plaintext.len()); | ||
|
|
||
| // Bob decrypts | ||
| let decrypted = bob.decrypt(&encrypted, ctx).expect("decryption failed"); | ||
| assert_eq!(&decrypted[..], plaintext); | ||
| println!("Bob decrypted successfully: {:?}", core::str::from_utf8(&decrypted).unwrap()); | ||
|
|
||
| // Alice cannot decrypt (wrong key) | ||
| let result = alice.decrypt(&encrypted, ctx); | ||
| assert!(result.is_err()); | ||
| println!("Alice cannot decrypt Bob's message: {:?}", result.unwrap_err()); | ||
|
|
||
| // Wrong context fails | ||
| let result = bob.decrypt(&encrypted, b"wrong-context"); | ||
| assert!(result.is_err()); | ||
| println!("Wrong context fails: {:?}", result.unwrap_err()); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Until the original non-fork version of this has the relevant feature and is available on crates.io, we won't be able to merge this: git URLs prevent publishing, and I would not want to deviate from the Parity crate, in large part for security reasons :)