@ledgerhq/context-module 0.0.0-ledger-button-20250821163751 → 0.0.0-ledger-button-20250905004746
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/src/DefaultContextModule.js +1 -1
- package/lib/cjs/src/DefaultContextModule.js.map +3 -3
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +3 -3
- package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js +2 -0
- package/lib/cjs/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
- package/lib/cjs/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
- package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +2 -0
- package/lib/cjs/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
- package/lib/cjs/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
- package/lib/cjs/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
- package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js +2 -0
- package/lib/cjs/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/cjs/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
- package/lib/cjs/src/index.js +1 -1
- package/lib/cjs/src/index.js.map +2 -2
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
- package/lib/cjs/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
- package/lib/cjs/src/shared/model/ClearSignContext.js +1 -1
- package/lib/cjs/src/shared/model/ClearSignContext.js.map +2 -2
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js +1 -1
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.js.map +1 -1
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js +1 -1
- package/lib/cjs/src/transaction/data/HttpProxyDataSource.test.js.map +1 -1
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js +1 -1
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.js.map +3 -3
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js +1 -1
- package/lib/cjs/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/cjs/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
- package/lib/esm/src/DefaultContextModule.js +1 -1
- package/lib/esm/src/DefaultContextModule.js.map +3 -3
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js +1 -0
- package/lib/esm/src/dynamic-network/data/DynamicNetworkDataSource.js.map +7 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js +2 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.js.map +7 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js +2 -0
- package/lib/esm/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.js.map +7 -0
- package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js +1 -0
- package/lib/esm/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.js.map +7 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js +2 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkModuleFactory.js.map +7 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js +2 -0
- package/lib/esm/src/dynamic-network/di/dynamicNetworkTypes.js.map +7 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js +2 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.js.map +7 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js +2 -0
- package/lib/esm/src/dynamic-network/domain/DynamicNetworkContextLoader.test.js.map +7 -0
- package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js +1 -0
- package/lib/esm/src/dynamic-network/model/DynamicNetworkConfiguration.js.map +7 -0
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js +1 -1
- package/lib/esm/src/external-plugin/domain/ExternalPluginContextLoader.test.js.map +2 -2
- package/lib/esm/src/index.js +1 -1
- package/lib/esm/src/index.js.map +2 -2
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js +1 -1
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.js.map +3 -3
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js +1 -1
- package/lib/esm/src/pki/domain/DefaultPkiCertificateLoader.test.js.map +3 -3
- package/lib/esm/src/shared/model/ClearSignContext.js +1 -1
- package/lib/esm/src/shared/model/ClearSignContext.js.map +2 -2
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js +1 -1
- package/lib/esm/src/transaction/data/HttpProxyDataSource.js.map +1 -1
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js +1 -1
- package/lib/esm/src/transaction/data/HttpProxyDataSource.test.js.map +1 -1
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js +1 -1
- package/lib/esm/src/transaction/domain/TransactionContextLoader.js.map +3 -3
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js +1 -1
- package/lib/esm/src/transaction/domain/TransactionContextLoader.test.js.map +3 -3
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js +1 -1
- package/lib/esm/src/trusted-name/domain/TrustedNameContextLoader.test.js.map +2 -2
- package/lib/types/src/DefaultContextModule.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts +6 -0
- package/lib/types/src/dynamic-network/data/DynamicNetworkDataSource.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts +13 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts +2 -0
- package/lib/types/src/dynamic-network/data/HttpDynamicNetworkDataSource.test.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts +14 -0
- package/lib/types/src/dynamic-network/data/dto/DynamicNetworkApiResponseDto.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts +3 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkModuleFactory.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts +5 -0
- package/lib/types/src/dynamic-network/di/dynamicNetworkTypes.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts +15 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts +2 -0
- package/lib/types/src/dynamic-network/domain/DynamicNetworkContextLoader.test.d.ts.map +1 -0
- package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts +16 -0
- package/lib/types/src/dynamic-network/model/DynamicNetworkConfiguration.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +2 -0
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/pki/domain/DefaultPkiCertificateLoader.d.ts.map +1 -1
- package/lib/types/src/shared/model/ClearSignContext.d.ts +2 -0
- package/lib/types/src/shared/model/ClearSignContext.d.ts.map +1 -1
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts +1 -3
- package/lib/types/src/transaction/domain/TransactionContextLoader.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.ts"],
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { inject, injectable } from \"inversify\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { dynamicNetworkTypes } from \"@/dynamic-network/di/dynamicNetworkTypes\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { ContextLoader } from \"@/shared/domain/ContextLoader\";\nimport {\n ClearSignContext,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport {\n TransactionContext,\n TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\n\nconst NETWORK_SIGNATURE_TAG = \"15\";\n\n@injectable()\nexport class DynamicNetworkContextLoader implements ContextLoader {\n private readonly _networkDataSource: DynamicNetworkDataSource;\n private readonly _config: ContextModuleConfig;\n private readonly _certificateLoader: PkiCertificateLoader;\n\n constructor(\n @inject(dynamicNetworkTypes.DynamicNetworkDataSource)\n networkDataSource: DynamicNetworkDataSource,\n @inject(configTypes.Config)\n config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n certificateLoader: PkiCertificateLoader,\n ) {\n this._networkDataSource = networkDataSource;\n this._config = config;\n this._certificateLoader = certificateLoader;\n }\n\n async load(ctx: TransactionContext): Promise<ClearSignContext[]> {\n if (ctx.deviceModelId === DeviceModelId.NANO_S) return [];\n\n const result = await this._networkDataSource.getDynamicNetworkConfiguration(\n ctx.chainId,\n );\n\n // Fetch certificate for the network configuration upfront\n const certificate = await this._certificateLoader.loadCertificate({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: ctx.deviceModelId,\n });\n\n return result.caseOf({\n Left: () => [],\n Right: (configuration) => {\n const contexts: ClearSignContext[] = [];\n const descriptor = configuration.descriptors[ctx.deviceModelId];\n\n if (!descriptor) {\n return [];\n }\n\n const signature = descriptor.signatures[this._config.cal.mode];\n\n if (!signature) {\n return [];\n }\n\n const configPayload = HexStringUtils.appendSignatureToPayload(\n descriptor.data,\n signature,\n NETWORK_SIGNATURE_TAG,\n );\n\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: configPayload,\n certificate,\n });\n\n // Add icon if available in the descriptor\n if (descriptor.icon) {\n // Icons don't need signatures appended\n contexts.push({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: descriptor.icon,\n });\n }\n\n return contexts;\n },\n });\n }\n\n // Dynamic network context doesn't support field-level loading\n loadField(_field: TransactionFieldContext): Promise<ClearSignContext | null> {\n return Promise.resolve(null);\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,eAAAC,MAAmB,0BAG5B,OAAS,uBAAAC,MAA2B,2CACpC,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAEE,wBAAAC,MACK,kCAKP,OAAS,kBAAAC,MAAsB,gCAE/B,MAAMC,EAAwB,KAGvB,IAAMC,EAAN,KAA2D,CAC/C,mBACA,QACA,mBAEjB,YAEEC,EAEAC,EAEAC,EACA,CACA,KAAK,mBAAqBF,EAC1B,KAAK,QAAUC,EACf,KAAK,mBAAqBC,CAC5B,CAEA,MAAM,KAAKC,EAAsD,CAC/D,GAAIA,EAAI,gBAAkBC,EAAc,OAAQ,MAAO,CAAC,EAExD,MAAMC,EAAS,MAAM,KAAK,mBAAmB,+BAC3CF,EAAI,OACN,EAGMG,EAAc,MAAM,KAAK,mBAAmB,gBAAgB,CAChE,MAAOC,EAAM,WACb,SAAUC,EAAS,QACnB,aAAcL,EAAI,aACpB,CAAC,EAED,OAAOE,EAAO,OAAO,CACnB,KAAM,IAAM,CAAC,EACb,MAAQI,GAAkB,CACxB,MAAMC,EAA+B,CAAC,EAChCC,EAAaF,EAAc,YAAYN,EAAI,aAAa,EAE9D,GAAI,CAACQ,EACH,MAAO,CAAC,EAGV,MAAMC,EAAYD,EAAW,WAAW,KAAK,QAAQ,IAAI,IAAI,EAE7D,GAAI,CAACC,EACH,MAAO,CAAC,EAGV,MAAMC,EAAgBC,EAAe,yBACnCH,EAAW,KACXC,EACAd,CACF,EAEA,OAAAY,EAAS,KAAK,CACZ,KAAMK,EAAqB,gBAC3B,QAASF,EACT,YAAAP,CACF,CAAC,EAGGK,EAAW,MAEbD,EAAS,KAAK,CACZ,KAAMK,EAAqB,qBAC3B,QAASJ,EAAW,IACtB,CAAC,EAGID,CACT,CACF,CAAC,CACH,CAGA,UAAUM,EAAmE,CAC3E,OAAO,QAAQ,QAAQ,IAAI,CAC7B,CACF,EA9EajB,EAANkB,EAAA,CADNC,EAAW,EAOPC,EAAA,EAAAC,EAAOC,EAAoB,wBAAwB,GAEnDF,EAAA,EAAAC,EAAOE,EAAY,MAAM,GAEzBH,EAAA,EAAAC,EAAOG,EAAS,oBAAoB,IAV5BxB",
|
|
6
|
+
"names": ["DeviceModelId", "inject", "injectable", "configTypes", "dynamicNetworkTypes", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "HexStringUtils", "NETWORK_SIGNATURE_TAG", "DynamicNetworkContextLoader", "networkDataSource", "config", "certificateLoader", "ctx", "DeviceModelId", "result", "certificate", "KeyId", "KeyUsage", "configuration", "contexts", "descriptor", "signature", "configPayload", "HexStringUtils", "ClearSignContextType", "_field", "__decorateClass", "injectable", "__decorateParam", "inject", "dynamicNetworkTypes", "configTypes", "pkiTypes"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{DeviceModelId as e}from"@ledgerhq/device-management-kit";import{Left as m,Right as s}from"purify-ts";import{DynamicNetworkContextLoader as f}from"../../dynamic-network/domain/DynamicNetworkContextLoader";import{KeyId as g}from"../../pki/model/KeyId";import{KeyUsage as x}from"../../pki/model/KeyUsage";import{ClearSignContextType as p}from"../../shared/model/ClearSignContext";describe("DynamicNetworkContextLoader",()=>{const a={getDynamicNetworkConfiguration:vi.fn()},l={cal:{url:"https://crypto-assets-service.api.ledger.com",mode:"prod",branch:"main"},web3checks:{url:"https://web3checks.api.ledger.com"},metadataServiceDomain:{url:"https://metadata.api.ledger.com"},defaultLoaders:!0,customLoaders:[]},d={loadCertificate:vi.fn()},u={keyUsageNumber:1,payload:new Uint8Array([1,2,3])},n=new f(a,l,d),t=o=>({data:"",descriptorType:"",descriptorVersion:"",signatures:{prod:"",test:""},icon:void 0,...o});beforeEach(()=>{vi.restoreAllMocks(),vi.spyOn(d,"loadCertificate").mockResolvedValue(u)}),describe("load function",()=>{it("should return empty array when network data source returns error",async()=>{const o={chainId:1,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(m(new Error("Network error")));const i=await n.load(o);expect(i).toEqual([]),expect(a.getDynamicNetworkConfiguration).toHaveBeenCalledWith(1)}),it("should return empty array when descriptor for device model is not found",async()=>{const o={chainId:1,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0})}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const r=await n.load(o);expect(r).toEqual([])}),it("should return empty array when signature for mode is not found",async()=>{const o={chainId:1,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:t({data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{test:"test-sig"},icon:void 0})}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const r=await n.load(o);expect(r).toEqual([])}),it("should return context with network configuration when all data is available",async()=>{const o={chainId:137,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"polygon",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101080201015101012308000000000000008952",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d",test:"test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const r=await n.load(o);expect(r).toHaveLength(1),expect(r[0]).toMatchObject({type:p.DYNAMIC_NETWORK,payload:expect.stringContaining("0x0101080201015101012308000000000000008952"),certificate:u}),expect(d.loadCertificate).toHaveBeenCalledWith({keyId:g.CalNetwork,keyUsage:x.Network,targetDevice:e.STAX})}),it("should include icon context when icon is available",async()=>{const o={chainId:1,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:"icon-hex-data"}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const r=await n.load(o);expect(r).toHaveLength(2),expect(r[0]).toMatchObject({type:p.DYNAMIC_NETWORK,payload:expect.any(String),certificate:u}),expect(r[1]).toMatchObject({type:p.DYNAMIC_NETWORK_ICON,payload:"icon-hex-data"})}),it("should handle multiple device models correctly",async()=>{const o={chainId:1,deviceModelId:e.FLEX,to:"0x123",data:"0x456",selector:"0x789"},i={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:{data:"0xFLEX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"flex-prod-sig",test:"flex-test-sig"},icon:void 0},[e.STAX]:{data:"0xSTAX",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"stax-prod-sig",test:"stax-test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(i));const r=await n.load(o);expect(r).toHaveLength(1);const c=r[0];c&&"payload"in c&&(expect(c.payload).toContain("0xFLEX"),expect(c.payload).toContain("flex-prod-sig"))}),it("should use test mode signature when configured",async()=>{const o=new f(a,{...l,cal:{...l.cal,mode:"test"}},d),i={chainId:1,deviceModelId:e.STAX,to:"0x123",data:"0x456",selector:"0x789"},r={id:"ethereum",descriptors:{[e.APEX]:t(),[e.NANO_S]:t(),[e.NANO_SP]:t(),[e.NANO_X]:t(),[e.FLEX]:t(),[e.STAX]:{data:"0x0101",descriptorType:"network",descriptorVersion:"v1",signatures:{prod:"prod-sig",test:"test-sig"},icon:void 0}}};vi.spyOn(a,"getDynamicNetworkConfiguration").mockResolvedValue(s(r));const c=await o.load(i);expect(c).toHaveLength(1);const y=c[0];y&&"payload"in y&&expect(y.payload).toContain("test-sig")})}),describe("loadField function",()=>{it("should always return null",async()=>{const o={type:p.TOKEN,chainId:1,address:"0x123"},i=await n.loadField(o);expect(i).toBeNull()})})});
|
|
2
|
+
//# sourceMappingURL=DynamicNetworkContextLoader.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/dynamic-network/domain/DynamicNetworkContextLoader.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { type DynamicNetworkDataSource } from \"@/dynamic-network/data/DynamicNetworkDataSource\";\nimport { DynamicNetworkContextLoader } from \"@/dynamic-network/domain/DynamicNetworkContextLoader\";\nimport {\n type DynamicNetworkConfiguration,\n type DynamicNetworkDescriptor,\n} from \"@/dynamic-network/model/DynamicNetworkConfiguration\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { ClearSignContextType } from \"@/shared/model/ClearSignContext\";\nimport {\n type TransactionContext,\n type TransactionFieldContext,\n} from \"@/shared/model/TransactionContext\";\n\ndescribe(\"DynamicNetworkContextLoader\", () => {\n const mockNetworkDataSource: DynamicNetworkDataSource = {\n getDynamicNetworkConfiguration: vi.fn(),\n };\n\n const mockConfig: ContextModuleConfig = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com\",\n mode: \"prod\",\n branch: \"main\",\n },\n web3checks: {\n url: \"https://web3checks.api.ledger.com\",\n },\n metadataServiceDomain: {\n url: \"https://metadata.api.ledger.com\",\n },\n defaultLoaders: true,\n customLoaders: [],\n };\n\n const mockCertificateLoader: PkiCertificateLoader = {\n loadCertificate: vi.fn(),\n };\n\n const mockCertificate: PkiCertificate = {\n keyUsageNumber: 1,\n payload: new Uint8Array([0x01, 0x02, 0x03]),\n };\n\n const loader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n mockConfig,\n mockCertificateLoader,\n );\n\n // Helper function to create a mock NetworkDescriptor\n const createMockDescriptor = (\n partial?: Partial<DynamicNetworkDescriptor>,\n ): DynamicNetworkDescriptor => ({\n data: \"\",\n descriptorType: \"\",\n descriptorVersion: \"\",\n signatures: {\n prod: \"\",\n test: \"\",\n },\n icon: undefined,\n ...partial,\n });\n\n beforeEach(() => {\n vi.restoreAllMocks();\n vi.spyOn(mockCertificateLoader, \"loadCertificate\").mockResolvedValue(\n mockCertificate,\n );\n });\n\n describe(\"load function\", () => {\n it(\"should return empty array when network data source returns error\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Left(new Error(\"Network error\")));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n expect(\n mockNetworkDataSource.getDynamicNetworkConfiguration,\n ).toHaveBeenCalledWith(1);\n });\n\n it(\"should return empty array when descriptor for device model is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n // STAX descriptor is intentionally missing\n [DeviceModelId.FLEX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n }),\n } as Record<DeviceModelId, DynamicNetworkDescriptor>,\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return empty array when signature for mode is not found\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: createMockDescriptor({\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n test: \"test-sig\",\n // Missing prod signature - intentionally partial\n } as { prod: string; test: string },\n icon: undefined,\n }),\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return context with network configuration when all data is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 137,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"polygon\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101080201015101012308000000000000008952\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"3045022100cf42c039c16fc95dc97c09f15cdd93bed0e63ee45cf5c38c2b30bb8a3bc17f8d022053a96c9e51695c3c1c1a31f5cbf84bd6febadc97f4bb02bdc67cf3e24ad0c32d\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.stringContaining(\n \"0x0101080201015101012308000000000000008952\",\n ),\n certificate: mockCertificate,\n });\n expect(mockCertificateLoader.loadCertificate).toHaveBeenCalledWith({\n keyId: KeyId.CalNetwork,\n keyUsage: KeyUsage.Network,\n targetDevice: DeviceModelId.STAX,\n });\n });\n\n it(\"should include icon context when icon is available\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: \"icon-hex-data\",\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(2);\n expect(result[0]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK,\n payload: expect.any(String),\n certificate: mockCertificate,\n });\n expect(result[1]).toMatchObject({\n type: ClearSignContextType.DYNAMIC_NETWORK_ICON,\n payload: \"icon-hex-data\",\n });\n });\n\n it(\"should handle multiple device models correctly\", async () => {\n // GIVEN\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.FLEX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: {\n data: \"0xFLEX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"flex-prod-sig\",\n test: \"flex-test-sig\",\n },\n icon: undefined,\n },\n [DeviceModelId.STAX]: {\n data: \"0xSTAX\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"stax-prod-sig\",\n test: \"stax-test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"0xFLEX\");\n expect(context.payload).toContain(\"flex-prod-sig\");\n }\n });\n\n it(\"should use test mode signature when configured\", async () => {\n // GIVEN\n const testModeLoader = new DynamicNetworkContextLoader(\n mockNetworkDataSource,\n { ...mockConfig, cal: { ...mockConfig.cal, mode: \"test\" } },\n mockCertificateLoader,\n );\n const transaction: TransactionContext = {\n chainId: 1,\n deviceModelId: DeviceModelId.STAX,\n to: \"0x123\",\n data: \"0x456\",\n selector: \"0x789\",\n };\n const networkConfig: DynamicNetworkConfiguration = {\n id: \"ethereum\",\n descriptors: {\n [DeviceModelId.APEX]: createMockDescriptor(),\n [DeviceModelId.NANO_S]: createMockDescriptor(),\n [DeviceModelId.NANO_SP]: createMockDescriptor(),\n [DeviceModelId.NANO_X]: createMockDescriptor(),\n [DeviceModelId.FLEX]: createMockDescriptor(),\n [DeviceModelId.STAX]: {\n data: \"0x0101\",\n descriptorType: \"network\",\n descriptorVersion: \"v1\",\n signatures: {\n prod: \"prod-sig\",\n test: \"test-sig\",\n },\n icon: undefined,\n },\n },\n };\n vi.spyOn(\n mockNetworkDataSource,\n \"getDynamicNetworkConfiguration\",\n ).mockResolvedValue(Right(networkConfig));\n\n // WHEN\n const result = await testModeLoader.load(transaction);\n\n // THEN\n expect(result).toHaveLength(1);\n const context = result[0];\n if (context && \"payload\" in context) {\n expect(context.payload).toContain(\"test-sig\");\n }\n });\n });\n\n describe(\"loadField function\", () => {\n it(\"should always return null\", async () => {\n // GIVEN\n const field: TransactionFieldContext = {\n type: ClearSignContextType.TOKEN,\n chainId: 1,\n address: \"0x123\",\n };\n\n // WHEN\n const result = await loader.loadField(field);\n\n // THEN\n expect(result).toBeNull();\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,kCAC9B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAI5B,OAAS,+BAAAC,MAAmC,uDAM5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAEzB,OAAS,wBAAAC,MAA4B,kCAMrC,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAkD,CACtD,+BAAgC,GAAG,GAAG,CACxC,EAEMC,EAAkC,CACtC,IAAK,CACH,IAAK,+CACL,KAAM,OACN,OAAQ,MACV,EACA,WAAY,CACV,IAAK,mCACP,EACA,sBAAuB,CACrB,IAAK,iCACP,EACA,eAAgB,GAChB,cAAe,CAAC,CAClB,EAEMC,EAA8C,CAClD,gBAAiB,GAAG,GAAG,CACzB,EAEMC,EAAkC,CACtC,eAAgB,EAChB,QAAS,IAAI,WAAW,CAAC,EAAM,EAAM,CAAI,CAAC,CAC5C,EAEMC,EAAS,IAAIR,EACjBI,EACAC,EACAC,CACF,EAGMG,EACJC,IAC8B,CAC9B,KAAM,GACN,eAAgB,GAChB,kBAAmB,GACnB,WAAY,CACV,KAAM,GACN,KAAM,EACR,EACA,KAAM,OACN,GAAGA,CACL,GAEA,WAAW,IAAM,CACf,GAAG,gBAAgB,EACnB,GAAG,MAAMJ,EAAuB,iBAAiB,EAAE,kBACjDC,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AAE,kBAAkBL,EAAMc,CAAa,CAAC,EAGxC,MAAMD,EAAS,MAAMG,EAAe,KAAKJ,CAAW,EAGpD,OAAOC,CAAM,EAAE,aAAa,CAAC,EAC7B,MAAME,EAAUF,EAAO,CAAC,EACpBE,GAAW,YAAaA,GAC1B,OAAOA,EAAQ,OAAO,EAAE,UAAU,UAAU,CAEhD,CAAC,CACH,CAAC,EAED,SAAS,qBAAsB,IAAM,CACnC,GAAG,4BAA6B,SAAY,CAE1C,MAAME,EAAiC,CACrC,KAAMb,EAAqB,MAC3B,QAAS,EACT,QAAS,OACX,EAGMS,EAAS,MAAMJ,EAAO,UAAUQ,CAAK,EAG3C,OAAOJ,CAAM,EAAE,SAAS,CAC1B,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "Left", "Right", "DynamicNetworkContextLoader", "KeyId", "KeyUsage", "ClearSignContextType", "mockNetworkDataSource", "mockConfig", "mockCertificateLoader", "mockCertificate", "loader", "createMockDescriptor", "partial", "transaction", "result", "networkConfig", "context", "testModeLoader", "field"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=DynamicNetworkConfiguration.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Interface as m}from"ethers";import{Left as i,Right as c}from"purify-ts";import o from"@/external-plugin/__tests__/abi.json";import{ExternalPluginContextLoader as
|
|
1
|
+
import{Interface as m}from"ethers";import{Left as i,Right as c}from"purify-ts";import o from"@/external-plugin/__tests__/abi.json";import{ExternalPluginContextLoader as u}from"../../external-plugin/domain/ExternalPluginContextLoader";import{ClearSignContextType as t}from"../../shared/model/ClearSignContext";const p=({abi:d,selectorDetails:n})=>({abi:d,selectorDetails:{erc20OfInterest:[],method:"",plugin:"",serializedData:"123456",signature:"7890",...n}}),l=(d,n,s)=>{const a=new m(JSON.stringify(d)).encodeFunctionData(n,s);return{to:"0x0",data:a,selector:a.slice(0,10)}};describe("ExternalPluginContextLoader",()=>{const d={getTokenInfosPayload:vi.fn()},n={getDappInfos:vi.fn()},s=new u(n,d);beforeEach(()=>{vi.clearAllMocks(),vi.spyOn(d,"getTokenInfosPayload").mockImplementation(({address:e})=>Promise.resolve(c(`payload-${e}`)))}),describe("load function",()=>{it("should return an empty array if no destination address is provided",async()=>{const e={},a=()=>s.load(e);await expect(a()).resolves.toEqual([])}),it("should return an empty array if no data provided",async()=>{const e={to:"0x0",data:"0x",selector:"0x0"},a=await s.load(e);expect(a).toEqual([])}),it("should return an empty array if no dapp info is povided",async()=>{const e=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(void 0));const a=await s.load(e);expect(a).toEqual([])}),it("should return e plugin if no erc20OfInterest is provided",async()=>{const e=p({abi:o,selectorDetails:{erc20OfInterest:[],method:"singleParam"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.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:o,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual(expect.arrayContaining([{type:t.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.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:o,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e)),vi.spyOn(d,"getTokenInfosPayload").mockResolvedValue(i(Error("error")));const r=await s.load(a);expect(r).toEqual([{type:t.ERROR,error:new Error("error")},{type:t.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:o,selectorDetails:{erc20OfInterest:["fromToken","toToken"],method:"multipleParams"}}),a=l(o,"multipleParams",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual(expect.arrayContaining([{type:t.EXTERNAL_PLUGIN,payload:"1234567890"},{type:t.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"}]))}),it("should return a list of context responses when one erc20OfInterest is an array",async()=>{const e=p({abi:o,selectorDetails:{erc20OfInterest:["fromToken.0","fromToken.1","fromToken.2","fromToken.-1"],method:"arrayParam"}}),a=l(o,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when a token datasource returns an error",async()=>{const e=p({abi:o,selectorDetails:{erc20OfInterest:["fromToken"],method:"singleParam"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e)),vi.spyOn(d,"getTokenInfosPayload").mockResolvedValue(i(new Error("error")));const r=await s.load(a);expect(r).toEqual([{type:t.ERROR,error:new Error("error")},{type:t.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"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.ERROR,error:new Error("[ContextModule] ExternalPluginContextLoader: Unable to parse abi")},{type:t.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should throw an error when the erc20OfInterest doest not exist in the transaction",async()=>{const e=p({abi:o,selectorDetails:{erc20OfInterest:["notFound"],method:"singleParam"}}),a=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.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:o,selectorDetails:{erc20OfInterest:["fromToken.3"],method:"arrayParam"}}),a=l(o,"arrayParam",[["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","0xdAC17F958D2ee523a2206206994597C13D831ec7","0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.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:o,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"}}),a=l(o,"complexStructParam",[{address1:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",param1:{param2:[{param3:{addresses:["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"]}},{param3:{addresses:["0xB8c77482e45F1F44dE1745F52C74426C631bDD52"]}}]}}]);vi.spyOn(n,"getDappInfos").mockResolvedValue(c(e));const r=await s.load(a);expect(r).toEqual([{type:t.TOKEN,payload:"payload-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},{type:t.TOKEN,payload:"payload-0xdAC17F958D2ee523a2206206994597C13D831ec7"},{type:t.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.TOKEN,payload:"payload-0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"},{type:t.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.TOKEN,payload:"payload-0xB8c77482e45F1F44dE1745F52C74426C631bDD52"},{type:t.EXTERNAL_PLUGIN,payload:"1234567890"}])}),it("should return an error when datasource return a Left",async()=>{const e=l(o,"singleParam",["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]);vi.spyOn(n,"getDappInfos").mockResolvedValue(i(new Error("error")));const a=await s.load(e);expect(a).toEqual([{type:t.ERROR,error:new Error("error")}])}),it("should return an error when transaction data is not a valid hex string",async()=>{const e={to:"0x0",data:"notAHexString"},a=await s.load(e);expect(a).toEqual([{type:t.ERROR,error:new Error("Invalid selector")}])})})});
|
|
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 { ExternalPluginContextLoader } 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 TransactionContext } from \"@/shared/model/TransactionContext\";\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 transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n selector: data.slice(0, 10),\n } as TransactionContext;\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(\"load function\", async () => {\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"0x\",\n selector: \"0x0\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"notAHexString\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,aAAAA,MAAiB,SAC1B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAOC,MAAS,uCAEhB,OAAS,+BAAAC,MAAmC,uDAG5C,OAAS,wBAAAC,MAA4B,kCAIrC,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,EAAqB,CACzBF,EACAG,EACAC,IACuB,CAEvB,MAAMC,EADW,IAAIZ,EAAU,KAAK,UAAUO,CAAG,CAAC,EAC5B,mBAAmBG,EAAcC,CAAM,EAC7D,MAAO,CACL,GAAI,MACJ,KAAAC,EACA,SAAUA,EAAK,MAAM,EAAG,EAAE,CAC5B,CACF,EAEA,SAAS,8BAA+B,IAAM,CAC5C,MAAMC,EAAuC,CAC3C,qBAAsB,GAAG,GAAG,CAC9B,EACMC,EAAyD,CAC7D,aAAc,GAAG,GAAG,CACtB,EACMC,EAAS,IAAIX,EACjBU,EACAD,CACF,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EACjB,GAAG,MAAMA,EAAqB,sBAAsB,EAAE,mBACpD,CAAC,CAAE,QAAAG,CAAQ,IAAM,QAAQ,QAAQd,EAAM,WAAWc,CAAO,EAAE,CAAC,CAC9D,CACF,CAAC,EAED,SAAS,gBAAiB,
|
|
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 { ExternalPluginContextLoader } 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 TransactionContext } from \"@/shared/model/TransactionContext\";\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 transactionBuilder = (\n abi: object,\n functionName: string,\n params: unknown[],\n): TransactionContext => {\n const contract = new Interface(JSON.stringify(abi));\n const data = contract.encodeFunctionData(functionName, params);\n return {\n to: \"0x0\",\n data,\n selector: data.slice(0, 10),\n } as TransactionContext;\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(\"load function\", () => {\n it(\"should return an empty array if no destination address is provided\", async () => {\n // GIVEN\n const transaction = {} as TransactionContext;\n\n // WHEN\n const promise = () => loader.load(transaction);\n\n // THEN\n await expect(promise()).resolves.toEqual([]);\n });\n\n it(\"should return an empty array if no data provided\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"0x\",\n selector: \"0x0\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([]);\n });\n\n it(\"should return an empty array if no dapp info is povided\", async () => {\n // GIVEN\n const transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(undefined),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(ABI, \"singleParam\", [\n \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n ]);\n vi.spyOn(mockExternalPluginDataSource, \"getDappInfos\").mockResolvedValue(\n Right(dappInfos),\n );\n\n // WHEN\n const result = await loader.load(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\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 transaction = transactionBuilder(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(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"error\"),\n },\n ]);\n });\n\n it(\"should return an error when transaction data is not a valid hex string\", async () => {\n // GIVEN\n const transaction = {\n to: \"0x0\",\n data: \"notAHexString\",\n } as TransactionContext;\n\n // WHEN\n const result = await loader.load(transaction);\n\n // THEN\n expect(result).toEqual([\n {\n type: ClearSignContextType.ERROR,\n error: new Error(\"Invalid selector\"),\n },\n ]);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,aAAAA,MAAiB,SAC1B,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAOC,MAAS,uCAEhB,OAAS,+BAAAC,MAAmC,uDAG5C,OAAS,wBAAAC,MAA4B,kCAIrC,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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,CACrB,CACE,KAAMd,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,MAC3B,QAAS,oDACX,EACA,CACE,KAAMA,EAAqB,gBAC3B,QAAS,YACX,CACF,CAAC,CACH,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,MAAMY,EAAcR,EAAmBN,EAAK,cAAe,CACzD,4CACF,CAAC,EACD,GAAG,MAAMW,EAA8B,cAAc,EAAE,kBACrDb,EAAK,IAAI,MAAM,OAAO,CAAC,CACzB,EAGA,MAAMkB,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMd,EAAqB,MAC3B,MAAO,IAAI,MAAM,OAAO,CAC1B,CACF,CAAC,CACH,CAAC,EAED,GAAG,yEAA0E,SAAY,CAEvF,MAAMY,EAAc,CAClB,GAAI,MACJ,KAAM,eACR,EAGME,EAAS,MAAMJ,EAAO,KAAKE,CAAW,EAG5C,OAAOE,CAAM,EAAE,QAAQ,CACrB,CACE,KAAMd,EAAqB,MAC3B,MAAO,IAAI,MAAM,kBAAkB,CACrC,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["Interface", "Left", "Right", "ABI", "ExternalPluginContextLoader", "ClearSignContextType", "dappInfosBuilder", "abi", "selectorDetails", "transactionBuilder", "functionName", "params", "data", "mockTokenDataSource", "mockExternalPluginDataSource", "loader", "address", "transaction", "promise", "result", "dappInfos"]
|
|
7
7
|
}
|
package/lib/esm/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./config/model/ContextModuleConfig";export*from"./ContextModule";export*from"./ContextModuleBuilder";export*from"./DefaultContextModule";export*from"./external-plugin/domain/ExternalPluginContextLoader";export*from"./nft/domain/NftContextLoader";export*from"./pki/domain/PkiCertificateLoader";export*from"./pki/model/KeyId";export*from"./pki/model/KeyUsage";export*from"./pki/model/PkiCertificate";export*from"./pki/model/PkiCertificateInfo";export*from"./shared/domain/ContextLoader";export*from"./shared/model/ClearSignContext";export*from"./shared/model/GenericPath";export*from"./shared/model/TransactionContext";export*from"./shared/model/TransactionSubset";export*from"./shared/model/TypedDataClearSignContext";export*from"./shared/model/TypedDataContext";export*from"./token/domain/TokenContextLoader";export*from"./trusted-name/domain/TrustedNameContextLoader";export*from"./web3-check/domain/Web3CheckContextLoader";export*from"./web3-check/domain/web3CheckTypes";
|
|
1
|
+
export*from"./config/model/ContextModuleConfig";export*from"./ContextModule";export*from"./ContextModuleBuilder";export*from"./DefaultContextModule";export*from"./dynamic-network/domain/DynamicNetworkContextLoader";export*from"./dynamic-network/model/DynamicNetworkConfiguration";export*from"./external-plugin/domain/ExternalPluginContextLoader";export*from"./nft/domain/NftContextLoader";export*from"./pki/domain/PkiCertificateLoader";export*from"./pki/model/KeyId";export*from"./pki/model/KeyUsage";export*from"./pki/model/PkiCertificate";export*from"./pki/model/PkiCertificateInfo";export*from"./shared/domain/ContextLoader";export*from"./shared/model/ClearSignContext";export*from"./shared/model/GenericPath";export*from"./shared/model/TransactionContext";export*from"./shared/model/TransactionSubset";export*from"./shared/model/TypedDataClearSignContext";export*from"./shared/model/TypedDataContext";export*from"./token/domain/TokenContextLoader";export*from"./trusted-name/domain/TrustedNameContextLoader";export*from"./web3-check/domain/Web3CheckContextLoader";export*from"./web3-check/domain/web3CheckTypes";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/src/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
|
|
5
|
-
"mappings": "AAAA,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,uDACd,WAAc,gCACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,oCACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,oCACd,WAAc,iDACd,WAAc,6CACd,WAAc",
|
|
4
|
+
"sourcesContent": ["export * from \"./config/model/ContextModuleConfig\";\nexport * from \"./ContextModule\";\nexport * from \"./ContextModuleBuilder\";\nexport * from \"./DefaultContextModule\";\nexport * from \"./dynamic-network/domain/DynamicNetworkContextLoader\";\nexport * from \"./dynamic-network/model/DynamicNetworkConfiguration\";\nexport * from \"./external-plugin/domain/ExternalPluginContextLoader\";\nexport * from \"./nft/domain/NftContextLoader\";\nexport * from \"./pki/domain/PkiCertificateLoader\";\nexport * from \"./pki/model/KeyId\";\nexport * from \"./pki/model/KeyUsage\";\nexport * from \"./pki/model/PkiCertificate\";\nexport * from \"./pki/model/PkiCertificateInfo\";\nexport * from \"./shared/domain/ContextLoader\";\nexport * from \"./shared/model/ClearSignContext\";\nexport * from \"./shared/model/GenericPath\";\nexport * from \"./shared/model/TransactionContext\";\nexport * from \"./shared/model/TransactionSubset\";\nexport * from \"./shared/model/TypedDataClearSignContext\";\nexport * from \"./shared/model/TypedDataContext\";\nexport * from \"./token/domain/TokenContextLoader\";\nexport * from \"./trusted-name/domain/TrustedNameContextLoader\";\nexport * from \"./web3-check/domain/Web3CheckContextLoader\";\nexport * from \"./web3-check/domain/web3CheckTypes\";\n"],
|
|
5
|
+
"mappings": "AAAA,WAAc,qCACd,WAAc,kBACd,WAAc,yBACd,WAAc,yBACd,WAAc,uDACd,WAAc,sDACd,WAAc,uDACd,WAAc,gCACd,WAAc,oCACd,WAAc,oBACd,WAAc,uBACd,WAAc,6BACd,WAAc,iCACd,WAAc,gCACd,WAAc,kCACd,WAAc,6BACd,WAAc,oCACd,WAAc,mCACd,WAAc,2CACd,WAAc,kCACd,WAAc,oCACd,WAAc,iDACd,WAAc,6CACd,WAAc",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=(a,t,e,r)=>{for(var i=r>1?void 0:r?s(t,e):t,o=a.length-1,f;o>=0;o--)(f=a[o])&&(i=(r?f(t,e,i):f(i))||i);return r&&i&&n(t,e,i),i},p=(a,t)=>(e,r)=>t(e,r,a);import{inject as u,injectable as C}from"inversify";import{pkiTypes as k}from"../../pki/di/pkiTypes";let c=class{_dataSource;constructor(t){this._dataSource=t}async loadCertificate(t){return(await this._dataSource.fetchCertificate(t)).orDefault(void 0)}};c=m([C(),p(0,u(k.PkiCertificateDataSource))],c);export{c as DefaultPkiCertificateLoader};
|
|
2
2
|
//# sourceMappingURL=DefaultPkiCertificateLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.ts"],
|
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n
|
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,
|
|
6
|
-
"names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "
|
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type PkiCertificateDataSource } from \"@/pki/data/PkiCertificateDataSource\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\nimport { PkiCertificateLoader } from \"./PkiCertificateLoader\";\n\n@injectable()\nexport class DefaultPkiCertificateLoader implements PkiCertificateLoader {\n private _dataSource: PkiCertificateDataSource;\n\n constructor(\n @inject(pkiTypes.PkiCertificateDataSource)\n dataSource: PkiCertificateDataSource,\n ) {\n this._dataSource = dataSource;\n }\n\n async loadCertificate(\n certificateInfos: PkiCertificateInfo,\n ): Promise<PkiCertificate | undefined> {\n const certificate =\n await this._dataSource.fetchCertificate(certificateInfos);\n\n // TODO add logs error with certificate.left()\n return certificate.orDefault(undefined);\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAGnC,OAAS,YAAAC,MAAgB,oBAOlB,IAAMC,EAAN,KAAkE,CAC/D,YAER,YAEEC,EACA,CACA,KAAK,YAAcA,CACrB,CAEA,MAAM,gBACJC,EACqC,CAKrC,OAHE,MAAM,KAAK,YAAY,iBAAiBA,CAAgB,GAGvC,UAAU,MAAS,CACxC,CACF,EAnBaF,EAANG,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAS,wBAAwB,IAJhCP",
|
|
6
|
+
"names": ["inject", "injectable", "pkiTypes", "DefaultPkiCertificateLoader", "dataSource", "certificateInfos", "__decorateClass", "injectable", "__decorateParam", "inject", "pkiTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as
|
|
1
|
+
import{Left as n,Right as l}from"purify-ts";import{DefaultPkiCertificateLoader as r}from"../../pki/domain/DefaultPkiCertificateLoader";import{KeyId as o}from"../../pki/model/KeyId";import{KeyUsage as c}from"../../pki/model/KeyUsage";describe("DefaultPkiCertificateLoader",()=>{describe("loadCertificate",()=>{it("should call loadCertificate",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])},t={fetchCertificate:vi.fn().mockResolvedValue(l(a))},i=await new r(t).loadCertificate(e);expect(i).toEqual(a),expect(t.fetchCertificate).toHaveBeenCalledWith(e)}),it("Returns undefined when the data source returns a Left(error)",async()=>{const e={targetDevice:"targetDevice",keyUsage:c.Calldata,keyId:o.CalNetwork},a=new Error("failed"),t={fetchCertificate:vi.fn().mockResolvedValue(n(a))},i=await new r(t).loadCertificate(e);expect(i).toBeUndefined(),expect(t.fetchCertificate).toHaveBeenCalledWith(e)})})});
|
|
2
2
|
//# sourceMappingURL=DefaultPkiCertificateLoader.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/pki/domain/DefaultPkiCertificateLoader.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,
|
|
6
|
-
"names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError"
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DefaultPkiCertificateLoader } from \"@/pki/domain/DefaultPkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { type PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\n\ndescribe(\"DefaultPkiCertificateLoader\", () => {\n describe(\"loadCertificate\", () => {\n it(\"should call loadCertificate\", async () => {\n // GIVEN\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const certificate = {\n keyUsageNumber: 11,\n payload: new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x15, 0x04, 0x05, 0x06, 0x07, 0x08,\n ]),\n };\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Right(certificate)),\n };\n\n // WHEN\n const loader = new DefaultPkiCertificateLoader(dataSource);\n const result = await loader.loadCertificate(certificateInfos);\n\n // THEN\n expect(result).toEqual(certificate);\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n\n it(\"Returns undefined when the data source returns a Left(error)\", async () => {\n // given\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: \"targetDevice\",\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalNetwork,\n };\n const fetchError = new Error(\"failed\");\n const dataSource = {\n fetchCertificate: vi.fn().mockResolvedValue(Left(fetchError)),\n };\n const loader = new DefaultPkiCertificateLoader(dataSource);\n\n // when / then\n const result = await loader.loadCertificate(certificateInfos);\n expect(result).toBeUndefined();\n expect(dataSource.fetchCertificate).toHaveBeenCalledWith(\n certificateInfos,\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,+BAAAC,MAAmC,2CAC5C,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,SAAS,8BAA+B,IAAM,CAC5C,SAAS,kBAAmB,IAAM,CAChC,GAAG,8BAA+B,SAAY,CAE5C,MAAMC,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMG,EAAc,CAClB,eAAgB,GAChB,QAAS,IAAI,WAAW,CACtB,EAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,CACH,EACMC,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBN,EAAMK,CAAW,CAAC,CAChE,EAIME,EAAS,MADA,IAAIN,EAA4BK,CAAU,EAC7B,gBAAgBF,CAAgB,EAG5D,OAAOG,CAAM,EAAE,QAAQF,CAAW,EAClC,OAAOC,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,EAED,GAAG,+DAAgE,SAAY,CAE7E,MAAMA,EAAuC,CAC3C,aAAc,eACd,SAAUD,EAAS,SACnB,MAAOD,EAAM,UACf,EACMM,EAAa,IAAI,MAAM,QAAQ,EAC/BF,EAAa,CACjB,iBAAkB,GAAG,GAAG,EAAE,kBAAkBP,EAAKS,CAAU,CAAC,CAC9D,EAIMD,EAAS,MAHA,IAAIN,EAA4BK,CAAU,EAG7B,gBAAgBF,CAAgB,EAC5D,OAAOG,CAAM,EAAE,cAAc,EAC7B,OAAOD,EAAW,gBAAgB,EAAE,qBAClCF,CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["Left", "Right", "DefaultPkiCertificateLoader", "KeyId", "KeyUsage", "certificateInfos", "certificate", "dataSource", "result", "fetchError"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_DELEGATE_CALL="proxyDelegateCall",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.ERROR="error",e))(t||{});export{t as ClearSignContextType};
|
|
1
|
+
var t=(e=>(e.TOKEN="token",e.NFT="nft",e.TRUSTED_NAME="trustedName",e.PLUGIN="plugin",e.EXTERNAL_PLUGIN="externalPlugin",e.TRANSACTION_INFO="transactionInfo",e.PROXY_DELEGATE_CALL="proxyDelegateCall",e.ENUM="enum",e.TRANSACTION_FIELD_DESCRIPTION="transactionFieldDescription",e.WEB3_CHECK="web3Check",e.DYNAMIC_NETWORK="dynamicNetwork",e.DYNAMIC_NETWORK_ICON="dynamicNetworkIcon",e.ERROR="error",e))(t||{});export{t as ClearSignContextType};
|
|
2
2
|
//# sourceMappingURL=ClearSignContext.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/shared/model/ClearSignContext.ts"],
|
|
4
|
-
"sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_DELEGATE_CALL = \"proxyDelegateCall\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
|
|
5
|
-
"mappings": "AAIO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,oBAAsB,oBACtBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,MAAQ,
|
|
4
|
+
"sourcesContent": ["import { type PkiCertificate } from \"@/pki/model/PkiCertificate\";\n\nimport { type GenericPath } from \"./GenericPath\";\n\nexport enum ClearSignContextType {\n TOKEN = \"token\",\n NFT = \"nft\",\n TRUSTED_NAME = \"trustedName\",\n PLUGIN = \"plugin\",\n EXTERNAL_PLUGIN = \"externalPlugin\",\n TRANSACTION_INFO = \"transactionInfo\",\n PROXY_DELEGATE_CALL = \"proxyDelegateCall\",\n ENUM = \"enum\",\n TRANSACTION_FIELD_DESCRIPTION = \"transactionFieldDescription\",\n WEB3_CHECK = \"web3Check\",\n DYNAMIC_NETWORK = \"dynamicNetwork\",\n DYNAMIC_NETWORK_ICON = \"dynamicNetworkIcon\",\n ERROR = \"error\",\n}\n\nexport type ClearSignContextReferenceType =\n | ClearSignContextType.TOKEN\n | ClearSignContextType.NFT\n | ClearSignContextType.ENUM\n | ClearSignContextType.TRUSTED_NAME;\n\nexport type ClearSignContextReference<\n Type extends ClearSignContextReferenceType = ClearSignContextReferenceType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n valuePath: GenericPath;\n id: number; // enum id to reference\n }\n : Type extends ClearSignContextType.TRUSTED_NAME\n ? {\n type: ClearSignContextType.TRUSTED_NAME;\n valuePath: GenericPath;\n types: string[];\n sources: string[];\n }\n :\n | {\n type: Type;\n valuePath: GenericPath;\n value?: never;\n }\n | {\n type: Type;\n valuePath?: never;\n value: string;\n };\n\nexport type ClearSignContextSuccessType = Exclude<\n ClearSignContextType,\n ClearSignContextType.ERROR\n>;\n\n// NOTE: this is a union of all possible success types\n// There is currently two types of success:\n// - ENUM: which is a special case, we need to handle it differently\n// because we don't want to send the whole enum\n// but only the parts that are needed.\n// - id: the enum id to reference\n// - payload: the payload to send with a provideEnum command\n// - name: the name of the enum to be displayed on the device\n// - value: the value of the enum to be retrieved from the transaction\n// - All other types\n// - payload: the payload to send with a provide command\n// - reference: the reference to the value to be retrieved from the transaction\nexport type ClearSignContextSuccess<\n Type extends ClearSignContextSuccessType = ClearSignContextSuccessType,\n> = Type extends ClearSignContextType.ENUM\n ? {\n type: ClearSignContextType.ENUM;\n id: number;\n payload: string;\n value: number;\n certificate?: PkiCertificate;\n }\n : {\n type: Exclude<\n ClearSignContextType,\n ClearSignContextType.ENUM | ClearSignContextType.ERROR\n >;\n payload: string;\n reference?: ClearSignContextReference;\n certificate?: PkiCertificate;\n };\n\nexport type ClearSignContextError = {\n type: ClearSignContextType.ERROR;\n error: Error;\n};\n\nexport type ClearSignContext = ClearSignContextSuccess | ClearSignContextError;\n"],
|
|
5
|
+
"mappings": "AAIO,IAAKA,OACVA,EAAA,MAAQ,QACRA,EAAA,IAAM,MACNA,EAAA,aAAe,cACfA,EAAA,OAAS,SACTA,EAAA,gBAAkB,iBAClBA,EAAA,iBAAmB,kBACnBA,EAAA,oBAAsB,oBACtBA,EAAA,KAAO,OACPA,EAAA,8BAAgC,8BAChCA,EAAA,WAAa,YACbA,EAAA,gBAAkB,iBAClBA,EAAA,qBAAuB,qBACvBA,EAAA,MAAQ,QAbEA,OAAA",
|
|
6
6
|
"names": ["ClearSignContextType"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/
|
|
1
|
+
var P=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=(i,e,t,r)=>{for(var o=r>1?void 0:r?f(e,t):e,n=i.length-1,s;n>=0;n--)(s=i[n])&&(o=(r?s(e,t,o):s(o))||o);return r&&o&&P(e,t,o),o},m=(i,e)=>(t,r)=>e(t,r,i);import p from"axios";import{inject as D,injectable as u}from"inversify";import{Left as a,Right as y}from"purify-ts";import{configTypes as E}from"../../config/di/configTypes";import{LEDGER_CLIENT_VERSION_HEADER as x,LEDGER_ORIGIN_TOKEN_HEADER as c}from"../../shared/constant/HttpHeaders";import g from"../../../package.json";let d=class{constructor(e){this.config=e}async getProxyDelegateCall({proxyAddress:e,calldata:t,chainId:r,challenge:o}){let n;try{n=(await p.request({method:"POST",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${r}/contract/proxy/delegate`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken},data:{proxy:e,data:t,challenge:o}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy"))}return n?this.isProxyDelegateCallDto(n)?y({delegateAddresses:n.addresses,signedDescriptor:n.signedDescriptor}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${e} on chain ${r}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${r}`))}async getProxyImplementationAddress({proxyAddress:e,chainId:t}){let r;try{r=(await p.request({method:"GET",url:`${this.config.metadataServiceDomain.url}/v2/ethereum/${t}/contract/proxy/${e}`,headers:{[x]:`context-module/${g.version}`,[c]:this.config.originToken}})).data}catch{return a(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address"))}return r?this.isProxyImplementationAddressDto(r)?y({implementationAddress:r.implementationAddress}):a(new Error(`[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${e} on chain ${t}`)):a(new Error(`[ContextModule] HttpProxyDataSource: No data received for proxy ${e} on chain ${t}`))}isProxyDelegateCallDto(e){return typeof e=="object"&&e!==null&&"addresses"in e&&"signedDescriptor"in e&&Array.isArray(e.addresses)&&e.addresses.every(t=>typeof t=="string")&&typeof e.signedDescriptor=="string"}isProxyImplementationAddressDto(e){return typeof e=="object"&&e!==null&&"proxyAddress"in e&&"implementationAddress"in e&&"standard"in e&&typeof e.proxyAddress=="string"&&typeof e.implementationAddress=="string"&&typeof e.standard=="string"&&e.standard.length>0}};d=l([u(),m(0,D(E.Config))],d);export{d as HttpProxyDataSource};
|
|
2
2
|
//# sourceMappingURL=HttpProxyDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/transaction/data/HttpProxyDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/
|
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport {\n LEDGER_CLIENT_VERSION_HEADER,\n LEDGER_ORIGIN_TOKEN_HEADER,\n} from \"@/shared/constant/HttpHeaders\";\nimport { type ProxyDelegateCall } from \"@/transaction/model/ProxyDelegateCall\";\nimport { type ProxyImplementationAddress } from \"@/transaction/model/ProxyImplementationAddress\";\nimport PACKAGE from \"@root/package.json\";\n\nimport { type ProxyDelegateCallDto } from \"./dto/ProxyDelegateCallDto\";\nimport { type ProxyImplementationAddressDto } from \"./dto/ProxyImplementationAddressDto\";\n\nexport type GetProxyDelegateCallParam = {\n proxyAddress: string;\n calldata: string;\n chainId: number;\n challenge: string;\n};\n\nexport type GetProxyImplementationAddressParam = {\n proxyAddress: string;\n chainId: number;\n};\n\nexport interface ProxyDataSource {\n getProxyDelegateCall(\n params: GetProxyDelegateCallParam,\n ): Promise<Either<Error, ProxyDelegateCall>>;\n getProxyImplementationAddress(\n params: GetProxyImplementationAddressParam,\n ): Promise<Either<Error, ProxyImplementationAddress>>;\n}\n\n@injectable()\nexport class HttpProxyDataSource implements ProxyDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n ) {}\n\n public async getProxyDelegateCall({\n proxyAddress,\n calldata,\n chainId,\n challenge,\n }: GetProxyDelegateCallParam): Promise<Either<Error, ProxyDelegateCall>> {\n let dto: ProxyDelegateCallDto | undefined;\n try {\n const response = await axios.request<ProxyDelegateCallDto>({\n method: \"POST\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/delegate`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n data: {\n proxy: proxyAddress,\n data: calldata,\n challenge,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyDelegateCallDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({\n delegateAddresses: dto.addresses,\n signedDescriptor: dto.signedDescriptor,\n });\n }\n\n public async getProxyImplementationAddress({\n proxyAddress,\n chainId,\n }: GetProxyImplementationAddressParam): Promise<\n Either<Error, ProxyImplementationAddress>\n > {\n let dto: ProxyImplementationAddressDto | undefined;\n try {\n const response = await axios.request<ProxyImplementationAddressDto>({\n method: \"GET\",\n url: `${this.config.metadataServiceDomain.url}/v2/ethereum/${chainId}/contract/proxy/${proxyAddress}`,\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n [LEDGER_ORIGIN_TOKEN_HEADER]: this.config.originToken,\n },\n });\n dto = response.data;\n } catch (_error) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Failed to fetch implementation address`,\n ),\n );\n }\n\n if (!dto) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: No data received for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n if (!this.isProxyImplementationAddressDto(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy ${proxyAddress} on chain ${chainId}`,\n ),\n );\n }\n\n return Right({ implementationAddress: dto.implementationAddress });\n }\n\n /**\n * Type guard to validate ProxyDelegateCallDto\n */\n private isProxyDelegateCallDto(\n value: unknown,\n ): value is ProxyDelegateCallDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"addresses\" in value &&\n \"signedDescriptor\" in value &&\n Array.isArray(value.addresses) &&\n value.addresses.every((address) => typeof address === \"string\") &&\n typeof value.signedDescriptor === \"string\"\n );\n }\n\n /**\n * Type guard to validate ProxyImplementationAddressDto\n */\n private isProxyImplementationAddressDto(\n value: unknown,\n ): value is ProxyImplementationAddressDto {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"proxyAddress\" in value &&\n \"implementationAddress\" in value &&\n \"standard\" in value &&\n typeof value.proxyAddress === \"string\" &&\n typeof value.implementationAddress === \"string\" &&\n typeof value.standard === \"string\" &&\n value.standard.length > 0\n );\n }\n}\n"],
|
|
5
5
|
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAE5B,OACE,gCAAAC,EACA,8BAAAC,MACK,gCAGP,OAAOC,MAAa,qBA2Bb,IAAMC,EAAN,KAAqD,CAC1D,YAC+CC,EAC7C,CAD6C,YAAAA,CAC5C,CAEH,MAAa,qBAAqB,CAChC,aAAAC,EACA,SAAAC,EACA,QAAAC,EACA,UAAAC,CACF,EAAyE,CACvE,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAMC,EAAM,QAA8B,CACzD,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,2BACpE,QAAS,CACP,CAACI,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,EACA,KAAM,CACJ,MAAOR,EACP,KAAMC,EACN,UAAAE,CACF,CACF,CAAC,GACc,IACjB,MAAiB,CACf,OAAOM,EACL,IAAI,MACF,qEACF,CACF,CACF,CAEA,OAAKL,EAQA,KAAK,uBAAuBA,CAAG,EAQ7BM,EAAM,CACX,kBAAmBN,EAAI,UACvB,iBAAkBA,EAAI,gBACxB,CAAC,EAVQK,EACL,IAAI,MACF,8FAA8FT,CAAY,aAAaE,CAAO,EAChI,CACF,EAZOO,EACL,IAAI,MACF,mEAAmET,CAAY,aAAaE,CAAO,EACrG,CACF,CAeJ,CAEA,MAAa,8BAA8B,CACzC,aAAAF,EACA,QAAAE,CACF,EAEE,CACA,IAAIE,EACJ,GAAI,CASFA,GARiB,MAAMC,EAAM,QAAuC,CAClE,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,sBAAsB,GAAG,gBAAgBH,CAAO,mBAAmBF,CAAY,GACnG,QAAS,CACP,CAACM,CAA4B,EAAG,kBAAkBC,EAAQ,OAAO,GACjE,CAACC,CAA0B,EAAG,KAAK,OAAO,WAC5C,CACF,CAAC,GACc,IACjB,MAAiB,CACf,OAAOC,EACL,IAAI,MACF,6EACF,CACF,CACF,CAEA,OAAKL,EAQA,KAAK,gCAAgCA,CAAG,EAQtCM,EAAM,CAAE,sBAAuBN,EAAI,qBAAsB,CAAC,EAPxDK,EACL,IAAI,MACF,uGAAuGT,CAAY,aAAaE,CAAO,EACzI,CACF,EAZOO,EACL,IAAI,MACF,mEAAmET,CAAY,aAAaE,CAAO,EACrG,CACF,CAYJ,CAKQ,uBACNS,EAC+B,CAC/B,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,cAAeA,GACf,qBAAsBA,GACtB,MAAM,QAAQA,EAAM,SAAS,GAC7BA,EAAM,UAAU,MAAOC,GAAY,OAAOA,GAAY,QAAQ,GAC9D,OAAOD,EAAM,kBAAqB,QAEtC,CAKQ,gCACNA,EACwC,CACxC,OACE,OAAOA,GAAU,UACjBA,IAAU,MACV,iBAAkBA,GAClB,0BAA2BA,GAC3B,aAAcA,GACd,OAAOA,EAAM,cAAiB,UAC9B,OAAOA,EAAM,uBAA0B,UACvC,OAAOA,EAAM,UAAa,UAC1BA,EAAM,SAAS,OAAS,CAE5B,CACF,EAxIab,EAANe,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,IAFjBnB",
|
|
6
6
|
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "LEDGER_CLIENT_VERSION_HEADER", "LEDGER_ORIGIN_TOKEN_HEADER", "PACKAGE", "HttpProxyDataSource", "config", "proxyAddress", "calldata", "chainId", "challenge", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "LEDGER_ORIGIN_TOKEN_HEADER", "Left", "Right", "value", "address", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/
|
|
1
|
+
import a from"axios";import{Left as n,Right as l}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as p,LEDGER_ORIGIN_TOKEN_HEADER as m}from"../../shared/constant/HttpHeaders";import x from"../../../package.json";import{HttpProxyDataSource as y}from"./HttpProxyDataSource";vi.mock("axios");describe("HttpProxyDataSource",()=>{const c={web3checks:{url:"web3checksUrl"},originToken:"originToken"};let t;const s={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:1,challenge:"0x1234567890abcdef"},r={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:1},i={addresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"},u={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3"},d={implementationAddress:"0x91ae842a5ffd8d12023116943e72a606179294f3",proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",standard:"proxy"};beforeEach(()=>{vi.clearAllMocks(),t=new y({metadataServiceDomain:{url:"https://nft.api.live.ledger.com"},originToken:"originToken"})}),describe("getDelegateProxy",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyDelegateCall(s),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should return the delegate proxy response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:i});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(l({delegateAddresses:["0xd9db270c1b5e3bd161e8c8503c55ceabee709552"],signedDescriptor:"0x1234567890abcdef"}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("fail"));const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch delegate proxy")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{foo:"bar"}});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy delegate call response format for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:i}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0x72CBdEaAdddD14Ec95b92995933CeC69566650f0",calldata:"0x6a76120200000000000000000000000072cbdeaadddd14ec95b92995933cec69566650f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000440d582f13000000000000000000000000cfa7eae32032bf431aed95532142a9c2b35715d40000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041000000000000000000000000a0766b65a4f7b1da79a1af79ac695456efa2864400000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000",chainId:137,challenge:"0x1234567890abcdef"};await t.getProxyDelegateCall(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"POST",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/delegate"}))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyDelegateCall(s);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0x72CBdEaAdddD14Ec95b92995933CeC69566650f0 on chain 1")))})}),describe("getImplementAddress",()=>{it("should call axios with the ledger client version header",async()=>{const e=`context-module/${x.version}`,o=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(o),await t.getProxyImplementationAddress(r),expect(o).toHaveBeenCalledWith(expect.objectContaining({headers:{[p]:e,[m]:c.originToken}}))}),it("should make a GET request to the correct URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e),await t.getProxyImplementationAddress(r),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/1/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should use the provided chainId in the URL",async()=>{const e=vi.fn(()=>Promise.resolve({data:d}));vi.spyOn(a,"request").mockImplementation(e);const o={proxyAddress:"0xee6a57ec80ea46401049e92587e52f5ec1c24785",chainId:137};await t.getProxyImplementationAddress(o),expect(e).toHaveBeenCalledWith(expect.objectContaining({method:"GET",url:"https://nft.api.live.ledger.com/v2/ethereum/137/contract/proxy/0xee6a57ec80ea46401049e92587e52f5ec1c24785"}))}),it("should return the implementation address response on success",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:d});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(l(u))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(a,"request").mockRejectedValue(new Error("network error"));const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Failed to fetch implementation address")))}),it("should return an error if response shape is invalid",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:{invalid:"data"}});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: Invalid proxy implementation address response format for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))}),it("should return an error if no dto is returned from the api",async()=>{vi.spyOn(a,"request").mockResolvedValue({data:void 0});const e=await t.getProxyImplementationAddress(r);expect(e).toEqual(n(new Error("[ContextModule] HttpProxyDataSource: No data received for proxy 0xee6a57ec80ea46401049e92587e52f5ec1c24785 on chain 1")))})})});
|
|
2
2
|
//# sourceMappingURL=HttpProxyDataSource.test.js.map
|