@ledgerhq/context-module 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +2 -2
- package/lib/cjs/src/DefaultContextModule.js +1 -1
- package/lib/cjs/src/DefaultContextModule.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/uniswap/constants/uniswap.js +1 -1
- package/lib/cjs/src/uniswap/constants/uniswap.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/esm/package.json +2 -2
- package/lib/esm/src/DefaultContextModule.js +1 -1
- package/lib/esm/src/DefaultContextModule.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/uniswap/constants/uniswap.js +1 -1
- package/lib/esm/src/uniswap/constants/uniswap.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.js.map +3 -3
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js +1 -1
- package/lib/esm/src/uniswap/domain/UniswapContextLoader.test.js.map +3 -3
- package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts +9 -1
- package/lib/types/src/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -1
- package/lib/types/src/uniswap/constants/uniswap.d.ts +0 -1
- package/lib/types/src/uniswap/constants/uniswap.d.ts.map +1 -1
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts +0 -8
- package/lib/types/src/uniswap/domain/UniswapContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/lib/cjs/src/uniswap/constants/plugin.js +0 -2
- package/lib/cjs/src/uniswap/constants/plugin.js.map +0 -7
- package/lib/esm/src/uniswap/constants/plugin.js +0 -2
- package/lib/esm/src/uniswap/constants/plugin.js.map +0 -7
- package/lib/types/src/uniswap/constants/plugin.d.ts +0 -3
- package/lib/types/src/uniswap/constants/plugin.d.ts.map +0 -1
package/lib/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/context-module",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"exports": {
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"reflect-metadata": "catalog:"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@ledgerhq/device-management-kit": "^0.9.
|
|
56
|
+
"@ledgerhq/device-management-kit": "^0.9.1"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},S=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of T(e))!D.call(r,a)&&a!==t&&s(r,a,{get:()=>e[a],enumerable:!(o=g(e,a))||o.enumerable});return r};var b=r=>S(s({},"__esModule",{value:!0}),r);var F={};k(F,{DefaultContextModule:()=>w});module.exports=b(F);var c=require("purify-ts"),x=require("./calldata/di/calldataTypes"),m=require("./dynamic-network/di/dynamicNetworkTypes"),l=require("./trusted-name/di/trustedNameTypes"),L=require("./external-plugin/di/externalPluginTypes"),C=require("./nft/di/nftTypes"),y=require("./proxy/di/proxyTypes"),n=require("./shared/model/ClearSignContext"),u=require("./solana/di/solanaContextTypes"),p=require("./token/di/tokenTypes"),f=require("./typed-data/di/typedDataTypes"),h=require("./web3-check/di/web3CheckTypes"),_=require("./di");class w{_container;_loaders;_typedDataLoader;_web3CheckLoader;_solanaLoader;_fieldLoaders;constructor(e){this._container=(0,_.makeContainer)({config:e}),this._loaders=e.defaultLoaders?this._getDefaultLoaders():[],this._loaders.push(...e.customLoaders),this._fieldLoaders=e.defaultFieldLoaders?this._getDefaultFieldLoaders():[],this._fieldLoaders.push(...e.customFieldLoaders),this._typedDataLoader=e.customTypedDataLoader??this._getDefaultTypedDataLoader(),this._web3CheckLoader=e.customWeb3CheckLoader??this._getWeb3CheckLoader(),this._solanaLoader=e.customSolanaLoader??this._getSolanaLoader()}_getDefaultFieldLoaders(){return[this._container.get(C.nftTypes.NftContextFieldLoader),this._container.get(p.tokenTypes.TokenContextFieldLoader),this._container.get(l.trustedNameTypes.TrustedNameContextFieldLoader),this._container.get(y.proxyTypes.ProxyContextFieldLoader)]}_getDefaultLoaders(){return[this._container.get(L.externalPluginTypes.ExternalPluginContextLoader),this._container.get(l.trustedNameTypes.TrustedNameContextLoader),this._container.get(C.nftTypes.NftContextLoader),this._container.get(p.tokenTypes.TokenContextLoader),this._container.get(x.calldataTypes.CalldataContextLoader),this._container.get(m.dynamicNetworkTypes.DynamicNetworkContextLoader)]}_getDefaultTypedDataLoader(){return this._container.get(f.typedDataTypes.TypedDataContextLoader)}_getWeb3CheckLoader(){return this._container.get(h.web3CheckTypes.Web3CheckContextLoader)}_getSolanaLoader(){try{return this._container.get(u.solanaContextTypes.SolanaContextLoader)}catch{return{load:async e=>(0,c.Left)(new Error("[ContextModule] - DefaultContextModule: no SolanaContextLoader bound"))}}}async getContexts(e,t){const o=Object.values(n.ClearSignContextType),d=this._loaders.filter(i=>i.canHandle(e,t??o)).map(i=>i.load(e));return(await Promise.all(d)).flat()}async getFieldContext(e,t){const o=this._fieldLoaders.filter(a=>a.canHandle(e,t));if(o.length===0)return Promise.resolve({type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)});for(const a of o){const d=await a.loadField(e);if(d.type!==n.ClearSignContextType.ERROR)return d}return{type:n.ClearSignContextType.ERROR,error:new Error(`Loader not found for field: ${e} and expected type: ${t}`)}}async getTypedDataFilters(e){return this._typedDataLoader.load(e)}async getWeb3Checks(e){return(await this._web3CheckLoader.load(e)).caseOf({Right:o=>({type:n.ClearSignContextType.WEB3_CHECK,payload:o.descriptor,certificate:o.certificate}),Left:()=>null})}async getSolanaContext(e){return await this._solanaLoader.load(e)}}0&&(module.exports={DefaultContextModule});
|
|
2
2
|
//# sourceMappingURL=DefaultContextModule.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DefaultContextModule.ts"],
|
|
4
|
-
"sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport {
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAqB,qBAErBC,EAA8B,uCAC9BC,EAAoC,oDAGpCC,EAAiC,8CAGjCC,EAAoC,oDACpCC,EAAyB,6BACzBC,EAA2B,iCAG3BC,EAIO,2CAEPC,EAAmC,0CAGnCC,EAA2B,iCAC3BC,EAA+B,0CAE/BC,
|
|
6
|
-
"names": ["DefaultContextModule_exports", "__export", "DefaultContextModule", "__toCommonJS", "import_purify_ts", "import_calldataTypes", "import_dynamicNetworkTypes", "import_trustedNameTypes", "import_externalPluginTypes", "import_nftTypes", "import_proxyTypes", "import_ClearSignContext", "import_solanaContextTypes", "import_tokenTypes", "import_typedDataTypes", "
|
|
4
|
+
"sourcesContent": ["import { type Container } from \"inversify\";\nimport { Left } from \"purify-ts\";\n\nimport { calldataTypes } from \"@/calldata/di/calldataTypes\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport type { TypedDataClearSignContext } from \"@/shared/model/TypedDataClearSignContext\";\nimport type { TypedDataContext } from \"@/shared/model/TypedDataContext\";\nimport { trustedNameTypes } from \"@/trusted-name/di/trustedNameTypes\";\n\nimport { type ContextModuleConfig } from \"./config/model/ContextModuleConfig\";\nimport { externalPluginTypes } from \"./external-plugin/di/externalPluginTypes\";\nimport { nftTypes } from \"./nft/di/nftTypes\";\nimport { proxyTypes } from \"./proxy/di/proxyTypes\";\nimport { type ContextFieldLoader } from \"./shared/domain/ContextFieldLoader\";\nimport { type ContextLoader } from \"./shared/domain/ContextLoader\";\nimport {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n} from \"./shared/model/ClearSignContext\";\nimport { type SolanaTransactionContext } from \"./shared/model/SolanaTransactionContext\";\nimport { solanaContextTypes } from \"./solana/di/solanaContextTypes\";\nimport { type SolanaContextLoader } from \"./solana/domain/SolanaContextLoader\";\nimport { type SolanaTransactionContextResult } from \"./solana/domain/solanaContextTypes\";\nimport { tokenTypes } from \"./token/di/tokenTypes\";\nimport { typedDataTypes } from \"./typed-data/di/typedDataTypes\";\nimport type { TypedDataContextLoader } from \"./typed-data/domain/TypedDataContextLoader\";\nimport { web3CheckTypes } from \"./web3-check/di/web3CheckTypes\";\nimport { type Web3CheckContextLoader } from \"./web3-check/domain/Web3CheckContextLoader\";\nimport {\n type Web3CheckContext,\n type Web3Checks,\n} from \"./web3-check/domain/web3CheckTypes\";\nimport { type ContextModule } from \"./ContextModule\";\nimport { makeContainer } from \"./di\";\n\nexport class DefaultContextModule implements ContextModule {\n private _container: Container;\n private _loaders: ContextLoader<unknown>[];\n private _typedDataLoader: TypedDataContextLoader;\n private _web3CheckLoader: Web3CheckContextLoader;\n private _solanaLoader: SolanaContextLoader;\n private _fieldLoaders: ContextFieldLoader<unknown>[];\n\n constructor(args: ContextModuleConfig) {\n this._container = makeContainer({ config: args });\n\n this._loaders = args.defaultLoaders ? this._getDefaultLoaders() : [];\n this._loaders.push(...args.customLoaders);\n\n this._fieldLoaders = args.defaultFieldLoaders\n ? this._getDefaultFieldLoaders()\n : [];\n this._fieldLoaders.push(...args.customFieldLoaders);\n\n this._typedDataLoader =\n args.customTypedDataLoader ?? this._getDefaultTypedDataLoader();\n this._web3CheckLoader =\n args.customWeb3CheckLoader ?? this._getWeb3CheckLoader();\n this._solanaLoader = args.customSolanaLoader ?? this._getSolanaLoader();\n }\n\n private _getDefaultFieldLoaders(): ContextFieldLoader[] {\n return [\n this._container.get<ContextFieldLoader>(nftTypes.NftContextFieldLoader),\n this._container.get<ContextFieldLoader>(\n tokenTypes.TokenContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n trustedNameTypes.TrustedNameContextFieldLoader,\n ),\n this._container.get<ContextFieldLoader>(\n proxyTypes.ProxyContextFieldLoader,\n ),\n ];\n }\n\n private _getDefaultLoaders(): ContextLoader<unknown>[] {\n return [\n this._container.get<ContextLoader>(\n externalPluginTypes.ExternalPluginContextLoader,\n ),\n this._container.get<ContextLoader>(\n trustedNameTypes.TrustedNameContextLoader,\n ),\n this._container.get<ContextLoader>(nftTypes.NftContextLoader),\n this._container.get<ContextLoader>(tokenTypes.TokenContextLoader),\n this._container.get<ContextLoader>(calldataTypes.CalldataContextLoader),\n this._container.get<ContextLoader>(\n dynamicNetworkTypes.DynamicNetworkContextLoader,\n ),\n ];\n }\n\n private _getDefaultTypedDataLoader(): TypedDataContextLoader {\n return this._container.get<TypedDataContextLoader>(\n typedDataTypes.TypedDataContextLoader,\n );\n }\n\n private _getWeb3CheckLoader(): Web3CheckContextLoader {\n return this._container.get<Web3CheckContextLoader>(\n web3CheckTypes.Web3CheckContextLoader,\n );\n }\n\n private _getSolanaLoader(): SolanaContextLoader {\n try {\n return this._container.get<SolanaContextLoader>(\n solanaContextTypes.SolanaContextLoader,\n );\n } catch {\n return {\n load: async (_ctx) =>\n Left(\n new Error(\n \"[ContextModule] - DefaultContextModule: no SolanaContextLoader bound\",\n ),\n ),\n };\n }\n }\n\n public async getContexts(\n input: unknown,\n expectedTypes?: ClearSignContextType[],\n ): Promise<ClearSignContext[]> {\n const allContextTypes = Object.values(ClearSignContextType);\n const loaders = this._loaders.filter((l) =>\n l.canHandle(input, expectedTypes ?? allContextTypes),\n );\n const promises = loaders.map((fetcher) => fetcher.load(input));\n const responses = await Promise.all(promises);\n return responses.flat();\n }\n\n public async getFieldContext<TInput>(\n field: TInput,\n expectedType: ClearSignContextType,\n ): Promise<ClearSignContext> {\n const loaders = this._fieldLoaders.filter((l) =>\n l.canHandle(field, expectedType),\n );\n if (loaders.length === 0) {\n return Promise.resolve({\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n });\n }\n\n for (const loader of loaders) {\n const context = await loader.loadField(field);\n if (context.type !== ClearSignContextType.ERROR) {\n return context;\n }\n }\n\n return {\n type: ClearSignContextType.ERROR,\n error: new Error(\n `Loader not found for field: ${field} and expected type: ${expectedType}`,\n ),\n };\n }\n\n public async getTypedDataFilters(\n typedData: TypedDataContext,\n ): Promise<TypedDataClearSignContext> {\n return this._typedDataLoader.load(typedData);\n }\n\n public async getWeb3Checks(\n transactionContext: Web3CheckContext,\n ): Promise<ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null> {\n const web3Checks = await this._web3CheckLoader.load(transactionContext);\n\n return web3Checks.caseOf({\n Right: (checks: Web3Checks) => ({\n type: ClearSignContextType.WEB3_CHECK,\n payload: checks.descriptor,\n certificate: checks.certificate,\n }),\n Left: () => null,\n });\n }\n\n public async getSolanaContext(\n transactionContext: SolanaTransactionContext,\n ): Promise<SolanaTransactionContextResult> {\n return await this._solanaLoader.load(transactionContext);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAqB,qBAErBC,EAA8B,uCAC9BC,EAAoC,oDAGpCC,EAAiC,8CAGjCC,E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B,CACzD,CACF",
|
|
6
|
+
"names": ["DefaultContextModule_exports", "__export", "DefaultContextModule", "__toCommonJS", "import_purify_ts", "import_calldataTypes", "import_dynamicNetworkTypes", "import_trustedNameTypes", "import_externalPluginTypes", "import_nftTypes", "import_proxyTypes", "import_ClearSignContext", "import_solanaContextTypes", "import_tokenTypes", "import_typedDataTypes", "import_web3CheckTypes", "import_di", "args", "_ctx", "input", "expectedTypes", "allContextTypes", "promises", "l", "fetcher", "field", "expectedType", "loaders", "loader", "context", "typedData", "transactionContext", "checks"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)m(n,r,{get:e[r],enumerable:!0})},H=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of w(e))!_.call(n,a)&&a!==r&&m(n,a,{get:()=>e[a],enumerable:!(t=P(e,a))||t.enumerable});return n};var O=n=>H(m({},"__esModule",{value:!0}),n),E=(n,e,r,t)=>{for(var a=t>1?void 0:t?P(e,r):e,s=n.length-1,d;s>=0;s--)(d=n[s])&&(a=(t?d(e,r,a):d(a))||a);return t&&a&&m(e,r,a),a},C=(n,e)=>(r,t)=>e(r,t,n);var v={};b(v,{ExternalPluginContextLoader:()=>p});module.exports=O(v);var g=require("@ledgerhq/device-management-kit"),D=require("ethers"),c=require("inversify"),l=require("purify-ts"),I=require("../../external-plugin/di/externalPluginTypes"),o=require("../../shared/model/ClearSignContext"),T=require("../../token/di/tokenTypes"),L=require("../../uniswap/di/uniswapTypes");const U=[o.ClearSignContextType.EXTERNAL_PLUGIN,o.ClearSignContextType.TOKEN];let p=class{constructor(e,r,t){this._externalPluginDataSource=e;this._tokenDataSource=r;this._uniswapLoader=t;this._customPluginLoaders={Uniswap:this._uniswapLoader}}_customPluginLoaders;canHandle(e,r){return typeof e=="object"&&e!==null&&"to"in e&&"data"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&(0,g.isHexaString)(e.to)&&e.to!=="0x"&&(0,g.isHexaString)(e.data)&&e.data!=="0x"&&(0,g.isHexaString)(e.selector)&&e.selector!=="0x"&&U.every(t=>r.includes(t))}async load(e){const{to:r,data:t,selector:a,chainId:s}=e,d=await this._externalPluginDataSource.getDappInfos({address:r,chainId:s,selector:a});return(0,l.EitherAsync)(async({liftEither:u})=>{const i=await u(d);if(!i)return[];const f={type:o.ClearSignContextType.EXTERNAL_PLUGIN,payload:i.selectorDetails.serializedData.concat(i.selectorDetails.signature)},h=this._customPluginLoaders[i.selectorDetails.plugin];if(h!==void 0&&h.canHandle(e,[o.ClearSignContextType.TOKEN])){const x=await h.load(e);return[f,...x]}const y=this.getDecodedCallData(i.abi,i.selectorDetails.method,t);if(y.isLeft())return[{type:o.ClearSignContextType.ERROR,error:y.extract()},f];const R=y.extract(),k=i.selectorDetails.erc20OfInterest.map(async x=>this.getTokenPayload(e,x,R));return[...(await Promise.all(k)).map(x=>x.caseOf({Left:S=>({type:o.ClearSignContextType.ERROR,error:S}),Right:S=>({type:o.ClearSignContextType.TOKEN,payload:S})})),f]}).caseOf({Left:u=>[{type:o.ClearSignContextType.ERROR,error:u}],Right:u=>u})}getTokenPayload(e,r,t){const a=this.getAddressFromPath(r,t);return(0,l.EitherAsync)(({fromPromise:s})=>s(this._tokenDataSource.getTokenInfosPayload({address:a,chainId:e.chainId})))}getDecodedCallData(e,r,t){try{const a=new D.Interface(e);return(0,l.Right)(a.decodeFunctionData(r,t))}catch{return(0,l.Left)(new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi"))}}getAddressFromPath(e,r){let t=r;for(const a of e.split("."))a==="-1"?t=t[t.length-1]:t=t[a];if(!(0,g.isHexaString)(t))throw new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address");return t}};p=E([(0,c.injectable)(),C(0,(0,c.inject)(I.externalPluginTypes.ExternalPluginDataSource)),C(1,(0,c.inject)(T.tokenTypes.TokenDataSource)),C(2,(0,c.inject)(L.uniswapTypes.UniswapContextLoader))],p);0&&(module.exports={ExternalPluginContextLoader});
|
|
2
2
|
//# sourceMappingURL=ExternalPluginContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n];\n\n@injectable()\nexport class ExternalPluginContextLoader\n implements ContextLoader<ExternalPluginContextInput>\n{\n private
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAAkC,kBAClCC,EAAmC,qBACnCC,EAAiD,qBAGjDC,EAAoC,oDAEpCC,EAGO,2CAEPC,EAA2B,
|
|
6
|
-
"names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "
|
|
4
|
+
"sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { ethers, Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, EitherAsync, Left, Right } from \"purify-ts\";\n\nimport type { ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport { externalPluginTypes } from \"@/external-plugin/di/externalPluginTypes\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport type { TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\nimport type { UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nexport type ExternalPluginContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nexport type ExternalPluginTokensInput = {\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n];\n\n@injectable()\nexport class ExternalPluginContextLoader\n implements ContextLoader<ExternalPluginContextInput>\n{\n private _customPluginLoaders: Record<\n string,\n ContextLoader<ExternalPluginTokensInput>\n >;\n\n constructor(\n @inject(externalPluginTypes.ExternalPluginDataSource)\n private _externalPluginDataSource: ExternalPluginDataSource,\n @inject(tokenTypes.TokenDataSource)\n private _tokenDataSource: TokenDataSource,\n @inject(uniswapTypes.UniswapContextLoader)\n private _uniswapLoader: UniswapContextLoader,\n ) {\n this._customPluginLoaders = {\n Uniswap: this._uniswapLoader,\n };\n }\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is ExternalPluginContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.to) &&\n input.to !== \"0x\" &&\n isHexaString(input.data) &&\n input.data !== \"0x\" && // non empty data\n isHexaString(input.selector) &&\n input.selector !== \"0x\" &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: ExternalPluginContextInput): Promise<ClearSignContext[]> {\n const { to, data, selector, chainId } = input;\n\n const eitherDappInfos = await this._externalPluginDataSource.getDappInfos({\n address: to,\n chainId,\n selector,\n });\n\n return EitherAsync<Error, ClearSignContext[]>(async ({ liftEither }) => {\n const dappInfos = await liftEither(eitherDappInfos);\n\n // if the dappInfos is null, return an empty array\n // this means that the selector is not a known selector\n if (!dappInfos) {\n return [];\n }\n\n const externalPluginContext: ClearSignContext = {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: dappInfos.selectorDetails.serializedData.concat(\n dappInfos.selectorDetails.signature,\n ),\n };\n\n const customLoader =\n this._customPluginLoaders[dappInfos.selectorDetails.plugin];\n if (\n customLoader !== undefined &&\n customLoader.canHandle(input, [ClearSignContextType.TOKEN])\n ) {\n const tokens = await customLoader.load(input);\n return [externalPluginContext, ...tokens];\n }\n\n const decodedCallData = this.getDecodedCallData(\n dappInfos.abi,\n dappInfos.selectorDetails.method,\n data,\n );\n\n // if the call data cannot be decoded, return the error\n // but also the externalPluginContext because it is still valid\n if (decodedCallData.isLeft()) {\n return [\n {\n type: ClearSignContextType.ERROR,\n error: decodedCallData.extract(),\n },\n externalPluginContext,\n ];\n }\n\n // decodedCallData is a Right so we can extract it safely\n const extractedDecodedCallData =\n decodedCallData.extract() as ethers.Result;\n\n // get the token payload for each erc20OfInterest\n // and return the payload or the error\n const promises = dappInfos.selectorDetails.erc20OfInterest.map(\n async (erc20Path) =>\n this.getTokenPayload(input, erc20Path, extractedDecodedCallData),\n );\n\n const tokensPayload = await Promise.all(promises);\n\n // map the payload or the error to a ClearSignContext\n const contexts: ClearSignContext[] = tokensPayload.map((eitherToken) =>\n eitherToken.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n\n return [...contexts, externalPluginContext];\n }).caseOf<ClearSignContext[]>({\n // parse all errors into ClearSignContext\n Left: (error) => [{ type: ClearSignContextType.ERROR, error }],\n Right: (contexts) => contexts,\n });\n }\n\n private getTokenPayload(\n input: ExternalPluginContextInput,\n erc20Path: string,\n decodedCallData: ethers.Result,\n ) {\n const address = this.getAddressFromPath(erc20Path, decodedCallData);\n\n return EitherAsync<Error, string>(({ fromPromise }) =>\n fromPromise(\n this._tokenDataSource.getTokenInfosPayload({\n address,\n chainId: input.chainId,\n }),\n ),\n );\n }\n\n private getDecodedCallData(\n abi: object[],\n method: string,\n data: string,\n ): Either<Error, ethers.Result> {\n try {\n const contractInterface = new Interface(abi);\n return Right(contractInterface.decodeFunctionData(method, data));\n } catch (_error) {\n return Left(\n new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n );\n }\n }\n\n private getAddressFromPath(\n path: string,\n decodedCallData: ethers.Result,\n ): HexaString {\n // ethers.Result is a record string, any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let value: any = decodedCallData;\n for (const key of path.split(\".\")) {\n // In Solidity, a struct cannot begin with a number\n // Additionally, when we use -1, it signifies the last element of the array.\n if (key === \"-1\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[value.length - 1];\n } else {\n // This access can throw a RangeError error in case of an invalid key\n // but is correctly caught by the liftEither above\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n value = value[key];\n }\n }\n\n if (!isHexaString(value)) {\n throw new Error(\n \"[ContextModule] External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,YAAUF,CAAG,EAC3C,SAAO,SAAME,EAAkB,mBAAmBD,EAAQpB,CAAI,CAAC,CACjE,MAAiB,CACf,SAAO,QACL,IAAI,MACF,kEACF,CACF,CACF,CACF,CAEQ,mBACNsB,EACAb,EACY,CAGZ,IAAIc,EAAad,EACjB,UAAWe,KAAOF,EAAK,MAAM,GAAG,EAG1BE,IAAQ,KAEVD,EAAQA,EAAMA,EAAM,OAAS,CAAC,EAK9BA,EAAQA,EAAMC,CAAG,EAIrB,GAAI,IAAC,gBAAaD,CAAK,EACrB,MAAM,IAAI,MACR,oEACF,EAGF,OAAOA,CACT,CACF,EA5La/B,EAANiC,EAAA,IADN,cAAW,EAUPC,EAAA,eAAO,sBAAoB,wBAAwB,GAEnDA,EAAA,eAAO,aAAW,eAAe,GAEjCA,EAAA,eAAO,eAAa,oBAAoB,IAbhClC",
|
|
6
|
+
"names": ["ExternalPluginContextLoader_exports", "__export", "ExternalPluginContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_externalPluginTypes", "import_ClearSignContext", "import_tokenTypes", "import_uniswapTypes", "SUPPORTED_TYPES", "ExternalPluginContextLoader", "_externalPluginDataSource", "_tokenDataSource", "_uniswapLoader", "input", "expectedTypes", "type", "to", "data", "selector", "chainId", "eitherDappInfos", "liftEither", "dappInfos", "externalPluginContext", "customLoader", "tokens", "decodedCallData", "extractedDecodedCallData", "promises", "erc20Path", "eitherToken", "error", "payload", "contexts", "address", "fromPromise", "abi", "method", "contractInterface", "path", "value", "key", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var m=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var D=(c,n,o,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of y(n))!b.call(c,t)&&t!==o&&i(c,t,{get:()=>n[t],enumerable:!(e=f(n,t))||e.enumerable});return c};var I=(c,n,o)=>(o=c!=null?m(x(c)):{},D(n||!c||!c.__esModule?i(o,"default",{value:c,enumerable:!0}):o,c));var u=require("ethers"),l=require("purify-ts"),s=I(require("@/external-plugin/__tests__/abi.json")),E=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const p=({abi:c,selectorDetails:n})=>({abi:c,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...n}}),d=(c,n,o)=>{const t=new u.Interface(JSON.stringify(c)).encodeFunctionData(n,o);return{to:"0x0",data:t,selector:t.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const c={getTokenInfosPayload:vi.fn()},n={getDappInfos:vi.fn()},o=new E.ExternalPluginContextLoader(n,c);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(c,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,l.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(o.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(o.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,data:"0x"},"empty data (0x)"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,chainId:void 0},"undefined chainId"]])("should return false for %s",(t,r)=>{expect(o.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(void 0));const t=await o.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=d(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e)),vi.spyOn(c,"getTokenInfosPayload").mockResolvedValue((0,l.Left)(new Error("error")));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const e=p({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=d(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const e=p({abi:s.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),t=d(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Right)(e));const r=await o.load(t);expect(r).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const e=d(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue((0,l.Left)(new Error("error")));const t=await o.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
|
|
1
|
+
"use strict";var y=Object.create;var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var I=(l,o,c,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of x(o))!D.call(l,e)&&e!==c&&u(l,e,{get:()=>o[e],enumerable:!(r=f(o,e))||r.enumerable});return l};var g=(l,o,c)=>(c=l!=null?y(b(l)):{},I(o||!l||!l.__esModule?u(c,"default",{value:l,enumerable:!0}):c,l));var E=require("ethers"),d=require("purify-ts"),s=g(require("@/external-plugin/__tests__/abi.json")),m=require("../../external-plugin/domain/ExternalPluginContextLoader"),a=require("../../shared/model/ClearSignContext");const i=({abi:l,selectorDetails:o})=>({abi:l,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...o}}),p=(l,o,c)=>{const e=new E.Interface(JSON.stringify(l)).encodeFunctionData(o,c);return{to:"0x0",data:e,selector:e.slice(0,10),chainId:1}};describe("ExternalPluginContextLoader",()=>{const l={getTokenInfosPayload:vi.fn()},o={getDappInfos:vi.fn()},c={canHandle:vi.fn(),load:vi.fn()},r=new m.ExternalPluginContextLoader(o,l,c);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(l,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve((0,d.Right)(`payload-${e}`)))}),describe("canHandle function",()=>{const e={to:"0x1234567890123456789012345678901234567890",data:"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890",selector:"0x095ea7b3",chainId:1};it("should return true for valid input",()=>{expect(r.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!0)}),it("should return false for invalid expected type",()=>{expect(r.canHandle(e,[a.ClearSignContextType.NFT])).toBe(!1),expect(r.canHandle(e,[a.ClearSignContextType.TOKEN])).toBe(!1),expect(r.canHandle(e,[a.ClearSignContextType.EXTERNAL_PLUGIN])).toBe(!1)}),it.each([[null,"null input"],[void 0,"undefined input"],[{},"empty object"],["string","string input"],[123,"number input"]])("should return false for %s",(t,n)=>{expect(r.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:void 0},"missing to"],[{...e,data:void 0},"missing data"],[{...e,selector:void 0},"missing selector"],[{...e,chainId:void 0},"missing chainId"]])("should return false for %s",(t,n)=>{expect(r.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,to:"invalid-hex"},"invalid to hex"],[{...e,to:"0x"},"empty to hex"],[{...e,data:"invalid-hex"},"invalid data hex"],[{...e,data:"0x"},"empty data (0x)"],[{...e,selector:"invalid-hex"},"invalid selector hex"],[{...e,selector:"0x"},"empty selector hex"]])("should return false for %s",(t,n)=>{expect(r.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)}),it.each([[{...e,chainId:"1"},"string chainId"],[{...e,chainId:null},"null chainId"],[{...e,chainId:void 0},"undefined chainId"]])("should return false for %s",(t,n)=>{expect(r.canHandle(t,[a.ClearSignContextType.EXTERNAL_PLUGIN,a.ClearSignContextType.TOKEN])).toBe(!1)})}),describe("load function",()=>{it("should return an empty array if no dapp info is provided",async()=>{const e=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(void 0));const t=await r.load(e);expect(t).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when one erc20OfInterest is provided for a single parameter",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam",plugin:"TestPlugin"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"}]))}),it("should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(Error("error")));const n=await r.load(t);expect(c.canHandle).not.toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a list of context responses when two erc20OfInterest are provided for two parameters",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),t=p(s.default,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual(expect.arrayContaining([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(l,"getTokenInfosPayload").mockResolvedValue((0,d.Left)(new Error("error")));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when the abi is not conform",async()=>{const e=i({abi:[{fakeabi:"notworking"}],selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to get address")}])}),it("should throw an error when an out-of-bounds element is present in erc20OfInterest",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),t=p(s.default,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.ERROR,error:new RangeError("out of result range")}])}),it("should return a list of context responses when one erc20OfInterest is a complex struct",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:["complexStruct.address1","complexStruct.param1.param2.0.param3.addresses.0","complexStruct.param1.param2.0.param3.addresses.1","complexStruct.param1.param2.0.param3.addresses.-1","complexStruct.param1.param2.1.param3.addresses.0","complexStruct.param1.param2.-1.param3.addresses.0"],method:"complexStructParam"}}),t=p(s.default,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e));const n=await r.load(t);expect(n).toEqual([{type:a.ClearSignContextType.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap not being able to load token",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!1);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).not.toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return a plugin with Uniswap extracted tokens",async()=>{const e=i({abi:s.default,selectorDetails:{erc20OfInterest:[],method:"singleParam",plugin:"Uniswap"}}),t=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Right)(e)),vi.spyOn(c,"canHandle").mockReturnValueOnce(!0),vi.spyOn(c,"load").mockResolvedValue([{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}]);const n=await r.load(t);expect(c.canHandle).toHaveBeenCalled(),expect(c.load).toHaveBeenCalled(),expect(n).toEqual([{type:a.ClearSignContextType.EXTERNAL_PLUGIN,payload:"1234567890"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:a.ClearSignContextType.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"}])}),it("should return an error when datasource return a Left",async()=>{const e=p(s.default,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(o,"getDappInfos").mockResolvedValue((0,d.Left)(new Error("error")));const t=await r.load(e);expect(t).toEqual([{type:a.ClearSignContextType.ERROR,error:new Error("error")}])})})});
|
|
2
2
|
//# sourceMappingURL=ExternalPluginContextLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/external-plugin/domain/ExternalPluginContextLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport {\n type ExternalPluginContextInput,\n ExternalPluginContextLoader,\n} from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst inputBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): ExternalPluginContextInput => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data: data as `0x${string}`,\n selector: data.slice(0, 10) as `0x${string}`,\n chainId: 1,\n };\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: ExternalPluginContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890\",\n selector: \"0x095ea7b3\",\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data (0x)\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, chainId: undefined }, \"undefined chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dapp info is provided\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const input = inputBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const input = inputBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAGO,gEAGPC,EAAqC,
|
|
6
|
-
"names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "validInput", "input", "_description", "ABI", "result", "dappInfos"]
|
|
4
|
+
"sourcesContent": ["import { Interface } from \"ethers\";\nimport { Left, Right } from \"purify-ts\";\n\nimport ABI from \"@/external-plugin/__tests__/abi.json\";\nimport { type ExternalPluginDataSource } from \"@/external-plugin/data/ExternalPluginDataSource\";\nimport {\n type ExternalPluginContextInput,\n ExternalPluginContextLoader,\n} from \"@/external-plugin/domain/ExternalPluginContextLoader\";\nimport { type DappInfos } from \"@/external-plugin/model/DappInfos\";\nimport { type SelectorDetails } from \"@/external-plugin/model/SelectorDetails\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type UniswapContextLoader } from \"@/uniswap/domain/UniswapContextLoader\";\n\nconst dappInfosBuilder = ({\n abi,\n selectorDetails,\n}: {\n abi?: object[];\n selectorDetails?: Partial<SelectorDetails>;\n}) => {\n return {\n abi: abi,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"\",\n plugin: \"\",\n serializedData: \"123456\",\n signature: \"7890\",\n ...selectorDetails,\n },\n } as DappInfos;\n};\n\nconst inputBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): ExternalPluginContextInput => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data: data as `0x${string}`,\n selector: data.slice(0, 10) as `0x${string}`,\n chainId: 1,\n };\n};\n\ndescribe(\"ExternalPluginContextLoader\", () => {\n const mockTokenDataSource: TokenDataSource = {\n getTokenInfosPayload: vi.fn(),\n };\n const mockExternalPluginDataSource: ExternalPluginDataSource = {\n getDappInfos: vi.fn(),\n };\n const mockUniswapLoader: UniswapContextLoader = {\n canHandle: vi.fn(),\n load: vi.fn(),\n } as unknown as UniswapContextLoader;\n const loader = new ExternalPluginContextLoader(\n mockExternalPluginDataSource,\n mockTokenDataSource,\n mockUniswapLoader,\n );\n\n beforeEach(() => {\n vi.clearAllMocks();\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockImplementation(\n ({ address }) => Promise.resolve(Right(`payload-${address}`)),\n );\n });\n\n describe(\"canHandle function\", () => {\n const validInput: ExternalPluginContextInput = {\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0x095ea7b30000000000000000000000001234567890123456789012345678901234567890\",\n selector: \"0x095ea7b3\",\n chainId: 1,\n };\n\n it(\"should return true for valid input\", () => {\n expect(\n loader.canHandle(validInput, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(true);\n });\n\n it(\"should return false for invalid expected type\", () => {\n expect(loader.canHandle(validInput, [ClearSignContextType.NFT])).toBe(\n false,\n );\n expect(loader.canHandle(validInput, [ClearSignContextType.TOKEN])).toBe(\n false,\n );\n expect(\n loader.canHandle(validInput, [ClearSignContextType.EXTERNAL_PLUGIN]),\n ).toBe(false);\n });\n\n it.each([\n [null, \"null input\"],\n [undefined, \"undefined input\"],\n [{}, \"empty object\"],\n [\"string\", \"string input\"],\n [123, \"number input\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: undefined }, \"missing to\"],\n [{ ...validInput, data: undefined }, \"missing data\"],\n [{ ...validInput, selector: undefined }, \"missing selector\"],\n [{ ...validInput, chainId: undefined }, \"missing chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, to: \"invalid-hex\" }, \"invalid to hex\"],\n [{ ...validInput, to: \"0x\" }, \"empty to hex\"],\n [{ ...validInput, data: \"invalid-hex\" }, \"invalid data hex\"],\n [{ ...validInput, data: \"0x\" }, \"empty data (0x)\"],\n [{ ...validInput, selector: \"invalid-hex\" }, \"invalid selector hex\"],\n [{ ...validInput, selector: \"0x\" }, \"empty selector hex\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n\n it.each([\n [{ ...validInput, chainId: \"1\" }, \"string chainId\"],\n [{ ...validInput, chainId: null }, \"null chainId\"],\n [{ ...validInput, chainId: undefined }, \"undefined chainId\"],\n ])(\"should return false for %s\", (input, _description) => {\n expect(\n loader.canHandle(input, [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n ]),\n ).toBe(false);\n });\n });\n\n describe(\"load function\", () => {\n it(\"should return an empty array if no dapp info is provided\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return e plugin if no erc20OfInterest is provided\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"TestPlugin\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is provided for a single parameter\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n plugin: \"TestPlugin\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n ]),\n );\n });\n\n it(\"should return a context response with only set external plugin when one erc20OfInterest is provided for a single parameter but no payload is feched\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a list of context responses when two erc20OfInterest are provided for two parameters\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\", \"toToken\"],\n method: \"multipleParams\",\n },\n });\n const input = inputBuilder(ABI, \"multipleParams\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual(\n expect.arrayContaining([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n ]),\n );\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is an array\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"fromToken.0\",\n \"fromToken.1\",\n \"fromToken.2\",\n \"fromToken.-1\",\n ],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n // fromToken.2\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n // fromToken.-1\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when a token datasource returns an error\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockTokenDataSource, \"getTokenInfosPayload\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return an error when the abi is not conform\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: [{ fakeabi: \"notworking\" }],\n selectorDetails: {\n erc20OfInterest: [\"fromToken\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to parse abi\",\n ),\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should throw an error when the erc20OfInterest doest not exist in the transaction\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"notFound\"],\n method: \"singleParam\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\n \"[ContextModule] ExternalPluginContextLoader: Unable to get address\",\n ),\n },\n ]);\n });\n\n it(\"should throw an error when an out-of-bounds element is present in erc20OfInterest\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\"fromToken.3\"],\n method: \"arrayParam\",\n },\n });\n const input = inputBuilder(ABI, \"arrayParam\", [\n [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n ],\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new RangeError(\"out of result range\"),\n },\n ]);\n });\n\n it(\"should return a list of context responses when one erc20OfInterest is a complex struct\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [\n \"complexStruct.address1\",\n \"complexStruct.param1.param2.0.param3.addresses.0\",\n \"complexStruct.param1.param2.0.param3.addresses.1\",\n \"complexStruct.param1.param2.0.param3.addresses.-1\",\n \"complexStruct.param1.param2.1.param3.addresses.0\",\n \"complexStruct.param1.param2.-1.param3.addresses.0\",\n ],\n method: \"complexStructParam\",\n },\n });\n const input = inputBuilder(ABI, \"complexStructParam\", [\n {\n address1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n param1: {\n param2: [\n {\n param3: {\n addresses: [\n \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n \"0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n ],\n },\n },\n {\n param3: {\n addresses: [\"0xB8c77482e45F1F44dE1745F52C74426C631bDD52\"],\n },\n },\n ],\n },\n },\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a plugin with Uniswap not being able to load token\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"Uniswap\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockUniswapLoader, \"canHandle\").mockReturnValueOnce(false);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).toHaveBeenCalled();\n expect(mockUniswapLoader.load).not.toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n ]);\n });\n\n it(\"should return a plugin with Uniswap extracted tokens\", async () => {\n // GIVEN\n const dappInfos = dappInfosBuilder({\n abi: ABI,\n selectorDetails: {\n erc20OfInterest: [],\n method: \"singleParam\",\n plugin: \"Uniswap\",\n },\n });\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n vi.spyOn(mockUniswapLoader, \"canHandle\").mockReturnValueOnce(true);\n vi.spyOn(mockUniswapLoader, \"load\").mockResolvedValue([\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n ]);\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(mockUniswapLoader.canHandle).toHaveBeenCalled();\n expect(mockUniswapLoader.load).toHaveBeenCalled();\n expect(result).toEqual([\n {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: \"1234567890\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE\",\n },\n {\n type: ClearSignContextType.TOKEN,\n payload: \"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52\",\n },\n ]);\n });\n\n it(\"should return an error when datasource return a Left\", async () => {\n // GIVEN\n const input = inputBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Left(new Error(\"error\")),\n );\n\n // WHEN\n const result = await loader.load(input);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "wdAAA,IAAAA,EAA0B,kBAC1BC,EAA4B,qBAE5BC,EAAgB,mDAEhBC,EAGO,gEAGPC,EAAqC,2CAIrC,MAAMC,EAAmB,CAAC,CACxB,IAAAC,EACA,gBAAAC,CACF,KAIS,CACL,IAAKD,EACL,gBAAiB,CACf,gBAAiB,CAAC,EAClB,OAAQ,GACR,OAAQ,GACR,eAAgB,SAChB,UAAW,OACX,GAAGC,CACL,CACF,GAGIC,EAAe,CACnBF,EACAG,EACAC,IAC+B,CAE/B,MAAMC,EADW,IAAI,YAAU,KAAK,UAAUL,CAAG,CAAC,EAC5B,mBAAmBG,EAAcC,CAAM,EAC7D,MAAO,CACL,GAAI,MACJ,KAAMC,EACN,SAAUA,EAAK,MAAM,EAAG,EAAE,EAC1B,QAAS,CACX,CACF,EAEA,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAyD,CAC7D,aAAc,GAAG,GAAG,CACtB,EACMC,EAA0C,CAC9C,UAAW,GAAG,GAAG,EACjB,KAAM,GAAG,GAAG,CACd,EACMC,EAAS,IAAI,8BACjBF,EACAD,EACAE,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMF,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAI,CAAQ,I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CAAC,EAClB,OAAQ,cACR,OAAQ,SACV,CACF,CAAC,EACKF,EAAQV,EAAa,EAAAY,QAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMP,EAA8B,cAAc,EAAE,qBACrD,SAAMS,CAAS,CACjB,EACA,GAAG,MAAMR,EAAmB,WAAW,EAAE,oBAAoB,EAAI,EACjE,GAAG,MAAMA,EAAmB,MAAM,EAAE,kBAAkB,CACpD,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,EAGD,MAAMO,EAAS,MAAMN,EAAO,KAAKG,CAAK,EAGtC,OAAOJ,EAAkB,SAAS,EAAE,iBAAiB,EACrD,OAAOA,EAAkB,IAAI,EAAE,iBAAiB,EAChD,OAAOO,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,gBAC3B,QAAS,YACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAM,uBAAqB,MAC3B,QAAS,oDACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMH,EAAQV,EAAa,EAAAY,QAAK,cAAe,CAC7C,4CACF,CAAC,EACD,GAAG,MAAMP,EAA8B,cAAc,EAAE,qBACrD,QAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMQ,EAAS,MAAMN,EAAO,KAAKG,CAAK,EAGtC,OAAOG,CAAM,EAAE,QAAQ,CACrB,CACE,KAAM,uBAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_ethers", "import_purify_ts", "import_abi", "import_ExternalPluginContextLoader", "import_ClearSignContext", "dappInfosBuilder", "abi", "selectorDetails", "inputBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "mockUniswapLoader", "loader", "address", "validInput", "input", "_description", "ABI", "result", "dappInfos"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var R=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var R=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var M=(A,T)=>{for(var P in T)R(A,P,{get:T[P],enumerable:!0})},p=(A,T,P,S)=>{if(T&&typeof T=="object"||typeof T=="function")for(let E of W(T))!t.call(A,E)&&E!==P&&R(A,E,{get:()=>T[E],enumerable:!(S=C(T,E))||S.enumerable});return A};var a=A=>p(R({},"__esModule",{value:!0}),A);var O={};M(O,{UNISWAP_COMMANDS:()=>o,UNISWAP_EXECUTE_ABI:()=>e,UNISWAP_EXECUTE_SELECTOR:()=>n,UNISWAP_SWAP_COMMANDS:()=>N,UniswapSupportedCommand:()=>I});module.exports=a(O);const e=["function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable"],n="0x3593564c";var I=(_=>(_.V2_SWAP_EXACT_IN="V2_SWAP_EXACT_IN",_.V2_SWAP_EXACT_OUT="V2_SWAP_EXACT_OUT",_.V3_SWAP_EXACT_IN="V3_SWAP_EXACT_IN",_.V3_SWAP_EXACT_OUT="V3_SWAP_EXACT_OUT",_.WRAP_ETH="WRAP_ETH",_.UNWRAP_ETH="UNWRAP_ETH",_.PERMIT2_PERMIT="PERMIT2_PERMIT",_.PERMIT2_TRANSFER_FROM="PERMIT2_TRANSFER_FROM",_.PERMIT2_PERMIT_BATCH="PERMIT2_PERMIT_BATCH",_.PERMIT2_TRANSFER_FROM_BATCH="PERMIT2_TRANSFER_FROM_BATCH",_.PAY_PORTION="PAY_PORTION",_.SWEEP="SWEEP",_))(I||{});const o={"0x08":"V2_SWAP_EXACT_IN","0x09":"V2_SWAP_EXACT_OUT","0x00":"V3_SWAP_EXACT_IN","0x01":"V3_SWAP_EXACT_OUT","0x0b":"WRAP_ETH","0x0c":"UNWRAP_ETH","0x0a":"PERMIT2_PERMIT","0x0d":"PERMIT2_TRANSFER_FROM","0x02":"PERMIT2_PERMIT_BATCH","0x03":"PERMIT2_TRANSFER_FROM_BATCH","0x06":"PAY_PORTION","0x04":"SWEEP"},N=["V2_SWAP_EXACT_IN","V2_SWAP_EXACT_OUT","V3_SWAP_EXACT_IN","V3_SWAP_EXACT_OUT"];0&&(module.exports={UNISWAP_COMMANDS,UNISWAP_EXECUTE_ABI,UNISWAP_EXECUTE_SELECTOR,UNISWAP_SWAP_COMMANDS,UniswapSupportedCommand});
|
|
2
2
|
//# sourceMappingURL=uniswap.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/uniswap/constants/uniswap.ts"],
|
|
4
|
-
"sourcesContent": ["import { type HexaString } from \"@ledgerhq/device-management-kit\";\n\nexport const UNISWAP_EXECUTE_ABI = [\n \"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable\",\n];\n\nexport const
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,wBAAAC,EAAA,6BAAAC,EAAA,0BAAAC,EAAA,
|
|
6
|
-
"names": ["uniswap_exports", "__export", "UNISWAP_COMMANDS", "UNISWAP_EXECUTE_ABI", "UNISWAP_EXECUTE_SELECTOR", "UNISWAP_SWAP_COMMANDS", "
|
|
4
|
+
"sourcesContent": ["import { type HexaString } from \"@ledgerhq/device-management-kit\";\n\nexport const UNISWAP_EXECUTE_ABI = [\n \"function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable\",\n];\n\nexport const UNISWAP_EXECUTE_SELECTOR = \"0x3593564c\";\n\nexport enum UniswapSupportedCommand {\n V2_SWAP_EXACT_IN = \"V2_SWAP_EXACT_IN\",\n V2_SWAP_EXACT_OUT = \"V2_SWAP_EXACT_OUT\",\n V3_SWAP_EXACT_IN = \"V3_SWAP_EXACT_IN\",\n V3_SWAP_EXACT_OUT = \"V3_SWAP_EXACT_OUT\",\n WRAP_ETH = \"WRAP_ETH\",\n UNWRAP_ETH = \"UNWRAP_ETH\",\n PERMIT2_PERMIT = \"PERMIT2_PERMIT\",\n PERMIT2_TRANSFER_FROM = \"PERMIT2_TRANSFER_FROM\",\n PERMIT2_PERMIT_BATCH = \"PERMIT2_PERMIT_BATCH\",\n PERMIT2_TRANSFER_FROM_BATCH = \"PERMIT2_TRANSFER_FROM_BATCH\",\n PAY_PORTION = \"PAY_PORTION\",\n SWEEP = \"SWEEP\",\n}\n\nexport const UNISWAP_COMMANDS: Record<HexaString, UniswapSupportedCommand> = {\n \"0x08\": UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n \"0x09\": UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n \"0x00\": UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n \"0x01\": UniswapSupportedCommand.V3_SWAP_EXACT_OUT,\n \"0x0b\": UniswapSupportedCommand.WRAP_ETH,\n \"0x0c\": UniswapSupportedCommand.UNWRAP_ETH,\n \"0x0a\": UniswapSupportedCommand.PERMIT2_PERMIT,\n \"0x0d\": UniswapSupportedCommand.PERMIT2_TRANSFER_FROM,\n \"0x02\": UniswapSupportedCommand.PERMIT2_PERMIT_BATCH,\n \"0x03\": UniswapSupportedCommand.PERMIT2_TRANSFER_FROM_BATCH,\n \"0x06\": UniswapSupportedCommand.PAY_PORTION,\n \"0x04\": UniswapSupportedCommand.SWEEP,\n};\n\nexport const UNISWAP_SWAP_COMMANDS: UniswapSupportedCommand[] = [\n UniswapSupportedCommand.V2_SWAP_EXACT_IN,\n UniswapSupportedCommand.V2_SWAP_EXACT_OUT,\n UniswapSupportedCommand.V3_SWAP_EXACT_IN,\n UniswapSupportedCommand.V3_SWAP_EXACT_OUT,\n];\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,wBAAAC,EAAA,6BAAAC,EAAA,0BAAAC,EAAA,4BAAAC,IAAA,eAAAC,EAAAP,GAEO,MAAMG,EAAsB,CACjC,uGACF,EAEaC,EAA2B,aAEjC,IAAKE,OACVA,EAAA,iBAAmB,mBACnBA,EAAA,kBAAoB,oBACpBA,EAAA,iBAAmB,mBACnBA,EAAA,kBAAoB,oBACpBA,EAAA,SAAW,WACXA,EAAA,WAAa,aACbA,EAAA,eAAiB,iBACjBA,EAAA,sBAAwB,wBACxBA,EAAA,qBAAuB,uBACvBA,EAAA,4BAA8B,8BAC9BA,EAAA,YAAc,cACdA,EAAA,MAAQ,QAZEA,OAAA,IAeL,MAAMJ,EAAgE,CAC3E,OAAQ,mBACR,OAAQ,oBACR,OAAQ,mBACR,OAAQ,oBACR,OAAQ,WACR,OAAQ,aACR,OAAQ,iBACR,OAAQ,wBACR,OAAQ,uBACR,OAAQ,8BACR,OAAQ,cACR,OAAQ,OACV,EAEaG,EAAmD,CAC9D,mBACA,oBACA,mBACA,mBACF",
|
|
6
|
+
"names": ["uniswap_exports", "__export", "UNISWAP_COMMANDS", "UNISWAP_EXECUTE_ABI", "UNISWAP_EXECUTE_SELECTOR", "UNISWAP_SWAP_COMMANDS", "UniswapSupportedCommand", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},U=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of I(e))!k.call(r,a)&&a!==t&&l(r,a,{get:()=>e[a],enumerable:!(n=y(e,a))||n.enumerable});return r};var N=r=>U(l({},"__esModule",{value:!0}),r),h=(r,e,t,n)=>{for(var a=n>1?void 0:n?y(e,t):e,o=r.length-1,i;o>=0;o--)(i=r[o])&&(a=(n?i(e,t,a):i(a))||a);return n&&a&&l(e,t,a),a},f=(r,e)=>(t,n)=>e(t,n,r);var v={};E(v,{UniswapContextLoader:()=>p});module.exports=N(v);var m=require("@ledgerhq/device-management-kit"),D=require("ethers"),S=require("inversify"),u=require("purify-ts"),C=require("../../shared/model/ClearSignContext"),w=require("../../token/di/tokenTypes"),c=require("../../uniswap/constants/uniswap"),T=require("../../uniswap/di/uniswapTypes");const b=[C.ClearSignContextType.TOKEN];let p=class{constructor(e,t){this.commandDecoderDataSource=e;this.tokenDataSource=t}canHandle(e,t){return typeof e=="object"&&e!==null&&"data"in e&&"selector"in e&&"chainId"in e&&typeof e.chainId=="number"&&(0,m.isHexaString)(e.data)&&e.data!=="0x"&&(0,m.isHexaString)(e.selector)&&e.selector===c.UNISWAP_EXECUTE_SELECTOR&&b.every(n=>t.includes(n))}async load(e){const{data:t,chainId:n}=e;return await this._extractClearSignContexts(t,n)}async _extractClearSignContexts(e,t){try{const a=new D.Interface(c.UNISWAP_EXECUTE_ABI).parseTransaction({data:e}),o=a?.args[0],i=a?.args[1];if(!(0,m.isHexaString)(o)||!this._isHexaStringArray(i))return[];const g=this._extractCommands(o).orDefault([]);if(o.length===0||i.length!==g.length)return[];const x=g.reduce((s,d,H)=>{const P=i[H],A=this.commandDecoderDataSource.decode(d,P,t);return s.push([d,A]),s},[]);if(!this._isChainingSwapSupported(x))return[];const _=[...new Set(x.flatMap(([,s])=>s))];return(await Promise.all(_.map(s=>this.tokenDataSource.getTokenInfosPayload({address:s,chainId:t})))).map(s=>s.caseOf({Left:d=>({type:C.ClearSignContextType.ERROR,error:d}),Right:d=>({type:C.ClearSignContextType.TOKEN,payload:d})}))}catch{return[]}}_extractCommands(e){return u.Maybe.fromNullable(e.slice(2).match(/../g)).map(t=>t.map(n=>`0x${n}`)).map(t=>t.map(n=>c.UNISWAP_COMMANDS[n])).chain(t=>t.every(n=>n!==void 0)?u.Maybe.of(t):u.Nothing)}_isChainingSwapSupported(e){let t,n;for(const[a,o]of e){if(!c.UNISWAP_SWAP_COMMANDS.includes(a))continue;const i=a.slice(0,2);if(t&&(t!==o[0]||n!==i))return!1;t=o[o.length-1],n=i}return!0}_isHexaStringArray(e){return Array.isArray(e)&&e.every(t=>typeof t=="string"&&(0,m.isHexaString)(t))}};p=h([(0,S.injectable)(),f(0,(0,S.inject)(T.uniswapTypes.CommandDecoderDataSource)),f(1,(0,S.inject)(w.tokenTypes.TokenDataSource))],p);0&&(module.exports={UniswapContextLoader});
|
|
2
2
|
//# sourceMappingURL=UniswapContextLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/uniswap/domain/UniswapContextLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n HexaString,\n hexaStringToBuffer,\n isHexaString,\n} from \"@ledgerhq/device-management-kit\";\nimport { Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport {\n UNISWAP_PLUGIN_NAME,\n UNISWAP_PLUGIN_SIGNATURE,\n} from \"@/uniswap/constants/plugin\";\nimport {\n UNISWAP_COMMANDS,\n UNISWAP_EXECUTE_ABI,\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_SWAP_COMMANDS,\n UNISWAP_UNIVERSAL_ROUTER_ADDRESS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\nexport type UniswapContextInput = {\n to: HexaString;\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.TOKEN,\n];\n\n@injectable()\nexport class UniswapContextLoader\n implements ContextLoader<UniswapContextInput>\n{\n constructor(\n @inject(uniswapTypes.CommandDecoderDataSource)\n private commandDecoderDataSource: CommandDecoderDataSource,\n @inject(tokenTypes.TokenDataSource)\n private tokenDataSource: TokenDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is UniswapContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"to\" in input &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.data) &&\n input.data !== \"0x\" &&\n isHexaString(input.selector) &&\n input.selector === UNISWAP_EXECUTE_SELECTOR &&\n isHexaString(input.to) &&\n input.to === UNISWAP_UNIVERSAL_ROUTER_ADDRESS &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: UniswapContextInput): Promise<ClearSignContext[]> {\n const { data, chainId } = input;\n\n const externalPluginContext = this._buildUniswapPluginCommandData();\n const tokenContexts = await this._extractClearSignContexts(data, chainId);\n\n if (tokenContexts.length > 0)\n return [externalPluginContext, ...tokenContexts];\n\n return [];\n }\n\n /**\n * Constructs the external plugin context for Uniswap external plugin command.\n *\n * @private\n * @returns {ClearSignContext} - The generated external plugin context.\n */\n private _buildUniswapPluginCommandData(): ClearSignContext {\n const buffer = new ByteArrayBuilder()\n .add8BitUIntToData(UNISWAP_PLUGIN_NAME.length)\n .addAsciiStringToData(UNISWAP_PLUGIN_NAME)\n .addBufferToData(hexaStringToBuffer(UNISWAP_UNIVERSAL_ROUTER_ADDRESS)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_EXECUTE_SELECTOR)!)\n .addBufferToData(hexaStringToBuffer(UNISWAP_PLUGIN_SIGNATURE)!)\n .build();\n\n return {\n type: ClearSignContextType.EXTERNAL_PLUGIN,\n payload: bufferToHexaString(buffer, false),\n };\n }\n\n /**\n * Extracts and decodes the clear sign contexts from a Uniswap calldata transaction.\n *\n * This function:\n * - Parses the calldata using the Uniswap `execute` function signature.\n * - Extracts and validates the `commands` and `inputs`.\n * - Decodes the commands and ensures they match the number of inputs.\n * - Extracts addresses used in the transaction and verifies if chaining swaps are supported.\n * - Fetches token information for unique addresses.\n * - Returns an array of `ClearSignContext` objects representing either token data or errors.\n *\n * @private\n * @param {HexaString} calldata - The raw calldata of the Uniswap transaction.\n * @param {number} chainId - The blockchain chain ID where the transaction is being executed.\n * @returns {Promise<ClearSignContext[]>} - A promise resolving to an array of clear sign contexts.\n */\n private async _extractClearSignContexts(\n calldata: HexaString,\n chainId: number,\n ): Promise<ClearSignContext[]> {\n try {\n const iface = new Interface(UNISWAP_EXECUTE_ABI);\n\n const tx = iface.parseTransaction({ data: calldata });\n const commands: unknown = tx?.args[0];\n const inputs: unknown = tx?.args[1];\n\n if (!isHexaString(commands) || !this._isHexaStringArray(inputs)) {\n return [];\n }\n\n const decodedCommands = this._extractCommands(commands).orDefault([]);\n if (commands.length === 0 || inputs.length !== decodedCommands.length) {\n // Invalid commands or inputs\n return [];\n }\n\n const addressesByCommand = decodedCommands.reduce(\n (acc, command, index) => {\n const input = inputs[index]!;\n const decoded: HexaString[] = this.commandDecoderDataSource.decode(\n command,\n input,\n chainId,\n );\n\n acc.push([command, decoded]);\n\n return acc;\n },\n [] as [UniswapSupportedCommand, HexaString[]][],\n );\n\n if (!this._isChainingSwapSupported(addressesByCommand)) {\n return [];\n }\n\n const uniqueAddresses = [\n ...new Set(addressesByCommand.flatMap(([, addresses]) => addresses)),\n ];\n\n const tokensPayload = await Promise.all(\n uniqueAddresses.map((address) =>\n this.tokenDataSource.getTokenInfosPayload({ address, chainId }),\n ),\n );\n\n return tokensPayload.map((either) =>\n either.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n } catch (_) {\n return [];\n }\n }\n\n /**\n * Extracts Uniswap-supported commands from a hexadecimal string.\n * Each command is represented by one byte (2 hex characters), and this function:\n * - Maps each command to a known Uniswap command.\n * - Returns `Nothing` if any extracted command is unsupported.\n *\n * @private\n * @param {HexaString} hex - A hexadecimal string representing commands.\n * @returns {Maybe<UniswapSupportedCommand[]>} - A `Maybe` containing an array of recognized commands, or `Nothing` if any command is unsupported.\n *\n * @example\n * // Valid command extraction\n * _extractCommands('0x0008');\n * // Returns: Just(['0x00', '0x08'])\n *\n * @example\n * // Contains an unsupported command (0x05 is not supported)\n * _extractCommands('0x0005');\n * // Returns: Nothing\n *\n * @example\n * // Empty or invalid input\n * _extractCommands('0x');\n * // Returns: Nothing\n */\n private _extractCommands(hex: HexaString): Maybe<UniswapSupportedCommand[]> {\n return Maybe.fromNullable(hex.slice(2).match(/../g))\n .map((bytes) => bytes.map((b) => `0x${b}` as HexaString))\n .map((hexBytes) => hexBytes.map((b) => UNISWAP_COMMANDS[b]))\n .chain((commands) =>\n commands.every((command) => command !== undefined)\n ? Maybe.of(commands as UniswapSupportedCommand[])\n : Nothing,\n );\n }\n\n /**\n * Checks if the provided swap commands can be chained together.\n * A valid chain requires that:\n * - The output asset of the previous swap matches the input asset of the next swap.\n * - The pool version remains consistent across swaps.\n *\n * @private\n * @param {Array<[UniswapSupportedCommand, HexaString[]]>} data - An array of tuples containing a swap command and associated addresses.\n * @returns {boolean} - Returns `true` if the swap commands form a valid chain, otherwise `false`.\n *\n * @example\n * // Valid chaining: same output/input asset and pool version\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x08', ['0xDEF', '0x123']]\n * ]);\n * // Returns: true\n *\n * @example\n * // Invalid chaining: different pool versions\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x01', ['0xDEF', '0x123']]\n * ]);\n * // Returns: false\n *\n * @example\n * // Invalid chaining: output does not match next input\n * _isChainingSwapSupported([\n * ['0x01A1', ['0xABC', '0xDEF']],\n * ['0x01B2', ['0xXYZ', '0x123']]\n * ]);\n * // Returns: false\n */\n private _isChainingSwapSupported(\n data: [UniswapSupportedCommand, HexaString[]][],\n ): boolean {\n let lastAsset: HexaString | undefined = undefined;\n let lastPoolVersion: string | undefined = undefined;\n\n for (const [command, addresses] of data) {\n if (!UNISWAP_SWAP_COMMANDS.includes(command)) continue; // Ignore non-swap commands\n\n const poolVersion = command.slice(0, 2);\n\n if (\n lastAsset &&\n (lastAsset !== addresses[0] || lastPoolVersion !== poolVersion)\n ) {\n // Invalid chaining, return empty array\n return false;\n }\n\n // update last asset and pool version\n lastAsset = addresses[addresses.length - 1];\n lastPoolVersion = poolVersion;\n }\n\n return true;\n }\n\n /**\n * Checks if a given value is an array of hexadecimal strings.\n *\n * @private\n * @param {unknown} array - The value to check.\n * @returns {array is HexaString[]} - `true` if the value is an array of hexadecimal strings, otherwise `false`.\n */\n private _isHexaStringArray(array: unknown): array is HexaString[] {\n return (\n Array.isArray(array) &&\n array.every((item) => typeof item === \"string\" && isHexaString(item))\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,
|
|
6
|
-
"names": ["UniswapContextLoader_exports", "__export", "UniswapContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_ClearSignContext", "import_tokenTypes", "
|
|
4
|
+
"sourcesContent": ["import { HexaString, isHexaString } from \"@ledgerhq/device-management-kit\";\nimport { Interface } from \"ethers\";\nimport { inject, injectable } from \"inversify\";\nimport { Maybe, Nothing } from \"purify-ts\";\n\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { tokenTypes } from \"@/token/di/tokenTypes\";\nimport {\n UNISWAP_COMMANDS,\n UNISWAP_EXECUTE_ABI,\n UNISWAP_EXECUTE_SELECTOR,\n UNISWAP_SWAP_COMMANDS,\n UniswapSupportedCommand,\n} from \"@/uniswap/constants/uniswap\";\nimport { type CommandDecoderDataSource } from \"@/uniswap/data/CommandDecoderDataSource\";\nimport { uniswapTypes } from \"@/uniswap/di/uniswapTypes\";\n\nexport type UniswapContextInput = {\n data: HexaString;\n selector: HexaString;\n chainId: number;\n};\n\nconst SUPPORTED_TYPES: ClearSignContextType[] = [ClearSignContextType.TOKEN];\n\n@injectable()\nexport class UniswapContextLoader\n implements ContextLoader<UniswapContextInput>\n{\n constructor(\n @inject(uniswapTypes.CommandDecoderDataSource)\n private commandDecoderDataSource: CommandDecoderDataSource,\n @inject(tokenTypes.TokenDataSource)\n private tokenDataSource: TokenDataSource,\n ) {}\n\n canHandle(\n input: unknown,\n expectedTypes: ClearSignContextType[],\n ): input is UniswapContextInput {\n return (\n typeof input === \"object\" &&\n input !== null &&\n \"data\" in input &&\n \"selector\" in input &&\n \"chainId\" in input &&\n typeof input.chainId === \"number\" &&\n isHexaString(input.data) &&\n input.data !== \"0x\" &&\n isHexaString(input.selector) &&\n input.selector === UNISWAP_EXECUTE_SELECTOR &&\n SUPPORTED_TYPES.every((type) => expectedTypes.includes(type))\n );\n }\n\n async load(input: UniswapContextInput): Promise<ClearSignContext[]> {\n const { data, chainId } = input;\n return await this._extractClearSignContexts(data, chainId);\n }\n\n /**\n * Extracts and decodes the clear sign contexts from a Uniswap calldata transaction.\n *\n * This function:\n * - Parses the calldata using the Uniswap `execute` function signature.\n * - Extracts and validates the `commands` and `inputs`.\n * - Decodes the commands and ensures they match the number of inputs.\n * - Extracts addresses used in the transaction and verifies if chaining swaps are supported.\n * - Fetches token information for unique addresses.\n * - Returns an array of `ClearSignContext` objects representing either token data or errors.\n *\n * @private\n * @param {HexaString} calldata - The raw calldata of the Uniswap transaction.\n * @param {number} chainId - The blockchain chain ID where the transaction is being executed.\n * @returns {Promise<ClearSignContext[]>} - A promise resolving to an array of clear sign contexts.\n */\n private async _extractClearSignContexts(\n calldata: HexaString,\n chainId: number,\n ): Promise<ClearSignContext[]> {\n try {\n const iface = new Interface(UNISWAP_EXECUTE_ABI);\n\n const tx = iface.parseTransaction({ data: calldata });\n const commands: unknown = tx?.args[0];\n const inputs: unknown = tx?.args[1];\n\n if (!isHexaString(commands) || !this._isHexaStringArray(inputs)) {\n return [];\n }\n\n const decodedCommands = this._extractCommands(commands).orDefault([]);\n if (commands.length === 0 || inputs.length !== decodedCommands.length) {\n // Invalid commands or inputs\n return [];\n }\n\n const addressesByCommand = decodedCommands.reduce(\n (acc, command, index) => {\n const input = inputs[index]!;\n const decoded: HexaString[] = this.commandDecoderDataSource.decode(\n command,\n input,\n chainId,\n );\n\n acc.push([command, decoded]);\n\n return acc;\n },\n [] as [UniswapSupportedCommand, HexaString[]][],\n );\n\n if (!this._isChainingSwapSupported(addressesByCommand)) {\n return [];\n }\n\n const uniqueAddresses = [\n ...new Set(addressesByCommand.flatMap(([, addresses]) => addresses)),\n ];\n\n const tokensPayload = await Promise.all(\n uniqueAddresses.map((address) =>\n this.tokenDataSource.getTokenInfosPayload({ address, chainId }),\n ),\n );\n\n return tokensPayload.map((either) =>\n either.caseOf<ClearSignContext>({\n Left: (error) => ({ type: ClearSignContextType.ERROR, error }),\n Right: (payload) => ({ type: ClearSignContextType.TOKEN, payload }),\n }),\n );\n } catch (_) {\n return [];\n }\n }\n\n /**\n * Extracts Uniswap-supported commands from a hexadecimal string.\n * Each command is represented by one byte (2 hex characters), and this function:\n * - Maps each command to a known Uniswap command.\n * - Returns `Nothing` if any extracted command is unsupported.\n *\n * @private\n * @param {HexaString} hex - A hexadecimal string representing commands.\n * @returns {Maybe<UniswapSupportedCommand[]>} - A `Maybe` containing an array of recognized commands, or `Nothing` if any command is unsupported.\n *\n * @example\n * // Valid command extraction\n * _extractCommands('0x0008');\n * // Returns: Just(['0x00', '0x08'])\n *\n * @example\n * // Contains an unsupported command (0x05 is not supported)\n * _extractCommands('0x0005');\n * // Returns: Nothing\n *\n * @example\n * // Empty or invalid input\n * _extractCommands('0x');\n * // Returns: Nothing\n */\n private _extractCommands(hex: HexaString): Maybe<UniswapSupportedCommand[]> {\n return Maybe.fromNullable(hex.slice(2).match(/../g))\n .map((bytes) => bytes.map((b) => `0x${b}` as HexaString))\n .map((hexBytes) => hexBytes.map((b) => UNISWAP_COMMANDS[b]))\n .chain((commands) =>\n commands.every((command) => command !== undefined)\n ? Maybe.of(commands as UniswapSupportedCommand[])\n : Nothing,\n );\n }\n\n /**\n * Checks if the provided swap commands can be chained together.\n * A valid chain requires that:\n * - The output asset of the previous swap matches the input asset of the next swap.\n * - The pool version remains consistent across swaps.\n *\n * @private\n * @param {Array<[UniswapSupportedCommand, HexaString[]]>} data - An array of tuples containing a swap command and associated addresses.\n * @returns {boolean} - Returns `true` if the swap commands form a valid chain, otherwise `false`.\n *\n * @example\n * // Valid chaining: same output/input asset and pool version\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x08', ['0xDEF', '0x123']]\n * ]);\n * // Returns: true\n *\n * @example\n * // Invalid chaining: different pool versions\n * _isChainingSwapSupported([\n * ['0x08', ['0xABC', '0xDEF']],\n * ['0x01', ['0xDEF', '0x123']]\n * ]);\n * // Returns: false\n *\n * @example\n * // Invalid chaining: output does not match next input\n * _isChainingSwapSupported([\n * ['0x01A1', ['0xABC', '0xDEF']],\n * ['0x01B2', ['0xXYZ', '0x123']]\n * ]);\n * // Returns: false\n */\n private _isChainingSwapSupported(\n data: [UniswapSupportedCommand, HexaString[]][],\n ): boolean {\n let lastAsset: HexaString | undefined = undefined;\n let lastPoolVersion: string | undefined = undefined;\n\n for (const [command, addresses] of data) {\n if (!UNISWAP_SWAP_COMMANDS.includes(command)) continue; // Ignore non-swap commands\n\n const poolVersion = command.slice(0, 2);\n\n if (\n lastAsset &&\n (lastAsset !== addresses[0] || lastPoolVersion !== poolVersion)\n ) {\n // Invalid chaining, return empty array\n return false;\n }\n\n // update last asset and pool version\n lastAsset = addresses[addresses.length - 1];\n lastPoolVersion = poolVersion;\n }\n\n return true;\n }\n\n /**\n * Checks if a given value is an array of hexadecimal strings.\n *\n * @private\n * @param {unknown} array - The value to check.\n * @returns {array is HexaString[]} - `true` if the value is an array of hexadecimal strings, otherwise `false`.\n */\n private _isHexaStringArray(array: unknown): array is HexaString[] {\n return (\n Array.isArray(array) &&\n array.every((item) => typeof item === \"string\" && isHexaString(item))\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyC,2CACzCC,EAA0B,kBAC1BC,EAAmC,qBACnCC,EAA+B,qBAG/BC,EAGO,2CAEPC,EAA2B,iCAC3BC,EAMO,uCAEPC,EAA6B,qCAQ7B,MAAMC,EAA0C,CAAC,uBAAqB,KAAK,EAGpE,IAAMC,EAAN,KAEP,CACE,YAEUC,EAEAC,EACR,CAHQ,8BAAAD,EAEA,qBAAAC,CACP,CAEH,UACEC,EACAC,EAC8B,CAC9B,OACE,OAAOD,GAAU,UACjBA,IAAU,MACV,SAAUA,GACV,aAAcA,GACd,YAAaA,GACb,OAAOA,EAAM,SAAY,aACzB,gBAAaA,EAAM,IAAI,GACvBA,EAAM,OAAS,SACf,gBAAaA,EAAM,QAAQ,GAC3BA,EAAM,WAAa,4BACnBJ,EAAgB,MAAOM,GAASD,EAAc,SAASC,CAAI,CAAC,CAEhE,CAEA,MAAM,KAAKF,EAAyD,CAClE,KAAM,CAAE,KAAAG,EAAM,QAAAC,CAAQ,EAAIJ,EAC1B,OAAO,MAAM,KAAK,0BAA0BG,EAAMC,CAAO,CAC3D,CAkBA,MAAc,0BACZC,EACAD,EAC6B,CAC7B,GAAI,CAGF,MAAME,EA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AAKA,CAAC,EAAgB,CAAC,EACvD,IAAKC,GAAaA,EAAS,IAAKD,GAAM,mBAAiBA,CAAC,CAAC,CAAC,EAC1D,MAAOhB,GACNA,EAAS,MAAOK,GAAYA,IAAY,MAAS,EAC7C,QAAM,GAAGL,CAAqC,EAC9C,SACN,CACJ,CAoCQ,yBACNJ,EACS,CACT,IAAIsB,EACAC,EAEJ,SAAW,CAACd,EAASI,CAAS,IAAKb,EAAM,CACvC,GAAI,CAAC,wBAAsB,SAASS,CAAO,EAAG,SAE9C,MAAMe,EAAcf,EAAQ,MAAM,EAAG,CAAC,EAEtC,GACEa,IACCA,IAAcT,EAAU,CAAC,GAAKU,IAAoBC,GAGnD,MAAO,GAITF,EAAYT,EAAUA,EAAU,OAAS,CAAC,EAC1CU,EAAkBC,CACpB,CAEA,MAAO,EACT,CASQ,mBAAmBC,EAAuC,CAChE,OACE,MAAM,QAAQA,CAAK,GACnBA,EAAM,MAAOC,GAAS,OAAOA,GAAS,aAAY,gBAAaA,CAAI,CAAC,CAExE,CACF,EA9NahC,EAANiC,EAAA,IADN,cAAW,EAKPC,EAAA,eAAO,eAAa,wBAAwB,GAE5CA,EAAA,eAAO,aAAW,eAAe,IANzBlC",
|
|
6
|
+
"names": ["UniswapContextLoader_exports", "__export", "UniswapContextLoader", "__toCommonJS", "import_device_management_kit", "import_ethers", "import_inversify", "import_purify_ts", "import_ClearSignContext", "import_tokenTypes", "import_uniswap", "import_uniswapTypes", "SUPPORTED_TYPES", "UniswapContextLoader", "commandDecoderDataSource", "tokenDataSource", "input", "expectedTypes", "type", "data", "chainId", "calldata", "tx", "commands", "inputs", "decodedCommands", "addressesByCommand", "acc", "command", "index", "decoded", "uniqueAddresses", "addresses", "address", "either", "error", "payload", "hex", "bytes", "b", "hexBytes", "lastAsset", "lastPoolVersion", "poolVersion", "array", "item", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|