-
Notifications
You must be signed in to change notification settings - Fork 289
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 all commits
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,42 @@ | ||
| // 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 alice_vk = alice.viewing_key(); | ||
| let bob_vk = bob.viewing_key(); | ||
|
|
||
| let plaintext = b"The quick brown fox jumps over the lazy dog"; | ||
| let ctx = b"example-ecies"; | ||
|
|
||
| // Alice encrypts a message for Bob | ||
| let encrypted = alice | ||
| .encrypt(plaintext, bob_vk.ivk_public(), ctx, alice_vk.ovk()) | ||
| .expect("encryption failed"); | ||
|
|
||
| println!("Plaintext: {} bytes", plaintext.len()); | ||
| println!("Ciphertext: {} bytes (overhead: {} bytes)", encrypted.len(), encrypted.len() - plaintext.len()); | ||
|
|
||
| // Bob decrypts with his viewing key | ||
| let decrypted = bob_vk.decrypt_incoming(&encrypted, ctx).expect("decryption failed"); | ||
| assert_eq!(&decrypted[..], plaintext); | ||
| println!("Bob decrypted: {:?}", core::str::from_utf8(&decrypted).unwrap()); | ||
|
|
||
| // Alice re-reads her outgoing message | ||
| let outgoing = alice_vk | ||
| .decrypt_outgoing(&encrypted, bob_vk.ivk_public(), ctx) | ||
| .expect("outgoing decryption failed"); | ||
| assert_eq!(&outgoing[..], plaintext); | ||
| println!("Alice re-read outgoing: {:?}", core::str::from_utf8(&outgoing).unwrap()); | ||
|
|
||
| // Wrong context fails | ||
| let result = bob_vk.decrypt_incoming(&encrypted, b"wrong-context"); | ||
| assert!(result.is_err()); | ||
| println!("Wrong context fails: {:?}", result.unwrap_err()); | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 :)