Small QoL improvements for wallet developers (#2651)

* Small changes for wallet devs

* Move create_nonce into Keychain trait

* Replace match by map_err

* Add flag to Slate to skip fee check

* Fix secp dependency

* Remove check_fee flag in Slate
This commit is contained in:
jaspervdm
2019-03-19 17:13:49 +01:00
committed by Yeastplume
parent 7fad5b040f
commit f4d3b2e204
5 changed files with 22 additions and 20 deletions
+2 -1
View File
@@ -34,7 +34,8 @@ pub struct Context<'a, K>
where
K: Keychain,
{
keychain: &'a K,
/// The keychain used for key derivation
pub keychain: &'a K,
}
/// Function type returned by the transaction combinators. Transforms a
+6 -19
View File
@@ -14,29 +14,12 @@
//! Rangeproof library functions
use crate::blake2;
use crate::keychain::{Identifier, Keychain};
use crate::libtx::error::{Error, ErrorKind};
use crate::util::secp::key::SecretKey;
use crate::util::secp::pedersen::{Commitment, ProofInfo, ProofMessage, RangeProof};
use crate::util::secp::{self, Secp256k1};
fn create_nonce<K>(k: &K, commit: &Commitment) -> Result<SecretKey, Error>
where
K: Keychain,
{
// hash(commit|wallet root secret key (m)) as nonce
let root_key = k.derive_key(0, &K::root_key_id())?;
let res = blake2::blake2b::blake2b(32, &commit.0, &root_key.0[..]);
let res = res.as_bytes();
match SecretKey::from_slice(k.secp(), &res) {
Ok(sk) => Ok(sk),
Err(e) => Err(ErrorKind::RangeProof(
format!("Unable to create nonce: {:?}", e).to_string(),
))?,
}
}
/// Create a bulletproof
pub fn create<K>(
k: &K,
@@ -50,7 +33,9 @@ where
{
let commit = k.commit(amount, key_id)?;
let skey = k.derive_key(amount, key_id)?;
let nonce = create_nonce(k, &commit)?;
let nonce = k
.create_nonce(&commit)
.map_err(|e| ErrorKind::RangeProof(e.to_string()))?;
let message = ProofMessage::from_bytes(&key_id.serialize_path());
Ok(k.secp()
.bullet_proof(amount, skey, nonce, extra_data, Some(message)))
@@ -80,7 +65,9 @@ pub fn rewind<K>(
where
K: Keychain,
{
let nonce = create_nonce(k, &commit)?;
let nonce = k
.create_nonce(&commit)
.map_err(|e| ErrorKind::RangeProof(e.to_string()))?;
let proof_message = k
.secp()
.rewind_bullet_proof(commit, nonce, extra_data, proof);