@ledgerhq/context-module 1.4.0 → 1.7.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 +2 -2
- package/lib/cjs/src/config/di/configModuleFactory.js +1 -1
- package/lib/cjs/src/config/di/configModuleFactory.js.map +3 -3
- 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/data/DynamicNetworkDataSource.js +2 -0
- package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +2 -0
- package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
- package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js +2 -0
- package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js.map +2 -2
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
- package/lib/cjs/src/external-plugin/di/externalPluginModuleFactory.js +1 -1
- package/lib/cjs/src/external-plugin/di/externalPluginModuleFactory.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/data/HttpNftDataSource.js +1 -1
- package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +3 -3
- package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
- package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +3 -3
- 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/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 +2 -2
- package/lib/cjs/src/pki/di/pkiModuleFactory.js +1 -1
- package/lib/cjs/src/pki/di/pkiModuleFactory.js.map +3 -3
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +2 -2
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
- package/lib/cjs/src/shared/constant/HttpHeaders.js +1 -1
- package/lib/cjs/src/shared/constant/HttpHeaders.js.map +1 -1
- package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
- package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
- package/lib/cjs/src/shared/model/SolanaTransactionContext.js +2 -0
- package/lib/cjs/src/shared/model/SolanaTransactionContext.js.map +7 -0
- 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/solana/data/HttpSolanaOwnerInfoDataSource.js +2 -0
- package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +7 -0
- package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +2 -0
- package/lib/cjs/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +7 -0
- package/lib/cjs/src/solana/data/SolanaDataSource.js +2 -0
- package/lib/cjs/src/solana/data/SolanaDataSource.js.map +7 -0
- package/lib/cjs/src/solana/di/SolanaContextModuleFactory.js +2 -0
- package/lib/cjs/src/solana/di/SolanaContextModuleFactory.js.map +7 -0
- package/lib/cjs/src/solana/di/solanaContextTypes.js +2 -0
- package/lib/cjs/src/solana/di/solanaContextTypes.js.map +7 -0
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js +2 -0
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.js.map +7 -0
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js +2 -0
- package/lib/cjs/src/solana/domain/DefaultSolanaContextLoader.test.js.map +7 -0
- package/lib/cjs/src/solana/domain/SolanaContextLoader.js +2 -0
- package/lib/cjs/src/solana/domain/SolanaContextLoader.js.map +7 -0
- package/lib/cjs/src/solana/domain/solanaContextTypes.js +2 -0
- package/lib/cjs/src/solana/domain/solanaContextTypes.js.map +7 -0
- 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/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 +2 -2
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +2 -0
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +7 -0
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +2 -0
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +7 -0
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +2 -2
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
- package/lib/cjs/src/transaction/data/{CalldataDto.js.map → dto/CalldataDto.js.map} +1 -1
- package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js +2 -0
- package/lib/cjs/src/transaction/data/dto/ProxyDelegateCallDto.js.map +7 -0
- package/lib/cjs/src/transaction/data/dto/ProxyImplementationAddressDto.js +2 -0
- package/lib/cjs/src/transaction/data/dto/ProxyImplementationAddressDto.js.map +7 -0
- package/lib/cjs/src/transaction/di/transactionModuleFactory.js +1 -1
- package/lib/cjs/src/transaction/di/transactionModuleFactory.js.map +3 -3
- package/lib/cjs/src/transaction/di/transactionTypes.js +1 -1
- package/lib/cjs/src/transaction/di/transactionTypes.js.map +2 -2
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
- package/lib/cjs/src/transaction/model/ProxyDelegateCall.js +2 -0
- package/lib/cjs/src/transaction/model/ProxyDelegateCall.js.map +7 -0
- package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js +2 -0
- package/lib/cjs/src/transaction/model/ProxyImplementationAddress.js.map +7 -0
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +2 -2
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
- 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/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 +2 -2
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +2 -2
- 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/di/typedDataModuleFactory.js +1 -1
- package/lib/cjs/src/typed-data/di/typedDataModuleFactory.js.map +3 -3
- package/lib/cjs/src/uniswap/di/uniswapModuleFactory.js +1 -1
- package/lib/cjs/src/uniswap/di/uniswapModuleFactory.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 +2 -2
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js.map +2 -2
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +2 -2
- package/lib/cjs/src/web3-check/di/web3CheckModuleFactory.js +1 -1
- package/lib/cjs/src/web3-check/di/web3CheckModuleFactory.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 +2 -2
- package/lib/esm/src/config/di/configModuleFactory.js +1 -1
- package/lib/esm/src/config/di/configModuleFactory.js.map +3 -3
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js +1 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
- package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +1 -0
- package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
- package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js +1 -0
- package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
- package/lib/esm/src/external-plugin/di/externalPluginModuleFactory.js +1 -1
- package/lib/esm/src/external-plugin/di/externalPluginModuleFactory.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/data/HttpNftDataSource.js +1 -1
- package/lib/esm/src/nft/data/HttpNftDataSource.js.map +3 -3
- package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
- package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +3 -3
- 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/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 +2 -2
- package/lib/esm/src/pki/di/pkiModuleFactory.js +1 -1
- package/lib/esm/src/pki/di/pkiModuleFactory.js.map +3 -3
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +2 -2
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
- package/lib/esm/src/shared/constant/HttpHeaders.js +1 -1
- package/lib/esm/src/shared/constant/HttpHeaders.js.map +1 -1
- package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
- package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
- package/lib/esm/src/shared/model/SolanaTransactionContext.js +1 -0
- package/lib/esm/src/shared/model/SolanaTransactionContext.js.map +7 -0
- package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js +2 -0
- package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.js.map +7 -0
- package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js +2 -0
- package/lib/esm/src/solana/data/HttpSolanaOwnerInfoDataSource.test.js.map +7 -0
- package/lib/esm/src/solana/data/SolanaDataSource.js +1 -0
- package/lib/esm/src/solana/data/SolanaDataSource.js.map +7 -0
- package/lib/esm/src/solana/di/SolanaContextModuleFactory.js +2 -0
- package/lib/esm/src/solana/di/SolanaContextModuleFactory.js.map +7 -0
- package/lib/esm/src/solana/di/solanaContextTypes.js +2 -0
- package/lib/esm/src/solana/di/solanaContextTypes.js.map +7 -0
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js +2 -0
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.js.map +7 -0
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js +2 -0
- package/lib/esm/src/solana/domain/DefaultSolanaContextLoader.test.js.map +7 -0
- package/lib/esm/src/solana/domain/SolanaContextLoader.js +1 -0
- package/lib/esm/src/solana/domain/SolanaContextLoader.js.map +7 -0
- package/lib/esm/src/solana/domain/solanaContextTypes.js +1 -0
- package/lib/esm/src/solana/domain/solanaContextTypes.js.map +7 -0
- 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/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 +2 -2
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js +2 -0
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +7 -0
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +2 -0
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +7 -0
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
- package/lib/esm/src/transaction/data/dto/CalldataDto.js.map +7 -0
- package/lib/esm/src/transaction/data/dto/ProxyDelegateCallDto.js +1 -0
- package/lib/esm/src/transaction/data/dto/ProxyDelegateCallDto.js.map +7 -0
- package/lib/esm/src/transaction/data/dto/ProxyImplementationAddressDto.js +1 -0
- package/lib/esm/src/transaction/data/dto/ProxyImplementationAddressDto.js.map +7 -0
- package/lib/esm/src/transaction/di/transactionModuleFactory.js +1 -1
- package/lib/esm/src/transaction/di/transactionModuleFactory.js.map +3 -3
- package/lib/esm/src/transaction/di/transactionTypes.js +1 -1
- package/lib/esm/src/transaction/di/transactionTypes.js.map +2 -2
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
- package/lib/esm/src/transaction/model/ProxyDelegateCall.js +1 -0
- package/lib/esm/src/transaction/model/ProxyDelegateCall.js.map +7 -0
- package/lib/esm/src/transaction/model/ProxyImplementationAddress.js +1 -0
- package/lib/esm/src/transaction/model/ProxyImplementationAddress.js.map +7 -0
- 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 +3 -3
- 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/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 +2 -2
- 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/di/typedDataModuleFactory.js +1 -1
- package/lib/esm/src/typed-data/di/typedDataModuleFactory.js.map +3 -3
- package/lib/esm/src/uniswap/di/uniswapModuleFactory.js +1 -1
- package/lib/esm/src/uniswap/di/uniswapModuleFactory.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 +2 -2
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js.map +3 -3
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
- package/lib/esm/src/web3-check/di/web3CheckModuleFactory.js +1 -1
- package/lib/esm/src/web3-check/di/web3CheckModuleFactory.js.map +3 -3
- package/lib/types/src/ContextModule.d.ts +3 -0
- package/lib/types/src/ContextModule.d.ts.map +1 -1
- package/lib/types/src/ContextModuleBuilder.d.ts +18 -3
- package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
- package/lib/types/src/DefaultContextModule.d.ts +5 -0
- package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
- package/lib/types/src/config/di/configModuleFactory.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleConfig.d.ts +6 -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/data/DynamicNetworkDataSource.d.ts +6 -0
- package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +13 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts +2 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts +14 -0
- package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts +3 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts +5 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +15 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts +2 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts +16 -0
- package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts.map +1 -0
- package/lib/types/src/external-plugin/data/HttpExternalPluginDataSource.d.ts.map +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +2 -0
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/nft/data/HttpNftDataSource.d.ts +3 -0
- package/lib/types/src/nft/data/HttpNftDataSource.d.ts.map +1 -1
- package/lib/types/src/nft/domain/NftContextLoader.d.ts +1 -1
- package/lib/types/src/nft/domain/NftContextLoader.d.ts.map +1 -1
- package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
- package/lib/types/src/shared/constant/HttpHeaders.d.ts +1 -1
- package/lib/types/src/shared/constant/HttpHeaders.d.ts.map +1 -1
- package/lib/types/src/shared/model/ClearSignContext.d.ts +3 -0
- package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
- package/lib/types/src/shared/model/SolanaTransactionContext.d.ts +11 -0
- package/lib/types/src/shared/model/SolanaTransactionContext.d.ts.map +1 -0
- package/lib/types/src/shared/model/TransactionSubset.d.ts +3 -3
- package/lib/types/src/shared/model/TransactionSubset.d.ts.map +1 -1
- package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts +13 -0
- package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.d.ts.map +1 -0
- package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.test.d.ts +2 -0
- package/lib/types/src/solana/data/HttpSolanaOwnerInfoDataSource.test.d.ts.map +1 -0
- package/lib/types/src/solana/data/SolanaDataSource.d.ts +12 -0
- package/lib/types/src/solana/data/SolanaDataSource.d.ts.map +1 -0
- package/lib/types/src/solana/di/SolanaContextModuleFactory.d.ts +3 -0
- package/lib/types/src/solana/di/SolanaContextModuleFactory.d.ts.map +1 -0
- package/lib/types/src/solana/di/solanaContextTypes.d.ts +5 -0
- package/lib/types/src/solana/di/solanaContextTypes.d.ts.map +1 -0
- package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts +11 -0
- package/lib/types/src/solana/domain/DefaultSolanaContextLoader.d.ts.map +1 -0
- package/lib/types/src/solana/domain/DefaultSolanaContextLoader.test.d.ts +2 -0
- package/lib/types/src/solana/domain/DefaultSolanaContextLoader.test.d.ts.map +1 -0
- package/lib/types/src/solana/domain/SolanaContextLoader.d.ts +5 -0
- package/lib/types/src/solana/domain/SolanaContextLoader.d.ts.map +1 -0
- package/lib/types/src/solana/domain/solanaContextTypes.d.ts +27 -0
- package/lib/types/src/solana/domain/solanaContextTypes.d.ts.map +1 -0
- package/lib/types/src/token/domain/TokenContextLoader.d.ts +1 -1
- package/lib/types/src/token/domain/TokenContextLoader.d.ts.map +1 -1
- package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts +33 -0
- package/lib/types/src/transaction/data/HttpProxyDataSource.d.ts.map +1 -0
- package/lib/types/src/transaction/data/HttpProxyDataSource.test.d.ts +2 -0
- package/lib/types/src/transaction/data/HttpProxyDataSource.test.d.ts.map +1 -0
- package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
- package/lib/types/src/transaction/data/dto/CalldataDto.d.ts.map +1 -0
- package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts +5 -0
- package/lib/types/src/transaction/data/dto/ProxyDelegateCallDto.d.ts.map +1 -0
- package/lib/types/src/transaction/data/dto/ProxyImplementationAddressDto.d.ts +6 -0
- package/lib/types/src/transaction/data/dto/ProxyImplementationAddressDto.d.ts.map +1 -0
- package/lib/types/src/transaction/di/transactionModuleFactory.d.ts.map +1 -1
- package/lib/types/src/transaction/di/transactionTypes.d.ts +1 -0
- package/lib/types/src/transaction/di/transactionTypes.d.ts.map +1 -1
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +4 -2
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
- package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts +5 -0
- package/lib/types/src/transaction/model/ProxyDelegateCall.d.ts.map +1 -0
- package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts +4 -0
- package/lib/types/src/transaction/model/ProxyImplementationAddress.d.ts.map +1 -0
- package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts +1 -1
- package/lib/types/src/trusted-name/domain/TrustedNameContextLoader.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
- package/lib/types/src/web3-check/data/HttpWeb3CheckDataSource.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/lib/types/src/transaction/data/CalldataDto.d.ts.map +0 -1
- /package/lib/cjs/src/transaction/data/{CalldataDto.js → dto/CalldataDto.js} +0 -0
- /package/lib/esm/src/{transaction/data/CalldataDto.js.map → dynamic-network/data/DynamicNetworkDataSource.js.map} +0 -0
- /package/lib/esm/src/transaction/data/{CalldataDto.js → dto/CalldataDto.js} +0 -0
- /package/lib/types/src/transaction/data/{CalldataDto.d.ts → dto/CalldataDto.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n HexaString,\n hexaStringToBuffer,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport {\n UNISWAP_PLUGIN_NAME,\n UNISWAP_PLUGIN_SIGNATURE,\n} from \"@/uniswap/constants/plugin\";\nimport {\n UNISWAP_COMMANDS,\n UNISWAP_EXECUTE_ABI,\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_SWAP_COMMANDS,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\n@injectable()\nexport class UniswapContextLoader implements ContextLoader {\n constructor(\n @inject(uniswapTypes.CommandDecoderDataSource)\n private commandDecoderDataSource: CommandDecoderDataSource,\n @inject(tokenTypes.TokenDataSource)\n private tokenDataSource: TokenDataSource,\n ) {}\n\n async load(
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,2CACPC,EAA0B,kBAC1BC,EAAmC,qBACnCC,EAA+B,qBAG/BC,EAGO,2CAGPC,EAA2B,iCAC3BC,EAGO,sCACPC,EAOO,uCAEPC,EAA6B,qCAGtB,IAAMC,EAAN,KAAoD,CACzD,YAEUC,EAEAC,EACR,CAHQ,8BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,
|
|
6
|
-
"names": ["UniswapContextLoader_exports", "__export", "UniswapContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_ClearSignContext", "import_tokenTypes", "import_plugin", "import_uniswap", "import_uniswapTypes", "UniswapContextLoader", "commandDecoderDataSource", "tokenDataSource", "
|
|
4
|
+
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n HexaString,\n hexaStringToBuffer,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport {\n UNISWAP_PLUGIN_NAME,\n UNISWAP_PLUGIN_SIGNATURE,\n} from \"@/uniswap/constants/plugin\";\nimport {\n UNISWAP_COMMANDS,\n UNISWAP_EXECUTE_ABI,\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_SWAP_COMMANDS,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\n@injectable()\nexport class UniswapContextLoader implements ContextLoader {\n constructor(\n @inject(uniswapTypes.CommandDecoderDataSource)\n private commandDecoderDataSource: CommandDecoderDataSource,\n @inject(tokenTypes.TokenDataSource)\n private tokenDataSource: TokenDataSource,\n ) {}\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n const { data, selector, chainId } = ctx;\n if (!isHexaString(data)) {\n return [];\n }\n\n if (selector !== UNISWAP_EXECUTE_SELECTOR) {\n return [];\n }\n\n const externalPluginContext = this._buildUniswapPluginCommandData();\n const tokenContexts = await this._extractClearSignContexts(data, chainId);\n\n if (tokenContexts.length > 0)\n return [externalPluginContext, ...tokenContexts];\n\n return [];\n }\n\n /**\n * Constructs the external plugin context for Uniswap external plugin command.\n *\n * @private\n * @returns {ClearSignContext} - The generated external plugin context.\n */\n private _buildUniswapPluginCommandData(): ClearSignContext {\n const buffer = new ByteArrayBuilder()\n .add8BitUIntToData(UNISWAP_PLUGIN_NAME.length)\n .addAsciiStringToData(UNISWAP_PLUGIN_NAME)\n .addBufferToData(hexaStringToBuffer(UNISWAP_UNIVERSAL_ROUTER_ADDRESS)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_EXECUTE_SELECTOR)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_PLUGIN_SIGNATURE)!)\n .build();\n\n return {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: bufferToHexaString(buffer, false),\n };\n }\n\n /**\n * Extracts and decodes the clear sign contexts from a Uniswap calldata transaction.\n *\n * This function:\n * - Parses the calldata using the Uniswap `execute` function signature.\n * - Extracts and validates the `commands` and `inputs`.\n * - Decodes the commands and ensures they match the number of inputs.\n * - Extracts addresses used in the transaction and verifies if chaining swaps are supported.\n * - Fetches token information for unique addresses.\n * - Returns an array of `ClearSignContext` objects representing either token data or errors.\n *\n * @private\n * @param {HexaString} calldata - The raw calldata of the Uniswap transaction.\n * @param {number} chainId - The blockchain chain ID where the transaction is being executed.\n * @returns {Promise<ClearSignContext[]>} - A promise resolving to an array of clear sign contexts.\n */\n private async _extractClearSignContexts(\n calldata: HexaString,\n chainId: number,\n ): Promise<ClearSignContext[]> {\n try {\n const iface = new Interface(UNISWAP_EXECUTE_ABI);\n\n const tx = iface.parseTransaction({ data: calldata });\n const commands: unknown = tx?.args[0];\n const inputs: unknown = tx?.args[1];\n\n if (!isHexaString(commands) || !this._isHexaStringArray(inputs)) {\n return [];\n }\n\n const decodedCommands = this._extractCommands(commands).orDefault([]);\n if (commands.length === 0 || inputs.length !== decodedCommands.length) {\n // Invalid commands or inputs\n return [];\n }\n\n const addressesByCommand = decodedCommands.reduce(\n (acc, command, index) => {\n const input = inputs[index]!;\n const decoded: HexaString[] = this.commandDecoderDataSource.decode(\n command,\n input,\n chainId,\n );\n\n acc.push([command, decoded]);\n\n return acc;\n },\n [] as [UniswapSupportedCommand, HexaString[]][],\n );\n\n if (!this._isChainingSwapSupported(addressesByCommand)) {\n return [];\n }\n\n const uniqueAddresses = [\n ...new Set(addressesByCommand.flatMap(([, addresses]) => addresses)),\n ];\n\n const tokensPayload = await Promise.all(\n uniqueAddresses.map((address) =>\n this.tokenDataSource.getTokenInfosPayload({ address, chainId }),\n ),\n );\n\n return tokensPayload.map((either) =>\n either.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n } catch (_) {\n return [];\n }\n }\n\n /**\n * Extracts Uniswap-supported commands from a hexadecimal string.\n * Each command is represented by one byte (2 hex characters), and this function:\n * - Maps each command to a known Uniswap command.\n * - Returns `Nothing` if any extracted command is unsupported.\n *\n * @private\n * @param {HexaString} hex - A hexadecimal string representing commands.\n * @returns {Maybe<UniswapSupportedCommand[]>} - A `Maybe` containing an array of recognized commands, or `Nothing` if any command is unsupported.\n *\n * @example\n * // Valid command extraction\n * _extractCommands('0x0008');\n * // Returns: Just(['0x00', '0x08'])\n *\n * @example\n * // Contains an unsupported command (0x05 is not supported)\n * _extractCommands('0x0005');\n * // Returns: Nothing\n *\n * @example\n * // Empty or invalid input\n * _extractCommands('0x');\n * // Returns: Nothing\n */\n private _extractCommands(hex: HexaString): Maybe<UniswapSupportedCommand[]> {\n return Maybe.fromNullable(hex.slice(2).match(/../g))\n .map((bytes) => bytes.map((b) => `0x${b}` as HexaString))\n .map((hexBytes) => hexBytes.map((b) => UNISWAP_COMMANDS[b]))\n .chain((commands) =>\n commands.every((command) => command !== undefined)\n ? Maybe.of(commands as UniswapSupportedCommand[])\n : Nothing,\n );\n }\n\n /**\n * Checks if the provided swap commands can be chained together.\n * A valid chain requires that:\n * - The output asset of the previous swap matches the input asset of the next swap.\n * - The pool version remains consistent across swaps.\n *\n * @private\n * @param {Array<[UniswapSupportedCommand, HexaString[]]>} data - An array of tuples containing a swap command and associated addresses.\n * @returns {boolean} - Returns `true` if the swap commands form a valid chain, otherwise `false`.\n *\n * @example\n * // Valid chaining: same output/input asset and pool version\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x08', ['0xDEF', '0x123']]\n * ]);\n * // Returns: true\n *\n * @example\n * // Invalid chaining: different pool versions\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x01', ['0xDEF', '0x123']]\n * ]);\n * // Returns: false\n *\n * @example\n * // Invalid chaining: output does not match next input\n * _isChainingSwapSupported([\n * ['0x01A1', ['0xABC', '0xDEF']],\n * ['0x01B2', ['0xXYZ', '0x123']]\n * ]);\n * // Returns: false\n */\n private _isChainingSwapSupported(\n data: [UniswapSupportedCommand, HexaString[]][],\n ): boolean {\n let lastAsset: HexaString | undefined = undefined;\n let lastPoolVersion: string | undefined = undefined;\n\n for (const [command, addresses] of data) {\n if (!UNISWAP_SWAP_COMMANDS.includes(command)) continue; // Ignore non-swap commands\n\n const poolVersion = command.slice(0, 2);\n\n if (\n lastAsset &&\n (lastAsset !== addresses[0] || lastPoolVersion !== poolVersion)\n ) {\n // Invalid chaining, return empty array\n return false;\n }\n\n // update last asset and pool version\n lastAsset = addresses[addresses.length - 1];\n lastPoolVersion = poolVersion;\n }\n\n return true;\n }\n\n /**\n * Checks if a given value is an array of hexadecimal strings.\n *\n * @private\n * @param {unknown} array - The value to check.\n * @returns {array is HexaString[]} - `true` if the value is an array of hexadecimal strings, otherwise `false`.\n */\n private _isHexaStringArray(array: unknown): array is HexaString[] {\n return (\n Array.isArray(array) &&\n array.every((item) => typeof item === \"string\" && isHexaString(item))\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,2CACPC,EAA0B,kBAC1BC,EAAmC,qBACnCC,EAA+B,qBAG/BC,EAGO,2CAGPC,EAA2B,iCAC3BC,EAGO,sCACPC,EAOO,uCAEPC,EAA6B,qCAGtB,IAAMC,EAAN,KAAoD,CACzD,YAEUC,EAEAC,EACR,CAHQ,8BAAAD,EAEA,qBAAAC,CACP,CAEH,MAAM,KAAKC,EAAsD,CAC/D,KAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,CAAQ,EAAIH,EACpC,GAAI,IAAC,gB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AC,CAExE,CACF,EA5OanC,EAANoC,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,eAAa,wBAAwB,GAE5CA,EAAA,eAAO,aAAW,eAAe,IAJzBrC",
|
|
6
|
+
"names": ["UniswapContextLoader_exports", "__export", "UniswapContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_ClearSignContext", "import_tokenTypes", "import_plugin", "import_uniswap", "import_uniswapTypes", "UniswapContextLoader", "commandDecoderDataSource", "tokenDataSource", "ctx", "data", "selector", "chainId", "externalPluginContext", "tokenContexts", "buffer", "calldata", "tx", "commands", "inputs", "decodedCommands", "addressesByCommand", "acc", "command", "index", "input", "decoded", "uniqueAddresses", "addresses", "address", "either", "error", "payload", "hex", "bytes", "b", "hexBytes", "lastAsset", "lastPoolVersion", "poolVersion", "array", "item", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=require("ethers"),r=require("purify-ts"),f=require("../../shared/model/ClearSignContext"),e=require("../../uniswap/constants/uniswap"),l=require("../../uniswap/data/DefaultCommandDecoderDataSource"),x=require("../../uniswap/data/EthersAbiDecoderDataSource"),p=require("./UniswapContextLoader");describe("UniswapContextLoader",()=>{const t={decode:vi.fn()},o={getTokenInfosPayload:vi.fn()};let c;describe("load",()=>{describe("with tokenDataSourceMock",()=>{beforeEach(()=>{vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,r.Right)(`payload-${a}`))),c=new p.UniswapContextLoader(new l.DefaultCommandDecoderDataSource(new x.EthersAbiDecoderDataSource),o)}),it("should return the external plugin context and the decoded contexts",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee"},n=await c.load(a);expect(n).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}])}),it("should return the external plugin context and the decoded contexts with a permit",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771"},n=await c.load(a);expect(n).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"},{type:"token",payload:"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e"}])}),it("should return an empty array if the transaction is not supported",async()=>{const a={};vi.spyOn(t,"decode").mockReturnValue([]);const n=await c.load(a);expect(n).toEqual([])}),it("should return an empty array if a command is not supported",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8"},n=await c.load(a);expect(n).toEqual([])})}),describe("with mocked ethers parseTransaction",()=>{beforeEach(()=>{vi.resetAllMocks(),c=new p.UniswapContextLoader(t,o)}),it("should return an array with contexts if 2 chain swaps are supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x04","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x04",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x04"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an array with contexts if 1 chain swap with a non swap command",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0b0004",["0x0001","0x0002","0x0003"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x04"]),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.WRAP_ETH,"0x0001",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x04",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"},{type:"token",payload:"payload-0x04"}])}),it("should return an array with contexts if one token is not found",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(o,"getTokenInfosPayload").mockResolvedValueOnce((0,r.Left)("error")),vi.spyOn(o,"getTokenInfosPayload").mockImplementation(({address:i})=>Promise.resolve((0,r.Right)(`payload-${i}`)));const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(o.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"error",error:"error"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an empty array if the if 2 chain swaps are not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(t,"decode").mockReturnValueOnce(["0x01","0x02"]),vi.spyOn(t,"decode").mockReturnValueOnce(["0x03","0x04"]);const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if no command are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:[""]});const n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if no inputs are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x08",[]]});const n=await c.load(a);expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if parseTransaction throws an error",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockImplementation(()=>{throw new Error});const n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if the swap is with multiple pool versions",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x080900",["0x00","0x01","0x02"]]}),vi.spyOn(t,"decode").mockReturnValue(["0x01","0x02"]);const d=await c.load(a);expect(t.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x00",66),expect(t.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x01",66),expect(t.decode).toHaveBeenNthCalledWith(3,e.UniswapSupportedCommand.V3_SWAP_EXACT_IN,"0x02",66),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if the selector is not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:"0x00000000",chainId:66},n=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(n).toEqual([])}),it("should return an empty array if the length of the commands and inputs are different",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001"]]});const d=await c.load(a);expect(t.decode).not.toHaveBeenCalled(),expect(o.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])})})})});
|
|
1
|
+
"use strict";var s=require("ethers"),r=require("purify-ts"),f=require("../../shared/model/ClearSignContext"),e=require("../../uniswap/constants/uniswap"),p=require("../../uniswap/data/DefaultCommandDecoderDataSource"),x=require("../../uniswap/data/EthersAbiDecoderDataSource"),i=require("./UniswapContextLoader");describe("UniswapContextLoader",()=>{const n={decode:vi.fn()},t={getTokenInfosPayload:vi.fn()};let c;describe("load",()=>{describe("with tokenDataSourceMock",()=>{beforeEach(()=>{vi.spyOn(t,"getTokenInfosPayload").mockImplementation(({address:a})=>Promise.resolve((0,r.Right)(`payload-${a}`))),c=new i.UniswapContextLoader(new p.DefaultCommandDecoderDataSource(new x.EthersAbiDecoderDataSource),t)}),it("should return an empty array if the selector is not UNISWAP_EXECUTE_SELECTOR",async()=>{const a={selector:"0x00000000",data:"0x00000000"},o=await c.load(a);expect(o).toEqual([])}),it("should return the external plugin context and the decoded contexts",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee",selector:e.UNISWAP_EXECUTE_SELECTOR},o=await c.load(a);expect(o).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}])}),it("should return the external plugin context and the decoded contexts with a permit",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771",selector:e.UNISWAP_EXECUTE_SELECTOR},o=await c.load(a);expect(o).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"},{type:"token",payload:"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e"}])}),it("should return an empty array if the transaction is not supported",async()=>{const a={};vi.spyOn(n,"decode").mockReturnValue([]);const o=await c.load(a);expect(o).toEqual([])}),it("should return an empty array if a command is not supported",async()=>{const a={chainId:1,data:"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8",selector:e.UNISWAP_EXECUTE_SELECTOR},o=await c.load(a);expect(o).toEqual([])})}),describe("with mocked ethers parseTransaction",()=>{beforeEach(()=>{vi.resetAllMocks(),c=new i.UniswapContextLoader(n,t)}),it("should return an array with contexts if 2 chain swaps are supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(n,"decode").mockReturnValueOnce(["0x01","0x04","0x02"]).mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(t,"getTokenInfosPayload").mockImplementation(({address:l})=>Promise.resolve((0,r.Right)(`payload-${l}`)));const d=await c.load(a);expect(n.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(n.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x04",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x02",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x04"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an array with contexts if 1 chain swap with a non swap command",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0b0004",["0x0001","0x0002","0x0003"]]}),vi.spyOn(n,"decode").mockReturnValueOnce(["0x01"]).mockReturnValueOnce(["0x02","0x03"]).mockReturnValueOnce(["0x04"]),vi.spyOn(t,"getTokenInfosPayload").mockImplementation(({address:l})=>Promise.resolve((0,r.Right)(`payload-${l}`)));const d=await c.load(a);expect(n.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.WRAP_ETH,"0x0001",66),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(4,{address:"0x04",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"token",payload:"payload-0x01"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"},{type:"token",payload:"payload-0x04"}])}),it("should return an array with contexts if one token is not found",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(n,"decode").mockReturnValueOnce(["0x01","0x02"]).mockReturnValueOnce(["0x02","0x03"]),vi.spyOn(t,"getTokenInfosPayload").mockResolvedValueOnce((0,r.Left)("error")).mockImplementation(({address:l})=>Promise.resolve((0,r.Right)(`payload-${l}`)));const d=await c.load(a);expect(n.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(n.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(1,{address:"0x01",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(2,{address:"0x02",chainId:66}),expect(t.getTokenInfosPayload).toHaveBeenNthCalledWith(3,{address:"0x03",chainId:66}),expect(d).toEqual([{type:f.ClearSignContextType.EXTERNAL_PLUGIN,payload:"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935"},{type:"error",error:"error"},{type:"token",payload:"payload-0x02"},{type:"token",payload:"payload-0x03"}])}),it("should return an empty array if the if 2 chain swaps are not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001","0x0002"]]}),vi.spyOn(n,"decode").mockReturnValueOnce(["0x01","0x02"]),vi.spyOn(n,"decode").mockReturnValueOnce(["0x03","0x04"]);const d=await c.load(a);expect(n.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x0001",66),expect(n.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x0002",66),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if no command are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:[""]});const o=await c.load(a);expect(n.decode).not.toHaveBeenCalled(),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(o).toEqual([])}),it("should return an empty array if no inputs are returned from parseTransaction",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x08",[]]});const o=await c.load(a);expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(o).toEqual([])}),it("should return an empty array if parseTransaction throws an error",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockImplementation(()=>{throw new Error});const o=await c.load(a);expect(n.decode).not.toHaveBeenCalled(),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(o).toEqual([])}),it("should return an empty array if the swap is with multiple pool versions",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x080900",["0x00","0x01","0x02"]]}),vi.spyOn(n,"decode").mockReturnValue(["0x01","0x02"]);const d=await c.load(a);expect(n.decode).toHaveBeenNthCalledWith(1,e.UniswapSupportedCommand.V2_SWAP_EXACT_IN,"0x00",66),expect(n.decode).toHaveBeenNthCalledWith(2,e.UniswapSupportedCommand.V2_SWAP_EXACT_OUT,"0x01",66),expect(n.decode).toHaveBeenNthCalledWith(3,e.UniswapSupportedCommand.V3_SWAP_EXACT_IN,"0x02",66),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])}),it("should return an empty array if the selector is not supported",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:"0x00000000",chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR},o=await c.load(a);expect(n.decode).not.toHaveBeenCalled(),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(o).toEqual([])}),it("should return an empty array if the length of the commands and inputs are different",async()=>{const a={to:e.UNISWAP_UNIVERSAL_ROUTER_ADDRESS,data:e.UNISWAP_EXECUTE_SELECTOR,chainId:66,selector:e.UNISWAP_EXECUTE_SELECTOR};vi.spyOn(s.Interface.prototype,"parseTransaction").mockReturnValue({args:["0x0809",["0x0001"]]});const d=await c.load(a);expect(n.decode).not.toHaveBeenCalled(),expect(t.getTokenInfosPayload).not.toHaveBeenCalled(),expect(d).toEqual([])})})})});
|
|
2
2
|
//# sourceMappingURL=UniswapContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Interface, type TransactionDescription } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport {\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\n\nimport { UniswapContextLoader } from \"./UniswapContextLoader\";\n\ndescribe(\"UniswapContextLoader\", () => {\n const commandDecoderMock: CommandDecoderDataSource = {\n decode: vi.fn(),\n };\n const tokenDataSourceMock = {\n getTokenInfosPayload: vi.fn(),\n };\n let loader: UniswapContextLoader;\n\n describe(\"load\", () => {\n describe(\"with tokenDataSourceMock\", () => {\n beforeEach(() => {\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return the external plugin context and the decoded contexts\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e\",\n }, // ERC20\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n ]);\n });\n\n it(\"should return the external plugin context and the decoded contexts with a permit\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc4df7ccc0527541d0e80856a8f38deedc48c84825e9355469ba02d873502ce2f\n // PERMIT2_PERMIT, V3_SWAP_EXACT_OUT, UNWRAP_ETH\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n {\n type: \"token\",\n payload: \"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e\",\n }, // ERC20\n ]);\n });\n\n it(\"should return an empty array if the transaction is not supported\", async () => {\n // GIVEN\n const transactionContext = {} as TransactionContext;\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if a command is not supported\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n // The command 0x05 (TRANSFER) is not supported\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"with mocked ethers parseTransaction\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n loader = new UniswapContextLoader(\n commandDecoderMock,\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an array with contexts if 2 chain swaps are supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x04\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x04\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if 1 chain swap with a non swap command\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0b0004`; // WRAP_ETH, V3_SWAP_EXACT_IN, SWEEP\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\", \"0x0003\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\"0x01\"]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\"0x04\"]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.WRAP_ETH,\n \"0x0001\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x04\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if one token is not found\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x02\",\n \"0x03\",\n ]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockResolvedValueOnce(Left(\"error\"));\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"error\",\n error: \"error\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an empty array if the if 2 chain swaps are not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x03\", // should be 0x02\n \"0x04\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no command are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"\"],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no inputs are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"0x08\", []],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if parseTransaction throws an error\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockImplementation(\n () => {\n throw new Error();\n },\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the swap is with multiple pool versions\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x080900`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT, V3_SWAP_EXACT_IN\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x00\", \"0x01\", \"0x02\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([\n \"0x01\",\n \"0x02\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x00\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x01\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 3,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x02\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: \"0x00000000\",\n chainId: 0x42,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the length of the commands and inputs are different\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\"]],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAAuD,kBACvDC,EAA4B,qBAE5BC,EAAqC,2CAGrCC,EAIO,uCAEPC,EAAgD,0DAChDC,EAA2C,qDAE3CC,EAAqC,kCAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA+C,CACnD,OAAQ,GAAG,GAAG,CAChB,EACMC,EAAsB,CAC1B,qBAAsB,GAAG,GAAG,CAC9B,EACA,IAAIC,EAEJ,SAAS,OAAQ,IAAM,CACrB,SAAS,2BAA4B,IAAM,CACzC,WAAW,IAAM,CACf,GAAG,MACDD,EACA,sBACF,EAAE,mBAAmB,CAAC,CAAE,QAAAE,CAAQ,IAC9B,QAAQ,WAAQ,SAAM,WAAWA,CAAO,EAAE,CAAC,CAC7C,EACAD,EAAS,IAAI,uBACX,IAAI,kCAAgC,IAAI,4BAA4B,EACpED,CACF,CACF,CAAC,EAED,GAAG,qEAAsE,SAAY,CAGnF,
|
|
4
|
+
"sourcesContent": ["import { Interface, type TransactionDescription } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TransactionContext } from \"@/shared/model/TransactionContext\";\nimport { type HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport {\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { DefaultCommandDecoderDataSource } from \"@/uniswap/data/DefaultCommandDecoderDataSource\";\nimport { EthersAbiDecoderDataSource } from \"@/uniswap/data/EthersAbiDecoderDataSource\";\n\nimport { UniswapContextLoader } from \"./UniswapContextLoader\";\n\ndescribe(\"UniswapContextLoader\", () => {\n const commandDecoderMock: CommandDecoderDataSource = {\n decode: vi.fn(),\n };\n const tokenDataSourceMock = {\n getTokenInfosPayload: vi.fn(),\n };\n let loader: UniswapContextLoader;\n\n describe(\"load\", () => {\n describe(\"with tokenDataSourceMock\", () => {\n beforeEach(() => {\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n loader = new UniswapContextLoader(\n new DefaultCommandDecoderDataSource(new EthersAbiDecoderDataSource()),\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an empty array if the selector is not UNISWAP_EXECUTE_SELECTOR\", async () => {\n // GIVEN\n const transactionContext = {\n selector: \"0x00000000\",\n data: \"0x00000000\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return the external plugin context and the decoded contexts\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc9821c32c1782d9ab6baf6f9ca4b2565bce11aaf5146a2d303215bda026f5e48\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4855b000000000000000000000000000000000000000000000000000000000000000300060c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000a18f07d736b90be5500000000000000000000000000000000000000000000000000000000b0b8122abd8412900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bb9f599ce614feb2e1bbe58f180f370d05b39344e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000017cc6042605381c158d2adab487434bde79aa61c000000000000000000000000000000000000000000000000000000000000005b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000b0b8122abd84129c001a053efc49d03b694742500f49aa09df2360bd7e297fa730c745e0d4320b42fc33fa01ca1c85a46c561f624830fffbae2441ba0f2d54eb5b0f17e0e3561d10db0b7ee\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xb9f599ce614feb2e1bbe58f180f370d05b39344e\",\n }, // ERC20\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n ]);\n });\n\n it(\"should return the external plugin context and the decoded contexts with a permit\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xc4df7ccc0527541d0e80856a8f38deedc48c84825e9355469ba02d873502ce2f\n // PERMIT2_PERMIT, V3_SWAP_EXACT_OUT, UNWRAP_ETH\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000030a010c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000016000000000000000000000000055747be9f9f5beb232ad59fe7af013b81d95fd5e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066c32b0d0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000ef1c6e67703c7bd7107eed8303fbe6ec2554bf6b00000000000000000000000000000000000000000000000000000000669b9ec100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000410d756f55acf289e9754faf91bba0a704b5c7c0aa4b1dfd551115ccbe4c7f290234e1a14265e1da0bc872a23627d997fe37a689c290d519f7b8c9bdde1b79108e1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000030ba49cbff5a00000000000000000000000000000000000000000000000089677c957272141800000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002bc02aaa39b223fe8d0a0e5c4f27ead9083c756cc200271055747be9f9f5beb232ad59fe7af013b81d95fd5e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000030ba49cbff5a000c001a0e406d9c91c8b46d959fcd31a28518a77bb248ebb316c5fab7b98335cce922f2aa0462cb970c32a8dbfe71c57b888c43b9ed04fce41d169dbfcc745445587adb771\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\",\n }, // WETH\n {\n type: \"token\",\n payload: \"payload-0x55747be9f9f5beb232ad59fe7af013b81d95fd5e\",\n }, // ERC20\n ]);\n });\n\n it(\"should return an empty array if the transaction is not supported\", async () => {\n // GIVEN\n const transactionContext = {} as TransactionContext;\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if a command is not supported\", async () => {\n // GIVEN\n // https://etherscan.io/getRawTx?tx=0xa628c8b3da2ad984aed0354d8ca4b4c3c42941491dc4e0d6a5f423fd65e6c90a\n // The command 0x05 (TRANSFER) is not supported\n const transactionContext = {\n chainId: 1,\n data: \"0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a4bef600000000000000000000000000000000000000000000000000000000000000050b0105040c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000078e6708e70aed0f000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000059a16770000000000000000000000000000000000000000000000000078e6708e70aed0f00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb480001f4c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000027213e28d7fda5c57fe9e5dd923818dbccf71c4700000000000000000000000000000000000000000000000000000000003938700000000000000000000000000000000000000000000000000000000000000060000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006f939b43d65be049b7533907db08e80ba6969f450000000000000000000000000000000000000000000000000000000059682f0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000006f939b43d65be049b7533907db08e80ba6969f4500000000000000000000000000000000000000000000000000000000000000000cc080a07c86dd5813ec1f3725c402f8bea6105546d1093c59676023b971f1d83f61bd4ea02a353bf3028cabcbe68c5dc8906752bafe55afc86b6344edb3ffd8a3650332e8\",\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(result).toEqual([]);\n });\n });\n\n describe(\"with mocked ethers parseTransaction\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n loader = new UniswapContextLoader(\n commandDecoderMock,\n tokenDataSourceMock as unknown as HttpTokenDataSource,\n );\n });\n\n it(\"should return an array with contexts if 2 chain swaps are supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x04\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x04\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if 1 chain swap with a non swap command\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x0b0004`; // WRAP_ETH, V3_SWAP_EXACT_IN, SWEEP\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\", \"0x0003\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"])\n .mockReturnValueOnce([\"0x04\"]);\n vi.spyOn(\n tokenDataSourceMock,\n \"getTokenInfosPayload\",\n ).mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.WRAP_ETH,\n \"0x0001\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(4, { address: \"0x04\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"token\",\n payload: \"payload-0x01\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n {\n type: \"token\",\n payload: \"payload-0x04\",\n },\n ]);\n });\n\n it(\"should return an array with contexts if one token is not found\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\")\n .mockReturnValueOnce([\"0x01\", \"0x02\"])\n .mockReturnValueOnce([\"0x02\", \"0x03\"]);\n vi.spyOn(tokenDataSourceMock, \"getTokenInfosPayload\")\n .mockResolvedValueOnce(Left(\"error\"))\n .mockImplementation(({ address }) =>\n Promise.resolve(Right(`payload-${address}`)),\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(1, { address: \"0x01\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(2, { address: \"0x02\", chainId: 0x42 });\n expect(\n tokenDataSourceMock.getTokenInfosPayload,\n ).toHaveBeenNthCalledWith(3, { address: \"0x03\", chainId: 0x42 });\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload:\n \"07556e69737761703fc91a3afd70395cd496c647d5a6cc9d4b2b7fad3593564c3044022014391e8f355867a57fe88f6a5a4dbcb8bf8f888a9db3ff3449caf72d120396bd02200c13d9c3f79400fe0aa0434ac54d59b79503c9964a4abc3e8cd22763e0242935\",\n },\n {\n type: \"error\",\n error: \"error\",\n },\n {\n type: \"token\",\n payload: \"payload-0x02\",\n },\n {\n type: \"token\",\n payload: \"payload-0x03\",\n },\n ]);\n });\n\n it(\"should return an empty array if the if 2 chain swaps are not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\", \"0x0002\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x01\",\n \"0x02\",\n ]);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValueOnce([\n \"0x03\", // should be 0x02\n \"0x04\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x0001\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x0002\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no command are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"\"],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no inputs are returned from parseTransaction\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [\"0x08\", []],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if parseTransaction throws an error\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockImplementation(\n () => {\n throw new Error();\n },\n );\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the swap is with multiple pool versions\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x080900`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT, V3_SWAP_EXACT_IN\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x00\", \"0x01\", \"0x02\"]],\n } as TransactionDescription);\n vi.spyOn(commandDecoderMock, \"decode\").mockReturnValue([\n \"0x01\",\n \"0x02\",\n ]);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 1,\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x00\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 2,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x01\",\n 0x42,\n );\n expect(commandDecoderMock.decode).toHaveBeenNthCalledWith(\n 3,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x02\",\n 0x42,\n );\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the selector is not supported\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: \"0x00000000\",\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if the length of the commands and inputs are different\", async () => {\n // GIVEN\n const transactionContext = {\n to: UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n data: UNISWAP_EXECUTE_SELECTOR,\n chainId: 0x42,\n selector: UNISWAP_EXECUTE_SELECTOR,\n } as TransactionContext;\n const commands = `0x0809`; // V2_SWAP_EXACT_IN, V2_SWAP_EXACT_OUT\n vi.spyOn(Interface.prototype, \"parseTransaction\").mockReturnValue({\n args: [commands, [\"0x0001\"]],\n } as TransactionDescription);\n\n // WHEN\n const result = await loader.load(transactionContext);\n\n // THEN\n expect(commandDecoderMock.decode).not.toHaveBeenCalled();\n expect(tokenDataSourceMock.getTokenInfosPayload).not.toHaveBeenCalled();\n expect(result).toEqual([]);\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAuD,kBACvDC,EAA4B,qBAE5BC,EAAqC,2CAGrCC,EAIO,uCAEPC,EAAgD,0DAChDC,EAA2C,qDAE3CC,EAAqC,kCAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA+C,CACnD,OAAQ,GAAG,GAAG,CAChB,EACMC,EAAsB,CAC1B,qBAAsB,GAAG,GAAG,CAC9B,EACA,IAAIC,EAEJ,SAAS,OAAQ,IAAM,CACrB,SAAS,2BAA4B,IAAM,CACzC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AoB,oBAAoB,EAAE,IAAI,iBAAiB,EACtE,OAAOI,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,gEAAiE,SAAY,CAE9E,MAAMD,EAAqB,CACzB,GAAI,mCACJ,KAAM,aACN,QAAS,GACT,SAAU,0BACZ,EAGMC,EAAS,MAAMH,EAAO,KAAKE,CAAkB,EAGnD,OAAOJ,EAAmB,MAAM,EAAE,IAAI,iBAAiB,EACvD,OAAOC,EAAoB,oBAAoB,EAAE,IAAI,iBAAiB,EACtE,OAAOI,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,EAED,GAAG,sFAAuF,SAAY,CAEpG,MAAMD,EAAqB,CACzB,GAAI,mCACJ,KAAM,2BACN,QAAS,GACT,SAAU,0BACZ,EAEA,GAAG,MAAM,YAAU,UAAW,kBAAkB,EAAE,gBAAgB,CAChE,KAAM,CAFS,SAEE,CAAC,QAAQ,CAAC,CAC7B,CAA2B,EAG3B,MAAMC,EAAS,MAAMH,EAAO,KAAKE,CAAkB,EAGnD,OAAOJ,EAAmB,MAAM,EAAE,IAAI,iBAAiB,EACvD,OAAOC,EAAoB,oBAAoB,EAAE,IAAI,iBAAiB,EACtE,OAAOI,CAAM,EAAE,QAAQ,CAAC,CAAC,CAC3B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_ethers", "import_purify_ts", "import_ClearSignContext", "import_uniswap", "import_DefaultCommandDecoderDataSource", "import_EthersAbiDecoderDataSource", "import_UniswapContextLoader", "commandDecoderMock", "tokenDataSourceMock", "loader", "address", "transactionContext", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var x=Object.create;var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var r in e)a(t,r,{get:e[r],enumerable:!0})},k=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of w(e))!L.call(t,i)&&i!==r&&a(t,i,{get:()=>e[i],enumerable:!(o=d(e,i))||o.enumerable});return t};var m=(t,e,r)=>(r=t!=null?x(T(t)):{},k(e||!t||!t.__esModule?a(r,"default",{value:t,enumerable:!0}):r,t)),v=t=>k(a({},"__esModule",{value:!0}),t),l=(t,e,r,o)=>{for(var i=o>1?void 0:o?d(e,r):e,c=t.length-1,n;c>=0;c--)(n=t[c])&&(i=(o?n(e,r,i):n(i))||i);return o&&i&&a(e,r,i),i},f=(t,e)=>(r,o)=>e(r,o,t);var I={};R(I,{HttpWeb3CheckDataSource:()=>s});module.exports=v(I);var u=m(require("axios")),p=require("inversify"),h=require("purify-ts"),b=require("../../config/di/configTypes"),y=require("../../pki/di/pkiTypes"),g=require("../../pki/model/KeyUsage"),C=require("../../shared/constant/HttpHeaders"),D=m(require("../../../package.json"));let s=class{constructor(e,r){this.config=e;this._certificateLoader=r;if(!this.config.originToken)throw new Error("Origin token is required")}async getWeb3Checks(e){const{from:r,deviceModelId:o}=e;let i,c,n;this.isTypedDataContext(e)?(c={msg:{from:r,data:e.data}},n=`${this.config.web3checks.url}/ethereum/scan/eip-712`):(c={tx:{from:r,raw:e.rawTx},chain:e.chainId},n=`${this.config.web3checks.url}/ethereum/scan/tx`);try{i=(await u.default.request({method:"POST",url:n,data:c,headers:{[C.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${D.default.version}`,[C.LEDGER_ORIGIN_TOKEN_HEADER]:this.config.originToken}})).data}catch{return(0,h.Left)(new Error("[ContextModule] HttpWeb3CheckDataSource: Failed to fetch web3 checks informations"))}if(!this.isWeb3CheckDto(i))return(0,h.Left)(new Error("[ContextModule] HttpWeb3CheckDataSource: Cannot exploit Web3 checks data received"));const W=await this._certificateLoader.loadCertificate({keyId:i.public_key_id,keyUsage:g.KeyUsage.TxSimulationSigner,targetDevice:o}),_={publicKeyId:i.public_key_id,descriptor:i.descriptor,certificate:W};return(0,h.Right)(_)}isTypedDataContext(e){return"data"in e}isWeb3CheckDto(e){return e!=null&&typeof e=="object"&&"public_key_id"in e&&e.public_key_id!=null&&typeof e.public_key_id=="string"&&"descriptor"in e&&e.descriptor!=null&&typeof e.descriptor=="string"}};s=l([(0,p.injectable)(),f(0,(0,p.inject)(b.configTypes.Config)),f(1,(0,p.inject)(y.pkiTypes.PkiCertificateLoader))],s);0&&(module.exports={HttpWeb3CheckDataSource});
|
|
2
2
|
//# sourceMappingURL=HttpWeb3CheckDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/web3-check/data/HttpWeb3CheckDataSource.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 type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport {
|
|
5
|
-
"mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAAyB,6BAEzBC,EAAyB,gCACzBC,
|
|
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 type { ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport {\n type Web3CheckContext,\n type Web3Checks,\n type Web3CheckTypedDataContext,\n} from \"@/web3-check/domain/web3CheckTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { Web3CheckDataSource } from \"./Web3CheckDataSource\";\nimport { GetWeb3ChecksRequestDto, Web3CheckDto } from \"./Web3CheckDto\";\n\n@injectable()\nexport class HttpWeb3CheckDataSource implements Web3CheckDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {\n if (!this.config.originToken) {\n throw new Error(\"Origin token is required\");\n }\n }\n\n async getWeb3Checks(\n context: Web3CheckContext,\n ): Promise<Either<Error, Web3Checks>> {\n const { from, deviceModelId } = context;\n let web3CheckDto: Web3CheckDto;\n let requestDto: GetWeb3ChecksRequestDto;\n let url: string;\n if (this.isTypedDataContext(context)) {\n requestDto = {\n msg: {\n from,\n data: context.data,\n },\n };\n url = `${this.config.web3checks.url}/ethereum/scan/eip-712`;\n } else {\n requestDto = {\n tx: {\n from,\n raw: context.rawTx,\n },\n chain: context.chainId,\n };\n url = `${this.config.web3checks.url}/ethereum/scan/tx`;\n }\n\n try {\n const response = await axios.request<Web3CheckDto>({\n method: \"POST\",\n url,\n data: requestDto,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n web3CheckDto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] HttpWeb3CheckDataSource: Failed to fetch web3 checks informations\",\n ),\n );\n }\n\n if (!this.isWeb3CheckDto(web3CheckDto)) {\n return Left(\n new Error(\n \"[ContextModule] HttpWeb3CheckDataSource: Cannot exploit Web3 checks data received\",\n ),\n );\n }\n\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: web3CheckDto.public_key_id,\n keyUsage: KeyUsage.TxSimulationSigner,\n targetDevice: deviceModelId,\n });\n\n const result: Web3Checks = {\n publicKeyId: web3CheckDto.public_key_id,\n descriptor: web3CheckDto.descriptor,\n certificate,\n };\n\n return Right(result);\n }\n\n private isTypedDataContext(\n context: Web3CheckContext,\n ): context is Web3CheckTypedDataContext {\n return \"data\" in context;\n }\n\n private isWeb3CheckDto(dto: unknown): dto is Web3CheckDto {\n return (\n dto != null &&\n typeof dto == \"object\" &&\n \"public_key_id\" in dto &&\n dto.public_key_id != null &&\n typeof dto.public_key_id == \"string\" &&\n \"descriptor\" in dto &&\n dto.descriptor != null &&\n typeof dto.descriptor == \"string\"\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "qtBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAClBC,EAAmC,qBACnCC,EAAoC,qBAEpCC,EAA4B,mCAE5BC,EAAyB,6BAEzBC,EAAyB,gCACzBC,EAGO,yCAMPC,EAAoB,iCAMb,IAAMC,EAAN,KAA6D,CAClE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,EAEjB,GAAI,CAAC,KAAK,OAAO,YACf,MAAM,IAAI,MAAM,0BAA0B,CAE9C,CAEA,MAAM,cACJC,EACoC,CACpC,KAAM,CAAE,KAAAC,EAAM,cAAAC,CAAc,EAAIF,EAChC,IAAIG,EACAC,EACAC,EACA,KAAK,mBAAmBL,CAAO,GACjCI,EAAa,CACX,IAAK,CACH,KAAAH,EACA,KAAMD,EAAQ,IAChB,CACF,EACAK,EAAM,GAAG,KAAK,OAAO,WAAW,GAAG,2BAEnCD,EAAa,CACX,GAAI,CACF,KAAAH,EACA,IAAKD,EAAQ,KACf,EACA,MAAOA,EAAQ,OACjB,EACAK,EAAM,GAAG,KAAK,OAAO,WAAW,GAAG,qBAGrC,GAAI,CAUFF,GATiB,MAAM,EAAAG,QAAM,QAAsB,CACjD,OAAQ,OACR,IAAAD,EACA,KAAMD,EACN,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAG,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACuB,IAC1B,MAAiB,CACf,SAAO,QACL,IAAI,MACF,mFACF,CACF,CACF,CAEA,GAAI,CAAC,KAAK,eAAeJ,CAAY,EACnC,SAAO,QACL,IAAI,MACF,mFACF,CACF,EAGF,MAAMK,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAOL,EAAa,cACpB,SAAU,WAAS,mBACnB,aAAcD,CAChB,CAAC,EAEKO,EAAqB,CACzB,YAAaN,EAAa,cAC1B,WAAYA,EAAa,WACzB,YAAAK,CACF,EAEA,SAAO,SAAMC,CAAM,CACrB,CAEQ,mBACNT,EACsC,CACtC,MAAO,SAAUA,CACnB,CAEQ,eAAeU,EAAmC,CACxD,OACEA,GAAO,MACP,OAAOA,GAAO,UACd,kBAAmBA,GACnBA,EAAI,eAAiB,MACrB,OAAOA,EAAI,eAAiB,UAC5B,eAAgBA,GAChBA,EAAI,YAAc,MAClB,OAAOA,EAAI,YAAc,QAE7B,CACF,EAjGab,EAANc,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,cAAY,MAAM,GACzBA,EAAA,eAAO,WAAS,oBAAoB,IAH5Bf",
|
|
6
6
|
"names": ["HttpWeb3CheckDataSource_exports", "__export", "HttpWeb3CheckDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_HttpHeaders", "import_package", "HttpWeb3CheckDataSource", "config", "_certificateLoader", "context", "from", "deviceModelId", "web3CheckDto", "requestDto", "url", "axios", "PACKAGE", "certificate", "result", "dto", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var f=Object.create;var
|
|
1
|
+
"use strict";var f=Object.create;var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of m(e))!b.call(t,a)&&a!==o&&p(t,a,{get:()=>e[a],enumerable:!(r=h(e,a))||r.enumerable});return t};var l=(t,e,o)=>(o=t!=null?f(C(t)):{},w(e||!t||!t.__esModule?p(o,"default",{value:t,enumerable:!0}):o,t));var s=require("@ledgerhq/device-management-kit"),c=l(require("axios")),d=require("purify-ts"),u=require("../../shared/constant/HttpHeaders"),i=require("../../web3-check/data/HttpWeb3CheckDataSource"),k=l(require("../../../package.json"));vi.mock("axios");describe("HttpWeb3CheckDataSource",()=>{const t={web3checks:{url:"web3checksUrl"},originToken:"originToken"},e={loadCertificate:vi.fn()};beforeEach(()=>{vi.resetAllMocks()}),describe("getWeb3Checks",()=>{it("should return an object if the request is successful",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",rawTx:"rawTx",chainId:1},r={public_key_id:"partner",descriptor:"descriptor"};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r}),vi.spyOn(e,"loadCertificate").mockResolvedValueOnce(void 0);const n=await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o);expect(n).toEqual((0,d.Right)({publicKeyId:"partner",descriptor:"descriptor"}))}),it("should return an object if the typed data request is successful",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",data:"typed data"},r={public_key_id:"partner",descriptor:"descriptor"};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r}),vi.spyOn(e,"loadCertificate").mockResolvedValueOnce(void 0);const n=await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o);expect(n).toEqual((0,d.Right)({publicKeyId:"partner",descriptor:"descriptor"}))}),it("should return an object with a certificate if the request is successful",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",rawTx:"rawTx",chainId:1},r={public_key_id:"partner",descriptor:"descriptor"};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:r}),vi.spyOn(e,"loadCertificate").mockResolvedValueOnce({keyUsageNumber:11,payload:new Uint8Array([1])});const n=await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o);expect(n).toEqual((0,d.Right)({publicKeyId:"partner",descriptor:"descriptor",certificate:{keyUsageNumber:11,payload:new Uint8Array([1])}}))}),it("should return an error if the request fails",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",rawTx:"rawTx",chainId:1};vi.spyOn(c.default,"request").mockRejectedValue(new Error("error"));const a=await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o);expect(a).toEqual((0,d.Left)(new Error("[ContextModule] HttpWeb3CheckDataSource: Failed to fetch web3 checks informations")))}),it("should return an error if the response is invalid",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",rawTx:"rawTx",chainId:1},r={};vi.spyOn(c.default,"request").mockResolvedValue({data:r}),vi.spyOn(e,"loadCertificate").mockResolvedValue(void 0);const n=await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o);expect(n).toEqual((0,d.Left)(new Error("[ContextModule] HttpWeb3CheckDataSource: Cannot exploit Web3 checks data received")))}),it("should throw an error if origin token is not provided",()=>{expect(()=>new i.HttpWeb3CheckDataSource({...t,originToken:void 0},e)).toThrow("Origin token is required")}),it("should call axios with the correct headers",async()=>{const o={deviceModelId:s.DeviceModelId.FLEX,from:"from",rawTx:"rawTx",chainId:1};vi.spyOn(c.default,"request").mockResolvedValueOnce({data:{}}),await new i.HttpWeb3CheckDataSource(t,e).getWeb3Checks(o),expect(c.default.request).toHaveBeenCalledWith(expect.objectContaining({headers:{[u.LEDGER_CLIENT_VERSION_HEADER]:`context-module/${k.default.version}`,[u.LEDGER_ORIGIN_TOKEN_HEADER]:t.originToken}}))})})});
|
|
2
2
|
//# sourceMappingURL=HttpWeb3CheckDataSource.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/web3-check/data/HttpWeb3CheckDataSource.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport {
|
|
5
|
-
"mappings": "wdAAA,IAAAA,EAA8B,2CAC9BC,EAAkB,oBAClBC,EAA4B,qBAI5BC,
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { HttpWeb3CheckDataSource } from \"@/web3-check/data/HttpWeb3CheckDataSource\";\nimport { type Web3CheckDto } from \"@/web3-check/data/Web3CheckDto\";\nimport type { Web3CheckTypedData } from \"@/web3-check/domain/web3CheckTypes\";\nimport { type Web3CheckContext } from \"@/web3-check/domain/web3CheckTypes\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpWeb3CheckDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\n originToken: \"originToken\",\n } as ContextModuleConfig;\n const certificateLoaderMock = {\n loadCertificate: vi.fn(),\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"getWeb3Checks\", () => {\n it(\"should return an object if the request is successful\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n };\n const dto: Web3CheckDto = {\n public_key_id: \"partner\",\n descriptor: \"descriptor\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: dto });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValueOnce(\n undefined,\n );\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n const result = await dataSource.getWeb3Checks(params);\n\n // THEN\n expect(result).toEqual(\n Right({\n publicKeyId: \"partner\",\n descriptor: \"descriptor\",\n }),\n );\n });\n\n it(\"should return an object if the typed data request is successful\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n data: \"typed data\" as unknown as Web3CheckTypedData,\n };\n const dto: Web3CheckDto = {\n public_key_id: \"partner\",\n descriptor: \"descriptor\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: dto });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValueOnce(\n undefined,\n );\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n const result = await dataSource.getWeb3Checks(params);\n\n // THEN\n expect(result).toEqual(\n Right({\n publicKeyId: \"partner\",\n descriptor: \"descriptor\",\n }),\n );\n });\n\n it(\"should return an object with a certificate if the request is successful\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n };\n const dto: Web3CheckDto = {\n public_key_id: \"partner\",\n descriptor: \"descriptor\",\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: dto });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValueOnce({\n keyUsageNumber: 11,\n payload: new Uint8Array([0x01]),\n });\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n const result = await dataSource.getWeb3Checks(params);\n\n // THEN\n expect(result).toEqual(\n Right({\n publicKeyId: \"partner\",\n descriptor: \"descriptor\",\n certificate: { keyUsageNumber: 11, payload: new Uint8Array([0x01]) },\n }),\n );\n });\n\n it(\"should return an error if the request fails\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n };\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error(\"error\"));\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n const result = await dataSource.getWeb3Checks(params);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpWeb3CheckDataSource: Failed to fetch web3 checks informations\",\n ),\n ),\n );\n });\n\n it(\"should return an error if the response is invalid\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n };\n const dto = {};\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: dto });\n vi.spyOn(certificateLoaderMock, \"loadCertificate\").mockResolvedValue(\n undefined,\n );\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n const result = await dataSource.getWeb3Checks(params);\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpWeb3CheckDataSource: Cannot exploit Web3 checks data received\",\n ),\n ),\n );\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n expect(\n () =>\n new HttpWeb3CheckDataSource(\n { ...config, originToken: undefined },\n certificateLoaderMock as unknown as PkiCertificateLoader,\n ),\n ).toThrow(\"Origin token is required\");\n });\n\n it(\"should call axios with the correct headers\", async () => {\n // GIVEN\n const params: Web3CheckContext = {\n deviceModelId: DeviceModelId.FLEX,\n from: \"from\",\n rawTx: \"rawTx\",\n chainId: 1,\n };\n vi.spyOn(axios, \"request\").mockResolvedValueOnce({ data: {} });\n\n // WHEN\n const dataSource = new HttpWeb3CheckDataSource(\n config,\n certificateLoaderMock as unknown as PkiCertificateLoader,\n );\n await dataSource.getWeb3Checks(params);\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});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAA8B,2CAC9BC,EAAkB,oBAClBC,EAA4B,qBAI5BC,EAGO,yCACPC,EAAwC,qDAIxCC,EAAoB,iCAEpB,GAAG,KAAK,OAAO,EAEf,SAAS,0BAA2B,IAAM,CACxC,MAAMC,EAAS,CACb,WAAY,CACV,IAAK,eACP,EACA,YAAa,aACf,EACMC,EAAwB,CAC5B,gBAAiB,GAAG,GAAG,CACzB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,uDAAwD,SAAY,CAErE,MAAMC,EAA2B,CAC/B,cAAe,gBAAc,KAC7B,KAAM,OACN,MAAO,QACP,QAAS,CACX,EACMC,EAAoB,CACxB,cAAe,UACf,WAAY,YACd,EACA,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,sBAAsB,CAAE,KAAMD,CAAI,CAAC,EAC9D,GAAG,MAAMF,EAAuB,iBAAiB,EAAE,sBACjD,MACF,EAOA,MAAMI,EAAS,MAJI,IAAI,0BACrBL,EACAC,CACF,EACgC,cAAcC,CAAM,EAGpD,OAAOG,CAAM,EAAE,WACb,SAAM,CACJ,YAAa,UACb,WAAY,YACd,CAAC,CACH,CACF,CAAC,EAED,GAAG,k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AM,EAGpD,OAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,mFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,MAAMH,EAA2B,CAC/B,cAAe,gBAAc,KAC7B,KAAM,OACN,MAAO,QACP,QAAS,CACX,EACMC,EAAM,CAAC,EACb,GAAG,MAAM,EAAAC,QAAO,SAAS,EAAE,kBAAkB,CAAE,KAAMD,CAAI,CAAC,EAC1D,GAAG,MAAMF,EAAuB,iBAAiB,EAAE,kBACjD,MACF,EAOA,MAAMI,EAAS,MAJI,IAAI,0BACrBL,EACAC,CACF,EACgC,cAAcC,CAAM,EAGpD,OAAOG,CAAM,EAAE,WACb,QACE,IAAI,MACF,mFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,wDAAyD,IAAM,CAChE,OACE,IACE,IAAI,0BACF,CAAE,GAAGL,EAAQ,YAAa,MAAU,EACpCC,CACF,CACJ,EAAE,QAAQ,0BAA0B,CACtC,CAAC,EAED,GAAG,6CAA8C,SAAY,CAE3D,MAAMC,EAA2B,CAC/B,cAAe,gBAAc,KAC7B,KAAM,OACN,MAAO,QACP,QAAS,CACX,EACA,GAAG,MAAM,EAAAE,QAAO,SAAS,EAAE,sBAAsB,CAAE,KAAM,CAAC,CAAE,CAAC,EAO7D,MAJmB,IAAI,0BACrBJ,EACAC,CACF,EACiB,cAAcC,CAAM,EAGrC,OAAO,EAAAE,QAAM,OAAO,EAAE,qBACpB,OAAO,iBAAiB,CACtB,QAAS,CACP,CAAC,8BAA4B,EAAG,kBAAkB,EAAAE,QAAQ,OAAO,GACjE,CAAC,4BAA0B,EAAGN,EAAO,WACvC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_device_management_kit", "import_axios", "import_purify_ts", "import_HttpHeaders", "import_HttpWeb3CheckDataSource", "import_package", "config", "certificateLoaderMock", "params", "dto", "axios", "result", "PACKAGE"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var n=(e,o)=>{for(var r in o)c(e,r,{get:o[r],enumerable:!0})},u=(e,o,r,C)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of b(o))!f.call(e,t)&&t!==r&&c(e,t,{get:()=>o[t],enumerable:!(C=k(o,t))||C.enumerable});return e};var i=e=>u(c({},"__esModule",{value:!0}),e);var d={};n(d,{web3CheckModuleFactory:()=>W});module.exports=i(d);var m=require("inversify"),p=require("../../web3-check/data/HttpWeb3CheckDataSource"),h=require("../../web3-check/domain/DefaultWeb3CheckLoader"),a=require("./web3CheckTypes");const W=()=>new m.ContainerModule(({bind:e})=>{e(a.web3CheckTypes.Web3CheckDataSource).to(p.HttpWeb3CheckDataSource),e(a.web3CheckTypes.Web3CheckContextLoader).to(h.DefaultWeb3CheckContextLoader)});0&&(module.exports={web3CheckModuleFactory});
|
|
2
2
|
//# sourceMappingURL=web3CheckModuleFactory.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/web3-check/di/web3CheckModuleFactory.ts"],
|
|
4
|
-
"sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpWeb3CheckDataSource } from \"@/web3-check/data/HttpWeb3CheckDataSource\";\nimport { DefaultWeb3CheckContextLoader } from \"@/web3-check/domain/DefaultWeb3CheckLoader\";\n\nimport { web3CheckTypes } from \"./web3CheckTypes\";\n\nexport const web3CheckModuleFactory = () =>\n new ContainerModule((bind
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAwC,qDACxCC,EAA8C,sDAE9CC,EAA+B,4BAExB,MAAML,EAAyB,IACpC,IAAI,kBAAgB,
|
|
6
|
-
"names": ["web3CheckModuleFactory_exports", "__export", "web3CheckModuleFactory", "__toCommonJS", "import_inversify", "import_HttpWeb3CheckDataSource", "import_DefaultWeb3CheckLoader", "import_web3CheckTypes", "bind"
|
|
4
|
+
"sourcesContent": ["import { ContainerModule } from \"inversify\";\n\nimport { HttpWeb3CheckDataSource } from \"@/web3-check/data/HttpWeb3CheckDataSource\";\nimport { DefaultWeb3CheckContextLoader } from \"@/web3-check/domain/DefaultWeb3CheckLoader\";\n\nimport { web3CheckTypes } from \"./web3CheckTypes\";\n\nexport const web3CheckModuleFactory = () =>\n new ContainerModule(({ bind }) => {\n bind(web3CheckTypes.Web3CheckDataSource).to(HttpWeb3CheckDataSource);\n bind(web3CheckTypes.Web3CheckContextLoader).to(\n DefaultWeb3CheckContextLoader,\n );\n });\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,qBAEhCC,EAAwC,qDACxCC,EAA8C,sDAE9CC,EAA+B,4BAExB,MAAML,EAAyB,IACpC,IAAI,kBAAgB,CAAC,CAAE,KAAAM,CAAK,IAAM,CAChCA,EAAK,iBAAe,mBAAmB,EAAE,GAAG,yBAAuB,EACnEA,EAAK,iBAAe,sBAAsB,EAAE,GAC1C,+BACF,CACF,CAAC",
|
|
6
|
+
"names": ["web3CheckModuleFactory_exports", "__export", "web3CheckModuleFactory", "__toCommonJS", "import_inversify", "import_HttpWeb3CheckDataSource", "import_DefaultWeb3CheckLoader", "import_web3CheckTypes", "bind"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/context-module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"reflect-metadata": "catalog:"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@ledgerhq/device-management-kit": "
|
|
56
|
+
"@ledgerhq/device-management-kit": "workspace:*"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultContextModule as t}from"./DefaultContextModule";const
|
|
1
|
+
import{DefaultContextModule as t}from"./DefaultContextModule";const o="https://crypto-assets-service.api.ledger.com/v1",r="https://web3checks-backend.api.ledger.com/v3",n="https://nft.api.live.ledger.com",i={cal:{url:o,mode:"prod",branch:"main"},web3checks:{url:r},metadataServiceDomain:{url:n},defaultLoaders:!0,customLoaders:[],customTypedDataLoader:void 0,customSolanaLoader:void 0};class s{config=i;needOriginToken=!0;originToken;constructor({originToken:e}={}){this.originToken=e}removeDefaultLoaders(){return this.config.defaultLoaders=!1,this}addLoader(e){return this.config.customLoaders.push(e),this}addTypedDataLoader(e){return this.config.customTypedDataLoader=e,this}addWeb3CheckLoader(e){return this.needOriginToken=!1,this.config.customWeb3CheckLoader=e,this}addSolanaLoader(e){return this.config.customSolanaLoader=e,this}setCalConfig(e){return this.config.cal=e,this}setMetadataServiceConfig(e){return this.config.metadataServiceDomain=e,this}setWeb3ChecksConfig(e){return this.config.web3checks=e,this}build(){if(this.needOriginToken&&!this.originToken)throw new Error("Origin token is required");const e={...this.config,originToken:this.originToken};return new t(e)}}export{s as ContextModuleBuilder,i as DEFAULT_CONFIG};
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type Web3CheckContextLoader } from \"./web3-check/domain/Web3CheckContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n defaultLoaders: true,\n customLoaders: [],\n customTypedDataLoader: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private needOriginToken: boolean = true;\n private originToken?: string;\n\n constructor({ originToken }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for web3 checks\n *\n * @param loader loader to use for web3 checks\n * @returns this\n */\n addWeb3CheckLoader(loader: Web3CheckContextLoader) {\n this.needOriginToken = false;\n this.config.customWeb3CheckLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loader", "calConfig", "web3ChecksConfig", "config"]
|
|
4
|
+
"sourcesContent": ["import { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleMetadataServiceConfig,\n type ContextModuleWeb3ChecksConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { type Web3CheckContextLoader } from \"./web3-check/domain/Web3CheckContextLoader\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\nconst DEFAULT_CAL_URL = \"https://crypto-assets-service.api.ledger.com/v1\";\nconst DEFAULT_WEB3_CHECKS_URL = \"https://web3checks-backend.api.ledger.com/v3\";\nconst DEFAULT_METADATA_SERVICE_DOMAIN = \"https://nft.api.live.ledger.com\";\n\nexport const DEFAULT_CONFIG: ContextModuleConfig = {\n cal: {\n url: DEFAULT_CAL_URL,\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: DEFAULT_WEB3_CHECKS_URL,\n },\n metadataServiceDomain: {\n url: DEFAULT_METADATA_SERVICE_DOMAIN,\n },\n defaultLoaders: true,\n customLoaders: [],\n customTypedDataLoader: undefined,\n customSolanaLoader: undefined,\n};\n\nexport class ContextModuleBuilder {\n private config: ContextModuleConfig = DEFAULT_CONFIG;\n private needOriginToken: boolean = true;\n private originToken?: string;\n\n constructor({ originToken }: ContextModuleConstructorArgs = {}) {\n this.originToken = originToken;\n }\n\n /**\n * Remove default loaders from the list of loaders\n *\n * @returns this\n */\n removeDefaultLoaders() {\n this.config.defaultLoaders = false;\n return this;\n }\n\n /**\n * Add a custom loader to the list of loaders\n *\n * @param loader loader to add to the list of loaders\n * @returns this\n */\n addLoader(loader: ContextLoader) {\n this.config.customLoaders.push(loader);\n return this;\n }\n\n /**\n * Replace the default loader for typed data clear signing contexts\n *\n * @param loader loader to use for typed data clear signing contexts\n * @returns this\n */\n addTypedDataLoader(loader: TypedDataContextLoader) {\n this.config.customTypedDataLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for web3 checks\n *\n * @param loader loader to use for web3 checks\n * @returns this\n */\n addWeb3CheckLoader(loader: Web3CheckContextLoader) {\n this.needOriginToken = false;\n this.config.customWeb3CheckLoader = loader;\n return this;\n }\n\n /**\n * Replace the default loader for Solana context\n *\n * @param loader loader to use for Solana context\n * @returns this\n */\n addSolanaLoader(loader: SolanaContextLoader) {\n this.config.customSolanaLoader = loader;\n return this;\n }\n\n /**\n * Add a custom CAL configuration\n *\n * @param calConfig\n * @returns this\n */\n setCalConfig(calConfig: ContextModuleCalConfig) {\n this.config.cal = calConfig;\n return this;\n }\n\n /**\n * Add a custom metadata service configuration\n *\n * @param metadataServiceConfig\n * @returns this\n */\n setMetadataServiceConfig(\n metadataServiceConfig: ContextModuleMetadataServiceConfig,\n ) {\n this.config.metadataServiceDomain = metadataServiceConfig;\n return this;\n }\n\n /**\n * Add a custom web3 checks configuration\n *\n * @param web3ChecksConfig\n * @returns this\n */\n setWeb3ChecksConfig(web3ChecksConfig: ContextModuleWeb3ChecksConfig) {\n this.config.web3checks = web3ChecksConfig;\n return this;\n }\n\n /**\n * Build the context module\n *\n * @returns the context module\n */\n build(): ContextModule {\n if (this.needOriginToken && !this.originToken) {\n throw new Error(\"Origin token is required\");\n }\n\n const config = { ...this.config, originToken: this.originToken };\n return new DefaultContextModule(config);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAYA,OAAS,wBAAAA,MAA4B,yBAErC,MAAMC,EAAkB,kDAClBC,EAA0B,+CAC1BC,EAAkC,kCAE3BC,EAAsC,CACjD,IAAK,CACH,IAAKH,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,sBAAuB,CACrB,IAAKC,CACP,EACA,eAAgB,GAChB,cAAe,CAAC,EAChB,sBAAuB,OACvB,mBAAoB,MACtB,EAEO,MAAME,CAAqB,CACxB,OAA8BD,EAC9B,gBAA2B,GAC3B,YAER,YAAY,CAAE,YAAAE,CAAY,EAAkC,CAAC,EAAG,CAC9D,KAAK,YAAcA,CACrB,CAOA,sBAAuB,CACrB,YAAK,OAAO,eAAiB,GACtB,IACT,CAQA,UAAUC,EAAuB,CAC/B,YAAK,OAAO,cAAc,KAAKA,CAAM,EAC9B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,mBAAmBA,EAAgC,CACjD,YAAK,gBAAkB,GACvB,KAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,gBAAgBA,EAA6B,CAC3C,YAAK,OAAO,mBAAqBA,EAC1B,IACT,CAQA,aAAaC,EAAmC,CAC9C,YAAK,OAAO,IAAMA,EACX,IACT,CAQA,yBACEC,EACA,CACA,YAAK,OAAO,sBAAwBA,EAC7B,IACT,CAQA,oBAAoBC,EAAiD,CACnE,YAAK,OAAO,WAAaA,EAClB,IACT,CAOA,OAAuB,CACrB,GAAI,KAAK,iBAAmB,CAAC,KAAK,YAChC,MAAM,IAAI,MAAM,0BAA0B,EAG5C,MAAMC,EAAS,CAAE,GAAG,KAAK,OAAQ,YAAa,KAAK,WAAY,EAC/D,OAAO,IAAIX,EAAqBW,CAAM,CACxC,CACF",
|
|
6
|
+
"names": ["DefaultContextModule", "DEFAULT_CAL_URL", "DEFAULT_WEB3_CHECKS_URL", "DEFAULT_METADATA_SERVICE_DOMAIN", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "config"]
|
|
7
7
|
}
|