Skip to content

Commit

Permalink
Bump ckb dependencies to v0.117.0
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Jul 30, 2024
1 parent 98e498b commit c24679a
Show file tree
Hide file tree
Showing 17 changed files with 594 additions and 416 deletions.
845 changes: 501 additions & 344 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-cli"
version = "1.10.0"
version = "1.11.0"
license = "MIT"
authors = [
"Linfeng Qian <thewawar@gmail.com>",
Expand All @@ -10,26 +10,26 @@ edition = "2021"
description = "ckb command line interface"

[dependencies]
ckb-jsonrpc-types = "=0.116.1"
ckb-hash = "=0.116.1"
ckb-crypto = { version = "=0.116.1", features = ["secp"] }
ckb-build-info = "=0.116.1"
ckb-types = "=0.116.1"
ckb-util = "=0.116.1"
ckb-error = "=0.116.1"
ckb-script = "=0.116.1"
ckb-chain-spec = "=0.116.1"
ckb-sdk = { version="3.2.1", features = ["native-tls-vendored"] }
ckb-mock-tx-types = { version = "=0.116.1" }
ckb-jsonrpc-types = "=0.117.0"
ckb-hash = "=0.117.0"
ckb-crypto = { version = "=0.117.0", features = ["secp"] }
ckb-build-info = "=0.117.0"
ckb-types = "=0.117.0"
ckb-util = "=0.117.0"
ckb-error = "=0.117.0"
ckb-script = "=0.117.0"
ckb-chain-spec = "=0.117.0"
ckb-sdk = { version = "3.3.0", features = ["native-tls-vendored"] }
ckb-mock-tx-types = "=0.117.0"
ckb-signer = { path = "ckb-signer", version = "0.4.1" }
plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=1.3.1" }
jsonrpc-core-client = "18"
jsonrpc-core = "18"
jsonrpc-derive = "18"
jsonrpc-http-server = "18"
jsonrpc-server-utils = "18"
secp256k1 = { version = "0.24", features = ["recovery"] }
bitcoin = "0.29"
secp256k1 = { version = "0.29.0", features = ["recovery"] }
bitcoin = "0.32"
faster-hex = "0.6"
env_logger = "0.6"
crossbeam-channel = "0.5.8"
Expand Down Expand Up @@ -76,7 +76,7 @@ termion = "1.5"
rand = "0.7"

[build-dependencies]
ckb-build-info = "=0.116.1"
ckb-build-info = "=0.117.0"

[workspace]
members = ["ckb-signer", "plugin-protocol"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ci: fmt clippy test security-audit check-crates check-licenses
git diff --exit-code Cargo.lock

integration:
bash devtools/ci/integration.sh v0.116.0-rc2
bash devtools/ci/integration.sh v0.117.0-rc5

prod: ## Build binary with release profile.
cargo build --release
Expand Down
12 changes: 6 additions & 6 deletions ckb-signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ repository = "https://github.com/nervosnetwork/ckb-cli"

[dependencies]
serde_json = "1.0"
secp256k1 = { version = "0.24", features = ["recovery"] }
secp256k1 = { version = "0.29.0", features = ["recovery"] }
faster-hex = "0.6"
aes-ctr = "0.6.0"
scrypt = "0.2.0"
rand = "0.7.3"
tiny-keccak = "1.4"
uuid = { version = "0.7.4", features = ["v4"] }
bitcoin = "0.29"
bitcoin = "0.32"
chrono = "0.4"
thiserror = "1.0.30"
parking_lot = "0.11"
anyhow = "1.0.63"

ckb-types = "=0.116.1"
ckb-hash = "=0.116.1"
ckb-crypto = { version = "=0.116.1", features = ["secp"] }
ckb-sdk = { version="3.2.1", features = ["native-tls-vendored"] }
ckb-types = "=0.117.0"
ckb-hash = "=0.117.0"
ckb-crypto = { version = "=0.117.0", features = ["secp"] }
ckb-sdk = { version = "3.3.0", features = ["native-tls-vendored"] }
49 changes: 23 additions & 26 deletions ckb-signer/src/keystore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::{Duration, Instant};

use bitcoin::bip32::{ChainCode, ChildNumber, DerivationPath, Xpriv, Xpub};
use chrono::{Datelike, Timelike, Utc};
use faster_hex::{hex_decode, hex_string};
use rand::Rng;
use secp256k1::ecdsa::{RecoverableSignature, Signature};
use uuid::Uuid;

use bitcoin::util::bip32::{
ChainCode, ChildNumber, DerivationPath, ExtendedPrivKey, ExtendedPubKey,
};
use ckb_crypto::secp::SECP256K1;
use ckb_hash::blake2b_256;
use ckb_sdk::util::{zeroize_privkey, zeroize_slice};
use ckb_types::{H160, H256};
use faster_hex::{hex_decode, hex_string};
use rand::Rng;
use secp256k1::ecdsa::{RecoverableSignature, Signature};
use uuid::Uuid;

pub use error::Error;
pub use passphrase::{CipherParams, Crypto, KdfParams, ScryptParams, ScryptType};
Expand Down Expand Up @@ -264,7 +261,7 @@ impl KeyStore {
let key = self.storage.get_key(hash160, filepath, password)?;
Ok(key.master_privkey.sign_recoverable(message, path))
}
pub fn extended_pubkey<P>(&mut self, hash160: &H160, path: &P) -> Result<ExtendedPubKey, Error>
pub fn extended_pubkey<P>(&mut self, hash160: &H160, path: &P) -> Result<Xpub, Error>
where
P: AsRef<[ChildNumber]>,
{
Expand All @@ -278,7 +275,7 @@ impl KeyStore {
hash160: &H160,
path: &P,
password: &[u8],
) -> Result<ExtendedPubKey, Error>
) -> Result<Xpub, Error>
where
P: AsRef<[ChildNumber]>,
{
Expand Down Expand Up @@ -555,7 +552,7 @@ impl DerivedKeySet {
#[derive(Clone)]
pub struct CkbRoot {
pub path: &'static str,
extended_pubkey: ExtendedPubKey,
extended_pubkey: Xpub,
}

impl CkbRoot {
Expand Down Expand Up @@ -599,13 +596,13 @@ impl CkbRoot {
}
let mut chain_code = [0u8; 32];
chain_code.copy_from_slice(&chain_code_bin[..]);
let extended_pubkey = ExtendedPubKey {
network: bitcoin::Network::Bitcoin,
let extended_pubkey = Xpub {
network: bitcoin::NetworkKind::Main,
depth,
parent_fingerprint,
child_number,
public_key,
chain_code: ChainCode::from(&chain_code[..]),
chain_code: ChainCode::from(&chain_code),
};

// let pubkey
Expand Down Expand Up @@ -673,7 +670,7 @@ impl CkbRoot {
(path, hash160)
}

pub fn derived_pubkey(&self, chain: KeyChain, index: u32) -> (DerivationPath, ExtendedPubKey) {
pub fn derived_pubkey(&self, chain: KeyChain, index: u32) -> (DerivationPath, Xpub) {
let children = vec![
ChildNumber::from_normal_idx(chain as u32).expect("normal child"),
ChildNumber::from_normal_idx(index).expect("normal child"),
Expand All @@ -695,7 +692,7 @@ impl CkbRoot {
chain: KeyChain,
start: u32,
length: u32,
) -> Vec<(DerivationPath, ExtendedPubKey)> {
) -> Vec<(DerivationPath, Xpub)> {
// At least one pubkey
(0..length)
.map(|i| self.derived_pubkey(chain, i + start))
Expand Down Expand Up @@ -852,17 +849,17 @@ impl MasterPrivKey {
bytes
}

fn sub_privkey<P>(&self, path: &P) -> ExtendedPrivKey
fn sub_privkey<P>(&self, path: &P) -> Xpriv
where
P: AsRef<[ChildNumber]>,
{
let sk = ExtendedPrivKey {
network: bitcoin::Network::Bitcoin,
let sk = Xpriv {
network: bitcoin::NetworkKind::Main,
depth: 0,
parent_fingerprint: Default::default(),
child_number: ChildNumber::Normal { index: 0 },
private_key: self.secp_secret_key,
chain_code: ChainCode::from(&self.chain_code[..]),
chain_code: ChainCode::from(&self.chain_code),
};
sk.derive_priv(&SECP256K1, path)
.expect("Derive sub-privkey error")
Expand All @@ -872,8 +869,8 @@ impl MasterPrivKey {
where
P: AsRef<[ChildNumber]>,
{
let message =
secp256k1::Message::from_slice(message.as_bytes()).expect("Convert to message failed");
let message = secp256k1::Message::from_digest_slice(message.as_bytes())
.expect("Convert to message failed");
let sub_sk = self.sub_privkey(path);
SECP256K1.sign_ecdsa(&message, &sub_sk.private_key)
}
Expand All @@ -882,18 +879,18 @@ impl MasterPrivKey {
where
P: AsRef<[ChildNumber]>,
{
let message =
secp256k1::Message::from_slice(message.as_bytes()).expect("Convert to message failed");
let message = secp256k1::Message::from_digest_slice(message.as_bytes())
.expect("Convert to message failed");
let sub_sk = self.sub_privkey(path);
SECP256K1.sign_ecdsa_recoverable(&message, &sub_sk.private_key)
}

pub fn extended_pubkey<P>(&self, path: &P) -> ExtendedPubKey
pub fn extended_pubkey<P>(&self, path: &P) -> Xpub
where
P: AsRef<[ChildNumber]>,
{
let sub_sk = self.sub_privkey(path);
ExtendedPubKey::from_priv(&SECP256K1, &sub_sk)
Xpub::from_priv(&SECP256K1, &sub_sk)
}

pub fn ckb_root(&self) -> CkbRoot {
Expand Down
2 changes: 1 addition & 1 deletion ckb-signer/src/keystore/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use anyhow::anyhow;
use bitcoin::util::bip32::DerivationPath;
use bitcoin::bip32::DerivationPath;
use parking_lot::Mutex;

use ckb_sdk::traits::{Signer, SignerError};
Expand Down
4 changes: 2 additions & 2 deletions plugin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "ckb-cli plugin protocol"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-types = "=0.116.1"
ckb-jsonrpc-types = "=0.116.1"
ckb-types = "=0.117.0"
ckb-jsonrpc-types = "=0.117.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::Path;
use std::str::FromStr;
use std::thread::{self, JoinHandle};

use bitcoin::util::bip32::DerivationPath;
use bitcoin::bip32::DerivationPath;
use crossbeam_channel::bounded;

use ckb_sdk::util::serialize_signature;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::atomic::AtomicU64;
use std::sync::Arc;
use std::thread::{self, JoinHandle};

use bitcoin::util::bip32::{ChildNumber, DerivationPath};
use bitcoin::bip32::{ChildNumber, DerivationPath};
use crossbeam_channel::{bounded, select, Sender};

use ckb_jsonrpc_types::{BlockNumber, HeaderView, JsonBytes, Script};
Expand Down
11 changes: 9 additions & 2 deletions src/subcommands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Write;
use std::os::unix::fs::OpenOptionsExt;
use std::path::{Path, PathBuf};

use bitcoin::util::bip32::DerivationPath;
use bitcoin::bip32::DerivationPath;

use ckb_sdk::{Address, AddressPayload, NetworkType};
use ckb_signer::{Key, KeyStore, MasterPrivKey};
Expand Down Expand Up @@ -454,8 +454,15 @@ impl<'a> CliSubCommand for AccountSubCommand<'a> {
set.iter()
.map(|(path, hash160)| {
let payload = AddressPayload::from_pubkey_hash(hash160.clone());
let path = {
if !path.to_string().starts_with("m/"){
String::new()+ "m/" + &path.to_string()
}else{
path.to_string()
}
};
serde_json::json!({
"path": path.to_string(),
"path": path,
"address(deprecated)": Address::new(network, payload.clone(), false).to_string(),
"address": Address::new(network, payload, true).to_string(),
})
Expand Down
16 changes: 8 additions & 8 deletions src/subcommands/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs;
use std::io::Read;
use std::path::PathBuf;

use bitcoin::util::bip32::{ChildNumber, DerivationPath};
use bitcoin::bip32::{ChildNumber, DerivationPath};
use chrono::prelude::*;
use clap::{App, Arg, ArgMatches};
use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh};
Expand Down Expand Up @@ -559,7 +559,7 @@ message = "0x"
} else {
return Err(format!("Invalid signature length: {}", signature.len()));
};
let message = secp256k1::Message::from_slice(message.as_bytes())
let message = secp256k1::Message::from_digest_slice(message.as_bytes())
.expect("Convert to message failed");
let verify_ok = SECP256K1
.verify_ecdsa(&message, &signature, &pubkey)
Expand Down Expand Up @@ -683,7 +683,7 @@ message = "0x"

let genesis_timestamp =
NaiveDateTime::parse_from_str("2019-11-16 06:00:00", "%Y-%m-%d %H:%M:%S")
.map(|dt| dt.timestamp_millis() as u64)
.map(|dt| dt.and_utc().timestamp_millis() as u64)
.unwrap();
let target_timestamp = to_timestamp(locktime)?;
let elapsed = target_timestamp.saturating_sub(genesis_timestamp);
Expand All @@ -694,8 +694,8 @@ message = "0x"
if debug {
eprintln!(
"[DEBUG] genesis_time: {}, target_time: {}, elapsed_in_secs: {}, target_epoch: {}, lock_arg: {}, code_hash: {:#x}",
NaiveDateTime::from_timestamp_opt(genesis_timestamp as i64 / 1000, 0).expect("genesis time"),
NaiveDateTime::from_timestamp_opt(target_timestamp as i64 / 1000, 0).ok_or_else(|| "target timestamp out of range".to_string())?,
DateTime::from_timestamp(genesis_timestamp as i64 / 1000, 0).expect("genesis time"),
DateTime::from_timestamp(target_timestamp as i64 / 1000, 0).ok_or_else(|| "target timestamp out of range".to_string())?,
elapsed / 1000,
epoch_fraction,
hex_string(multisig_addr.payload().args().as_ref()),
Expand Down Expand Up @@ -876,14 +876,14 @@ fn sign_message<P: ?Sized + AsRef<[ChildNumber]>>(
) -> Result<Vec<u8>, String> {
match (from_privkey_opt, from_account_opt, recoverable) {
(Some(privkey), _, false) => {
let message = secp256k1::Message::from_slice(message.as_bytes()).unwrap();
let message = secp256k1::Message::from_digest_slice(message.as_bytes()).unwrap();
Ok(SECP256K1
.sign_ecdsa(&message, privkey)
.serialize_compact()
.to_vec())
}
(Some(privkey), _, true) => {
let message = secp256k1::Message::from_slice(message.as_bytes()).unwrap();
let message = secp256k1::Message::from_digest_slice(message.as_bytes()).unwrap();
Ok(serialize_signature(&SECP256K1.sign_ecdsa_recoverable(&message, privkey)).to_vec())
}
(None, Some((plugin_mgr, account)), false) => plugin_mgr
Expand Down Expand Up @@ -930,7 +930,7 @@ fn to_timestamp(input: &str) -> Result<u64, String> {
let date = NaiveDate::parse_from_str(input, "%Y-%m-%d").map_err(|err| format!("{:?}", err))?;
let date = NaiveDateTime::parse_from_str(&format!("{} 00:00:00", date), "%Y-%m-%d %H:%M:%S")
.map_err(|err| format!("{:?}", err))?;
Ok(date.timestamp_millis() as u64)
Ok(date.and_utc().timestamp_millis() as u64)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, str::FromStr};

use bitcoin::util::bip32::DerivationPath;
use bitcoin::bip32::DerivationPath;
use clap::{App, Arg, ArgMatches};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/mock_tx_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ mod test {
if &lock_arg != target_lock_arg {
return Err(String::from("lock arg not match"));
}
let message = secp256k1::Message::from_slice(tx_hash_hash.as_bytes())
let message = secp256k1::Message::from_digest_slice(tx_hash_hash.as_bytes())
.expect("Convert to secp256k1 message failed");
let signature = SECP256K1.sign_ecdsa_recoverable(&message, &privkey);
let (recov_id, data) = signature.serialize_compact();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub fn get_privkey_signer(privkey: PrivkeyWrapper) -> SignerFn {
if message == &h256!("0x0") {
Ok(Some([0u8; 65]))
} else {
let message = secp256k1::Message::from_slice(message.as_bytes())
let message = secp256k1::Message::from_digest_slice(message.as_bytes())
.expect("Convert to secp256k1 message failed");
let signature = SECP256K1.sign_ecdsa_recoverable(&message, &privkey);
Ok(Some(serialize_signature(&signature)))
Expand Down
Loading

0 comments on commit c24679a

Please sign in to comment.