Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Encryption, decryption and public key RPCs. #1946

Merged
merged 15 commits into from
Sep 22, 2016
Merged

Encryption, decryption and public key RPCs. #1946

merged 15 commits into from
Sep 22, 2016

Conversation

gavofyork
Copy link
Contributor

@gavofyork gavofyork commented Aug 17, 2016

Still need to add support for "signer" to decrypt payloads; this can be separate PR though.

@gavofyork gavofyork added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Aug 17, 2016
@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 86.98% when pulling d5add87 on rpc-fix into ccdf80f on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 86.871% when pulling c1641b3 on rpc-fix into ccdf80f on master.

@rphmeier rphmeier added the M4-core ⛓ Core client code / Rust. label Sep 13, 2016
@gavofyork gavofyork added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 21, 2016
self.sender.set(Some(s));
Ok(s)
}
}
}

/// Returns the public key of the sender.
pub fn public_key(&self) -> Result<Public, Error> {
Ok(try!(recover(&self.signature(), &self.unsigned.hash())))
Copy link
Contributor

@rphmeier rphmeier Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok(try!(...)) can just be .... If the error type is wrong then a .map(Into::into) might be more idiomatic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also may want to move the caching of self.sender into this function, so that all uses of public_key can benefit from the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't really work for further calls to public_key, but would indeed mean sender were cached on a call to public_key.

Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a way to do this without a non-standard transaction structure. also reducing recover calls would be nice to the user's machine, especially as we already have a cache for that specific purpose.

try!(self.active());
from_params::<(RpcH160, RpcBytes)>(params).and_then(|(address, ciphertext)| {
let s = try!(take_weak!(self.accounts).decrypt(address.into(), &[0; 0], &ciphertext.0).map_err(|_| Error::internal_error()));
Ok(to_value(&RpcBytes::from(s)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_value can now take arguments by value.

@@ -75,6 +78,7 @@ impl From<LocalizedTransaction> for Transaction {
Action::Call(_) => None,
},
raw: ::rlp::encode(&t.signed).to_vec().into(),
public_key: t.public_key().ok().map(Into::into),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example, using the existing cache would prevent an extra ec_recover here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to cache both public_key and sender's address to retain present cache performance on sender since you can't derive public_key from sender.

@@ -51,6 +51,9 @@ pub struct Transaction {
pub creates: Option<H160>,
/// Raw transaction data
pub raw: Bytes,
/// Public key of the signer.
#[serde(rename="publicKey")]
pub public_key: Option<H512>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This transaction structure diverges from the spec: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash

Affected: all getTransactionBy* and getBlockBy* functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's additive functionality and therefore of no great harm. in any case, we're doing it already with additional APIs and providing a separate API for it would be substantially more code/complexity with relatively little gain.

Copy link
Contributor Author

@gavofyork gavofyork Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other thing to note is that we already provide a non-standard block structure (with the key sealFields). it's not especially controversial.

@@ -235,6 +239,7 @@ pub trait EthSigning: Sized + Send + Sync + 'static {
delegate.add_method("eth_postSign", EthSigning::post_sign);
delegate.add_method("eth_postTransaction", EthSigning::post_transaction);
delegate.add_method("eth_checkRequest", EthSigning::check_request);
delegate.add_method("ethcore_decryptMessage", EthSigning::decrypt_message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing of module names here? Strange that EthSigning would bridge both eth and ethcore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EthSigning is a bit of an odd one as it pollutes into eth_ namespace. this just makes it pollute into ethcore_ namespace, too.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 85.178% when pulling 403d0e7 on rpc-fix into 5e0dcd0 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 85.181% when pulling 403d0e7 on rpc-fix into 5e0dcd0 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 85.138% when pulling 6067159 on rpc-fix into 5e0dcd0 on master.

@gavofyork gavofyork merged commit 07b5e9a into master Sep 22, 2016
@gavofyork gavofyork deleted the rpc-fix branch September 22, 2016 12:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants