diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4bd31d6..71b2cf1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,21 +6,12 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: "install wasmtime" - run: | - mkdir /home/runner/bin - echo "/home/runner/bin" >> $GITHUB_PATH - wget https://github.com/bytecodealliance/wasmtime/releases/download/v0.18.0/wasmtime-v0.18.0-x86_64-linux.tar.xz - tar xf wasmtime-v0.18.0-x86_64-linux.tar.xz - cp wasmtime-v0.18.0-x86_64-linux/wasmtime /home/runner/bin/wasmtime - - name: "install vessel" - run: | - wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/v0.6.0/vessel-linux64 - chmod +x /home/runner/bin/vessel - - name: "check" + - uses: actions/checkout@v4 + - name: Install Mops toolchain + uses: dfinity/setup-mops@v1 + - name: Verify locked dependencies + run: mops install --locked + - name: Test run: make check-strict - - name: "test" - run: make test - - name: "docs" + - name: Generate docs run: make docs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f011a09..bd4c43e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,13 +9,11 @@ jobs: generate-docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - name: "install vessel" - run: | - mkdir /home/runner/bin - echo "/home/runner/bin" >> $GITHUB_PATH - wget --output-document /home/runner/bin/vessel https://github.com/dfinity/vessel/releases/download/v0.6.0/vessel-linux64 - chmod +x /home/runner/bin/vessel + - uses: actions/checkout@v4 + - name: Install Mops toolchain + uses: dfinity/setup-mops@v1 + - name: Verify locked dependencies + run: mops install --locked - name: "docs" run: make docs - name: Upload docs diff --git a/.gitignore b/.gitignore index 73e22dd..e918e26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .mops -mops.lock *.wasm docs/ obj/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2ce6876 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## 0.1.0 + +- Establish the ICDevs-maintained `evm-txs-core` successor while preserving + the complete `evm-txs.mo` history and attribution. +- Require Motoko 1.8.2 and migrate the library from `mo:base` to `mo:core`. +- Pin cryptographic and encoding dependencies to immutable Git commits. +- Add reproducible transaction benchmarks covering all supported envelopes. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..0baf070 --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +evm-txs-core + +Based on evm-txs.mo by av1ctor and contributors, developed through +ICDevs bounty #32. Portions were ported from nikolas-con/ic-evm-sign. +This successor is modified and maintained by ICDevs.org. diff --git a/README.md b/README.md index 007c5d3..824df11 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,32 @@ -# evm-txs.mo -EVM transactions creation, encoding, and decoding library in pure Motoko. +# evm-txs-core + +EVM transaction creation, encoding, and decoding in Motoko, maintained for +the modern `mo:core` ecosystem by ICDevs.org. + +This is the history-preserving successor to +[`av1ctor/evm-txs.mo`](https://github.com/av1ctor/evm-txs.mo). It retains the +original authorship and attribution while moving maintenance to ICDevs. + ICDevs.org bounty #32, see: https://forum.dfinity.org/t/open-icdevs-org-bounty-32-evm-transactions-motoko-8-000/17884 +## Installation + +After the package is published to Mops: + +```sh +mops add evm-txs-core +``` + +Until then, consumers can pin an immutable commit from this repository. + ## References - Ported from https://github.com/nikolas-con/ic-evm-sign ## Dependencies -- libsecp256k1.mo: https://github.com/av1ctor/libsecp256k1.mo -- rlp-motoko: https://github.com/relaxed04/rlp-motoko -- motoko-sha3: https://github.com/hanbu97/motoko-sha3 +- [`libsecp256k1.mo`](https://github.com/skilesare/libsecp256k1.mo) +- [`rlp-motoko`](https://github.com/skilesare/rlp-motoko) +- [`motoko-sha3`](https://github.com/skilesare/motoko-sha3) +- [`core`](https://mops.one/core) ## Features - Supports legacy, EIP2930, EIP1559, EIP4844, and EIP7702 transactions @@ -21,6 +39,8 @@ See e2e/tx_tools for a complete example ## Testing - Run the library test suite with `mops test --reporter files` - Or use the repo wrapper: `make -C test test` +- Compare performance with the checked-in baseline using + `mops bench --compare --replica pocket-ic` ## Notes - `Address`, `Transaction`, `Contract`, and `Transfer` are the intended high-level entry points for normal library use. diff --git a/mops.lock b/mops.lock new file mode 100644 index 0000000..41e0375 --- /dev/null +++ b/mops.lock @@ -0,0 +1,131 @@ +{ + "version": 3, + "mopsTomlDepsHash": "d08270cb4571ffdbd86d9dca8ef3fb8b631d4ea8a9a09af28791eda01caceaf3", + "deps": { + "bench": "2.0.1", + "core": "2.3.1", + "libsecp256k1": "https://github.com/skilesare/libsecp256k1.mo#2934ff0df01a0e450364c748acba8aa0bba30a47", + "rlp-motoko": "https://github.com/skilesare/rlp-motoko#46327f3ebf5c0e2961b1e8e6f8dbcce1edcc447c", + "sha3": "https://github.com/skilesare/motoko-sha3#70dd02960bc3985d146cc1e6443a9fea2c53314f", + "test": "2.1.2" + }, + "graph": { + "bench@2.0.1": { + "core": "2.0.0" + }, + "core@2.0.0": {}, + "core@2.3.1": {}, + "test@2.1.2": { + "core": "2.0.0" + } + }, + "github": { + "libsecp256k1": { + "resolved": "2934ff0df01a0e450364c748acba8aa0bba30a47", + "hash": "4c932a68f23d5b84b122639a13ff983199c51bb65d39dfbf09d570e9f7755ff1" + }, + "rlp-motoko": { + "resolved": "46327f3ebf5c0e2961b1e8e6f8dbcce1edcc447c", + "hash": "a3e0079bd015a857505448a9e3fc345a81bfbee6acff115eb0e0873c4d05ba6d" + }, + "sha3": { + "resolved": "70dd02960bc3985d146cc1e6443a9fea2c53314f", + "hash": "0a889e3243f44eddda4c641ab9eca7441137fce662337bef77e76aec00bf8b4f" + } + }, + "hashes": { + "bench@2.0.1": { + "bench@2.0.1/LICENSE": "2ad35734674f9151a4e12bc75435daf19031ab8c3880ced03f23243bc47a2204", + "bench@2.0.1/README.md": "f988592ee6b8b4f55bb6a4ff358153c9036fbdd910ffe764b40a9b3dd29db807", + "bench@2.0.1/mops.toml": "d15a6e1e7a65c8e857c2026f1d08871cae837ae32d19ebd1575678c91cf7b32f", + "bench@2.0.1/src/lib.mo": "48d9982ab86a7d8382ea4b093e67c061783fdc044903a65a685380e5a18ad967" + }, + "core@2.3.1": { + "core@2.3.1/LICENSE": "840e3d57a38a8061f55d04470fbd58b9345326fa04ea10ee42add5c6e3b2aa08", + "core@2.3.1/NOTICE": "d62ca4ef9e2c9df064115c339013593cf0769e2b9dc78fa4b3211222541c7f83", + "core@2.3.1/README.md": "8b7ad09b20a1b7809b3fb7e523898d7d17e057db6a90faf21ee9c1e33a249fd8", + "core@2.3.1/mops.toml": "db62bd2f5e4ad533a9ae3c7b272761feeaa96f360f2f6233883b51f03d5d49af", + "core@2.3.1/src/Array.mo": "7400fd0e6d2550ddb6d01833f67a69109c617032ac445275aabc7c7d188caf8d", + "core@2.3.1/src/Base64.mo": "91cafbfe48d6850e11ee4ae7c9a754821047ac65e6b5dfc84e51e8bead0b58b1", + "core@2.3.1/src/Blob.mo": "25d7c07e9786f11ceb8611a32a83b8491769580024054086e4548607a67afbe4", + "core@2.3.1/src/Bool.mo": "3b606a6631f28c774e3055bc860201e56260fd32fdc5e8dc00d901506be95db5", + "core@2.3.1/src/CertifiedData.mo": "5af3182d77ab7aab2384d1f663a8cd992bbd6652aacff29c443314cf2186328f", + "core@2.3.1/src/Char.mo": "ecc2550a6c70ccbb204d216bd18a422d2fcfbb4668a89ac49aab059972902041", + "core@2.3.1/src/Cycles.mo": "9f5c1fceea47f05c43f22a1c25e8753fb7e552e36106d27bceef24b1310f4cbc", + "core@2.3.1/src/Debug.mo": "526c3f9d94e4a682917febb7b0021831a7cc345a2aa63e2499ddeda33cf63b3e", + "core@2.3.1/src/Error.mo": "2112280ea5300ae94ff9188c3bbd75a7db87f0c6eb65c2ac5bf04bc27c851d98", + "core@2.3.1/src/Float.mo": "0ca58a2c2e1cbce2a4a963160f5075831fc40f4a7e43cac775e90277ba100b4d", + "core@2.3.1/src/Func.mo": "535991ccca8d551d48129a0b7df03ea7bd6ebf3d74b1b572259d10ce709d7d46", + "core@2.3.1/src/Int.mo": "03886964690ff75ecd4170decd67653c517dadc65d9957fc644d03e9c1cf9abb", + "core@2.3.1/src/Int16.mo": "78c72aafbc039e2c0becc824caa4181158206759d6859e83077db360bc8568c3", + "core@2.3.1/src/Int32.mo": "41d42155e753ef9fc1301c8823f255134bf2202d4a74ef33e7b7b54a8fc53af4", + "core@2.3.1/src/Int64.mo": "f1fda85af9f20b47bcbfda6eaef08c6eee11cab6e5fe3eadb2d9b1c2bcef2e65", + "core@2.3.1/src/Int8.mo": "361af007cfc333937c6bb8e238304db1a7f07a310ec3321a85b89d627f16990f", + "core@2.3.1/src/InternetComputer.mo": "969951411beb5caf7d60ba6d5e906a5c70a3b466cee42e1135d1cd3d791cb3a1", + "core@2.3.1/src/Iter.mo": "3627fbf52a392bfa76c6d6803c584b1556add077d0ad214d55802e17acf4d773", + "core@2.3.1/src/List.mo": "263c61ad591bc94f5adfc27517122ce060b9f50425b52e4e01c2d0ed1ced029d", + "core@2.3.1/src/Map.mo": "71c1dd738868479cc9770470706f6f222ac9d7b4a2743f59b33b16b31fd98ac7", + "core@2.3.1/src/Nat.mo": "78dab3e33310b766ee9066095a3e6acb1884a8dac32ae9a7cd560637d1e4ea4a", + "core@2.3.1/src/Nat16.mo": "2b04622ab82be11147130dce8968195c0d4a09b37de8f57d16580673ca780f78", + "core@2.3.1/src/Nat32.mo": "e3630af6551ae2a80f3809870f55d137c07f68092940c8d9255395504e4e81c8", + "core@2.3.1/src/Nat64.mo": "b7ea9f45a35f82c81771c1c36d99d73fdbd9e21f5b0c10e832685f7327246c5e", + "core@2.3.1/src/Nat8.mo": "e45a6ae2a55ee6ff890d556dc289816b1bdf352d52d4b3ce54e57ae795deffc2", + "core@2.3.1/src/Option.mo": "aeec94cd6954e7b8b5463a5b15abddfb56c5322cb9b9e7ac782092d5c33a8b38", + "core@2.3.1/src/Order.mo": "6c21e905e1e8c2b40cd50438218230c207d0bbec0d2514779edd76f9f84a812c", + "core@2.3.1/src/Principal.mo": "bf4fb0c50fc749ba9d4f4b55d4a11147208b3039a272ce85a8922726ddafe052", + "core@2.3.1/src/PriorityQueue.mo": "37b9906d1d5a61e520027fd2e48a77facb28ddc760d8129447d6902e037ef7ce", + "core@2.3.1/src/Queue.mo": "807ae8b4bdcaef6e37c57b65a93a04c0c5ed72f77e315e9916f5a25f62ce424f", + "core@2.3.1/src/Random.mo": "f5d48c30297b579a068af8cd8c6f4f986605e492b1b65424329a5171d1480e97", + "core@2.3.1/src/Region.mo": "741a6fae4f61e42fa0a938b00646515edfc96527341a3a2c3936d436c973798b", + "core@2.3.1/src/Result.mo": "0932722ab0187524c3c11539ccf2a1b9453438a9f3a042dde94e45d9c56a32c5", + "core@2.3.1/src/Runtime.mo": "d221bd16b45cb717cb4ef4fd698fa8632a415aecbbb5a6fdc8b5cd4bc50a9e56", + "core@2.3.1/src/Set.mo": "d64fed0989da152d0a4baa81719bef548ad3f461367d5d434d14e98cb18281f0", + "core@2.3.1/src/Stack.mo": "ed3c98fae4164ab4f934752f9adc2a92098af8f6d9fc71b16a54867cdb8787f8", + "core@2.3.1/src/Text.mo": "c23d3f2970234a9553d33aaed7907684d16b220e2cea95ebce02b25c3215e787", + "core@2.3.1/src/Time.mo": "fcffd56cbeb21c3d8613973f3f1ea382babcf122ea93c9689149f0101c5f3e96", + "core@2.3.1/src/Timer.mo": "389c247eed600fc8195ad1d9872f98fcc92faad96335c9734cf5265d573612e2", + "core@2.3.1/src/Tuples.mo": "0156c1fc21fffedd71d173e0d1b1e7a9a19726cbc49ec1cf49029d6d93bc7955", + "core@2.3.1/src/Types.mo": "00dc0132996b3bb3eaf5cc4413be78ca860137ef26f5b472b0e7b3ef68f6652f", + "core@2.3.1/src/VarArray.mo": "289e68fe216caa39d7d4829b73ccc03ed6e5e2e1d07079e3baa83b55651d1dd8", + "core@2.3.1/src/WeakReference.mo": "06e58a6d67bf67c4b31ff871416d0cf6d6e34bfb409ce73d83372ef6b74de3cf", + "core@2.3.1/src/internal/BTreeHelper.mo": "20a475baf18f924ee0297fc234469fa0985cdaa31c85ce002b5a921383b0534d", + "core@2.3.1/src/internal/PRNG.mo": "8a93e87baa2b12f613c82394a4a05b425e44a695bbace4ca36f9a1f78be26442", + "core@2.3.1/src/internal/SortHelper.mo": "fff4f2eec5c59a3db13e46eeb69152bb1b98931f45cb58ac481439a0cd0d10bb", + "core@2.3.1/src/pure/List.mo": "b4fb45cf75410461fb1501a316d2384d1be63fee1fccf11ed1d29677e5e2393c", + "core@2.3.1/src/pure/Map.mo": "e9868fc4dd5e8e6272382e33241c59f8664e3de2e618cbf62fa8b20beabecfab", + "core@2.3.1/src/pure/Queue.mo": "ed0bd0968457ea3bb24c5367f0dbdb159cfe950d0e2666224985e57a784fae3b", + "core@2.3.1/src/pure/RealTimeQueue.mo": "af133ae61c69ce4e00db5e9db53ddeccad84373fef82a156c85360c2426349dd", + "core@2.3.1/src/pure/Set.mo": "f0155b1d548cbc8889fcff75ef52f0cab7998b034621e4faac8d3b79d7bbac07" + }, + "test@2.1.2": { + "test@2.1.2/LICENSE": "ec415b57f8143746b567c94bfad243f5342f3edf110c94641a1a60e02722db55", + "test@2.1.2/README.md": "991a9ea896698d7ef1e7e55d038c7580d68182b3d30f78886304e374c64fbc01", + "test@2.1.2/mops.toml": "83e5024af6a5558f18a41b3ab8b60291f65e8470c0375c7e880896ccb02edf14", + "test@2.1.2/src/async.mo": "79b433a5d32184d0cad289f0b7ee6cd2256534689a015430efc43e3510c2217a", + "test@2.1.2/src/expect/async.mo": "c1518bd82ef8c2def86bc6b5fc1df1691eab9935adacc413cab4fe9f1eda6f4a", + "test@2.1.2/src/expect/expect-array.mo": "f5e6808b28c5948a40e11def8f5534bcacef1211a0b6f02e63e8653e5ee5e6aa", + "test@2.1.2/src/expect/expect-blob.mo": "944d92855573f5056d10cab2ee67f5ca153a792de9aa5074ccb0da7417a77ceb", + "test@2.1.2/src/expect/expect-bool.mo": "dd663249dd67d5ff5241a8ecb9b16e016abe24f0570e5aac8b912fc312e4a5d4", + "test@2.1.2/src/expect/expect-call.mo": "9aeeb5d56f753586e685fd3a7544b4a895e9e2a1f01f2c3423c66f87059512eb", + "test@2.1.2/src/expect/expect-char.mo": "7464e454a815e76e9d56989d59b8eda8781dd7dd28019ada3c513b764a5ff863", + "test@2.1.2/src/expect/expect-int.mo": "67837bcbd681bc180a8c528defab5153d9f8aaf4998b91ca3f787e714011cdf6", + "test@2.1.2/src/expect/expect-int16.mo": "15dfb2b13e74819d9f02927708c8f7cbbb8e0b13c0a9b249d843b16c3bcf4659", + "test@2.1.2/src/expect/expect-int32.mo": "577cc992737c99f07df7eb71462bb99f0b9b34727a4edf31dea88a7aff2bd48a", + "test@2.1.2/src/expect/expect-int64.mo": "c3d0025bca7dcda18872b5ea59baad9f485b33647a7118af45a12700793f3c19", + "test@2.1.2/src/expect/expect-int8.mo": "a88f864f471413fd4fe8300b828805a9e95c42278d55aa4351526d3c4f3c1e2c", + "test@2.1.2/src/expect/expect-nat.mo": "0f9cefc54f429a48a5ec1eb2f26bb73f771b6ca165fac300bf7228633429b049", + "test@2.1.2/src/expect/expect-nat16.mo": "eff67a91dc8eed0478d3558c1900257802c5c6c527d13f4ef6726ebd53492d6a", + "test@2.1.2/src/expect/expect-nat32.mo": "3ea76a0c53c806fad57d768ca79702c65faaf85b69ad61e49688b90d9a32094b", + "test@2.1.2/src/expect/expect-nat64.mo": "13536637dbb595bceec51db56c7cfc39221a9d5b5ea23baee66d19d6103f600f", + "test@2.1.2/src/expect/expect-nat8.mo": "2b5145da40599eb01ef5fe6807162cc9b2a5fbe5044fd4003ebdf6bf26cbf4b6", + "test@2.1.2/src/expect/expect-option.mo": "d5f2bce86a6f5c8e0bdbe1a72f1cbb80b01d3822b73da90239b84d91cb0af5d6", + "test@2.1.2/src/expect/expect-principal.mo": "93842843aa02bde6cdb94ee4daa35ed95d4b2da87bc228689b9cc8c5d9bdc178", + "test@2.1.2/src/expect/expect-result.mo": "3c03969dc0f08c80fa003ab23760a933f47ac928834734faca0f62fe940d3ab9", + "test@2.1.2/src/expect/expect-text.mo": "ffb21d802a48411ed45555e82edd5b5a82c91eb37b88c5d8d061880bab897735", + "test@2.1.2/src/expect/lib.mo": "b74da3928ed8c23c31b5979059f0ac549cd7f09e7a29af9b105d8f9e32e192ed", + "test@2.1.2/src/expect/utils.mo": "22e364d2ec8285c09ace83cb99b3257ba66a87cfe0312f6623ab0ab35ce47009", + "test@2.1.2/src/lib.mo": "e4559fbc3bcd229fb99de7dcdd68d56319ae8bc27509d6f3ad6d13c514915a39", + "test@2.1.2/src/utils.mo": "6b81172d908c2fb759597373b811e22a987d4cd69f1aa69615da252bed6e7466" + } + } +} \ No newline at end of file diff --git a/mops.toml b/mops.toml index e35ad8c..a38ca6f 100644 --- a/mops.toml +++ b/mops.toml @@ -1,18 +1,18 @@ [package] -name = "evm-txs" -version = "0.1.3" -description = "Motoko EVM transaction creation, encoding, and decoding" -repository = "https://github.com/av1ctor/evm-txs.mo" +name = "evm-txs-core" +version = "0.1.0" +description = "Motoko Core EVM transaction creation, encoding, and decoding" +repository = "https://github.com/icdevsorg/evm-txs-core" [dependencies] -base = "0.7.6" -rlp-motoko = "https://github.com/skilesare/rlp-motoko#46327f3" -libsecp256k1 = "https://github.com/skilesare/libsecp256k1.mo#2934ff0" -sha3 = "https://github.com/skilesare/motoko-sha3#70dd029" +core = "2.3.1" +rlp-motoko = "https://github.com/skilesare/rlp-motoko#46327f3ebf5c0e2961b1e8e6f8dbcce1edcc447c" +libsecp256k1 = "https://github.com/skilesare/libsecp256k1.mo#2934ff0df01a0e450364c748acba8aa0bba30a47" +sha3 = "https://github.com/skilesare/motoko-sha3#70dd02960bc3985d146cc1e6443a9fea2c53314f" [dev-dependencies] test = "2.1.2" bench = "2.0.1" [toolchain] -moc = "1.3.0" +moc = "1.8.2" diff --git a/src/Address.mo b/src/Address.mo index 8d47dfc..54359f5 100644 --- a/src/Address.mo +++ b/src/Address.mo @@ -1,7 +1,7 @@ -import Array "mo:base/Array"; -import Blob "mo:base/Blob"; -import Result "mo:base/Result"; -import Error "mo:base/Error"; +import Array "mo:core/Array"; +import Blob "mo:core/Blob"; +import Result "mo:core/Result"; +import Error "mo:core/Error"; import SHA3 "mo:sha3/"; import PublicKey "mo:libsecp256k1/PublicKey"; import Signature "mo:libsecp256k1/Signature"; @@ -14,9 +14,9 @@ import Scalar "mo:libsecp256k1/core/scalar"; import Helper "transactions/Helper"; import TU "utils/TextUtils"; import Prim "mo:⛔"; -import Nat "mo:base/Nat"; -import Nat64 "mo:base/Nat64"; -import D "mo:base/Debug"; +import Nat "mo:core/Nat"; +import Nat64 "mo:core/Nat64"; +import D "mo:core/Debug"; import AU "utils/ArrayUtils"; import HU "utils/HashUtils"; import EcdsaApi "interfaces/EcdsaApi"; @@ -469,4 +469,4 @@ module { }; }; }; -} \ No newline at end of file +} diff --git a/src/Context.mo b/src/Context.mo index e7358fc..0ea6f28 100644 --- a/src/Context.mo +++ b/src/Context.mo @@ -1,6 +1,6 @@ import Ecmult "mo:libsecp256k1/core/ecmult"; import Group "mo:libsecp256k1/core/group"; -import Nat32 "mo:base/Nat32"; +import Nat32 "mo:core/Nat32"; module { /// Convenience wrappers for libsecp256k1 context allocation and preload @@ -36,4 +36,4 @@ module { ): [[Group.AffineStorage]] { return Ecmult.loadPrec(prec); }; -} \ No newline at end of file +} diff --git a/src/Contract.mo b/src/Contract.mo index e92a992..ab1b295 100644 --- a/src/Contract.mo +++ b/src/Contract.mo @@ -1,5 +1,5 @@ -import Error "mo:base/Error"; -import Result "mo:base/Result"; +import Error "mo:core/Error"; +import Result "mo:core/Result"; import Ecmult "mo:libsecp256k1/core/ecmult"; import Transaction "Transaction"; import Types "Types"; @@ -44,4 +44,4 @@ module { }; }; }; -} \ No newline at end of file +} diff --git a/src/Transaction.mo b/src/Transaction.mo index 870bc6a..39dda3f 100644 --- a/src/Transaction.mo +++ b/src/Transaction.mo @@ -1,6 +1,6 @@ -import Blob "mo:base/Blob"; -import Error "mo:base/Error"; -import Result "mo:base/Result"; +import Blob "mo:core/Blob"; +import Error "mo:core/Error"; +import Result "mo:core/Result"; import Ecmult "mo:libsecp256k1/core/ecmult"; import Types "Types"; import Eip2930 "transactions/EIP2930"; @@ -301,4 +301,4 @@ module { }; }; }; -}; \ No newline at end of file +}; diff --git a/src/Transfer.mo b/src/Transfer.mo index db07e3d..d9a0e65 100644 --- a/src/Transfer.mo +++ b/src/Transfer.mo @@ -1,7 +1,7 @@ -import Array "mo:base/Array"; -import Blob "mo:base/Blob"; -import Error "mo:base/Error"; -import Result "mo:base/Result"; +import Array "mo:core/Array"; +import Blob "mo:core/Blob"; +import Error "mo:core/Error"; +import Result "mo:core/Result"; import Ecmult "mo:libsecp256k1/core/ecmult"; import Transaction "Transaction"; import Types "Types"; @@ -78,4 +78,4 @@ module { }; }; }; -} \ No newline at end of file +} diff --git a/src/interfaces/EcdsaApi.mo b/src/interfaces/EcdsaApi.mo index 85482d0..48765ab 100644 --- a/src/interfaces/EcdsaApi.mo +++ b/src/interfaces/EcdsaApi.mo @@ -1,4 +1,4 @@ -import Error "mo:base/Error"; +import Error "mo:core/Error"; module { public type createFn = (keyName: Text, derivationPath: [Blob]) -> async* Blob; public type signFn = (keyName: Text, derivationPath: [Blob], messageHash: Blob) -> async* Blob; @@ -10,4 +10,4 @@ module { public let create = _create; public let sign = _sign; }; -}; \ No newline at end of file +}; diff --git a/src/transactions/EIP1559.mo b/src/transactions/EIP1559.mo index c560e27..486d6d3 100644 --- a/src/transactions/EIP1559.mo +++ b/src/transactions/EIP1559.mo @@ -1,6 +1,6 @@ -import Buffer "mo:base/Buffer"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; +import Buffer "../utils/Buffer"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import Ecmult "mo:libsecp256k1/core/ecmult"; diff --git a/src/transactions/EIP2930.mo b/src/transactions/EIP2930.mo index ac8cc69..d9aedcc 100644 --- a/src/transactions/EIP2930.mo +++ b/src/transactions/EIP2930.mo @@ -1,6 +1,6 @@ -import Buffer "mo:base/Buffer"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; +import Buffer "../utils/Buffer"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import Ecmult "mo:libsecp256k1/core/ecmult"; diff --git a/src/transactions/EIP4844.mo b/src/transactions/EIP4844.mo index b462388..d4b3617 100644 --- a/src/transactions/EIP4844.mo +++ b/src/transactions/EIP4844.mo @@ -1,7 +1,7 @@ -import Buffer "mo:base/Buffer"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; -import Nat8 "mo:base/Nat8"; +import Buffer "../utils/Buffer"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; +import Nat8 "mo:core/Nat8"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import Ecmult "mo:libsecp256k1/core/ecmult"; diff --git a/src/transactions/EIP7702.mo b/src/transactions/EIP7702.mo index ed9acc1..576244c 100644 --- a/src/transactions/EIP7702.mo +++ b/src/transactions/EIP7702.mo @@ -1,7 +1,7 @@ -import Buffer "mo:base/Buffer"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; -import Nat8 "mo:base/Nat8"; +import Buffer "../utils/Buffer"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; +import Nat8 "mo:core/Nat8"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import Ecmult "mo:libsecp256k1/core/ecmult"; diff --git a/src/transactions/Helper.mo b/src/transactions/Helper.mo index 7fc53c0..fea1305 100644 --- a/src/transactions/Helper.mo +++ b/src/transactions/Helper.mo @@ -3,13 +3,13 @@ import Signature "mo:libsecp256k1/Signature"; import Message "mo:libsecp256k1/Message"; import Ecdsa "mo:libsecp256k1/Ecdsa"; import Ecmult "mo:libsecp256k1/core/ecmult"; -import Result "mo:base/Result"; -import Iter "mo:base/Iter"; -import Nat8 "mo:base/Nat8"; -import Nat64 "mo:base/Nat64"; -import Buffer "mo:base/Buffer"; -import Array "mo:base/Array"; -import Text "mo:base/Text"; +import Result "mo:core/Result"; +import Nat "mo:core/Nat"; +import Nat8 "mo:core/Nat8"; +import Nat64 "mo:core/Nat64"; +import Buffer "../utils/Buffer"; +import Array "mo:core/Array"; +import Text "mo:core/Text"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import HU "../utils/HashUtils"; @@ -48,7 +48,7 @@ module { }; }; - label L for(i in Iter.range(0, 2)) { + label L for(i in Nat.rangeInclusive(0, 2)) { let recovery_id = switch(RecoveryId.parse_rpc(Nat8.fromNat(27 + i))) { case (#ok(id)) { id; diff --git a/src/transactions/Legacy.mo b/src/transactions/Legacy.mo index 56781f9..1f63a87 100644 --- a/src/transactions/Legacy.mo +++ b/src/transactions/Legacy.mo @@ -1,8 +1,8 @@ -import Buffer "mo:base/Buffer"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; -import Nat8 "mo:base/Nat8"; -import Int64 "mo:base/Int64"; +import Buffer "../utils/Buffer"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; +import Nat8 "mo:core/Nat8"; +import Int64 "mo:core/Int64"; import Rlp "mo:rlp-motoko"; import RlpTypes "mo:rlp-motoko/types"; import Ecmult "mo:libsecp256k1/core/ecmult"; diff --git a/src/utils/ArrayUtils.mo b/src/utils/ArrayUtils.mo index a0952eb..a9c50ac 100644 --- a/src/utils/ArrayUtils.mo +++ b/src/utils/ArrayUtils.mo @@ -1,12 +1,13 @@ -import Nat "mo:base/Nat"; -import Buffer "mo:base/Buffer"; -import Array "mo:base/Array"; -import Nat64 "mo:base/Nat64"; -import Nat32 "mo:base/Nat32"; -import Nat8 "mo:base/Nat8"; -import Char "mo:base/Char"; -import Iter "mo:base/Iter"; -import Text "mo:base/Text"; +import Nat "mo:core/Nat"; +import Buffer "Buffer"; +import Array "mo:core/Array"; +import VarArray "mo:core/VarArray"; +import Nat64 "mo:core/Nat64"; +import Nat32 "mo:core/Nat32"; +import Nat8 "mo:core/Nat8"; +import Char "mo:core/Char"; +import Iter "mo:core/Iter"; +import Text "mo:core/Text"; import CU "CharUtils"; module { @@ -19,7 +20,7 @@ module { return arr; }; - let res = Array.tabulateVar(size, func i = default); + let res = VarArray.tabulate(size, func _ = default); var i = 0; while(i < arr.size()) { @@ -27,7 +28,7 @@ module { i += 1; }; - return Array.freeze(res); + return VarArray.toArray(res); }; public func left( @@ -212,4 +213,4 @@ module { }; -}; \ No newline at end of file +}; diff --git a/src/utils/Buffer.mo b/src/utils/Buffer.mo new file mode 100644 index 0000000..39d741d --- /dev/null +++ b/src/utils/Buffer.mo @@ -0,0 +1,31 @@ +import PureList "mo:core/pure/List"; + +module { + /// Small append-only builder backed by a pure list. Elements are prepended + /// in O(1), then reversed once when materialized as an array. + public class Buffer(_capacity: Nat) { + var values: PureList.List = PureList.empty(); + var count = 0; + + public func add(value: T) { + values := ?(value, values); + count += 1; + }; + + public func size(): Nat = count; + + public func snapshot(): [T] = PureList.toArray(PureList.reverse(values)); + + public func append(other: Buffer) { + for (value in other.snapshot().vals()) add(value); + }; + }; + + public func fromArray(values: [T]): Buffer { + let result = Buffer(values.size()); + for (value in values.vals()) result.add(value); + result; + }; + + public func toArray(buffer: Buffer): [T] = buffer.snapshot(); +}; diff --git a/src/utils/CharUtils.mo b/src/utils/CharUtils.mo index 90d3f06..8856452 100644 --- a/src/utils/CharUtils.mo +++ b/src/utils/CharUtils.mo @@ -1,4 +1,4 @@ -import Char "mo:base/Char"; +import Char "mo:core/Char"; module { let ZERO_CHAR = 48: Nat32; @@ -30,4 +30,4 @@ module { return Char.fromNat32(A_LC_CHAR + (val - 10)); }; }; -} \ No newline at end of file +} diff --git a/src/utils/IcEcdsaApi.mo b/src/utils/IcEcdsaApi.mo index a75274c..5074479 100644 --- a/src/utils/IcEcdsaApi.mo +++ b/src/utils/IcEcdsaApi.mo @@ -1,5 +1,3 @@ -import ExperimentalCycles "mo:base/ExperimentalCycles"; - module { /// Minimal Internet Computer ECDSA adapter used by the higher-level signing /// helpers. This is a convenience implementation, not the core transaction @@ -62,8 +60,7 @@ module { derivationPath : [Blob], messageHash : Blob ) : async* Blob { - ExperimentalCycles.add(10_000_000_000); - let res = await ecdsa_canister_actor.sign_with_ecdsa({ + let res = await (with cycles = 10_000_000_000) ecdsa_canister_actor.sign_with_ecdsa({ message_hash = messageHash; derivation_path = derivationPath; key_id = { diff --git a/src/utils/RlpUtils.mo b/src/utils/RlpUtils.mo index 3286ffb..cb9aa83 100644 --- a/src/utils/RlpUtils.mo +++ b/src/utils/RlpUtils.mo @@ -1,4 +1,4 @@ -import Buffer "mo:base/Buffer"; +import Buffer "Buffer"; import RlpTypes "mo:rlp-motoko/types"; import AU "ArrayUtils"; diff --git a/src/utils/TextUtils.mo b/src/utils/TextUtils.mo index 45fa950..93616ed 100644 --- a/src/utils/TextUtils.mo +++ b/src/utils/TextUtils.mo @@ -1,13 +1,14 @@ -import Text "mo:base/Text"; -import Array "mo:base/Array"; -import Nat "mo:base/Nat"; -import Iter "mo:base/Iter"; -import Char "mo:base/Char"; -import Int "mo:base/Int"; -import Blob "mo:base/Blob"; -import Buffer "mo:base/Buffer"; -import Nat8 "mo:base/Nat8"; -import Nat32 "mo:base/Nat32"; +import Text "mo:core/Text"; +import Array "mo:core/Array"; +import VarArray "mo:core/VarArray"; +import Iter "mo:core/Iter"; +import Nat "mo:core/Nat"; +import Char "mo:core/Char"; +import Int "mo:core/Int"; +import Blob "mo:core/Blob"; +import Buffer "Buffer"; +import Nat8 "mo:core/Nat8"; +import Nat32 "mo:core/Nat32"; module TextUtils { public func encodeUtf8( @@ -27,8 +28,8 @@ module TextUtils { let src = _textToCharArray(text); let offset = Nat.sub(chars, src.size()); - let res = Array.init(chars, value); - for(i in Iter.range(0, src.size()-1)) { + let res = VarArray.repeat(value, chars); + for(i in Nat.range(0, src.size())) { res[offset + i] := src[i]; }; @@ -83,4 +84,4 @@ module TextUtils { ): Text { Text.fromIter(text.vals()); }; -}; \ No newline at end of file +}; diff --git a/test/async/Utils.test.mo b/test/async/Utils.test.mo index 7de4465..e2839b7 100644 --- a/test/async/Utils.test.mo +++ b/test/async/Utils.test.mo @@ -2,7 +2,7 @@ import { test; suite } "mo:test"; import HU "../../src/utils/HashUtils"; import AU "../../src/utils/ArrayUtils"; import Transfer "../../src/Transfer"; -import Debug "mo:base/Debug"; +import Debug "mo:core/Debug"; suite("nat64ToArray", func() { test("0xdeadbeef=[0xde, 0xad, 0xbe, 0xef]", func() { diff --git a/test/async/WithECmultContext.test.mo b/test/async/WithECmultContext.test.mo index acc44d9..559a937 100644 --- a/test/async/WithECmultContext.test.mo +++ b/test/async/WithECmultContext.test.mo @@ -1,5 +1,5 @@ import { suite; test } "mo:test/async"; -import Principal "mo:base/Principal"; +import Principal "mo:core/Principal"; import Address "../../src/Address"; import Legacy "../../src/transactions/Legacy"; import EIP2930 "../../src/transactions/EIP2930"; @@ -12,7 +12,7 @@ import IcEcdsaApi "../mocks/IcEcdsaApi"; import Random "../mocks/Random"; import Types "../../src/Types"; import Transaction "../../src/Transaction"; -import Debug "mo:base/Debug"; +import Debug "mo:core/Debug"; let testContext = TestContext.Context(); let icEcdsaApi = IcEcdsaApi.IcEcdsaApiMock(testContext.ecGenCtx, Random.RandomMock()); @@ -866,4 +866,4 @@ await suite("Address.recover", func() : async () { await test("invalid message", func() : async () { assert(recoverInvalidMessage()); }); -}); \ No newline at end of file +}); diff --git a/test/mocks/IcEcdsaApi.mo b/test/mocks/IcEcdsaApi.mo index 5eed3d4..8228042 100644 --- a/test/mocks/IcEcdsaApi.mo +++ b/test/mocks/IcEcdsaApi.mo @@ -5,9 +5,8 @@ import Signature "mo:libsecp256k1/Signature"; import Ecdsa "mo:libsecp256k1/Ecdsa"; import ECMult "mo:libsecp256k1/core/ecmult"; import AU "../../src/utils/ArrayUtils"; -import Blob "mo:base/Blob"; -import Prelude "mo:base/Prelude"; -import Error "mo:base/Error"; +import Blob "mo:core/Blob"; +import Error "mo:core/Error"; import Random "mo:libsecp256k1/interfaces/Random"; module { @@ -56,4 +55,4 @@ module { }; }; }; -} \ No newline at end of file +} diff --git a/test/mocks/Random.mo b/test/mocks/Random.mo index 894e94e..03c853c 100644 --- a/test/mocks/Random.mo +++ b/test/mocks/Random.mo @@ -1,15 +1,13 @@ -import Array "mo:base/Array"; - -import Nat8 "mo:base/Nat8"; -import Iter "mo:base/Iter"; +import VarArray "mo:core/VarArray"; +import Nat8 "mo:core/Nat8"; module { public class RandomMock() { - let n = Array.tabulateVar(32, func i = Nat8.fromNat(i)); + let n = VarArray.tabulate(32, func i = Nat8.fromNat(i)); public let next = func(): [Nat8] { /*for(i in Iter.range(0, 31)) { n[i] := n[i] ^ 1; };*/ - return Array.freeze(n); + return VarArray.toArray(n); }; }; -} \ No newline at end of file +} diff --git a/test/sync/getBoxed.test.mo b/test/sync/getBoxed.test.mo index 094f423..8f01cc5 100644 --- a/test/sync/getBoxed.test.mo +++ b/test/sync/getBoxed.test.mo @@ -1,8 +1,8 @@ import {test; suite} "mo:test"; import Transaction "../../src/Transaction"; -import Debug "mo:base/Debug"; -import Result "mo:base/Result"; -import Nat64 "mo:base/Nat64"; +import Debug "mo:core/Debug"; +import Result "mo:core/Result"; +import Nat64 "mo:core/Nat64"; suite("EIP-2930 getBoxed with real tx data", func() {