aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock228
-rw-r--r--Cargo.toml12
-rw-r--r--src/account.rs25
-rw-r--r--src/account/signature.rs24
-rw-r--r--src/cmd/hash.rs12
-rw-r--r--src/cmd/sign.rs15
-rw-r--r--src/hash.rs18
-rw-r--r--src/lib.rs1
-rw-r--r--src/message.rs10
-rw-r--r--src/mnemonic.rs15
-rw-r--r--src/transaction.rs7
-rw-r--r--src/typeddata.rs50
-rw-r--r--tests/util/mod.rs1
13 files changed, 210 insertions, 208 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 45b5909..761f8db 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,47 +4,48 @@ version = 3
[[package]]
name = "anstream"
-version = "0.5.0"
+version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c"
+checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
+ "is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
-version = "1.0.3"
+version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46"
+checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
[[package]]
name = "anstyle-parse"
-version = "0.2.1"
+version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
+checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
-version = "1.0.0"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
+checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
-version = "2.1.0"
+version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd"
+checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
dependencies = [
"anstyle",
"windows-sys",
@@ -52,9 +53,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.75"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
+checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "base16ct"
@@ -85,9 +86,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
-version = "4.4.3"
+version = "4.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "84ed82781cea27b43c9b106a979fe450a13a31aab0500595fb3fc06616de08e6"
+checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f"
dependencies = [
"clap_builder",
"clap_derive",
@@ -95,9 +96,9 @@ dependencies = [
[[package]]
name = "clap_builder"
-version = "4.4.2"
+version = "4.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08"
+checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f"
dependencies = [
"anstream",
"anstyle",
@@ -107,9 +108,9 @@ dependencies = [
[[package]]
name = "clap_derive"
-version = "4.4.2"
+version = "4.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
+checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
dependencies = [
"heck",
"proc-macro2",
@@ -119,36 +120,36 @@ dependencies = [
[[package]]
name = "clap_lex"
-version = "0.5.1"
+version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
+checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
[[package]]
name = "colorchoice"
-version = "1.0.0"
+version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
+checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
name = "const-oid"
-version = "0.9.5"
+version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f"
+checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "cpufeatures"
-version = "0.2.9"
+version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
+checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
dependencies = [
"libc",
]
[[package]]
name = "crypto-bigint"
-version = "0.5.3"
+version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124"
+checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [
"generic-array",
"rand_core",
@@ -168,9 +169,9 @@ dependencies = [
[[package]]
name = "der"
-version = "0.7.8"
+version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c"
+checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
dependencies = [
"const-oid",
"zeroize",
@@ -190,9 +191,9 @@ dependencies = [
[[package]]
name = "ecdsa"
-version = "0.16.8"
+version = "0.16.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4"
+checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca"
dependencies = [
"der",
"digest",
@@ -204,9 +205,9 @@ dependencies = [
[[package]]
name = "elliptic-curve"
-version = "0.13.5"
+version = "0.13.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b"
+checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
dependencies = [
"base16ct",
"crypto-bigint",
@@ -223,29 +224,29 @@ dependencies = [
[[package]]
name = "ethaddr"
-version = "0.1.2"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b95bb7621599236a07e6da2fd637dad0daad962bfd9d144e840495493f0bb958"
+checksum = "ecbcc1770d1b2e3fb83915c80c47a10efbe1964544a40e0211fe40274f8363c8"
dependencies = [
- "ethaddr-macros",
"serde",
"sha3",
]
[[package]]
-name = "ethaddr-macros"
-version = "0.1.2"
+name = "ethdigest"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fe1f104cb671aa4f3c99fea5ad19389f847a36078aa0281d1069e939bbfb8500"
+checksum = "3cadad23be1ff9cf970f84a87e8e9666c19b4a4393c1acf89a1790d727ae11cc"
dependencies = [
+ "serde",
"sha3",
]
[[package]]
name = "ethnum"
-version = "1.4.0"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c8ff382b2fa527fb7fb06eeebfc5bbb3f17e3cc6b9d70b006c41daa8824adac"
+checksum = "b90ca2580b73ab6a1f724b76ca11ab632df820fd6040c336200d2c1df7b3c82c"
dependencies = [
"serde",
]
@@ -273,9 +274,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.10"
+version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
+checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
@@ -300,6 +301,7 @@ dependencies = [
"anyhow",
"clap",
"ethaddr",
+ "ethdigest",
"ethnum",
"hex",
"hex-literal",
@@ -310,15 +312,14 @@ dependencies = [
"serde",
"serde_json",
"sha2",
- "sha3",
"unicode-normalization",
]
[[package]]
name = "heck"
-version = "0.4.1"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hex"
@@ -342,16 +343,22 @@ dependencies = [
]
[[package]]
+name = "is_terminal_polyfill"
+version = "1.70.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
+
+[[package]]
name = "itoa"
-version = "1.0.9"
+version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
+checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "k256"
-version = "0.13.1"
+version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc"
+checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b"
dependencies = [
"cfg-if",
"ecdsa",
@@ -363,18 +370,18 @@ dependencies = [
[[package]]
name = "keccak"
-version = "0.1.4"
+version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940"
+checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654"
dependencies = [
"cpufeatures",
]
[[package]]
name = "libc"
-version = "0.2.148"
+version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
+checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "maplit"
@@ -384,9 +391,9 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "once_cell"
-version = "1.18.0"
+version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "pbkdf2"
@@ -409,18 +416,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.67"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.33"
+version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
@@ -446,9 +453,9 @@ dependencies = [
[[package]]
name = "ryu"
-version = "1.0.15"
+version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
+checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "sec1"
@@ -466,18 +473,18 @@ dependencies = [
[[package]]
name = "serde"
-version = "1.0.188"
+version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
+checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.188"
+version = "1.0.203"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
+checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
dependencies = [
"proc-macro2",
"quote",
@@ -486,9 +493,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.107"
+version = "1.0.118"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
+checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4"
dependencies = [
"itoa",
"ryu",
@@ -497,9 +504,9 @@ dependencies = [
[[package]]
name = "sha2"
-version = "0.10.7"
+version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"
+checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
@@ -518,9 +525,9 @@ dependencies = [
[[package]]
name = "signature"
-version = "2.1.0"
+version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500"
+checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest",
"rand_core",
@@ -528,9 +535,9 @@ dependencies = [
[[package]]
name = "spki"
-version = "0.7.2"
+version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a"
+checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
dependencies = [
"base64ct",
"der",
@@ -538,21 +545,21 @@ dependencies = [
[[package]]
name = "strsim"
-version = "0.10.0"
+version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "subtle"
-version = "2.5.0"
+version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
+checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
-version = "2.0.35"
+version = "2.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "59bf04c28bee9043ed9ea1e41afc0552288d3aba9c6efdd78903b802926f4879"
+checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9"
dependencies = [
"proc-macro2",
"quote",
@@ -561,9 +568,9 @@ dependencies = [
[[package]]
name = "tinyvec"
-version = "1.6.0"
+version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
+checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82"
dependencies = [
"tinyvec_macros",
]
@@ -588,18 +595,18 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
-version = "0.1.22"
+version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
+checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
dependencies = [
"tinyvec",
]
[[package]]
name = "utf8parse"
-version = "0.2.1"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
+checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "version_check"
@@ -615,22 +622,23 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
-version = "0.48.0"
+version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
+checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
+checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
+ "windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
@@ -639,48 +647,54 @@ dependencies = [
[[package]]
name = "windows_aarch64_gnullvm"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
+checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
+checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
+checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
+checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
+checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
+checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
-version = "0.48.5"
+version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
+checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
[[package]]
name = "zeroize"
-version = "1.6.0"
+version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
+checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
diff --git a/Cargo.toml b/Cargo.toml
index 7e98e69..7c0eaab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,18 +1,19 @@
[package]
name = "hdwallet"
version = "0.2.4"
-authors = ["Nicholas Rodrigues Lordello <[email protected]>"]
+authors = ["Nicholas Rodrigues Lordello <[email protected]>"]
edition = "2021"
description = "Hierarchical deterministic wallet for Ethereum"
documentation = "https://docs.rs/hdwallet"
-homepage = "https://github.com/nlordell/hdwallet"
-repository = "https://github.com/nlordell/hdwallet"
-license = "GPL-3.0-or-later"
+homepage = "https://codeberg.org/nlordell/hdwallet"
+repository = "https://codeberg.org/nlordell/hdwallet"
+license = "GPL-3.0-only"
[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive", "env"] }
-ethaddr = { version = "0.1", features = ["macros", "serde"] }
+ethaddr = { version = "0.2", features = ["serde"] }
+ethdigest = { version = "0.4", features = ["serde"] }
ethnum = { version = "1", features = ["serde"] }
hex = "0.4"
hmac = { version = "0.12", features = ["std"] }
@@ -21,7 +22,6 @@ pbkdf2 = { version = "0.12", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.10"
-sha3 = "0.10"
unicode-normalization = "0.1"
[dev-dependencies]
diff --git a/src/account.rs b/src/account.rs
index f862853..f3340aa 100644
--- a/src/account.rs
+++ b/src/account.rs
@@ -4,9 +4,9 @@ mod public;
mod signature;
pub use self::{public::PublicKey, signature::Signature};
-use crate::hash;
use anyhow::Result;
use ethaddr::Address;
+use ethdigest::Digest;
use k256::{
ecdsa::{hazmat::SignPrimitive, SigningKey},
SecretKey,
@@ -40,9 +40,9 @@ impl PrivateKey {
// an uncompressed point) and the subsequent bytes are the coordinates
// we want. So discard the first byte for the address calculation.
debug_assert_eq!(encoded[0], 0x04);
- let hash = hash::keccak256(&encoded[1..]);
+ let digest = Digest::of(&encoded[1..]);
- Address::from_slice(&hash[12..])
+ Address::from_slice(&digest[12..])
}
/// Returns the private key's 32 byte secret.
@@ -51,15 +51,15 @@ impl PrivateKey {
}
/// Generate a signature for the specified message.
- pub fn sign(&self, message: [u8; 32]) -> Signature {
+ pub fn sign(&self, message: Digest) -> Signature {
self.try_sign(message).expect("signature operation failed")
}
/// Generate a signature for the specified message.
- pub fn try_sign(&self, message: [u8; 32]) -> Result<Signature> {
+ pub fn try_sign(&self, message: Digest) -> Result<Signature> {
let (signature, recovery_id) = SigningKey::from(&self.0)
.as_nonzero_scalar()
- .try_sign_prehashed_rfc6979::<Sha256>(&message.into(), b"")?;
+ .try_sign_prehashed_rfc6979::<Sha256>(&message.0.into(), b"")?;
Ok(Signature(signature, recovery_id.unwrap()))
}
}
@@ -74,26 +74,27 @@ impl Debug for PrivateKey {
mod tests {
use super::*;
use crate::ganache::DETERMINISTIC_PRIVATE_KEY;
- use hex_literal::hex;
+ use ethaddr::address;
+ use ethnum::uint;
#[test]
fn ganache_determinitic_address() {
let key = PrivateKey::new(DETERMINISTIC_PRIVATE_KEY).unwrap();
assert_eq!(
- *key.address(),
- hex!("90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"),
+ key.address(),
+ address!("90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"),
);
}
#[test]
fn ganache_deterministic_signature() {
let key = PrivateKey::new(DETERMINISTIC_PRIVATE_KEY).unwrap();
- let message = hash::keccak256(b"\x19Ethereum Signed Message:\n12Hello World!");
+ let message = Digest::of(b"\x19Ethereum Signed Message:\n12Hello World!");
assert_eq!(
key.sign(message),
Signature::from_parts(
- hex!("408790f153cbfa2722fc708a57d97a43b24429724cf060df7c915d468c43bd84"),
- hex!("61c96aac95ce37d7a31087b6634f4a3ea439a9f704b5c818584fa2a32fa83859"),
+ uint!("0x408790f153cbfa2722fc708a57d97a43b24429724cf060df7c915d468c43bd84"),
+ uint!("0x61c96aac95ce37d7a31087b6634f4a3ea439a9f704b5c818584fa2a32fa83859"),
1,
),
);
diff --git a/src/account/signature.rs b/src/account/signature.rs
index ba3b959..dbc47d6 100644
--- a/src/account/signature.rs
+++ b/src/account/signature.rs
@@ -43,9 +43,9 @@ impl Signature {
/// # Panics
///
/// Panics on invalid signature parts.
- pub fn from_parts(r: [u8; 32], s: [u8; 32], y_parity: u8) -> Self {
+ pub fn from_parts(r: U256, s: U256, y_parity: u8) -> Self {
Self(
- ecdsa::Signature::from_scalars(r, s).unwrap(),
+ ecdsa::Signature::from_scalars(r.to_be_bytes(), s.to_be_bytes()).unwrap(),
y_parity.try_into().unwrap(),
)
}
@@ -77,10 +77,13 @@ impl FromStr for Signature {
_ => bail!("invalid V-value, must be 27 or 28 but got {v}"),
};
- Ok(Self::from_parts(
- signature[0..32].try_into().unwrap(),
- signature[32..64].try_into().unwrap(),
- y_parity,
+ Ok(Self(
+ ecdsa::Signature::from_scalars(
+ <[u8; 32]>::try_from(&signature[0..32])?,
+ <[u8; 32]>::try_from(&signature[32..64])?,
+ )
+ .unwrap(),
+ y_parity.try_into()?,
))
}
}
@@ -88,16 +91,21 @@ impl FromStr for Signature {
#[cfg(test)]
mod tests {
use super::*;
+ use ethnum::uint;
#[test]
fn replay_protection() {
- let signature = Signature::from_parts([1; 32], [2; 32], 0);
+ let signature = Signature::from_parts(U256::new(1), U256::new(2), 0);
assert_eq!(signature.v(Some(U256::new(1))), U256::new(37));
}
#[test]
fn signature_to_string() {
- let signature = Signature::from_parts([1; 32], [2; 32], 0);
+ let signature = Signature::from_parts(
+ uint!("0x0101010101010101010101010101010101010101010101010101010101010101"),
+ uint!("0x0202020202020202020202020202020202020202020202020202020202020202"),
+ 0,
+ );
assert_eq!(
signature.to_string(),
"0x0101010101010101010101010101010101010101010101010101010101010101\
diff --git a/src/cmd/hash.rs b/src/cmd/hash.rs
index 4a93d3a..1235d9f 100644
--- a/src/cmd/hash.rs
+++ b/src/cmd/hash.rs
@@ -3,9 +3,9 @@
use crate::cmd;
use anyhow::Result;
use clap::Parser;
+use ethdigest::Digest;
use hdwallet::{
- account::Signature, hash, message::EthereumMessage, transaction::Transaction,
- typeddata::TypedData,
+ account::Signature, message::EthereumMessage, transaction::Transaction, typeddata::TypedData,
};
use std::path::PathBuf;
@@ -59,7 +59,7 @@ enum Input {
}
pub fn run(options: Options) -> Result<()> {
- let hash = match options.input {
+ let digest = match options.input {
Input::Transaction {
transaction,
signature,
@@ -67,7 +67,7 @@ pub fn run(options: Options) -> Result<()> {
let transaction =
serde_json::from_slice::<Transaction>(&cmd::read_input(&transaction)?)?;
match signature {
- Some(signature) => hash::keccak256(transaction.encode(signature)),
+ Some(signature) => Digest::of(transaction.encode(signature)),
None => transaction.signing_message(),
}
}
@@ -88,10 +88,10 @@ pub fn run(options: Options) -> Result<()> {
}
Input::Data { data } => {
let data = cmd::read_input(&data)?;
- hash::keccak256(data)
+ Digest::of(data)
}
};
- println!("0x{}", hex::encode(hash));
+ println!("{digest}");
Ok(())
}
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index d3005ea..75cc2bc 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -1,14 +1,15 @@
//! Module implementing the `sign` subcommand for generating ECDSA signatures.
use crate::cmd::{self, AccountOptions};
-use anyhow::{ensure, Context as _, Result};
+use anyhow::{ensure, Result};
use clap::Parser;
+use ethdigest::Digest;
use hdwallet::{
message::EthereumMessage,
transaction::{LegacyTransaction, Transaction},
typeddata::TypedData,
};
-use std::{convert::TryInto, path::PathBuf};
+use std::path::PathBuf;
#[derive(Debug, Parser)]
pub struct Options {
@@ -58,8 +59,8 @@ enum Input {
/// Sign a raw data.
Raw {
/// The 32 byte message to sign specified as a hexadecimal string.
- #[clap(name = "BYTES", value_parser = permissive_hex_digest)]
- message: [u8; 32],
+ #[clap(name = "BYTES")]
+ message: Digest,
},
}
@@ -101,9 +102,3 @@ pub fn run(options: Options) -> Result<()> {
}
Ok(())
}
-
-fn permissive_hex_digest(s: &str) -> Result<[u8; 32]> {
- cmd::permissive_hex(s)?[..]
- .try_into()
- .context("message for signing must be exactly 32 bytes long")
-}
diff --git a/src/hash.rs b/src/hash.rs
deleted file mode 100644
index b3091d2..0000000
--- a/src/hash.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-//! Module implementing various hashing utilities.
-
-use sha2::{Digest as _, Sha256};
-use sha3::Keccak256;
-
-/// Returns the Keccak-256 hash of the specified input.
-pub fn keccak256(data: impl AsRef<[u8]>) -> [u8; 32] {
- let mut hasher = Keccak256::new();
- hasher.update(data.as_ref());
- hasher.finalize().into()
-}
-
-/// Returns the SHA256 hash of the specified input.
-pub fn sha256(data: impl AsRef<[u8]>) -> [u8; 32] {
- let mut hasher = Sha256::new();
- hasher.update(data.as_ref());
- hasher.finalize().into()
-}
diff --git a/src/lib.rs b/src/lib.rs
index ba715bd..7bd9d5f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,6 @@
//! these derived keys for signing various messages relative to Ethereum.
pub mod account;
-pub mod hash;
pub mod hdk;
pub mod message;
pub mod mnemonic;
diff --git a/src/message.rs b/src/message.rs
index 1c0d594..449a16e 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -1,6 +1,6 @@
//! Ethereum message for signing.
-use crate::hash;
+use ethdigest::Digest;
use std::io::Write as _;
/// A message to be signed with an Ethereum specific prefix.
@@ -11,13 +11,13 @@ where
T: AsRef<[u8]>,
{
/// Computes the 32-byte message used for ECDSA signing with a private key.
- pub fn signing_message(&self) -> [u8; 32] {
+ pub fn signing_message(&self) -> Digest {
digest(self.0.as_ref())
}
}
/// Computes the Ethereum-specific digest for a message.
-fn digest(data: &[u8]) -> [u8; 32] {
+fn digest(data: &[u8]) -> Digest {
let mut buffer = Vec::with_capacity(46 + data.len());
buffer.extend_from_slice(b"\x19Ethereum Signed Message:\n");
// Display implementation for `usize` should not error when writing to an
@@ -27,7 +27,7 @@ fn digest(data: &[u8]) -> [u8; 32] {
write!(buffer, "{}", data.len()).expect("unexpected error writing number");
buffer.extend_from_slice(data);
- hash::keccak256(buffer)
+ Digest::of(buffer)
}
#[cfg(test)]
@@ -38,7 +38,7 @@ mod tests {
fn computes_digest() {
assert_eq!(
digest(b"hello world!"),
- hash::keccak256(b"\x19Ethereum Signed Message:\n12hello world!"),
+ Digest::of(b"\x19Ethereum Signed Message:\n12hello world!"),
);
}
}
diff --git a/src/mnemonic.rs b/src/mnemonic.rs
index bd9e108..a9420c4 100644
--- a/src/mnemonic.rs
+++ b/src/mnemonic.rs
@@ -4,12 +4,11 @@ mod language;
mod wordlist;
pub use self::{language::Language, wordlist::WORD_COUNT};
-use crate::{hash, rand};
+use crate::rand;
use anyhow::{ensure, Context as _, Result};
use hmac::Hmac;
-use sha2::Sha512;
+use sha2::{Digest as _, Sha256, Sha512};
use std::{
- convert::TryInto,
fmt::{self, Display, Formatter},
mem,
ops::Deref,
@@ -49,7 +48,7 @@ impl Mnemonic {
let (seed, hash) = buf.split_at_mut(len);
rand::get_entropy(&mut *seed)?;
- hash[..32].copy_from_slice(&hash::sha256(seed));
+ hash_seed(seed, hash);
buf
};
@@ -94,7 +93,7 @@ impl Mnemonic {
debug_assert_eq!(len * 8 + bit_offset, words.len() * WORD_BITS);
debug_assert_eq!(byte_offset, len);
- hash[..32].copy_from_slice(&hash::sha256(seed));
+ hash_seed(seed, hash);
let checksum_mask = (1 << bit_offset) - 1;
ensure!(
@@ -209,6 +208,12 @@ fn mnemonic_to_byte_length(len: usize) -> Result<usize> {
Ok((len * WORD_BITS * 32 / 33) / 8)
}
+fn hash_seed(seed: &[u8], hash: &mut [u8]) {
+ let mut hasher = Sha256::new();
+ hasher.update(seed);
+ hasher.finalize_into((&mut hash[..32]).into());
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/transaction.rs b/src/transaction.rs
index cbc0e4f..5635766 100644
--- a/src/transaction.rs
+++ b/src/transaction.rs
@@ -10,7 +10,8 @@ mod rlp;
pub use self::{
eip1559::Eip1559Transaction, eip2930::Eip2930Transaction, legacy::LegacyTransaction,
};
-use crate::{account::Signature, hash, serialization::JsonObject};
+use crate::{account::Signature, serialization::JsonObject};
+use ethdigest::Digest;
use serde::{
de::{self, Deserializer},
Deserialize,
@@ -26,8 +27,8 @@ pub enum Transaction {
impl Transaction {
/// Returns the RLP encoded transaction with an optional signature.
- pub fn signing_message(&self) -> [u8; 32] {
- hash::keccak256(self.rlp_encode(None))
+ pub fn signing_message(&self) -> Digest {
+ Digest::of(self.rlp_encode(None))
}
/// Returns the 32-byte message used for signing.
diff --git a/src/typeddata.rs b/src/typeddata.rs
index 35ecdd6..84bae2b 100644
--- a/src/typeddata.rs
+++ b/src/typeddata.rs
@@ -1,11 +1,9 @@
//! Module for hashing EIP-712 typed data.
-use crate::{
- hash,
- serialization::{self, JsonObject},
-};
+use crate::serialization::{self, JsonObject};
use anyhow::{bail, ensure, Context as _, Result};
use ethaddr::Address;
+use ethdigest::Digest;
use ethnum::{serde::permissive, I256, U256};
use serde::{
de::{self, Deserializer},
@@ -20,26 +18,26 @@ use std::{
/// EIP-712 typed data.
pub struct TypedData {
- digest: [u8; 32],
- domain_separator: [u8; 32],
- message_hash: [u8; 32],
+ digest: Digest,
+ domain_separator: Digest,
+ message_hash: Digest,
}
impl TypedData {
/// Returns the 32-byte message to be used for siging the typed data.
///
/// This is the EIP-712 digest of the typed data.
- pub fn signing_message(&self) -> [u8; 32] {
+ pub fn signing_message(&self) -> Digest {
self.digest
}
/// Returns the 32-byte hash of the typed data domain.
- pub fn domain_separator(&self) -> [u8; 32] {
+ pub fn domain_separator(&self) -> Digest {
self.domain_separator
}
/// Returns the 32-byte hash of the typed data message.
- pub fn message_hash(&self) -> [u8; 32] {
+ pub fn message_hash(&self) -> Digest {
self.message_hash
}
}
@@ -79,9 +77,9 @@ impl TypedDataBlob {
let mut buffer = [0; 66];
buffer[0..2].copy_from_slice(b"\x19\x01");
- buffer[2..34].copy_from_slice(&domain_separator);
- buffer[34..66].copy_from_slice(&message_hash);
- let digest = hash::keccak256(buffer);
+ buffer[2..34].copy_from_slice(domain_separator.as_slice());
+ buffer[34..66].copy_from_slice(message_hash.as_slice());
+ let digest = Digest::of(buffer);
Ok(TypedData {
digest,
@@ -127,10 +125,10 @@ impl TypedDataBlob {
struct Types(HashMap<String, Vec<Member>>);
impl Types {
- fn struct_hash(&self, kind: &str, mut data: JsonObject) -> Result<[u8; 32]> {
+ fn struct_hash(&self, kind: &str, mut data: JsonObject) -> Result<Digest> {
let type_definition = self.type_definition(kind)?;
let mut buffer = vec![0_u8; 32 * (1 + type_definition.members.len())];
- buffer[0..32].copy_from_slice(&self.type_hash(kind)?);
+ buffer[0..32].copy_from_slice(self.type_hash(kind)?.as_slice());
for (i, member) in type_definition.members.iter().enumerate() {
buffer[(i + 1) * 32..][..32].copy_from_slice(
&self.encode_value(
@@ -147,7 +145,7 @@ impl Types {
"additional unspecified {kind} properties: {}",
data.keys().cloned().collect::<Vec<_>>().join(", "),
);
- Ok(hash::keccak256(&buffer))
+ Ok(Digest::of(buffer))
}
fn encode_type(&self, kind: &str) -> Result<String> {
@@ -172,9 +170,9 @@ impl Types {
Ok(buffer)
}
- fn type_hash(&self, kind: &str) -> Result<[u8; 32]> {
+ fn type_hash(&self, kind: &str) -> Result<Digest> {
let encoded_type = self.encode_type(kind)?;
- Ok(hash::keccak256(encoded_type))
+ Ok(Digest::of(encoded_type))
}
fn type_definition<'a>(&'a self, kind: &'a str) -> Result<TypeDefinition<'a>> {
@@ -204,7 +202,7 @@ impl Types {
.copy_from_slice(&bytes);
buffer
}
- None => hash::keccak256(&bytes),
+ None => Digest::of(&bytes).0,
}
}
MemberKind::Uint(n) => {
@@ -234,13 +232,13 @@ impl Types {
buffer[12..].copy_from_slice(&*address);
buffer
}
- MemberKind::String => hash::keccak256(&*Cow::<str>::deserialize(value)?),
+ MemberKind::String => Digest::of(&*Cow::<str>::deserialize(value)?).0,
MemberKind::Struct(inner) => {
let value = match value {
Value::Object(value) => value,
value => bail!("expected JSON object but got '{value}'"),
};
- self.struct_hash(inner, value)?
+ *self.struct_hash(inner, value)?
}
MemberKind::Array(inner, size) => {
let value = match value {
@@ -259,7 +257,7 @@ impl Types {
for (i, element) in value.into_iter().enumerate() {
buffer[(i * 32)..][..32].copy_from_slice(&self.encode_value(inner, element)?);
}
- hash::keccak256(&buffer)
+ Digest::of(&buffer).0
}
})
}
@@ -281,7 +279,7 @@ impl<'a> TypeDefinition<'a> {
impl Display for TypeDefinition<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}(", self.kind)?;
- if let Some(first_member) = self.members.get(0) {
+ if let Some(first_member) = self.members.first() {
write!(f, "{first_member}")?;
}
for member in self.members.get(1..).into_iter().flatten() {
@@ -390,7 +388,7 @@ impl<'de> Deserialize<'de> for MemberKind {
#[cfg(test)]
mod tests {
use super::*;
- use hex_literal::hex;
+ use ethdigest::digest;
use maplit::hashmap;
use serde_json::json;
@@ -438,7 +436,7 @@ mod tests {
.unwrap();
assert_eq!(
typed_data.signing_message(),
- hex!("be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2"),
+ digest!("be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2"),
);
}
@@ -499,7 +497,7 @@ mod tests {
.unwrap();
assert_eq!(
typed_data.signing_message(),
- hex!("a150d6fdc3fe189531a29808ccdd2808005c24274de09187af619f69377221a1"),
+ digest!("a150d6fdc3fe189531a29808ccdd2808005c24274de09187af619f69377221a1"),
);
}
diff --git a/tests/util/mod.rs b/tests/util/mod.rs
index c965ffd..4fe7c18 100644
--- a/tests/util/mod.rs
+++ b/tests/util/mod.rs
@@ -3,7 +3,6 @@
#[path = "../../src/ganache.rs"]
mod ganache;
-pub use ganache::*;
use std::{
io::Write as _,
process::{Command, Stdio},