@ledgerhq/context-module 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/lib/cjs/package.json +13 -13
- package/lib/cjs/src/ContextModuleBuilder.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.js.map +3 -3
- package/lib/cjs/src/ContextModuleBuilder.test.js +1 -1
- package/lib/cjs/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/cjs/src/DefaultContextModule.test.js +1 -1
- package/lib/cjs/src/DefaultContextModule.test.js.map +2 -2
- package/lib/cjs/src/config/di/configTypes.js +1 -1
- package/lib/cjs/src/config/di/configTypes.js.map +2 -2
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js +2 -0
- package/lib/cjs/src/config/model/ContextModuleBuildArgs.js.map +7 -0
- package/lib/cjs/src/config/model/ContextModuleConfig.js +1 -1
- package/lib/cjs/src/config/model/ContextModuleConfig.js.map +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
- package/lib/cjs/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
- package/lib/cjs/src/nft/data/HttpNftDataSource.js +1 -1
- package/lib/cjs/src/nft/data/HttpNftDataSource.js.map +3 -3
- package/lib/cjs/src/nft/data/HttpNftDataSource.test.js +1 -1
- package/lib/cjs/src/nft/data/HttpNftDataSource.test.js.map +3 -3
- package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
- package/lib/cjs/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
- package/lib/cjs/src/shared/constant/HttpHeaders.js +2 -0
- package/lib/cjs/src/shared/constant/HttpHeaders.js.map +7 -0
- package/lib/cjs/src/token/data/HttpTokenDataSource.js +1 -1
- package/lib/cjs/src/token/data/HttpTokenDataSource.js.map +3 -3
- package/lib/cjs/src/token/data/HttpTokenDataSource.test.js +1 -1
- package/lib/cjs/src/token/data/HttpTokenDataSource.test.js.map +3 -3
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js +1 -1
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
- package/lib/cjs/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/cjs/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
- package/lib/cjs/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.js.map +3 -3
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
- package/lib/cjs/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
- package/lib/esm/package.json +13 -13
- package/lib/esm/src/ContextModuleBuilder.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.js.map +3 -3
- package/lib/esm/src/ContextModuleBuilder.test.js +1 -1
- package/lib/esm/src/ContextModuleBuilder.test.js.map +3 -3
- package/lib/esm/src/DefaultContextModule.test.js +1 -1
- package/lib/esm/src/DefaultContextModule.test.js.map +2 -2
- package/lib/esm/src/config/di/configTypes.js +1 -1
- package/lib/esm/src/config/di/configTypes.js.map +2 -2
- package/lib/esm/src/config/model/ContextModuleBuildArgs.js +1 -0
- package/lib/esm/src/config/model/ContextModuleBuildArgs.js.map +7 -0
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js +1 -1
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.js.map +3 -3
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js +1 -1
- package/lib/esm/src/external-plugin/data/HttpExternalPluginDataSource.test.js.map +3 -3
- package/lib/esm/src/nft/data/HttpNftDataSource.js +1 -1
- package/lib/esm/src/nft/data/HttpNftDataSource.js.map +3 -3
- package/lib/esm/src/nft/data/HttpNftDataSource.test.js +1 -1
- package/lib/esm/src/nft/data/HttpNftDataSource.test.js.map +3 -3
- package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js +1 -1
- package/lib/esm/src/pki/data/HttpPkiCertificateDataSource.js.map +3 -3
- package/lib/esm/src/shared/constant/HttpHeaders.js +2 -0
- package/lib/esm/src/shared/constant/HttpHeaders.js.map +7 -0
- package/lib/esm/src/token/data/HttpTokenDataSource.js +1 -1
- package/lib/esm/src/token/data/HttpTokenDataSource.js.map +3 -3
- package/lib/esm/src/token/data/HttpTokenDataSource.test.js +1 -1
- package/lib/esm/src/token/data/HttpTokenDataSource.test.js.map +3 -3
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js +1 -1
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.js.map +3 -3
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js +1 -1
- package/lib/esm/src/transaction/data/HttpTransactionDataSource.test.js.map +3 -3
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.js.map +3 -3
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js +1 -1
- package/lib/esm/src/trusted-name/data/HttpTrustedNameDataSource.test.js.map +3 -3
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.js.map +3 -3
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js +1 -1
- package/lib/esm/src/typed-data/data/HttpTypedDataDataSource.test.js.map +3 -3
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js +1 -1
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.js.map +3 -3
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js +1 -1
- package/lib/esm/src/web3-check/data/HttpWeb3CheckDataSource.test.js.map +3 -3
- package/lib/types/src/ContextModuleBuilder.d.ts +4 -1
- package/lib/types/src/ContextModuleBuilder.d.ts.map +1 -1
- package/lib/types/src/config/di/configTypes.d.ts +1 -0
- package/lib/types/src/config/di/configTypes.d.ts.map +1 -1
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts +4 -0
- package/lib/types/src/config/model/ContextModuleBuildArgs.d.ts.map +1 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts +1 -0
- package/lib/types/src/config/model/ContextModuleConfig.d.ts.map +1 -1
- package/lib/types/src/external-plugin/data/HttpExternalPluginDataSource.d.ts.map +1 -1
- package/lib/types/src/nft/data/HttpNftDataSource.d.ts.map +1 -1
- package/lib/types/src/pki/data/HttpPkiCertificateDataSource.d.ts.map +1 -1
- package/lib/types/src/shared/constant/HttpHeaders.d.ts +3 -0
- package/lib/types/src/shared/constant/HttpHeaders.d.ts.map +1 -0
- package/lib/types/src/token/data/HttpTokenDataSource.d.ts.map +1 -1
- package/lib/types/src/transaction/data/HttpTransactionDataSource.d.ts.map +1 -1
- package/lib/types/src/trusted-name/data/HttpTrustedNameDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.d.ts.map +1 -1
- package/lib/types/src/typed-data/data/HttpTypedDataDataSource.test.d.ts.map +1 -1
- package/lib/types/src/web3-check/data/HttpWeb3CheckDataSource.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +12 -12
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import o from"axios";import{Left as n}from"purify-ts";import{
|
|
1
|
+
import o from"axios";import{Left as n}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as r}from"../../shared/constant/HttpHeaders";import{HttpTokenDataSource as s}from"../../token/data/HttpTokenDataSource";import d from"../../../package.json";vi.mock("axios");describe("HttpTokenDataSource",()=>{let t;beforeAll(()=>{const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"prod",branch:"main"}};t=new s(e),vi.clearAllMocks()}),it("should call axios with the ledger client version header",async()=>{const e=`context-module/${d.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),await t.getTokenInfosPayload({address:"0x00",chainId:1}),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[r]:e}}))}),it("should return a string when axios response is correct",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{prod:"0123"}}};vi.spyOn(o,"request").mockResolvedValue({data:[e]});const a=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(a.extract()).toEqual("04555344430000000008000000010123")}),it("should return an error when data is empty",async()=>{vi.spyOn(o,"request").mockResolvedValue({data:void 0});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual(n(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no signature",async()=>{vi.spyOn(o,"request").mockResolvedValue({data:[{}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual(n(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no ticker",async()=>{const e={ticker:"USDC",descriptor:{data:"55534443000000000800000001",signatures:{test:"0123"}}};vi.spyOn(o,"request").mockResolvedValue({data:[e]});const a=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(a).toEqual(n(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return undefined when no decimals",async()=>{vi.spyOn(o,"request").mockResolvedValue({data:[{live_signature:"0x0",ticker:"USDC"}]});const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual(n(new Error("[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1")))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error);const e=await t.getTokenInfosPayload({address:"0x00",chainId:1});expect(e).toEqual(n(new Error("[ContextModule] HttpTokenDataSource: Failed to fetch token informations")))})});
|
|
2
2
|
//# sourceMappingURL=HttpTokenDataSource.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/token/data/HttpTokenDataSource.test.ts"],
|
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type TokenDto } from \"@/token/data/TokenDto\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpTokenDataSource\", () => {\n let datasource: TokenDataSource;\n\n beforeAll(() => {\n const config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n datasource = new HttpTokenDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getTokenInfosPayload({ address: \"0x00\", chainId: 1 });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: {
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,uBAAAC,MAA2B,mCAGpC,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,IAAIC,EAEJ,UAAU,IAAM,CACd,MAAMC,EAAS,CACb,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,CACF,EACAD,EAAa,IAAIF,EAAoBG,CAAM,EAC3C,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,0DAA2D,SAAY,CAExE,MAAMC,EAAU,kBAAkBH,EAAQ,OAAO,GAC3CI,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,
|
|
6
|
-
"names": ["axios", "Left", "HttpTokenDataSource", "PACKAGE", "datasource", "config", "version", "requestSpy", "tokenDTO", "result"]
|
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { Left } from \"purify-ts\";\n\nimport { type ContextModuleConfig } from \"@/config/model/ContextModuleConfig\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport { HttpTokenDataSource } from \"@/token/data/HttpTokenDataSource\";\nimport { type TokenDataSource } from \"@/token/data/TokenDataSource\";\nimport { type TokenDto } from \"@/token/data/TokenDto\";\nimport PACKAGE from \"@root/package.json\";\n\nvi.mock(\"axios\");\n\ndescribe(\"HttpTokenDataSource\", () => {\n let datasource: TokenDataSource;\n\n beforeAll(() => {\n const config = {\n cal: {\n url: \"https://crypto-assets-service.api.ledger.com/v1\",\n mode: \"prod\",\n branch: \"main\",\n },\n } as ContextModuleConfig;\n datasource = new HttpTokenDataSource(config);\n vi.clearAllMocks();\n });\n\n it(\"should call axios with the ledger client version header\", async () => {\n // GIVEN\n const version = `context-module/${PACKAGE.version}`;\n const requestSpy = vi.fn(() => Promise.resolve({ data: [] }));\n vi.spyOn(axios, \"request\").mockImplementation(requestSpy);\n\n // WHEN\n await datasource.getTokenInfosPayload({ address: \"0x00\", chainId: 1 });\n\n // THEN\n expect(requestSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n headers: { [LEDGER_CLIENT_VERSION_HEADER]: version },\n }),\n );\n });\n\n it(\"should return a string when axios response is correct\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n prod: \"0123\",\n },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result.extract()).toEqual(\"04555344430000000008000000010123\");\n });\n\n it(\"should return an error when data is empty\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: undefined });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no signature\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [{}] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no ticker\", async () => {\n // GIVEN\n const tokenDTO: TokenDto = {\n ticker: \"USDC\",\n descriptor: {\n data: \"55534443000000000800000001\",\n signatures: {\n test: \"0123\",\n },\n },\n };\n vi.spyOn(axios, \"request\").mockResolvedValue({ data: [tokenDTO] });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return undefined when no decimals\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockResolvedValue({\n data: [{ live_signature: \"0x0\", ticker: \"USDC\" }],\n });\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: no token metadata for address 0x00 on chain 1\",\n ),\n ),\n );\n });\n\n it(\"should return an error when axios throws an error\", async () => {\n // GIVEN\n vi.spyOn(axios, \"request\").mockRejectedValue(new Error());\n\n // WHEN\n const result = await datasource.getTokenInfosPayload({\n address: \"0x00\",\n chainId: 1,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new Error(\n \"[ContextModule] HttpTokenDataSource: Failed to fetch token informations\",\n ),\n ),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,MAAY,YAGrB,OAAS,gCAAAC,MAAoC,gCAC7C,OAAS,uBAAAC,MAA2B,mCAGpC,OAAOC,MAAa,qBAEpB,GAAG,KAAK,OAAO,EAEf,SAAS,sBAAuB,IAAM,CACpC,IAAIC,EAEJ,UAAU,IAAM,CACd,MAAMC,EAAS,CACb,IAAK,CACH,IAAK,kDACL,KAAM,OACN,OAAQ,MACV,CACF,EACAD,EAAa,IAAIF,EAAoBG,CAAM,EAC3C,GAAG,cAAc,CACnB,CAAC,EAED,GAAG,0DAA2D,SAAY,CAExE,MAAMC,EAAU,kBAAkBH,EAAQ,OAAO,GAC3CI,EAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,KAAM,CAAC,CAAE,CAAC,CAAC,EAC5D,GAAG,MAAMR,EAAO,SAAS,EAAE,mBAAmBQ,CAAU,EAGxD,MAAMH,EAAW,qBAAqB,CAAE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AW,qBAAqB,CACnD,QAAS,OACT,QAAS,CACX,CAAC,EAGD,OAAOK,CAAM,EAAE,QACbT,EACE,IAAI,MACF,oFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,2CAA4C,SAAY,CAEzD,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,CAC3C,KAAM,CAAC,CAAE,eAAgB,MAAO,OAAQ,MAAO,CAAC,CAClD,CAAC,EAGD,MAAMU,EAAS,MAAML,EAAW,qBAAqB,CACnD,QAAS,OACT,QAAS,CACX,CAAC,EAGD,OAAOK,CAAM,EAAE,QACbT,EACE,IAAI,MACF,oFACF,CACF,CACF,CACF,CAAC,EAED,GAAG,oDAAqD,SAAY,CAElE,GAAG,MAAMD,EAAO,SAAS,EAAE,kBAAkB,IAAI,KAAO,EAGxD,MAAMU,EAAS,MAAML,EAAW,qBAAqB,CACnD,QAAS,OACT,QAAS,CACX,CAAC,EAGD,OAAOK,CAAM,EAAE,QACbT,EACE,IAAI,MACF,yEACF,CACF,CACF,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["axios", "Left", "LEDGER_CLIENT_VERSION_HEADER", "HttpTokenDataSource", "PACKAGE", "datasource", "config", "version", "requestSpy", "tokenDTO", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var d=(l,e,t,r)=>{for(var o=r>1?void 0:r?S(e,t):e,n=l.length-1,i;n>=0;n--)(i=l[n])&&(o=(r?i(e,t,o):i(o))||o);return r&&o&&P(e,t,o),o},f=(l,e)=>(t,r)=>e(t,r,l);import M from"axios";import{inject as m,injectable as I}from"inversify";import{Left as c,Right as R}from"purify-ts";import{configTypes as x}from"../../config/di/configTypes";import{pkiTypes as O}from"../../pki/di/pkiTypes";import{KeyId as F}from"../../pki/model/KeyId";import{KeyUsage as L}from"../../pki/model/KeyUsage";import{LEDGER_CLIENT_VERSION_HEADER as U}from"../../shared/constant/HttpHeaders";import{ClearSignContextType as a}from"../../shared/model/ClearSignContext";import{INFO_SIGNATURE_TAG as h}from"../../shared/model/SignatureTags";import{HexStringUtils as T}from"../../shared/utils/HexStringUtils";import k from"../../../package.json";let y=class{constructor(e,t){this.config=e;this._certificateLoader=t}async getTransactionDescriptors({chainId:e,address:t,selector:r,deviceModelId:o}){let n;try{n=(await M.request({method:"GET",url:`${this.config.cal.url}/dapps`,params:{output:"descriptors_calldata",chain_id:e,contracts:t,ref:`branch:${this.config.cal.branch}`},headers:{[U]:`context-module/${k.version}`}})).data}catch(i){return c(new Error(`[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${i}`))}if(!Array.isArray(n))return c(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array"));if(n.length===0)return c(new Error(`[ContextModule] HttpTransactionDataSource: No data for contract ${t} and selector ${r}`));for(const i of n){t=t.toLowerCase(),r=`0x${r.slice(2).toLowerCase()}`;const s=i.descriptors_calldata?.[t]?.[r];if(!s||!this.isCalldataDescriptorV1(s,this.config.cal.mode))continue;const E=s.transaction_info.descriptor.data,g=s.transaction_info.descriptor.signatures[this.config.cal.mode],D={targetDevice:o,keyUsage:L.Calldata,keyId:F.CalCalldataKey},u=await this._certificateLoader.loadCertificate(D),V={type:a.TRANSACTION_INFO,payload:T.appendSignatureToPayload(E,g,h),certificate:u},C=[];for(const[p,_]of Object.entries(s.enums))for(const[N,{data:b,signatures:v}]of Object.entries(_))C.push({type:a.ENUM,id:Number(p),value:Number(N),payload:T.appendSignatureToPayload(b,v[this.config.cal.mode],h),certificate:u});const A=s.fields.map(p=>({type:a.TRANSACTION_FIELD_DESCRIPTION,payload:p.descriptor,reference:this.getReference(p.param)}));return R([V,...C,...A])}return c(new Error(`[ContextModule] HttpTransactionDataSource: Invalid response for contract ${t} and selector ${r}`))}getReference(e){if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="path")return{type:a.TOKEN,valuePath:this.toGenericPath(e.token.binary_path)};if(e.type==="TOKEN_AMOUNT"&&e.token!==void 0&&e.token.type==="constant")return{type:a.TOKEN,value:e.token.value};if(e.type==="NFT"&&e.collection.type==="path")return{type:a.NFT,valuePath:this.toGenericPath(e.collection.binary_path)};if(e.type==="NFT"&&e.collection.type==="constant")return{type:a.NFT,value:e.collection.value};if(e.type==="TRUSTED_NAME"&&e.value.type==="path")return{type:a.TRUSTED_NAME,valuePath:this.toGenericPath(e.value.binary_path),types:e.types,sources:e.sources};if(e.type==="ENUM"&&e.value.type==="path")return{type:a.ENUM,valuePath:this.toGenericPath(e.value.binary_path),id:e.id}}toGenericPath(e){return e.type==="CONTAINER"?e.value:e.elements.map(t=>{if(t.type==="ARRAY"){const{weight:r,...o}=t;return{itemSize:r,...o}}else if(t.type==="LEAF"){const{leaf_type:r,...o}=t;return{leafType:r,...o}}return t})}isCalldataDescriptorV1(e,t){return typeof e=="object"&&e.type==="calldata"&&e.version==="v1"&&this.isTransactionInfoV1(e.transaction_info,t)&&this.isEnumV1(e.enums,t)&&Array.isArray(e.fields)&&e.fields.every(r=>this.isFieldV1(r))}isTransactionInfoV1(e,t){return typeof e=="object"&&typeof e.descriptor=="object"&&typeof e.descriptor.data=="string"&&typeof e.descriptor.signatures=="object"&&typeof e.descriptor.signatures[t]=="string"}isEnumV1(e,t){return typeof e=="object"&&Object.entries(e).every(([r,o])=>typeof r=="string"&&typeof o=="object"&&Object.entries(o).every(([n,i])=>typeof n=="string"&&typeof i=="object"&&typeof i.data=="string"&&i.signatures!==void 0&&this.isCalldataSignatures(i.signatures,t)))}isCalldataSignatures(e,t){return typeof e=="object"&&typeof e[t]=="string"}isFieldV1(e){return typeof e=="object"&&typeof e.descriptor=="string"&&typeof e.param=="object"&&typeof e.param.value=="object"&&this.isDescriptorValueV1(e.param.value)&&(e.param.type==="RAW"||e.param.type==="AMOUNT"||e.param.type==="DATETIME"||e.param.type==="DURATION"||e.param.type==="UNIT"||e.param.type==="ENUM"||e.param.type==="NFT"&&this.isDescriptorValueV1(e.param.collection)||e.param.type==="TOKEN_AMOUNT"&&(e.param.token===void 0||this.isDescriptorValueV1(e.param.token))||e.param.type==="TRUSTED_NAME"&&Array.isArray(e.param.types)&&Array.isArray(e.param.sources)&&e.param.types.every(t=>typeof t=="string")&&e.param.sources.every(t=>typeof t=="string"))}isDescriptorValueV1(e){return typeof e=="object"&&typeof e.type_family=="string"&&["UINT","INT","UFIXED","FIXED","ADDRESS","BOOL","BYTES","STRING"].includes(e.type_family)&&(typeof e.type_size>"u"||typeof e.type_size=="number")&&(e.type==="path"&&this.isCalldataDescriptorValueBinaryPathV1(e)||e.type==="constant"&&this.isCalldataDescriptorValueConstantV1(e))}isCalldataDescriptorValueConstantV1(e){return typeof e=="object"&&e.type==="constant"&&typeof e.value=="string"}isCalldataDescriptorValueBinaryPathV1(e){return typeof e=="object"&&(e.type==="path"&&e.binary_path.type==="CONTAINER"&&["FROM","TO","VALUE"].includes(e.binary_path.value)||e.binary_path.type==="DATA"&&Array.isArray(e.binary_path.elements)&&e.binary_path.elements.every(t=>this.isPathElementV1(t)))}isPathElementV1(e){return typeof e=="object"&&(e.type==="REF"||e.type==="TUPLE"&&typeof e.offset=="number"||e.type==="ARRAY"&&typeof e.weight=="number"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number")||e.type==="LEAF"&&typeof e.leaf_type=="string"&&["ARRAY_LEAF","TUPLE_LEAF","STATIC_LEAF","DYNAMIC_LEAF"].includes(e.leaf_type)||e.type==="SLICE"&&(typeof e.start>"u"||typeof e.start=="number")&&(typeof e.end>"u"||typeof e.end=="number"))}};y=d([I(),f(0,m(x.Config)),f(1,m(O.PkiCertificateLoader))],y);export{y as HttpTransactionDataSource};
|
|
2
2
|
//# sourceMappingURL=HttpTransactionDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/transaction/data/HttpTransactionDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport {\n ClearSignContextReference,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n \"X-Ledger-Client-Version\": `context-module/${PACKAGE.version}`,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAiB,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAAS,eAAAC,MAAmB,0BAK5B,OAAS,YAAAC,MAAgB,oBAEzB,OAAS,SAAAC,MAAa,oBACtB,OAAS,YAAAC,MAAgB,uBAGzB,OAGE,wBAAAC,MACK,kCAEP,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,kBAAAC,MAAsB,gCAC/B,OAAOC,MAAa,qBAyBb,IAAMC,EAAN,KAAiE,CACtE,YAC+CC,EAE5BC,EACjB,CAH6C,YAAAD,EAE5B,wBAAAC,CAChB,CAEH,MAAa,0BAA0B,CACrC,QAAAC,EACA,QAAAC,EACA,SAAAC,EACA,cAAAC,CACF,EAEE,CACA,IAAIC,EACJ,GAAI,CAcFA,GAbiB,MAAMC,EAAM,QAAuB,CAClD,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,IAAI,GAAG,SAC3B,OAAQ,CACN,OAAQ,uBACR,SAAUL,EACV,UAAWC,EACX,IAAK,UAAU,KAAK,OAAO,IAAI,MAAM,EACvC,EACA,QAAS,CACP,
|
|
6
|
-
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpTransactionDataSource", "config", "_certificateLoader", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "PACKAGE", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
|
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport { configTypes } from \"@/config/di/configTypes\";\nimport {\n type ContextModuleCalMode,\n type ContextModuleConfig,\n} from \"@/config/model/ContextModuleConfig\";\nimport { pkiTypes } from \"@/pki/di/pkiTypes\";\nimport { type PkiCertificateLoader } from \"@/pki/domain/PkiCertificateLoader\";\nimport { KeyId } from \"@/pki/model/KeyId\";\nimport { KeyUsage } from \"@/pki/model/KeyUsage\";\nimport { PkiCertificate } from \"@/pki/model/PkiCertificate\";\nimport { PkiCertificateInfo } from \"@/pki/model/PkiCertificateInfo\";\nimport { LEDGER_CLIENT_VERSION_HEADER } from \"@/shared/constant/HttpHeaders\";\nimport {\n ClearSignContextReference,\n ClearSignContextSuccess,\n ClearSignContextType,\n} from \"@/shared/model/ClearSignContext\";\nimport { GenericPath } from \"@/shared/model/GenericPath\";\nimport { INFO_SIGNATURE_TAG } from \"@/shared/model/SignatureTags\";\nimport { HexStringUtils } from \"@/shared/utils/HexStringUtils\";\nimport PACKAGE from \"@root/package.json\";\n\nimport {\n CalldataDescriptor,\n CalldataDescriptorContainerPathV1,\n CalldataDescriptorParam,\n CalldataDescriptorPathElementsV1,\n CalldataDescriptorPathElementV1,\n CalldataDescriptorV1,\n CalldataDescriptorValueBinaryPathV1,\n CalldataDescriptorValueConstantV1,\n CalldataDescriptorValueV1,\n CalldataDto,\n CalldataEnumV1,\n CalldataFieldV1,\n CalldataSignatures,\n CalldataTransactionDescriptor,\n CalldataTransactionInfoV1,\n} from \"./CalldataDto\";\nimport {\n GetTransactionDescriptorsParams,\n TransactionDataSource,\n} from \"./TransactionDataSource\";\n\n@injectable()\nexport class HttpTransactionDataSource implements TransactionDataSource {\n constructor(\n @inject(configTypes.Config) private readonly config: ContextModuleConfig,\n @inject(pkiTypes.PkiCertificateLoader)\n private readonly _certificateLoader: PkiCertificateLoader,\n ) {}\n\n public async getTransactionDescriptors({\n chainId,\n address,\n selector,\n deviceModelId,\n }: GetTransactionDescriptorsParams): Promise<\n Either<Error, ClearSignContextSuccess[]>\n > {\n let dto: CalldataDto[] | undefined;\n try {\n const response = await axios.request<CalldataDto[]>({\n method: \"GET\",\n url: `${this.config.cal.url}/dapps`,\n params: {\n output: \"descriptors_calldata\",\n chain_id: chainId,\n contracts: address,\n ref: `branch:${this.config.cal.branch}`,\n },\n headers: {\n [LEDGER_CLIENT_VERSION_HEADER]: `context-module/${PACKAGE.version}`,\n },\n });\n dto = response.data;\n } catch (error) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: ${error}`,\n ),\n );\n }\n\n if (!Array.isArray(dto)) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Response is not an array`,\n ),\n );\n }\n\n if (dto.length === 0) {\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: No data for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n for (const calldata of dto) {\n // Normalize the address and selector\n address = address.toLowerCase();\n selector = `0x${selector.slice(2).toLowerCase()}`;\n const calldataDescriptor =\n calldata.descriptors_calldata?.[address]?.[selector];\n\n if (\n !calldataDescriptor ||\n !this.isCalldataDescriptorV1(calldataDescriptor, this.config.cal.mode)\n ) {\n continue;\n }\n\n const infoData = calldataDescriptor.transaction_info.descriptor.data;\n const infoSignature =\n calldataDescriptor.transaction_info.descriptor.signatures[\n this.config.cal.mode\n ];\n\n const certificateInfos: PkiCertificateInfo = {\n targetDevice: deviceModelId,\n keyUsage: KeyUsage.Calldata,\n keyId: KeyId.CalCalldataKey,\n };\n const certificate: PkiCertificate | undefined =\n await this._certificateLoader.loadCertificate(certificateInfos);\n\n const info: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: HexStringUtils.appendSignatureToPayload(\n infoData,\n infoSignature,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n };\n\n const enums: ClearSignContextSuccess[] = [];\n for (const [id, values] of Object.entries(calldataDescriptor.enums)) {\n for (const [\n value,\n { data, signatures },\n ] of Object.entries<CalldataTransactionDescriptor>(values)) {\n enums.push({\n type: ClearSignContextType.ENUM,\n id: Number(id),\n value: Number(value),\n payload: HexStringUtils.appendSignatureToPayload(\n data,\n signatures[this.config.cal.mode]!,\n INFO_SIGNATURE_TAG,\n ),\n certificate,\n });\n }\n }\n\n const fields: ClearSignContextSuccess[] = calldataDescriptor.fields.map(\n (field) => ({\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: field.descriptor,\n reference: this.getReference(field.param),\n }),\n );\n return Right([info, ...enums, ...fields]);\n }\n\n return Left(\n new Error(\n `[ContextModule] HttpTransactionDataSource: Invalid response for contract ${address} and selector ${selector}`,\n ),\n );\n }\n\n private getReference(\n param: CalldataDescriptorParam,\n ): ClearSignContextReference | undefined {\n if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"path\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n valuePath: this.toGenericPath(param.token.binary_path),\n };\n } else if (\n param.type === \"TOKEN_AMOUNT\" &&\n param.token !== undefined &&\n param.token.type === \"constant\"\n ) {\n return {\n type: ClearSignContextType.TOKEN,\n value: param.token.value,\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"path\") {\n return {\n type: ClearSignContextType.NFT,\n valuePath: this.toGenericPath(param.collection.binary_path),\n };\n } else if (param.type === \"NFT\" && param.collection.type === \"constant\") {\n return {\n type: ClearSignContextType.NFT,\n value: param.collection.value,\n };\n } else if (param.type === \"TRUSTED_NAME\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.TRUSTED_NAME,\n valuePath: this.toGenericPath(param.value.binary_path),\n types: param.types,\n sources: param.sources,\n };\n } else if (param.type === \"ENUM\" && param.value.type === \"path\") {\n return {\n type: ClearSignContextType.ENUM,\n valuePath: this.toGenericPath(param.value.binary_path),\n id: param.id,\n };\n }\n return undefined;\n }\n\n private toGenericPath(\n path: CalldataDescriptorContainerPathV1 | CalldataDescriptorPathElementsV1,\n ): GenericPath {\n if (path.type === \"CONTAINER\") {\n return path.value;\n }\n return path.elements.map((element) => {\n if (element.type === \"ARRAY\") {\n const { weight: itemSize, ...rest } = element;\n return {\n itemSize,\n ...rest,\n };\n } else if (element.type === \"LEAF\") {\n const { leaf_type: leafType, ...rest } = element;\n return {\n leafType,\n ...rest,\n };\n }\n return element;\n });\n }\n\n private isCalldataDescriptorV1(\n data: CalldataDescriptor,\n mode: ContextModuleCalMode,\n ): data is CalldataDescriptorV1 & {\n transaction_info: {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n };\n } {\n return (\n typeof data === \"object\" &&\n data.type === \"calldata\" &&\n data.version === \"v1\" &&\n this.isTransactionInfoV1(data.transaction_info, mode) &&\n this.isEnumV1(data.enums, mode) &&\n Array.isArray(data.fields) &&\n data.fields.every((f) => this.isFieldV1(f))\n );\n }\n\n private isTransactionInfoV1(\n data: CalldataTransactionInfoV1,\n mode: ContextModuleCalMode,\n ): data is CalldataTransactionInfoV1 & {\n descriptor: {\n signatures: { [_key in ContextModuleCalMode]: string };\n };\n } {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"object\" &&\n typeof data.descriptor.data === \"string\" &&\n typeof data.descriptor.signatures === \"object\" &&\n typeof data.descriptor.signatures[mode] === \"string\"\n );\n }\n\n private isEnumV1(\n calldata: CalldataEnumV1,\n mode: ContextModuleCalMode,\n ): calldata is CalldataEnumV1 {\n return (\n typeof calldata === \"object\" &&\n Object.entries(calldata).every(\n ([id, values]) =>\n typeof id === \"string\" &&\n typeof values === \"object\" &&\n Object.entries<CalldataTransactionDescriptor>(values).every(\n ([value, obj]) =>\n typeof value === \"string\" &&\n typeof obj === \"object\" &&\n typeof obj.data === \"string\" &&\n obj.signatures !== undefined &&\n this.isCalldataSignatures(obj.signatures, mode),\n ),\n )\n );\n }\n\n private isCalldataSignatures(\n data: CalldataSignatures,\n mode: ContextModuleCalMode,\n ): data is CalldataSignatures & { [_key in ContextModuleCalMode]: string } {\n return typeof data === \"object\" && typeof data[mode] === \"string\";\n }\n\n private isFieldV1(data: CalldataFieldV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.descriptor === \"string\" &&\n typeof data.param === \"object\" &&\n typeof data.param.value === \"object\" &&\n this.isDescriptorValueV1(data.param.value) &&\n (data.param.type === \"RAW\" ||\n data.param.type === \"AMOUNT\" ||\n data.param.type === \"DATETIME\" ||\n data.param.type === \"DURATION\" ||\n data.param.type === \"UNIT\" ||\n data.param.type === \"ENUM\" ||\n (data.param.type === \"NFT\" &&\n this.isDescriptorValueV1(data.param.collection)) ||\n (data.param.type === \"TOKEN_AMOUNT\" &&\n (data.param.token === undefined ||\n this.isDescriptorValueV1(data.param.token))) ||\n (data.param.type === \"TRUSTED_NAME\" &&\n Array.isArray(data.param.types) &&\n Array.isArray(data.param.sources) &&\n data.param.types.every((t) => typeof t === \"string\") &&\n data.param.sources.every((t) => typeof t === \"string\")))\n );\n }\n\n private isDescriptorValueV1(data: CalldataDescriptorValueV1): boolean {\n return (\n typeof data === \"object\" &&\n typeof data.type_family === \"string\" &&\n [\n \"UINT\",\n \"INT\",\n \"UFIXED\",\n \"FIXED\",\n \"ADDRESS\",\n \"BOOL\",\n \"BYTES\",\n \"STRING\",\n ].includes(data.type_family) &&\n (typeof data.type_size === \"undefined\" ||\n typeof data.type_size === \"number\") &&\n ((data.type === \"path\" &&\n this.isCalldataDescriptorValueBinaryPathV1(data)) ||\n (data.type === \"constant\" &&\n this.isCalldataDescriptorValueConstantV1(data)))\n );\n }\n\n private isCalldataDescriptorValueConstantV1(\n data: CalldataDescriptorValueConstantV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n data.type === \"constant\" &&\n typeof data.value === \"string\"\n );\n }\n\n private isCalldataDescriptorValueBinaryPathV1(\n data: CalldataDescriptorValueBinaryPathV1,\n ): boolean {\n return (\n typeof data === \"object\" &&\n ((data.type === \"path\" &&\n data.binary_path.type === \"CONTAINER\" &&\n [\"FROM\", \"TO\", \"VALUE\"].includes(data.binary_path.value)) ||\n (data.binary_path.type === \"DATA\" &&\n Array.isArray(data.binary_path.elements) &&\n data.binary_path.elements.every((e) => this.isPathElementV1(e))))\n );\n }\n\n private isPathElementV1(data: CalldataDescriptorPathElementV1): boolean {\n return (\n typeof data === \"object\" &&\n (data.type === \"REF\" ||\n (data.type === \"TUPLE\" && typeof data.offset === \"number\") ||\n (data.type === \"ARRAY\" &&\n typeof data.weight === \"number\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")) ||\n (data.type === \"LEAF\" &&\n typeof data.leaf_type === \"string\" &&\n [\"ARRAY_LEAF\", \"TUPLE_LEAF\", \"STATIC_LEAF\", \"DYNAMIC_LEAF\"].includes(\n data.leaf_type,\n )) ||\n (data.type === \"SLICE\" &&\n (typeof data.start === \"undefined\" ||\n typeof data.start === \"number\") &&\n (typeof data.end === \"undefined\" || typeof data.end === \"number\")))\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,OAAOA,EAAK,WAAc,UAC1B,CAAC,aAAc,aAAc,cAAe,cAAc,EAAE,SAC1DA,EAAK,SACP,GACDA,EAAK,OAAS,UACZ,OAAOA,EAAK,MAAU,KACrB,OAAOA,EAAK,OAAU,YACvB,OAAOA,EAAK,IAAQ,KAAe,OAAOA,EAAK,KAAQ,UAEhE,CACF,EA3Wa7B,EAAN4C,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAY,MAAM,GACzBF,EAAA,EAAAC,EAAOE,EAAS,oBAAoB,IAH5BjD",
|
|
6
|
+
"names": ["axios", "inject", "injectable", "Left", "Right", "configTypes", "pkiTypes", "KeyId", "KeyUsage", "LEDGER_CLIENT_VERSION_HEADER", "ClearSignContextType", "INFO_SIGNATURE_TAG", "HexStringUtils", "PACKAGE", "HttpTransactionDataSource", "config", "_certificateLoader", "chainId", "address", "selector", "deviceModelId", "dto", "axios", "LEDGER_CLIENT_VERSION_HEADER", "PACKAGE", "error", "Left", "calldata", "calldataDescriptor", "infoData", "infoSignature", "certificateInfos", "KeyUsage", "KeyId", "certificate", "info", "ClearSignContextType", "HexStringUtils", "INFO_SIGNATURE_TAG", "enums", "id", "values", "value", "data", "signatures", "fields", "field", "Right", "param", "path", "element", "itemSize", "rest", "leafType", "mode", "f", "obj", "e", "__decorateClass", "injectable", "__decorateParam", "inject", "configTypes", "pkiTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as c}from"@ledgerhq/device-management-kit";import o from"axios";import{Left as i}from"purify-ts";import{HttpTransactionDataSource as D}from"../../transaction/data/HttpTransactionDataSource";import h from"../../../package.json";vi.mock("axios");describe("HttpTransactionDataSource",()=>{let t,r,u,l,v,m,f,p,b,y,x;const d={loadCertificate:vi.fn()};beforeAll(()=>{vi.clearAllMocks();const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"}};t=new D(e,d),r={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},u={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},f=E("FROM","UFIXED","AMOUNT","06"),p=E("TO","FIXED","DATETIME","07"),b=E("TO","BOOL","UNIT","08"),y=E("VALUE","INT","DURATION","09"),l={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT",type_size:32},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},v={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},m={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},x={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"}});function E(e,a,n,T){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:e},type_family:a,type_size:32},type:n},descriptor:T}}function s(e,a,n){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:e,enums:a,fields:n}}}}}it("should call axios with the ledger client version header",async()=>{const e=`context-module/${h.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0),await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{"X-Ledger-Client-Version":e}}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: Error")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{vi.spyOn(o,"request").mockResolvedValue({data:[]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const e=s(r,u,[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const e=s(r,u,[l,v,m,x]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const e=s(r,u,[l,v,m,x]),a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValueOnce(a);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:a},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:x.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const e=s(r,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata on third array element",async()=>{const e=s(r,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[{},{},e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const e={descriptor:{data:r.descriptor.data,signatures:{test:r.descriptor.signatures.test+"0"}}},a=s(e,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const e={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},a=s(r,[],[e]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const e={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},a=s(r,[],[e]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const e={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:r,enums:u,fields:[l]}}}};vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const e=s({descriptor:{data:"1234",signatures:{prod:"1234"}}},u,[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const e=s(r,["badEnum"],[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const e=s(r,{0:{1:{data:"1234"}}},[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const e=s(r,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const e=s(r,[],[{descriptor:3}]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))})});
|
|
1
|
+
import{DeviceModelId as c}from"@ledgerhq/device-management-kit";import o from"axios";import{Left as i}from"purify-ts";import{LEDGER_CLIENT_VERSION_HEADER as D}from"../../shared/constant/HttpHeaders";import{HttpTransactionDataSource as h}from"../../transaction/data/HttpTransactionDataSource";import I from"../../../package.json";vi.mock("axios");describe("HttpTransactionDataSource",()=>{let t,r,u,l,v,m,f,p,b,y,E;const d={loadCertificate:vi.fn()};beforeAll(()=>{vi.clearAllMocks();const e={cal:{url:"https://crypto-assets-service.api.ledger.com/v1",mode:"test",branch:"main"}};t=new h(e,d),r={descriptor:{data:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c",signatures:{test:"3045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f"}}},u={0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c65",signatures:{test:"3045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582"}},2:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c65",signatures:{test:"3045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523"}}}},f=x("FROM","UFIXED","AMOUNT","06"),p=x("TO","FIXED","DATETIME","07"),b=x("TO","BOOL","UNIT","08"),y=x("VALUE","INT","DURATION","09"),l={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT",type_size:32},type:"TOKEN_AMOUNT",token:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",start:0,end:5,weight:1},{type:"LEAF",leaf_type:"DYNAMIC_LEAF"}]},type_family:"ADDRESS",type_size:20}},descriptor:"0001000112416d6f756e7420746f20776974686472617702010203580001000115000100010101020120030a000100010200010401030215000100010105020114030a000100010200000401030420ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff05034d6178"},v={param:{value:{type:"path",binary_path:{type:"CONTAINER",value:"TO"},type_family:"STRING",type_size:20},type:"TRUSTED_NAME",types:["eoa"],sources:["ens","unstoppable_domain"]},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114030a00010001020002040103020101030402030402"},m={param:{value:{type:"path",binary_path:{type:"DATA",elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES",type_size:20},collection:{type:"path",binary_path:{type:"DATA",elements:[{type:"REF"},{type:"LEAF",leaf_type:"ARRAY_LEAF"},{type:"SLICE",start:1}]},type_family:"INT",type_size:20},type:"NFT"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020114"},E={param:{id:0,value:{type:"path",binary_path:{type:"DATA",elements:[]},type_family:"BYTES",type_size:20},type:"ENUM"},descriptor:"000100010c546f20726563697069656e7402010803230001000115000100010105020112"}});function x(e,a,n,T){return{param:{value:{type:"path",binary_path:{type:"CONTAINER",value:e},type_family:a,type_size:32},type:n},descriptor:T}}function s(e,a,n){return{descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldata",version:"v1",transaction_info:e,enums:a,fields:n}}}}}it("should call axios with the ledger client version header",async()=>{const e=`context-module/${I.version}`,a=vi.fn(()=>Promise.resolve({data:[]}));vi.spyOn(o,"request").mockImplementation(a),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0),await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"}),expect(a).toHaveBeenCalledWith(expect.objectContaining({headers:{[D]:e}}))}),it("should return an error when axios throws an error",async()=>{vi.spyOn(o,"request").mockRejectedValue(new Error),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Failed to fetch transaction informations: Error")))}),it("should return an error when no payload is returned",async()=>{const e={data:{test:""}};vi.spyOn(o,"request").mockResolvedValue(e),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Response is not an array")))}),it("should return an error when an empty array is returned",async()=>{vi.spyOn(o,"request").mockResolvedValue({data:[]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const e=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x0abc",selector:"0x01ff"});expect(e).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: No data for contract 0x0abc and selector 0x01ff")))}),it("should return an error when selector is not found",async()=>{const e=s(r,u,[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x01fe"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x01fe")))}),it("Calldata with fields references and enums",async()=>{const e=s(r,u,[l,v,m,E]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata with fields references and enums with certificates",async()=>{const e=s(r,u,[l,v,m,E]),a={keyUsageNumber:11,payload:new Uint8Array([1,2,3,4,21,4,5,6,7,8])};vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValueOnce(a);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80B7a3454c06bdac94a69ddc7a9",selector:"0x69328dEc"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo",certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec0401000501010606737461626c6581ff473045022100862e724db664f5d94484928a6a5963268a22cd8178ad36e8c4ff13769ac5c27e0220079da2b6e86810156f6b5955b8190bc016c2fe813d27fcb878a9b99658546582",type:"enum",id:0,value:1,certificate:a},{payload:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010206087661726961626c6581ff473045022100b838ee3d597d6bad2533606cef7335f6c8a45b46d5717803e646777f6c8a6897022074f04b82c3dad8445bb6230ab762010c5fc6ee06198fd3e54752287cbf95c523",type:"enum",id:0,value:2,certificate:a},{payload:l.descriptor,type:"transactionFieldDescription",reference:{type:"token",valuePath:[{type:"ARRAY",start:0,end:5,itemSize:1},{type:"LEAF",leafType:"DYNAMIC_LEAF"}]}},{payload:v.descriptor,type:"transactionFieldDescription",reference:{type:"trustedName",valuePath:"TO",types:["eoa"],sources:["ens","unstoppable_domain"]}},{payload:m.descriptor,type:"transactionFieldDescription",reference:{type:"nft",valuePath:[{type:"REF"},{type:"LEAF",leafType:"ARRAY_LEAF"},{type:"SLICE",start:1}]}},{payload:E.descriptor,type:"transactionFieldDescription",reference:{type:"enum",valuePath:[],id:0}}])}),it("Calldata without fields references",async()=>{const e=s(r,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata on third array element",async()=>{const e=s(r,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[{},{},e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata without fields references and transaction info signature length % 2 different from 0",async()=>{const e={descriptor:{data:r.descriptor.data,signatures:{test:r.descriptor.signatures.test+"0"}}},a=s(e,[],[f,p,b,y]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff4803045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f0",type:"transactionInfo"},{type:"transactionFieldDescription",payload:f.descriptor},{type:"transactionFieldDescription",payload:p.descriptor},{type:"transactionFieldDescription",payload:b.descriptor},{type:"transactionFieldDescription",payload:y.descriptor}])}),it("Calldata with token fields references as constants",async()=>{const e={name:"Amount to exchange",param:{type:"TOKEN_AMOUNT",token:{raw:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",type:"constant",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_stETHAmount"}]},type_size:32,binary_path:{type:"DATA",version:1,elements:[{type:"TUPLE",offset:0},{type:"LEAF",leaf_type:"STATIC_LEAF"}]},type_family:"UINT"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f0001010101050201140514ae7ab96520de3a18e5e111b5eaab095312d7fe84"},a=s(r,[],[e]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"token",value:"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"}}])}),it("Calldata with collection fields references as constants",async()=>{const e={name:"Collection ID",param:{type:"NFT",collection:{raw:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",type:"constant",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",version:1,type_size:20,type_family:"ADDRESS"},value:{type:"path",version:1,abi_path:{type:"data",absolute:!0,elements:[{type:"field",identifier:"_collectionId"}]},type_size:20,binary_path:{type:"DATA",version:1,elements:[{type:"ARRAY",weight:2},{type:"LEAF",leaf_type:"TUPLE_LEAF"},{type:"SLICE",end:2}]},type_family:"BYTES"},version:1},version:1,descriptor:"0001010112416d6f756e7420746f2065786368616e6765020102033b0001010115000101010101020120030a00010101020000040103021f00010101010502011405147d2768de32b0b80b7a3454c06bdac94a69ddc7a9"},a=s(r,[],[e]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n.extract()).toEqual([{payload:"0001000108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04207d5e9ed0004b8035b164edd9d78c37415ad6b1d123be4943d0abd5a50035cae3050857697468647261770604416176650708416176652044414f081068747470733a2f2f616176652e636f6d0a045fc4ba9c81ff473045022100eb67599abfd9c7360b07599a2a2cb769c6e3f0f74e1e52444d788c8f577a16d20220402e92b0adbf97d890fa2f9654bc30c7bd70dacabe870f160e6842d9eb73d36f",type:"transactionInfo"},{payload:e.descriptor,type:"transactionFieldDescription",reference:{type:"nft",value:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9"}}])}),it("should return an error when calldata is not correctly formatted",async()=>{const e={descriptors_calldata:{"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9":{"0x69328dec":{type:"calldat",version:"v1",transaction_info:r,enums:u,fields:[l]}}}};vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when transactionInfo is not correctly formatted",async()=>{const e=s({descriptor:{data:"1234",signatures:{prod:"1234"}}},u,[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum is not correctly formatted",async()=>{const e=s(r,["badEnum"],[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum does not contain a signature",async()=>{const e=s(r,{0:{1:{data:"1234"}}},[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when enum contain the wrong signature",async()=>{const e=s(r,{0:{1:{data:"0001010108000000000000000102147d2768de32b0b80b7a3454c06bdac94a69ddc7a9030469328dec04010005010106067374626c65",signatures:{prod:"wrongSignature"}}}},[l]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field is not correctly formatted",async()=>{const e=s(r,[],[{descriptor:3}]);vi.spyOn(o,"request").mockResolvedValue({data:[e]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const a=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(a).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field value is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"TO",type_family:"UNKNOWN",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field container path is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"UNKNOWN",type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field calldata path is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:{elements:[{type:"UNKNOWN"}]},type_family:"ADDRESS",type_size:20},type:"DATETIME"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))}),it("should return an error when field type is not correctly formatted",async()=>{const a=s(r,[],[{param:{value:{binary_path:"TO",type_family:"ADDRESS",type_size:20},type:"UNKNOWN"},descriptor:"000100010c546f20726563697069667"}]);vi.spyOn(o,"request").mockResolvedValue({data:[a]}),vi.spyOn(d,"loadCertificate").mockResolvedValue(void 0);const n=await t.getTransactionDescriptors({deviceModelId:c.FLEX,chainId:1,address:"0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9",selector:"0x69328dec"});expect(n).toEqual(i(new Error("[ContextModule] HttpTransactionDataSource: Invalid response for contract 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9 and selector 0x69328dec")))})});
|
|
2
2
|
//# sourceMappingURL=HttpTransactionDataSource.test.js.map
|