From 4507a4519924bef3e5ea43a64dd4b32174860942 Mon Sep 17 00:00:00 2001 From: jxom Date: Fri, 27 Sep 2024 15:28:00 +1000 Subject: [PATCH] docs: up --- pnpm-lock.yaml | 161 +++++++++++++++------ src/Errors.test.ts | 1 - src/Errors.ts | 2 - src/internal/AbiParameters/errors.ts | 64 +++++++- src/internal/AccessList/errors.ts | 1 + src/internal/Address/errors.ts | 13 ++ src/internal/Blobs/errors.ts | 5 + src/internal/Bytes/errors.ts | 56 +++++++ src/internal/Hex/errors.ts | 90 ++++++++++++ src/internal/Log/errors.ts | 31 ---- src/internal/Promise/errors.ts | 1 + src/internal/Provider/errors.ts | 1 + src/internal/PublicKey/errors.ts | 18 +++ src/internal/RpcResponse/errors.ts | 13 ++ src/internal/RpcTransport/errors.ts | 2 + src/internal/Signature/errors.ts | 6 + src/internal/Siwe/errors.ts | 21 +++ src/internal/TransactionEnvelope/errors.ts | 107 ++++++++++++++ src/internal/TypedData/errors.ts | 2 + src/internal/Value/errors.ts | 11 ++ src/internal/WebAuthnP256/errors.ts | 2 + 21 files changed, 525 insertions(+), 83 deletions(-) delete mode 100644 src/internal/Log/errors.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18237cb3..3e798f39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -174,8 +174,8 @@ importers: specifier: ^18.2.0 version: 18.3.1(react@18.3.1) vocs: - specifier: 1.0.0-alpha.59 - version: 1.0.0-alpha.59(@types/node@22.5.4)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@4.20.0)(terser@5.31.5)(typescript@5.5.4) + specifier: 1.0.0-alpha.60 + version: 1.0.0-alpha.60(@types/node@22.5.4)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@4.20.0)(terser@5.31.5)(typescript@5.5.4) src: dependencies: @@ -1609,17 +1609,29 @@ packages: '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} - '@shikijs/core@1.12.1': - resolution: {integrity: sha512-biCz/mnkMktImI6hMfMX3H9kOeqsInxWEyCHbSlL8C/2TR1FqfmGxTLRNwYCKsyCyxWLbB8rEqXRVZuyxuLFmA==} + '@shikijs/core@1.20.0': + resolution: {integrity: sha512-KlO3iE0THzSdYkzDFugt8SHe6FR3qNYTkmpbdW1d6xo8juQkMjybxAw/cBi2npL2eb2F4PbbnSs5Z9tDusfvyg==} - '@shikijs/rehype@1.12.1': - resolution: {integrity: sha512-AZLC80TIiRWFwPbSqdwykeSeMjQwYWlkX8yfI7T4nan0qgWfvv/oP7C767JQ8USudEylbe5KzBdE8Ao2sHsidA==} + '@shikijs/engine-javascript@1.20.0': + resolution: {integrity: sha512-ZUMo758uduM0Tfgzi/kd+0IKMbNdumCxxWjY36uf1DIs2Qyg9HIq3vA1Wfa/vc6HE7tHWFpANRi3mv7UzJ68MQ==} - '@shikijs/transformers@1.12.1': - resolution: {integrity: sha512-zOpj/S2thBvnJV4Ty3EE8aRs/VqCbV+lgtEYeBRkPxTW22uLADEIZq0qjt5W2Rfy2KSu29e73nRyzp4PefjUTg==} + '@shikijs/engine-oniguruma@1.20.0': + resolution: {integrity: sha512-MQ40WkVTZk7by33ces4PGK6XNFSo6PYvKTSAr2kTWdRNhFmOcnaX+1XzvFwB26eySXR7U74t91czZ1qJkEgxTA==} - '@shikijs/twoslash@1.12.1': - resolution: {integrity: sha512-k4D6sC9p9GksbHa4RnB1VkQIZtQ+L7nQMqi/YAxEgTKZF5v7IW6dHak0Z7bvZXrfhle36NIqWMJXz5xDexupvw==} + '@shikijs/rehype@1.20.0': + resolution: {integrity: sha512-HJrk74r1Tk+mN/sXYFiqVNnYsvrrr/CDD3wz42iNSbqxLLYeHdQ8o+9oWn7la/f6F2VC2Alw4YKOVUhzsShEpQ==} + + '@shikijs/transformers@1.20.0': + resolution: {integrity: sha512-TNS5KAErbNIOm1QqabuVaU77NOs5xWfpjpnqME059SA8yddr3mN5ZNAeCI+4QAAnNqZd8RKXjp+9hw66f5ak/A==} + + '@shikijs/twoslash@1.20.0': + resolution: {integrity: sha512-NGaZgluqyo/P8r35/y82lhGtHjQaDlFTpmRzl/T+aNMshatcOsTvMN9uVWSNy83di1VGTxhH4ruX0xUsOAgdtg==} + + '@shikijs/types@1.20.0': + resolution: {integrity: sha512-y+EaDvU2K6/GaXOKXxJaGnr1XtmZMF7MfS0pSEDdxEq66gCtKsLwQvVwoQFdp7R7dLlNAro3ijEE19sMZ0pzqg==} + + '@shikijs/vscode-textmate@9.2.2': + resolution: {integrity: sha512-TMp15K+GGYrWlZM8+Lnj9EaHEFmOen0WJBrfa17hF7taDOYthuPPV0GWzfd/9iMij0akS/8Yw2ikquH7uVi/fg==} '@sinclair/typebox@0.27.8': resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} @@ -1830,9 +1842,6 @@ packages: resolution: {integrity: sha512-RnlSOPh14QbopGCApgkSx5UBgGda5MX1cHqp2fsqfiDyCwGL/m1jaeB9fzu7didVS81LQqGZZuxFBcg8YU8EVw==} hasBin: true - '@typescript/vfs@1.5.0': - resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==} - '@typescript/vfs@1.6.0': resolution: {integrity: sha512-hvJUjNVeBMp77qPINuUvYXj4FyWeeMMKZkxEATEU3hqBAQ7qdTBCUFT7Sp0Zu0faeEtFf+ldXxMEDr/bk73ISg==} peerDependencies: @@ -3023,6 +3032,9 @@ packages: hast-util-to-estree@3.1.0: resolution: {integrity: sha512-lfX5g6hqVh9kjS/B9E2gSkvHH4SZNiQFiqWS0x9fENzEl+8W12RqdRxX6d/Cwxi30tPQs3bIO+aolQJNp1bIyw==} + hast-util-to-html@9.0.3: + resolution: {integrity: sha512-M17uBDzMJ9RPCqLMO92gNNUDuBSq10a25SDBI08iCCxmorf4Yy6sYHK57n9WAbRAAaU+DuR4W6GN9K4DFZesYg==} + hast-util-to-jsx-runtime@2.3.0: resolution: {integrity: sha512-H/y0+IWPdsLLS738P8tDnrQ8Z+dj12zQQ6WC11TIM21C8WFVoIxcqWXf2H3hiTVZjF1AWqoimGwrTWecWrnmRQ==} @@ -3042,6 +3054,9 @@ packages: html-escaper@2.0.2: resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} + html-void-elements@3.0.0: + resolution: {integrity: sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==} + http-errors@2.0.0: resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} engines: {node: '>= 0.8'} @@ -3781,6 +3796,9 @@ packages: resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} engines: {node: '>=12'} + oniguruma-to-js@0.4.3: + resolution: {integrity: sha512-X0jWUcAlxORhOqqBREgPMgnshB7ZGYszBNspP+tS9hPD3l13CdaXcHbgImoHUHlrvGx/7AvFEkTRhAGYh+jzjQ==} + optionator@0.9.4: resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} engines: {node: '>= 0.8.0'} @@ -4170,6 +4188,9 @@ packages: regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} + regex@4.3.2: + resolution: {integrity: sha512-kK/AA3A9K6q2js89+VMymcboLOlF5lZRCYJv3gzszXFHBr6kO6qLGzbm+UIugBEV8SMMKCTR59txoY6ctRHYVw==} + rehype-autolink-headings@7.1.0: resolution: {integrity: sha512-rItO/pSdvnvsP4QRB1pmPiNHUskikqtPojZKJPPPAVx9Hj8i8TwMBhofrrAYRhYOOBZH9tgmG5lPqDLuIWPWmw==} @@ -4358,8 +4379,8 @@ packages: resolution: {integrity: sha512-R6aHBquTiQlD4NzJHTaaJDAwsMzVuZa0RR8y3UpqH4muPX2694HvVtcKAIYpnuxQSrvx2CRdyGGa9+577eJxUQ==} hasBin: true - shiki@1.12.1: - resolution: {integrity: sha512-nwmjbHKnOYYAe1aaQyEBHvQymJgfm86ZSS7fT8OaPRr4sbAcBNz7PbfAikMEFSDQ6se2j2zobkXvVKcBOm0ysg==} + shiki@1.20.0: + resolution: {integrity: sha512-MZJJ1PCFsQB1Piq+25wiz0a75yUv8Q3/fzy7SzRx5ONdjdtGdyiKwYn8vb/FnK5kjS0voWGnPpjG16POauUR+g==} siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} @@ -4714,11 +4735,11 @@ packages: engines: {node: '>=18.0.0'} hasBin: true - twoslash-protocol@0.2.9: - resolution: {integrity: sha512-uKQl8UboT6JU4VAtYaSI3DbNtgaNhFaTpCSMy/n3tRl5lMlMhrjiuNKdqx15xjcviconuGJ9oObkz1h9zJFrJg==} + twoslash-protocol@0.2.11: + resolution: {integrity: sha512-rp+nkOWbKfJnBTDZtnIaBGjnU+4CaMhqu6db2UU7byU96rH8X4hao4BOxYw6jdZc85Lhv5pOfcjgfHeQyLzndQ==} - twoslash@0.2.9: - resolution: {integrity: sha512-oj7XY6h8E9nTZBmfRE1gpsSSUqAQo5kcIpFkXyQPp8UCsyCQsUlP2bJ2s32o02c1n5+xl4h9rcCsQ1F97Z6LZg==} + twoslash@0.2.11: + resolution: {integrity: sha512-392Qkcu5sD2hROLZ+XPywChreDGJ8Yu5nnK/Moxfti/R39q0Q39MaV7iHjz92B5qucyjsQFnKMdYIzafX5T8dg==} peerDependencies: typescript: '*' @@ -4941,8 +4962,8 @@ packages: jsdom: optional: true - vocs@1.0.0-alpha.59: - resolution: {integrity: sha512-N3u4SUgGKeGWsfosjSZ7e2GLxvEZ0hvEjxcx8XbYmo5cw8D4AqCAraGLCCWBd55MVGMPXebnQpMEtOmjw8BHnA==} + vocs@1.0.0-alpha.60: + resolution: {integrity: sha512-WrCDa6s7qcwhqOC2M8xCe1ezmOhOV0aF/l3jPx/SBXP25AZHR0Be07YEIeZcQRicYTZcIwK/Pq/ciWybwOedZg==} hasBin: true peerDependencies: react: ^18.2.0 @@ -6545,31 +6566,55 @@ snapshots: '@sec-ant/readable-stream@0.4.1': {} - '@shikijs/core@1.12.1': + '@shikijs/core@1.20.0': dependencies: + '@shikijs/engine-javascript': 1.20.0 + '@shikijs/engine-oniguruma': 1.20.0 + '@shikijs/types': 1.20.0 + '@shikijs/vscode-textmate': 9.2.2 '@types/hast': 3.0.4 + hast-util-to-html: 9.0.3 + + '@shikijs/engine-javascript@1.20.0': + dependencies: + '@shikijs/types': 1.20.0 + '@shikijs/vscode-textmate': 9.2.2 + oniguruma-to-js: 0.4.3 + + '@shikijs/engine-oniguruma@1.20.0': + dependencies: + '@shikijs/types': 1.20.0 + '@shikijs/vscode-textmate': 9.2.2 - '@shikijs/rehype@1.12.1': + '@shikijs/rehype@1.20.0': dependencies: - '@shikijs/transformers': 1.12.1 + '@shikijs/types': 1.20.0 '@types/hast': 3.0.4 hast-util-to-string: 3.0.0 - shiki: 1.12.1 + shiki: 1.20.0 unified: 11.0.5 unist-util-visit: 5.0.0 - '@shikijs/transformers@1.12.1': + '@shikijs/transformers@1.20.0': dependencies: - shiki: 1.12.1 + shiki: 1.20.0 - '@shikijs/twoslash@1.12.1(typescript@5.5.4)': + '@shikijs/twoslash@1.20.0(typescript@5.5.4)': dependencies: - '@shikijs/core': 1.12.1 - twoslash: 0.2.9(typescript@5.5.4) + '@shikijs/core': 1.20.0 + '@shikijs/types': 1.20.0 + twoslash: 0.2.11(typescript@5.5.4) transitivePeerDependencies: - supports-color - typescript + '@shikijs/types@1.20.0': + dependencies: + '@shikijs/vscode-textmate': 9.2.2 + '@types/hast': 3.0.4 + + '@shikijs/vscode-textmate@9.2.2': {} + '@sinclair/typebox@0.27.8': {} '@sindresorhus/merge-streams@2.3.0': {} @@ -6846,12 +6891,6 @@ snapshots: treeify: 1.1.0 yargs: 16.2.0 - '@typescript/vfs@1.5.0': - dependencies: - debug: 4.3.6 - transitivePeerDependencies: - - supports-color - '@typescript/vfs@1.6.0(typescript@5.5.4)': dependencies: debug: 4.3.6 @@ -8298,6 +8337,20 @@ snapshots: transitivePeerDependencies: - supports-color + hast-util-to-html@9.0.3: + dependencies: + '@types/hast': 3.0.4 + '@types/unist': 3.0.2 + ccount: 2.0.1 + comma-separated-tokens: 2.0.3 + hast-util-whitespace: 3.0.0 + html-void-elements: 3.0.0 + mdast-util-to-hast: 13.2.0 + property-information: 6.5.0 + space-separated-tokens: 2.0.2 + stringify-entities: 4.0.4 + zwitch: 2.0.4 + hast-util-to-jsx-runtime@2.3.0: dependencies: '@types/estree': 1.0.5 @@ -8338,6 +8391,8 @@ snapshots: html-escaper@2.0.2: {} + html-void-elements@3.0.0: {} + http-errors@2.0.0: dependencies: depd: 2.0.0 @@ -9309,6 +9364,10 @@ snapshots: dependencies: mimic-fn: 4.0.0 + oniguruma-to-js@0.4.3: + dependencies: + regex: 4.3.2 + optionator@0.9.4: dependencies: deep-is: 0.1.4 @@ -9697,6 +9756,8 @@ snapshots: regenerator-runtime@0.14.1: {} + regex@4.3.2: {} + rehype-autolink-headings@7.1.0: dependencies: '@types/hast': 3.0.4 @@ -9957,9 +10018,13 @@ snapshots: sherif-windows-arm64: 0.11.0 sherif-windows-x64: 0.11.0 - shiki@1.12.1: + shiki@1.20.0: dependencies: - '@shikijs/core': 1.12.1 + '@shikijs/core': 1.20.0 + '@shikijs/engine-javascript': 1.20.0 + '@shikijs/engine-oniguruma': 1.20.0 + '@shikijs/types': 1.20.0 + '@shikijs/vscode-textmate': 9.2.2 '@types/hast': 3.0.4 siginfo@2.0.0: {} @@ -10314,12 +10379,12 @@ snapshots: optionalDependencies: fsevents: 2.3.3 - twoslash-protocol@0.2.9: {} + twoslash-protocol@0.2.11: {} - twoslash@0.2.9(typescript@5.5.4): + twoslash@0.2.11(typescript@5.5.4): dependencies: - '@typescript/vfs': 1.5.0 - twoslash-protocol: 0.2.9 + '@typescript/vfs': 1.6.0(typescript@5.5.4) + twoslash-protocol: 0.2.11 typescript: 5.5.4 transitivePeerDependencies: - supports-color @@ -10596,7 +10661,7 @@ snapshots: - supports-color - terser - vocs@1.0.0-alpha.59(@types/node@22.5.4)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@4.20.0)(terser@5.31.5)(typescript@5.5.4): + vocs@1.0.0-alpha.60(@types/node@22.5.4)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(rollup@4.20.0)(terser@5.31.5)(typescript@5.5.4): dependencies: '@floating-ui/react': 0.26.22(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@hono/node-server': 1.12.0 @@ -10611,9 +10676,9 @@ snapshots: '@radix-ui/react-navigation-menu': 1.2.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-popover': 1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@radix-ui/react-tabs': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@shikijs/rehype': 1.12.1 - '@shikijs/transformers': 1.12.1 - '@shikijs/twoslash': 1.12.1(typescript@5.5.4) + '@shikijs/rehype': 1.20.0 + '@shikijs/transformers': 1.20.0 + '@shikijs/twoslash': 1.20.0(typescript@5.5.4) '@vanilla-extract/css': 1.15.3 '@vanilla-extract/dynamic': 2.1.1 '@vanilla-extract/vite-plugin': 3.9.5(@types/node@22.5.4)(terser@5.31.5)(vite@5.4.6(@types/node@22.5.4)(terser@5.31.5)) @@ -10653,10 +10718,10 @@ snapshots: remark-mdx-frontmatter: 4.0.0 remark-parse: 11.0.0 serve-static: 1.15.0 - shiki: 1.12.1 + shiki: 1.20.0 tailwindcss: 3.4.10 toml: 3.0.0 - twoslash: 0.2.9(typescript@5.5.4) + twoslash: 0.2.11(typescript@5.5.4) ua-parser-js: 1.0.38 unified: 11.0.5 unist-util-visit: 5.0.0 diff --git a/src/Errors.test.ts b/src/Errors.test.ts index 86cda588..346e7a0e 100644 --- a/src/Errors.test.ts +++ b/src/Errors.test.ts @@ -44,7 +44,6 @@ test('exports', () => { "Hex_SizeExceedsPaddingSizeError", "Hex_SizeOverflowError", "Hex_SliceOffsetOutOfBoundsError", - "Log_ArgsMismatchError", "Provider_IsUndefinedError", "PublicKey_InvalidCompressedPrefixError", "PublicKey_InvalidError", diff --git a/src/Errors.ts b/src/Errors.ts index 76019304..b82bcc84 100644 --- a/src/Errors.ts +++ b/src/Errors.ts @@ -65,8 +65,6 @@ export { Hex_SliceOffsetOutOfBoundsError, } from './internal/Hex/errors.js' -export { Log_ArgsMismatchError } from './internal/Log/errors.js' - export { Provider_IsUndefinedError } from './internal/Provider/errors.js' export { diff --git a/src/internal/AbiParameters/errors.ts b/src/internal/AbiParameters/errors.ts index ea46d383..e767cffe 100644 --- a/src/internal/AbiParameters/errors.ts +++ b/src/internal/AbiParameters/errors.ts @@ -3,6 +3,31 @@ import { BaseError } from '../Errors/base.js' import { Hex_size } from '../Hex/size.js' import type { Hex } from '../Hex/types.js' +/** + * Throws when the data size is too small for the given parameters. + * + * @example + * ```ts twoslash + * import { AbiParameters } from 'ox' + * + * AbiParameters.decode([{ type: 'uint256' }], '0x010f') + * // ↑ ❌ 2 bytes + * // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters. + * // @error: Params: (uint256) + * // @error: Data: 0x010f (2 bytes) + * ``` + * + * ### Solution + * + * Pass a valid data size. + * + * ```ts twoslash + * import { AbiParameters } from 'ox' + * + * AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f') + * // ↑ ✅ 32 bytes + * ``` + */ export class AbiParameters_DataSizeTooSmallError extends BaseError { override readonly name = 'AbiParameters.DataSizeTooSmallError' constructor({ @@ -19,6 +44,31 @@ export class AbiParameters_DataSizeTooSmallError extends BaseError { } } +/** + * Throws when zero data is provided, but data is expected. + * + * @example + * ```ts twoslash + * import { AbiParameters } from 'ox' + * + * AbiParameters.decode([{ type: 'uint256' }], '0x') + * // ↑ ❌ zero data + * // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters. + * // @error: Params: (uint256) + * // @error: Data: 0x010f (2 bytes) + * ``` + * + * ### Solution + * + * Pass valid data. + * + * ```ts twoslash + * import { AbiParameters } from 'ox' + * + * AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f') + * // ↑ ✅ 32 bytes + * ``` + */ export class AbiParameters_ZeroDataError extends BaseError { override readonly name = 'AbiParameters.ZeroDataError' constructor() { @@ -49,7 +99,7 @@ export class AbiParameters_ZeroDataError extends BaseError { * import { AbiParameters } from 'ox' * // ---cut--- * AbiParameters.encode(AbiParameters.from(['uint256[3]']), [[69n, 420n, 69n]]) - * // ↑ ✅ length: 3 + * // ↑ ✅ length: 3 * ``` */ export class AbiParameters_ArrayLengthMismatchError extends BaseError { @@ -175,6 +225,18 @@ export class AbiParameters_InvalidArrayError extends BaseError { } } +/** + * Throws when the ABI parameter type is invalid. + * + * @example + * ```ts twoslash + * import { AbiParameters } from 'ox' + * + * AbiParameters.decode([{ type: 'lol' }], '0x00000000000000000000000000000000000000000000000000000000000010f') + * // ↑ ❌ invalid type + * // @error: AbiParameters.InvalidTypeError: Type `lol` is not a valid ABI Type. + * ``` + */ export class AbiParameters_InvalidTypeError extends BaseError { override readonly name = 'AbiParameters.InvalidTypeError' constructor(type: string) { diff --git a/src/internal/AccessList/errors.ts b/src/internal/AccessList/errors.ts index ed433f92..c192e318 100644 --- a/src/internal/AccessList/errors.ts +++ b/src/internal/AccessList/errors.ts @@ -2,6 +2,7 @@ import { BaseError } from '../Errors/base.js' import { Hex_size } from '../Hex/size.js' import type { Hex } from '../Hex/types.js' +/** Thrown when the size of a storage key is invalid. */ export class AccessList_InvalidStorageKeySizeError extends BaseError { override readonly name = 'AccessList.InvalidStorageKeySizeError' constructor({ storageKey }: { storageKey: Hex }) { diff --git a/src/internal/Address/errors.ts b/src/internal/Address/errors.ts index 6fd0cd3f..da0b7e4d 100644 --- a/src/internal/Address/errors.ts +++ b/src/internal/Address/errors.ts @@ -1,5 +1,16 @@ import { BaseError } from '../Errors/base.js' +/** + * Thrown when an address is invalid. + * + * @example + * ```ts twoslash + * import { Address } from 'ox' + * + * Address.from('0x123') + * // @error: Address.InvalidAddressError: Address `0x123` is invalid. + * ``` + */ export class Address_InvalidAddressError< cause extends Address_InvalidInputError | Address_InvalidChecksumError = | Address_InvalidInputError @@ -15,6 +26,7 @@ export class Address_InvalidAddressError< } } +/** Thrown when an address is not a 20 byte (40 hexadecimal character) value. */ export class Address_InvalidInputError extends BaseError { override readonly name = 'Address.InvalidInputError' @@ -23,6 +35,7 @@ export class Address_InvalidInputError extends BaseError { } } +/** Thrown when an address does not match its checksum counterpart. */ export class Address_InvalidChecksumError extends BaseError { override readonly name = 'Address.InvalidChecksumError' diff --git a/src/internal/Blobs/errors.ts b/src/internal/Blobs/errors.ts index 27e0518a..84e912b5 100644 --- a/src/internal/Blobs/errors.ts +++ b/src/internal/Blobs/errors.ts @@ -3,6 +3,7 @@ import { Kzg_versionedHashVersion } from '../Kzg/constants.js' import { BaseError } from '../Errors/base.js' +/** Thrown when the blob size is too large. */ export class Blobs_BlobSizeTooLargeError extends BaseError { override readonly name = 'Blobs.BlobSizeTooLargeError' constructor({ maxSize, size }: { maxSize: number; size: number }) { @@ -12,6 +13,7 @@ export class Blobs_BlobSizeTooLargeError extends BaseError { } } +/** Thrown when the blob is empty. */ export class Blobs_EmptyBlobError extends BaseError { override readonly name = 'Blobs.EmptyBlobError' constructor() { @@ -19,6 +21,7 @@ export class Blobs_EmptyBlobError extends BaseError { } } +/** Thrown when the blob versioned hashes are empty. */ export class Blobs_EmptyBlobVersionedHashesError extends BaseError { override readonly name = 'Blobs.EmptyBlobVersionedHashesError' constructor() { @@ -26,6 +29,7 @@ export class Blobs_EmptyBlobVersionedHashesError extends BaseError { } } +/** Thrown when the blob versioned hash size is invalid. */ export class Blobs_InvalidVersionedHashSizeError extends BaseError { override readonly name = 'Blobs.InvalidVersionedHashSizeError' constructor({ @@ -41,6 +45,7 @@ export class Blobs_InvalidVersionedHashSizeError extends BaseError { } } +/** Thrown when the blob versioned hash version is invalid. */ export class Blobs_InvalidVersionedHashVersionError extends BaseError { override readonly name = 'Blobs.InvalidVersionedHashVersionError' constructor({ diff --git a/src/internal/Bytes/errors.ts b/src/internal/Bytes/errors.ts index 04c27869..2360647f 100644 --- a/src/internal/Bytes/errors.ts +++ b/src/internal/Bytes/errors.ts @@ -2,6 +2,18 @@ import type { Bytes } from '../Bytes/types.js' import { BaseError } from '../Errors/base.js' import { Json_stringify } from '../Json/stringify.js' +/** + * Thrown when the bytes value cannot be represented as a boolean. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.toBoolean(Bytes.from([5])) + * // @error: Bytes.InvalidBytesBooleanError: Bytes value `[5]` is not a valid boolean. + * // @error: The bytes array must contain a single byte of either a `0` or `1` value. + * ``` + */ export class Bytes_InvalidBytesBooleanError extends BaseError { override readonly name = 'Bytes.InvalidBytesBooleanError' @@ -15,6 +27,17 @@ export class Bytes_InvalidBytesBooleanError extends BaseError { } } +/** + * Thrown when a value cannot be converted to bytes. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.from('foo') + * // @error: Bytes.InvalidBytesTypeError: Value `foo` of type `string` is an invalid Bytes value. + * ``` + */ export class Bytes_InvalidBytesTypeError extends BaseError { override readonly name = 'Bytes.InvalidBytesTypeError' @@ -29,6 +52,17 @@ export class Bytes_InvalidBytesTypeError extends BaseError { } } +/** + * Thrown when a size exceeds the maximum allowed size. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.fromString('Hello World!', { size: 8 }) + * // @error: Bytes.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes. + * ``` + */ export class Bytes_SizeOverflowError extends BaseError { override readonly name = 'Bytes.SizeOverflowError' @@ -42,6 +76,17 @@ export class Bytes_SizeOverflowError extends BaseError { } } +/** + * Thrown when a slice offset is out-of-bounds. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.slice(Bytes.from([1, 2, 3]), 4) + * // @error: Bytes.SliceOffsetOutOfBoundsError: Slice starting at offset `4` is out-of-bounds (size: `3`). + * ``` + */ export class Bytes_SliceOffsetOutOfBoundsError extends BaseError { override readonly name = 'Bytes.SliceOffsetOutOfBoundsError' @@ -61,6 +106,17 @@ export class Bytes_SliceOffsetOutOfBoundsError extends BaseError { } } +/** + * Thrown when a the padding size exceeds the maximum allowed size. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.padLeft(Bytes.fromString('Hello World!'), 8) + * // @error: [Bytes.SizeExceedsPaddingSizeError: Bytes size (`12`) exceeds padding size (`8`). + * ``` + */ export class Bytes_SizeExceedsPaddingSizeError extends BaseError { override readonly name = 'Bytes.SizeExceedsPaddingSizeError' diff --git a/src/internal/Hex/errors.ts b/src/internal/Hex/errors.ts index 811b208c..b5410c43 100644 --- a/src/internal/Hex/errors.ts +++ b/src/internal/Hex/errors.ts @@ -2,6 +2,17 @@ import { BaseError } from '../Errors/base.js' import type { Hex } from '../Hex/types.js' import { Json_stringify } from '../Json/stringify.js' +/** + * Thrown when the provided integer is out of range, and cannot be represented as a hex value. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.fromNumber(420182738912731283712937129) + * // @error: Hex.IntegerOutOfRangeError: Number \`4.2018273891273126e+26\` is not in safe unsigned integer range (`0` to `9007199254740991`) + * ``` + */ export class Hex_IntegerOutOfRangeError extends BaseError { override readonly name = 'Hex.IntegerOutOfRangeError' @@ -29,6 +40,18 @@ export class Hex_IntegerOutOfRangeError extends BaseError { } } +/** + * Thrown when the provided hex value cannot be represented as a boolean. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.toBoolean('0xa') + * // @error: Hex.InvalidHexBooleanError: Hex value `"0xa"` is not a valid boolean. + * // @error: The hex value must be `"0x0"` (false) or `"0x1"` (true). + * ``` + */ export class Hex_InvalidHexBooleanError extends BaseError { override readonly name = 'Hex.InvalidHexBooleanError' @@ -42,6 +65,17 @@ export class Hex_InvalidHexBooleanError extends BaseError { } } +/** + * Thrown when the provided value is not a valid hex type. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.assert(1) + * // @error: Hex.InvalidHexTypeError: Value `1` of type `number` is an invalid hex type. + * ``` + */ export class Hex_InvalidHexTypeError extends BaseError { override readonly name = 'Hex.InvalidHexTypeError' @@ -56,6 +90,18 @@ export class Hex_InvalidHexTypeError extends BaseError { } } +/** + * Thrown when the provided hex value is invalid. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.assert('0x0123456789abcdefg') + * // @error: Hex.InvalidHexValueError: Value `0x0123456789abcdefg` is an invalid hex value. + * // @error: Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F). + * ``` + */ export class Hex_InvalidHexValueError extends BaseError { override readonly name = 'Hex.InvalidHexValueError' @@ -69,6 +115,17 @@ export class Hex_InvalidHexValueError extends BaseError { } } +/** + * Thrown when the provided hex value is an odd length. + * + * @example + * ```ts twoslash + * import { Bytes } from 'ox' + * + * Bytes.fromHex('0xabcde') + * // @error: Hex.InvalidLengthError: Hex value `"0xabcde"` is an odd length (5 nibbles). + * ``` + */ export class Hex_InvalidLengthError extends BaseError { override readonly name = 'Hex.InvalidLengthError' @@ -83,6 +140,17 @@ export class Hex_InvalidLengthError extends BaseError { } } +/** + * Thrown when the size of the value exceeds the expected max size. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.fromString('Hello World!', { size: 8 }) + * // @error: Hex.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes. + * ``` + */ export class Hex_SizeOverflowError extends BaseError { override readonly name = 'Hex.SizeOverflowError' @@ -96,6 +164,17 @@ export class Hex_SizeOverflowError extends BaseError { } } +/** + * Thrown when the slice offset exceeds the bounds of the value. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.slice('0x0123456789', 6) + * // @error: Hex.SliceOffsetOutOfBoundsError: Slice starting at offset `6` is out-of-bounds (size: `5`). + * ``` + */ export class Hex_SliceOffsetOutOfBoundsError extends BaseError { override readonly name = 'Hex.SliceOffsetOutOfBoundsError' @@ -115,6 +194,17 @@ export class Hex_SliceOffsetOutOfBoundsError extends BaseError { } } +/** + * Thrown when the size of the value exceeds the pad size. + * + * @example + * ```ts twoslash + * import { Hex } from 'ox' + * + * Hex.padLeft('0x1a4e12a45a21323123aaa87a897a897a898a6567a578a867a98778a667a85a875a87a6a787a65a675a6a9', 32) + * // @error: Hex.SizeExceedsPaddingSizeError: Hex size (`43`) exceeds padding size (`32`). + * ``` + */ export class Hex_SizeExceedsPaddingSizeError extends BaseError { override readonly name = 'Hex.SizeExceedsPaddingSizeError' diff --git a/src/internal/Log/errors.ts b/src/internal/Log/errors.ts deleted file mode 100644 index 022172fd..00000000 --- a/src/internal/Log/errors.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { AbiEvent_format } from '../AbiEvent/format.js' -import type { AbiEvent } from '../AbiEvent/types.js' -import { BaseError } from '../Errors/base.js' -import { prettyPrint } from '../Errors/utils.js' - -export class Log_ArgsMismatchError extends BaseError { - override readonly name = 'Log.ArgsMismatchError' - - constructor({ - abiEvent, - expected, - given, - }: { - abiEvent: AbiEvent - expected: unknown - given: unknown - }) { - super( - 'Provided arguments to not match the arguments decoded from the log.', - { - metaMessages: [ - `Event: ${AbiEvent_format(abiEvent)}`, - `Decoded Arguments: ${!expected ? 'None' : ''}`, - expected ? prettyPrint(expected) : undefined, - `Provided Arguments: ${!given ? 'None' : ''}`, - given ? prettyPrint(given) : undefined, - ], - }, - ) - } -} diff --git a/src/internal/Promise/errors.ts b/src/internal/Promise/errors.ts index 5be7e85a..6a77cecf 100644 --- a/src/internal/Promise/errors.ts +++ b/src/internal/Promise/errors.ts @@ -1,5 +1,6 @@ import { BaseError } from '../Errors/base.js' +/** Thrown when an operation times out. */ export class Promise_TimeoutError extends BaseError { override readonly name = 'Promise.TimeoutError' diff --git a/src/internal/Provider/errors.ts b/src/internal/Provider/errors.ts index 22e9f8fb..e63fb12f 100644 --- a/src/internal/Provider/errors.ts +++ b/src/internal/Provider/errors.ts @@ -1,5 +1,6 @@ import { BaseError } from '../Errors/base.js' +/** Thrown when the provider is undefined. */ export class Provider_IsUndefinedError extends BaseError { override readonly name = 'Provider.IsUndefinedError' diff --git a/src/internal/PublicKey/errors.ts b/src/internal/PublicKey/errors.ts index b2478542..9b939c6c 100644 --- a/src/internal/PublicKey/errors.ts +++ b/src/internal/PublicKey/errors.ts @@ -5,6 +5,20 @@ import { Hex_size } from '../Hex/size.js' import type { Hex } from '../Hex/types.js' import { Json_stringify } from '../Json/stringify.js' +/** + * Thrown when a public key is invalid. + * + * @example + * ```ts twoslash + * import { PublicKey } from 'ox' + * + * PublicKey.assert({ y: 1n }) + * // @error: PublicKey.InvalidError: Value `{"y":1n}` is not a valid public key. + * // @error: Public key must contain: + * // @error: - an `x` and `prefix` value (compressed) + * // @error: - an `x`, `y`, and `prefix` value (uncompressed) + * ``` + */ export class PublicKey_InvalidError extends BaseError { override readonly name = 'PublicKey.InvalidError' @@ -19,6 +33,7 @@ export class PublicKey_InvalidError extends BaseError { } } +/** Thrown when a public key has an invalid prefix. */ export class PublicKey_InvalidPrefixError< cause extends | PublicKey_InvalidCompressedPrefixError @@ -35,6 +50,7 @@ export class PublicKey_InvalidPrefixError< } } +/** Thrown when the public key has an invalid prefix for a compressed public key. */ export class PublicKey_InvalidCompressedPrefixError extends BaseError { override readonly name = 'PublicKey.InvalidCompressedPrefixError' @@ -43,6 +59,7 @@ export class PublicKey_InvalidCompressedPrefixError extends BaseError { } } +/** Thrown when the public key has an invalid prefix for an uncompressed public key. */ export class PublicKey_InvalidUncompressedPrefixError extends BaseError { override readonly name = 'PublicKey.InvalidUncompressedPrefixError' @@ -51,6 +68,7 @@ export class PublicKey_InvalidUncompressedPrefixError extends BaseError { } } +/** Thrown when the public key has an invalid serialized size. */ export class PublicKey_InvalidSerializedSizeError extends BaseError { override readonly name = 'PublicKey.InvalidSerializedSizeError' diff --git a/src/internal/RpcResponse/errors.ts b/src/internal/RpcResponse/errors.ts index 08cdf2c3..98581a20 100644 --- a/src/internal/RpcResponse/errors.ts +++ b/src/internal/RpcResponse/errors.ts @@ -1,5 +1,6 @@ import type { RpcResponse_ErrorObject } from './types.js' +/** Thrown when a JSON-RPC error has occurred. */ export type RpcResponse_ErrorType = RpcResponse_Error & { name: 'JsonRpcError' } export class RpcResponse_Error extends Error { override name = 'RpcResponse_Error' @@ -15,72 +16,84 @@ export class RpcResponse_Error extends Error { } } +/** Thrown when the input to a JSON-RPC method is invalid. */ export class RpcResponse_InvalidInputError extends RpcResponse_Error { static readonly code = -32000 override readonly code = -32000 override readonly name = 'RpcResponse.InvalidInputError' } +/** Thrown when a JSON-RPC resource is not found. */ export class RpcResponse_ResourceNotFoundError extends RpcResponse_Error { static readonly code = -32001 override readonly code = -32001 override readonly name = 'RpcResponse.ResourceNotFoundError' } +/** Thrown when a JSON-RPC resource is unavailable. */ export class RpcResponse_ResourceUnavailableError extends RpcResponse_Error { static readonly code = -32002 override readonly code = -32002 override readonly name = 'RpcResponse.ResourceUnavailableError' } +/** Thrown when a JSON-RPC transaction is rejected. */ export class RpcResponse_TransactionRejectedError extends RpcResponse_Error { static readonly code = -32003 override readonly code = -32003 override readonly name = 'RpcResponse.TransactionRejectedError' } +/** Thrown when a JSON-RPC method is not supported. */ export class RpcResponse_MethodNotSupportedError extends RpcResponse_Error { static readonly code = -32004 override readonly code = -32004 override readonly name = 'RpcResponse.MethodNotSupportedError' } +/** Thrown when a rate-limit is exceeded. */ export class RpcResponse_LimitExceededError extends RpcResponse_Error { static readonly code = -32005 override readonly code = -32005 override readonly name = 'RpcResponse.LimitExceededError' } +/** Thrown when a JSON-RPC version is not supported. */ export class RpcResponse_VersionNotSupportedError extends RpcResponse_Error { static readonly code = -32006 override readonly code = -32006 override readonly name = 'RpcResponse.VersionNotSupportedError' } +/** Thrown when a JSON-RPC request is invalid. */ export class RpcResponse_InvalidRequestError extends RpcResponse_Error { static readonly code = -32600 override readonly code = -32600 override readonly name = 'RpcResponse.InvalidRequestError' } +/** Thrown when a JSON-RPC method is not found. */ export class RpcResponse_MethodNotFoundError extends RpcResponse_Error { static readonly code = -32601 override readonly code = -32601 override readonly name = 'RpcResponse.MethodNotFoundError' } +/** Thrown when the parameters to a JSON-RPC method are invalid. */ export class RpcResponse_InvalidParamsError extends RpcResponse_Error { static readonly code = -32602 override readonly code = -32602 override readonly name = 'RpcResponse.InvalidParamsError' } +/** Thrown when an internal JSON-RPC error has occurred. */ export class RpcResponse_InternalError extends RpcResponse_Error { static readonly code = -32603 override readonly code = -32603 override readonly name = 'RpcResponse.InternalErrorError' } +/** Thrown when a JSON-RPC response is invalid. */ export class RpcResponse_ParseError extends RpcResponse_Error { static readonly code = -32700 override readonly code = -32700 diff --git a/src/internal/RpcTransport/errors.ts b/src/internal/RpcTransport/errors.ts index ea943292..101314c1 100644 --- a/src/internal/RpcTransport/errors.ts +++ b/src/internal/RpcTransport/errors.ts @@ -1,6 +1,7 @@ import { BaseError } from '../Errors/base.js' import { getUrl } from '../Errors/utils.js' +/** Thrown when a HTTP request fails. */ export class RpcTransport_HttpError extends BaseError { override readonly name = 'RpcTransport.HttpError' @@ -21,6 +22,7 @@ export class RpcTransport_HttpError extends BaseError { } } +/** Thrown when a HTTP response is malformed. */ export class RpcTransport_MalformedResponseError extends BaseError { override readonly name = 'RpcTransport.MalformedResponseError' diff --git a/src/internal/Signature/errors.ts b/src/internal/Signature/errors.ts index 41ae2ae3..e83f7e45 100644 --- a/src/internal/Signature/errors.ts +++ b/src/internal/Signature/errors.ts @@ -5,6 +5,7 @@ import { Hex_size } from '../Hex/size.js' import type { Hex } from '../Hex/types.js' import { Json_stringify } from '../Json/stringify.js' +/** Thrown when the serialized signature is of an invalid size. */ export class Signature_InvalidSerializedSizeError extends BaseError { override readonly name = 'Signature.InvalidSerializedSizeError' @@ -19,6 +20,7 @@ export class Signature_InvalidSerializedSizeError extends BaseError { } } +/** Thrown when the signature is missing either an `r`, `s`, or `yParity` property. */ export class Signature_MissingPropertiesError extends BaseError { override readonly name = 'Signature.MissingPropertiesError' @@ -32,6 +34,7 @@ export class Signature_MissingPropertiesError extends BaseError { } } +/** Thrown when the signature has an invalid `r` value. */ export class Signature_InvalidRError extends BaseError { override readonly name = 'Signature.InvalidRError' @@ -42,6 +45,7 @@ export class Signature_InvalidRError extends BaseError { } } +/** Thrown when the signature has an invalid `s` value. */ export class Signature_InvalidSError extends BaseError { override readonly name = 'Signature.InvalidSError' @@ -52,6 +56,7 @@ export class Signature_InvalidSError extends BaseError { } } +/** Thrown when the signature has an invalid `yParity` value. */ export class Signature_InvalidYParityError extends BaseError { override readonly name = 'Signature.InvalidYParityError' @@ -65,6 +70,7 @@ export class Signature_InvalidYParityError extends BaseError { } } +/** Thrown when the signature has an invalid `v` value. */ export class Signature_InvalidVError extends BaseError { override readonly name = 'Signature.InvalidVError' diff --git a/src/internal/Siwe/errors.ts b/src/internal/Siwe/errors.ts index 7d253186..660bfbfc 100644 --- a/src/internal/Siwe/errors.ts +++ b/src/internal/Siwe/errors.ts @@ -1,5 +1,26 @@ import { BaseError } from '../Errors/base.js' +/** + * Thrown when a field in a SIWE Message is invalid. + * + * @example + * ```ts twoslash + * import { Siwe } from 'ox' + * + * Siwe.createMessage({ + * address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', + * chainId: 1.1, + * domain: 'example.com', + * nonce: 'foobarbaz', + * uri: 'https://example.com/path', + * version: '1', + * }) + * // @error: Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "chainId". + * // @error: - Chain ID must be a EIP-155 chain ID. + * // @error: - See https://eips.ethereum.org/EIPS/eip-155 + * // @error: Provided value: 1.1 + * ``` + */ export class Siwe_InvalidMessageFieldError extends BaseError { override readonly name = 'Siwe.InvalidMessageFieldError' diff --git a/src/internal/TransactionEnvelope/errors.ts b/src/internal/TransactionEnvelope/errors.ts index 06f0c901..dfca12a8 100644 --- a/src/internal/TransactionEnvelope/errors.ts +++ b/src/internal/TransactionEnvelope/errors.ts @@ -3,6 +3,32 @@ import { prettyPrint } from '../Errors/utils.js' import type { Hex } from '../Hex/types.js' import { Value_formatGwei } from '../Value/formatGwei.js' +/** + * Thrown when a transaction type cannot be inferred. + * + * @example + * ```ts twoslash + * import { TransactionEnvelope } from 'ox' + * + * const tx = TransactionEnvelope.from({ + * chainId: 1, + * }) + * // @error: TransactionEnvelope.CannotInferTypeError: Cannot infer a transaction type from provided transaction. + * ``` + * + * ### Solution + * + * Provide a `type` to the transaction, or a property that will infer the type. + * + * ```ts twoslash + * import { TransactionEnvelope } from 'ox' + * + * const tx = TransactionEnvelope.from({ + * chainId: 1, + * type: 'eip1559', // [!code ++] + * }) + * ``` + */ export class TransactionEnvelope_CannotInferTypeError extends BaseError { override readonly name = 'TransactionEnvelope.CannotInferTypeError' constructor({ transaction }: { transaction: Record }) { @@ -25,6 +51,21 @@ export class TransactionEnvelope_CannotInferTypeError extends BaseError { } } +/** + * Thrown when a fee cap is too high. + * + * @example + * ```ts twoslash + * import { TransactionEnvelope } from 'ox' + * + * TransactionEnvelope.assert({ + * maxFeePerGas: 2n ** 256n - 1n + 1n, + * chainId: 1, + * type: 'eip1559', + * }) + * // @error: TransactionEnvelope.FeeCapTooHighError: The fee cap (`maxFeePerGas`/`maxPriorityFeePerGas` = 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei) cannot be higher than the maximum allowed value (2^256-1). + * ``` + */ export class TransactionEnvelope_FeeCapTooHighError extends BaseError { override readonly name = 'TransactionEnvelope.FeeCapTooHighError' constructor({ @@ -40,6 +81,21 @@ export class TransactionEnvelope_FeeCapTooHighError extends BaseError { } } +/** + * Thrown when a gas price is too high. + * + * @example + * ```ts twoslash + * import { TransactionEnvelope } from 'ox' + * + * TransactionEnvelope.assert({ + * gasPrice: 2n ** 256n - 1n + 1n, + * chainId: 1, + * type: 'legacy', + * }) + * // @error: TransactionEnvelope.GasPriceTooHighError: The gas price (`gasPrice` = 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei) cannot be higher than the maximum allowed value (2^256-1). + * ``` + */ export class TransactionEnvelope_GasPriceTooHighError extends BaseError { override readonly name = 'TransactionEnvelope.GasPriceTooHighError' constructor({ @@ -55,6 +111,17 @@ export class TransactionEnvelope_GasPriceTooHighError extends BaseError { } } +/** + * Thrown when a chain ID is invalid. + * + * @example + * ```ts twoslash + * import { TransactionEnvelopeEip1559 } from 'ox' + * + * TransactionEnvelopeEip1559.assert({ chainId: 0 }) + * // @error: TransactionEnvelope.InvalidChainIdError: Chain ID "0" is invalid. + * ``` + */ export class TransactionEnvelope_InvalidChainIdError extends BaseError { override readonly name = 'TransactionEnvelope.InvalidChainIdError' constructor({ chainId }: { chainId?: number | undefined }) { @@ -66,6 +133,19 @@ export class TransactionEnvelope_InvalidChainIdError extends BaseError { } } +/** + * Thrown when a serialized transaction is invalid. + * + * @example + * ```ts twoslash + * import { TransactionEnvelopeEip1559 } from 'ox' + * + * TransactionEnvelopeEip1559.deserialize('0x02c0') + * // @error: TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "eip1559" was provided. + * // @error: Serialized Transaction: "0x02c0" + * // @error: Missing Attributes: chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList + * ``` + */ export class TransactionEnvelope_InvalidSerializedError extends BaseError { override readonly name = 'TransactionEnvelope.InvalidSerializedError' constructor({ @@ -89,6 +169,18 @@ export class TransactionEnvelope_InvalidSerializedError extends BaseError { } } +/** + * Thrown when a transaction type is not implemented. + * + * @example + * ```ts twoslash + * // @noErrors + * import { TransactionEnvelope } from 'ox' + * + * TransactionEnvelope.from({ type: 'foo' }) + * // @error: TransactionEnvelope.TypeNotImplementedError: The provided transaction type `foo` is not implemented. + * ``` + */ export class TransactionEnvelope_TypeNotImplementedError extends BaseError { override readonly name = 'TransactionEnvelope.TypeNotImplementedError' constructor({ type }: { type: string }) { @@ -96,6 +188,21 @@ export class TransactionEnvelope_TypeNotImplementedError extends BaseError { } } +/** + * Thrown when a tip is higher than a fee cap. + * + * @example + * ```ts twoslash + * import { TransactionEnvelopeEip1559 } from 'ox' + * + * TransactionEnvelopeEip1559.assert({ + * chainId: 1, + * maxFeePerGas: 10n, + * maxPriorityFeePerGas: 11n, + * }) + * // @error: TransactionEnvelope.TipAboveFeeCapError: The provided tip (`maxPriorityFeePerGas` = 11 gwei) cannot be higher than the fee cap (`maxFeePerGas` = 10 gwei). + * ``` + */ export class TransactionEnvelope_TipAboveFeeCapError extends BaseError { override readonly name = 'TransactionEnvelope.TipAboveFeeCapError' constructor({ diff --git a/src/internal/TypedData/errors.ts b/src/internal/TypedData/errors.ts index a06d8e61..5a74c07a 100644 --- a/src/internal/TypedData/errors.ts +++ b/src/internal/TypedData/errors.ts @@ -1,6 +1,7 @@ import { BaseError } from '../Errors/base.js' import type { TypedData } from './types.js' +/** Thrown when the bytes size of a typed data value does not match the expected size. */ export class TypedData_BytesSizeMismatchError extends BaseError { override readonly name = 'TypedData.BytesSizeMismatchError' @@ -14,6 +15,7 @@ export class TypedData_BytesSizeMismatchError extends BaseError { } } +/** Thrown when the primary type of a typed data value is invalid. */ export class TypedData_InvalidPrimaryTypeError extends BaseError { override readonly name = 'TypedData.InvalidPrimaryTypeError' diff --git a/src/internal/Value/errors.ts b/src/internal/Value/errors.ts index 047a0e9e..6ea35387 100644 --- a/src/internal/Value/errors.ts +++ b/src/internal/Value/errors.ts @@ -1,5 +1,16 @@ import { BaseError } from '../Errors/base.js' +/** + * Thrown when a value is not a valid decimal number. + * + * @example + * ```ts twoslash + * import { Value } from 'ox' + * + * Value.fromEther('123.456.789') + * // @error: Value.InvalidDecimalNumberError: Value `123.456.789` is not a valid decimal number. + * ``` + */ export class Value_InvalidDecimalNumberError extends BaseError { override readonly name = 'Value.InvalidDecimalNumberError' constructor({ value }: { value: string }) { diff --git a/src/internal/WebAuthnP256/errors.ts b/src/internal/WebAuthnP256/errors.ts index 19906c89..fd6a2239 100644 --- a/src/internal/WebAuthnP256/errors.ts +++ b/src/internal/WebAuthnP256/errors.ts @@ -1,5 +1,6 @@ import { BaseError } from '../Errors/base.js' +/** Thrown when a WebAuthn P256 credential creation fails. */ export class WebAuthnP256_CredentialCreationFailedError extends BaseError { override readonly name = 'WebAuthnP256.CredentialCreationFailedError' @@ -10,6 +11,7 @@ export class WebAuthnP256_CredentialCreationFailedError extends BaseError } } +/** Thrown when a WebAuthn P256 credential request fails. */ export class WebAuthnP256_CredentialRequestFailedError extends BaseError { override readonly name = 'WebAuthnP256.CredentialRequestFailedError'