@ledgerhq/context-module 1.3.1 → 1.6.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/README.md +17 -5
- package/lib/cjs/package.json +12 -12
- 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/di/configTypes.js +1 -1
- package/lib/cjs/src/config/di/configTypes.js.map +2 -2
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +2 -0
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +7 -0
- package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
- package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +3 -3
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
- 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/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/data/HttpPkiCertificateDataSource.js +1 -1
- package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
- 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 +1 -1
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
- 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 +2 -0
- package/lib/cjs/src/shared/constant/HttpHeaders.js.map +7 -0
- 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/data/HttpTokenDataSource.js +1 -1
- package/lib/cjs/src/token/data/HttpTokenDataSource.js.map +3 -3
- package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
- package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +3 -3
- 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 +3 -3
- 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 +2 -2
- 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 +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +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/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
- package/lib/cjs/src/typed-data/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 +3 -3
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
- 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 +12 -12
- 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/config/di/configTypes.js +1 -1
- package/lib/esm/src/config/di/configTypes.js.map +2 -2
- package/lib/esm/src/config/model/ContextModuleBuildArgs.js +1 -0
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- 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/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/data/HttpPkiCertificateDataSource.js +1 -1
- package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
- 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 +1 -1
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
- 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 +2 -0
- package/lib/esm/src/shared/constant/HttpHeaders.js.map +7 -0
- 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/data/HttpTokenDataSource.js +1 -1
- package/lib/esm/src/token/data/HttpTokenDataSource.js.map +3 -3
- package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
- package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +3 -3
- 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 +2 -2
- 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/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 +22 -4
- 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/di/configTypes.d.ts +1 -0
- package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +4 -0
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts +7 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/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/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/data/HttpPkiCertificateDataSource.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 +3 -0
- package/lib/types/src/shared/constant/HttpHeaders.d.ts.map +1 -0
- 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/data/HttpTokenDataSource.d.ts.map +1 -1
- 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 +32 -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 +1 -1
- 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 +13 -13
- 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 → config/model/ContextModuleBuildArgs.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.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,WAAW,IAAM,CACf,GAAG,MACDD,EACA,sBACF,E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AOI,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 {\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\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
|
|
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,
|
|
6
|
-
"names": ["HttpWeb3CheckDataSource_exports", "__export", "HttpWeb3CheckDataSource", "__toCommonJS", "import_axios", "import_inversify", "import_purify_ts", "import_configTypes", "import_pkiTypes", "import_KeyUsage", "import_package", "HttpWeb3CheckDataSource", "config", "_certificateLoader", "context", "from", "deviceModelId", "web3CheckDto", "requestDto", "url", "axios", "PACKAGE", "certificate", "result", "dto", "__decorateClass", "__decorateParam"]
|
|
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
|
+
"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
|
|
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 { 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\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpWeb3CheckDataSource\", () => {\n const config = {\n web3checks: {\n url: \"web3checksUrl\",\n },\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});\n"],
|
|
5
|
-
"mappings": "wdAAA,IAAAA,EAA8B,2CAC9BC,EAAkB,oBAClBC,EAA4B,qBAI5BC,EAAwC,
|
|
6
|
-
"names": ["import_device_management_kit", "import_axios", "import_purify_ts", "import_HttpWeb3CheckDataSource", "config", "certificateLoaderMock", "params", "dto", "axios", "result"]
|
|
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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_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.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"prebuild": "rimraf lib",
|
|
23
|
-
"build": "pnpm
|
|
23
|
+
"build": "pnpm ldmk-tool build --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
24
24
|
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
|
|
25
|
-
"watch:builds": "pnpm
|
|
25
|
+
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
26
26
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
|
|
27
27
|
"lint": "eslint",
|
|
28
28
|
"lint:fix": "pnpm lint --fix",
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@ledgerhq/device-management-kit": "workspace:*",
|
|
39
|
-
"@ledgerhq/
|
|
39
|
+
"@ledgerhq/ldmk-tool": "workspace:*",
|
|
40
40
|
"@ledgerhq/eslint-config-dsdk": "workspace:*",
|
|
41
41
|
"@ledgerhq/prettier-config-dsdk": "workspace:*",
|
|
42
42
|
"@ledgerhq/tsconfig-dsdk": "workspace:*",
|
|
43
43
|
"@ledgerhq/vitest-config-dmk": "workspace:*",
|
|
44
|
-
"@types/crypto-js": "
|
|
45
|
-
"ts-node": "
|
|
44
|
+
"@types/crypto-js": "catalog:",
|
|
45
|
+
"ts-node": "catalog:"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"axios": "
|
|
49
|
-
"crypto-js": "
|
|
50
|
-
"ethers": "
|
|
51
|
-
"inversify": "
|
|
52
|
-
"purify-ts": "
|
|
53
|
-
"reflect-metadata": "
|
|
48
|
+
"axios": "catalog:",
|
|
49
|
+
"crypto-js": "catalog:",
|
|
50
|
+
"ethers": "catalog:",
|
|
51
|
+
"inversify": "catalog:",
|
|
52
|
+
"purify-ts": "catalog:",
|
|
53
|
+
"reflect-metadata": "catalog:"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@ledgerhq/device-management-kit": "workspace:*"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultContextModule as
|
|
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/v1",i={cal:{url:o,mode:"prod",branch:"main"},web3checks:{url:r},metadataService:{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.metadataService=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 {\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\n constructor() {}\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.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", "loader", "calConfig", "web3ChecksConfig"]
|
|
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_URL = \"https://nft.api.live.ledger.com/v1\";\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 metadataService: {\n url: DEFAULT_METADATA_SERVICE_URL,\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.metadataService = 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,EAA+B,qCAExBC,EAAsC,CACjD,IAAK,CACH,IAAKH,EACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAKC,CACP,EACA,gBAAiB,CACf,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,gBAAkBA,EACvB,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_URL", "DEFAULT_CONFIG", "ContextModuleBuilder", "originToken", "loader", "calConfig", "metadataServiceConfig", "web3ChecksConfig", "config"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{configTypes as
|
|
1
|
+
import{configTypes as s}from"./config/di/configTypes";import{ContextModuleBuilder as c}from"./ContextModuleBuilder";import{DefaultContextModule as r}from"./DefaultContextModule";describe("ContextModuleBuilder",()=>{const d={url:"https://cal/v1",mode:"prod",branch:"main"},a={url:"https://web3checks/v1"},i={originToken:"test"};beforeEach(()=>{vi.resetAllMocks()}),it("should return a default context module",()=>{const e=new c(i).build();expect(e).toBeInstanceOf(r)}),it("should return a custom context module",()=>{const t=new c(i),e={load:vi.fn()},o=t.removeDefaultLoaders().addLoader(e).build();expect(o).toBeInstanceOf(r)}),it("should return a custom context module with a custom typed data loader",()=>{const t=new c(i),e={load:vi.fn()},o=t.removeDefaultLoaders().addTypedDataLoader(e).build();expect(o).toBeInstanceOf(r),expect(o._typedDataLoader).toBe(e)}),it("should return a custom context module with a custom config",()=>{const e=new c(i).setCalConfig(d).setWeb3ChecksConfig(a).build(),o=e._container.get(s.Config);expect(e).toBeInstanceOf(r),expect(o.cal).toEqual(d),expect(o.web3checks).toEqual(a)}),it("should return a custom context module with a custom custom web3checks loader",()=>{const t=new c,e={load:vi.fn()},o=t.removeDefaultLoaders().addWeb3CheckLoader(e).build();expect(o).toBeInstanceOf(r),expect(o._web3CheckLoader).toBe(e)}),it("should throw an error if origin token is not provided",()=>{const t=new c;expect(()=>t.build()).toThrow("Origin token is required")}),it("should not throw an error if origin token is provided",()=>{const t=new c(i);expect(()=>t.build()).not.toThrow()}),it("should not throw an error if origin token is not provided and addWeb3CheckLoader is called",()=>{const t=new c;expect(()=>t.addWeb3CheckLoader({load:vi.fn()}).build()).not.toThrow()}),describe("setMetadataServiceConfig",()=>{it("should set the metadata service configuration",()=>{const t=new c(i),e={url:"https://custom-metadata-service.com/v3"},o=t.setMetadataServiceConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(r),expect(n.metadataService).toEqual(e)}),it("should override the default metadata service configuration",()=>{const t=new c(i),e={url:"https://override-metadata-service.com/v1"},n=t.setMetadataServiceConfig(e).build()._container.get(s.Config);expect(n.metadataService.url).toBe(e.url),expect(n.metadataService.url).not.toBe("https://nft.api.live.ledger.com/v2")})}),describe("setCalConfig",()=>{it("should set the CAL configuration",()=>{const t=new c(i),e={url:"https://custom-cal-service.com/v2",mode:"test",branch:"next"},o=t.setCalConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(r),expect(n.cal).toEqual(e)}),it("should override the default CAL configuration",()=>{const t=new c(i),e={url:"https://override-cal-service.com/v1",mode:"prod",branch:"demo"},n=t.setCalConfig(e).build()._container.get(s.Config);expect(n.cal.url).toBe(e.url),expect(n.cal.mode).toBe(e.mode),expect(n.cal.branch).toBe(e.branch),expect(n.cal.url).not.toBe("https://crypto-assets-service.api.ledger.com/v1")})}),describe("setWeb3ChecksConfig",()=>{it("should set the web3 checks configuration",()=>{const t=new c(i),e={url:"https://custom-web3checks-service.com/v4"},o=t.setWeb3ChecksConfig(e).build(),n=o._container.get(s.Config);expect(o).toBeInstanceOf(r),expect(n.web3checks).toEqual(e)}),it("should override the default web3 checks configuration",()=>{const t=new c(i),e={url:"https://override-web3checks-service.com/v2"},n=t.setWeb3ChecksConfig(e).build()._container.get(s.Config);expect(n.web3checks.url).toBe(e.url),expect(n.web3checks.url).not.toBe("https://web3checks-backend.api.ledger.com/v3")})})});
|
|
2
2
|
//# sourceMappingURL=ContextModuleBuilder.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ContextModuleBuilder.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n const res = contextModuleBuilder\n .
|
|
5
|
-
"mappings": "AAEA,OAAS,eAAAA,MAAmB,
|
|
6
|
-
"names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "res", "contextModuleBuilder", "customLoader", "config"]
|
|
4
|
+
"sourcesContent": ["import { type Container } from \"inversify\";\n\nimport { configTypes } from \"./config/di/configTypes\";\nimport { type ContextModuleConstructorArgs } from \"./config/model/ContextModuleBuildArgs\";\nimport {\n type ContextModuleCalConfig,\n type ContextModuleConfig,\n type ContextModuleMetadataServiceConfig,\n} from \"./config/model/ContextModuleConfig\";\nimport { ContextModuleBuilder } from \"./ContextModuleBuilder\";\nimport { DefaultContextModule } from \"./DefaultContextModule\";\n\ndescribe(\"ContextModuleBuilder\", () => {\n const defaultCalConfig: ContextModuleCalConfig = {\n url: \"https://cal/v1\",\n mode: \"prod\",\n branch: \"main\",\n };\n const defaultWeb3ChecksConfig = {\n url: \"https://web3checks/v1\",\n };\n const defaultBuilderArgs: ContextModuleConstructorArgs = {\n originToken: \"test\",\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return a default context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder.build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n });\n\n it(\"should return a custom context module with a custom typed data loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addTypedDataLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _typedDataLoader is private\n expect(res[\"_typedDataLoader\"]).toBe(customLoader);\n });\n\n it(\"should return a custom context module with a custom config\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n const res = contextModuleBuilder\n .setCalConfig(defaultCalConfig)\n .setWeb3ChecksConfig(defaultWeb3ChecksConfig)\n .build();\n // @ts-expect-error _container is private\n const config = (res[\"_container\"] as Container).get<ContextModuleConfig>(\n configTypes.Config,\n );\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(defaultCalConfig);\n expect(config.web3checks).toEqual(defaultWeb3ChecksConfig);\n });\n\n it(\"should return a custom context module with a custom custom web3checks loader\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n const customLoader = { load: vi.fn() };\n\n const res = contextModuleBuilder\n .removeDefaultLoaders()\n .addWeb3CheckLoader(customLoader)\n .build();\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n // @ts-expect-error _web3CheckLoader is private\n expect(res[\"_web3CheckLoader\"]).toBe(customLoader);\n });\n\n it(\"should throw an error if origin token is not provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n expect(() => contextModuleBuilder.build()).toThrow(\n \"Origin token is required\",\n );\n });\n\n it(\"should not throw an error if origin token is provided\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n\n expect(() => contextModuleBuilder.build()).not.toThrow();\n });\n\n it(\"should not throw an error if origin token is not provided and addWeb3CheckLoader is called\", () => {\n const contextModuleBuilder = new ContextModuleBuilder();\n\n expect(() =>\n contextModuleBuilder.addWeb3CheckLoader({ load: vi.fn() }).build(),\n ).not.toThrow();\n });\n\n describe(\"setMetadataServiceConfig\", () => {\n it(\"should set the metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://custom-metadata-service.com/v3\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.metadataService).toEqual(customMetadataConfig);\n });\n\n it(\"should override the default metadata service configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customMetadataConfig: ContextModuleMetadataServiceConfig = {\n url: \"https://override-metadata-service.com/v1\",\n };\n\n const res = contextModuleBuilder\n .setMetadataServiceConfig(customMetadataConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.metadataService.url).toBe(customMetadataConfig.url);\n expect(config.metadataService.url).not.toBe(\n \"https://nft.api.live.ledger.com/v2\",\n );\n });\n });\n\n describe(\"setCalConfig\", () => {\n it(\"should set the CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://custom-cal-service.com/v2\",\n mode: \"test\",\n branch: \"next\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.cal).toEqual(customCalConfig);\n });\n\n it(\"should override the default CAL configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customCalConfig: ContextModuleCalConfig = {\n url: \"https://override-cal-service.com/v1\",\n mode: \"prod\",\n branch: \"demo\",\n };\n\n const res = contextModuleBuilder.setCalConfig(customCalConfig).build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.cal.url).toBe(customCalConfig.url);\n expect(config.cal.mode).toBe(customCalConfig.mode);\n expect(config.cal.branch).toBe(customCalConfig.branch);\n expect(config.cal.url).not.toBe(\n \"https://crypto-assets-service.api.ledger.com/v1\",\n );\n });\n });\n\n describe(\"setWeb3ChecksConfig\", () => {\n it(\"should set the web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://custom-web3checks-service.com/v4\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(res).toBeInstanceOf(DefaultContextModule);\n expect(config.web3checks).toEqual(customWeb3ChecksConfig);\n });\n\n it(\"should override the default web3 checks configuration\", () => {\n const contextModuleBuilder = new ContextModuleBuilder(defaultBuilderArgs);\n const customWeb3ChecksConfig = {\n url: \"https://override-web3checks-service.com/v2\",\n };\n\n const res = contextModuleBuilder\n .setWeb3ChecksConfig(customWeb3ChecksConfig)\n .build();\n const config = (res as DefaultContextModule)[\n \"_container\"\n ].get<ContextModuleConfig>(configTypes.Config);\n\n expect(config.web3checks.url).toBe(customWeb3ChecksConfig.url);\n expect(config.web3checks.url).not.toBe(\n \"https://web3checks-backend.api.ledger.com/v3\",\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,eAAAA,MAAmB,0BAO5B,OAAS,wBAAAC,MAA4B,yBACrC,OAAS,wBAAAC,MAA4B,yBAErC,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAA2C,CAC/C,IAAK,iBACL,KAAM,OACN,OAAQ,MACV,EACMC,EAA0B,CAC9B,IAAK,uBACP,EACMC,EAAmD,CACvD,YAAa,MACf,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,yCAA0C,IAAM,CAGjD,MAAMC,EAFuB,IAAIL,EAAqBI,CAAkB,EAEvC,MAAM,EAEvC,OAAOC,CAAG,EAAE,eAAeJ,CAAoB,CACjD,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChD,MAAMK,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEG,EAAe,CAAE,KAAM,GAAG,GAAG,CAAE,EAE/BF,EAAMC,EACT,qBAAqB,EACrB,UAAUC,CAAY,EACtB,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeJ,CAAoB,CACjD,CAAC,EAED,GAAG,wEAAyE,IAAM,CAChF,MAAMK,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEG,EAAe,CAAE,KAAM,GAAG,GAAG,CAAE,EAE/BF,EAAMC,EACT,qBAAqB,EACrB,mBAAmBC,CAAY,EAC/B,MAAM,EAET,OAAOF,CAAG,EAAE,eAAeJ,CAAoB,EAE/C,OAAOI,EAAI,gBAAmB,EAAE,KAAKE,CAAY,CACnD,CAAC,EAED,GAAG,6DAA8D,IAAM,CAGrE,MAAMF,EAFuB,IAAIL,EAAqBI,CAAkB,EAGrE,aAAaF,CAAgB,EAC7B,oBAAoBC,CAAuB,EAC3C,MAAM,EAEHK,EAAUH,EAAI,WAA4B,IAC9CN,EAAY,MACd,EAEA,OAAOM,CAAG,E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ACd,WACA,IAAyBN,EAAY,MAAM,EAE7C,OAAOM,CAAG,EAAE,eAAeJ,CAAoB,EAC/C,OAAOO,EAAO,UAAU,EAAE,QAAQG,CAAsB,CAC1D,CAAC,EAED,GAAG,wDAAyD,IAAM,CAChE,MAAML,EAAuB,IAAIN,EAAqBI,CAAkB,EAClEO,EAAyB,CAC7B,IAAK,4CACP,EAKMH,EAHMF,EACT,oBAAoBK,CAAsB,EAC1C,MAAM,EAEP,WACA,IAAyBZ,EAAY,MAAM,EAE7C,OAAOS,EAAO,WAAW,GAAG,EAAE,KAAKG,EAAuB,GAAG,EAC7D,OAAOH,EAAO,WAAW,GAAG,EAAE,IAAI,KAChC,8CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["configTypes", "ContextModuleBuilder", "DefaultContextModule", "defaultCalConfig", "defaultWeb3ChecksConfig", "defaultBuilderArgs", "res", "contextModuleBuilder", "customLoader", "config", "customMetadataConfig", "customCalConfig", "customWeb3ChecksConfig"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Left as n}from"purify-ts";import{transactionTypes as i}from"./transaction/di/transactionTypes";import{trustedNameTypes as p}from"./trusted-name/di/trustedNameTypes";import{externalPluginTypes as s}from"./external-plugin/di/externalPluginTypes";import{nftTypes as d}from"./nft/di/nftTypes";import{ClearSignContextType as r}from"./shared/model/ClearSignContext";import{solanaContextTypes as C}from"./solana/di/solanaContextTypes";import{tokenTypes as l}from"./token/di/tokenTypes";import{typedDataTypes as m}from"./typed-data/di/typedDataTypes";import{uniswapTypes as x}from"./uniswap/di/uniswapTypes";import{web3CheckTypes as c}from"./web3-check/di/web3CheckTypes";import{makeContainer as y}from"./di";class P{_container;_loaders;_typedDataLoader;_web3CheckLoader;_solanaLoader;constructor(e){this._container=y({config:e}),this._loaders=e.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...e.customLoaders),this._typedDataLoader=e.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._web3CheckLoader=e.customWeb3CheckLoader??this._getWeb3CheckLoader(),this._solanaLoader=e.customSolanaLoader??this._getSolanaLoader()}_getDefaultLoaders(){return[this._container.get(s.ExternalPluginContextLoader),this._container.get(p.TrustedNameContextLoader),this._container.get(d.NftContextLoader),this._container.get(l.TokenContextLoader),this._container.get(i.TransactionContextLoader),this._container.get(x.UniswapContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(m.TypedDataContextLoader)}_getWeb3CheckLoader(){return this._container.get(c.Web3CheckContextLoader)}_getSolanaLoader(){try{return this._container.get(C.SolanaContextLoader)}catch{return{load:async e=>n(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(e){const o=this._loaders.map(t=>t.load(e));return(await Promise.all(o)).flat()}async getContext(e){const o=this._loaders.filter(t=>t.loadField).map(t=>t.loadField(e));return(await Promise.all(o)).find(t=>t!==null)||{type:r.ERROR,error:new Error(`Field type not supported: ${e.type}`)}}async getTypedDataFilters(e){return this._typedDataLoader.load(e)}async getWeb3Checks(e){return(await this._web3CheckLoader.load(e)).caseOf({Right:a=>({type:r.WEB3_CHECK,payload:a.descriptor,certificate:a.certificate}),Left:()=>null})}async getSolanaContext(e){return await this._solanaLoader.load(e)}}export{P as DefaultContextModule};
|
|
2
2
|
//# sourceMappingURL=DefaultContextModule.js.map
|