Skip to content

Commit 49b53be

Browse files
authored
Merge pull request #489 from hashgraph/sr/flows
2 parents fb0f07c + 4a54810 commit 49b53be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3327
-58
lines changed

sdk/rust/Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ tokio = { version = "1.24.2", features = ["rt-multi-thread"] }
4747
tonic = "0.8.0"
4848
tinystr = "0.7.0"
4949
arc-swap = "1.6.0"
50+
rlp = "0.5.2"
51+
bytes = "1.2.1"
5052

5153
[dependencies.rust_decimal]
5254
version = "1.26.1"

sdk/rust/crypto/src/key/private.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl PrivateKey {
164164
}
165165

166166
pub(crate) fn from_encrypted_info(der: &[u8], password: &[u8]) -> crate::Result<Self> {
167-
let info = pkcs8::EncryptedPrivateKeyInfo::from_der(&der)
167+
let info = pkcs8::EncryptedPrivateKeyInfo::from_der(der)
168168
.map_err(|e| Error::key_parse(e.to_string()))?;
169169

170170
let decrypted = info.decrypt(password).map_err(|e| Error::key_parse(e.to_string()))?;

sdk/rust/src/account/account_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ use crate::entity_id::{
3333
PartialEntityId,
3434
ValidateChecksums,
3535
};
36-
use crate::evm_address::EvmAddress;
3736
use crate::{
3837
Client,
3938
EntityId,
4039
Error,
40+
EvmAddress,
4141
FromProtobuf,
4242
LedgerId,
4343
PublicKey,
@@ -274,7 +274,7 @@ mod tests {
274274

275275
use hex_literal::hex;
276276

277-
use crate::evm_address::EvmAddress;
277+
use crate::ethereum::EvmAddress;
278278
use crate::{
279279
AccountId,
280280
Client,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* ‌
3+
* Hedera Rust SDK
4+
* ​
5+
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC
6+
* ​
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* ‍
19+
*/
20+
21+
use crate::transaction::TransactionExecute;
22+
use crate::{
23+
AccountId,
24+
AccountInfoQuery,
25+
Client,
26+
Error,
27+
Key,
28+
PublicKey,
29+
Transaction,
30+
};
31+
32+
async fn query_pk(client: &Client, account_id: AccountId) -> crate::Result<PublicKey> {
33+
let key = AccountInfoQuery::new().account_id(account_id).execute(client).await?.key;
34+
35+
match key {
36+
Key::Single(it) => Ok(it),
37+
_ => {
38+
Err(Error::signature_verify("`{account_id}`: unsupported key kind: {key:?}".to_owned()))
39+
}
40+
}
41+
}
42+
43+
/// Verify the `signature` for `msg` via the given account's public key.
44+
pub async fn verify_signature(
45+
client: &Client,
46+
account_id: AccountId,
47+
msg: impl AsRef<[u8]>,
48+
signature: impl AsRef<[u8]>,
49+
) -> crate::Result<()> {
50+
let key = query_pk(client, account_id).await?;
51+
52+
key.verify(msg.as_ref(), signature.as_ref())
53+
}
54+
55+
/// Returns `Ok(())` if the given account's public key has signed the given transaction.
56+
pub async fn verify_transaction_signature<D: TransactionExecute>(
57+
client: &Client,
58+
account_id: AccountId,
59+
transaction: &mut Transaction<D>,
60+
) -> crate::Result<()> {
61+
let key = query_pk(client, account_id).await?;
62+
63+
key.verify_transaction(transaction)
64+
}

sdk/rust/src/account/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ mod account_create_transaction;
2626
mod account_delete_transaction;
2727
mod account_id;
2828
mod account_info;
29+
// note(sr): there's absolutely no way I'm going to write an enum or struct for namespacing here.
30+
/// Flow for verifying signatures via account info.
31+
pub mod account_info_flow;
2932
mod account_info_query;
3033
mod account_records_query;
3134
mod account_stakers_query;

sdk/rust/src/client/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* ‍
1919
*/
2020

21+
use std::fmt;
2122
use std::sync::atomic::{
2223
AtomicBool,
2324
AtomicU64,
@@ -58,6 +59,13 @@ struct ClientInner {
5859
#[derive(Clone)]
5960
pub struct Client(Arc<ClientInner>);
6061

62+
impl fmt::Debug for Client {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
// todo: put anything important here.
65+
f.debug_tuple("Client").finish()
66+
}
67+
}
68+
6169
impl Client {
6270
fn with_network(
6371
network: Network,

0 commit comments

Comments
 (0)