ox 1.0.0-beta.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1143 -0
- package/dist/core/Abi.d.ts +6 -2
- package/dist/core/Abi.d.ts.map +1 -1
- package/dist/core/Abi.js +6 -3
- package/dist/core/Abi.js.map +1 -1
- package/dist/core/AbiConstructor.d.ts +2 -1
- package/dist/core/AbiConstructor.d.ts.map +1 -1
- package/dist/core/AbiConstructor.js +2 -2
- package/dist/core/AbiConstructor.js.map +1 -1
- package/dist/core/AbiError.d.ts +3 -1
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +2 -2
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +3 -1
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +2 -2
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +3 -1
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +2 -2
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts +6 -3
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +9 -7
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/AbiParameter.d.ts +88 -0
- package/dist/core/AbiParameter.d.ts.map +1 -0
- package/dist/core/AbiParameter.js +82 -0
- package/dist/core/AbiParameter.js.map +1 -0
- package/dist/core/AbiParameters.d.ts +58 -2
- package/dist/core/AbiParameters.d.ts.map +1 -1
- package/dist/core/AbiParameters.js +60 -6
- package/dist/core/AbiParameters.js.map +1 -1
- package/dist/core/Rlp.d.ts +27 -5
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +40 -4
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcSchema.d.ts +2 -2
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +21 -3
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/human-readable/errors.d.ts +103 -0
- package/dist/core/internal/human-readable/errors.d.ts.map +1 -0
- package/dist/core/internal/human-readable/errors.js +142 -0
- package/dist/core/internal/human-readable/errors.js.map +1 -0
- package/dist/core/internal/human-readable/formatAbi.d.ts +19 -0
- package/dist/core/internal/human-readable/formatAbi.d.ts.map +1 -0
- package/dist/core/internal/human-readable/formatAbi.js +18 -0
- package/dist/core/internal/human-readable/formatAbi.js.map +1 -0
- package/dist/core/internal/human-readable/formatAbiItem.d.ts +23 -0
- package/dist/core/internal/human-readable/formatAbiItem.d.ts.map +1 -0
- package/dist/core/internal/human-readable/formatAbiItem.js +25 -0
- package/dist/core/internal/human-readable/formatAbiItem.js.map +1 -0
- package/dist/core/internal/human-readable/formatAbiParameter.d.ts +41 -0
- package/dist/core/internal/human-readable/formatAbiParameter.d.ts.map +1 -0
- package/dist/core/internal/human-readable/formatAbiParameter.js +36 -0
- package/dist/core/internal/human-readable/formatAbiParameter.js.map +1 -0
- package/dist/core/internal/human-readable/formatAbiParameters.d.ts +26 -0
- package/dist/core/internal/human-readable/formatAbiParameters.d.ts.map +1 -0
- package/dist/core/internal/human-readable/formatAbiParameters.js +19 -0
- package/dist/core/internal/human-readable/formatAbiParameters.js.map +1 -0
- package/dist/core/internal/human-readable/parseAbi.d.ts +22 -0
- package/dist/core/internal/human-readable/parseAbi.d.ts.map +1 -0
- package/dist/core/internal/human-readable/parseAbi.js +22 -0
- package/dist/core/internal/human-readable/parseAbi.js.map +1 -0
- package/dist/core/internal/human-readable/parseAbiItem.d.ts +23 -0
- package/dist/core/internal/human-readable/parseAbiItem.d.ts.map +1 -0
- package/dist/core/internal/human-readable/parseAbiItem.js +30 -0
- package/dist/core/internal/human-readable/parseAbiItem.js.map +1 -0
- package/dist/core/internal/human-readable/parseAbiParameter.d.ts +28 -0
- package/dist/core/internal/human-readable/parseAbiParameter.d.ts.map +1 -0
- package/dist/core/internal/human-readable/parseAbiParameter.js +32 -0
- package/dist/core/internal/human-readable/parseAbiParameter.js.map +1 -0
- package/dist/core/internal/human-readable/parseAbiParameters.d.ts +38 -0
- package/dist/core/internal/human-readable/parseAbiParameters.d.ts.map +1 -0
- package/dist/core/internal/human-readable/parseAbiParameters.js +39 -0
- package/dist/core/internal/human-readable/parseAbiParameters.js.map +1 -0
- package/dist/core/internal/human-readable/regex.d.ts +9 -0
- package/dist/core/internal/human-readable/regex.d.ts.map +1 -0
- package/dist/core/internal/human-readable/regex.js +12 -0
- package/dist/core/internal/human-readable/regex.js.map +1 -0
- package/dist/core/internal/human-readable/runtime/cache.d.ts +22 -0
- package/dist/core/internal/human-readable/runtime/cache.d.ts.map +1 -0
- package/dist/core/internal/human-readable/runtime/cache.js +86 -0
- package/dist/core/internal/human-readable/runtime/cache.js.map +1 -0
- package/dist/core/internal/human-readable/runtime/signatures.d.ts +39 -0
- package/dist/core/internal/human-readable/runtime/signatures.d.ts.map +1 -0
- package/dist/core/internal/human-readable/runtime/signatures.js +67 -0
- package/dist/core/internal/human-readable/runtime/signatures.js.map +1 -0
- package/dist/core/internal/human-readable/runtime/structs.d.ts +3 -0
- package/dist/core/internal/human-readable/runtime/structs.d.ts.map +1 -0
- package/dist/core/internal/human-readable/runtime/structs.js +79 -0
- package/dist/core/internal/human-readable/runtime/structs.js.map +1 -0
- package/dist/core/internal/human-readable/runtime/utils.d.ts +205 -0
- package/dist/core/internal/human-readable/runtime/utils.d.ts.map +1 -0
- package/dist/core/internal/human-readable/runtime/utils.js +232 -0
- package/dist/core/internal/human-readable/runtime/utils.js.map +1 -0
- package/dist/core/internal/human-readable/types/signatures.d.ts +38 -0
- package/dist/core/internal/human-readable/types/signatures.d.ts.map +1 -0
- package/dist/core/internal/human-readable/types/signatures.js +2 -0
- package/dist/core/internal/human-readable/types/signatures.js.map +1 -0
- package/dist/core/internal/human-readable/types/structs.d.ts +48 -0
- package/dist/core/internal/human-readable/types/structs.d.ts.map +1 -0
- package/dist/core/internal/human-readable/types/structs.js +2 -0
- package/dist/core/internal/human-readable/types/structs.js.map +1 -0
- package/dist/core/internal/human-readable/types/utils.d.ts +163 -0
- package/dist/core/internal/human-readable/types/utils.d.ts.map +1 -0
- package/dist/core/internal/human-readable/types/utils.js +2 -0
- package/dist/core/internal/human-readable/types/utils.js.map +1 -0
- package/dist/core/internal/human-readable/types.d.ts +29 -0
- package/dist/core/internal/human-readable/types.d.ts.map +1 -0
- package/dist/core/internal/human-readable/types.js +2 -0
- package/dist/core/internal/human-readable/types.js.map +1 -0
- package/dist/core/internal/rpcSchemas/eth.d.ts +36 -0
- package/dist/core/internal/rpcSchemas/eth.d.ts.map +1 -1
- package/dist/erc4337/EntryPoint.d.ts +1072 -1
- package/dist/erc4337/EntryPoint.d.ts.map +1 -1
- package/dist/erc4337/EntryPoint.js +872 -0
- package/dist/erc4337/EntryPoint.js.map +1 -1
- package/dist/erc4337/RpcSchema.d.ts +2 -2
- package/dist/erc4337/RpcSchema.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.d.ts +39 -10
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +62 -48
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc4337/UserOperationGas.d.ts +9 -5
- package/dist/erc4337/UserOperationGas.d.ts.map +1 -1
- package/dist/erc4337/UserOperationGas.js +17 -15
- package/dist/erc4337/UserOperationGas.js.map +1 -1
- package/dist/erc4337/UserOperationReceipt.d.ts +4 -4
- package/dist/erc4337/UserOperationReceipt.d.ts.map +1 -1
- package/dist/erc4337/UserOperationReceipt.js.map +1 -1
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/tempo/Channel.d.ts +8 -14
- package/dist/tempo/Channel.d.ts.map +1 -1
- package/dist/tempo/Channel.js +4 -8
- package/dist/tempo/Channel.js.map +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +5 -5
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +4 -4
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/MultisigConfig.d.ts +37 -85
- package/dist/tempo/MultisigConfig.d.ts.map +1 -1
- package/dist/tempo/MultisigConfig.js +39 -83
- package/dist/tempo/MultisigConfig.js.map +1 -1
- package/dist/tempo/PoolId.d.ts +8 -7
- package/dist/tempo/PoolId.d.ts.map +1 -1
- package/dist/tempo/PoolId.js +10 -6
- package/dist/tempo/PoolId.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +32 -30
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +56 -51
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/Transaction.d.ts +16 -5
- package/dist/tempo/Transaction.d.ts.map +1 -1
- package/dist/tempo/Transaction.js +34 -7
- package/dist/tempo/Transaction.js.map +1 -1
- package/dist/tempo/TransactionReceipt.d.ts +3 -3
- package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
- package/dist/tempo/TransactionReceipt.js +8 -1
- package/dist/tempo/TransactionReceipt.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +15 -2
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +65 -29
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts +2 -3
- package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +5 -6
- package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/tempo/index.d.ts +6 -26
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +6 -26
- package/dist/tempo/index.js.map +1 -1
- package/dist/zod/Abi.d.ts +214 -0
- package/dist/zod/Abi.d.ts.map +1 -0
- package/dist/zod/Abi.js +5 -0
- package/dist/zod/Abi.js.map +1 -0
- package/dist/zod/AbiConstructor.d.ts +58 -0
- package/dist/zod/AbiConstructor.d.ts.map +1 -0
- package/dist/zod/AbiConstructor.js +18 -0
- package/dist/zod/AbiConstructor.js.map +1 -0
- package/dist/zod/AbiError.d.ts +20 -0
- package/dist/zod/AbiError.d.ts.map +1 -0
- package/dist/zod/AbiError.js +9 -0
- package/dist/zod/AbiError.js.map +1 -0
- package/dist/zod/AbiEvent.d.ts +23 -0
- package/dist/zod/AbiEvent.d.ts.map +1 -0
- package/dist/zod/AbiEvent.js +11 -0
- package/dist/zod/AbiEvent.js.map +1 -0
- package/dist/zod/AbiFallback.d.ts +16 -0
- package/dist/zod/AbiFallback.d.ts.map +1 -0
- package/dist/zod/AbiFallback.js +16 -0
- package/dist/zod/AbiFallback.js.map +1 -0
- package/dist/zod/AbiFunction.d.ts +109 -0
- package/dist/zod/AbiFunction.d.ts.map +1 -0
- package/dist/zod/AbiFunction.js +26 -0
- package/dist/zod/AbiFunction.js.map +1 -0
- package/dist/zod/AbiItem.d.ts +216 -0
- package/dist/zod/AbiItem.d.ts.map +1 -0
- package/dist/zod/AbiItem.js +26 -0
- package/dist/zod/AbiItem.js.map +1 -0
- package/dist/zod/AbiParameter.d.ts +32 -0
- package/dist/zod/AbiParameter.d.ts.map +1 -0
- package/dist/zod/AbiParameter.js +28 -0
- package/dist/zod/AbiParameter.js.map +1 -0
- package/dist/zod/AbiParameters.d.ts +30 -0
- package/dist/zod/AbiParameters.d.ts.map +1 -0
- package/dist/zod/AbiParameters.js +6 -0
- package/dist/zod/AbiParameters.js.map +1 -0
- package/dist/zod/AbiReceive.d.ts +6 -0
- package/dist/zod/AbiReceive.d.ts.map +1 -0
- package/dist/zod/AbiReceive.js +7 -0
- package/dist/zod/AbiReceive.js.map +1 -0
- package/dist/zod/RpcSchema.d.ts +6 -5
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/Solidity.d.ts +15 -0
- package/dist/zod/Solidity.d.ts.map +1 -0
- package/dist/zod/Solidity.js +41 -0
- package/dist/zod/Solidity.js.map +1 -0
- package/dist/zod/TypedData.d.ts +226 -0
- package/dist/zod/TypedData.d.ts.map +1 -0
- package/dist/zod/TypedData.js +84 -0
- package/dist/zod/TypedData.js.map +1 -0
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +1 -0
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Eth.js +5 -0
- package/dist/zod/internal/rpcSchemas/Eth.js.map +1 -1
- package/dist/zod/tempo/AuthorizationTempo.d.ts +0 -20
- package/dist/zod/tempo/AuthorizationTempo.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.d.ts +503 -67
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +32 -15
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +216 -34
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts +0 -6
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +0 -2
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +1479 -333
- package/dist/zod/tempo/Transaction.d.ts.map +1 -1
- package/dist/zod/tempo/Transaction.js +65 -16
- package/dist/zod/tempo/Transaction.js.map +1 -1
- package/dist/zod/tempo/TransactionRequest.d.ts +410 -57
- package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/zod/tempo/TransactionRequest.js +81 -18
- package/dist/zod/tempo/TransactionRequest.js.map +1 -1
- package/dist/zod/tempo/TxEnvelopeTempo.d.ts +225 -18
- package/dist/zod/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/zod/tempo/TxEnvelopeTempo.js +1 -1
- package/dist/zod/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/zod/tempo/ZoneRpcAuthentication.d.ts +0 -3
- package/dist/zod/tempo/ZoneRpcAuthentication.d.ts.map +1 -1
- package/dist/zod/tempo/z.d.ts +0 -1
- package/dist/zod/tempo/z.d.ts.map +1 -1
- package/dist/zod/tempo/z.js +0 -1
- package/dist/zod/tempo/z.js.map +1 -1
- package/dist/zod/z.d.ts +12 -0
- package/dist/zod/z.d.ts.map +1 -1
- package/dist/zod/z.js +12 -0
- package/dist/zod/z.js.map +1 -1
- package/package.json +67 -11
- package/src/core/Abi.bench.ts +30 -0
- package/src/core/Abi.ts +13 -4
- package/src/core/AbiConstructor.ts +3 -2
- package/src/core/AbiError.ts +6 -2
- package/src/core/AbiEvent.ts +6 -2
- package/src/core/AbiFunction.ts +6 -2
- package/src/core/AbiItem.bench.ts +19 -0
- package/src/core/AbiItem.ts +20 -10
- package/src/core/AbiParameter.bench.ts +35 -0
- package/src/core/AbiParameter.ts +126 -0
- package/src/core/AbiParameters.bench.ts +22 -0
- package/src/core/AbiParameters.ts +77 -8
- package/src/core/Rlp.ts +66 -3
- package/src/core/RpcSchema.ts +2 -2
- package/src/core/_test/Abi.test.ts +4 -0
- package/src/core/_test/AbiItem.test.ts +3 -0
- package/src/core/_test/AbiParameter.test-d.ts +41 -0
- package/src/core/_test/AbiParameter.test.ts +84 -0
- package/src/core/_test/AbiParameters.decode.test.ts +88 -12
- package/src/core/_test/AbiParameters.encode.test.ts +68 -0
- package/src/core/_test/AbiParameters.test.ts +7 -0
- package/src/core/_test/Rlp.test.ts +101 -0
- package/src/core/_test/index.test.ts +1 -0
- package/src/core/internal/abiParameters.ts +21 -3
- package/src/core/internal/human-readable/_snap/formatAbi.test.ts.snap +74 -0
- package/src/core/internal/human-readable/_snap/parseAbi.test.ts.snap +2353 -0
- package/src/core/internal/human-readable/errors.test.ts +258 -0
- package/src/core/internal/human-readable/errors.ts +205 -0
- package/src/core/internal/human-readable/formatAbi.test-d.ts +144 -0
- package/src/core/internal/human-readable/formatAbi.test.ts +23 -0
- package/src/core/internal/human-readable/formatAbi.ts +37 -0
- package/src/core/internal/human-readable/formatAbiItem.test-d.ts +115 -0
- package/src/core/internal/human-readable/formatAbiItem.test.ts +102 -0
- package/src/core/internal/human-readable/formatAbiItem.ts +136 -0
- package/src/core/internal/human-readable/formatAbiParameter.test-d.ts +125 -0
- package/src/core/internal/human-readable/formatAbiParameter.test.ts +126 -0
- package/src/core/internal/human-readable/formatAbiParameter.ts +86 -0
- package/src/core/internal/human-readable/formatAbiParameters.test-d.ts +92 -0
- package/src/core/internal/human-readable/formatAbiParameters.test.ts +32 -0
- package/src/core/internal/human-readable/formatAbiParameters.ts +46 -0
- package/src/core/internal/human-readable/human-readable.bench-d.ts +58 -0
- package/src/core/internal/human-readable/integration.test.ts +68 -0
- package/src/core/internal/human-readable/parseAbi.test-d.ts +188 -0
- package/src/core/internal/human-readable/parseAbi.test.ts +82 -0
- package/src/core/internal/human-readable/parseAbi.ts +59 -0
- package/src/core/internal/human-readable/parseAbiItem.test-d.ts +183 -0
- package/src/core/internal/human-readable/parseAbiItem.test.ts +264 -0
- package/src/core/internal/human-readable/parseAbiItem.ts +91 -0
- package/src/core/internal/human-readable/parseAbiParameter.test-d.ts +68 -0
- package/src/core/internal/human-readable/parseAbiParameter.test.ts +207 -0
- package/src/core/internal/human-readable/parseAbiParameter.ts +95 -0
- package/src/core/internal/human-readable/parseAbiParameters.test-d.ts +160 -0
- package/src/core/internal/human-readable/parseAbiParameters.test.ts +80 -0
- package/src/core/internal/human-readable/parseAbiParameters.ts +123 -0
- package/src/core/internal/human-readable/regex.ts +15 -0
- package/src/core/internal/human-readable/runtime/cache.ts +96 -0
- package/src/core/internal/human-readable/runtime/signatures.test.ts +236 -0
- package/src/core/internal/human-readable/runtime/signatures.ts +106 -0
- package/src/core/internal/human-readable/runtime/structs.test.ts +210 -0
- package/src/core/internal/human-readable/runtime/structs.ts +97 -0
- package/src/core/internal/human-readable/runtime/utils.test.ts +717 -0
- package/src/core/internal/human-readable/runtime/utils.ts +344 -0
- package/src/core/internal/human-readable/types/signatures.test-d.ts +255 -0
- package/src/core/internal/human-readable/types/signatures.ts +369 -0
- package/src/core/internal/human-readable/types/structs.test-d.ts +221 -0
- package/src/core/internal/human-readable/types/structs.ts +88 -0
- package/src/core/internal/human-readable/types/utils.test-d.ts +1029 -0
- package/src/core/internal/human-readable/types/utils.ts +392 -0
- package/src/core/internal/human-readable/types.ts +69 -0
- package/src/core/internal/rpcSchemas/eth.ts +36 -0
- package/src/erc4337/EntryPoint.ts +875 -1
- package/src/erc4337/RpcSchema.ts +4 -2
- package/src/erc4337/UserOperation.ts +130 -60
- package/src/erc4337/UserOperationGas.ts +36 -28
- package/src/erc4337/UserOperationReceipt.ts +15 -7
- package/src/erc4337/_test/EntryPoint.test.ts +48 -0
- package/src/erc4337/_test/RpcSchema.test-d.ts +56 -0
- package/src/erc4337/_test/UserOperation.snap-d.ts +31 -0
- package/src/erc4337/_test/UserOperation.test.ts +221 -5
- package/src/erc4337/_test/UserOperationGas.test.ts +30 -1
- package/src/index.ts +38 -0
- package/src/tempo/Channel.test.ts +2 -23
- package/src/tempo/Channel.ts +10 -22
- package/src/tempo/KeyAuthorization.test.ts +22 -0
- package/src/tempo/KeyAuthorization.ts +9 -9
- package/src/tempo/MultisigConfig.test.ts +54 -37
- package/src/tempo/MultisigConfig.ts +59 -134
- package/src/tempo/PoolId.test.ts +7 -41
- package/src/tempo/PoolId.ts +15 -10
- package/src/tempo/SignatureEnvelope.test.ts +118 -17
- package/src/tempo/SignatureEnvelope.ts +77 -72
- package/src/tempo/Transaction.test.ts +0 -15
- package/src/tempo/Transaction.ts +63 -12
- package/src/tempo/TransactionReceipt.test.ts +76 -0
- package/src/tempo/TransactionReceipt.ts +11 -5
- package/src/tempo/TransactionRequest.test.ts +174 -1
- package/src/tempo/TransactionRequest.ts +84 -32
- package/src/tempo/TxEnvelopeTempo.test.ts +2 -2
- package/src/tempo/TxEnvelopeTempo.ts +7 -7
- package/src/tempo/e2e.test.ts +228 -50
- package/src/tempo/index.ts +6 -26
- package/src/version.ts +1 -1
- package/src/zod/Abi.ts +5 -0
- package/src/zod/AbiConstructor.ts +24 -0
- package/src/zod/AbiError.ts +9 -0
- package/src/zod/AbiEvent.ts +11 -0
- package/src/zod/AbiFallback.ts +22 -0
- package/src/zod/AbiFunction.ts +32 -0
- package/src/zod/AbiItem.ts +28 -0
- package/src/zod/AbiParameter.ts +36 -0
- package/src/zod/AbiParameters.ts +7 -0
- package/src/zod/AbiReceive.ts +7 -0
- package/src/zod/RpcSchema.ts +5 -5
- package/src/zod/Solidity.ts +83 -0
- package/src/zod/TypedData.ts +111 -0
- package/src/zod/_test/Abi.test-d.ts +46 -0
- package/src/zod/_test/Abi.test.ts +163 -0
- package/src/zod/_test/TypedData.test-d.ts +20 -0
- package/src/zod/_test/TypedData.test.ts +87 -0
- package/src/zod/_test/z.test-d.ts +6 -0
- package/src/zod/_test/z.test.ts +17 -0
- package/src/zod/internal/rpcSchemas/Eth.ts +6 -0
- package/src/zod/tempo/KeyAuthorization.ts +34 -15
- package/src/zod/tempo/SignatureEnvelope.ts +0 -2
- package/src/zod/tempo/Transaction.ts +84 -22
- package/src/zod/tempo/TransactionRequest.ts +86 -20
- package/src/zod/tempo/TxEnvelopeTempo.ts +1 -1
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +53 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +0 -2
- package/src/zod/tempo/_test/Transaction.test.ts +155 -0
- package/src/zod/tempo/_test/TransactionRequest.test.ts +44 -0
- package/src/zod/tempo/z.ts +0 -1
- package/src/zod/z.ts +12 -0
- package/dist/tempo/TokenId.d.ts +0 -87
- package/dist/tempo/TokenId.d.ts.map +0 -1
- package/dist/tempo/TokenId.js +0 -123
- package/dist/tempo/TokenId.js.map +0 -1
- package/dist/zod/tempo/TokenId.d.ts +0 -6
- package/dist/zod/tempo/TokenId.d.ts.map +0 -1
- package/dist/zod/tempo/TokenId.js +0 -14
- package/dist/zod/tempo/TokenId.js.map +0 -1
- package/src/CHANGELOG.md +0 -820
- package/src/tempo/TokenId.bench.ts +0 -36
- package/src/tempo/TokenId.test.ts +0 -79
- package/src/tempo/TokenId.ts +0 -141
- package/src/zod/tempo/TokenId.ts +0 -15
- package/src/zod/tempo/_test/TokenId.test-d.ts +0 -17
- package/src/zod/tempo/_test/TokenId.test.ts +0 -21
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import type { AbiStateMutability } from 'abitype'
|
|
2
|
+
import type { Error } from '../types.js'
|
|
3
|
+
|
|
4
|
+
export type ErrorSignature<
|
|
5
|
+
name extends string = string,
|
|
6
|
+
parameters extends string = string,
|
|
7
|
+
> = `error ${name}(${parameters})`
|
|
8
|
+
export type IsErrorSignature<signature extends string> =
|
|
9
|
+
signature extends ErrorSignature<infer name> ? IsName<name> : false
|
|
10
|
+
export type EventSignature<
|
|
11
|
+
name extends string = string,
|
|
12
|
+
parameters extends string = string,
|
|
13
|
+
> = `event ${name}(${parameters})`
|
|
14
|
+
export type IsEventSignature<signature extends string> =
|
|
15
|
+
signature extends EventSignature<infer name> ? IsName<name> : false
|
|
16
|
+
|
|
17
|
+
export type FunctionSignature<
|
|
18
|
+
name extends string = string,
|
|
19
|
+
tail extends string = string,
|
|
20
|
+
> = `function ${name}(${tail}`
|
|
21
|
+
export type IsFunctionSignature<signature> =
|
|
22
|
+
signature extends FunctionSignature<infer name>
|
|
23
|
+
? IsName<name> extends true
|
|
24
|
+
? signature extends ValidFunctionSignatures
|
|
25
|
+
? true
|
|
26
|
+
: // Check that `Parameters` is not absorbing other types (e.g. `returns`)
|
|
27
|
+
signature extends `function ${string}(${infer parameters})`
|
|
28
|
+
? parameters extends InvalidFunctionParameters
|
|
29
|
+
? false
|
|
30
|
+
: true
|
|
31
|
+
: false
|
|
32
|
+
: false
|
|
33
|
+
: false
|
|
34
|
+
export type Scope = 'public' | 'external' // `internal` or `private` functions wouldn't make it to ABI so can ignore
|
|
35
|
+
type Returns = `returns (${string})` | `returns(${string})`
|
|
36
|
+
// Almost all valid function signatures, except `function ${string}(${infer parameters})` since `parameters` can absorb returns
|
|
37
|
+
type ValidFunctionSignatures =
|
|
38
|
+
| `function ${string}()`
|
|
39
|
+
// basic
|
|
40
|
+
| `function ${string}() ${Returns}`
|
|
41
|
+
| `function ${string}() ${AbiStateMutability}`
|
|
42
|
+
| `function ${string}() ${Scope}`
|
|
43
|
+
// combinations
|
|
44
|
+
| `function ${string}() ${AbiStateMutability} ${Returns}`
|
|
45
|
+
| `function ${string}() ${Scope} ${Returns}`
|
|
46
|
+
| `function ${string}() ${Scope} ${AbiStateMutability}`
|
|
47
|
+
| `function ${string}() ${Scope} ${AbiStateMutability} ${Returns}`
|
|
48
|
+
// Parameters
|
|
49
|
+
| `function ${string}(${string}) ${Returns}`
|
|
50
|
+
| `function ${string}(${string}) ${AbiStateMutability}`
|
|
51
|
+
| `function ${string}(${string}) ${Scope}`
|
|
52
|
+
| `function ${string}(${string}) ${AbiStateMutability} ${Returns}`
|
|
53
|
+
| `function ${string}(${string}) ${Scope} ${Returns}`
|
|
54
|
+
| `function ${string}(${string}) ${Scope} ${AbiStateMutability}`
|
|
55
|
+
| `function ${string}(${string}) ${Scope} ${AbiStateMutability} ${Returns}`
|
|
56
|
+
|
|
57
|
+
export type StructSignature<
|
|
58
|
+
name extends string = string,
|
|
59
|
+
properties extends string = string,
|
|
60
|
+
> = `struct ${name} {${properties}}`
|
|
61
|
+
export type IsStructSignature<signature extends string> =
|
|
62
|
+
signature extends StructSignature<infer name> ? IsName<name> : false
|
|
63
|
+
|
|
64
|
+
type ConstructorSignature<tail extends string = string> = `constructor(${tail}`
|
|
65
|
+
export type IsConstructorSignature<signature> =
|
|
66
|
+
signature extends ConstructorSignature
|
|
67
|
+
? signature extends ValidConstructorSignatures
|
|
68
|
+
? true
|
|
69
|
+
: false
|
|
70
|
+
: false
|
|
71
|
+
type ValidConstructorSignatures =
|
|
72
|
+
| `constructor(${string})`
|
|
73
|
+
| `constructor(${string}) payable`
|
|
74
|
+
|
|
75
|
+
export type FallbackSignature<
|
|
76
|
+
abiStateMutability extends '' | ' payable' = '' | ' payable',
|
|
77
|
+
> = `fallback() external${abiStateMutability}`
|
|
78
|
+
export type IsFallbackSignature<signature extends string> = signature extends
|
|
79
|
+
| FallbackSignature<''>
|
|
80
|
+
| FallbackSignature<' payable'>
|
|
81
|
+
? true
|
|
82
|
+
: false
|
|
83
|
+
|
|
84
|
+
export type ReceiveSignature = 'receive() external payable'
|
|
85
|
+
|
|
86
|
+
// TODO: Maybe use this for signature validation one day
|
|
87
|
+
// https://twitter.com/devanshj__/status/1610423724708343808
|
|
88
|
+
export type IsSignature<type extends string> =
|
|
89
|
+
| (IsErrorSignature<type> extends true ? true : never)
|
|
90
|
+
| (IsEventSignature<type> extends true ? true : never)
|
|
91
|
+
| (IsFunctionSignature<type> extends true ? true : never)
|
|
92
|
+
| (IsStructSignature<type> extends true ? true : never)
|
|
93
|
+
| (IsConstructorSignature<type> extends true ? true : never)
|
|
94
|
+
| (IsFallbackSignature<type> extends true ? true : never)
|
|
95
|
+
| (type extends ReceiveSignature ? true : never) extends infer condition
|
|
96
|
+
? [condition] extends [never]
|
|
97
|
+
? false
|
|
98
|
+
: true
|
|
99
|
+
: false
|
|
100
|
+
|
|
101
|
+
export type Signature<
|
|
102
|
+
string1 extends string,
|
|
103
|
+
string2 extends string | unknown = unknown,
|
|
104
|
+
> =
|
|
105
|
+
IsSignature<string1> extends true
|
|
106
|
+
? string1
|
|
107
|
+
: string extends string1 // if exactly `string` (not narrowed), then pass through as valid
|
|
108
|
+
? string1
|
|
109
|
+
: Error<`Signature "${string1}" is invalid${string2 extends string
|
|
110
|
+
? ` at position ${string2}`
|
|
111
|
+
: ''}.`>
|
|
112
|
+
|
|
113
|
+
export type Signatures<signatures extends readonly string[]> = {
|
|
114
|
+
[key in keyof signatures]: Signature<signatures[key], key>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type Modifier = 'calldata' | 'indexed' | 'memory' | 'payable' | 'storage'
|
|
118
|
+
export type FunctionModifier = Extract<
|
|
119
|
+
Modifier,
|
|
120
|
+
'calldata' | 'memory' | 'payable' | 'storage'
|
|
121
|
+
>
|
|
122
|
+
export type EventModifier = Extract<Modifier, 'indexed'>
|
|
123
|
+
|
|
124
|
+
export type IsName<name extends string> = name extends ''
|
|
125
|
+
? false
|
|
126
|
+
: ValidateName<name> extends name
|
|
127
|
+
? true
|
|
128
|
+
: false
|
|
129
|
+
|
|
130
|
+
export type AssertName<name extends string> =
|
|
131
|
+
ValidateName<name> extends infer invalidName extends string[]
|
|
132
|
+
? `[${invalidName[number]}]`
|
|
133
|
+
: name
|
|
134
|
+
|
|
135
|
+
export type ValidateName<
|
|
136
|
+
name extends string,
|
|
137
|
+
checkCharacters extends boolean = false,
|
|
138
|
+
> = name extends `${string}${' '}${string}`
|
|
139
|
+
? Error<`Identifier "${name}" cannot contain whitespace.`>
|
|
140
|
+
: IsSolidityKeyword<name> extends true
|
|
141
|
+
? Error<`"${name}" is a protected Solidity keyword.`>
|
|
142
|
+
: name extends `${number}`
|
|
143
|
+
? Error<`Identifier "${name}" cannot be a number string.`>
|
|
144
|
+
: name extends `${number}${string}`
|
|
145
|
+
? Error<`Identifier "${name}" cannot start with a number.`>
|
|
146
|
+
: checkCharacters extends true
|
|
147
|
+
? IsValidCharacter<name> extends true
|
|
148
|
+
? name
|
|
149
|
+
: Error<`"${name}" contains invalid character.`>
|
|
150
|
+
: name
|
|
151
|
+
|
|
152
|
+
export type IsSolidityKeyword<type extends string> =
|
|
153
|
+
type extends SolidityKeywords ? true : false
|
|
154
|
+
|
|
155
|
+
export type SolidityKeywords =
|
|
156
|
+
| 'after'
|
|
157
|
+
| 'alias'
|
|
158
|
+
| 'anonymous'
|
|
159
|
+
| 'apply'
|
|
160
|
+
| 'auto'
|
|
161
|
+
| 'byte'
|
|
162
|
+
| 'calldata'
|
|
163
|
+
| 'case'
|
|
164
|
+
| 'catch'
|
|
165
|
+
| 'constant'
|
|
166
|
+
| 'copyof'
|
|
167
|
+
| 'default'
|
|
168
|
+
| 'defined'
|
|
169
|
+
| 'error'
|
|
170
|
+
| 'event'
|
|
171
|
+
| 'external'
|
|
172
|
+
| 'false'
|
|
173
|
+
| 'final'
|
|
174
|
+
| 'function'
|
|
175
|
+
| 'immutable'
|
|
176
|
+
| 'implements'
|
|
177
|
+
| 'in'
|
|
178
|
+
| 'indexed'
|
|
179
|
+
| 'inline'
|
|
180
|
+
| 'internal'
|
|
181
|
+
| 'let'
|
|
182
|
+
| 'mapping'
|
|
183
|
+
| 'match'
|
|
184
|
+
| 'memory'
|
|
185
|
+
| 'mutable'
|
|
186
|
+
| 'null'
|
|
187
|
+
| 'of'
|
|
188
|
+
| 'override'
|
|
189
|
+
| 'partial'
|
|
190
|
+
| 'private'
|
|
191
|
+
| 'promise'
|
|
192
|
+
| 'public'
|
|
193
|
+
| 'pure'
|
|
194
|
+
| 'reference'
|
|
195
|
+
| 'relocatable'
|
|
196
|
+
| 'return'
|
|
197
|
+
| 'returns'
|
|
198
|
+
| 'sizeof'
|
|
199
|
+
| 'static'
|
|
200
|
+
| 'storage'
|
|
201
|
+
| 'struct'
|
|
202
|
+
| 'super'
|
|
203
|
+
| 'supports'
|
|
204
|
+
| 'switch'
|
|
205
|
+
| 'this'
|
|
206
|
+
| 'true'
|
|
207
|
+
| 'try'
|
|
208
|
+
| 'typedef'
|
|
209
|
+
| 'typeof'
|
|
210
|
+
| 'var'
|
|
211
|
+
| 'view'
|
|
212
|
+
| 'virtual'
|
|
213
|
+
| `address${`[${string}]` | ''}`
|
|
214
|
+
| `bool${`[${string}]` | ''}`
|
|
215
|
+
| `string${`[${string}]` | ''}`
|
|
216
|
+
| `tuple${`[${string}]` | ''}`
|
|
217
|
+
| `bytes${number | ''}${`[${string}]` | ''}`
|
|
218
|
+
| `${'u' | ''}int${number | ''}${`[${string}]` | ''}`
|
|
219
|
+
|
|
220
|
+
export type IsValidCharacter<character extends string> =
|
|
221
|
+
character extends `${ValidCharacters}${infer tail}`
|
|
222
|
+
? tail extends ''
|
|
223
|
+
? true
|
|
224
|
+
: IsValidCharacter<tail>
|
|
225
|
+
: false
|
|
226
|
+
|
|
227
|
+
// biome-ignore format: no formatting
|
|
228
|
+
type ValidCharacters =
|
|
229
|
+
// uppercase letters
|
|
230
|
+
| 'A'
|
|
231
|
+
| 'B'
|
|
232
|
+
| 'C'
|
|
233
|
+
| 'D'
|
|
234
|
+
| 'E'
|
|
235
|
+
| 'F'
|
|
236
|
+
| 'G'
|
|
237
|
+
| 'H'
|
|
238
|
+
| 'I'
|
|
239
|
+
| 'J'
|
|
240
|
+
| 'K'
|
|
241
|
+
| 'L'
|
|
242
|
+
| 'M'
|
|
243
|
+
| 'N'
|
|
244
|
+
| 'O'
|
|
245
|
+
| 'P'
|
|
246
|
+
| 'Q'
|
|
247
|
+
| 'R'
|
|
248
|
+
| 'S'
|
|
249
|
+
| 'T'
|
|
250
|
+
| 'U'
|
|
251
|
+
| 'V'
|
|
252
|
+
| 'W'
|
|
253
|
+
| 'X'
|
|
254
|
+
| 'Y'
|
|
255
|
+
| 'Z'
|
|
256
|
+
// lowercase letters
|
|
257
|
+
| 'a'
|
|
258
|
+
| 'b'
|
|
259
|
+
| 'c'
|
|
260
|
+
| 'd'
|
|
261
|
+
| 'e'
|
|
262
|
+
| 'f'
|
|
263
|
+
| 'g'
|
|
264
|
+
| 'h'
|
|
265
|
+
| 'i'
|
|
266
|
+
| 'j'
|
|
267
|
+
| 'k'
|
|
268
|
+
| 'l'
|
|
269
|
+
| 'm'
|
|
270
|
+
| 'n'
|
|
271
|
+
| 'o'
|
|
272
|
+
| 'p'
|
|
273
|
+
| 'q'
|
|
274
|
+
| 'r'
|
|
275
|
+
| 's'
|
|
276
|
+
| 't'
|
|
277
|
+
| 'u'
|
|
278
|
+
| 'v'
|
|
279
|
+
| 'w'
|
|
280
|
+
| 'x'
|
|
281
|
+
| 'y'
|
|
282
|
+
| 'z'
|
|
283
|
+
// numbers
|
|
284
|
+
| '0'
|
|
285
|
+
| '1'
|
|
286
|
+
| '2'
|
|
287
|
+
| '3'
|
|
288
|
+
| '4'
|
|
289
|
+
| '5'
|
|
290
|
+
| '6'
|
|
291
|
+
| '7'
|
|
292
|
+
| '8'
|
|
293
|
+
| '9'
|
|
294
|
+
// special characters
|
|
295
|
+
| '_'
|
|
296
|
+
| '$'
|
|
297
|
+
|
|
298
|
+
// Template string inference can absorb `returns`:
|
|
299
|
+
// type Result = `function foo(string) return s (uint256)` extends `function ${string}(${infer Parameters})` ? Parameters : never
|
|
300
|
+
// // ^? type Result = "string ) return s (uint256"
|
|
301
|
+
// So we need to validate against `returns` keyword with all combinations of whitespace
|
|
302
|
+
type InvalidFunctionParameters =
|
|
303
|
+
| `${string}${MangledReturns} (${string}`
|
|
304
|
+
| `${string}) ${MangledReturns}${string}`
|
|
305
|
+
| `${string})${string}${MangledReturns}${string}(${string}`
|
|
306
|
+
// r_e_t_u_r_n_s
|
|
307
|
+
type MangledReturns =
|
|
308
|
+
// Single
|
|
309
|
+
| `r${string}eturns`
|
|
310
|
+
| `re${string}turns`
|
|
311
|
+
| `ret${string}urns`
|
|
312
|
+
| `retu${string}rns`
|
|
313
|
+
| `retur${string}ns`
|
|
314
|
+
| `return${string}s`
|
|
315
|
+
// Double
|
|
316
|
+
// `r_e*`
|
|
317
|
+
| `r${string}e${string}turns`
|
|
318
|
+
| `r${string}et${string}urns`
|
|
319
|
+
| `r${string}etu${string}rns`
|
|
320
|
+
| `r${string}etur${string}ns`
|
|
321
|
+
| `r${string}eturn${string}s`
|
|
322
|
+
// `re_t*`
|
|
323
|
+
| `re${string}t${string}urns`
|
|
324
|
+
| `re${string}tu${string}rns`
|
|
325
|
+
| `re${string}tur${string}ns`
|
|
326
|
+
| `re${string}turn${string}s`
|
|
327
|
+
// `ret_u*`
|
|
328
|
+
| `ret${string}u${string}rns`
|
|
329
|
+
| `ret${string}ur${string}ns`
|
|
330
|
+
| `ret${string}urn${string}s`
|
|
331
|
+
// `retu_r*`
|
|
332
|
+
| `retu${string}r${string}ns`
|
|
333
|
+
| `retu${string}rn${string}s`
|
|
334
|
+
// `retur_n*`
|
|
335
|
+
| `retur${string}n${string}s`
|
|
336
|
+
// Triple
|
|
337
|
+
// `r_e_t*`
|
|
338
|
+
| `r${string}e${string}t${string}urns`
|
|
339
|
+
| `r${string}e${string}tu${string}rns`
|
|
340
|
+
| `r${string}e${string}tur${string}ns`
|
|
341
|
+
| `r${string}e${string}turn${string}s`
|
|
342
|
+
// `re_t_u*`
|
|
343
|
+
| `re${string}t${string}u${string}rns`
|
|
344
|
+
| `re${string}t${string}ur${string}ns`
|
|
345
|
+
| `re${string}t${string}urn${string}s`
|
|
346
|
+
// `ret_u_r*`
|
|
347
|
+
| `ret${string}u${string}r${string}ns`
|
|
348
|
+
| `ret${string}u${string}rn${string}s`
|
|
349
|
+
// `retu_r_n*`
|
|
350
|
+
| `retu${string}r${string}n${string}s`
|
|
351
|
+
// Quadruple
|
|
352
|
+
// `r_e_t_u*`
|
|
353
|
+
| `r${string}e${string}t${string}u${string}rns`
|
|
354
|
+
| `r${string}e${string}t${string}ur${string}ns`
|
|
355
|
+
| `r${string}e${string}t${string}urn${string}s`
|
|
356
|
+
// `re_t_u_r*`
|
|
357
|
+
| `re${string}t${string}u${string}r${string}ns`
|
|
358
|
+
| `re${string}t${string}u${string}rn${string}s`
|
|
359
|
+
// `ret_u_r_n*`
|
|
360
|
+
| `ret${string}u${string}r${string}n${string}s`
|
|
361
|
+
// Quintuple
|
|
362
|
+
// `r_e_t_u_r*`
|
|
363
|
+
| `r${string}e${string}t${string}u${string}r${string}ns`
|
|
364
|
+
| `r${string}e${string}t${string}u${string}rn${string}s`
|
|
365
|
+
// `re_t_u_r_n*`
|
|
366
|
+
| `re${string}t${string}u${string}r${string}n${string}s`
|
|
367
|
+
// Sextuple
|
|
368
|
+
// `r_e_t_u_r_n_s`
|
|
369
|
+
| `r${string}e${string}t${string}u${string}r${string}n${string}s`
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ParseStruct,
|
|
5
|
+
ParseStructProperties,
|
|
6
|
+
ParseStructs,
|
|
7
|
+
ResolveStructs,
|
|
8
|
+
StructLookup,
|
|
9
|
+
} from './structs.js'
|
|
10
|
+
|
|
11
|
+
test('ParseStructs', () => {
|
|
12
|
+
type Result = ParseStructs<
|
|
13
|
+
[
|
|
14
|
+
'struct Person { Name name; }',
|
|
15
|
+
'struct Name { Foo foo; }',
|
|
16
|
+
'struct Foo { string bar; }',
|
|
17
|
+
'function addPerson(Person person)',
|
|
18
|
+
]
|
|
19
|
+
>
|
|
20
|
+
expectTypeOf<Result>().toEqualTypeOf<{
|
|
21
|
+
Person: readonly [
|
|
22
|
+
{
|
|
23
|
+
readonly name: 'name'
|
|
24
|
+
readonly type: 'tuple'
|
|
25
|
+
readonly components: readonly [
|
|
26
|
+
{
|
|
27
|
+
readonly name: 'foo'
|
|
28
|
+
readonly type: 'tuple'
|
|
29
|
+
readonly components: readonly [
|
|
30
|
+
{
|
|
31
|
+
readonly type: 'string'
|
|
32
|
+
readonly name: 'bar'
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
Foo: readonly [{ readonly type: 'string'; readonly name: 'bar' }]
|
|
40
|
+
Name: readonly [
|
|
41
|
+
{
|
|
42
|
+
readonly type: 'tuple'
|
|
43
|
+
readonly name: 'foo'
|
|
44
|
+
readonly components: readonly [
|
|
45
|
+
{ readonly type: 'string'; readonly name: 'bar' },
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
}>()
|
|
50
|
+
|
|
51
|
+
expectTypeOf<
|
|
52
|
+
ParseStructs<['struct Foo { Bar bar; }', 'struct Bar { Foo foo; }']>
|
|
53
|
+
>().toEqualTypeOf<{
|
|
54
|
+
Foo: readonly [
|
|
55
|
+
{
|
|
56
|
+
readonly name: 'bar'
|
|
57
|
+
readonly type: 'tuple'
|
|
58
|
+
readonly components: readonly [
|
|
59
|
+
{
|
|
60
|
+
readonly name: 'foo'
|
|
61
|
+
readonly type: 'tuple'
|
|
62
|
+
readonly components: readonly [
|
|
63
|
+
[
|
|
64
|
+
'Error: Circular reference detected. Struct "Bar" is a circular reference.',
|
|
65
|
+
],
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
Bar: readonly [
|
|
72
|
+
{
|
|
73
|
+
readonly name: 'foo'
|
|
74
|
+
readonly type: 'tuple'
|
|
75
|
+
readonly components: readonly [
|
|
76
|
+
{
|
|
77
|
+
readonly name: 'bar'
|
|
78
|
+
readonly type: 'tuple'
|
|
79
|
+
readonly components: readonly [
|
|
80
|
+
[
|
|
81
|
+
'Error: Circular reference detected. Struct "Foo" is a circular reference.',
|
|
82
|
+
],
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
}>()
|
|
89
|
+
|
|
90
|
+
expectTypeOf<ParseStructs<['struct Foo { Foo foo; }']>>().toEqualTypeOf<{
|
|
91
|
+
Foo: readonly [
|
|
92
|
+
{
|
|
93
|
+
readonly name: 'foo'
|
|
94
|
+
readonly type: 'tuple'
|
|
95
|
+
readonly components: readonly [
|
|
96
|
+
[
|
|
97
|
+
'Error: Circular reference detected. Struct "Foo" is a circular reference.',
|
|
98
|
+
],
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
]
|
|
102
|
+
}>()
|
|
103
|
+
|
|
104
|
+
expectTypeOf<
|
|
105
|
+
ParseStructs<['struct Person { Name name;']>
|
|
106
|
+
>().toEqualTypeOf<{}>()
|
|
107
|
+
|
|
108
|
+
expectTypeOf<ParseStructs<[]>>().toEqualTypeOf<{}>()
|
|
109
|
+
expectTypeOf<
|
|
110
|
+
ParseStructs<['function addPerson(Person person)']>
|
|
111
|
+
>().toEqualTypeOf<{}>()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('ParseStruct', () => {
|
|
115
|
+
expectTypeOf<
|
|
116
|
+
ParseStruct<'struct Foo { string foo; string bar; }'>
|
|
117
|
+
>().toEqualTypeOf<{
|
|
118
|
+
readonly name: 'Foo'
|
|
119
|
+
readonly components: [
|
|
120
|
+
{ readonly type: 'string'; readonly name: 'foo' },
|
|
121
|
+
{ readonly type: 'string'; readonly name: 'bar' },
|
|
122
|
+
]
|
|
123
|
+
}>()
|
|
124
|
+
expectTypeOf<ParseStruct<'struct Foo {}'>>().toEqualTypeOf<{
|
|
125
|
+
readonly name: 'Foo'
|
|
126
|
+
readonly components: []
|
|
127
|
+
}>()
|
|
128
|
+
expectTypeOf<ParseStruct<'struct Foo { Bar bar; }'>>().toEqualTypeOf<{
|
|
129
|
+
readonly name: 'Foo'
|
|
130
|
+
readonly components: [
|
|
131
|
+
{
|
|
132
|
+
readonly type: 'Bar'
|
|
133
|
+
readonly name: 'bar'
|
|
134
|
+
},
|
|
135
|
+
]
|
|
136
|
+
}>()
|
|
137
|
+
|
|
138
|
+
expectTypeOf<ParseStruct<''>>().toEqualTypeOf<never>()
|
|
139
|
+
expectTypeOf<ParseStruct<'function foo()'>>().toEqualTypeOf<never>()
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('ResolveStructs', () => {
|
|
143
|
+
type Result = ResolveStructs<
|
|
144
|
+
[{ type: 'Name'; name: 'name' }],
|
|
145
|
+
{
|
|
146
|
+
Person: [{ type: 'Name'; name: 'name' }]
|
|
147
|
+
Name: [{ type: 'Foo'; name: 'foo' }]
|
|
148
|
+
Foo: [{ type: 'string'; name: 'bar' }, { type: 'uint16'; name: 'baz' }]
|
|
149
|
+
}
|
|
150
|
+
>
|
|
151
|
+
expectTypeOf<Result>().toEqualTypeOf<
|
|
152
|
+
readonly [
|
|
153
|
+
{
|
|
154
|
+
readonly name: 'name'
|
|
155
|
+
readonly type: 'tuple'
|
|
156
|
+
readonly components: readonly [
|
|
157
|
+
{
|
|
158
|
+
readonly name: 'foo'
|
|
159
|
+
readonly type: 'tuple'
|
|
160
|
+
readonly components: readonly [
|
|
161
|
+
{ type: 'string'; name: 'bar' },
|
|
162
|
+
{ type: 'uint16'; name: 'baz' },
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
>()
|
|
169
|
+
|
|
170
|
+
expectTypeOf<ResolveStructs<[], StructLookup>>().toEqualTypeOf<readonly []>()
|
|
171
|
+
expectTypeOf<
|
|
172
|
+
ResolveStructs<
|
|
173
|
+
[{ type: 'Foo[]'; name: 'foo' }],
|
|
174
|
+
{ Foo: [{ type: 'string'; name: 'bar' }] }
|
|
175
|
+
>
|
|
176
|
+
>().toEqualTypeOf<
|
|
177
|
+
readonly [
|
|
178
|
+
{
|
|
179
|
+
readonly name: 'foo'
|
|
180
|
+
readonly type: 'tuple[]'
|
|
181
|
+
readonly components: readonly [
|
|
182
|
+
{
|
|
183
|
+
type: 'string'
|
|
184
|
+
name: 'bar'
|
|
185
|
+
},
|
|
186
|
+
]
|
|
187
|
+
},
|
|
188
|
+
]
|
|
189
|
+
>()
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
test('ParseStructProperties', () => {
|
|
193
|
+
expectTypeOf<ParseStructProperties<'string;'>>().toEqualTypeOf<
|
|
194
|
+
[{ readonly type: 'string' }]
|
|
195
|
+
>()
|
|
196
|
+
expectTypeOf<ParseStructProperties<'string foo;'>>().toEqualTypeOf<
|
|
197
|
+
[{ readonly type: 'string'; readonly name: 'foo' }]
|
|
198
|
+
>()
|
|
199
|
+
expectTypeOf<
|
|
200
|
+
ParseStructProperties<'string; string;'> extends [
|
|
201
|
+
{ readonly type: 'string' },
|
|
202
|
+
{ readonly type: 'string' },
|
|
203
|
+
]
|
|
204
|
+
? true
|
|
205
|
+
: false
|
|
206
|
+
>().toEqualTypeOf<true>()
|
|
207
|
+
expectTypeOf<
|
|
208
|
+
ParseStructProperties<'string foo; string bar;'>
|
|
209
|
+
>().toEqualTypeOf<
|
|
210
|
+
[
|
|
211
|
+
{ readonly type: 'string'; readonly name: 'foo' },
|
|
212
|
+
{ readonly type: 'string'; readonly name: 'bar' },
|
|
213
|
+
]
|
|
214
|
+
>()
|
|
215
|
+
|
|
216
|
+
expectTypeOf<ParseStructProperties<''>>().toEqualTypeOf<[]>()
|
|
217
|
+
expectTypeOf<ParseStructProperties<'string'>>().toEqualTypeOf<[]>()
|
|
218
|
+
expectTypeOf<ParseStructProperties<'string; string'>>().toEqualTypeOf<
|
|
219
|
+
[{ readonly type: 'string' }]
|
|
220
|
+
>()
|
|
221
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { AbiParameter } from 'abitype'
|
|
2
|
+
import type { Error, Trim } from '../types.js'
|
|
3
|
+
import type { StructSignature } from './signatures.js'
|
|
4
|
+
import type { ParseAbiParameter } from './utils.js'
|
|
5
|
+
|
|
6
|
+
export type StructLookup = Record<string, readonly AbiParameter[]>
|
|
7
|
+
|
|
8
|
+
export type ParseStructs<signatures extends readonly string[]> =
|
|
9
|
+
// Create "shallow" version of each struct (and filter out non-structs or invalid structs)
|
|
10
|
+
{
|
|
11
|
+
[signature in signatures[number] as ParseStruct<signature> extends infer struct extends
|
|
12
|
+
{
|
|
13
|
+
name: string
|
|
14
|
+
}
|
|
15
|
+
? struct['name']
|
|
16
|
+
: never]: ParseStruct<signature>['components']
|
|
17
|
+
} extends infer structs extends Record<
|
|
18
|
+
string,
|
|
19
|
+
readonly (AbiParameter & { type: string })[]
|
|
20
|
+
>
|
|
21
|
+
? // Resolve nested structs inside each struct
|
|
22
|
+
{
|
|
23
|
+
[structName in keyof structs]: ResolveStructs<
|
|
24
|
+
structs[structName],
|
|
25
|
+
structs
|
|
26
|
+
>
|
|
27
|
+
}
|
|
28
|
+
: never
|
|
29
|
+
|
|
30
|
+
export type ParseStruct<
|
|
31
|
+
signature extends string,
|
|
32
|
+
structs extends StructLookup | unknown = unknown,
|
|
33
|
+
> =
|
|
34
|
+
signature extends StructSignature<infer name, infer properties>
|
|
35
|
+
? {
|
|
36
|
+
readonly name: Trim<name>
|
|
37
|
+
readonly components: ParseStructProperties<properties, structs>
|
|
38
|
+
}
|
|
39
|
+
: never
|
|
40
|
+
|
|
41
|
+
export type ResolveStructs<
|
|
42
|
+
abiParameters extends readonly (AbiParameter & { type: string })[],
|
|
43
|
+
structs extends Record<string, readonly (AbiParameter & { type: string })[]>,
|
|
44
|
+
keyReferences extends { [_: string]: unknown } | unknown = unknown,
|
|
45
|
+
> = readonly [
|
|
46
|
+
...{
|
|
47
|
+
[key in keyof abiParameters]: abiParameters[key]['type'] extends `${infer head extends
|
|
48
|
+
string & keyof structs}[${infer tail}]` // Struct arrays (e.g. `type: 'Struct[]'`, `type: 'Struct[10]'`, `type: 'Struct[][]'`)
|
|
49
|
+
? head extends keyof keyReferences
|
|
50
|
+
? Error<`Circular reference detected. Struct "${abiParameters[key]['type']}" is a circular reference.`>
|
|
51
|
+
: {
|
|
52
|
+
readonly name: abiParameters[key]['name']
|
|
53
|
+
readonly type: `tuple[${tail}]`
|
|
54
|
+
readonly components: ResolveStructs<
|
|
55
|
+
structs[head],
|
|
56
|
+
structs,
|
|
57
|
+
keyReferences & { [_ in head]: true }
|
|
58
|
+
>
|
|
59
|
+
}
|
|
60
|
+
: // Basic struct (e.g. `type: 'Struct'`)
|
|
61
|
+
abiParameters[key]['type'] extends keyof structs
|
|
62
|
+
? abiParameters[key]['type'] extends keyof keyReferences
|
|
63
|
+
? Error<`Circular reference detected. Struct "${abiParameters[key]['type']}" is a circular reference.`>
|
|
64
|
+
: {
|
|
65
|
+
readonly name: abiParameters[key]['name']
|
|
66
|
+
readonly type: 'tuple'
|
|
67
|
+
readonly components: ResolveStructs<
|
|
68
|
+
structs[abiParameters[key]['type']],
|
|
69
|
+
structs,
|
|
70
|
+
keyReferences & { [_ in abiParameters[key]['type']]: true }
|
|
71
|
+
>
|
|
72
|
+
}
|
|
73
|
+
: abiParameters[key]
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
export type ParseStructProperties<
|
|
78
|
+
signature extends string,
|
|
79
|
+
structs extends StructLookup | unknown = unknown,
|
|
80
|
+
result extends any[] = [],
|
|
81
|
+
> =
|
|
82
|
+
Trim<signature> extends `${infer head};${infer tail}`
|
|
83
|
+
? ParseStructProperties<
|
|
84
|
+
tail,
|
|
85
|
+
structs,
|
|
86
|
+
[...result, ParseAbiParameter<head, { structs: structs }>]
|
|
87
|
+
>
|
|
88
|
+
: result
|