From 5f4fe03a37fba68fb4133acb214265697b138165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Pietro=20Calabr=C3=B2?= <33911400+rodolfopietro97@users.noreply.github.com> Date: Wed, 29 May 2024 15:18:49 +0200 Subject: [PATCH] Dappkit fixes 3 (#924) * fix: rlp name * fix: release 9 * fix: reset flag --- apps/sdk-hardhat-integration/package.json | 6 +- apps/sdk-hardhat-integration/yarn.lock | 68 +++---- apps/sdk-nextjs-integration/package.json | 4 +- apps/sdk-nextjs-integration/yarn.lock | 44 ++--- apps/sdk-node-integration/package.json | 2 +- apps/sdk-node-integration/yarn.lock | 44 ++--- docs/encoding.md | 10 +- docs/examples/encoding/rlp.ts | 12 +- docs/package.json | 4 +- packages/core/package.json | 6 +- packages/core/src/assertions/rlp/rlp.ts | 6 +- .../rlp/helpers/compactfixedhexblobkind.ts | 6 +- .../encoding/rlp/helpers/fixedhexblobkind.ts | 6 +- .../src/encoding/rlp/helpers/hexblobkind.ts | 10 +- .../src/encoding/rlp/helpers/numerickind.ts | 18 +- packages/core/src/encoding/rlp/index.ts | 12 +- packages/core/src/encoding/rlp/kind/index.ts | 8 +- packages/core/src/encoding/rlp/rlp.ts | 32 ++-- packages/core/src/utils/const/transaction.ts | 39 ++-- packages/core/tests/rlp/rlp.fixture.ts | 176 +++++++++--------- packages/core/tests/rlp/rlp.unit.test.ts | 58 +++--- packages/errors/package.json | 2 +- packages/errors/src/model/core/rlp.ts | 14 +- packages/errors/src/types/errorTypes.ts | 21 ++- packages/errors/tests/fixture.ts | 64 +++---- .../error-builder/error-handling.unit.test.ts | 2 +- packages/ethers-adapter/package.json | 6 +- packages/hardhat-plugin/package.json | 6 +- packages/logging/package.json | 4 +- packages/network/package.json | 8 +- packages/rpc-proxy/package.json | 6 +- 31 files changed, 360 insertions(+), 344 deletions(-) diff --git a/apps/sdk-hardhat-integration/package.json b/apps/sdk-hardhat-integration/package.json index a81940fb7..f453cb760 100644 --- a/apps/sdk-hardhat-integration/package.json +++ b/apps/sdk-hardhat-integration/package.json @@ -13,9 +13,9 @@ "deploy-testnet": "npx hardhat run scripts/deploy.ts --network vechain_testnet" }, "dependencies": { - "@vechain/sdk-core": "1.0.0-beta.8", - "@vechain/sdk-hardhat-plugin": "1.0.0-beta.8", - "@vechain/sdk-logging": "1.0.0-beta.8", + "@vechain/sdk-core": "1.0.0-beta.9", + "@vechain/sdk-hardhat-plugin": "1.0.0-beta.9", + "@vechain/sdk-logging": "1.0.0-beta.9", "@openzeppelin/contracts": "^5.0.2" }, "devDependencies": { diff --git a/apps/sdk-hardhat-integration/yarn.lock b/apps/sdk-hardhat-integration/yarn.lock index da062ec5a..7e8ccacaa 100644 --- a/apps/sdk-hardhat-integration/yarn.lock +++ b/apps/sdk-hardhat-integration/yarn.lock @@ -969,61 +969,61 @@ dependencies: "@types/node" "*" -"@vechain/sdk-core@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.8.tgz#d41c928077a8ff6c625aba6ce5830e6bf03c11f2" - integrity sha512-YPQqWVAEPKtFrQgg5Gwb6AJM4z6BNGaHxZ6tsnQPDoqT3FgKuv0n8Zor161h1mJQS71vkOUPXFxefaG5e5+zMA== +"@vechain/sdk-core@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.9.tgz#ca680e3dabd483778c128fee3deb58090b9ff490" + integrity sha512-fXYTMoyhl9GSnaQ9AOwkfKmJ1glik5EqnybnzPXkexXvJj963vhUm57NyuSRCf/3du7hX8UDculM+GagRa68qA== dependencies: "@ethereumjs/rlp" "^5.0.2" "@noble/ciphers" "^0.5.2" "@scure/bip32" "^1.4.0" "@scure/bip39" "^1.3.0" "@types/elliptic" "^6.4.18" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" bignumber.js "^9.1.2" blakejs "^1.2.1" elliptic "^6.5.5" ethers "6.12.1" fast-json-stable-stringify "^2.1.0" -"@vechain/sdk-errors@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.8.tgz#adeda992f9e9ddd6ef26008acd05d304ab0d2353" - integrity sha512-0KKm8WmNYn+4+TnprkFj3XhKYlic7pChHdYVbkBYrioceaQvwa7+Fp/RMTruOopHSYSetlHbReuhFnQmBMDhuQ== +"@vechain/sdk-errors@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.9.tgz#48d8950b9d4086b0fbbf8d208a42555384511509" + integrity sha512-OJx8lXLoPs48prgGWwKNuRyQ+R+EB24Ces30hOq7tkZ4H6A6HnFB7/HAjuLOjTqhWQrCQ8EnOnlMmtk6PNH13g== -"@vechain/sdk-ethers-adapter@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-ethers-adapter/-/sdk-ethers-adapter-1.0.0-beta.8.tgz#a69e85770ea1327e3112fb501d2245dded0af45a" - integrity sha512-ZZUTfA0eyYCN84E/AhVC4iQlB6yvT02Wn49PkdqFz5aDaWc1Ubrbwsa66pZbvNdyj1Sx3Lm/tT/eyo+Bn14WEA== +"@vechain/sdk-ethers-adapter@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-ethers-adapter/-/sdk-ethers-adapter-1.0.0-beta.9.tgz#a0739add898a170c6969a3ea39951ac1bcb84205" + integrity sha512-u+Asf1z3Ro75dxNa1hLyYHzHMlN+eR+aPXLtVEHrt+6KmGkxMNnRZ3uF5g6Fm7K6ie9FHECoI5sUt17Z2Felvw== dependencies: - "@vechain/sdk-core" "1.0.0-beta.8" - "@vechain/sdk-network" "1.0.0-beta.8" + "@vechain/sdk-core" "1.0.0-beta.9" + "@vechain/sdk-network" "1.0.0-beta.9" -"@vechain/sdk-hardhat-plugin@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-hardhat-plugin/-/sdk-hardhat-plugin-1.0.0-beta.8.tgz#e5f0d8409e312a690dd9c48bc4c35424653ad526" - integrity sha512-mWmWYTXsLZpUTSUiPOpsEU/cUhgPI1+eEg1GOna9nml7/ctz2wK/ahS3LI5SvkD/xdvM84ZKeZLtW8ZnMqM2sw== +"@vechain/sdk-hardhat-plugin@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-hardhat-plugin/-/sdk-hardhat-plugin-1.0.0-beta.9.tgz#93e43ea1cffbea99d62f6f50e4340bdca22a9591" + integrity sha512-WWZr9vG0PVOPy1rEj6SDKFhxTxtCvmrrt9N0rEkOCysD4X70JomwAU7RT5k8RO06XI9CVgZoBDoXquETbhEQ7w== dependencies: - "@vechain/sdk-ethers-adapter" "1.0.0-beta.8" - "@vechain/sdk-network" "1.0.0-beta.8" + "@vechain/sdk-ethers-adapter" "1.0.0-beta.9" + "@vechain/sdk-network" "1.0.0-beta.9" -"@vechain/sdk-logging@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.8.tgz#850254e44b3a163294b60a0f020ff6fdd93ddd32" - integrity sha512-yupdWQ/H4XVrnJysZscpk1z9Nj+3S7mtmJmvPx6ciDOJw0+g8rAMVla+LBXDrhx5xJxFccTjVoobdnTJgDI+kg== +"@vechain/sdk-logging@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.9.tgz#4daac10f27cd432e98ce9e05fca48193ec93a58e" + integrity sha512-WRiy/R1Z8y3xoURppmyLOyY4Ei3ySd3R8DMs913rR/JZ4k+MG+jD6vxq5Phk8TuZYo+1XAaOMx3Z3Gc6uCxmnA== dependencies: - "@vechain/sdk-errors" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" -"@vechain/sdk-network@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.8.tgz#bf3b167110915507dfd8d44e0d1e8729f8812f62" - integrity sha512-JaH7LAv4n4nc6ihx4G2m1YS1nqCf+fMco8z2ztiYkdWsfFXTOSqv/T/PVv7YxsvTiFhUPOHol8xqUJNcOp7vCQ== +"@vechain/sdk-network@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.9.tgz#63d574fa3b580f9fd6472dbf1188a27a3f3a314a" + integrity sha512-Uf3nYV2rfM8+m41InNu7w3cPrqOYRnAN58/4T5ntE4garFTvI24ipuUPpPB7gMSBoOplWTXibaRDuuZiLo3bLA== dependencies: "@types/ws" "^8.5.10" - "@vechain/sdk-core" "1.0.0-beta.8" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-core" "1.0.0-beta.9" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" axios "^1.7.2" abbrev@1: diff --git a/apps/sdk-nextjs-integration/package.json b/apps/sdk-nextjs-integration/package.json index d84c507de..bc1badcb2 100644 --- a/apps/sdk-nextjs-integration/package.json +++ b/apps/sdk-nextjs-integration/package.json @@ -12,8 +12,8 @@ "test:watch": "jest --watch" }, "dependencies": { - "@vechain/sdk-core": "1.0.0-beta.8", - "@vechain/sdk-network": "1.0.0-beta.8", + "@vechain/sdk-core": "1.0.0-beta.9", + "@vechain/sdk-network": "1.0.0-beta.9", "install": "^0.13.0", "next": "14", "react": "^18", diff --git a/apps/sdk-nextjs-integration/yarn.lock b/apps/sdk-nextjs-integration/yarn.lock index 1eb1cc3fc..9c9c44b3f 100644 --- a/apps/sdk-nextjs-integration/yarn.lock +++ b/apps/sdk-nextjs-integration/yarn.lock @@ -1052,45 +1052,45 @@ resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406" integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ== -"@vechain/sdk-core@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.8.tgz#d41c928077a8ff6c625aba6ce5830e6bf03c11f2" - integrity sha512-YPQqWVAEPKtFrQgg5Gwb6AJM4z6BNGaHxZ6tsnQPDoqT3FgKuv0n8Zor161h1mJQS71vkOUPXFxefaG5e5+zMA== +"@vechain/sdk-core@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.9.tgz#ca680e3dabd483778c128fee3deb58090b9ff490" + integrity sha512-fXYTMoyhl9GSnaQ9AOwkfKmJ1glik5EqnybnzPXkexXvJj963vhUm57NyuSRCf/3du7hX8UDculM+GagRa68qA== dependencies: "@ethereumjs/rlp" "^5.0.2" "@noble/ciphers" "^0.5.2" "@scure/bip32" "^1.4.0" "@scure/bip39" "^1.3.0" "@types/elliptic" "^6.4.18" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" bignumber.js "^9.1.2" blakejs "^1.2.1" elliptic "^6.5.5" ethers "6.12.1" fast-json-stable-stringify "^2.1.0" -"@vechain/sdk-errors@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.8.tgz#adeda992f9e9ddd6ef26008acd05d304ab0d2353" - integrity sha512-0KKm8WmNYn+4+TnprkFj3XhKYlic7pChHdYVbkBYrioceaQvwa7+Fp/RMTruOopHSYSetlHbReuhFnQmBMDhuQ== +"@vechain/sdk-errors@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.9.tgz#48d8950b9d4086b0fbbf8d208a42555384511509" + integrity sha512-OJx8lXLoPs48prgGWwKNuRyQ+R+EB24Ces30hOq7tkZ4H6A6HnFB7/HAjuLOjTqhWQrCQ8EnOnlMmtk6PNH13g== -"@vechain/sdk-logging@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.8.tgz#850254e44b3a163294b60a0f020ff6fdd93ddd32" - integrity sha512-yupdWQ/H4XVrnJysZscpk1z9Nj+3S7mtmJmvPx6ciDOJw0+g8rAMVla+LBXDrhx5xJxFccTjVoobdnTJgDI+kg== +"@vechain/sdk-logging@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.9.tgz#4daac10f27cd432e98ce9e05fca48193ec93a58e" + integrity sha512-WRiy/R1Z8y3xoURppmyLOyY4Ei3ySd3R8DMs913rR/JZ4k+MG+jD6vxq5Phk8TuZYo+1XAaOMx3Z3Gc6uCxmnA== dependencies: - "@vechain/sdk-errors" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" -"@vechain/sdk-network@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.8.tgz#bf3b167110915507dfd8d44e0d1e8729f8812f62" - integrity sha512-JaH7LAv4n4nc6ihx4G2m1YS1nqCf+fMco8z2ztiYkdWsfFXTOSqv/T/PVv7YxsvTiFhUPOHol8xqUJNcOp7vCQ== +"@vechain/sdk-network@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.9.tgz#63d574fa3b580f9fd6472dbf1188a27a3f3a314a" + integrity sha512-Uf3nYV2rfM8+m41InNu7w3cPrqOYRnAN58/4T5ntE4garFTvI24ipuUPpPB7gMSBoOplWTXibaRDuuZiLo3bLA== dependencies: "@types/ws" "^8.5.10" - "@vechain/sdk-core" "1.0.0-beta.8" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-core" "1.0.0-beta.9" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" axios "^1.7.2" abab@^2.0.6: diff --git a/apps/sdk-node-integration/package.json b/apps/sdk-node-integration/package.json index c308ecf51..1f837d95c 100644 --- a/apps/sdk-node-integration/package.json +++ b/apps/sdk-node-integration/package.json @@ -11,7 +11,7 @@ "test": "jest" }, "dependencies": { - "@vechain/sdk-network": "1.0.0-beta.8", + "@vechain/sdk-network": "1.0.0-beta.9", "axios": "^1.6.8", "typescript": "^5.3.3" }, diff --git a/apps/sdk-node-integration/yarn.lock b/apps/sdk-node-integration/yarn.lock index 404daad74..8bcb35338 100644 --- a/apps/sdk-node-integration/yarn.lock +++ b/apps/sdk-node-integration/yarn.lock @@ -999,45 +999,45 @@ dependencies: "@types/yargs-parser" "*" -"@vechain/sdk-core@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.8.tgz#d41c928077a8ff6c625aba6ce5830e6bf03c11f2" - integrity sha512-YPQqWVAEPKtFrQgg5Gwb6AJM4z6BNGaHxZ6tsnQPDoqT3FgKuv0n8Zor161h1mJQS71vkOUPXFxefaG5e5+zMA== +"@vechain/sdk-core@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-core/-/sdk-core-1.0.0-beta.9.tgz#ca680e3dabd483778c128fee3deb58090b9ff490" + integrity sha512-fXYTMoyhl9GSnaQ9AOwkfKmJ1glik5EqnybnzPXkexXvJj963vhUm57NyuSRCf/3du7hX8UDculM+GagRa68qA== dependencies: "@ethereumjs/rlp" "^5.0.2" "@noble/ciphers" "^0.5.2" "@scure/bip32" "^1.4.0" "@scure/bip39" "^1.3.0" "@types/elliptic" "^6.4.18" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" bignumber.js "^9.1.2" blakejs "^1.2.1" elliptic "^6.5.5" ethers "6.12.1" fast-json-stable-stringify "^2.1.0" -"@vechain/sdk-errors@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.8.tgz#adeda992f9e9ddd6ef26008acd05d304ab0d2353" - integrity sha512-0KKm8WmNYn+4+TnprkFj3XhKYlic7pChHdYVbkBYrioceaQvwa7+Fp/RMTruOopHSYSetlHbReuhFnQmBMDhuQ== +"@vechain/sdk-errors@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-errors/-/sdk-errors-1.0.0-beta.9.tgz#48d8950b9d4086b0fbbf8d208a42555384511509" + integrity sha512-OJx8lXLoPs48prgGWwKNuRyQ+R+EB24Ces30hOq7tkZ4H6A6HnFB7/HAjuLOjTqhWQrCQ8EnOnlMmtk6PNH13g== -"@vechain/sdk-logging@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.8.tgz#850254e44b3a163294b60a0f020ff6fdd93ddd32" - integrity sha512-yupdWQ/H4XVrnJysZscpk1z9Nj+3S7mtmJmvPx6ciDOJw0+g8rAMVla+LBXDrhx5xJxFccTjVoobdnTJgDI+kg== +"@vechain/sdk-logging@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-logging/-/sdk-logging-1.0.0-beta.9.tgz#4daac10f27cd432e98ce9e05fca48193ec93a58e" + integrity sha512-WRiy/R1Z8y3xoURppmyLOyY4Ei3ySd3R8DMs913rR/JZ4k+MG+jD6vxq5Phk8TuZYo+1XAaOMx3Z3Gc6uCxmnA== dependencies: - "@vechain/sdk-errors" "1.0.0-beta.8" + "@vechain/sdk-errors" "1.0.0-beta.9" -"@vechain/sdk-network@1.0.0-beta.8": - version "1.0.0-beta.8" - resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.8.tgz#bf3b167110915507dfd8d44e0d1e8729f8812f62" - integrity sha512-JaH7LAv4n4nc6ihx4G2m1YS1nqCf+fMco8z2ztiYkdWsfFXTOSqv/T/PVv7YxsvTiFhUPOHol8xqUJNcOp7vCQ== +"@vechain/sdk-network@1.0.0-beta.9": + version "1.0.0-beta.9" + resolved "https://registry.yarnpkg.com/@vechain/sdk-network/-/sdk-network-1.0.0-beta.9.tgz#63d574fa3b580f9fd6472dbf1188a27a3f3a314a" + integrity sha512-Uf3nYV2rfM8+m41InNu7w3cPrqOYRnAN58/4T5ntE4garFTvI24ipuUPpPB7gMSBoOplWTXibaRDuuZiLo3bLA== dependencies: "@types/ws" "^8.5.10" - "@vechain/sdk-core" "1.0.0-beta.8" - "@vechain/sdk-errors" "1.0.0-beta.8" - "@vechain/sdk-logging" "1.0.0-beta.8" + "@vechain/sdk-core" "1.0.0-beta.9" + "@vechain/sdk-errors" "1.0.0-beta.9" + "@vechain/sdk-logging" "1.0.0-beta.9" axios "^1.7.2" acorn-walk@^8.1.1: diff --git a/docs/encoding.md b/docs/encoding.md index ee8a1bc29..9720a9c74 100644 --- a/docs/encoding.md +++ b/docs/encoding.md @@ -105,9 +105,9 @@ By supporting ABI and RLP encoding handling, VeChainSDK equips developers with t const profile = { name: 'clause', kind: [ - { name: 'to', kind: new RLP.OptionalFixedHexBlobKind(20) }, - { name: 'value', kind: new RLP.NumericKind(32) }, - { name: 'data', kind: new RLP.HexBlobKind() } + { name: 'to', kind: new RLP_CODER.OptionalFixedHexBlobKind(20) }, + { name: 'value', kind: new RLP_CODER.NumericKind(32) }, + { name: 'data', kind: new RLP_CODER.HexBlobKind() } ] }; @@ -119,9 +119,9 @@ const clause = { data: '0x' }; -// 3 - RLP Instance to encode and decode +// 3 - RLP_CODER Instance to encode and decode -const rlp = new RLP.Profiler(profile); +const rlp = new RLP_CODER.Profiler(profile); // Encoding and Decoding const data = rlp.encodeObject(clause); diff --git a/docs/examples/encoding/rlp.ts b/docs/examples/encoding/rlp.ts index 4c74dc6df..1e4e5a6e0 100644 --- a/docs/examples/encoding/rlp.ts +++ b/docs/examples/encoding/rlp.ts @@ -1,4 +1,4 @@ -import { RLP } from '@vechain/sdk-core'; +import { RLP_CODER } from '@vechain/sdk-core'; import { expect } from 'expect'; // START_SNIPPET: RlpSnippet @@ -8,9 +8,9 @@ import { expect } from 'expect'; const profile = { name: 'clause', kind: [ - { name: 'to', kind: new RLP.OptionalFixedHexBlobKind(20) }, - { name: 'value', kind: new RLP.NumericKind(32) }, - { name: 'data', kind: new RLP.HexBlobKind() } + { name: 'to', kind: new RLP_CODER.OptionalFixedHexBlobKind(20) }, + { name: 'value', kind: new RLP_CODER.NumericKind(32) }, + { name: 'data', kind: new RLP_CODER.HexBlobKind() } ] }; @@ -22,9 +22,9 @@ const clause = { data: '0x' }; -// 3 - RLP Instance to encode and decode +// 3 - RLP_CODER Instance to encode and decode -const rlp = new RLP.Profiler(profile); +const rlp = new RLP_CODER.Profiler(profile); // Encoding and Decoding const data = rlp.encodeObject(clause); diff --git a/docs/package.json b/docs/package.json index f2913ee59..8ee5d6b85 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "docs", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "Documentation for the SDK with examples", "author": "vechain Foundation", "license": "MIT", @@ -20,7 +20,7 @@ "test:examples:solo": "(yarn start-thor-solo && yarn test:examples && yarn stop-thor-solo) || yarn stop-thor-solo" }, "dependencies": { - "@vechain/sdk-core": "1.0.0-beta.8", + "@vechain/sdk-core": "1.0.0-beta.9", "typescript": "^5.4.4" }, "devDependencies": { diff --git a/packages/core/package.json b/packages/core/package.json index 816805fd9..f0b3670fa 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-core", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "Includes modules for fundamental operations like hashing and cryptography", "author": "vechain Foundation", "license": "MIT", @@ -39,8 +39,8 @@ "@scure/bip32": "^1.4.0", "@scure/bip39": "^1.3.0", "@types/elliptic": "^6.4.18", - "@vechain/sdk-errors": "1.0.0-beta.8", - "@vechain/sdk-logging": "1.0.0-beta.8", + "@vechain/sdk-errors": "1.0.0-beta.9", + "@vechain/sdk-logging": "1.0.0-beta.9", "bignumber.js": "^9.1.2", "blakejs": "^1.2.1", "elliptic": "^6.5.5", diff --git a/packages/core/src/assertions/rlp/rlp.ts b/packages/core/src/assertions/rlp/rlp.ts index 0c66891e4..29ddd9a2b 100644 --- a/packages/core/src/assertions/rlp/rlp.ts +++ b/packages/core/src/assertions/rlp/rlp.ts @@ -1,4 +1,4 @@ -import { assert, RLP as RLPError, RLP } from '@vechain/sdk-errors'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; import { type RLPInput } from '../../encoding'; /** @@ -18,7 +18,7 @@ function assertIsValidBuffer( assert( `assertIsValidBuffer - ${methodName}`, Buffer.isBuffer(bufferToCheck), - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Expected a Buffer type in ${context}.`, { bufferToCheck, @@ -44,7 +44,7 @@ function assertIsArray( assert( `assertIsArray - ${methodName}`, Array.isArray(arrayToCheck), - RLPError.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Expected an array in ${context}.`, { context diff --git a/packages/core/src/encoding/rlp/helpers/compactfixedhexblobkind.ts b/packages/core/src/encoding/rlp/helpers/compactfixedhexblobkind.ts index 74ab28ced..c9dd4e1b6 100644 --- a/packages/core/src/encoding/rlp/helpers/compactfixedhexblobkind.ts +++ b/packages/core/src/encoding/rlp/helpers/compactfixedhexblobkind.ts @@ -1,4 +1,4 @@ -import { assert, RLP } from '@vechain/sdk-errors'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; import { Hex0x } from '../../../utils'; /** @@ -17,7 +17,7 @@ const assertCompactFixedHexBlobBuffer = ( assert( 'assertCompactFixedHexBlobBuffer', buffer.length <= bytes, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Buffer in ${context} must be at most ${bytes} bytes.`, { buffer, context } ); @@ -25,7 +25,7 @@ const assertCompactFixedHexBlobBuffer = ( assert( 'assertCompactFixedHexBlobBuffer', buffer.length === 0 || buffer[0] !== 0, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Buffer in ${context} should not have leading zero bytes.`, { buffer, diff --git a/packages/core/src/encoding/rlp/helpers/fixedhexblobkind.ts b/packages/core/src/encoding/rlp/helpers/fixedhexblobkind.ts index 37963b5e8..acbef064a 100644 --- a/packages/core/src/encoding/rlp/helpers/fixedhexblobkind.ts +++ b/packages/core/src/encoding/rlp/helpers/fixedhexblobkind.ts @@ -1,4 +1,4 @@ -import { assert, RLP } from '@vechain/sdk-errors'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; /** * Asserts that the data is a hex string of the correct length. @@ -16,7 +16,7 @@ const assertFixedHexBlobKindData = ( assert( 'assertFixedHexBlobKindData', data.length === bytes * 2 + 2, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Hex string in ${context} must be exactly ${bytes} bytes in length.`, { data, context } ); @@ -39,7 +39,7 @@ const assertFixedHexBlobKindBuffer = ( assert( 'assertFixedHexBlobKindBuffer', buffer.length === bytes, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Buffer in ${context} must be exactly ${bytes} bytes in length.`, { buffer, context } ); diff --git a/packages/core/src/encoding/rlp/helpers/hexblobkind.ts b/packages/core/src/encoding/rlp/helpers/hexblobkind.ts index 5fb6a6503..71ad5c114 100644 --- a/packages/core/src/encoding/rlp/helpers/hexblobkind.ts +++ b/packages/core/src/encoding/rlp/helpers/hexblobkind.ts @@ -1,6 +1,6 @@ import { Hex0x } from '../../../utils'; import { type RLPInput } from '../types'; -import { assert, RLP } from '@vechain/sdk-errors'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; /** * Validates if the input is a proper hex string for HexBlobKind. @@ -13,7 +13,7 @@ const assertValidHexBlobKindData = (data: RLPInput, context: string): void => { assert( 'assertValidHexBlobKindData', typeof data === 'string', - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, 'Validation error: Input must be a string.', { data, @@ -25,7 +25,7 @@ const assertValidHexBlobKindData = (data: RLPInput, context: string): void => { assert( 'assertValidHexBlobKindData', Hex0x.isValid(data as string), - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, "Validation error: Input must be a valid hex string with a '0x' prefix.", { data, context } ); @@ -34,7 +34,7 @@ const assertValidHexBlobKindData = (data: RLPInput, context: string): void => { assert( 'assertValidHexBlobKindData', (data as string).length % 2 === 0, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, 'Validation error: Hex string must have an even length.', { data, context } ); @@ -54,7 +54,7 @@ const assertValidHexBlobKindBuffer = ( assert( 'assertValidHexBlobKindBuffer', Buffer.isBuffer(buffer), - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, 'Validation error: Input must be a valid buffer.', { buffer, diff --git a/packages/core/src/encoding/rlp/helpers/numerickind.ts b/packages/core/src/encoding/rlp/helpers/numerickind.ts index e5bc193a1..5de9ba927 100644 --- a/packages/core/src/encoding/rlp/helpers/numerickind.ts +++ b/packages/core/src/encoding/rlp/helpers/numerickind.ts @@ -1,6 +1,6 @@ -import { dataUtils, Hex0x, Hex } from '../../../utils'; +import { dataUtils, Hex, Hex0x } from '../../../utils'; import { type RLPInput } from '../types'; -import { assert, RLP } from '@vechain/sdk-errors'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; /** * Validates and converts the input data to a BigInt. @@ -16,7 +16,7 @@ const validateNumericKindData = (data: RLPInput, context: string): bigint => { assert( 'validateNumericKindData', typeof data === 'number' || typeof data === 'string', - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Input in ${context} must be a string or number.`, { data, context } ); @@ -46,7 +46,7 @@ const _validateNumericKindNumber = (num: number, context: string): void => { assert( 'validateNumericKindNumber', Number.isSafeInteger(num) && num >= 0, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Number in ${context} must be a safe and non-negative integer.`, { num, @@ -75,7 +75,7 @@ const _validateNumericKindString = (str: string, context: string): void => { assert( '_validateNumericKindString', isHex || isDecimal, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: String in ${context} must represent a non-negative integer in hex or decimal format.`, { str, context } ); @@ -84,7 +84,7 @@ const _validateNumericKindString = (str: string, context: string): void => { assert( '_validateNumericKindString', !isHex || str.length > 2, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Hex string number in ${context} must be of valid length.`, { str, context } ); @@ -111,7 +111,7 @@ const assertValidNumericKindBuffer = ( assert( 'assertValidNumericKindBuffer', maxBytes === undefined || buf.length <= maxBytes, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Buffer in ${context} must be less than ${maxBytes} bytes.`, { maxBytes, context } ); @@ -120,7 +120,7 @@ const assertValidNumericKindBuffer = ( assert( 'assertValidNumericKindBuffer', buf[0] !== 0, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Buffer in ${context} must represent a canonical integer (no leading zeros).`, { buf, context } ); @@ -145,7 +145,7 @@ const encodeBigIntToBuffer = ( assert( 'encodeBigIntToBuffer', maxBytes === undefined || hex.length <= maxBytes * 2, - RLP.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Validation error: Encoded number in ${context} must fit within ${maxBytes} bytes.`, { maxBytes, hex, context } ); diff --git a/packages/core/src/encoding/rlp/index.ts b/packages/core/src/encoding/rlp/index.ts index 4edb3a70e..7865e0079 100644 --- a/packages/core/src/encoding/rlp/index.ts +++ b/packages/core/src/encoding/rlp/index.ts @@ -7,17 +7,17 @@ export * from './types.d'; export * from './helpers'; /** - * The `RLP` object, encapsulating all functionalities related to Recursive Length Prefix (RLP) encoding. + * The `RLP_CODER` object, encapsulating all functionalities related to Recursive Length Prefix (RLP_CODER) encoding. * - * RLP contains the following classes and methods: - * - `encode` - Encodes data using the Ethereumjs RLP library. - * - `decode` - Decodes RLP-encoded data using the Ethereumjs RLP library. - * - `Profiler` - Class handling the profiling of RLP encoded/decoded objects. + * RLP_CODER contains the following classes and methods: + * - `encode` - Encodes data using the Ethereumjs RLP_CODER library. + * - `decode` - Decodes RLP_CODER-encoded data using the Ethereumjs RLP_CODER library. + * - `Profiler` - Class handling the profiling of RLP_CODER encoded/decoded objects. * - `ScalarKind` - Abstract class for scalar types. * - `BufferKind` - Class managing buffers and ensuring type safety with encode/decode methods. * - `NumericKind` - Class managing numerical data ensuring it adheres to specific constraints. */ -export const RLP = { +export const RLP_CODER = { ...RLPBase, ...RLPProfiles }; diff --git a/packages/core/src/encoding/rlp/kind/index.ts b/packages/core/src/encoding/rlp/kind/index.ts index ade123a55..3f332681e 100644 --- a/packages/core/src/encoding/rlp/kind/index.ts +++ b/packages/core/src/encoding/rlp/kind/index.ts @@ -2,14 +2,14 @@ import { BufferKind } from './bufferkind'; import { NumericKind } from './numerickind'; import { ScalarKind } from './scalarkind.abstract'; import { - HexBlobKind, + CompactFixedHexBlobKind, FixedHexBlobKind, - OptionalFixedHexBlobKind, - CompactFixedHexBlobKind + HexBlobKind, + OptionalFixedHexBlobKind } from './hexblobkinds'; /** - * RLP profile classes. + * RLP_CODER profile classes. */ export const RLPProfiles = { ScalarKind, diff --git a/packages/core/src/encoding/rlp/rlp.ts b/packages/core/src/encoding/rlp/rlp.ts index 625f08b57..8907ad9c5 100644 --- a/packages/core/src/encoding/rlp/rlp.ts +++ b/packages/core/src/encoding/rlp/rlp.ts @@ -1,4 +1,4 @@ -import { RLP as rlp } from '@ethereumjs/rlp'; +import { RLP } from '@ethereumjs/rlp'; import { type RLPInput, type RLPOutput, @@ -6,8 +6,8 @@ import { type RLPValidObject, type RLPValueType } from './types'; -import { RLP } from '.'; -import { assert, RLP as RLPError } from '@vechain/sdk-errors'; +import { RLPProfiles } from '.'; +import { assert, RLP_ERRORS } from '@vechain/sdk-errors'; import { assertIsArray } from '../../assertions'; /** @@ -16,7 +16,7 @@ import { assertIsArray } from '../../assertions'; * @returns The encoded data as a Buffer. */ function encode(data: RLPInput): Buffer { - const encodedData = rlp.encode(data); + const encodedData = RLP.encode(data); return Buffer.from(encodedData); } @@ -26,7 +26,7 @@ function encode(data: RLPInput): Buffer { * @returns The decoded data or null if decoding fails. */ function decode(encodedData: Buffer): RLPOutput { - return rlp.decode(encodedData); + return RLP.decode(encodedData); } /** @@ -36,27 +36,27 @@ function decode(encodedData: Buffer): RLPOutput { class Profiler { /** * Creates a new Profiler instance. - * @param profile - RLP profile for encoding/decoding structures. + * @param profile - RLP_CODER profile for encoding/decoding structures. */ constructor(readonly profile: RLPProfile) {} /** - * Encodes an object following the provided RLP profile. + * Encodes an object following the provided RLP_CODER profile. * @param data - Object to be encoded. * @returns - Encoded data as a Buffer. */ public encodeObject(data: RLPValidObject): Buffer { const packedData = _packData(data, this.profile, ''); - return Buffer.from(rlp.encode(packedData)); + return Buffer.from(RLP.encode(packedData)); } /** - * Decodes an object following the provided RLP profile. + * Decodes an object following the provided RLP_CODER profile. * @param encodedData - Data to be decoded. * @returns - Decoded data as RLPValueType. */ public decodeObject(encodedData: Buffer): RLPValueType { - const packedData = rlp.decode(encodedData); + const packedData = RLP.decode(encodedData); return _unpackData(packedData, this.profile, ''); } } @@ -67,7 +67,7 @@ class Profiler { * * @throws{InvalidRLPError} * @param obj - The object data to be packed. - * @param profile - RLP profile for encoding structures. + * @param profile - RLP_CODER profile for encoding structures. * @param context - Encoding context for error tracing. * @returns Packed data as RLPInput. * @@ -82,7 +82,7 @@ const _packData = ( const kind = profile.kind; // ScalarKind: direct encoding using the provided method. - if (kind instanceof RLP.ScalarKind) { + if (kind instanceof RLPProfiles.ScalarKind) { return kind.data(obj, context).encode(); } @@ -115,7 +115,7 @@ const _packData = ( * * @throws{InvalidRLPError} * @param packed - The packed data to be unpacked. - * @param profile - RLP profile for decoding structures. + * @param profile - RLP_CODER profile for decoding structures. * @param context - Decoding context for error tracing. * @returns Unpacked data as RLPValueType. * @@ -131,11 +131,11 @@ const _unpackData = ( const kind = profile.kind; // ScalarKind: Direct decoding using the provided method. - if (kind instanceof RLP.ScalarKind) { + if (kind instanceof RLPProfiles.ScalarKind) { assert( '_unpackData', Buffer.isBuffer(packed) || packed instanceof Uint8Array, - RLPError.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, 'Unpacking error: Expected data type is Buffer.', { context } ); @@ -152,7 +152,7 @@ const _unpackData = ( assert( '_unpackData', parts.length === kind.length, - RLPError.INVALID_RLP, + RLP_ERRORS.INVALID_RLP, `Unpacking error: Expected ${kind.length} items, but got ${parts.length}.`, { context } ); diff --git a/packages/core/src/utils/const/transaction.ts b/packages/core/src/utils/const/transaction.ts index 5fafdbf2a..61f476b6c 100644 --- a/packages/core/src/utils/const/transaction.ts +++ b/packages/core/src/utils/const/transaction.ts @@ -1,4 +1,4 @@ -import { RLP } from '../../encoding'; +import { RLP_CODER } from '../../encoding'; /** * Transaction gas constants @@ -43,20 +43,20 @@ const TRANSACTION_FIELDS = [ /** * Chain tag. It represents the id of the chain the transaction is sent to. */ - { name: 'chainTag', kind: new RLP.NumericKind(1) }, + { name: 'chainTag', kind: new RLP_CODER.NumericKind(1) }, /** * Block reference. It represents the last block of the chain the transaction is sent to. */ { name: 'blockRef', - kind: new RLP.CompactFixedHexBlobKind(8) + kind: new RLP_CODER.CompactFixedHexBlobKind(8) }, /** * Expiration. It represents the expiration date of the transaction. */ - { name: 'expiration', kind: new RLP.NumericKind(4) }, + { name: 'expiration', kind: new RLP_CODER.NumericKind(4) }, /** * Clauses of the transaction. They represent the actions to be executed by the transaction. @@ -65,9 +65,12 @@ const TRANSACTION_FIELDS = [ name: 'clauses', kind: { item: [ - { name: 'to', kind: new RLP.OptionalFixedHexBlobKind(20) }, - { name: 'value', kind: new RLP.NumericKind(32) }, - { name: 'data', kind: new RLP.HexBlobKind() } + { + name: 'to', + kind: new RLP_CODER.OptionalFixedHexBlobKind(20) + }, + { name: 'value', kind: new RLP_CODER.NumericKind(32) }, + { name: 'data', kind: new RLP_CODER.HexBlobKind() } ] } }, @@ -75,27 +78,27 @@ const TRANSACTION_FIELDS = [ /** * Gas price coef. It represents the gas price coefficient of the transaction. */ - { name: 'gasPriceCoef', kind: new RLP.NumericKind(1) }, + { name: 'gasPriceCoef', kind: new RLP_CODER.NumericKind(1) }, /** * Gas. It represents the gas limit of the transaction. */ - { name: 'gas', kind: new RLP.NumericKind(8) }, + { name: 'gas', kind: new RLP_CODER.NumericKind(8) }, /** * Depends on. It represents the hash of the transaction the current transaction depends on. */ - { name: 'dependsOn', kind: new RLP.OptionalFixedHexBlobKind(32) }, + { name: 'dependsOn', kind: new RLP_CODER.OptionalFixedHexBlobKind(32) }, /** * Nonce. It represents the nonce of the transaction. */ - { name: 'nonce', kind: new RLP.NumericKind(8) }, + { name: 'nonce', kind: new RLP_CODER.NumericKind(8) }, /** * Reserved. It represents the reserved field of the transaction. */ - { name: 'reserved', kind: { item: new RLP.BufferKind() } } + { name: 'reserved', kind: { item: new RLP_CODER.BufferKind() } } ]; /** @@ -104,7 +107,7 @@ const TRANSACTION_FIELDS = [ */ const TRANSACTION_FEATURES_KIND = { name: 'reserved.features', - kind: new RLP.NumericKind(4) + kind: new RLP_CODER.NumericKind(4) }; /** @@ -113,23 +116,23 @@ const TRANSACTION_FEATURES_KIND = { */ const TRANSACTION_SIGNATURE_KIND = { name: 'signature', - kind: new RLP.BufferKind() + kind: new RLP_CODER.BufferKind() }; /** - * RLP profiler for simple unsigned transactions + * RLP_CODER profiler for simple unsigned transactions * @internal */ -const UNSIGNED_TRANSACTION_RLP = new RLP.Profiler({ +const UNSIGNED_TRANSACTION_RLP = new RLP_CODER.Profiler({ name: 'tx', kind: TRANSACTION_FIELDS }); /** - * RLP profiler for simple signed transactions + * RLP_CODER profiler for simple signed transactions * @internal */ -const SIGNED_TRANSACTION_RLP = new RLP.Profiler({ +const SIGNED_TRANSACTION_RLP = new RLP_CODER.Profiler({ name: 'tx', // Add signature to the transaction fields diff --git a/packages/core/tests/rlp/rlp.fixture.ts b/packages/core/tests/rlp/rlp.fixture.ts index fbab86326..66b9658d0 100644 --- a/packages/core/tests/rlp/rlp.fixture.ts +++ b/packages/core/tests/rlp/rlp.fixture.ts @@ -1,6 +1,6 @@ -import { RLP, type RLPValidObject, type RLPProfile } from '../../src'; +import { RLP_CODER, type RLPProfile, type RLPValidObject } from '../../src'; -/* Simple RLP encode */ +/* Simple RLP_CODER encode */ const encodeTestCases = [ { input: [1, 2, 3, [4, 5]], @@ -11,7 +11,7 @@ const encodeTestCases = [ { input: [], expected: 'c0', description: 'empty array' } ]; -/* Simple RLP decode */ +/* Simple RLP_CODER decode */ const decodeTestCases = [ { input: '2a', @@ -24,55 +24,55 @@ const decodeTestCases = [ /* NumericKind encode */ const numericKindEncodeTestCases = [ { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0x0', expected: '', description: 'zero hex string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0x123', expected: '0123', description: 'hex string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0', expected: '', description: 'zero number string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '100', expected: '64', description: 'number string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: 0, expected: '', description: 'zero number' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: 0x123, expected: '0123', description: 'number in hex format' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: 12524, expected: '30ec', description: 'number non hex format' }, { - kind: new RLP.NumericKind(1), + kind: new RLP_CODER.NumericKind(1), data: '5', expected: '05', description: 'number in hex format' }, { - kind: new RLP.NumericKind(1), + kind: new RLP_CODER.NumericKind(1), data: 255, expected: 'ff', description: 'number non hex format' @@ -81,37 +81,37 @@ const numericKindEncodeTestCases = [ const invalidNumericKindEncodeTestCases = [ { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0x123z', description: 'invalid hex string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: {}, description: 'invalid object' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0x', description: 'invalid hex string' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: -1, description: 'negative number' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: '0x12345678123456780', description: 'number overflow' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: 2 ** 64, description: 'number overflow' }, { - kind: new RLP.NumericKind(1), + kind: new RLP_CODER.NumericKind(1), data: 256, description: 'number overflow' } @@ -120,25 +120,25 @@ const invalidNumericKindEncodeTestCases = [ /* Numeric kind decode tests */ const numericKindDecodeTestCases = [ { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: Buffer.alloc(0), description: 'empty buffer', expected: 0 }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: Buffer.from([1, 2, 3]), description: 'buffer with data', expected: 0x010203 }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]), description: 'buffer with data', expected: '0x102030405060708' }, { - kind: new RLP.NumericKind(1), + kind: new RLP_CODER.NumericKind(1), data: Buffer.from('ff', 'hex'), description: 'buffer with data', expected: 255 @@ -147,7 +147,7 @@ const numericKindDecodeTestCases = [ const invalidBufferKindDecodeTestCases = [ { - kind: new RLP.BufferKind(), + kind: new RLP_CODER.BufferKind(), data: 42, description: 'invalid data' } @@ -155,12 +155,12 @@ const invalidBufferKindDecodeTestCases = [ const invalidNumericKindDecodeTestCases = [ { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: Buffer.alloc(9, 1), description: 'buffer exceeds max bytes' }, { - kind: new RLP.NumericKind(8), + kind: new RLP_CODER.NumericKind(8), data: Buffer.from([0, 1]), description: 'buffer with leading zero' } @@ -169,7 +169,7 @@ const invalidNumericKindDecodeTestCases = [ /* Hex Blob Kind encode tests */ const hexBlobKindEncodeTestCases = [ { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: '0x010203', expected: '010203', description: 'hex string' @@ -178,17 +178,17 @@ const hexBlobKindEncodeTestCases = [ const invalidHexBlobKindEncodeTestCases = [ { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: '0x123z', description: 'invalid hex string' }, { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: {}, description: 'invalid object' }, { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: '0x123', description: 'invalid hex string' } @@ -197,7 +197,7 @@ const invalidHexBlobKindEncodeTestCases = [ /* Fixed Hex Blob Kind encode tests */ const fixedHexBlobKindEncodeTestCases = [ { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: '0x01', expected: '01', description: 'hex string' @@ -206,22 +206,22 @@ const fixedHexBlobKindEncodeTestCases = [ const invalidFixedHexBlobEncodeTestCases = [ { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: '0x123z', description: 'invalid hex string' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: {}, description: 'invalid data type' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: '0x123', description: 'invalid hex string' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: '0x012345', description: 'overflow hex string' } @@ -230,19 +230,19 @@ const invalidFixedHexBlobEncodeTestCases = [ /* Hex Blob Kind decode tests */ const hexBlobKindDecodeTestCases = [ { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: Buffer.alloc(0), description: 'empty buffer', expected: '0x' }, { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: Buffer.from([1, 2, 3]), description: 'buffer with data', expected: '0x010203' }, { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: Buffer.from([1, 2, 3, 4, 5]), description: 'buffer with data', expected: '0x0102030405' @@ -251,7 +251,7 @@ const hexBlobKindDecodeTestCases = [ const invalidHexBlobKindDecodeTestCases = [ { - kind: new RLP.HexBlobKind(), + kind: new RLP_CODER.HexBlobKind(), data: 42, description: 'invalid data' } @@ -260,13 +260,13 @@ const invalidHexBlobKindDecodeTestCases = [ /* Fixed Hex Blob Kind decode tests */ const fixedHexBlobKindDecodeTestCases = [ { - kind: new RLP.FixedHexBlobKind(3), + kind: new RLP_CODER.FixedHexBlobKind(3), data: Buffer.from([1, 2, 3]), description: 'buffer with data', expected: '0x010203' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: Buffer.from([1]), description: 'buffer with data', expected: '0x01' @@ -275,17 +275,17 @@ const fixedHexBlobKindDecodeTestCases = [ const invalidFixedBlobKindDecodeTestCases = [ { - kind: new RLP.FixedHexBlobKind(3), + kind: new RLP_CODER.FixedHexBlobKind(3), data: Buffer.from([1, 2]), description: 'buffer with data' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: Buffer.from([1, 2]), description: 'buffer with data' }, { - kind: new RLP.FixedHexBlobKind(1), + kind: new RLP_CODER.FixedHexBlobKind(1), data: '0x123', description: 'invalid data buffer' } @@ -293,13 +293,13 @@ const invalidFixedBlobKindDecodeTestCases = [ const compactFixedHexBlobKindEncodeTestCases = [ { - kind: new RLP.CompactFixedHexBlobKind(4), + kind: new RLP_CODER.CompactFixedHexBlobKind(4), data: '0x00112233', description: 'buffer with data', expected: '112233' }, { - kind: new RLP.CompactFixedHexBlobKind(1), + kind: new RLP_CODER.CompactFixedHexBlobKind(1), data: '0x00', description: 'buffer with data', expected: '' @@ -308,20 +308,20 @@ const compactFixedHexBlobKindEncodeTestCases = [ const compactFixedHexBlobKindDecodeTestCases = [ { - kind: new RLP.CompactFixedHexBlobKind(4), + kind: new RLP_CODER.CompactFixedHexBlobKind(4), data: Buffer.from([1, 2, 3]), description: 'buffer with data', expected: '0x00010203' }, { - kind: new RLP.CompactFixedHexBlobKind(1), + kind: new RLP_CODER.CompactFixedHexBlobKind(1), data: Buffer.from([1]), description: 'buffer with data', expected: '0x01' } ]; -/* ------ RLP Profile Objects & Data ------- */ +/* ------ RLP_CODER Profile Objects & Data ------- */ const [bufferProfile, bufferData, invalidBufferData]: [ RLPProfile, RLPValidObject, @@ -330,8 +330,8 @@ const [bufferProfile, bufferData, invalidBufferData]: [ { name: '', kind: [ - { name: 'foo', kind: new RLP.BufferKind() }, - { name: 'bar', kind: new RLP.BufferKind() } + { name: 'foo', kind: new RLP_CODER.BufferKind() }, + { name: 'bar', kind: new RLP_CODER.BufferKind() } ] }, { @@ -348,25 +348,25 @@ const [numericProfile, numericData]: [RLPProfile, RLPValidObject] = [ { name: '', kind: [ - { name: 'foo', kind: new RLP.NumericKind() }, - { name: 'bar', kind: new RLP.NumericKind() }, + { name: 'foo', kind: new RLP_CODER.NumericKind() }, + { name: 'bar', kind: new RLP_CODER.NumericKind() }, { name: 'baz', kind: { item: [ - { name: 'x', kind: new RLP.NumericKind() }, - { name: 'y', kind: new RLP.NumericKind() }, + { name: 'x', kind: new RLP_CODER.NumericKind() }, + { name: 'y', kind: new RLP_CODER.NumericKind() }, { name: 'z', kind: { item: [ { name: 'a', - kind: new RLP.NumericKind() + kind: new RLP_CODER.NumericKind() }, { name: 'b', - kind: new RLP.NumericKind() + kind: new RLP_CODER.NumericKind() } ] } @@ -420,14 +420,14 @@ const [ { name: '', kind: [ - { name: 'foo', kind: new RLP.NumericKind(1) }, - { name: 'bar', kind: new RLP.NumericKind() }, + { name: 'foo', kind: new RLP_CODER.NumericKind(1) }, + { name: 'bar', kind: new RLP_CODER.NumericKind() }, { name: 'baz', kind: { item: [ - { name: 'x', kind: new RLP.NumericKind() }, - { name: 'y', kind: new RLP.NumericKind() } + { name: 'x', kind: new RLP_CODER.NumericKind() }, + { name: 'y', kind: new RLP_CODER.NumericKind() } ] } } @@ -472,8 +472,8 @@ const [hexBlobProfile, hexBlobData, hexBlobDataWithInvalidHex]: [ { name: '', kind: [ - { name: 'foo', kind: new RLP.HexBlobKind() }, - { name: 'bar', kind: new RLP.HexBlobKind() } + { name: 'foo', kind: new RLP_CODER.HexBlobKind() }, + { name: 'bar', kind: new RLP_CODER.HexBlobKind() } ] }, { @@ -490,8 +490,8 @@ const [fixedHexBlobProfile, fixedHexBlobData]: [RLPProfile, RLPValidObject] = [ { name: '', kind: [ - { name: 'foo', kind: new RLP.FixedHexBlobKind(1) }, - { name: 'bar', kind: new RLP.FixedHexBlobKind(3) } + { name: 'foo', kind: new RLP_CODER.FixedHexBlobKind(1) }, + { name: 'bar', kind: new RLP_CODER.FixedHexBlobKind(3) } ] }, { @@ -518,8 +518,8 @@ const [ { name: '', kind: [ - { name: 'foo', kind: new RLP.OptionalFixedHexBlobKind(1) }, - { name: 'bar', kind: new RLP.OptionalFixedHexBlobKind(3) } + { name: 'foo', kind: new RLP_CODER.OptionalFixedHexBlobKind(1) }, + { name: 'bar', kind: new RLP_CODER.OptionalFixedHexBlobKind(3) } ] }, { @@ -551,8 +551,8 @@ const [compactFixedHexBlobProfile, compactFixedHexBlobData]: [ { name: '', kind: [ - { name: 'foo', kind: new RLP.CompactFixedHexBlobKind(1) }, - { name: 'bar', kind: new RLP.CompactFixedHexBlobKind(3) } + { name: 'foo', kind: new RLP_CODER.CompactFixedHexBlobKind(1) }, + { name: 'bar', kind: new RLP_CODER.CompactFixedHexBlobKind(3) } ] }, { @@ -565,14 +565,14 @@ const [mixedKindProfile1, mixedKindData1]: [RLPProfile, RLPValidObject] = [ { name: '', kind: [ - { name: 'foo', kind: new RLP.NumericKind() }, - { name: 'bar', kind: new RLP.FixedHexBlobKind(4) }, + { name: 'foo', kind: new RLP_CODER.NumericKind() }, + { name: 'bar', kind: new RLP_CODER.FixedHexBlobKind(4) }, { name: 'baz', kind: { item: [ - { name: 'x', kind: new RLP.HexBlobKind() }, - { name: 'y', kind: new RLP.NumericKind() } + { name: 'x', kind: new RLP_CODER.HexBlobKind() }, + { name: 'y', kind: new RLP_CODER.NumericKind() } ] } } @@ -592,26 +592,32 @@ const [mixedKindProfile2, mixedKindData2]: [RLPProfile, RLPValidObject] = [ { name: 'tx', kind: [ - { name: 'chainTag', kind: new RLP.NumericKind(1) }, - { name: 'blockRef', kind: new RLP.CompactFixedHexBlobKind(8) }, - { name: 'expiration', kind: new RLP.NumericKind(4) }, + { name: 'chainTag', kind: new RLP_CODER.NumericKind(1) }, + { + name: 'blockRef', + kind: new RLP_CODER.CompactFixedHexBlobKind(8) + }, + { name: 'expiration', kind: new RLP_CODER.NumericKind(4) }, { name: 'clauses', kind: { item: [ { name: 'to', - kind: new RLP.OptionalFixedHexBlobKind(20) + kind: new RLP_CODER.OptionalFixedHexBlobKind(20) }, - { name: 'value', kind: new RLP.NumericKind(32) }, - { name: 'data', kind: new RLP.HexBlobKind() } + { name: 'value', kind: new RLP_CODER.NumericKind(32) }, + { name: 'data', kind: new RLP_CODER.HexBlobKind() } ] } }, - { name: 'gasPriceCoef', kind: new RLP.NumericKind(1) }, - { name: 'gas', kind: new RLP.NumericKind(8) }, - { name: 'dependsOn', kind: new RLP.OptionalFixedHexBlobKind(32) }, - { name: 'nonce', kind: new RLP.NumericKind(8) } + { name: 'gasPriceCoef', kind: new RLP_CODER.NumericKind(1) }, + { name: 'gas', kind: new RLP_CODER.NumericKind(8) }, + { + name: 'dependsOn', + kind: new RLP_CODER.OptionalFixedHexBlobKind(32) + }, + { name: 'nonce', kind: new RLP_CODER.NumericKind(8) } ] }, { @@ -637,7 +643,7 @@ const [mixedKindProfile2, mixedKindData2]: [RLPProfile, RLPValidObject] = [ } ]; -/* ------ RLP Profile Encode Tests ------- */ +/* ------ RLP_CODER Profile Encode Tests ------- */ const encodeNumericProfileTestCases = [ { profile: numericProfile, @@ -767,7 +773,7 @@ const invalidEncodeObjectTestCases = [ } ]; -/* ------ RLP Profile Decode Tests ------- */ +/* ------ RLP_CODER Profile Decode Tests ------- */ const decodeBufferProfileTestCases = [ { profile: bufferProfile, diff --git a/packages/core/tests/rlp/rlp.unit.test.ts b/packages/core/tests/rlp/rlp.unit.test.ts index 952d87048..c73b0618d 100644 --- a/packages/core/tests/rlp/rlp.unit.test.ts +++ b/packages/core/tests/rlp/rlp.unit.test.ts @@ -1,15 +1,21 @@ import { describe, expect, test } from '@jest/globals'; -import { Hex, RLP } from '../../src'; +import { Hex, RLP_CODER } from '../../src'; import { + compactFixedHexBlobKindDecodeTestCases, + compactFixedHexBlobKindEncodeTestCases, decodeBufferProfileTestCases, + decodeCompactFixedHexBlobProfileTestCases, decodeHexBlobProfileTestCases, + decodeMixedKindProfileTestCases, decodeNumericProfileTestCases, decodeTestCases, encodeBufferProfileTestCases, + encodeCompactFixedHexBlobProfileTestCases, encodeFixedHexBlobProfileTestCases, encodeHexBlobProfileTestCases, - encodeOptionalFixedHexBlobProfileTestCases, + encodeMixedKindProfileTestCases, encodeNumericProfileTestCases, + encodeOptionalFixedHexBlobProfileTestCases, encodeTestCases, fixedHexBlobKindDecodeTestCases, fixedHexBlobKindEncodeTestCases, @@ -25,35 +31,31 @@ import { invalidNumericKindDecodeTestCases, invalidNumericKindEncodeTestCases, numericKindDecodeTestCases, - numericKindEncodeTestCases, - encodeCompactFixedHexBlobProfileTestCases, - decodeCompactFixedHexBlobProfileTestCases, - encodeMixedKindProfileTestCases, - decodeMixedKindProfileTestCases, - compactFixedHexBlobKindEncodeTestCases, - compactFixedHexBlobKindDecodeTestCases + numericKindEncodeTestCases } from './rlp.fixture'; import { InvalidRLPError } from '@vechain/sdk-errors'; /** - * Test suite for RLP encoding/decoding functionality + * Test suite for RLP_CODER encoding/decoding functionality * @group unit/rlp */ describe('RLP', () => { - // Testing RLP encoding functionality + // Testing RLP_CODER encoding functionality describe('encode', () => { encodeTestCases.forEach(({ input, expected, description }) => { test(description, () => { - expect(Hex.of(RLP.encode(input))).toEqual(expected); + expect(Hex.of(RLP_CODER.encode(input))).toEqual(expected); }); }); }); - // Testing RLP decoding functionality + // Testing RLP_CODER decoding functionality describe('decode', () => { decodeTestCases.forEach(({ input, expected, description }) => { test(description, () => { - expect(RLP.decode(Buffer.from(input, 'hex'))).toEqual(expected); + expect(RLP_CODER.decode(Buffer.from(input, 'hex'))).toEqual( + expected + ); }); }); }); @@ -272,7 +274,7 @@ describe('RLP', () => { encodeBufferProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -287,7 +289,7 @@ describe('RLP', () => { encodeNumericProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -302,7 +304,7 @@ describe('RLP', () => { encodeHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -316,7 +318,7 @@ describe('RLP', () => { encodeFixedHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -331,7 +333,7 @@ describe('RLP', () => { encodeOptionalFixedHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -346,7 +348,7 @@ describe('RLP', () => { encodeCompactFixedHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -361,7 +363,7 @@ describe('RLP', () => { encodeMixedKindProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const encoded = rlp.encodeObject(data); @@ -376,7 +378,7 @@ describe('RLP', () => { invalidEncodeObjectTestCases.forEach( ({ profile, data, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); expect(() => { rlp.encodeObject(data); @@ -396,7 +398,7 @@ describe('RLP', () => { decodeBufferProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const decoded = rlp.decodeObject(data); @@ -411,7 +413,7 @@ describe('RLP', () => { decodeNumericProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const decoded = rlp.decodeObject(data); @@ -426,7 +428,7 @@ describe('RLP', () => { decodeHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const decoded = rlp.decodeObject(data); @@ -441,7 +443,7 @@ describe('RLP', () => { decodeCompactFixedHexBlobProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const decoded = rlp.decodeObject(data); @@ -456,7 +458,7 @@ describe('RLP', () => { decodeMixedKindProfileTestCases.forEach( ({ profile, data, expected, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); const decoded = rlp.decodeObject(data); @@ -471,7 +473,7 @@ describe('RLP', () => { invalidDecodeObjectTestCases.forEach( ({ profile, data, description }) => { test(description, () => { - const rlp = new RLP.Profiler(profile); + const rlp = new RLP_CODER.Profiler(profile); expect(() => { rlp.decodeObject(data); diff --git a/packages/errors/package.json b/packages/errors/package.json index c04489224..91b737568 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-errors", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "This module is dedicated to managing and customizing errors within the SDK", "author": "vechain Foundation", "license": "MIT", diff --git a/packages/errors/src/model/core/rlp.ts b/packages/errors/src/model/core/rlp.ts index d1f8daedf..bb6e65c54 100644 --- a/packages/errors/src/model/core/rlp.ts +++ b/packages/errors/src/model/core/rlp.ts @@ -1,21 +1,25 @@ import { ErrorBase } from '../base'; /** - * Invalid RLP error data interface. + * Invalid RLP_ERRORS error data interface. */ interface InvalidRLPErrorData { context: string; } /** - * Invalid RLP error to be thrown when an invalid RLP is detected. + * Invalid RLP_ERRORS error to be thrown when an invalid RLP_ERRORS is detected. */ -class InvalidRLPError extends ErrorBase {} +class InvalidRLPError extends ErrorBase< + RLP_ERRORS.INVALID_RLP, + InvalidRLPErrorData +> {} /** * Errors enum. */ -enum RLP { +enum RLP_ERRORS { INVALID_RLP = 'INVALID_RLP' } -export { InvalidRLPError, type InvalidRLPErrorData, RLP }; + +export { InvalidRLPError, type InvalidRLPErrorData, RLP_ERRORS }; diff --git a/packages/errors/src/types/errorTypes.ts b/packages/errors/src/types/errorTypes.ts index 92a1b0005..e20e6b6ad 100644 --- a/packages/errors/src/types/errorTypes.ts +++ b/packages/errors/src/types/errorTypes.ts @@ -6,6 +6,8 @@ import { CertificateInvalidSignatureFormatError, CertificateInvalidSignerError, CertificateNotSignedError, + CONTRACT, + ContractDeploymentFailedError, ContractInterfaceError, DATA, EIP1193, @@ -55,7 +57,7 @@ import { POLL_ERROR, type PollErrorData, PollExecutionError, - RLP, + RLP_ERRORS, SECP256K1, TRANSACTION, TransactionAlreadySignedError, @@ -64,7 +66,6 @@ import { TransactionMissingPrivateKeyError, TransactionNotSignedError } from '../model'; -import { CONTRACT, ContractDeploymentFailedError } from '../model'; /** * @note: REGISTER YOUR NEW FANCY ERRORS BELOW! @@ -88,7 +89,7 @@ type ErrorCode = | BLOOM | CERTIFICATE | ABI - | RLP + | RLP_ERRORS | DATA | TRANSACTION | HTTP_CLIENT @@ -105,8 +106,8 @@ type ErrorCode = * @param ErrorCodeT - The error code type from the error types enum. */ type DataType = - // RLP - ErrorCodeT extends RLP.INVALID_RLP + // RLP_ERRORS + ErrorCodeT extends RLP_ERRORS.INVALID_RLP ? InvalidRLPErrorData : // HTTP_CLIENT ErrorCodeT extends HTTP_CLIENT.INVALID_HTTP_REQUEST @@ -146,7 +147,7 @@ const ERROR_CODES = { BLOOM, CERTIFICATE, ABI, - RLP, + RLP: RLP_ERRORS, DATA, TRANSACTION, HTTP_CLIENT, @@ -219,8 +220,8 @@ type ErrorType = ? InvalidAbiFunctionError : ErrorCodeT extends ABI.CONTRACT_INTERFACE_ERROR ? ContractInterfaceError - : // RLP - ErrorCodeT extends RLP.INVALID_RLP + : // RLP_ERRORS + ErrorCodeT extends RLP_ERRORS.INVALID_RLP ? InvalidRLPError : // DATA ErrorCodeT extends DATA.INVALID_DATA_TYPE @@ -325,8 +326,8 @@ const ErrorClassMap = new Map< [ABI.INVALID_FUNCTION, InvalidAbiFunctionError], [ABI.CONTRACT_INTERFACE_ERROR, ContractInterfaceError], - // RLP - [RLP.INVALID_RLP, InvalidRLPError], + // RLP_ERRORS + [RLP_ERRORS.INVALID_RLP, InvalidRLPError], // DATA [DATA.INVALID_DATA_TYPE, InvalidDataTypeError], diff --git a/packages/errors/tests/fixture.ts b/packages/errors/tests/fixture.ts index 75baae857..47869a253 100644 --- a/packages/errors/tests/fixture.ts +++ b/packages/errors/tests/fixture.ts @@ -2,13 +2,24 @@ import { ABI, ADDRESS, BLOOM, + CERTIFICATE, + CertificateInvalidSignatureFormatError, + CertificateInvalidSignerError, + CertificateNotSignedError, + CONTRACT, + ContractDeploymentFailedError, + ContractInterfaceError, DATA, + EIP1193, + EIP1193ChainDisconnected, + EIP1193Disconnected, + EIP1193Unauthorized, + EIP1193UnsupportedMethod, + EIP1193UserRejectedRequest, + FUNCTION, HDNODE, - RLP, - KEYSTORE, - SECP256K1, - TRANSACTION, - CERTIFICATE, + HTTP_CLIENT, + HTTPClientError, InvalidAbiDataToDecodeError, InvalidAbiDataToEncodeError, InvalidAbiEventError, @@ -19,6 +30,7 @@ import { InvalidDataReturnTypeError, InvalidDataTypeError, InvalidHDNodeChaincodeError, + InvalidHDNodeDerivationPathError, InvalidHDNodeMnemonicsError, InvalidHDNodePrivateKeyError, InvalidHDNodePublicKeyError, @@ -30,35 +42,23 @@ import { InvalidSecp256k1PrivateKeyError, InvalidSecp256k1SignatureError, InvalidSecp256k1SignatureRecoveryError, + JSONRPC, + JSONRPCDefaultError, + JSONRPCInternalError, + JSONRPCInvalidParams, + JSONRPCInvalidRequest, + KEYSTORE, + NotImplementedError, + POLL_ERROR, + PollExecutionError, + RLP_ERRORS, + SECP256K1, + TRANSACTION, TransactionAlreadySignedError, TransactionBodyError, TransactionDelegationError, - TransactionNotSignedError, - InvalidHDNodeDerivationPathError, - CertificateNotSignedError, - CertificateInvalidSignatureFormatError, - CertificateInvalidSignerError, - ContractInterfaceError, - HTTP_CLIENT, - HTTPClientError, - POLL_ERROR, - PollExecutionError, - FUNCTION, - NotImplementedError, - EIP1193, - EIP1193UserRejectedRequest, - EIP1193Disconnected, - EIP1193Unauthorized, - EIP1193UnsupportedMethod, - EIP1193ChainDisconnected, - JSONRPC, - JSONRPCInvalidRequest, - JSONRPCInvalidParams, - JSONRPCInternalError, - JSONRPCDefaultError, - CONTRACT, - ContractDeploymentFailedError, - TransactionMissingPrivateKeyError + TransactionMissingPrivateKeyError, + TransactionNotSignedError } from '../src'; /** @@ -198,7 +198,7 @@ const ErrorsCodeAndClassesMapsFixture = [ name: 'Rlp', elements: [ { - errorCode: RLP.INVALID_RLP, + errorCode: RLP_ERRORS.INVALID_RLP, classExpected: InvalidRLPError } ] diff --git a/packages/errors/tests/utils/error-builder/error-handling.unit.test.ts b/packages/errors/tests/utils/error-builder/error-handling.unit.test.ts index 089c30e0e..0a251e252 100644 --- a/packages/errors/tests/utils/error-builder/error-handling.unit.test.ts +++ b/packages/errors/tests/utils/error-builder/error-handling.unit.test.ts @@ -50,7 +50,7 @@ describe('Error handler test', () => { * Verify that the error with additional data thrown is an instance of the expected error InvalidRLPError and * that the additional data has the expected fields */ - test('Throw Invalid RLP Exception with data', () => { + test('Throw Invalid RLP_ERRORS Exception with data', () => { try { throw buildError( 'test', diff --git a/packages/ethers-adapter/package.json b/packages/ethers-adapter/package.json index b6b2927c7..478f24b1c 100644 --- a/packages/ethers-adapter/package.json +++ b/packages/ethers-adapter/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-ethers-adapter", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "This module serves as a crucial bridge between the standard Ethereum tooling provided by Hardhat and the unique features of the vechain thor blockchain", "author": "vechain Foundation", "license": "MIT", @@ -34,8 +34,8 @@ "test": "rm -rf ./coverage && jest --coverage --coverageDirectory=coverage --group=integration --group=unit" }, "dependencies": { - "@vechain/sdk-core": "1.0.0-beta.8", - "@vechain/sdk-network": "1.0.0-beta.8" + "@vechain/sdk-core": "1.0.0-beta.9", + "@vechain/sdk-network": "1.0.0-beta.9" }, "devDependencies": { "@nomicfoundation/hardhat-ethers": "^3.0.6" diff --git a/packages/hardhat-plugin/package.json b/packages/hardhat-plugin/package.json index 9bba7b9f2..833a6900a 100644 --- a/packages/hardhat-plugin/package.json +++ b/packages/hardhat-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-hardhat-plugin", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "This module allows to create smart contracts and interact with them using the vechain SDK and Hardhat", "author": "vechain Foundation", "license": "MIT", @@ -34,8 +34,8 @@ "test": "rm -rf ./coverage && jest --coverage --coverageDirectory=coverage --group=integration --group=unit" }, "dependencies": { - "@vechain/sdk-network": "1.0.0-beta.8", - "@vechain/sdk-ethers-adapter": "1.0.0-beta.8" + "@vechain/sdk-network": "1.0.0-beta.9", + "@vechain/sdk-ethers-adapter": "1.0.0-beta.9" }, "devDependencies": { "@nomicfoundation/hardhat-ethers": "^3.0.6" diff --git a/packages/logging/package.json b/packages/logging/package.json index 94056202a..95d669616 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-logging", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "This module provides functionality to logging data for vechain-sdk", "author": "vechain Foundation", "license": "MIT", @@ -32,6 +32,6 @@ "test": "rm -rf ./coverage && jest --coverage --coverageDirectory=coverage --group=integration --group=unit" }, "dependencies": { - "@vechain/sdk-errors": "1.0.0-beta.8" + "@vechain/sdk-errors": "1.0.0-beta.9" } } \ No newline at end of file diff --git a/packages/network/package.json b/packages/network/package.json index 33b0885c8..5806829f0 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-network", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "This module allows to connect you seamlessly to the VeChainThor blockchain", "author": "vechain Foundation", "license": "MIT", @@ -39,9 +39,9 @@ }, "dependencies": { "@types/ws": "^8.5.10", - "@vechain/sdk-core": "1.0.0-beta.8", - "@vechain/sdk-errors": "1.0.0-beta.8", - "@vechain/sdk-logging": "1.0.0-beta.8", + "@vechain/sdk-core": "1.0.0-beta.9", + "@vechain/sdk-errors": "1.0.0-beta.9", + "@vechain/sdk-logging": "1.0.0-beta.9", "axios": "^1.7.2" } } \ No newline at end of file diff --git a/packages/rpc-proxy/package.json b/packages/rpc-proxy/package.json index 94f413a59..da291cb07 100644 --- a/packages/rpc-proxy/package.json +++ b/packages/rpc-proxy/package.json @@ -1,6 +1,6 @@ { "name": "@vechain/sdk-rpc-proxy", - "version": "1.0.0-beta.8", + "version": "1.0.0-beta.9", "description": "Proxy Thor's RESTful API to Eth JSON-RPC", "author": "vechain Foundation", "license": "MIT", @@ -31,8 +31,8 @@ "start": "yarn build && node dist/index.js" }, "dependencies": { - "@vechain/sdk-network": "1.0.0-beta.8", - "@vechain/sdk-logging": "1.0.0-beta.8", + "@vechain/sdk-network": "1.0.0-beta.9", + "@vechain/sdk-logging": "1.0.0-beta.9", "cors": "^2.8.5", "express": "^4.19.2" },