@ledgerhq/context-module 1.7.0 → 1.8.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/lib/cjs/package.json +2 -2
- package/lib/cjs/src/ContextModule.js +1 -1
- package/lib/cjs/src/ContextModule.js.map +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
- package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/cjs/src/DefaultContextModule.js +1 -1
- package/lib/cjs/src/DefaultContextModule.js.map +3 -3
- package/lib/cjs/src/DefaultContextModule.test.js +1 -1
- package/lib/cjs/src/DefaultContextModule.test.js.map +3 -3
- package/lib/cjs/src/calldata/data/CalldataDescriptorDataSource.js +2 -0
- package/lib/cjs/src/calldata/data/CalldataDescriptorDataSource.js.map +7 -0
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js +2 -0
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +7 -0
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.test.js +2 -0
- package/lib/cjs/src/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +7 -0
- package/lib/cjs/src/calldata/data/dto/CalldataDto.js +2 -0
- package/lib/cjs/src/calldata/data/dto/CalldataDto.js.map +7 -0
- package/lib/cjs/src/calldata/di/calldataModuleFactory.js +2 -0
- package/lib/cjs/src/calldata/di/calldataModuleFactory.js.map +7 -0
- package/lib/cjs/src/calldata/di/calldataTypes.js +2 -0
- package/lib/cjs/src/calldata/di/calldataTypes.js.map +7 -0
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js +2 -0
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.js.map +7 -0
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js +2 -0
- package/lib/cjs/src/calldata/domain/CalldataContextLoader.test.js.map +7 -0
- package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
- package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +3 -3
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/cjs/src/index.js +1 -1
- package/lib/cjs/src/index.js.map +2 -2
- package/lib/cjs/src/nft/di/nftModuleFactory.js +1 -1
- package/lib/cjs/src/nft/di/nftModuleFactory.js.map +3 -3
- package/lib/cjs/src/nft/di/nftTypes.js +1 -1
- package/lib/cjs/src/nft/di/nftTypes.js.map +2 -2
- package/lib/cjs/src/nft/domain/NftContextFieldLoader.js +2 -0
- package/lib/cjs/src/nft/domain/NftContextFieldLoader.js.map +7 -0
- package/lib/cjs/src/nft/domain/NftContextFieldLoader.test.js +2 -0
- package/lib/cjs/src/nft/domain/NftContextFieldLoader.test.js.map +7 -0
- package/lib/cjs/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/cjs/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/cjs/src/pki/model/PkiCertificateInfo.js +1 -1
- package/lib/cjs/src/pki/model/PkiCertificateInfo.js.map +1 -1
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.js +2 -0
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.js.map +7 -0
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js +2 -0
- package/lib/cjs/src/proxy/data/HttpProxyDataSource.test.js.map +7 -0
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js +2 -0
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.js.map +7 -0
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js +2 -0
- package/lib/cjs/src/proxy/data/HttpSafeProxyDataSource.test.js.map +7 -0
- package/lib/cjs/src/proxy/data/ProxyDataSource.js +2 -0
- package/lib/cjs/src/proxy/data/ProxyDataSource.js.map +7 -0
- package/lib/cjs/src/{transaction → proxy}/data/dto/ProxyDelegateCallDto.js.map +1 -1
- package/lib/cjs/src/{transaction → proxy}/data/dto/ProxyImplementationAddressDto.js.map +1 -1
- package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +2 -0
- package/lib/cjs/src/proxy/data/dto/SafeProxyImplementationAddressDto.js.map +7 -0
- package/lib/cjs/src/proxy/di/proxyModuleFactory.js +2 -0
- package/lib/cjs/src/proxy/di/proxyModuleFactory.js.map +7 -0
- package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js +2 -0
- package/lib/cjs/src/proxy/di/proxyModuleFactory.test.js.map +7 -0
- package/lib/cjs/src/proxy/di/proxyTypes.js +2 -0
- package/lib/cjs/src/proxy/di/proxyTypes.js.map +7 -0
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js +2 -0
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.js.map +7 -0
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js +2 -0
- package/lib/cjs/src/proxy/domain/ProxyContextFieldLoader.test.js.map +7 -0
- package/lib/cjs/src/proxy/model/ProxyDelegateCall.js +2 -0
- package/lib/cjs/src/proxy/model/ProxyDelegateCall.js.map +7 -0
- package/lib/cjs/src/shared/domain/ContextFieldLoader.js +2 -0
- package/lib/cjs/src/shared/domain/ContextFieldLoader.js.map +7 -0
- package/lib/cjs/src/shared/domain/ContextLoader.js +1 -1
- package/lib/cjs/src/shared/domain/ContextLoader.js.map +1 -1
- package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
- package/lib/cjs/src/shared/model/ClearSignContext.js.map +3 -3
- package/lib/cjs/src/shared/model/TransactionSubset.js +1 -1
- package/lib/cjs/src/shared/model/TransactionSubset.js.map +1 -1
- package/lib/cjs/src/shared/model/TypedDataClearSignContext.js +1 -1
- package/lib/cjs/src/shared/model/TypedDataClearSignContext.js.map +3 -3
- package/lib/cjs/src/shared/model/TypedDataContext.js +1 -1
- package/lib/cjs/src/shared/model/TypedDataContext.js.map +1 -1
- package/lib/cjs/src/shared/utils/KeyUsageMapper.js +1 -1
- package/lib/cjs/src/shared/utils/KeyUsageMapper.js.map +2 -2
- package/lib/cjs/src/token/di/tokenModuleFactory.js +1 -1
- package/lib/cjs/src/token/di/tokenModuleFactory.js.map +3 -3
- package/lib/cjs/src/token/di/tokenTypes.js +1 -1
- package/lib/cjs/src/token/di/tokenTypes.js.map +2 -2
- package/lib/cjs/src/token/domain/TokenContextFieldLoader.js +2 -0
- package/lib/cjs/src/token/domain/TokenContextFieldLoader.js.map +7 -0
- package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js +2 -0
- package/lib/cjs/src/token/domain/TokenContextFieldLoader.test.js.map +7 -0
- package/lib/cjs/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/cjs/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
- package/lib/cjs/src/trusted-name/data/TrustedNameDataSource.js +1 -1
- package/lib/cjs/src/trusted-name/data/TrustedNameDataSource.js.map +1 -1
- package/lib/cjs/src/trusted-name/data/TrustedNameDto.js +1 -1
- package/lib/cjs/src/trusted-name/data/TrustedNameDto.js.map +1 -1
- package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
- package/lib/cjs/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
- package/lib/cjs/src/trusted-name/di/trustedNameTypes.js +1 -1
- package/lib/cjs/src/trusted-name/di/trustedNameTypes.js.map +2 -2
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.js +2 -0
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.js.map +7 -0
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js +2 -0
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js.map +7 -0
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/cjs/src/typed-data/data/FiltersDto.js +1 -1
- package/lib/cjs/src/typed-data/data/FiltersDto.js.map +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
- package/lib/cjs/src/typed-data/data/TypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/TypedDataDataSource.js.map +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/cjs/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/cjs/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/esm/package.json +2 -2
- package/lib/esm/src/ContextModuleBuilder.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
- package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/esm/src/DefaultContextModule.js +1 -1
- package/lib/esm/src/DefaultContextModule.js.map +3 -3
- package/lib/esm/src/DefaultContextModule.test.js +1 -1
- package/lib/esm/src/DefaultContextModule.test.js.map +3 -3
- package/lib/esm/src/calldata/data/CalldataDescriptorDataSource.js +1 -0
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js +2 -0
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.js.map +7 -0
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.test.js +2 -0
- package/lib/esm/src/calldata/data/HttpCalldataDescriptorDataSource.test.js.map +7 -0
- package/lib/esm/src/calldata/di/calldataModuleFactory.js +2 -0
- package/lib/esm/src/calldata/di/calldataModuleFactory.js.map +7 -0
- package/lib/esm/src/calldata/di/calldataTypes.js +2 -0
- package/lib/esm/src/calldata/di/calldataTypes.js.map +7 -0
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js +2 -0
- package/lib/esm/src/calldata/domain/CalldataContextLoader.js.map +7 -0
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js +2 -0
- package/lib/esm/src/calldata/domain/CalldataContextLoader.test.js.map +7 -0
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +3 -3
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +1 -1
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.js.map +3 -3
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +3 -3
- package/lib/esm/src/index.js +1 -1
- package/lib/esm/src/index.js.map +2 -2
- package/lib/esm/src/nft/di/nftModuleFactory.js +1 -1
- package/lib/esm/src/nft/di/nftModuleFactory.js.map +3 -3
- package/lib/esm/src/nft/di/nftTypes.js +1 -1
- package/lib/esm/src/nft/di/nftTypes.js.map +2 -2
- package/lib/esm/src/nft/domain/NftContextFieldLoader.js +2 -0
- package/lib/esm/src/nft/domain/NftContextFieldLoader.js.map +7 -0
- package/lib/esm/src/nft/domain/NftContextFieldLoader.test.js +2 -0
- package/lib/esm/src/nft/domain/NftContextFieldLoader.test.js.map +7 -0
- package/lib/esm/src/nft/domain/NftContextLoader.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.js.map +3 -3
- package/lib/esm/src/nft/domain/NftContextLoader.test.js +1 -1
- package/lib/esm/src/nft/domain/NftContextLoader.test.js.map +3 -3
- package/lib/esm/src/proxy/data/HttpProxyDataSource.js +2 -0
- package/lib/esm/src/proxy/data/HttpProxyDataSource.js.map +7 -0
- package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js +2 -0
- package/lib/esm/src/proxy/data/HttpProxyDataSource.test.js.map +7 -0
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js +2 -0
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.js.map +7 -0
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js +2 -0
- package/lib/esm/src/proxy/data/HttpSafeProxyDataSource.test.js.map +7 -0
- package/lib/esm/src/proxy/data/ProxyDataSource.js +1 -0
- package/lib/esm/src/proxy/data/dto/SafeProxyImplementationAddressDto.js +1 -0
- package/lib/esm/src/proxy/di/proxyModuleFactory.js +2 -0
- package/lib/esm/src/proxy/di/proxyModuleFactory.js.map +7 -0
- package/lib/esm/src/proxy/di/proxyModuleFactory.test.js +2 -0
- package/lib/esm/src/proxy/di/proxyModuleFactory.test.js.map +7 -0
- package/lib/esm/src/proxy/di/proxyTypes.js +2 -0
- package/lib/esm/src/proxy/di/proxyTypes.js.map +7 -0
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js +2 -0
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.js.map +7 -0
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js +2 -0
- package/lib/esm/src/proxy/domain/ProxyContextFieldLoader.test.js.map +7 -0
- package/lib/esm/src/shared/domain/ContextFieldLoader.js +1 -0
- package/lib/esm/src/shared/domain/ContextFieldLoader.js.map +7 -0
- package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
- package/lib/esm/src/shared/model/ClearSignContext.js.map +3 -3
- package/lib/esm/src/shared/model/TypedDataClearSignContext.js +1 -1
- package/lib/esm/src/shared/model/TypedDataClearSignContext.js.map +3 -3
- package/lib/esm/src/shared/utils/KeyUsageMapper.js +1 -1
- package/lib/esm/src/shared/utils/KeyUsageMapper.js.map +2 -2
- package/lib/esm/src/token/di/tokenModuleFactory.js +1 -1
- package/lib/esm/src/token/di/tokenModuleFactory.js.map +3 -3
- package/lib/esm/src/token/di/tokenTypes.js +1 -1
- package/lib/esm/src/token/di/tokenTypes.js.map +2 -2
- package/lib/esm/src/token/domain/TokenContextFieldLoader.js +2 -0
- package/lib/esm/src/token/domain/TokenContextFieldLoader.js.map +7 -0
- package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js +2 -0
- package/lib/esm/src/token/domain/TokenContextFieldLoader.test.js.map +7 -0
- package/lib/esm/src/token/domain/TokenContextLoader.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.js.map +3 -3
- package/lib/esm/src/token/domain/TokenContextLoader.test.js +1 -1
- package/lib/esm/src/token/domain/TokenContextLoader.test.js.map +3 -3
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +2 -2
- package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js +1 -1
- package/lib/esm/src/trusted-name/di/trustedNameModuleFactory.js.map +3 -3
- package/lib/esm/src/trusted-name/di/trustedNameTypes.js +1 -1
- package/lib/esm/src/trusted-name/di/trustedNameTypes.js.map +2 -2
- package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.js +2 -0
- package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.js.map +7 -0
- package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js +2 -0
- package/lib/esm/src/trusted-name/domain/TrustedNameContextFieldLoader.test.js.map +7 -0
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.js.map +3 -3
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +3 -3
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.js.map +3 -3
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js +1 -1
- package/lib/esm/src/typed-data/domain/DefaultTypedDataContextLoader.test.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/types/src/ContextModule.d.ts +3 -4
- package/lib/types/src/ContextModule.d.ts.map +1 -1
- package/lib/types/src/ContextModuleBuilder.d.ts +8 -1
- package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
- package/lib/types/src/DefaultContextModule.d.ts +4 -3
- package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
- package/lib/types/src/{transaction/data/TransactionDataSource.d.ts → calldata/data/CalldataDescriptorDataSource.d.ts} +4 -4
- package/lib/types/src/calldata/data/CalldataDescriptorDataSource.d.ts.map +1 -0
- package/lib/types/src/{transaction/data/HttpTransactionDataSource.d.ts → calldata/data/HttpCalldataDescriptorDataSource.d.ts} +6 -5
- package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.d.ts.map +1 -0
- package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.test.d.ts +2 -0
- package/lib/types/src/calldata/data/HttpCalldataDescriptorDataSource.test.d.ts.map +1 -0
- package/lib/types/src/{transaction → calldata}/data/dto/CalldataDto.d.ts +10 -1
- package/lib/types/src/calldata/data/dto/CalldataDto.d.ts.map +1 -0
- package/lib/types/src/calldata/di/calldataModuleFactory.d.ts +3 -0
- package/lib/types/src/calldata/di/calldataModuleFactory.d.ts.map +1 -0
- package/lib/types/src/calldata/di/calldataTypes.d.ts +6 -0
- package/lib/types/src/calldata/di/calldataTypes.d.ts.map +1 -0
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts +23 -0
- package/lib/types/src/calldata/domain/CalldataContextLoader.d.ts.map +1 -0
- package/lib/types/src/calldata/domain/CalldataContextLoader.test.d.ts +2 -0
- package/lib/types/src/calldata/domain/CalldataContextLoader.test.d.ts.map +1 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts +7 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +9 -5
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +11 -4
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +40 -1
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/nft/di/nftModuleFactory.d.ts.map +1 -1
- package/lib/types/src/nft/di/nftTypes.d.ts +1 -0
- package/lib/types/src/nft/di/nftTypes.d.ts.map +1 -1
- package/lib/types/src/nft/domain/NftContextFieldLoader.d.ts +15 -0
- package/lib/types/src/nft/domain/NftContextFieldLoader.d.ts.map +1 -0
- package/lib/types/src/nft/domain/NftContextFieldLoader.test.d.ts +2 -0
- package/lib/types/src/nft/domain/NftContextFieldLoader.test.d.ts.map +1 -0
- package/lib/types/src/nft/domain/NftContextLoader.d.ts +10 -5
- package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
- package/lib/types/src/pki/model/PkiCertificateInfo.d.ts +1 -2
- package/lib/types/src/pki/model/PkiCertificateInfo.d.ts.map +1 -1
- package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts +13 -0
- package/lib/types/src/proxy/data/HttpProxyDataSource.d.ts.map +1 -0
- package/lib/types/src/proxy/data/HttpProxyDataSource.test.d.ts.map +1 -0
- package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts +13 -0
- package/lib/types/src/proxy/data/HttpSafeProxyDataSource.d.ts.map +1 -0
- package/lib/types/src/proxy/data/HttpSafeProxyDataSource.test.d.ts +2 -0
- package/lib/types/src/proxy/data/HttpSafeProxyDataSource.test.d.ts.map +1 -0
- package/lib/types/src/proxy/data/ProxyDataSource.d.ts +17 -0
- package/lib/types/src/proxy/data/ProxyDataSource.d.ts.map +1 -0
- package/lib/types/src/proxy/data/dto/ProxyDelegateCallDto.d.ts.map +1 -0
- package/lib/types/src/proxy/data/dto/ProxyImplementationAddressDto.d.ts.map +1 -0
- package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts +10 -0
- package/lib/types/src/proxy/data/dto/SafeProxyImplementationAddressDto.d.ts.map +1 -0
- package/lib/types/src/proxy/di/proxyModuleFactory.d.ts +4 -0
- package/lib/types/src/proxy/di/proxyModuleFactory.d.ts.map +1 -0
- package/lib/types/src/proxy/di/proxyModuleFactory.test.d.ts +2 -0
- package/lib/types/src/proxy/di/proxyModuleFactory.test.d.ts.map +1 -0
- package/lib/types/src/proxy/di/proxyTypes.d.ts +5 -0
- package/lib/types/src/proxy/di/proxyTypes.d.ts.map +1 -0
- package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts +21 -0
- package/lib/types/src/proxy/domain/ProxyContextFieldLoader.d.ts.map +1 -0
- package/lib/types/src/proxy/domain/ProxyContextFieldLoader.test.d.ts +2 -0
- package/lib/types/src/proxy/domain/ProxyContextFieldLoader.test.d.ts.map +1 -0
- package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts +7 -0
- package/lib/types/src/proxy/model/ProxyDelegateCall.d.ts.map +1 -0
- package/lib/types/src/shared/domain/ContextFieldLoader.d.ts +15 -0
- package/lib/types/src/shared/domain/ContextFieldLoader.d.ts.map +1 -0
- package/lib/types/src/shared/domain/ContextLoader.d.ts +13 -5
- package/lib/types/src/shared/domain/ContextLoader.d.ts.map +1 -1
- package/lib/types/src/shared/model/ClearSignContext.d.ts +27 -9
- package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
- package/lib/types/src/shared/model/TransactionSubset.d.ts +1 -0
- package/lib/types/src/shared/model/TransactionSubset.d.ts.map +1 -1
- package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts +33 -1
- package/lib/types/src/shared/model/TypedDataClearSignContext.d.ts.map +1 -1
- package/lib/types/src/shared/model/TypedDataContext.d.ts +3 -0
- package/lib/types/src/shared/model/TypedDataContext.d.ts.map +1 -1
- package/lib/types/src/shared/utils/KeyUsageMapper.d.ts +1 -2
- package/lib/types/src/shared/utils/KeyUsageMapper.d.ts.map +1 -1
- package/lib/types/src/token/di/tokenModuleFactory.d.ts.map +1 -1
- package/lib/types/src/token/di/tokenTypes.d.ts +1 -0
- package/lib/types/src/token/di/tokenTypes.d.ts.map +1 -1
- package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts +14 -0
- package/lib/types/src/token/domain/TokenContextFieldLoader.d.ts.map +1 -0
- package/lib/types/src/token/domain/TokenContextFieldLoader.test.d.ts +2 -0
- package/lib/types/src/token/domain/TokenContextFieldLoader.test.d.ts.map +1 -0
- package/lib/types/src/token/domain/TokenContextLoader.d.ts +10 -5
- package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
- package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts +7 -3
- package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
- package/lib/types/src/trusted-name/data/TrustedNameDataSource.d.ts +7 -2
- package/lib/types/src/trusted-name/data/TrustedNameDataSource.d.ts.map +1 -1
- package/lib/types/src/trusted-name/data/TrustedNameDto.d.ts +4 -5
- package/lib/types/src/trusted-name/data/TrustedNameDto.d.ts.map +1 -1
- package/lib/types/src/trusted-name/di/trustedNameModuleFactory.d.ts.map +1 -1
- package/lib/types/src/trusted-name/di/trustedNameTypes.d.ts +1 -0
- package/lib/types/src/trusted-name/di/trustedNameTypes.d.ts.map +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.d.ts +22 -0
- package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.d.ts.map +1 -0
- package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.test.d.ts +2 -0
- package/lib/types/src/trusted-name/domain/TrustedNameContextFieldLoader.test.d.ts.map +1 -0
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +14 -6
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/FiltersDto.d.ts +32 -2
- package/lib/types/src/typed-data/data/FiltersDto.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts +3 -0
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts +1 -0
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/TypedDataDataSource.d.ts +2 -1
- package/lib/types/src/typed-data/data/TypedDataDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts +12 -1
- package/lib/types/src/typed-data/domain/DefaultTypedDataContextLoader.d.ts.map +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +11 -4
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/lib/cjs/src/shared/model/TransactionContext.js +0 -2
- package/lib/cjs/src/shared/model/TransactionContext.js.map +0 -7
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +0 -2
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +0 -7
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +0 -2
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +0 -7
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +0 -2
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +0 -7
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js +0 -2
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js.map +0 -7
- package/lib/cjs/src/transaction/data/TransactionDataSource.js +0 -2
- package/lib/cjs/src/transaction/data/TransactionDataSource.js.map +0 -7
- package/lib/cjs/src/transaction/data/dto/CalldataDto.js +0 -2
- package/lib/cjs/src/transaction/data/dto/CalldataDto.js.map +0 -7
- package/lib/cjs/src/transaction/di/transactionModuleFactory.js +0 -2
- package/lib/cjs/src/transaction/di/transactionModuleFactory.js.map +0 -7
- package/lib/cjs/src/transaction/di/transactionTypes.js +0 -2
- package/lib/cjs/src/transaction/di/transactionTypes.js.map +0 -7
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +0 -2
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +0 -7
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +0 -2
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +0 -7
- package/lib/cjs/src/transaction/model/ProxyDelegateCall.js +0 -2
- package/lib/cjs/src/transaction/model/ProxyDelegateCall.js.map +0 -7
- package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js +0 -2
- package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js.map +0 -7
- package/lib/esm/src/shared/model/TransactionContext.js +0 -1
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js +0 -2
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +0 -7
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +0 -2
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +0 -7
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +0 -2
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +0 -7
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js +0 -2
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js.map +0 -7
- package/lib/esm/src/transaction/data/TransactionDataSource.js +0 -1
- package/lib/esm/src/transaction/di/transactionModuleFactory.js +0 -2
- package/lib/esm/src/transaction/di/transactionModuleFactory.js.map +0 -7
- package/lib/esm/src/transaction/di/transactionTypes.js +0 -2
- package/lib/esm/src/transaction/di/transactionTypes.js.map +0 -7
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js +0 -2
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +0 -7
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +0 -2
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +0 -7
- package/lib/esm/src/transaction/model/ProxyImplementationAddress.js +0 -1
- package/lib/types/src/shared/model/TransactionContext.d.ts +0 -21
- package/lib/types/src/shared/model/TransactionContext.d.ts.map +0 -1
- package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +0 -33
- package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +0 -1
- package/lib/types/src/transaction/data/HttpProxyDataSource.test.d.ts.map +0 -1
- package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +0 -1
- package/lib/types/src/transaction/data/HttpTransactionDataSource.test.d.ts +0 -2
- package/lib/types/src/transaction/data/HttpTransactionDataSource.test.d.ts.map +0 -1
- package/lib/types/src/transaction/data/TransactionDataSource.d.ts.map +0 -1
- package/lib/types/src/transaction/data/dto/CalldataDto.d.ts.map +0 -1
- package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +0 -1
- package/lib/types/src/transaction/data/dto/ProxyImplementationAddressDto.d.ts.map +0 -1
- package/lib/types/src/transaction/di/transactionModuleFactory.d.ts +0 -3
- package/lib/types/src/transaction/di/transactionModuleFactory.d.ts.map +0 -1
- package/lib/types/src/transaction/di/transactionTypes.d.ts +0 -6
- package/lib/types/src/transaction/di/transactionTypes.d.ts.map +0 -1
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +0 -12
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +0 -1
- package/lib/types/src/transaction/domain/TransactionContextLoader.test.d.ts +0 -2
- package/lib/types/src/transaction/domain/TransactionContextLoader.test.d.ts.map +0 -1
- package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts +0 -5
- package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts.map +0 -1
- package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts +0 -4
- package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts.map +0 -1
- /package/lib/cjs/src/{transaction → proxy}/data/dto/ProxyDelegateCallDto.js +0 -0
- /package/lib/cjs/src/{transaction → proxy}/data/dto/ProxyImplementationAddressDto.js +0 -0
- /package/lib/esm/src/{shared/model/TransactionContext.js.map → calldata/data/CalldataDescriptorDataSource.js.map} +0 -0
- /package/lib/esm/src/{transaction → calldata}/data/dto/CalldataDto.js +0 -0
- /package/lib/esm/src/{transaction → calldata}/data/dto/CalldataDto.js.map +0 -0
- /package/lib/esm/src/{transaction/data/TransactionDataSource.js.map → proxy/data/ProxyDataSource.js.map} +0 -0
- /package/lib/esm/src/{transaction → proxy}/data/dto/ProxyDelegateCallDto.js +0 -0
- /package/lib/esm/src/{transaction → proxy}/data/dto/ProxyDelegateCallDto.js.map +0 -0
- /package/lib/esm/src/{transaction → proxy}/data/dto/ProxyImplementationAddressDto.js +0 -0
- /package/lib/esm/src/{transaction → proxy}/data/dto/ProxyImplementationAddressDto.js.map +0 -0
- /package/lib/esm/src/{transaction/model/ProxyDelegateCall.js.map → proxy/data/dto/SafeProxyImplementationAddressDto.js.map} +0 -0
- /package/lib/esm/src/{transaction → proxy}/model/ProxyDelegateCall.js +0 -0
- /package/lib/esm/src/{transaction/model/ProxyImplementationAddress.js.map → proxy/model/ProxyDelegateCall.js.map} +0 -0
- /package/lib/types/src/{transaction → proxy}/data/HttpProxyDataSource.test.d.ts +0 -0
- /package/lib/types/src/{transaction → proxy}/data/dto/ProxyDelegateCallDto.d.ts +0 -0
- /package/lib/types/src/{transaction → proxy}/data/dto/ProxyImplementationAddressDto.d.ts +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as
|
|
1
|
+
import{DeviceModelId as x}from"@ledgerhq/device-management-kit";import{Left as y,Right as m}from"purify-ts";import{ClearSignContextType as o}from"./shared/model/ClearSignContext";import{DefaultContextModule as d}from"./DefaultContextModule";const u=i=>({load:vi.fn(),canHandle:vi.fn().mockReturnValue(i)}),r=()=>({canHandle:vi.fn(),loadField:vi.fn()});describe("DefaultContextModule",()=>{const i={load:vi.fn()},l={customLoaders:[],defaultLoaders:!1,defaultFieldLoaders:!1,customFieldLoaders:[],customTypedDataLoader:i,cal:{url:"https://cal/v1",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks/v3"},metadataServiceDomain:{url:"https://metadata.com"},originToken:"originToken"};beforeEach(()=>{vi.restoreAllMocks()}),it("should initialize the context module with all the default loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should return an empty array when no loaders",async()=>{const t=await new d(l).getContexts({});expect(t).toEqual([])}),it("should call all fetch method from metadata fetcher",async()=>{const e=u(!0);await new d({...l,customLoaders:[e,e]}).getContexts({}),expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2)}),it("should return an array of context response",async()=>{const e=u(!0),t=[[{type:"provideERC20Info",payload:"payload1"}],[{type:"provideERC20Info",payload:"payload2"},{type:"plugin",payload:"payload3"}]];vi.spyOn(e,"load").mockResolvedValueOnce(t[0]).mockResolvedValueOnce(t[1]);const n=await new d({...l,customLoaders:[e,e]}).getContexts({});expect(e.canHandle).toHaveBeenCalledTimes(2),expect(e.load).toHaveBeenCalledTimes(2),expect(n).toEqual(t.flat())}),it("should only call loaders that can handle the input",async()=>{const e=u(!0),t=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!1),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]),vi.spyOn(t,"load").mockResolvedValue([{type:o.NFT,payload:"payload2"}]);const a=new d({...l,customLoaders:[e,t]}),n={to:"0x123",selector:"0xabc"},s=await a.getContexts(n);expect(e.canHandle).toHaveBeenCalledWith(n,Object.values(o)),expect(t.canHandle).toHaveBeenCalledWith(n,Object.values(o)),expect(e.load).toHaveBeenCalledWith(n),expect(t.load).not.toHaveBeenCalled(),expect(s).toEqual([{type:"token",payload:"payload1"}])}),it("should use expected types if provided",async()=>{const e=u(!0);vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"load").mockResolvedValue([{type:o.TOKEN,payload:"payload1"}]);const t=new d({...l,customLoaders:[e]}),a={to:"0x123",selector:"0xabc"};await t.getContexts(a,[o.TOKEN]),expect(e.canHandle).toHaveBeenCalledWith(a,[o.TOKEN])}),it("should call the typed data loader",async()=>{await new d({...l,customTypedDataLoader:i}).getTypedDataFilters({}),expect(i.load).toHaveBeenCalledTimes(1)}),it("should return a web3 check context",async()=>{const e={load:vi.fn()};vi.spyOn(e,"load").mockResolvedValueOnce(m({descriptor:"payload"}));const a=await new d({...l,customLoaders:[],customWeb3CheckLoader:e}).getWeb3Checks({deviceModelId:x.FLEX,from:"from",rawTx:"rawTx",chainId:1});expect(e.load).toHaveBeenCalledTimes(1),expect(a).toEqual({type:"web3Check",payload:"payload"})}),it("should return null if no web3 check context",async()=>{const e={load:vi.fn()};vi.spyOn(e,"load").mockResolvedValue(y(new Error("error")));const a=await new d({...l,customLoaders:[],customWeb3CheckLoader:e}).getWeb3Checks({deviceModelId:x.FLEX,from:"from",rawTx:"rawTx",chainId:1});expect(e.load).toHaveBeenCalledTimes(1),expect(a).toBeNull()}),it("should throw an error if origin token is not provided",()=>{expect(()=>new d({...l,originToken:void 0})).toThrow("Origin token is required")}),describe("getFieldContext",()=>{it("should return error when no loader can handle the field",async()=>{const e=r();vi.spyOn(e,"canHandle").mockReturnValue(!1);const t=new d({...l,customFieldLoaders:[e]}),a={type:"unknown"},n=await t.getFieldContext(a,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(a,o.TOKEN),expect(e.loadField).not.toHaveBeenCalled(),expect(n).toEqual({type:o.ERROR,error:new Error(`Loader not found for field: ${a} and expected type: ${o.TOKEN}`)})}),it("should return context when a loader can handle the field",async()=>{const e=r(),t={type:o.TOKEN,payload:"test-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(t);const a=new d({...l,customFieldLoaders:[e]}),n={type:"token",address:"0x123"},s=await a.getFieldContext(n,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(n),expect(s).toEqual(t)}),it("should return first context when multiple loaders can handle the field",async()=>{const e=r(),t=r(),a={type:o.TOKEN,payload:"first-payload"},n={type:o.NFT,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(a),vi.spyOn(t,"loadField").mockResolvedValue(n);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"multi",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).not.toHaveBeenCalled(),expect(p).toEqual(a)}),it("should return second context when first context is an error",async()=>{const e=r(),t=r(),a={type:o.ERROR,error:new Error("first-error")},n={type:o.TOKEN,payload:"second-payload"};vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(t,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockResolvedValue(a),vi.spyOn(t,"loadField").mockResolvedValue(n);const s=new d({...l,customFieldLoaders:[e,t]}),c={type:"error",address:"0x123"},p=await s.getFieldContext(c,o.TOKEN);expect(e.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(t.canHandle).toHaveBeenCalledWith(c,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(c),expect(t.loadField).toHaveBeenCalledWith(c),expect(p).toEqual(n)}),it("should handle loader rejection gracefully",async()=>{const e=r(),t=new Error("Load field failed");vi.spyOn(e,"canHandle").mockReturnValue(!0),vi.spyOn(e,"loadField").mockRejectedValue(t);const a=new d({...l,customFieldLoaders:[e]}),n={type:"error",address:"0x123"};await expect(a.getFieldContext(n,o.TOKEN)).rejects.toThrow("Load field failed"),expect(e.canHandle).toHaveBeenCalledWith(n,o.TOKEN),expect(e.loadField).toHaveBeenCalledWith(n)})})});
|
|
2
2
|
//# sourceMappingURL=DefaultContextModule.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DefaultContextModule.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"./shared/model/TransactionContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = () => {\n return { load: vi.fn(), loadField: vi.fn() };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder();\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({} as TransactionContext);\n\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n it(\"should return a single context\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, { type: \"token\", payload: \"payload\" }];\n vi.spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: vi.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({ type: \"token\", payload: \"payload\" });\n });\n\n it(\"should return a web3 check context\", async () => {\n const loader = contextLoaderStubBuilder();\n vi.spyOn(loader, \"load\").mockResolvedValueOnce(\n Right({ descriptor: \"payload\" }),\n );\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toEqual({ type: \"web3Check\", payload: \"payload\" });\n });\n\n it(\"should return null if no web3 check context\", async () => {\n const loader = contextLoaderStubBuilder();\n vi.spyOn(loader, \"load\").mockResolvedValue(Left(new Error(\"error\")));\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toBeNull();\n });\n\n it(\"context field not supported\", async () => {\n const loader = contextLoaderStubBuilder();\n const responses = [null, null];\n vi.spyOn(loader, \"loadField\")\n .mockResolvedValueOnce(responses[0])\n .mockResolvedValueOnce(responses[1]);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, { load: vi.fn() }, loader],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(loader.loadField).toHaveBeenCalledTimes(2);\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n\n it(\"getField not implemented\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [{ load: vi.fn() }],\n });\n\n const res = await contextModule.getContext({\n type: \"token\",\n } as TransactionFieldContext);\n\n expect(res).toEqual({\n type: \"error\",\n error: new Error(\"Field type not supported: token\"),\n });\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n expect(\n () =>\n new DefaultContextModule({\n ...defaultContextModuleConfig,\n originToken: undefined,\n }),\n ).toThrow(\"Origin token is required\");\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,
|
|
6
|
-
"names": ["DeviceModelId", "Left", "Right", "DefaultContextModule", "contextLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type TypedDataContext } from \"./shared/model/TypedDataContext\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst contextLoaderStubBuilder = (canHandle: boolean): ContextLoader => {\n return {\n load: vi.fn(),\n canHandle: vi\n .fn()\n .mockReturnValue(canHandle) as unknown as ContextLoader[\"canHandle\"],\n };\n};\n\nconst fieldLoaderStubBuilder = (): ContextFieldLoader => {\n return {\n canHandle: vi.fn(),\n loadField: vi.fn(),\n };\n};\n\ndescribe(\"DefaultContextModule\", () => {\n const typedDataLoader: TypedDataContextLoader = { load: vi.fn() };\n const defaultContextModuleConfig: ContextModuleConfig = {\n customLoaders: [],\n defaultLoaders: false,\n defaultFieldLoaders: false,\n customFieldLoaders: [],\n customTypedDataLoader: typedDataLoader,\n cal: {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks/v3\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.com\",\n },\n originToken: \"originToken\",\n };\n\n beforeEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should initialize the context module with all the default loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should return an empty array when no loaders\", async () => {\n const contextModule = new DefaultContextModule(defaultContextModuleConfig);\n\n const res = await contextModule.getContexts({});\n\n expect(res).toEqual([]);\n });\n\n it(\"should call all fetch method from metadata fetcher\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n });\n\n it(\"should return an array of context response\", async () => {\n const loader = contextLoaderStubBuilder(true);\n const responses = [\n [{ type: \"provideERC20Info\", payload: \"payload1\" }],\n [\n { type: \"provideERC20Info\", payload: \"payload2\" },\n { type: \"plugin\", payload: \"payload3\" },\n ],\n ] as ClearSignContext[][];\n vi.spyOn(loader, \"load\")\n .mockResolvedValueOnce(responses[0]!)\n .mockResolvedValueOnce(responses[1]!);\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader, loader],\n });\n\n const res = await contextModule.getContexts({});\n\n expect(loader.canHandle).toHaveBeenCalledTimes(2);\n expect(loader.load).toHaveBeenCalledTimes(2);\n expect(res).toEqual(responses.flat());\n });\n\n it(\"should only call loaders that can handle the input\", async () => {\n const loader1 = contextLoaderStubBuilder(true);\n const loader2 = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(loader2, \"canHandle\").mockReturnValue(false);\n vi.spyOn(loader1, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n vi.spyOn(loader2, \"load\").mockResolvedValue([\n { type: ClearSignContextType.NFT, payload: \"payload2\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader1, loader2],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n const res = await contextModule.getContexts(testInput);\n\n expect(loader1.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader2.canHandle).toHaveBeenCalledWith(\n testInput,\n Object.values(ClearSignContextType),\n );\n expect(loader1.load).toHaveBeenCalledWith(testInput);\n expect(loader2.load).not.toHaveBeenCalled(); // Should not be called since canHandle returned false\n expect(res).toEqual([{ type: \"token\", payload: \"payload1\" }]);\n });\n\n it(\"should use expected types if provided\", async () => {\n const loader = contextLoaderStubBuilder(true);\n\n vi.spyOn(loader, \"canHandle\").mockReturnValue(true);\n\n vi.spyOn(loader, \"load\").mockResolvedValue([\n { type: ClearSignContextType.TOKEN, payload: \"payload1\" },\n ]);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [loader],\n });\n\n const testInput = { to: \"0x123\", selector: \"0xabc\" };\n await contextModule.getContexts(testInput, [ClearSignContextType.TOKEN]);\n\n expect(loader.canHandle).toHaveBeenCalledWith(testInput, [\n ClearSignContextType.TOKEN,\n ]);\n });\n\n it(\"should call the typed data loader\", async () => {\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customTypedDataLoader: typedDataLoader,\n });\n\n await contextModule.getTypedDataFilters({} as TypedDataContext);\n\n expect(typedDataLoader.load).toHaveBeenCalledTimes(1);\n });\n\n it(\"should return a web3 check context\", async () => {\n const loader = { load: vi.fn() }; // Web3CheckLoader doesn't use ContextLoader interface\n vi.spyOn(loader, \"load\").mockResolvedValueOnce(\n Right({ descriptor: \"payload\" }),\n );\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toEqual({ type: \"web3Check\", payload: \"payload\" });\n });\n\n it(\"should return null if no web3 check context\", async () => {\n const loader = { load: vi.fn() }; // Web3CheckLoader doesn't use ContextLoader interface\n vi.spyOn(loader, \"load\").mockResolvedValue(Left(new Error(\"error\")));\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customLoaders: [],\n customWeb3CheckLoader: loader,\n });\n\n const res = await contextModule.getWeb3Checks({\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n });\n\n expect(loader.load).toHaveBeenCalledTimes(1);\n expect(res).toBeNull();\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n expect(\n () =>\n new DefaultContextModule({\n ...defaultContextModuleConfig,\n originToken: undefined,\n }),\n ).toThrow(\"Origin token is required\");\n });\n\n describe(\"getFieldContext\", () => {\n it(\"should return error when no loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(false);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"unknown\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).not.toHaveBeenCalled();\n expect(result).toEqual({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${testField} and expected type: ${ClearSignContextType.TOKEN}`,\n ),\n });\n });\n\n it(\"should return context when a loader can handle the field\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const mockContext: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"test-payload\",\n };\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockResolvedValue(mockContext);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"token\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext);\n });\n\n it(\"should return first context when multiple loaders can handle the field\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"first-payload\",\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.NFT,\n payload: \"second-payload\",\n };\n\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"multi\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).not.toHaveBeenCalled();\n expect(result).toEqual(mockContext1); // Should return first context\n });\n\n it(\"should return second context when first context is an error\", async () => {\n // GIVEN\n const fieldLoader1 = fieldLoaderStubBuilder();\n const fieldLoader2 = fieldLoaderStubBuilder();\n const mockContext1: ClearSignContext = {\n type: ClearSignContextType.ERROR,\n error: new Error(\"first-error\"),\n };\n const mockContext2: ClearSignContext = {\n type: ClearSignContextType.TOKEN,\n payload: \"second-payload\",\n };\n vi.spyOn(fieldLoader1, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader2, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader1, \"loadField\").mockResolvedValue(mockContext1);\n vi.spyOn(fieldLoader2, \"loadField\").mockResolvedValue(mockContext2);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader1, fieldLoader2],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN\n const result = await contextModule.getFieldContext(\n testField,\n ClearSignContextType.TOKEN,\n );\n\n // THEN\n expect(fieldLoader1.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader2.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader1.loadField).toHaveBeenCalledWith(testField);\n expect(fieldLoader2.loadField).toHaveBeenCalledWith(testField);\n expect(result).toEqual(mockContext2);\n });\n\n it(\"should handle loader rejection gracefully\", async () => {\n // GIVEN\n const fieldLoader = fieldLoaderStubBuilder();\n const loadError = new Error(\"Load field failed\");\n\n vi.spyOn(fieldLoader, \"canHandle\").mockReturnValue(true);\n vi.spyOn(fieldLoader, \"loadField\").mockRejectedValue(loadError);\n\n const contextModule = new DefaultContextModule({\n ...defaultContextModuleConfig,\n customFieldLoaders: [fieldLoader],\n });\n\n const testField = { type: \"error\", address: \"0x123\" };\n\n // WHEN & THEN\n await expect(\n contextModule.getFieldContext(testField, ClearSignContextType.TOKEN),\n ).rejects.toThrow(\"Load field failed\");\n\n expect(fieldLoader.canHandle).toHaveBeenCalledWith(\n testField,\n ClearSignContextType.TOKEN,\n );\n expect(fieldLoader.loadField).toHaveBeenCalledWith(testField);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAK5B,OAEE,wBAAAC,MACK,kCAGP,OAAS,wBAAAC,MAA4B,yBAErC,MAAMC,EAA4BC,IACzB,CACL,KAAM,GAAG,GAAG,EACZ,UAAW,GACR,GAAG,EACH,gBAAgBA,CAAS,CAC9B,GAGIC,EAAyB,KACtB,CACL,UAAW,GAAG,GAAG,EACjB,UAAW,GAAG,GAAG,CACnB,GAGF,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA0C,CAAE,KAAM,GAAG,GAAG,CAAE,EAC1DC,EAAkD,CACtD,cAAe,CAAC,EAChB,eAAgB,GAChB,oBAAqB,GACrB,mBAAoB,CAAC,EACrB,sBAAuBD,EACvB,IAAK,CACH,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,uBACP,EACA,sBAAuB,CACrB,IAAK,sBACP,EACA,YAAa,aACf,EAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,CACrB,CAAC,EAED,GAAG,oEAAqE,SAAY,CAGlF,MAAME,EAAM,MAFU,IAAIN,EAAqBK,CAA0B,EAEzC,YAAY,CAAC,CAAC,EAE9C,OAAOC,CAAG,EAAE,QAAQ,CAAC,CAAC,CACxB,CAAC,EAED,GAAG,+CAAgD,SAAY,CAG7D,MAAMA,EAAM,MAFU,IAAIN,EAAqBK,CAA0B,EAEzC,YAAY,CAAC,CAAC,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KACvB,EACA,OAAOmB,EAAa,SAAS,EAAE,qBAC7BJ,EACAf,EAAqB,KACvB,EACA,OAAOkB,EAAa,SAAS,EAAE,qBAAqBH,CAAS,EAC7D,OAAOI,EAAa,SAAS,EAAE,qBAAqBJ,CAAS,EAC7D,OAAOC,CAAM,EAAE,QAAQK,CAAY,CACrC,CAAC,EAED,GAAG,4CAA6C,SAAY,CAE1D,MAAMP,EAAcV,EAAuB,EACrCkB,EAAY,IAAI,MAAM,mBAAmB,EAE/C,GAAG,MAAMR,EAAa,WAAW,EAAE,gBAAgB,EAAI,EACvD,GAAG,MAAMA,EAAa,WAAW,EAAE,kBAAkBQ,CAAS,EAE9D,MAAMV,EAAgB,IAAIX,EAAqB,CAC7C,GAAGK,EACH,mBAAoB,CAACQ,CAAW,CAClC,CAAC,EAEKC,EAAY,CAAE,KAAM,QAAS,QAAS,OAAQ,EAGpD,MAAM,OACJH,EAAc,gBAAgBG,EAAWf,EAAqB,KAAK,CACrE,EAAE,QAAQ,QAAQ,mBAAmB,EAErC,OAAOc,EAAY,SAAS,EAAE,qBAC5BC,EACAf,EAAqB,KACvB,EACA,OAAOc,EAAY,SAAS,EAAE,qBAAqBC,CAAS,CAC9D,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "Left", "Right", "ClearSignContextType", "DefaultContextModule", "contextLoaderStubBuilder", "canHandle", "fieldLoaderStubBuilder", "typedDataLoader", "defaultContextModuleConfig", "res", "loader", "responses", "loader1", "loader2", "contextModule", "testInput", "fieldLoader", "testField", "result", "mockContext", "fieldLoader1", "fieldLoader2", "mockContext1", "mockContext2", "loadError"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=CalldataDescriptorDataSource.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var I=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var h=(l,e,t,r)=>{for(var i=r>1?void 0:r?S(e,t):e,n=l.length-1,o;n>=0;n--)(o=l[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&I(e,t,i),i},y=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as R}from"inversify";import{Left as c,Right as L}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as G}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as k,LEDGER_ORIGIN_TOKEN_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextReferenceType as a,ClearSignContextType as f}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as D}from"../../shared/model/SignatureTags";import{HexStringUtils as E}from"../../shared/utils/HexStringUtils";import j from"../../../package.json";let u=class{constructor(e,t,r){this.config=e;this._certificateLoader=t;this.endpoint=r}async getCalldataDescriptors({chainId:e,address:t,selector:r,deviceModelId:i}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/${this.endpoint}`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,contract_address:t,ref:`branch:${this.config.cal.branch}`},headers:{[k]:`context-module/${j.version}`,[U]:this.config.originToken}})).data}catch(o){return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${o}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${t} and selector ${r}`));for(const o of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=o.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const V=s.transaction_info.descriptor.data,T=s.transaction_info.descriptor.signatures[this.config.cal.mode],g={targetDevice:i,keyUsage:G.Calldata,keyId:F.CalCalldataKey},C=await this._certificateLoader.loadCertificate(g),A={type:f.TRANSACTION_INFO,payload:E.appendSignatureToPayload(V,T,D),certificate:C},d=[];for(const[p,b]of Object.entries(s.enums))for(const[v,{data:P,signatures:N}]of Object.entries(b))d.push({type:f.ENUM,id:Number(p),value:Number(v),payload:E.appendSignatureToPayload(P,N[this.config.cal.mode],D),certificate:C});const _=s.fields.map(p=>({type:f.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return L([A,...d,..._])}return c(new Error(`[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id};if(e.type==="CALLDATA"&&e.value.type==="path"&&e.callee.type==="path")return{type:a.CALLDATA,valuePath:this.toGenericPath(e.value.binary_path),callee:this.toGenericPath(e.callee.binary_path),selector:e.selector?.type==="path"?this.toGenericPath(e.selector.binary_path):void 0,amount:e.amount?.type==="path"?this.toGenericPath(e.amount.binary_path):void 0,spender:e.spender?.type==="path"?this.toGenericPath(e.spender.binary_path):void 0,chainId:e.chainId?.type==="path"?this.toGenericPath(e.chainId.binary_path):void 0}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...i}=t;return{itemSize:r,...i}}else if(t.type==="LEAF"){const{leaf_type:r,...i}=t;return{leafType:r,...i}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,i])=>typeof r=="string"&&typeof i=="object"&&Object.entries(i).every(([n,o])=>typeof n=="string"&&typeof o=="object"&&typeof o.data=="string"&&o.signatures!==void 0&&this.isCalldataSignatures(o.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string")||e.param.type==="CALLDATA"&&this.isDescriptorValueV1(e.param.value)&&this.isDescriptorValueV1(e.param.callee)&&(e.param.selector===void 0||this.isDescriptorValueV1(e.param.selector))&&(e.param.amount===void 0||this.isDescriptorValueV1(e.param.amount))&&(e.param.spender===void 0||this.isDescriptorValueV1(e.param.spender))&&(e.param.chainId===void 0||this.isDescriptorValueV1(e.param.chainId)))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};u=h([R(),y(0,m(x.Config)),y(1,m(O.PkiCertificateLoader))],u);export{u as HttpCalldataDescriptorDataSource};
|
|
2
|
+
//# sourceMappingURL=HttpCalldataDescriptorDataSource.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.ts"],
|
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextReferenceType,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./dto/CalldataDto\";\nimport {\n CalldataDescriptorDataSource,\n GetCalldataDescriptorsParams,\n} from \"./CalldataDescriptorDataSource\";\n\n@injectable()\nexport class HttpCalldataDescriptorDataSource\n implements CalldataDescriptorDataSource\n{\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n private readonly endpoint: string,\n ) {}\n\n public async getCalldataDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetCalldataDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/${this.endpoint}`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address, // used for dapps\n contract_address: address, // used for tokens\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextReferenceType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextReferenceType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextReferenceType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n } else if (\n param.type === \"CALLDATA\" &&\n param.value.type === \"path\" &&\n param.callee.type === \"path\"\n ) {\n return {\n type: ClearSignContextReferenceType.CALLDATA,\n valuePath: this.toGenericPath(param.value.binary_path),\n callee: this.toGenericPath(param.callee.binary_path),\n selector:\n param.selector?.type === \"path\"\n ? this.toGenericPath(param.selector.binary_path)\n : undefined,\n amount:\n param.amount?.type === \"path\"\n ? this.toGenericPath(param.amount.binary_path)\n : undefined,\n spender:\n param.spender?.type === \"path\"\n ? this.toGenericPath(param.spender.binary_path)\n : undefined,\n chainId:\n param.chainId?.type === \"path\"\n ? this.toGenericPath(param.chainId.binary_path)\n : undefined,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")) ||\n (data.param.type === \"CALLDATA\" &&\n this.isDescriptorValueV1(data.param.value) &&\n this.isDescriptorValueV1(data.param.callee) &&\n (data.param.selector === undefined ||\n this.isDescriptorValueV1(data.param.selector)) &&\n (data.param.amount === undefined ||\n this.isDescriptorValueV1(data.param.amount)) &&\n (data.param.spender === undefined ||\n this.isDescriptorValueV1(data.param.spender)) &&\n (data.param.chainId === undefined ||\n this.isDescriptorValueV1(data.param.chainId))))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAEE,iCAAAC,EAEA,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAEP,CACE,YAC+CC,EAE5BC,EACAC,EACjB,CAJ6C,YAAAF,EAE5B,wBAAAC,EACA,cAAAC,CAChB,CAEH,MAAa,uBAAuB,CAClC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAgBFA,GAfiB,MAAMC,EAAM,QAAuB,CAClD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,IAAI,KAAK,QAAQ,GAC5C,OAAQ,CACN,OAAQ,uBACR,SAAUL,EACV,UAAWC,EACX,iBAAkBA,EAClB,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,EACA,QAAS,CACP,CAACK,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACc,IACjB,OAASC,EAAO,CACd,OAAOC,EACL,IAAI,MACF,2FAA2FD,CAAK,EAClG,CACF,CACF,CAEA,GAAI,CAAC,MAAM,QAAQL,CAAG,EACpB,OAAOM,EACL,IAAI,MACF,4EACF,CACF,EAGF,GAAIN,EA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EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EArZa/B,EAAN+C,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAL5BpD",
|
|
6
|
+
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "ClearSignContextReferenceType", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpCalldataDescriptorDataSource", "config", "_certificateLoader", "endpoint", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "ClearSignContextReferenceType", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{DeviceModelId as o}from"@ledgerhq/device-management-kit";import t from"axios";import{Left as i}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as A,LEDGER_ORIGIN_TOKEN_HEADER as h}from"../../shared/constant/HttpHeaders";import T from"../../../package.json";import{HttpCalldataDescriptorDataSource as I}from"./HttpCalldataDescriptorDataSource";vi.mock("axios");const C={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"},originToken:"originToken"};describe("HttpCalldataDescriptorDataSource",()=>{let d,l,u,n,v,E,p,f,b,y,m,x;const c={loadCertificate:vi.fn()};beforeAll(()=>{vi.clearAllMocks(),d=new I(C,c,"dapps"),l={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},u={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},p=D("FROM","UFIXED","AMOUNT","06"),f=D("TO","FIXED","DATETIME","07"),b=D("TO","BOOL","UNIT","08"),y=D("VALUE","INT","DURATION","09"),n={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},v={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},E={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},m={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"},x={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20},selector:{type:"path",binary_path:{type:"CONTAINER",value:"FROM"},type_family:"BYTES",type_size:4},amount:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"TUPLE_LEAF"}]},type_family:"UINT",type_size:32},spender:{type:"path",binary_path:{type:"DATA",elements:[{type:"SLICE",start:0,end:20},{type:"LEAF",leaf_type:"ARRAY_LEAF"}]},type_family:"ADDRESS",type_size:20},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"}});function D(a,e,r,F){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:a},type_family:e,type_size:32},type:r},descriptor:F}}function s(a,e,r){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:a,enums:e,fields:r}}}}}it("should call axios with the ledger client version header",async()=>{const a=`context-module/${T.version}`,e=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(t,"request").mockImplementation(e),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0),await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(e).toHaveBeenCalledWith(expect.objectContaining({headers:{[A]:a,[h]:C.originToken}}))}),it.each([["dapps"],["tokens"]])("should call axios with the correct url for endpoint '%s'",async a=>{const e=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(t,"request").mockImplementation(e),await new I(C,c,a).getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(e).toHaveBeenCalledWith(expect.objectContaining({url:`https://crypto-assets-service.api.ledger.com/v1/${a}`}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(t,"request").mockRejectedValue(new Error),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: Error")))}),it("should return an error when no payload is returned",async()=>{const a={data:{test:""}};vi.spyOn(t,"request").mockResolvedValue(a),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{vi.spyOn(t,"request").mockResolvedValue({data:[]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const a=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const a=s(l,u,[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const a=s(l,u,[n,v,E,m]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:n.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const a=s(l,u,[n,v,E,m]),e={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValueOnce(e);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:e},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:e},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:e},{payload:n.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const a=s(l,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata on third array element",async()=>{const a=s(l,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[{},{},a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const a={descriptor:{data:l.descriptor.data,signatures:{test:l.descriptor.signatures.test+"0"}}},e=s(a,[],[p,f,b,y]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const a={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const a={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("Calldata with CALLDATA fields references",async()=>{const a=s(l,[],[x]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"ARRAY",itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}],selector:"FROM",amount:[{type:"REF"},{type:"LEAF",leafType:"TUPLE_LEAF"}],spender:[{type:"SLICE",start:0,end:20},{type:"LEAF",leafType:"ARRAY_LEAF"}]}}])}),it("Calldata with CALLDATA fields references without optional properties",async()=>{const a={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},callee:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"BYTES",type_size:32},type:"CALLDATA"},descriptor:"000100010c43616c6c64617461207465737402010803230001000115000100010105020114"},e=s(l,[],[a]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:a.descriptor,type:"transactionFieldDescription",reference:{type:"calldata",valuePath:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],callee:[{type:"TUPLE",offset:0},{type:"LEAF",leafType:"STATIC_LEAF"}],selector:void 0,amount:void 0,spender:void 0,chainId:void 0}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const a={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:l,enums:u,fields:[n]}}}};vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const a=s({descriptor:{data:"1234",signatures:{prod:"1234"}}},u,[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const a=s(l,["badEnum"],[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const a=s(l,{0:{1:{data:"1234"}}},[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const a=s(l,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[n]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const a=s(l,[],[{descriptor:3}]);vi.spyOn(t,"request").mockResolvedValue({data:[a]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const e=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(e).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const e=s(l,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(t,"request").mockResolvedValue({data:[e]}),vi.spyOn(c,"loadCertificate").mockResolvedValue(void 0);const r=await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(r).toEqual(i(new Error("[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should call axios with the correct headers",async()=>{vi.spyOn(t,"request").mockResolvedValueOnce({data:{}}),await d.getCalldataDescriptors({deviceModelId:o.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"}),expect(t.request).toHaveBeenCalledWith(expect.objectContaining({headers:{[A]:`context-module/${T.version}`,[h]:C.originToken}}))})});
|
|
2
|
+
//# sourceMappingURL=HttpCalldataDescriptorDataSource.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/calldata/data/HttpCalldataDescriptorDataSource.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport type {\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataTransactionInfoV1,\n} from \"@/calldata/data/dto/CalldataDto\";\nimport type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type CalldataDescriptorDataSource } from \"@/index\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { HttpCalldataDescriptorDataSource } from \"./HttpCalldataDescriptorDataSource\";\n\nvi.mock(\"axios\");\nconst config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"test\",\n branch: \"main\",\n },\n originToken: \"originToken\",\n} as ContextModuleConfig;\n\ndescribe(\"HttpCalldataDescriptorDataSource\", () => {\n let datasource: CalldataDescriptorDataSource;\n let transactionInfo: CalldataTransactionInfoV1;\n let enums: CalldataEnumV1;\n let fieldToken: CalldataFieldV1;\n let fieldTrustedName: CalldataFieldV1;\n let fieldNft: CalldataFieldV1;\n let fieldAmount: CalldataFieldV1;\n let fieldDatetime: CalldataFieldV1;\n let fieldUnit: CalldataFieldV1;\n let fieldDuration: CalldataFieldV1;\n let fieldEnum: CalldataFieldV1;\n let fieldCalldata: CalldataFieldV1;\n const certificateLoaderMock = {\n loadCertificate: vi.fn(),\n };\n\n beforeAll(() => {\n vi.clearAllMocks();\n datasource = new HttpCalldataDescriptorDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n \"dapps\",\n );\n\n transactionInfo = {\n descriptor: {\n data: \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c\",\n signatures: {\n test: \"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n },\n },\n };\n enums = {\n \"0\": {\n \"1\": {\n data: \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65\",\n signatures: {\n test: \"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582\",\n },\n },\n \"2\": {\n data: \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65\",\n signatures: {\n test: \"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523\",\n },\n },\n },\n };\n\n fieldAmount = createFieldWithoutReference(\"FROM\", \"UFIXED\", \"AMOUNT\", \"06\");\n fieldDatetime = createFieldWithoutReference(\n \"TO\",\n \"FIXED\",\n \"DATETIME\",\n \"07\",\n );\n fieldUnit = createFieldWithoutReference(\"TO\", \"BOOL\", \"UNIT\", \"08\");\n fieldDuration = createFieldWithoutReference(\n \"VALUE\",\n \"INT\",\n \"DURATION\",\n \"09\",\n );\n fieldToken = {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"ARRAY\",\n start: 0,\n end: 5,\n weight: 1,\n },\n {\n type: \"LEAF\",\n leaf_type: \"DYNAMIC_LEAF\",\n },\n ],\n },\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n type: \"TOKEN_AMOUNT\",\n token: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"ARRAY\",\n start: 0,\n end: 5,\n weight: 1,\n },\n {\n type: \"LEAF\",\n leaf_type: \"DYNAMIC_LEAF\",\n },\n ],\n },\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n },\n descriptor:\n \"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178\",\n };\n fieldTrustedName = {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"CONTAINER\",\n value: \"TO\",\n },\n type_family: \"STRING\",\n type_size: 20,\n },\n type: \"TRUSTED_NAME\",\n types: [\"eoa\"],\n sources: [\"ens\", \"unstoppable_domain\"],\n },\n descriptor:\n \"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402\",\n };\n fieldNft = {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"ARRAY\",\n weight: 2,\n },\n {\n type: \"LEAF\",\n leaf_type: \"TUPLE_LEAF\",\n },\n {\n type: \"SLICE\",\n end: 2,\n },\n ],\n },\n type_family: \"BYTES\",\n type_size: 20,\n },\n collection: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"REF\",\n },\n {\n type: \"LEAF\",\n leaf_type: \"ARRAY_LEAF\",\n },\n {\n type: \"SLICE\",\n start: 1,\n },\n ],\n },\n type_family: \"INT\",\n type_size: 20,\n },\n type: \"NFT\",\n },\n descriptor:\n \"000100010c546f20726563697069656e7402010803230001000115000100010105020114\",\n };\n fieldEnum = {\n param: {\n id: 0,\n value: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [],\n },\n type_family: \"BYTES\",\n type_size: 20,\n },\n type: \"ENUM\",\n },\n descriptor:\n \"000100010c546f20726563697069656e7402010803230001000115000100010105020112\",\n };\n fieldCalldata = {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leaf_type: \"STATIC_LEAF\",\n },\n ],\n },\n type_family: \"BYTES\",\n type_size: 32,\n },\n callee: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"ARRAY\",\n weight: 1,\n },\n {\n type: \"LEAF\",\n leaf_type: \"DYNAMIC_LEAF\",\n },\n ],\n },\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n selector: {\n type: \"path\",\n binary_path: {\n type: \"CONTAINER\",\n value: \"FROM\",\n },\n type_family: \"BYTES\",\n type_size: 4,\n },\n amount: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"REF\",\n },\n {\n type: \"LEAF\",\n leaf_type: \"TUPLE_LEAF\",\n },\n ],\n },\n type_family: \"UINT\",\n type_size: 32,\n },\n spender: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"SLICE\",\n start: 0,\n end: 20,\n },\n {\n type: \"LEAF\",\n leaf_type: \"ARRAY_LEAF\",\n },\n ],\n },\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n type: \"CALLDATA\",\n },\n descriptor:\n \"000100010c43616c6c64617461207465737402010803230001000115000100010105020114\",\n };\n });\n\n function createFieldWithoutReference(\n binary_path: string,\n type_family: string,\n type: string,\n descriptor: string,\n ): CalldataFieldV1 {\n return {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"CONTAINER\",\n value: binary_path,\n },\n type_family,\n type_size: 32,\n },\n type,\n },\n descriptor,\n } as CalldataFieldV1;\n }\n\n function createCalldata(\n calldataTransactionInfo: CalldataTransactionInfoV1,\n calldataEnums: CalldataEnumV1,\n fields: unknown[],\n ): unknown {\n return {\n descriptors_calldata: {\n \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\": {\n \"0x69328dec\": {\n type: \"calldata\",\n version: \"v1\",\n transaction_info: calldataTransactionInfo,\n enums: calldataEnums,\n fields: fields,\n },\n },\n },\n };\n }\n\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x0abc\",\n selector: \"0x01ff\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: version,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n\n it.each([[\"dapps\"], [\"tokens\"]])(\n \"should call axios with the correct url for endpoint '%s'\",\n async (endpoint) => {\n // GIVEN\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n const customDataSource = new HttpCalldataDescriptorDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n endpoint,\n );\n\n // WHEN\n await customDataSource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x0abc\",\n selector: \"0x01ff\",\n });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n url: `https://crypto-assets-service.api.ledger.com/v1/${endpoint}`,\n }),\n );\n },\n );\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error());\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x0abc\",\n selector: \"0x01ff\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Failed to fetch calldata descriptors: Error\",\n ),\n ),\n );\n });\n\n it(\"should return an error when no payload is returned\", async () => {\n // GIVEN\n const response = { data: { test: \"\" } };\n vi.spyOn(axios, \"request\").mockResolvedValue(response);\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x0abc\",\n selector: \"0x01ff\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Response is not an array\",\n ),\n ),\n );\n });\n\n it(\"should return an error when an empty array is returned\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x0abc\",\n selector: \"0x01ff\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: No data for contract 0x0abc and selector 0x01ff\",\n ),\n ),\n );\n });\n\n it(\"should return an error when selector is not found\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(transactionInfo, enums, [fieldToken]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x01fe\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe\",\n ),\n ),\n );\n });\n\n it(\"Calldata with fields references and enums\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(transactionInfo, enums, [\n fieldToken,\n fieldTrustedName,\n fieldNft,\n fieldEnum,\n ]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dEc\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n payload:\n \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582\",\n type: \"enum\",\n id: 0,\n value: 1,\n },\n {\n payload:\n \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523\",\n type: \"enum\",\n id: 0,\n value: 2,\n },\n {\n payload: fieldToken.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"token\",\n valuePath: [\n {\n type: \"ARRAY\",\n start: 0,\n end: 5,\n itemSize: 1,\n },\n {\n type: \"LEAF\",\n leafType: \"DYNAMIC_LEAF\",\n },\n ],\n },\n },\n {\n payload: fieldTrustedName.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"trustedName\",\n valuePath: \"TO\",\n types: [\"eoa\"],\n sources: [\"ens\", \"unstoppable_domain\"],\n },\n },\n {\n payload: fieldNft.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"nft\",\n valuePath: [\n {\n type: \"REF\",\n },\n {\n type: \"LEAF\",\n leafType: \"ARRAY_LEAF\",\n },\n {\n type: \"SLICE\",\n start: 1,\n },\n ],\n },\n },\n {\n payload: fieldEnum.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"enum\",\n valuePath: [],\n id: 0,\n },\n },\n ]);\n });\n\n it(\"Calldata with fields references and enums with certificates\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(transactionInfo, enums, [\n fieldToken,\n fieldTrustedName,\n fieldNft,\n fieldEnum,\n ]);\n const certificate: PkiCertificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValueOnce(\n certificate,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dEc\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n // certificate is added to the transactionInfo\n certificate,\n },\n {\n payload:\n \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582\",\n type: \"enum\",\n id: 0,\n value: 1,\n // certificate is added also to the enum\n certificate,\n },\n {\n payload:\n \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523\",\n type: \"enum\",\n id: 0,\n value: 2,\n // certificate is added also to the enum\n certificate,\n },\n {\n payload: fieldToken.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"token\",\n valuePath: [\n {\n type: \"ARRAY\",\n start: 0,\n end: 5,\n itemSize: 1,\n },\n {\n type: \"LEAF\",\n leafType: \"DYNAMIC_LEAF\",\n },\n ],\n },\n },\n {\n payload: fieldTrustedName.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"trustedName\",\n valuePath: \"TO\",\n types: [\"eoa\"],\n sources: [\"ens\", \"unstoppable_domain\"],\n },\n },\n {\n payload: fieldNft.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"nft\",\n valuePath: [\n {\n type: \"REF\",\n },\n {\n type: \"LEAF\",\n leafType: \"ARRAY_LEAF\",\n },\n {\n type: \"SLICE\",\n start: 1,\n },\n ],\n },\n },\n {\n payload: fieldEnum.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"enum\",\n valuePath: [],\n id: 0,\n },\n },\n ]);\n });\n\n it(\"Calldata without fields references\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n [],\n [fieldAmount, fieldDatetime, fieldUnit, fieldDuration],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldAmount.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDatetime.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldUnit.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDuration.descriptor,\n },\n ]);\n });\n\n it(\"Calldata on third array element\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n [],\n [fieldAmount, fieldDatetime, fieldUnit, fieldDuration],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: [{}, {}, calldataDTO],\n });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldAmount.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDatetime.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldUnit.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDuration.descriptor,\n },\n ]);\n });\n\n it(\"Calldata without fields references and transaction info signature length % 2 different from 0\", async () => {\n // GIVEN\n const newTransactionInfo: CalldataTransactionInfoV1 = {\n descriptor: {\n data: transactionInfo.descriptor.data,\n signatures: {\n test: transactionInfo.descriptor.signatures.test + \"0\",\n },\n },\n };\n const calldataDTO = createCalldata(\n newTransactionInfo,\n [],\n [fieldAmount, fieldDatetime, fieldUnit, fieldDuration],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0\",\n type: \"transactionInfo\",\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldAmount.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDatetime.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldUnit.descriptor,\n },\n {\n type: \"transactionFieldDescription\",\n payload: fieldDuration.descriptor,\n },\n ]);\n });\n\n it(\"Calldata with token fields references as constants\", async () => {\n // GIVEN\n const field = {\n name: \"Amount to exchange\",\n param: {\n type: \"TOKEN_AMOUNT\",\n token: {\n raw: \"0xae7ab96520de3a18e5e111b5eaab095312d7fe84\",\n type: \"constant\",\n value: \"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84\",\n version: 1,\n type_size: 20,\n type_family: \"ADDRESS\",\n },\n value: {\n type: \"path\",\n version: 1,\n abi_path: {\n type: \"data\",\n absolute: true,\n elements: [\n {\n type: \"field\",\n identifier: \"_stETHAmount\",\n },\n ],\n },\n type_size: 32,\n binary_path: {\n type: \"DATA\",\n version: 1,\n elements: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leaf_type: \"STATIC_LEAF\",\n },\n ],\n },\n type_family: \"UINT\",\n },\n version: 1,\n },\n version: 1,\n descriptor:\n \"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n payload: field.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"token\",\n value: \"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84\",\n },\n },\n ]);\n });\n\n it(\"Calldata with collection fields references as constants\", async () => {\n // GIVEN\n const field = {\n name: \"Collection ID\",\n param: {\n type: \"NFT\",\n collection: {\n raw: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n type: \"constant\",\n value: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n version: 1,\n type_size: 20,\n type_family: \"ADDRESS\",\n },\n value: {\n type: \"path\",\n version: 1,\n abi_path: {\n type: \"data\",\n absolute: true,\n elements: [\n {\n type: \"field\",\n identifier: \"_collectionId\",\n },\n ],\n },\n type_size: 20,\n binary_path: {\n type: \"DATA\",\n version: 1,\n elements: [\n {\n type: \"ARRAY\",\n weight: 2,\n },\n {\n type: \"LEAF\",\n leaf_type: \"TUPLE_LEAF\",\n },\n {\n type: \"SLICE\",\n end: 2,\n },\n ],\n },\n type_family: \"BYTES\",\n },\n version: 1,\n },\n version: 1,\n descriptor:\n \"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n payload: field.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"nft\",\n value: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n },\n },\n ]);\n });\n\n it(\"Calldata with CALLDATA fields references\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(transactionInfo, [], [fieldCalldata]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n payload: fieldCalldata.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"calldata\",\n valuePath: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leafType: \"STATIC_LEAF\",\n },\n ],\n callee: [\n {\n type: \"ARRAY\",\n itemSize: 1,\n },\n {\n type: \"LEAF\",\n leafType: \"DYNAMIC_LEAF\",\n },\n ],\n selector: \"FROM\",\n amount: [\n {\n type: \"REF\",\n },\n {\n type: \"LEAF\",\n leafType: \"TUPLE_LEAF\",\n },\n ],\n spender: [\n {\n type: \"SLICE\",\n start: 0,\n end: 20,\n },\n {\n type: \"LEAF\",\n leafType: \"ARRAY_LEAF\",\n },\n ],\n },\n },\n ]);\n });\n\n it(\"Calldata with CALLDATA fields references without optional properties\", async () => {\n // GIVEN\n const fieldCalldataMinimal = {\n param: {\n value: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leaf_type: \"STATIC_LEAF\",\n },\n ],\n },\n type_family: \"BYTES\",\n type_size: 32,\n },\n callee: {\n type: \"path\",\n binary_path: {\n type: \"DATA\",\n elements: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leaf_type: \"STATIC_LEAF\",\n },\n ],\n },\n type_family: \"BYTES\",\n type_size: 32,\n },\n type: \"CALLDATA\",\n },\n descriptor:\n \"000100010c43616c6c64617461207465737402010803230001000115000100010105020114\",\n };\n const calldataDTO = createCalldata(\n transactionInfo,\n [],\n [fieldCalldataMinimal],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result.extract()).toEqual([\n {\n payload:\n \"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f\",\n type: \"transactionInfo\",\n },\n {\n payload: fieldCalldataMinimal.descriptor,\n type: \"transactionFieldDescription\",\n reference: {\n type: \"calldata\",\n valuePath: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leafType: \"STATIC_LEAF\",\n },\n ],\n callee: [\n {\n type: \"TUPLE\",\n offset: 0,\n },\n {\n type: \"LEAF\",\n leafType: \"STATIC_LEAF\",\n },\n ],\n selector: undefined,\n amount: undefined,\n spender: undefined,\n chainId: undefined,\n },\n },\n ]);\n });\n\n it(\"should return an error when calldata is not correctly formatted\", async () => {\n // GIVEN\n const calldataDTO = {\n descriptors_calldata: {\n \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\": {\n \"0x69328dec\": {\n type: \"calldat\",\n version: \"v1\",\n transaction_info: transactionInfo,\n enums: enums,\n fields: [fieldToken],\n },\n },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when transactionInfo is not correctly formatted\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n {\n descriptor: {\n data: \"1234\",\n signatures: {\n prod: \"1234\",\n },\n },\n },\n enums,\n [fieldToken],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when enum is not correctly formatted\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n [\"badEnum\"] as unknown as CalldataEnumV1,\n [fieldToken],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when enum does not contain a signature\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n { 0: { 1: { data: \"1234\" } } } as unknown as CalldataEnumV1,\n [fieldToken],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when enum contain the wrong signature\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n {\n 0: {\n 1: {\n data: \"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65\",\n signatures: {\n prod: \"wrongSignature\", // prod instead of test signature\n },\n },\n },\n },\n [fieldToken],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when field is not correctly formatted\", async () => {\n // GIVEN\n const calldataDTO = createCalldata(\n transactionInfo,\n [],\n [{ descriptor: 3 }],\n );\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when field value is not correctly formatted\", async () => {\n // GIVEN\n const field = {\n param: {\n value: {\n binary_path: \"TO\",\n type_family: \"UNKNOWN\",\n type_size: 20,\n },\n type: \"DATETIME\",\n },\n descriptor: \"000100010c546f20726563697069667\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when field container path is not correctly formatted\", async () => {\n // GIVEN\n const field = {\n param: {\n value: {\n binary_path: \"UNKNOWN\",\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n type: \"DATETIME\",\n },\n descriptor: \"000100010c546f20726563697069667\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when field calldata path is not correctly formatted\", async () => {\n // GIVEN\n const field = {\n param: {\n value: {\n binary_path: {\n elements: [\n {\n type: \"UNKNOWN\",\n },\n ],\n },\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n type: \"DATETIME\",\n },\n descriptor: \"000100010c546f20726563697069667\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should return an error when field type is not correctly formatted\", async () => {\n // GIVEN\n const field = {\n param: {\n value: {\n binary_path: \"TO\",\n type_family: \"ADDRESS\",\n type_size: 20,\n },\n type: \"UNKNOWN\",\n },\n descriptor: \"000100010c546f20726563697069667\",\n };\n const calldataDTO = createCalldata(transactionInfo, [], [field]);\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [calldataDTO] });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const result = await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpCalldataDescriptorDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec\",\n ),\n ),\n );\n });\n\n it(\"should call axios with the correct headers\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n await datasource.getCalldataDescriptors({\n deviceModelId: DeviceModelId.FLEX,\n chainId: 1,\n address: \"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9\",\n selector: \"0x69328dec\",\n });\n\n // THEN\n expect(axios.request).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: config.originToken,\n },\n }),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAOC,MAAW,QAClB,OAAS,QAAAC,MAAY,YAWrB,OACE,gCAAAC,EACA,8BAAAC,MACK,gCACP,OAAOC,MAAa,qBAEpB,OAAS,oCAAAC,MAAwC,qCAEjD,GAAG,KAAK,OAAO,EACf,MAAMC,EAAS,CACb,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,EACA,YAAa,aACf,EAEA,SAAS,mCAAoC,IAAM,CACjD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAwB,CAC5B,gBAAiB,GAAG,GAAG,CACzB,EAEA,UAAU,IAAM,CACd,GAAG,cAAc,EACjBZ,EAAa,IAAIF,EACfC,EACAa,EACA,OACF,EAEAX,EAAkB,CAChB,WAAY,CACV,KAAM,6PACN,WAAY,CACV,KAAM,gJACR,CACF,CACF,EACAC,EAAQ,CACN,EAAK,CACH,EAAK,CACH,KAAM,iHACN,WAAY,CACV,KAAM,gJACR,CACF,EACA,EAAK,CACH,KAAM,qHACN,WAAY,CACV,KAAM,gJACR,CACF,CACF,CACF,EAEAI,EAAcO,EAA4B,OAAQ,SAAU,SAAU,IAAI,EAC1EN,EAAgBM,EACd,KACA,QACA,WACA,IACF,EACAL,EAAYK,EAA4B,KAAM,OAAQ,OAAQ,IAAI,EAClEJ,EAAgBI,EACd,QACA,MACA,WACA,IACF,EACAV,EAAa,CACX,MAAO,CACL,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,MAAO,EACP,IAAK,EACL,OAAQ,CACV,EACA,CACE,KAAM,OACN,UAAW,cACb,CACF,CACF,EACA,YAAa,UACb,UAAW,EACb,EACA,KAAM,eACN,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,MAAO,EACP,IAAK,EACL,OAAQ,CACV,EACA,CACE,KAAM,OACN,UAAW,cACb,CACF,CACF,EACA,YAAa,UACb,UAAW,EACb,CACF,EACA,WACE,0OACJ,EACAC,EAAmB,CACjB,MAAO,CACL,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,YACN,MAAO,IACT,EACA,YAAa,SACb,UAAW,EACb,EACA,KAAM,eACN,MAAO,CAAC,KAAK,EACb,QAAS,CAAC,MAAO,oBAAoB,CACvC,EACA,WACE,oHACJ,EACAC,EAAW,CACT,MAAO,CACL,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,OAAQ,CACV,EACA,CACE,KAAM,OACN,UAAW,YACb,EACA,CACE,KAAM,QACN,IAAK,CACP,CACF,CACF,EACA,YAAa,QACb,UAAW,EACb,EACA,WAAY,CACV,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,KACR,EACA,CACE,KAAM,OACN,UAAW,YACb,EACA,CACE,KAAM,QACN,MAAO,CACT,CACF,CACF,EACA,YAAa,MACb,UAAW,EACb,EACA,KAAM,KACR,EACA,WACE,0EACJ,EACAK,EAAY,CACV,MAAO,CACL,GAAI,EACJ,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CAAC,CACb,EACA,YAAa,QACb,UAAW,EACb,EACA,KAAM,MACR,EACA,WACE,0EACJ,EACAC,EAAgB,CACd,MAAO,CACL,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,OAAQ,CACV,EACA,CACE,KAAM,OACN,UAAW,aACb,CACF,CACF,EACA,YAAa,QACb,UAAW,EACb,EACA,OAAQ,CACN,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,OAAQ,CACV,EACA,CACE,KAAM,OACN,UAAW,cACb,CACF,CACF,EACA,YAAa,UACb,UAAW,EACb,EACA,SAAU,CACR,KAAM,OACN,YAAa,CACX,KAAM,YACN,MAAO,MACT,EACA,YAAa,QACb,UAAW,CACb,EACA,OAAQ,CACN,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,KACR,EACA,CACE,KAAM,OACN,UAAW,YACb,CACF,CACF,EACA,YAAa,OACb,UAAW,EACb,EACA,QAAS,CACP,KAAM,OACN,YAAa,CACX,KAAM,OACN,SAAU,CACR,CACE,KAAM,QACN,MAAO,EACP,IAAK,EACP,EACA,CACE,KAAM,OACN,UAAW,YACb,CACF,CACF,EACA,YAAa,UACb,UAAW,EACb,EACA,KAAM,UACR,EACA,WACE,4EACJ,CACF,CAAC,EAED,SAASE,EACPC,EACAC,EACAC,EACAC,EACiB,CACjB,MAAO,CACL,MAAO,CACL,MAAO,CACL,KAAM,OACN,YAAa,CACX,KAAM,YACN,MAAOH,CACT,EACA,YAAAC,EACA,UAAW,EAC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qBACpB,OAAO,iBAAiB,CACtB,QAAS,CACP,CAACE,CAA4B,EAAG,kBAAkBE,EAAQ,OAAO,GACjE,CAACD,CAA0B,EAAGG,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "axios", "Left", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpCalldataDescriptorDataSource", "config", "datasource", "transactionInfo", "enums", "fieldToken", "fieldTrustedName", "fieldNft", "fieldAmount", "fieldDatetime", "fieldUnit", "fieldDuration", "fieldEnum", "fieldCalldata", "certificateLoaderMock", "createFieldWithoutReference", "binary_path", "type_family", "type", "descriptor", "createCalldata", "calldataTransactionInfo", "calldataEnums", "fields", "version", "requestSpy", "endpoint", "result", "response", "calldataDTO", "certificate", "newTransactionInfo", "field", "fieldCalldataMinimal"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ContainerModule as p}from"inversify";import{HttpCalldataDescriptorDataSource as e}from"../../calldata/data/HttpCalldataDescriptorDataSource";import{calldataTypes as o}from"../../calldata/di/calldataTypes";import{CalldataContextLoader as l}from"../../calldata/domain/CalldataContextLoader";import{configTypes as r}from"../../config/di/configTypes";import{pkiTypes as i}from"../../pki/di/pkiTypes";const s=()=>new p(({bind:t})=>{t(o.DappCalldataDescriptorDataSource).toDynamicValue(a=>new e(a.get(r.Config),a.get(i.PkiCertificateLoader),"dapps")),t(o.TokenCalldataDescriptorDataSource).toDynamicValue(a=>new e(a.get(r.Config),a.get(i.PkiCertificateLoader),"tokens")),t(o.CalldataContextLoader).to(l)});export{s as calldataModuleFactory};
|
|
2
|
+
//# sourceMappingURL=calldataModuleFactory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/calldata/di/calldataModuleFactory.ts"],
|
|
4
|
+
"sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpCalldataDescriptorDataSource } from \"@/calldata/data/HttpCalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { CalldataContextLoader } from \"@/calldata/domain/CalldataContextLoader\";\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\n\nexport const calldataModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(calldataTypes.DappCalldataDescriptorDataSource).toDynamicValue(\n (context) =>\n new HttpCalldataDescriptorDataSource(\n context.get(configTypes.Config),\n context.get(pkiTypes.PkiCertificateLoader),\n \"dapps\",\n ),\n );\n bind(calldataTypes.TokenCalldataDescriptorDataSource).toDynamicValue(\n (context) =>\n new HttpCalldataDescriptorDataSource(\n context.get(configTypes.Config),\n context.get(pkiTypes.PkiCertificateLoader),\n \"tokens\",\n ),\n );\n bind(calldataTypes.CalldataContextLoader).to(CalldataContextLoader);\n });\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,YAEhC,OAAS,oCAAAC,MAAwC,mDACjD,OAAS,iBAAAC,MAAqB,8BAC9B,OAAS,yBAAAC,MAA6B,0CACtC,OAAS,eAAAC,MAAmB,0BAC5B,OAAS,YAAAC,MAAgB,oBAElB,MAAMC,EAAwB,IACnC,IAAIN,EAAgB,CAAC,CAAE,KAAAO,CAAK,IAAM,CAChCA,EAAKL,EAAc,gCAAgC,EAAE,eAClDM,GACC,IAAIP,EACFO,EAAQ,IAAIJ,EAAY,MAAM,EAC9BI,EAAQ,IAAIH,EAAS,oBAAoB,EACzC,OACF,CACJ,EACAE,EAAKL,EAAc,iCAAiC,EAAE,eACnDM,GACC,IAAIP,EACFO,EAAQ,IAAIJ,EAAY,MAAM,EAC9BI,EAAQ,IAAIH,EAAS,oBAAoB,EACzC,QACF,CACJ,EACAE,EAAKL,EAAc,qBAAqB,EAAE,GAAGC,CAAqB,CACpE,CAAC",
|
|
6
|
+
"names": ["ContainerModule", "HttpCalldataDescriptorDataSource", "calldataTypes", "CalldataContextLoader", "configTypes", "pkiTypes", "calldataModuleFactory", "bind", "context"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const a={CalldataContextLoader:Symbol.for("CalldataContextLoader"),DappCalldataDescriptorDataSource:Symbol.for("DappCalldataDescriptorDataSource"),TokenCalldataDescriptorDataSource:Symbol.for("TokenCalldataDescriptorDataSource")};export{a as calldataTypes};
|
|
2
|
+
//# sourceMappingURL=calldataTypes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/calldata/di/calldataTypes.ts"],
|
|
4
|
+
"sourcesContent": ["export const calldataTypes = {\n CalldataContextLoader: Symbol.for(\"CalldataContextLoader\"),\n DappCalldataDescriptorDataSource: Symbol.for(\n \"DappCalldataDescriptorDataSource\",\n ),\n TokenCalldataDescriptorDataSource: Symbol.for(\n \"TokenCalldataDescriptorDataSource\",\n ),\n};\n"],
|
|
5
|
+
"mappings": "AAAO,MAAMA,EAAgB,CAC3B,sBAAuB,OAAO,IAAI,uBAAuB,EACzD,iCAAkC,OAAO,IACvC,kCACF,EACA,kCAAmC,OAAO,IACxC,mCACF,CACF",
|
|
6
|
+
"names": ["calldataTypes"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=(d,e,t,a)=>{for(var r=a>1?void 0:a?I(e,t):e,o=d.length-1,n;o>=0;o--)(n=d[o])&&(r=(a?n(e,t,r):n(r))||r);return a&&r&&g(e,t,r),r},i=(d,e)=>(t,a)=>e(t,a,d);import{DeviceModelId as P,isHexaString as C}from"@ledgerhq/device-management-kit";import{inject as y,injectable as M}from"inversify";import{MaybeAsync as D}from"purify-ts";import{calldataTypes as m}from"../../calldata/di/calldataTypes";import{proxyTypes as h}from"../../proxy/di/proxyTypes";import{ClearSignContextType as c}from"../../shared/model/ClearSignContext";const f=[c.TRANSACTION_INFO,c.TRANSACTION_FIELD_DESCRIPTION,c.PROXY_INFO,c.ENUM];let p=class{constructor(e,t,a){this.dappDataSource=e;this.tokenDataSource=t;this.proxyDataSource=a}canHandle(e,t){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&"deviceModelId"in e&&e.deviceModelId!==void 0&&e.deviceModelId!==P.NANO_S&&typeof e.chainId=="number"&&C(e.to)&&e.to!=="0x"&&C(e.data)&&C(e.selector)&&e.selector!=="0x"&&f.every(a=>t.includes(a))}async load(e){const{to:t,data:a,selector:r,chainId:o,deviceModelId:n}=e,s={address:t,chainId:o,selector:r,deviceModelId:n,data:a};return this._getContexts(s,this.dappDataSource).alt(this._getContexts(s,this.tokenDataSource)).alt(this._getContextsWithProxy(s,this.dappDataSource)).orDefault([{type:c.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}_getContexts({address:e,chainId:t,selector:a,deviceModelId:r},o){return D(async({liftMaybe:n})=>{const s=await o.getCalldataDescriptors({deviceModelId:r,address:e,chainId:t,selector:a});return n(s.toMaybe().filter(l=>l.length>0))})}_getContextsWithProxy({address:e,chainId:t,selector:a,deviceModelId:r,data:o},n){return D(async({liftMaybe:l})=>{const x=await this.proxyDataSource.getProxyImplementationAddress({calldata:o,proxyAddress:e,chainId:t,challenge:""});return l(x.toMaybe())}).map(({implementationAddress:l})=>{const x={address:l,chainId:t,selector:a,deviceModelId:r,data:o};return this._getContexts(x,n).map(u=>[{type:c.PROXY_INFO,payload:"0x"},...u])}).join()}};p=S([M(),i(0,y(m.DappCalldataDescriptorDataSource)),i(1,y(m.TokenCalldataDescriptorDataSource)),i(2,y(h.ProxyDataSource))],p);export{p as CalldataContextLoader};
|
|
2
|
+
//# sourceMappingURL=CalldataContextLoader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/calldata/domain/CalldataContextLoader.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n DeviceModelId,\n HexaString,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\nimport { MaybeAsync } from \"purify-ts\";\n\nimport type { CalldataDescriptorDataSource } from \"@/calldata/data/CalldataDescriptorDataSource\";\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport type { ProxyDataSource } from \"@/proxy/data/ProxyDataSource\";\nimport { proxyTypes } from \"@/proxy/di/proxyTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\n\nexport type CalldataContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n deviceModelId: DeviceModelId;\n};\n\ntype GetContextsParams = {\n address: string;\n chainId: number;\n data: string;\n selector: HexaString;\n deviceModelId: DeviceModelId;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n ClearSignContextType.PROXY_INFO,\n ClearSignContextType.ENUM,\n];\n\n@injectable()\nexport class CalldataContextLoader\n implements ContextLoader<CalldataContextInput>\n{\n constructor(\n @inject(calldataTypes.DappCalldataDescriptorDataSource)\n private dappDataSource: CalldataDescriptorDataSource,\n @inject(calldataTypes.TokenCalldataDescriptorDataSource)\n private tokenDataSource: CalldataDescriptorDataSource,\n @inject(proxyTypes.ProxyDataSource)\n private proxyDataSource: ProxyDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is CalldataContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n \"deviceModelId\" in input &&\n input.deviceModelId !== undefined &&\n input.deviceModelId !== DeviceModelId.NANO_S &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: CalldataContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId, deviceModelId } = input;\n\n const param: GetContextsParams = {\n address: to,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n\n return this._getContexts(param, this.dappDataSource)\n .alt(this._getContexts(param, this.tokenDataSource))\n .alt(this._getContextsWithProxy(param, this.dappDataSource))\n .orDefault([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] CalldataContextLoader: No calldata contexts found\",\n ),\n },\n ]);\n }\n\n private _getContexts(\n { address, chainId, selector, deviceModelId }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n return MaybeAsync(async ({ liftMaybe }) => {\n const result = await datasource.getCalldataDescriptors({\n deviceModelId,\n address,\n chainId,\n selector,\n });\n\n return liftMaybe(result.toMaybe().filter((ctxs) => ctxs.length > 0));\n });\n }\n\n private _getContextsWithProxy(\n { address, chainId, selector, deviceModelId, data }: GetContextsParams,\n datasource: CalldataDescriptorDataSource,\n ): MaybeAsync<ClearSignContext[]> {\n const proxyAddress = MaybeAsync(async ({ liftMaybe }) => {\n const result = await this.proxyDataSource.getProxyImplementationAddress({\n calldata: data,\n proxyAddress: address,\n chainId,\n challenge: \"\",\n });\n return liftMaybe(result.toMaybe());\n });\n\n return proxyAddress\n .map<MaybeAsync<ClearSignContext[]>>(({ implementationAddress }) => {\n const params = {\n address: implementationAddress,\n chainId,\n selector,\n deviceModelId,\n data,\n };\n return this._getContexts(params, datasource).map((contexts) => [\n // Add a proxy info context to the list of contexts\n // to specify that the proxy info should be refetched during the provide step\n {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"0x\",\n },\n ...contexts,\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,MACT,mEACF,CACF,CACF,CAAC,CACL,CAEQ,aACN,CAAE,QAAAgB,EAAS,QAAAH,EAAS,SAAAD,EAAU,cAAAE,CAAc,EAC5CG,EACgC,CAChC,OAAOC,EAAW,MAAO,CAAE,UAAAC,CAAU,IAAM,CACzC,MAAMC,EAAS,MAAMH,EAAW,uBAAuB,CACrD,cAAAH,EACA,QAAAE,EACA,QAAAH,EACA,SAAAD,CACF,CAAC,EAED,OAAOO,EAAUC,EAAO,QAAQ,EAAE,OAAQC,GAASA,EAAK,OAAS,CAAC,CAAC,CACrE,CAAC,CACH,CAEQ,sBACN,CAAE,QAAAL,EAAS,QAAAH,EAAS,SAAAD,EAAU,cAAAE,EAAe,KAAAH,CAAK,EAClDM,EACgC,CAWhC,OAVqBC,EAAW,MAAO,CAAE,UAAAC,CAAU,IAAM,CACvD,MAAMC,EAAS,MAAM,KAAK,gBAAgB,8BAA8B,CACtE,SAAUT,EACV,aAAcK,EACd,QAAAH,EACA,UAAW,EACb,CAAC,EACD,OAAOM,EAAUC,EAAO,QAAQ,CAAC,CACnC,CAAC,EAGE,IAAoC,CAAC,CAAE,sBAAAE,CAAsB,IAAM,CAClE,MAAMC,EAAS,CACb,QAASD,EACT,QAAAT,EACA,SAAAD,EACA,cAAAE,EACA,KAAAH,CACF,EACA,OAAO,KAAK,aAAaY,EAAQN,CAAU,EAAE,IAAKO,GAAa,CAG7D,CACE,KAAMxB,EAAqB,WAC3B,QAAS,IACX,EACA,GAAGwB,CACL,CAAC,CACH,CAAC,EACA,KAAK,CACV,CACF,EA/GavB,EAANwB,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAc,gCAAgC,GAErDF,EAAA,EAAAC,EAAOC,EAAc,iCAAiC,GAEtDF,EAAA,EAAAC,EAAOE,EAAW,eAAe,IARzB7B",
|
|
6
|
+
"names": ["DeviceModelId", "isHexaString", "inject", "injectable", "MaybeAsync", "calldataTypes", "proxyTypes", "ClearSignContextType", "SUPPORTED_TYPES", "ClearSignContextType", "CalldataContextLoader", "dappDataSource", "tokenDataSource", "proxyDataSource", "input", "expectedTypes", "DeviceModelId", "isHexaString", "type", "to", "data", "selector", "chainId", "deviceModelId", "param", "address", "datasource", "MaybeAsync", "liftMaybe", "result", "ctxs", "implementationAddress", "params", "contexts", "__decorateClass", "injectable", "__decorateParam", "inject", "calldataTypes", "proxyTypes"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{DeviceModelId as l}from"@ledgerhq/device-management-kit";import{Left as s,Right as n}from"purify-ts";import{CalldataContextLoader as f}from"../../calldata/domain/CalldataContextLoader";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";describe("CalldataContextLoader",()=>{const r=vi.fn(),d=vi.fn(),p=vi.fn(),u={getCalldataDescriptors:d},x={getCalldataDescriptors:p},I={getProxyImplementationAddress:r},o=new f(u,x,I),c=[a.TRANSACTION_INFO,a.TRANSACTION_FIELD_DESCRIPTION,a.PROXY_INFO,a.ENUM];beforeEach(()=>{vi.resetAllMocks()}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",chainId:1,deviceModelId:l.NANO_X};it("should return true for valid input",()=>{expect(o.canHandle(e,c)).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.NFT])).toBe(!1),expect(o.canHandle(e,[a.PROXY_INFO])).toBe(!1),expect(o.canHandle(e,[a.ENUM])).toBe(!1),expect(o.canHandle(e,[a.TRANSACTION_INFO])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"],[{...e,deviceModelId:void 0},"missing deviceModelId"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,deviceModelId:l.NANO_S},"deviceModelId is NANO_S"]])("should return false for %s",(t,i)=>{expect(o.canHandle(t,c)).toBe(!1)})}),it("should return an error if data source fails",async()=>{r.mockResolvedValue(s(new Error("data source error"))),d.mockResolvedValue(s(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(d).toHaveBeenCalledWith({address:"0x1234567890123456789012345678901234567890",chainId:3,selector:"0xaf68b302",deviceModelId:l.NANO_X}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])}),it("should return the contexts on success",async()=>{d.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue(s(new Error("data source error")));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return the proxy delegate call context on success",async()=>{d.mockResolvedValueOnce(n([])),d.mockResolvedValue(n([{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])),r.mockResolvedValue(n({implementationAddress:"0x1234567890abcdef",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(t).toEqual([{type:a.PROXY_INFO,payload:"0x"},{type:a.TRANSACTION_INFO,payload:"1234567890"},{type:a.TRANSACTION_FIELD_DESCRIPTION,payload:"deadbeef"}])}),it("should return an error when proxy delegate call succeeds but transaction descriptors for resolved address fail",async()=>{d.mockResolvedValueOnce(n([])),d.mockResolvedValueOnce(s(new Error("data source error"))),r.mockResolvedValue(n({implementationAddress:"0xResolvedAddress",signedDescriptor:"0x1234567890abcdef"}));const e={to:"0x1234567890123456789012345678901234567890",chainId:3,data:"0xaf68b302000000000000000000000000000000000000000000000000000000000002",selector:"0xaf68b302",deviceModelId:l.NANO_X},t=await o.load(e);expect(d).toHaveBeenCalledTimes(2),expect(d).toHaveBeenNthCalledWith(2,{address:"0xResolvedAddress",chainId:3,selector:"0xaf68b302",deviceModelId:l.NANO_X}),expect(t).toEqual([{type:a.ERROR,error:new Error("[ContextModule] CalldataContextLoader: No calldata contexts found")}])})});
|
|
2
|
+
//# sourceMappingURL=CalldataContextLoader.test.js.map
|