-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] #166: Signatures and Query all Accounts
Signed-off-by: Sam H. Smith <sam.henning.smith@protonmail.com>
- Loading branch information
Showing
11 changed files
with
176 additions
and
39 deletions.
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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
# Import dependency | ||
import iroha | ||
|
||
# Example ed25519 key pair | ||
key_pair = iroha.KeyPair.from_json(""" | ||
{ | ||
"public_key": "ed01207233BFC89DCBD68C19FDE6CE6158225298EC1131B6A130D1AEB454C1AB5183C0", | ||
"private_key": { | ||
"digest_function": "ed25519", | ||
"payload": "9ac47abf59b356e0bd7dcbbbb4dec080e302156a48ca907e47cb6aea1d32719e7233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c0" | ||
} | ||
} | ||
""") | ||
|
||
# Sign the user's email address: | ||
signature = key_pair.sign(b"email@address") | ||
|
||
# Retrieve the encoded Hex string of the user's `signature` | ||
print(f"Encoded signature:\n{bytes(signature).hex()}") |
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,28 @@ | ||
# Import dependency | ||
import iroha | ||
|
||
# Example signed transaction, encoded with SCALE codec and represented as hex string: | ||
encoded_transaction = "010400807233bfc89dcbd68c19fde6ce6158225298ec1131b6a130d1aeb454c1ab5183c00101b65301ad504ea1430c171379ed45226bfc5fe770a216815654e20491626bbf857247bee73f6790314f892ed1a3e4c18cc6815ce9ff85ce956e0f9ab46605bc093962fb8f8e01000028776f6e6465726c616e6414616c6963650008000d09020c786f7228776f6e6465726c616e6401000000020d1402000000000000000002000000000000000d08030c786f7228776f6e6465726c616e6428776f6e6465726c616e6414616c69636501a0860100000000000000" | ||
|
||
# Example ed25519 key pair | ||
key_pair = iroha.KeyPair.from_json(""" | ||
{ | ||
"public_key": "ed0120BA85186D0F8C995F8DEA6C95B3EDA321C88C983D4F6B28E079CC121B40AA8E00", | ||
"private_key": { | ||
"digest_function": "ed25519", | ||
"payload": "1b9068cd9b4acaabf1e8c66c622d9bd15ff3b04099819b750e3987be73d2096fba85186d0f8c995f8dea6c95b3eda321c88c983d4f6b28e079cc121b40aa8e00" | ||
} | ||
} | ||
""") | ||
|
||
# Decode the transaction: | ||
transaction = iroha.SignedTransaction.decode_hex(encoded_transaction) | ||
|
||
# Sign the transaction with the provided private key: | ||
transaction.append_signature(key_pair) | ||
|
||
# Re-encode the transaction: | ||
re_encoded_transaction = transaction.encode_hex() | ||
|
||
# Retrieve the encoded Hex string of the transaction: | ||
print(f"Signed and encoded transaction:\n{re_encoded_transaction}") |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use pyo3::{ | ||
exceptions::{PyRuntimeError, PyValueError}, | ||
prelude::*, | ||
}; | ||
|
||
use super::crypto::PyKeyPair; | ||
use iroha_data_model::prelude::SignedTransaction; | ||
use parity_scale_codec::{Decode, Encode}; | ||
|
||
use super::PyMirror; | ||
|
||
#[pyclass(name = "SignedTransaction")] | ||
#[derive(Clone, derive_more::From, derive_more::Into, derive_more::Deref)] | ||
pub struct PySignedTransaction(pub SignedTransaction); | ||
|
||
impl PyMirror for SignedTransaction { | ||
type Mirror = PySignedTransaction; | ||
|
||
fn mirror(self) -> PyResult<Self::Mirror> { | ||
Ok(PySignedTransaction(self)) | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PySignedTransaction { | ||
#[staticmethod] | ||
fn decode_hex(encoded: &str) -> PyResult<Self> { | ||
let bytes = hex::decode(encoded) | ||
.map_err(|e| PyValueError::new_err(format!("Failed to decode hex: {e}")))?; | ||
let pk = SignedTransaction::decode(&mut bytes.as_slice()) | ||
.map_err(|e| PyValueError::new_err(format!("Failed to decode transaction: {e}")))?; | ||
Ok(Self(pk)) | ||
} | ||
fn encode_hex(&self) -> String { | ||
hex::encode(self.encode()) | ||
} | ||
fn append_signature(&mut self, key_pair: &PyKeyPair) -> PyResult<()> { | ||
self.0 = self | ||
.0 | ||
.clone() | ||
.sign(key_pair.0.clone()) | ||
.map_err(|e| PyValueError::new_err(format!("Failed to sign transaction: {e}")))?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn register_items(_py: Python<'_>, module: &PyModule) -> PyResult<()> { | ||
module.add_class::<PySignedTransaction>()?; | ||
Ok(()) | ||
} |
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