diff --git a/Cargo.lock b/Cargo.lock index d2af0fb..08ab917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "base64" @@ -40,13 +40,19 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bindgen" version = "0.60.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "clap", @@ -69,6 +75,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "block-buffer" version = "0.9.0" @@ -80,9 +92,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -107,7 +119,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.79", + "syn", "syn_derive", ] @@ -122,9 +134,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cexpr" @@ -155,9 +167,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "clang-sys" -version = "1.4.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", @@ -166,14 +178,14 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.23" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", - "indexmap 1.9.2", + "indexmap 1.9.3", "strsim", "termcolor", "textwrap", @@ -188,11 +200,17 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -209,17 +227,44 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rustc_version", "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "darling" version = "0.20.10" @@ -240,7 +285,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.79", + "syn", ] [[package]] @@ -251,7 +296,17 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.79", + "syn", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", ] [[package]] @@ -265,21 +320,31 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", "crypto-common", ] [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ - "signature", + "pkcs8", + "signature 2.2.0", ] [[package]] @@ -288,19 +353,33 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek", - "ed25519", + "curve25519-dalek 3.2.0", + "ed25519 1.5.3", "rand", "serde", "sha2 0.9.9", "zeroize", ] +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek 4.1.3", + "ed25519 2.2.3", + "serde", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "either" -version = "1.8.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "env_logger" @@ -321,6 +400,22 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "fnv" version = "1.0.7" @@ -329,9 +424,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -345,7 +440,18 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -387,6 +493,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "humantime" version = "2.1.0" @@ -401,9 +516,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -421,15 +536,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lazycell" @@ -439,34 +554,37 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if 1.0.0", - "winapi", + "windows-targets", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" -version = "0.4.17" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memory_units" @@ -543,7 +661,7 @@ dependencies = [ "serde_json", "strum", "strum_macros", - "syn 2.0.79", + "syn", ] [[package]] @@ -564,9 +682,9 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.2" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -580,15 +698,15 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "os_str_bytes" -version = "6.4.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "peeking_take_while" @@ -596,11 +714,24 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro-crate" @@ -636,9 +767,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -648,11 +779,11 @@ name = "quickjs-rust-near" version = "0.1.0" dependencies = [ "bindgen", - "ed25519-dalek", + "ed25519-dalek 2.1.1", "hex", "near-sdk", "quickjs-rust-near-testenv", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -660,7 +791,7 @@ name = "quickjs-rust-near-fungible-token" version = "0.1.0" dependencies = [ "bindgen", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "lazy_static", "near-contract-standards", "near-sdk", @@ -683,7 +814,7 @@ name = "quickjs-rust-near-nft" version = "0.1.0" dependencies = [ "bindgen", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "lazy_static", "near-contract-standards", "near-sdk", @@ -705,10 +836,10 @@ dependencies = [ name = "quickjs-rust-near-testenv" version = "0.1.0" dependencies = [ - "ed25519-dalek", + "ed25519-dalek 1.0.1", "lazy_static", "near-sdk", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -726,10 +857,10 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha", - "rand_core", + "rand_core 0.5.1", "rand_hc", ] @@ -740,7 +871,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", ] [[package]] @@ -749,7 +880,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.15", ] [[package]] @@ -758,14 +898,26 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", ] [[package]] name = "regex" -version = "1.7.1" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -774,9 +926,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "rustc-hash" @@ -784,45 +936,74 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustversion" -version = "1.0.11" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn", ] [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.131" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf3" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -842,20 +1023,20 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] name = "shlex" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signature" @@ -863,6 +1044,25 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "strsim" version = "0.10.0" @@ -885,25 +1085,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.79", + "syn", ] [[package]] name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - -[[package]] -name = "syn" -version = "1.0.107" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -925,35 +1114,23 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", -] - -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", - "unicode-xid", + "syn", ] [[package]] name = "termcolor" -version = "1.1.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "tinyvec" @@ -989,27 +1166,21 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "unicode-xid" -version = "0.2.4" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -1017,6 +1188,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wee_alloc" version = "0.4.5" @@ -1031,13 +1208,14 @@ dependencies = [ [[package]] name = "which" -version = "4.3.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] @@ -1058,11 +1236,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -1071,6 +1249,88 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "0.6.20" @@ -1080,23 +1340,43 @@ dependencies = [ "memchr", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" -version = "1.3.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", - "synstructure", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index 1331e3c..4f7d126 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ strip = false [dependencies] near-sdk = "5.5.0" -ed25519-dalek = "1.0.1" +ed25519-dalek = "2.1.1" sha2 = "0.10.6" hex = "0.4.3" quickjs-rust-near-testenv = { path = "testenv" } @@ -40,4 +40,4 @@ members = [ "examples/purejs", "testenv", "." -] \ No newline at end of file +] diff --git a/e2e/e2e.test.js b/e2e/e2e.test.js index e8b1bc1..ba08580 100644 --- a/e2e/e2e.test.js +++ b/e2e/e2e.test.js @@ -1,8 +1,8 @@ -import { Worker } from 'near-workspaces'; +import { KeyPair, Worker } from 'near-workspaces'; import { before, after, test, describe } from 'node:test'; import { expect } from 'chai'; -describe('run simple js', () => { +describe('run simple js', { only: true }, () => { /** * @type {Worker} */ @@ -94,4 +94,49 @@ env.value_return(JSON.stringify(result)); ` expect(result).to.equal('valid'); }, 40000); + test('should verify signed message using ed25519_verify', { only: true }, async () => { + /** + * @type {KeyPair} + */ + const keyPair = contractAccountKeyPair; + const messageToBeSigned = 'the expected message to be signed'; + + const messageBytes = new TextEncoder().encode(messageToBeSigned); + const signature = Array.from((await keyPair.sign(messageBytes)).signature); + const message = Array.from(messageBytes); + const public_key = Array.from(keyPair.getPublicKey().data); + + await contract.call( + contract.accountId, + 'submit_script', + { + script: ` +const args = JSON.parse(env.input()); +const result = env.ed25519_verify(new Uint8Array(args.signature), new Uint8Array(args.message), new Uint8Array(args.public_key)); +env.value_return(JSON.stringify(result ? 'valid' : 'invalid')); +` + } + ); + + let result = await contract.view( + 'run_script_for_account_no_return', + { + account_id: contract.accountId, + message, + signature, + public_key + } + ); + expect(result).to.equal('valid'); + result = await contract.view( + 'run_script_for_account_no_return', + { + account_id: contract.accountId, + message: [3, 2, 5, 1], + signature, + public_key + } + ); + expect(result).to.equal('invalid'); + }, 40000); }); \ No newline at end of file diff --git a/examples/fungibletoken/e2e/e2e.test.js b/examples/fungibletoken/e2e/e2e.test.js index 1c75cfa..48a740d 100644 --- a/examples/fungibletoken/e2e/e2e.test.js +++ b/examples/fungibletoken/e2e/e2e.test.js @@ -1,7 +1,8 @@ import { connect, keyStores } from 'near-api-js'; import { Worker } from 'near-workspaces'; -import { before, after, test, describe } from 'node:test'; +import { before, after, test, describe, afterEach } from 'node:test'; import { expect } from 'chai'; +import { createHash } from 'crypto'; const connectionConfig = { networkId: "sandbox", @@ -9,7 +10,7 @@ const connectionConfig = { nodeUrl: "https://rpc.testnet.near.org" }; -describe('Fungible token contract', () => { +describe('Fungible token contract', { only: true }, () => { /** * @type {Worker} */ @@ -24,7 +25,13 @@ describe('Fungible token contract', () => { * @type {import('near-workspaces').NearAccount} */ let contract; + /** + * @type {import('near-workspaces').NearAccount} + */ let bob; + /** + * @type {import('near-workspaces').NearAccount} + */ let alice; /** @@ -46,12 +53,28 @@ describe('Fungible token contract', () => { await contract.call(contract.accountId, 'new_default_meta', { owner_id: 'bob.test.near', total_supply: 1_000_000n.toString() }); contractAccountKeyPair = await contract.getKey(); connectionConfig.keyStore.setKey("sandbox", contract.accountId, contractAccountKeyPair); + await alice.call(contract.accountId, 'storage_deposit', { + account_id: 'alice.test.near', + registration_only: true, + }, { + attachedDeposit: 1_0000_0000000000_0000000000n.toString() + }); }); after(async () => { await worker.tearDown(); }); - test('should run custom javascript in contract', async () => { + afterEach(async () => { + const aliceBalance = await contract.view('ft_balance_of', { account_id: 'alice.test.near' }); + await alice.call(contract.accountId, 'ft_transfer', { + receiver_id: 'bob.test.near', + amount: aliceBalance.toString(), + }, { + attachedDeposit: 1n.toString() + }); + }); + + test('should run custom javascript transfer functions in contract', async () => { const nearConnection = await connect(connectionConfig); const accountId = contract.accountId; @@ -79,18 +102,6 @@ describe('Fungible token contract', () => { ` } }); - await bob.call(accountId, 'storage_deposit', { - account_id: 'bob.test.near', - registration_only: true, - }, { - attachedDeposit: 1_0000_0000000000_0000000000n.toString() - }); - await alice.call(accountId, 'storage_deposit', { - account_id: 'alice.test.near', - registration_only: true, - }, { - attachedDeposit: 1_0000_0000000000_0000000000n.toString() - }); expect(await contract.view('ft_balance_of', { account_id: 'bob.test.near' })).to.equal(1_000_000n.toString()); @@ -113,4 +124,112 @@ describe('Fungible token contract', () => { expect(await contract.view('ft_balance_of', { account_id: 'bob.test.near' })).to.equal(999_000n.toString()); expect(await contract.view('ft_balance_of', { account_id: 'alice.test.near' })).to.equal(1_000n.toString()); }); + + test('should not double gas usage when calling transfer via JS', { only: false }, async () => { + const nearConnection = await connect(connectionConfig); + const accountId = contract.accountId; + + const account = await nearConnection.account(accountId); + await account.functionCall({ + contractId: accountId, + methodName: 'post_javascript', + gas: '300000000000000', + args: { + javascript: ` + export function ft_transfer_js() { + const { amount, receiver_id } = JSON.parse(env.input()); + env.ft_transfer(receiver_id, amount); + } + ` + } + }); + + let result = await bob.callRaw(accountId, 'call_js_func', + { + function_name: "ft_transfer_js", + receiver_id: "alice.test.near", + amount: "2000" + }, { + attachedDeposit: '1' + }); + expect(await contract.view('ft_balance_of', { account_id: 'alice.test.near' })).to.equal(2_000n.toString()); + const totalGasBurntJS = result.result.receipts_outcome.reduce((prev, receipt_outcome) => prev + receipt_outcome.outcome.gas_burnt, 0); + result = await bob.callRaw(accountId, 'ft_transfer', + { + receiver_id: "alice.test.near", + amount: "2000" + }, { + attachedDeposit: '1' + }); + expect(await contract.view('ft_balance_of', { account_id: 'alice.test.near' })).to.equal(4_000n.toString()); + const totalGasBurnt = result.result.receipts_outcome.reduce((prev, receipt_outcome) => prev + receipt_outcome.outcome.gas_burnt, 0); + + expect(totalGasBurntJS / totalGasBurnt).to.be.lessThan(2.0); + }); + + test('should run custom javascript transfer functions in contract with function access keys, and without attaching deposits', { only: true }, async () => { + const nearConnection = await connect(connectionConfig); + const accountId = contract.accountId; + + const account = await nearConnection.account(accountId); + const javascript = ` + export function start_ai_conversation() { + const amount = 2_000n; + let conversation_id = env.signer_account_id()+"_"+(new Date().getTime()); + env.set_data(conversation_id, JSON.stringify({receiver_id: env.signer_account_id(), amount: amount.toString() })); + env.ft_transfer_internal(env.signer_account_id(), 'bob.test.near', amount.toString()); + env.value_return(conversation_id); + } + + export function refund_unspent() { + const { refund_message, signature } = JSON.parse(env.input()); + const public_key = new Uint8Array([${Array.from((await bob.getKey()).getPublicKey().data).toString()}]); + + const signature_is_valid = env.ed25519_verify(new Uint8Array(signature), new Uint8Array(env.sha256_utf8(refund_message)) , public_key); + if (signature_is_valid) { + print("REFUNDING"); + const { receiver_id, refund_amount } = JSON.parse(refund_message); + env.ft_transfer_internal('bob.test.near', receiver_id, refund_amount); + } else { + print("INVALID SIGNATURE"); + } + } +`; + + await account.functionCall({ + contractId: accountId, + methodName: 'post_javascript', + gas: '300000000000000', + args: { + javascript + } + }); + + await bob.call(accountId, 'ft_transfer', { + receiver_id: 'alice.test.near', + amount: 2000n.toString(), + }, { + attachedDeposit: 1n.toString() + }); + + const conversation_id = await alice.call(accountId, 'call_js_func', { + function_name: "start_ai_conversation" + }); + + expect(conversation_id.split("_")[0]).to.equal("alice.test.near"); + expect(await contract.view('ft_balance_of', { account_id: 'alice.test.near' })).to.equal(0n.toString()); + + const refund_message = JSON.stringify({ receiver_id: 'alice.test.near', refund_amount: 1000n.toString() }); + const refund_message_hashed = createHash('sha256').update(Buffer.from(refund_message, 'utf8')).digest(); + const signature = (await bob.getKey()).sign(Uint8Array.from(refund_message_hashed)); + + await bob.call(accountId, 'call_js_func', + { + function_name: "refund_unspent", + signature: Array.from(signature.signature), + refund_message + }); + + expect(await contract.view('ft_balance_of', { account_id: 'alice.test.near' })).to.equal(1_000n.toString()); + }); }); diff --git a/localjstestenv/wasm-near-environment.js b/localjstestenv/wasm-near-environment.js index dd41375..fbbd012 100644 --- a/localjstestenv/wasm-near-environment.js +++ b/localjstestenv/wasm-near-environment.js @@ -195,3 +195,4 @@ export function storage_has_key(key_len, key_ptr) { } export function validator_stake() { } export function validator_total_stake() { } +export function ed25519_verify() { } diff --git a/quickjslib/.gitignore b/quickjslib/.gitignore index 392acc9..28d3c1f 100644 --- a/quickjslib/.gitignore +++ b/quickjslib/.gitignore @@ -1,3 +1,4 @@ *.wasm *.a *.o +*.o* \ No newline at end of file diff --git a/src/jslib.rs b/src/jslib.rs index e060607..9f1c11b 100644 --- a/src/jslib.rs +++ b/src/jslib.rs @@ -16,6 +16,23 @@ extern "C" { fn js_add_near_host_function(name: i32, func: i32, length: i32); fn JS_ToCStringLen2(ctx: i32, value_len_ptr: i32, val: i64, b: i32) -> i32; fn JS_NewStringLen(ctx: i32, buf: i32, buf_len: usize) -> i64; + fn JS_GetTypedArrayBuffer( + ctx: i32, // QuickJS context (JSContext*) + obj: i64, // The JSValueConst representing the typed array (JSValueConst as i64) + pbyte_offset: *mut usize, // Pointer to store the byte offset (size_t*) + pbyte_length: *mut usize, // Pointer to store the byte length (size_t*) + pbytes_per_element: *mut usize, // Pointer to store bytes per element (size_t*) + ) -> i64; + fn JS_GetArrayBuffer( + ctx: i32, // QuickJS context + psize: *mut usize, // Pointer to store the buffer size + obj: i64, // The JSValue representing the ArrayBuffer + ) -> *mut u8; // + fn JS_NewArrayBufferCopy( + ctx: i32, + data: *const u8, + size: usize + ) -> i64; } pub const JS_UNDEFINED: i64 = 0x0000000300000000; @@ -44,6 +61,51 @@ pub fn arg_to_number(_ctx: i32, arg_no: i32, argv: i32) -> i64 { } } +unsafe fn JS_GetArrayBufferRawData(ctx: i32, jsvalue: i64) -> *mut u8 { + let mut size: usize = 0; + let data_ptr = JS_GetArrayBuffer(ctx, &mut size as *mut usize, jsvalue); + return data_ptr; +} + +pub fn arg_to_u8_array(ctx: i32, arg_no: i32, argv: i32) -> Vec { + let mut byte_offset: usize = 0; + let mut byte_length: usize = 0; + let mut bytes_per_element: usize = 0; + let argv_ptr = (argv + (arg_no * 8)) as *const i64; // Access the argument as JSValue (i64) + + let array_data: Vec; + unsafe { + // Retrieve the typed array object (Uint8Array) + let typed_array: i64 = *argv_ptr; // JSValue as a 64-bit integer + + // Call JS_GetTypedArrayBuffer, which returns another JSValue representing the buffer + let buffer_jsvalue = JS_GetTypedArrayBuffer( + ctx, + typed_array, // Pass the JSValue (i64) + &mut byte_offset as *mut usize, // Offset pointer + &mut byte_length as *mut usize, // Length pointer + &mut bytes_per_element as *mut usize, // Bytes per element pointer + ); + + // Now we need to extract the raw buffer from this new JSValue (buffer_jsvalue) + if buffer_jsvalue != 0 && byte_length > 0 { + // Assume we have a function to get the raw buffer from JSValue (this needs to be implemented) + let data_ptr = JS_GetArrayBufferRawData(ctx, buffer_jsvalue); + + // Convert the raw pointer into a Vec + if !data_ptr.is_null() { + array_data = std::slice::from_raw_parts(data_ptr, byte_length).to_vec(); + } else { + array_data = Vec::new(); // Handle null case gracefully + } + } else { + array_data = Vec::new(); // If the returned value is invalid or length is zero + } + } + + return array_data; +} + /** * From near_sdk_js @@ -196,6 +258,38 @@ unsafe fn setup_quickjs() { }, 1, ); + add_function_to_js( + "sha256_utf8", + |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { + let message_sha256 = near_sdk::env::sha256(arg_to_str(ctx, 0, argv).as_bytes()); + JS_NewArrayBufferCopy( + ctx, + message_sha256.as_ptr(), // Pass the pointer to the data (const u8) + message_sha256.len() // Length of the data + ) + }, + 1, + ); + add_function_to_js( + "ed25519_verify", + |ctx: i32, _this_val: i64, _argc: i32, argv: i32| -> i64 { + let signature_vec = arg_to_u8_array(ctx, 0, argv); + let signature: &[u8; 64] = signature_vec[..].try_into().unwrap(); + let message_vec = arg_to_u8_array(ctx, 1, argv); + let message: &[u8] = message_vec.as_slice(); + + let public_key_vec = arg_to_u8_array(ctx, 2, argv); + let public_key: &[u8; 32] = public_key_vec[..].try_into().unwrap(); + + let result = near_sdk::env::ed25519_verify(signature, message, public_key); + if result { + JS_TRUE + } else { + JS_FALSE + } + }, + 1, + ); } pub fn run_js(script: String) -> i32 { @@ -258,7 +352,9 @@ pub fn compile_js(script: String, modulename: Option) -> Vec { mod tests { use super::{compile_js, js_get_property, js_get_string, run_js, run_js_bytecode}; use crate::viewaccesscontrol::store_signing_key_for_account; - use near_sdk::base64; + use near_sdk::{base64, env::sha256}; + use ed25519_dalek::{ed25519::signature::SignerMut, SigningKey}; + use quickjs_rust_near_testenv::testenv::{ alice, assert_latest_return_value_string_eq, set_input, set_signer_account_id, setup_test_env, @@ -356,4 +452,58 @@ mod tests { ); } } + + #[test] + fn test_ed25519_verify_message() { + let mut signing_key = SigningKey::from_bytes(&near_sdk::env::random_seed_array()); + let message_hashed = sha256(b"Hello"); + let signature = signing_key.sign(message_hashed[..].try_into().unwrap()); + let script = format!(" + (function () {{ + let signature = new Uint8Array({:?}); + let message = new Uint8Array(env.sha256_utf8(\"Hello\")); + let publicKey = new Uint8Array({:?}); + return env.ed25519_verify(signature, message, publicKey) ? 1 : 0; + }})(); + ", signature.to_bytes(), signing_key.verifying_key().as_bytes()); + + let bytecode = compile_js(script, None); + let result = run_js_bytecode(bytecode); + + assert_eq!(1, result); + } + + #[test] + fn test_ed25519_verify() { + setup_test_env(); + let bytecode = compile_js( + "(function () { + let signature = new Uint8Array([ + 202, 190, 247, 74, 243, 111, 52, 105, 50, 114, 227, + 162, 48, 43, 196, 41, 250, 186, 200, 69, 193, 79, + 125, 103, 18, 55, 153, 32, 27, 210, 186, 142, 160, + 121, 163, 87, 169, 246, 125, 204, 148, 183, 143, 86, + 59, 181, 174, 224, 113, 26, 160, 25, 137, 186, 65, + 196, 1, 137, 143, 184, 179, 90, 83, 0 + ]); + let message = new Uint8Array([ + 116, 104, 101, 32, 101, 120, 112, + 101, 99, 116, 101, 100, 32, 109, + 101, 115, 115, 97, 103, 101, 32, + 116, 111, 32, 98, 101, 32, 115, + 105, 103, 110, 101, 100 + ]); + let publicKey = new Uint8Array([ + 85, 107, 80, 196, 145, 120, 98, 16, 245, 69, 9, 42, 212, 6, 131, 229, 36, 235, + 122, 199, 84, 4, 164, 55, 218, 190, 147, 17, 144, 195, 95, 176, + ]); + return env.ed25519_verify(signature, message, publicKey) ? 1 : 0; + })()" + .to_string(), + None, + ); + let result = run_js_bytecode(bytecode); + + assert_eq!(1, result); + } } diff --git a/src/viewaccesscontrol.rs b/src/viewaccesscontrol.rs index 8ae2ba9..58b958a 100644 --- a/src/viewaccesscontrol.rs +++ b/src/viewaccesscontrol.rs @@ -1,7 +1,6 @@ -use ed25519_dalek::ed25519::signature::Signature as DalekSig; -use ed25519_dalek::PublicKey as DalekPK; use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use near_sdk::{base64, env}; +use near_sdk::env; +use near_sdk::base64::{engine::general_purpose, Engine as _}; use std::collections::HashMap; const ACCOUNT_SIGNING_KEYS_KEY: &[u8] = b"ACCSIGNKEYS"; @@ -59,7 +58,7 @@ pub fn store_signing_key_for_account(expires_timestamp_ms: u64) { pub fn verify_message_signed_by_account( signed_message: String, - signature: String, + signature_base64: String, account_id: String, ) -> bool { let account_signing_keys = load_account_signing_keys(); @@ -70,12 +69,10 @@ pub fn verify_message_signed_by_account( if account_signing_key_option.is_some() { let account_signing_key = account_signing_key_option.unwrap(); if account_signing_key.expires_timestamp_ms > env::block_timestamp_ms() { - let pk = - DalekPK::from_bytes(&account_signing_key_option.unwrap().public_key[1..].to_vec()) - .unwrap(); - let sig = DalekSig::from_bytes(base64::decode(&signature).unwrap().as_slice()).unwrap(); - - return pk.verify_strict(signed_message.as_bytes(), &sig).is_ok(); + let signature_vec = general_purpose::STANDARD.decode(signature_base64).unwrap(); + let signature = signature_vec.as_slice().try_into().unwrap(); + let public_key = account_signing_key_option.unwrap().public_key[1..].try_into().unwrap(); + return env::ed25519_verify(signature, signed_message.as_bytes(), public_key); } } return false; diff --git a/testenv/src/testenv.rs b/testenv/src/testenv.rs index 31f936b..413559d 100644 --- a/testenv/src/testenv.rs +++ b/testenv/src/testenv.rs @@ -1,3 +1,4 @@ +use ed25519_dalek::Signature; use near_sdk::{AccountId, NearToken, PublicKey}; use sha2::Digest; use std::collections::HashMap; @@ -491,6 +492,40 @@ pub extern "C" fn block_timestamp() -> i64 { } } +#[no_mangle] +pub extern "C" fn random_seed(_register: i64) { + +} + +#[no_mangle] +pub extern "C" fn ed25519_verify( + signature_len: i64, + signature_ptr: i64, + message_len: i64, + message_ptr: i64, + public_key_len: i64, + public_key_ptr: i64, +) -> i64 { + unsafe { + let signature = Signature::from_bytes(std::slice::from_raw_parts( + signature_ptr as *const u8, + signature_len as usize, + )) + .unwrap(); + let message = std::slice::from_raw_parts(message_ptr as *const u8, message_len as usize); + let public_key = ed25519_dalek::PublicKey::from_bytes(std::slice::from_raw_parts( + public_key_ptr as *const u8, + public_key_len as usize, + )) + .unwrap(); + if public_key.verify_strict(message, &signature).is_ok() { + 1 + } else { + 0 + } + } +} + #[cfg(test)] mod tests { use super::*;