From 59334220970e35d990ef2b4a9099995f656df72a Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Wed, 21 Aug 2024 10:55:00 +0800 Subject: [PATCH] chore: cleanup dependencies --- Cargo.lock | 278 +++++---------------------- Cargo.toml | 18 +- src/ic_cose_canister/Cargo.toml | 14 -- src/ic_cose_canister/src/api_cose.rs | 14 +- src/ic_cose_canister/src/lib.rs | 4 +- src/ic_cose_types/Cargo.toml | 4 - src/ic_cose_types/src/bytes.rs | 105 ---------- src/ic_cose_types/src/cose/mod.rs | 6 - src/ic_cose_types/src/lib.rs | 2 - src/ic_cose_types/src/types/mod.rs | 12 +- 10 files changed, 69 insertions(+), 388 deletions(-) delete mode 100644 src/ic_cose_types/src/bytes.rs diff --git a/Cargo.lock b/Cargo.lock index 344591a..30f56e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,9 +66,9 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "assert_matches" @@ -100,12 +100,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64ct" version = "1.6.0" @@ -213,14 +207,17 @@ dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] name = "cc" -version = "1.1.10" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" +dependencies = [ + "shlex", +] [[package]] name = "cfg-if" @@ -433,7 +430,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -582,12 +579,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - [[package]] name = "erased-serde" version = "0.3.31" @@ -632,15 +623,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "form_urlencoded" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" -dependencies = [ - "percent-encoding", -] - [[package]] name = "futures" version = "0.3.30" @@ -697,7 +679,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -789,12 +771,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "heck" version = "0.5.0" @@ -834,17 +810,6 @@ dependencies = [ "digest", ] -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "iana-time-zone" version = "0.1.60" @@ -910,9 +875,9 @@ dependencies = [ [[package]] name = "ic-cdk" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff384f182459bec490a7f50a58bbdf8f7a6934de4dcc259e30c70641bcbcb917" +checksum = "9cff1a3c3db565e3384c9c9d6d676b0a3f89a0886f4f787294d9c946d844369f" dependencies = [ "candid", "ic-cdk-macros 0.14.0", @@ -923,9 +888,9 @@ dependencies = [ [[package]] name = "ic-cdk" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c44983d6e97135d86132111bae5b86c34c498d96b4f182638bebcc7ac07e03c" +checksum = "038ff230bf0fc8630943e3c52e989d248a7c89834ccb65da408fabc5817a475b" dependencies = [ "candid", "ic-cdk-macros 0.15.0", @@ -945,7 +910,7 @@ dependencies = [ "quote", "serde", "serde_tokenstream", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -959,7 +924,7 @@ dependencies = [ "quote", "serde", "serde_tokenstream", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -969,25 +934,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc4a42e669e47cf58fc18e071898e67922c81aa480edbf930ed1468dd53f44ee" dependencies = [ "futures", - "ic-cdk 0.14.0", + "ic-cdk 0.14.1", "ic0", "serde", "serde_bytes", "slotmap", ] -[[package]] -name = "ic-certification" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64ee3d8b6e81b51f245716d3e0badb63c283c00f3c9fb5d5219afc30b5bf821" -dependencies = [ - "hex", - "serde", - "serde_bytes", - "sha2", -] - [[package]] name = "ic-constants" version = "0.9.0" @@ -1079,7 +1032,7 @@ name = "ic-crypto-internal-types" version = "0.9.0" source = "git+https://github.com/dfinity/ic/?rev=d19fa446ab35780b2c6d8b82ea32d808cca558d5#d19fa446ab35780b2c6d8b82ea32d808cca558d5" dependencies = [ - "arrayvec 0.7.4", + "arrayvec 0.7.6", "hex", "ic-protobuf", "phantom_newtype", @@ -1134,21 +1087,6 @@ dependencies = [ "strum_macros", ] -[[package]] -name = "ic-http-certification" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff0b97e949845039149dc5e7ea6a7c12ee4333bb402e37bc507904643c7b3e41" -dependencies = [ - "candid", - "http", - "ic-certification", - "ic-representation-independent-hash", - "serde", - "thiserror", - "urlencoding", -] - [[package]] name = "ic-management-canister-types" version = "0.9.0" @@ -1183,16 +1121,6 @@ dependencies = [ "slog", ] -[[package]] -name = "ic-representation-independent-hash" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08ae59483e377cd9aad94ec339ed1d2583b0d5929cab989328dac2d853b2f570" -dependencies = [ - "leb128", - "sha2", -] - [[package]] name = "ic-stable-structures" version = "0.6.5" @@ -1207,7 +1135,7 @@ name = "ic-types" version = "0.9.0" source = "git+https://github.com/dfinity/ic/?rev=d19fa446ab35780b2c6d8b82ea32d808cca558d5#d19fa446ab35780b2c6d8b82ea32d808cca558d5" dependencies = [ - "base64 0.13.1", + "base64", "bincode", "candid", "chrono", @@ -1257,56 +1185,38 @@ checksum = "8de254dd67bbd58073e23dc1c8553ba12fa1dc610a19de94ad2bbcd0460c067f" [[package]] name = "ic_cose_canister" -version = "0.1.0" +version = "0.1.1" dependencies = [ - "base64 0.21.7", - "bytes", "candid", "ciborium", - "ed25519-dalek", "getrandom", - "hex", - "hmac", - "ic-cdk 0.15.0", + "ic-cdk 0.15.1", "ic-cdk-timers", "ic-crypto-ed25519", "ic-crypto-extended-bip32", - "ic-http-certification", "ic-stable-structures", "ic_cose_types", - "icrc-ledger-types 0.1.5", - "lazy_static", - "num-traits", - "once_cell", "serde", "serde_bytes", - "serde_json", - "sha2", - "sha3", - "x25519-dalek", ] [[package]] name = "ic_cose_types" -version = "0.1.0" +version = "0.1.1" dependencies = [ "aes-gcm", - "base64 0.21.7", "candid", "ciborium", "coset", - "crc32fast", "ed25519-dalek", - "hex", "hmac", - "icrc-ledger-types 0.1.6", + "icrc-ledger-types", "k256", "num-traits", "serde", "serde_bytes", "sha2", "sha3", - "url", "x25519-dalek", ] @@ -1323,24 +1233,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "icrc-ledger-types" -version = "0.1.5" -source = "git+https://github.com/dfinity/ic/?rev=d19fa446ab35780b2c6d8b82ea32d808cca558d5#d19fa446ab35780b2c6d8b82ea32d808cca558d5" -dependencies = [ - "base32", - "candid", - "crc32fast", - "hex", - "itertools", - "num-bigint", - "num-traits", - "serde", - "serde_bytes", - "sha2", - "strum", -] - [[package]] name = "icrc-ledger-types" version = "0.1.6" @@ -1367,26 +1259,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" -dependencies = [ - "equivalent", - "hashbrown", -] - [[package]] name = "inout" version = "0.1.3" @@ -1460,9 +1332,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libm" @@ -1600,7 +1472,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" dependencies = [ - "base64 0.13.1", + "base64", ] [[package]] @@ -1612,12 +1484,6 @@ dependencies = [ "base64ct", ] -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - [[package]] name = "phantom_newtype" version = "0.9.0" @@ -1736,7 +1602,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -1846,9 +1712,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -1874,22 +1740,21 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.207" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] name = "serde_json" -version = "1.0.124" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ - "indexmap", "itoa", "memchr", "ryu", @@ -1898,14 +1763,14 @@ dependencies = [ [[package]] name = "serde_tokenstream" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8790a7c3fe883e443eaa2af6f705952bc5d6e8671a220b9335c8cae92c037e74" +checksum = "64060d864397305347a78851c51588fd283767e7e7589829e8121d65512340f1" dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -1951,6 +1816,12 @@ dependencies = [ "keccak", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -2048,7 +1919,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -2070,9 +1941,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.74" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -2096,7 +1967,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -2136,21 +2007,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tinyvec" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "typed-arena" version = "2.0.2" @@ -2163,27 +2019,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-segmentation" version = "1.11.0" @@ -2206,23 +2047,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "url" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf8-width" version = "0.1.7" @@ -2263,7 +2087,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", "wasm-bindgen-shared", ] @@ -2285,7 +2109,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2427,7 +2251,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] [[package]] @@ -2447,5 +2271,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.75", ] diff --git a/Cargo.toml b/Cargo.toml index 58dee83..044a39d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ strip = true opt-level = 's' [workspace.package] -version = "0.1.0" +version = "0.1.1" edition = "2021" repository = "https://github.com/ldclabs/ic-cose" keywords = ["config", "cbor", "canister", "icp", "encryption"] @@ -17,24 +17,13 @@ categories = ["web-programming"] license = "MIT OR Apache-2.0" [workspace.dependencies] -async-trait = "0.1" -bytes = "1" -base64 = "0.21" candid = "0.10" ciborium = "0.2" -ciborium-io = "0.2" -futures = "0.3" -futures-util = "0.3" -log = "0.4" serde = "1" serde_bytes = "0.11" -serde_json = { version = "1", features = ["preserve_order"] } -structured-logger = "1" -tokio = { version = "1", features = ["full"] } k256 = { version = "0.13", features = ["ecdsa", "schnorr"] } ed25519-dalek = "2" x25519-dalek = { version = "2", features = ["static_secrets"] } -hex = "0.4" hmac = "0.12" sha2 = "0.10" sha3 = "0.10" @@ -43,11 +32,6 @@ ic-cdk = "0.15" ic-cdk-timers = "0.8" ic-stable-structures = "0.6" icrc-ledger-types = "0.1" -ic-http-certification = { version = "2.5", features = ["serde"] } -anyhow = "1" -crc32fast = "1.4" -url = "2.5" -once_cell = "1.19" getrandom = { version = "0.2", features = ["custom"] } coset = "0.3.8" aes-gcm = "0.10" diff --git a/src/ic_cose_canister/Cargo.toml b/src/ic_cose_canister/Cargo.toml index 12468f1..85051ad 100644 --- a/src/ic_cose_canister/Cargo.toml +++ b/src/ic_cose_canister/Cargo.toml @@ -15,28 +15,14 @@ license.workspace = true crate-type = ["cdylib"] [dependencies] -bytes = { workspace = true } candid = { workspace = true } ciborium = { workspace = true } -sha2 = { workspace = true } -sha3 = { workspace = true } ic-cdk = { workspace = true } -hex = { workspace = true } -hmac = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true } serde_bytes = { workspace = true } -base64 = { workspace = true } -num-traits = { workspace = true } -once_cell = { workspace = true } ic-cdk-timers = { workspace = true } ic-stable-structures = { workspace = true } -ic-http-certification = { workspace = true } -ed25519-dalek = { workspace = true } -x25519-dalek = { workspace = true } -lazy_static = "1.4" getrandom = { version = "0.2", features = ["custom"] } ic_cose_types = { path = "../ic_cose_types", version = "0.1" } ic-crypto-extended-bip32 = { git = "https://github.com/dfinity/ic/", rev = "d19fa446ab35780b2c6d8b82ea32d808cca558d5" } ic-crypto-ed25519 = { git = "https://github.com/dfinity/ic/", rev = "d19fa446ab35780b2c6d8b82ea32d808cca558d5" } -icrc-ledger-types = { git = "https://github.com/dfinity/ic/", rev = "d19fa446ab35780b2c6d8b82ea32d808cca558d5" } diff --git a/src/ic_cose_canister/src/api_cose.rs b/src/ic_cose_canister/src/api_cose.rs index 92ae47d..98b2ca3 100644 --- a/src/ic_cose_canister/src/api_cose.rs +++ b/src/ic_cose_canister/src/api_cose.rs @@ -7,9 +7,9 @@ use ic_cose_types::{ CosePath, ECDHInput, ECDHOutput, PublicKeyInput, PublicKeyOutput, SchnorrAlgorithm, SignIdentityInput, SignInput, }, - validate_key, ByteN, MILLISECONDS, + validate_key, MILLISECONDS, }; -use serde_bytes::ByteBuf; +use serde_bytes::{ByteArray, ByteBuf}; use crate::{is_authenticated, rand_bytes, store}; @@ -135,7 +135,7 @@ async fn vetkd_public_key(path: CosePath) -> Result { } #[ic_cdk::update(guard = "is_authenticated")] -async fn vetkd_encrypted_key(path: CosePath, public_key: ByteN<48>) -> Result { +async fn vetkd_encrypted_key(path: CosePath, public_key: ByteArray<48>) -> Result { path.validate()?; let caller = ic_cdk::caller(); @@ -148,7 +148,11 @@ async fn vetkd_encrypted_key(path: CosePath, public_key: ByteN<48>) -> Result is a wrapper around ByteArray to provide CandidType implementation -#[derive( - Clone, Copy, Default, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash, -)] -pub struct ByteN(pub ByteArray); - -impl ByteN { - pub fn from_hex(val: &str) -> Result { - let data = hex::decode(val).map_err(|_| format!("failed to decode hex: {}", val))?; - Self::try_from(data.as_slice()) - } -} - -impl CandidType for ByteN { - fn _ty() -> candid::types::internal::Type { - candid::types::internal::TypeInner::Vec(candid::types::internal::TypeInner::Nat8.into()) - .into() - } - fn idl_serialize(&self, serializer: S) -> Result<(), S::Error> - where - S: candid::types::Serializer, - { - serializer.serialize_blob(self.0.as_slice()) - } -} - -impl Deref for ByteN { - type Target = [u8; N]; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl AsRef<[u8; N]> for ByteN { - fn as_ref(&self) -> &[u8; N] { - &self.0 - } -} - -impl From<[u8; N]> for ByteN { - fn from(val: [u8; N]) -> Self { - Self(ByteArray::new(val)) - } -} - -impl TryFrom<&[u8]> for ByteN { - type Error = String; - - fn try_from(value: &[u8]) -> Result { - if value.len() != N { - return Err(format!("expected {} bytes, got {}", N, value.len())); - } - let mut bytes = [0u8; N]; - bytes.copy_from_slice(value); - Ok(Self(ByteArray::new(bytes))) - } -} - -impl From> for ByteN { - fn from(val: ByteArray) -> Self { - Self(val) - } -} - -impl From> for ByteArray { - fn from(val: ByteN) -> Self { - val.0 - } -} - -impl From> for Vec { - fn from(val: ByteN) -> Self { - Vec::from(val.0.into_array()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::to_cbor_bytes; - use ciborium::from_reader; - - #[test] - fn byte_n_works() { - let b4: ByteN<4> = [1, 2, 3, 4].into(); - let data = to_cbor_bytes(&b4); - assert_eq!(&data, &[68, 1, 2, 3, 4]); - let v: ByteN<4> = from_reader(&data[..]).unwrap(); - assert_eq!(v, b4); - let res: Result, _> = from_reader([69, 1, 2, 3, 4, 0].as_slice()); - // println!("{:?}", res.err()); - assert!( - res.is_err(), - "invalid length 5, expected a byte array of length 4" - ); - let res: ByteN<5> = from_reader([69, 1, 2, 3, 4, 0].as_slice()).unwrap(); - assert_eq!(*res, [1, 2, 3, 4, 0]); - } -} diff --git a/src/ic_cose_types/src/cose/mod.rs b/src/ic_cose_types/src/cose/mod.rs index fe1603a..67395c0 100644 --- a/src/ic_cose_types/src/cose/mod.rs +++ b/src/ic_cose_types/src/cose/mod.rs @@ -23,12 +23,6 @@ where format!("{:?}", err) } -pub fn crc32(data: &[u8]) -> u32 { - let mut h = crc32fast::Hasher::new(); - h.update(data); - h.finalize() -} - pub fn sha256(data: &[u8]) -> [u8; 32] { let mut hasher = sha2::Sha256::new(); hasher.update(data); diff --git a/src/ic_cose_types/src/lib.rs b/src/ic_cose_types/src/lib.rs index 9143b40..46127df 100644 --- a/src/ic_cose_types/src/lib.rs +++ b/src/ic_cose_types/src/lib.rs @@ -6,11 +6,9 @@ use ciborium::into_writer; use serde::Serialize; use std::{collections::BTreeSet, ops::Deref}; -pub mod bytes; pub mod cose; pub mod types; -pub use bytes::*; pub use cose::format_error; pub static ANONYMOUS: Principal = Principal::anonymous(); diff --git a/src/ic_cose_types/src/types/mod.rs b/src/ic_cose_types/src/types/mod.rs index 0f7f271..eb3d0b0 100644 --- a/src/ic_cose_types/src/types/mod.rs +++ b/src/ic_cose_types/src/types/mod.rs @@ -1,13 +1,13 @@ use candid::{CandidType, Principal}; use serde::{Deserialize, Serialize}; -use serde_bytes::ByteBuf; +use serde_bytes::{ByteArray, ByteBuf}; use std::collections::BTreeMap; pub mod namespace; pub mod setting; pub mod state; -use crate::{bytes::ByteN, validate_key}; +use crate::validate_key; // should update to ICRC3Map pub type MapValue = @@ -48,14 +48,14 @@ pub struct SignIdentityInput { #[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct ECDHInput { - pub nonce: ByteN<12>, // should be random for each request - pub public_key: ByteN<32>, // client side ECDH public key + pub nonce: ByteArray<12>, // should be random for each request + pub public_key: ByteArray<32>, // client side ECDH public key } #[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub struct ECDHOutput { - pub payload: T, // should be random for each request - pub public_key: ByteN<32>, // server side ECDH public key + pub payload: T, // should be random for each request + pub public_key: ByteArray<32>, // server side ECDH public key } #[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]