From e005558904adfb9c3bcaf27f37036ab7a4a067ce Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Tue, 1 Nov 2022 14:26:55 +0800 Subject: [PATCH 1/2] chore: update ckb deps to v0.105.1 * update ckb-sdk to v2.3.0 * update ckb-mock-tx-types to v0.105.1 * update secp256k1 to v0.24 * update bitcoin to v0.29 --- Cargo.lock | 181 +++++++++++++++++++-------------- Cargo.toml | 28 ++--- Makefile | 3 +- ckb-signer/Cargo.toml | 12 +-- ckb-signer/src/keystore/mod.rs | 38 +++---- plugin-protocol/Cargo.toml | 4 +- src/plugin/builtin.rs | 1 - src/subcommands/rpc.rs | 6 +- src/subcommands/util.rs | 12 ++- src/utils/mock_tx_helper.rs | 2 +- src/utils/other.rs | 4 +- src/utils/rpc/client.rs | 7 +- src/utils/rpc/mod.rs | 2 +- src/utils/rpc/types.rs | 77 +++++++++++++- src/utils/signer.rs | 4 +- test/Cargo.toml | 10 +- 16 files changed, 240 insertions(+), 151 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33ddfd3c..ff46dac4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,6 +144,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bit-vec" version = "0.6.3" @@ -152,20 +158,20 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitcoin" -version = "0.27.1" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a41df6ad9642c5c15ae312dd3d074de38fd3eb7cc87ad4ce10f90292a83fe4d" +checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" dependencies = [ - "bech32", + "bech32 0.9.1", "bitcoin_hashes", "secp256k1", ] [[package]] name = "bitcoin_hashes" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006cc91e1a1d99819bc5b8214be3555c1f0611b169f527a1fdc54ed1f2b745b0" +checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" [[package]] name = "bitflags" @@ -344,15 +350,15 @@ dependencies = [ [[package]] name = "ckb-build-info" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18b85376a36a230baf37d762cafd44385feb861d8a0e68246e794f57c6db0a0" +checksum = "b27119a63dc1d5deb00ae3a44e4431dd2a0a65ca3283ef2b5e86306d347412fc" [[package]] name = "ckb-chain-spec" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d7c40f6ede10a33d07bee585cf30b1d16588e60ccccc2ad134b6ce00ef10d8" +checksum = "2f0f0606bce9ccbde520465890486807a0ac2fcba3e60d37df54a2d0be071725" dependencies = [ "ckb-constant", "ckb-crypto", @@ -365,15 +371,16 @@ dependencies = [ "ckb-resource", "ckb-traits", "ckb-types", + "ckb-util", "serde", "toml", ] [[package]] name = "ckb-channel" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe17832858b599109ac9cee6d9dcde419dad958a1982d6e37eb97fedb0ef5e6" +checksum = "5f0da1f4e474de48b05e30ad603da4da3b410344b619c7cf35d444e406c0bb6e" dependencies = [ "crossbeam-channel", ] @@ -401,7 +408,7 @@ dependencies = [ "ckb-signer", "ckb-types", "ckb-util", - "ckb-vm-definitions", + "ckb-vm-definitions 0.21.3", "clap", "clap_generate", "colored", @@ -454,15 +461,15 @@ dependencies = [ [[package]] name = "ckb-constant" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a4ba4a395a9e50a7179e08252276b183310c32c24dfc8b521925fdf8a9afa0" +checksum = "8a6df9fd997d58f1e5f12a683a00d98158a82c07a422e6f81ff390607f19c493" [[package]] name = "ckb-crypto" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a600bb463e6d72acb85c0ba821b106a1710855a52737b434a4afd6fcbab0e55" +checksum = "1650275e0f5a59e8ebbd747d835e10b9179d8ab4941b96100d5b7e48fada695e" dependencies = [ "ckb-fixed-hash", "faster-hex", @@ -474,9 +481,9 @@ dependencies = [ [[package]] name = "ckb-dao-utils" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac8bee17950819b550031c81b4200e1e6eddc364c5aab16d5fc9407d2035c775" +checksum = "b294c46e06c315900c9eb4e5719311902d68fcad6c802f43ebc658902715b5ea" dependencies = [ "byteorder", "ckb-error", @@ -485,9 +492,9 @@ dependencies = [ [[package]] name = "ckb-error" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73dc4bb1f4c889f42edc9509005aa593ca1b88b6f43f9cfbd59c6d4897994783" +checksum = "51748ac5e08dce6c685cf4b43e27dcbcfc98e21442c4001c9f06509a04a400ed" dependencies = [ "anyhow", "ckb-occupied-capacity", @@ -497,9 +504,9 @@ dependencies = [ [[package]] name = "ckb-fixed-hash" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8183ed12fd0fff3abfb142d3dde7b501f211519e2b77972c64815e00d38c8ed3" +checksum = "b3d665013dbb8ff2df8e67c4add67db703ae3b642679f1a2962f76399703eee1" dependencies = [ "ckb-fixed-hash-core", "ckb-fixed-hash-macros", @@ -507,9 +514,9 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-core" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e9a8f69f7174ce9f9b6045a82aafb2ceafc2aa6eedffa0562e0d6defaa4732" +checksum = "dd92b9d691bbfd11a900ee17ad1010a553ae0b5d3a120e0c8094afcd30f9b15e" dependencies = [ "faster-hex", "serde", @@ -518,9 +525,9 @@ dependencies = [ [[package]] name = "ckb-fixed-hash-macros" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f73281677e79cd8cbd873b86701209d560038549823e915cb3505d1b348f0a6" +checksum = "f24e42b82da4d891ac8b5b19de2807cae360c5377138a7cde377b60edc6ec953" dependencies = [ "ckb-fixed-hash-core", "proc-macro2", @@ -530,9 +537,9 @@ dependencies = [ [[package]] name = "ckb-hash" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac70ef20b9dac406f06bead70c0a2e4742205234f58051885e6ae1f50786e6be" +checksum = "c6b64eff869839aff45741515540e81a0447926d79262a439b5e9d0a5c98ac95" dependencies = [ "blake2b-ref", "blake2b-rs", @@ -540,9 +547,9 @@ dependencies = [ [[package]] name = "ckb-jsonrpc-types" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520d1cc13b7d5ea93a2b9a28362555410e6621e8141eb1289a0547e0c5ef6e46" +checksum = "82268ddea09f95324496d6def1b37d6bdc3a4841fecc185388e7a2bb6451687f" dependencies = [ "ckb-types", "faster-hex", @@ -552,18 +559,27 @@ dependencies = [ [[package]] name = "ckb-logger" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6839e2ab382fa92f3d3cb71d18d55a0c65965d54674dd5e375854bf07248ae6" +checksum = "8a312280df7ba55dc99cf8584ac4d3c9e3b85297a896202c76a21dfd43ffb0ea" dependencies = [ "log", ] +[[package]] +name = "ckb-merkle-mountain-range" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ccb671c5921be8a84686e6212ca184cb1d7c51cadcdbfcbd1cc3f042f5dfb8" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "ckb-mock-tx-types" -version = "0.4.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ba4c43798e257bb3e6ca76e5500065bda39973b72e78b94a73a8c9da6aa952" +checksum = "c73574949df81ecd84b5366992f1ab61d2a4e8dc905dabb58468b785fa90b22d" dependencies = [ "ckb-jsonrpc-types", "ckb-traits", @@ -574,9 +590,9 @@ dependencies = [ [[package]] name = "ckb-occupied-capacity" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0e4ccbc2b6af791b589a09db77518fb2b0fa79a72ba568e6a7dade7e935721" +checksum = "a11e010c034a98b734074a79655c738c40501e9113426173132856a35c6e71c6" dependencies = [ "ckb-occupied-capacity-core", "ckb-occupied-capacity-macros", @@ -584,18 +600,18 @@ dependencies = [ [[package]] name = "ckb-occupied-capacity-core" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773a03d5c3cf71d5f9b0e620b193fdd82a3e1f3434022792a32a8b4037550fa1" +checksum = "03e48f0306a3fe072711e0342b71335898ac6d0a82b897ca3ae13e43770ce0e0" dependencies = [ "serde", ] [[package]] name = "ckb-occupied-capacity-macros" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfcfb1f9f3812fd5e306d88f0a3683cdf9e8350f5a79c3288e835b8355425635" +checksum = "656db5615c791b8d7b31a38e024f98fb497be5e2cb120b38be48eb4d9d1d0f6d" dependencies = [ "ckb-occupied-capacity-core", "quote", @@ -604,9 +620,9 @@ dependencies = [ [[package]] name = "ckb-pow" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c09ed8c7588b6722bfba5c1df618943bccab49904fd2e0f4a8b7b978f55731" +checksum = "9708f81c8c9058bf3dab834be2be68d14dcd9fa41bd793727428a2cf6b1ddf59" dependencies = [ "byteorder", "ckb-hash", @@ -618,9 +634,9 @@ dependencies = [ [[package]] name = "ckb-rational" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a70041296dc87341c1993ff3c12268937bb998145b49afc5c299a764dc9ed12a" +checksum = "444926bc5a9ad789b2b98e75f90330bcfe741bab517ca45d8f084449fe35efd8" dependencies = [ "numext-fixed-uint", "serde", @@ -628,9 +644,9 @@ dependencies = [ [[package]] name = "ckb-resource" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45669446b51b6336f407044c1940cb31d709c09638fe4c2b34d6910d7d55f13" +checksum = "95464c0e69e20553f34c132789f6275a1e06468362226cf5a986719f6da96161" dependencies = [ "ckb-system-scripts", "ckb-types", @@ -643,9 +659,9 @@ dependencies = [ [[package]] name = "ckb-script" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75232e549f5b4eba2442eaca5232ab87a9deee54bfb1c9761f00b9978f17365" +checksum = "2f06c44207d8e90b86f2b29f2341188a6d1a3520f6b657eb2ba662b3a772abfc" dependencies = [ "byteorder", "ckb-chain-spec", @@ -661,12 +677,12 @@ dependencies = [ [[package]] name = "ckb-sdk" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d616057ea02546c88a78e4cc04fb99a4a4f74b491eca025db444ab211bae88c8" +checksum = "291b16984a8de03b28565eaa4b880a788380986ad4ee641acf2721e3404a06c3" dependencies = [ "anyhow", - "bech32", + "bech32 0.8.1", "bitflags", "bytes 1.2.1", "ckb-crypto", @@ -676,6 +692,7 @@ dependencies = [ "ckb-resource", "ckb-traits", "ckb-types", + "dashmap", "enum-repr-derive", "futures 0.3.24", "jsonrpc-core", @@ -733,18 +750,18 @@ dependencies = [ [[package]] name = "ckb-traits" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50acf0a06a8d1f32e1c5cf4638ad97e0d94a61ae2ca4dab797b40cb602e2260a" +checksum = "6d54a03a03af9857264cc252060f4274e11858956a4985793b04047117828329" dependencies = [ "ckb-types", ] [[package]] name = "ckb-types" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9ba3e13c93900267bc9670b3ea4379eab1a234c7cb470fcd6856640f165e2af" +checksum = "f06812497491fa58cea1c93dda2de074e0c5d51cf7d70d93dd50c862c661494c" dependencies = [ "bit-vec", "bytes 1.2.1", @@ -752,6 +769,7 @@ dependencies = [ "ckb-error", "ckb-fixed-hash", "ckb-hash", + "ckb-merkle-mountain-range", "ckb-occupied-capacity", "ckb-rational", "derive_more", @@ -763,9 +781,9 @@ dependencies = [ [[package]] name = "ckb-util" -version = "0.104.0" +version = "0.105.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ba722cd568e3514a40039b41074391df48b8e6deb009d2b7a7a1d51a7f40814" +checksum = "2c0f4f5647372cc1c2fdc7122e062984754e062edbcc654436a1af7f5b1382a0" dependencies = [ "linked-hash-map", "once_cell", @@ -775,19 +793,17 @@ dependencies = [ [[package]] name = "ckb-vm" -version = "0.21.3" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc81aeacb7eaa4981e4c4f8285e30bca92f8d7346937cbcfc0b77f26b21da2de" +checksum = "0f1126bf0240d100234bc06efa7020f0d50ca35fe90e5ac7cac1b7721e1bacb7" dependencies = [ "byteorder", "bytes 1.2.1", "cc", - "ckb-vm-definitions", + "ckb-vm-definitions 0.22.0", "derive_more", "goblin 0.2.3", "goblin 0.4.0", - "libc", - "mapr", "rand 0.7.3", "scroll", "serde", @@ -799,6 +815,12 @@ version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7968c559498b68833791364e87182fdd1a3aba803e8a16c34b1aa45fc08add1c" +[[package]] +name = "ckb-vm-definitions" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14739bf59648c169de9257ec7dd6aba1aeb6a41725d636005f1c91853df58fcc" + [[package]] name = "clap" version = "3.0.0-beta.1" @@ -981,6 +1003,19 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "dashmap" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core 0.9.3", +] + [[package]] name = "data-encoding" version = "2.3.2" @@ -1764,6 +1799,9 @@ name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +dependencies = [ + "serde", +] [[package]] name = "lock_api" @@ -1793,16 +1831,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "mapr" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a28a55dbc005b2f6f123c4058933d57add373d362f6fd3a76aab4fe6973500" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "matches" version = "0.1.9" @@ -2739,18 +2767,19 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.20.3" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a" +checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" dependencies = [ + "bitcoin_hashes", "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.4.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957da2573cde917463ece3570eab4a0b3f19de6f1646cde62e6fd3868f566036" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index e7188a91..7ba8c1e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,17 +7,17 @@ edition = "2021" description = "ckb command line interface" [dependencies] -ckb-jsonrpc-types = "=0.104.0" -ckb-hash = "=0.104.0" -ckb-crypto = { version = "=0.104.0", features = ["secp"] } -ckb-build-info = "=0.104.0" -ckb-types = "=0.104.0" -ckb-util = "=0.104.0" -ckb-error = "=0.104.0" -ckb-script = "=0.104.0" -ckb-chain-spec = "=0.104.0" -ckb-mock-tx-types = "0.4.0" -ckb-sdk = "2.2.0" +ckb-jsonrpc-types = "=0.105.1" +ckb-hash = "=0.105.1" +ckb-crypto = { version = "=0.105.1", features = ["secp"] } +ckb-build-info = "=0.105.1" +ckb-types = "=0.105.1" +ckb-util = "=0.105.1" +ckb-error = "=0.105.1" +ckb-script = "=0.105.1" +ckb-chain-spec = "=0.105.1" +ckb-mock-tx-types = "0.105.1" +ckb-sdk = "2.3.0" ckb-signer = { path = "ckb-signer", version = "0.3.0" } plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=1.1.0" } jsonrpc-core-client = "18" @@ -25,8 +25,8 @@ jsonrpc-core = "18" jsonrpc-derive = "18" jsonrpc-http-server = "18" jsonrpc-server-utils = "18" -secp256k1 = { version = "0.20", features = ["recovery"] } -bitcoin = "0.27" +secp256k1 = { version = "0.24", features = ["recovery"] } +bitcoin = "0.29" faster-hex = "0.6" env_logger = "0.6" crossbeam-channel = "0.5.1" @@ -72,7 +72,7 @@ termion = "1.5" rand = "0.7" [build-dependencies] -ckb-build-info = "=0.104.0" +ckb-build-info = "=0.105.1" [workspace] members = ["ckb-signer", "plugin-protocol"] diff --git a/Makefile b/Makefile index 435e6664..c5f00e6a 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +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.104.0 - bash devtools/ci/integration.sh develop + bash devtools/ci/integration.sh v0.105.1 prod: ## Build binary with release profile. cargo build --release diff --git a/ckb-signer/Cargo.toml b/ckb-signer/Cargo.toml index 2bc4f235..8ba9c79d 100644 --- a/ckb-signer/Cargo.toml +++ b/ckb-signer/Cargo.toml @@ -11,20 +11,20 @@ repository = "https://github.com/nervosnetwork/ckb-cli" [dependencies] serde_json = "1.0" -secp256k1 = { version = "0.20", features = ["recovery"] } +secp256k1 = { version = "0.24", 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.27" +bitcoin = "0.29" chrono = "0.4" thiserror = "1.0.30" parking_lot = "0.11" anyhow = "1.0.63" -ckb-types = "=0.104.0" -ckb-hash = "=0.104.0" -ckb-crypto = { version = "=0.104.0", features = ["secp"] } -ckb-sdk = "2.2.0" +ckb-types = "=0.105.1" +ckb-hash = "=0.105.1" +ckb-crypto = { version = "=0.105.1", features = ["secp"] } +ckb-sdk = "2.3.0" diff --git a/ckb-signer/src/keystore/mod.rs b/ckb-signer/src/keystore/mod.rs index 46513807..68db8eb0 100644 --- a/ckb-signer/src/keystore/mod.rs +++ b/ckb-signer/src/keystore/mod.rs @@ -15,7 +15,7 @@ use std::time::{Duration, Instant}; use chrono::{Datelike, Timelike, Utc}; use faster_hex::{hex_decode, hex_string}; use rand::Rng; -use secp256k1::recovery::RecoverableSignature; +use secp256k1::ecdsa::{RecoverableSignature, Signature}; use uuid::Uuid; use bitcoin::util::bip32::{ @@ -211,12 +211,7 @@ impl KeyStore { Ok(key.master_privkey) } - pub fn sign

( - &mut self, - hash160: &H160, - path: &P, - message: &H256, - ) -> Result + pub fn sign

(&mut self, hash160: &H160, path: &P, message: &H256) -> Result where P: AsRef<[ChildNumber]>, { @@ -245,7 +240,7 @@ impl KeyStore { path: &P, message: &H256, password: &[u8], - ) -> Result + ) -> Result where P: AsRef<[ChildNumber]>, { @@ -553,7 +548,7 @@ impl CkbRoot { ChildNumber::from_hardened_idx(0).expect("child number"), "child_number is wrong", ); - let pubkey_hex = hex_string(&self.extended_pubkey.public_key.key.serialize()[..]); + let pubkey_hex = hex_string(&self.extended_pubkey.public_key.serialize()[..]); let chain_code_hex = hex_string(&self.extended_pubkey.chain_code[..]); serde_json::json!({ "path": self.path, @@ -591,10 +586,7 @@ impl CkbRoot { depth, parent_fingerprint, child_number, - public_key: bitcoin::PublicKey { - compressed: true, - key: public_key, - }, + public_key, chain_code: ChainCode::from(&chain_code[..]), }; @@ -643,7 +635,7 @@ impl CkbRoot { .into_iter() .map(|(path, extended_pubkey)| { let pubkey = extended_pubkey.public_key; - let hash = H160::from_slice(&blake2b_256(&pubkey.key.serialize()[..])[0..20]) + let hash = H160::from_slice(&blake2b_256(&pubkey.serialize()[..])[0..20]) .expect("Generate hash(H160) from pubkey failed"); (path, hash) }) @@ -658,7 +650,7 @@ impl CkbRoot { pub fn derived_hash160(&self, chain: KeyChain, index: u32) -> (DerivationPath, H160) { let (path, extended_pubkey) = self.derived_pubkey(chain, index); let pubkey = extended_pubkey.public_key; - let hash160 = H160::from_slice(&blake2b_256(&pubkey.key.serialize()[..])[0..20]) + let hash160 = H160::from_slice(&blake2b_256(&pubkey.serialize()[..])[0..20]) .expect("Generate hash(H160) from pubkey failed"); (path, hash160) } @@ -851,25 +843,21 @@ impl MasterPrivKey { depth: 0, parent_fingerprint: Default::default(), child_number: ChildNumber::Normal { index: 0 }, - private_key: bitcoin::PrivateKey { - compressed: true, - network: bitcoin::Network::Bitcoin, - key: self.secp_secret_key, - }, + private_key: self.secp_secret_key, chain_code: ChainCode::from(&self.chain_code[..]), }; sk.derive_priv(&SECP256K1, path) .expect("Derive sub-privkey error") } - pub fn sign

(&self, message: &H256, path: &P) -> secp256k1::Signature + pub fn sign

(&self, message: &H256, path: &P) -> Signature where P: AsRef<[ChildNumber]>, { let message = secp256k1::Message::from_slice(message.as_bytes()).expect("Convert to message failed"); let sub_sk = self.sub_privkey(path); - SECP256K1.sign(&message, &sub_sk.private_key.key) + SECP256K1.sign_ecdsa(&message, &sub_sk.private_key) } pub fn sign_recoverable

(&self, message: &H256, path: &P) -> RecoverableSignature @@ -879,7 +867,7 @@ impl MasterPrivKey { let message = secp256k1::Message::from_slice(message.as_bytes()).expect("Convert to message failed"); let sub_sk = self.sub_privkey(path); - SECP256K1.sign_recoverable(&message, &sub_sk.private_key.key) + SECP256K1.sign_ecdsa_recoverable(&message, &sub_sk.private_key) } pub fn extended_pubkey

(&self, path: &P) -> ExtendedPubKey @@ -887,7 +875,7 @@ impl MasterPrivKey { P: AsRef<[ChildNumber]>, { let sub_sk = self.sub_privkey(path); - ExtendedPubKey::from_private(&SECP256K1, &sub_sk) + ExtendedPubKey::from_priv(&SECP256K1, &sub_sk) } pub fn ckb_root(&self) -> CkbRoot { @@ -904,7 +892,7 @@ impl MasterPrivKey { P: AsRef<[ChildNumber]>, { let sub_sk = self.sub_privkey(path); - let pubkey = secp256k1::PublicKey::from_secret_key(&SECP256K1, &sub_sk.private_key.key); + let pubkey = secp256k1::PublicKey::from_secret_key(&SECP256K1, &sub_sk.private_key); H160::from_slice(&blake2b_256(&pubkey.serialize()[..])[0..20]) .expect("Generate hash(H160) from pubkey failed") } diff --git a/plugin-protocol/Cargo.toml b/plugin-protocol/Cargo.toml index 9ead2c73..24b0b815 100644 --- a/plugin-protocol/Cargo.toml +++ b/plugin-protocol/Cargo.toml @@ -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.104.0" -ckb-jsonrpc-types = "=0.104.0" +ckb-types = "=0.105.1" +ckb-jsonrpc-types = "=0.105.1" serde = { version = "1.0", features = ["derive"] } serde_derive = "1.0" serde_json = "1.0" diff --git a/src/plugin/builtin.rs b/src/plugin/builtin.rs index 6a02ab20..9b6a5069 100644 --- a/src/plugin/builtin.rs +++ b/src/plugin/builtin.rs @@ -205,7 +205,6 @@ impl DefaultKeyStore { .extended_pubkey_with_password(&hash160, &path, password.as_bytes()) .map_err(|err| err.to_string())? .public_key - .key .serialize() .to_vec(); Ok(PluginResponse::Bytes(JsonBytes::from_vec(data))) diff --git a/src/subcommands/rpc.rs b/src/subcommands/rpc.rs index aa6b0761..7bee0be1 100644 --- a/src/subcommands/rpc.rs +++ b/src/subcommands/rpc.rs @@ -455,7 +455,7 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> { let resp = self .raw_rpc_client .get_transaction(hash) - .map(RawOptionTransactionWithStatus) + .map(RawOptionTransactionWithStatusResponse) .map_err(|err| err.to_string())?; Ok(Output::new_output(resp)) } else { @@ -801,7 +801,9 @@ pub struct BannedAddrList(pub Vec); pub struct RawRemoteNodes(pub Vec); #[derive(Serialize, Deserialize)] -pub struct RawOptionTransactionWithStatus(pub Option); +pub struct RawOptionTransactionWithStatusResponse( + pub Option, +); #[derive(Serialize, Deserialize)] pub struct RawOptionBlockView(pub Option); diff --git a/src/subcommands/util.rs b/src/subcommands/util.rs index 1604f72e..c051852e 100644 --- a/src/subcommands/util.rs +++ b/src/subcommands/util.rs @@ -8,7 +8,7 @@ use clap::{App, Arg, ArgMatches}; use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh}; use eaglesong::EagleSongBuilder; use faster_hex::hex_string; -use secp256k1::recovery::{RecoverableSignature, RecoveryId}; +use secp256k1::ecdsa::{RecoverableSignature, RecoveryId, Signature}; use ckb_crypto::secp::SECP256K1; use ckb_hash::blake2b_256; @@ -554,13 +554,15 @@ message = "0x" .map_err(|err| err.to_string())? .to_standard() } else if signature.len() == 64 { - secp256k1::Signature::from_compact(&signature).map_err(|err| err.to_string())? + Signature::from_compact(&signature).map_err(|err| err.to_string())? } else { return Err(format!("Invalid signature length: {}", signature.len())); }; let message = secp256k1::Message::from_slice(message.as_bytes()) .expect("Convert to message failed"); - let verify_ok = SECP256K1.verify(&message, &signature, &pubkey).is_ok(); + let verify_ok = SECP256K1 + .verify_ecdsa(&message, &signature, &pubkey) + .is_ok(); let result = serde_json::json!({ "pubkey": format!("0x{}", hex_string(&pubkey.serialize()[..])), "recoverable": recoverable, @@ -875,13 +877,13 @@ fn sign_message>( (Some(privkey), _, false) => { let message = secp256k1::Message::from_slice(message.as_bytes()).unwrap(); Ok(SECP256K1 - .sign(&message, privkey) + .sign_ecdsa(&message, privkey) .serialize_compact() .to_vec()) } (Some(privkey), _, true) => { let message = secp256k1::Message::from_slice(message.as_bytes()).unwrap(); - Ok(serialize_signature(&SECP256K1.sign_recoverable(&message, privkey)).to_vec()) + Ok(serialize_signature(&SECP256K1.sign_ecdsa_recoverable(&message, privkey)).to_vec()) } (None, Some((plugin_mgr, account)), false) => plugin_mgr .keystore_handler() diff --git a/src/utils/mock_tx_helper.rs b/src/utils/mock_tx_helper.rs index 87e3e5f7..b6a2bac2 100644 --- a/src/utils/mock_tx_helper.rs +++ b/src/utils/mock_tx_helper.rs @@ -436,7 +436,7 @@ mod test { } let message = secp256k1::Message::from_slice(tx_hash_hash.as_bytes()) .expect("Convert to secp256k1 message failed"); - let signature = SECP256K1.sign_recoverable(&message, &privkey); + let signature = SECP256K1.sign_ecdsa_recoverable(&message, &privkey); let (recov_id, data) = signature.serialize_compact(); let mut signature_bytes = [0u8; 65]; signature_bytes[0..64].copy_from_slice(&data[0..64]); diff --git a/src/utils/other.rs b/src/utils/other.rs index daa744af..a8f0b072 100644 --- a/src/utils/other.rs +++ b/src/utils/other.rs @@ -274,7 +274,7 @@ pub fn get_privkey_signer(privkey: PrivkeyWrapper) -> SignerFn { } else { let message = secp256k1::Message::from_slice(message.as_bytes()) .expect("Convert to secp256k1 message failed"); - let signature = SECP256K1.sign_recoverable(&message, &privkey); + let signature = SECP256K1.sign_ecdsa_recoverable(&message, &privkey); Ok(Some(serialize_signature(&signature))) } } else { @@ -284,7 +284,7 @@ pub fn get_privkey_signer(privkey: PrivkeyWrapper) -> SignerFn { ) } -pub fn serialize_signature(signature: &secp256k1::recovery::RecoverableSignature) -> [u8; 65] { +pub fn serialize_signature(signature: &secp256k1::ecdsa::RecoverableSignature) -> [u8; 65] { let (recov_id, data) = signature.serialize_compact(); let mut signature_bytes = [0u8; 65]; signature_bytes[0..64].copy_from_slice(&data[0..64]); diff --git a/src/utils/rpc/client.rs b/src/utils/rpc/client.rs index f105289a..fac90626 100644 --- a/src/utils/rpc/client.rs +++ b/src/utils/rpc/client.rs @@ -1,3 +1,5 @@ +use std::convert::TryInto; + use ckb_jsonrpc_types::{ Alert, BlockNumber, CellWithStatus, EpochNumber, JsonBytes, OutputsValidator, Script, }; @@ -102,8 +104,9 @@ impl HttpRpcClient { ) -> Result, String> { self.client .get_transaction(hash) - .map(|opt| opt.map(Into::into)) - .map_err(|err| err.to_string()) + .map(|opt| opt.map(TryInto::try_into)) + .map_err(|err| err.to_string())? + .transpose() } pub fn get_transaction_proof( &mut self, diff --git a/src/utils/rpc/mod.rs b/src/utils/rpc/mod.rs index 9b44a46b..2fd2ffc0 100644 --- a/src/utils/rpc/mod.rs +++ b/src/utils/rpc/mod.rs @@ -9,5 +9,5 @@ pub use types::{ CellDep, CellInput, CellOutput, ChainInfo, DepType, EpochView, Header, HeaderView, JsonBytes, LocalNode, MerkleProof, MinerReward, NodeAddress, OutPoint, ProposalShortId, RemoteNode, Script, ScriptHashType, Transaction, TransactionProof, TransactionView, TransactionWithStatus, - TxPoolInfo, TxStatus, Uint128, UncleBlock, UncleBlockView, + TransactionWithStatusResponse, TxPoolInfo, TxStatus, Uint128, UncleBlock, UncleBlockView, }; diff --git a/src/utils/rpc/types.rs b/src/utils/rpc/types.rs index 5a87c0ee..bfe0366a 100644 --- a/src/utils/rpc/types.rs +++ b/src/utils/rpc/types.rs @@ -330,16 +330,83 @@ impl From for TransactionView { } } +/// The enum `Either` with variants `Left` and `Right` is a general purpose +/// sum type with two cases. +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] +#[serde(untagged)] +pub enum Either { + /// A value of type `L`. + Left(L), + /// A value of type `R`. + Right(R), +} + +/// This is a wrapper for JSON serialization to select the format between Json and Hex. +/// +/// ## Examples +/// +/// `ResponseFormat` returns the block in its Json format or molecule serialized +/// Hex format. +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] +#[serde(transparent)] +pub struct ResponseFormat { + /// The inner value. + pub inner: Either, +} + #[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] pub struct TransactionWithStatus { + /// The transaction. pub transaction: Option, - /// Indicate the Transaction status + /// The Transaction status. + pub tx_status: TxStatus, +} +impl TryFrom for TransactionWithStatus { + type Error = String; + fn try_from( + json: rpc_types::TransactionWithStatusResponse, + ) -> Result { + Ok(TransactionWithStatus { + transaction: json + .transaction + .map(|tx| match tx.inner { + rpc_types::Either::Left(v) => Ok(TransactionView::from(v)), + rpc_types::Either::Right(bytes) => { + packed::TransactionReader::from_slice(bytes.as_bytes()) + .map(|reader| { + rpc_types::TransactionView::from(reader.to_entity().into_view()) + .into() + }) + .map_err(|err| { + format!("invalid molecule encoded TransactionView: {}", err) + }) + } + }) + .transpose()?, + tx_status: json.tx_status, + }) + } +} + +/// The JSON view of a transaction as well as its status. +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] +pub struct TransactionWithStatusResponse { + /// The transaction. + pub transaction: Option>, + /// The Transaction status. pub tx_status: TxStatus, } -impl From for TransactionWithStatus { - fn from(json: rpc_types::TransactionWithStatus) -> TransactionWithStatus { - TransactionWithStatus { - transaction: json.transaction.map(|tx| tx.into()), +impl From for TransactionWithStatusResponse { + fn from(json: rpc_types::TransactionWithStatusResponse) -> TransactionWithStatusResponse { + TransactionWithStatusResponse { + transaction: json.transaction.map(|tx| match tx.inner { + rpc_types::Either::Left(v) => ResponseFormat { + inner: Either::Left(v.into()), + }, + rpc_types::Either::Right(bytes) => ResponseFormat { + inner: Either::Right(bytes), + }, + }), tx_status: json.tx_status, } } diff --git a/src/utils/signer.rs b/src/utils/signer.rs index 90428645..deee3413 100644 --- a/src/utils/signer.rs +++ b/src/utils/signer.rs @@ -44,10 +44,10 @@ impl Signer for PrivkeyWrapper { } let msg = secp256k1::Message::from_slice(message).expect("Convert to message failed"); if recoverable { - let sig = SECP256K1.sign_recoverable(&msg, &self.0); + let sig = SECP256K1.sign_ecdsa_recoverable(&msg, &self.0); Ok(Bytes::from(serialize_signature(&sig).to_vec())) } else { - let sig = SECP256K1.sign(&msg, &self.0); + let sig = SECP256K1.sign_ecdsa(&msg, &self.0); Ok(Bytes::from(sig.serialize_compact().to_vec())) } } diff --git a/test/Cargo.toml b/test/Cargo.toml index aeb1d023..c4cf9636 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -14,12 +14,12 @@ log = "0.4" env_logger = "0.6" toml = "0.5.0" serde_yaml = "0.8.9" -ckb-sdk = "2.2.0" +ckb-sdk = "2.3.0" serde_json = "1.0" -ckb-types = "=0.104.0" -ckb-jsonrpc-types = "=0.104.0" -ckb-app-config = "=0.104.0" -ckb-chain-spec = "=0.104.0" +ckb-types = "=0.105.1" +ckb-jsonrpc-types = "=0.105.1" +ckb-app-config = "=0.105.1" +ckb-chain-spec = "=0.105.1" regex = "1.1.6" faster-hex = "0.6" From 1006224d3e299ea8eaede6b6429ae0dfafb5371f Mon Sep 17 00:00:00 2001 From: Linfeng Qian Date: Tue, 1 Nov 2022 14:34:20 +0800 Subject: [PATCH 2/2] doc: add change logs --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 121d9b49..c9bb599c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v1.2.0 +* Update ckb deps from `v0.104.0` to `v0.105.1` +* Update deps + - ckb-sdk to `v2.3.0` + - secp256k1 to `v0.24` + - bitcoin to `v0.27` +* Support ckb-indexer rpc from ckb node +* Add `account bitcoin-xpub` subcommand + # v1.1.0 * Update ckb deps from `v0.103.0` to `v0.104.0` * **BREAKING**: remove `ckb-index` crate, and effect following subcommands: